我正在创建一个NSIS脚本,其中可以在安装过程中设置要安装的Java应用程序的Xmx值.我不确定这个参数是否设置正确.有没有办法在应用程序运行时检查配置的Xmx值?
在现有项目上工作,我必须使用WinForms(暂时没有使用它)并且遇到与UI线程同步的问题.
我必须集成的设计如下:A BackgroundWorker获取Action一个参数并异步执行它.我正在采取的行动有两个部分; 核心类(包含业务逻辑)和GUI部分,如果必须请求用户交互,则由核心通过事件通知.
我已经将句柄创建添加到表单的构造函数中
if (!IsHandleCreated)
{
//be sure to create the handle in the constructor
//to allow synchronization with th GUI thread
//when using Show() or ShowDialog()
CreateHandle();
}
Run Code Online (Sandbox Code Playgroud)
有了这个,下面的代码工作:
private DialogResult ShowDialog(Form form)
{
DialogResult dialogResult = DialogResult.None;
Action action = delegate { dialogResult = form.ShowDialog(); };
form.Invoke(action);
return dialogResult;
}
Run Code Online (Sandbox Code Playgroud)
对于此示例,启动位置已设置为Windows默认值.
如果我将其更改为:
Action action = delegate { dialogResult = form.ShowDialog(ParentWindow); };
Run Code Online (Sandbox Code Playgroud)
哪里ParentWindow是实例IWin32Window和WindowStartupLocation设置为CenterParent.调用时遇到跨线程异常form.Invoke(action).
跨线程操作无效:控制从其创建的线程以外的线程访问的"ActivationConfirmationForm". …
我无法找到一种在swing GUI中调整某些组件大小的方法.一些自定义标签正被添加到FlowLayout中,当调整对话框大小时,它不会表现如何.该小组正在使用jgoodies表单框架构建.
如果使用这个,将FlowLayout添加到xy(3,y)
FormLayout layout = new FormLayout("r:d, 5px, f:d:g", // columns
"p, p, 5px, p, 5px, p") // rows
Run Code Online (Sandbox Code Playgroud)
FlowLayout展开并显示滚动条

如果使用
FormLayout layout = new FormLayout("r:d, 5px, f:10:g", // columns
"p, p, 5px, p, 5px, p") // rows
Run Code Online (Sandbox Code Playgroud)
FlowLayout使用可用空间,第二行上的项目消失

我想将包含FlowLayout的每一行的高度扩展到组件的当前高度.不幸的是,首选大小始终对应于单行的高度.
另一种布局会更合适吗?左侧的粗体文本应右对齐,然后是FlowLayout.
[编辑]在试图弄清楚如何执行这几周后,实际的问题可以恢复到这样:
一组标签被添加到JPanel.此JPanel应水平使用所有可用空间(对话框大小减去标签名称标签的宽度)并根据需要垂直展开.如果JPanel的高度比对话框大,则应显示垂直滚动条(水平滚动条永远不可见).对话框可以显示多个JPanel,它们将一个接一个地显示(垂直).
这是使用GridBagLayout和WrapLayout的尝试:
public class GridBagLayoutTagPanel extends JPanel {
private static final long serialVersionUID = -441746014057882848L;
private final int NB_TAGS = 5;
public GridBagLayoutTagPanel() {
setLayout(new GridLayout());
JPanel pTags = new JPanel(new GridBagLayout());
pTags.setBackground(Color.ORANGE); …Run Code Online (Sandbox Code Playgroud) 我正在建立一个新的 asp.net core 3.1 项目,以FHIR格式公开 RESTful API,这是一种扩展 JSON 的格式。
我想用SwaggerUI制作一个简单的用户界面。这就是我遇到的问题,即显示错误。
启动 SwaggerUI 时,没有错误。当扩展单个可用的 POST 请求时,会出现以下错误:

完整列表:
Resolver error at paths./Bundle/$analyze.post.requestBody.content.text/json.schema.properties.parameter.items.properties.children.items.properties.children.items.$ref
Could not resolve reference:
Resolver error at paths./Bundle/$analyze.post.requestBody.content.text/json.schema.properties.parameter.items.properties.extension.items.properties.extension.items.$ref
Could not resolve reference:
Resolver error at paths./Bundle/$analyze.post.requestBody.content.text/json.schema.properties.idElement.properties.extension.items.properties.extension.items.$ref
Could not resolve reference:
Resolver error at paths./Bundle/$analyze.post.requestBody.content.text/json.schema.properties.idElement.properties.children.items.properties.children.items.$ref
Could not resolve reference:
Resolver error at paths./Bundle/$analyze.post.requestBody.content.text/json.schema.properties.meta.properties.children.items.properties.children.items.$ref
Could not resolve reference:
Resolver error at paths./Bundle/$analyze.post.requestBody.content.text/json.schema.properties.meta.properties.extension.items.properties.extension.items.$ref
Could not resolve reference:
Resolver error at paths./Bundle/$analyze.post.requestBody.content.text/json.schema.properties.implicitRulesElement.properties.extension.items.properties.extension.items.$ref
Could not resolve reference:
Resolver error at paths./Bundle/$analyze.post.requestBody.content.text/json.schema.properties.implicitRulesElement.properties.children.items.properties.children.items.$ref …Run Code Online (Sandbox Code Playgroud) 在我参与的开源应用程序中,我们遇到了一个错误,应用程序并不总是正常关闭.这就是我想要解决的问题.
经验表明,这种情况大部分发生在线程和进程启动时,但未正确管理(例如,线程正在等待套接字连接,应用程序正在关闭并且线程一直在等待).
考虑到这一点,我在整个源代码中搜索了'.start()',发现了53次(让我感到有些害怕).
作为第一步,我想创建一个帮助器类(ThreadExecutor),其中当前代码'thread.start()'将被'ThreadExecutor.Execute(thread)'替换为a)现有源中只有一些更改和b)一个单独的类,我可以很容易地检查哪些线程没有按预期结束.要做到这一点,我想
这样我就可以获得所有正在执行的线程的最新列表,当应用程序挂起时,我可以看到哪个线程正在导致它.
问题:
只是为了澄清:在弄清楚如何正确终止应用程序之前,我在这里要问的是找到哪些线程对于某些非常难以重现的测试用例的原因是什么是最好/最简单的方法.
对于一个媒体库,我想在文件系统中的条目发生更改时更新条目,我想通过使用此示例来尝试“新”java.nio文件观看功能。
我期望在创建、移动(重命名)或删除文件时获得有用的事件,但在 windows7 上观看文件夹时发生的情况如下(尚未尝试其他操作系统):
格式:
[ThreadName] DEBUG 2012-04-09 18:20:35.934 GroupNumber-COMMAND:路径
ThreadName:每个监视文件夹在其自己的线程中运行,具有不同的 id
GroupNumber:使用相同 GroupNumber 发送的消息同时发送(通常..)
COMMAND:接收到的命令
Path:接收到的路径
Rename:
[Watch0] DEBUG 2012-04-09 18:20:35.934 2-ENTRY_DELETE: C:\tmp\tmp\test.avi
[Watch0] DEBUG 2012-04-09 18:20:35.935 2-ENTRY_CREATE: C:\tmp\tmp\test1.avi
[Watch0] DEBUG 2012-04-09 18:20:35.936 3-ENTRY_MODIFY: C:\tmp\tmp
[Watch0] DEBUG 2012-04-09 18:20:35.937 4-ENTRY_MODIFY: C:\tmp\tmp\test1.avi
[Watch4] DEBUG 2012-04-09 18:43:47.965 18-ENTRY_DELETE: F:\tmp\test.avi
[Watch4] DEBUG 2012-04-09 18:43:47.966 18-ENTRY_CREATE: F:\tmp\test1.avi
[Watch4] DEBUG 2012-04-09 18:43:47.967 19-ENTRY_MODIFY: F:\tmp\test1.avi
Create:
[Watch0] DEBUG 2012-04-09 18:22:02.055 5-ENTRY_CREATE: C:\tmp\test.avi
[Watch0] DEBUG 2012-04-09 18:22:02.066 6-ENTRY_MODIFY: C:\tmp\test.avi
[Watch0] DEBUG 2012-04-09 18:22:03.460 …Run Code Online (Sandbox Code Playgroud) 假设我有以下对象:
实体:
public class MyEntity : NamedEntity
{
}
public abstract class NamedEntity : VersionedEntity
{
public LocalizedText Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
复杂对象(LocalizedText):
public class LocalizedText : ILocalized<string>
{
protected LocalizedText()
{
}
public LocalizedText(string en, string de = null, string fr = null)
{
En = en;
De = de;
Fr = fr;
}
public string En { get; set; }
public string De { get; set; }
public string Fr { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这样,我得到以下异常: …
我正在开发一个工厂,该工厂将根据类型返回接口的通用实现。
我的主要问题正在说明
为什么这些 typeof(TException) != exception.GetType()?分别地,我必须更改什么才能拥有正确的 TException 类型?
上面的代码导致 InvalidCast 异常,因为它试图转换为 IDocumedisExceptionHandler<DocumedisException>而不是IDocumedisExceptionHandler<FhirParsingException>
工厂实施:
internal class DocumedisExceptionHandlerFactory : IDocumedisExceptionHandlerFactory
{
private readonly IDictionary<Type, object> _exceptionHandlers = new ConcurrentDictionary<Type, object>();
public void RegisterExceptionHandler<TException>(IDocumedisExceptionHandler<TException> exceptionHandler)
where TException : DocumedisException
{
_exceptionHandlers.Add(typeof(TException), exceptionHandler);
}
public IDocumedisExceptionHandler<TException> GetDocumedisExceptionHandler<TException>(TException exception)
where TException : DocumedisException
{
_exceptionHandlers.TryGetValue(exception.GetType(), out var exceptionHandler);
return (IDocumedisExceptionHandler<TException>) exceptionHandler;
}
}
Run Code Online (Sandbox Code Playgroud)
附带问题:有没有比object用作字典值更好的方法?
在启动时注册处理程序:
var exceptionHandlerFactory = app.ApplicationServices.GetService<IDocumedisExceptionHandlerFactory>();
exceptionHandlerFactory.RegisterExceptionHandler(new FhirParsingExceptionHandler());
Run Code Online (Sandbox Code Playgroud)
哪里FhirParsingExceptionHandler实施IDocumedisExceptionHandler
internal class FhirParsingExceptionHandler : IDocumedisExceptionHandler<FhirParsingException>
{ …Run Code Online (Sandbox Code Playgroud) 我们希望由 Swashbuckle 生成的 SwaggerUI 在调试时以及我们的测试环境中显示所有控制器和方法,但在集成和生产环境中隐藏一些控制器和方法。请注意,隐藏的控制器/方法将在所有场景中发挥作用,但不会记录在 SwaggerUI 中。
为此,我应用了此处描述的原理。
结果如下代码:
属性定义:
using System;
using Microsoft.AspNetCore.Mvc;
namespace Test
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public class SwaggerUIVisibilityAttribute : ApiExplorerSettingsAttribute
{
public SwaggerUIVisibilityAttribute(SwaggerUIVisibility visibility)
{
Visibility = visibility;
}
public SwaggerUIVisibility Visibility { get; }
}
public enum SwaggerUIVisibility
{
Debug,
Internal,
Public
}
}
Run Code Online (Sandbox Code Playgroud)
过滤器(正在进行中):
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
namespace Test
{
public class SwaggerUIVisibilityFilter : IDocumentFilter
{
#region Private Fields
private …Run Code Online (Sandbox Code Playgroud) 我在设置模拟(使用最小起订量)时遇到问题。
我们有一个通用的存储库:
public class Repository<T> : IRepository<T>
where T : EntityBase
{
public Repository(DbSet<T> set)
{
Set = set;
}
[...]
}
Run Code Online (Sandbox Code Playgroud)
我想动态创建将由我们的 IRepositoryResolver 返回的存储库:
public interface IRepositoryResolver
{
TRepository Resolve<TRepository, TEntity>()
where TRepository : IRepository<TEntity>
where TEntity : EntityBase;
IRepository<TEntity> ResolveFor<TEntity>()
where TEntity : EntityBase;
IRepository<TEntity> ResolveFor<TEntity>(TEntity entity)
where TEntity : EntityBase;
}
Run Code Online (Sandbox Code Playgroud)
为此,我实现了这些模拟设置方法:
private void SetupRepositoryResolverMock()
{
var basisDataTypes = Assembly.GetAssembly(typeof(Basisdata))
.GetTypes()
.Where(p => p.IsClass && !p.IsAbstract
&& typeof(Basisdata).IsAssignableFrom(p))
.ToList();
Basisdata[] basisdataInstances = new Basisdata[basisDataTypes.Count];
for (int i …Run Code Online (Sandbox Code Playgroud) c# ×5
java ×4
asp.net-core ×2
generics ×2
casting ×1
filesystems ×1
flowlayout ×1
hl7-fhir ×1
jgoodies ×1
jvm ×1
memory ×1
moq ×1
nio ×1
resize ×1
swagger ×1
swashbuckle ×1
swing ×1
watch ×1
winforms ×1