小编Mar*_*bel的帖子

使用Moq来模拟构造函数?

我有这样一组构造函数:

public BusinessObjectContext()
         : this(CloudStorageAccount.FromConfigurationSetting("DataConnectionString").TableEndpoint.ToString(),
                CloudStorageAccount.FromConfigurationSetting("DataConnectionString").Credentials) {}

public BusinessObjectContext(string dataConnectionString)
         : this(CloudStorageAccount.Parse(dataConnectionString).TableEndpoint.ToString(),
                CloudStorageAccount.Parse(dataConnectionString).Credentials) { }

public BusinessObjectContext(String baseAddress, StorageCredentials credentials) 
         : base(baseAddress, credentials) { } 
Run Code Online (Sandbox Code Playgroud)

但是在测试/模拟时我需要没有任何连接字符串参数的对象.我怎么能这样做 - 最好是在Moq?

这有可能吗?

.net c# constructor unit-testing moq

23
推荐指数
2
解决办法
3万
查看次数

从CefSharp 1中的javascript调用.Net - wpf

我刚学习C#WPF并且已经成功实现了CefSharp,如何从javascript中调用.NET函数,这是在CefSharp中加载的?

javascript c# cefsharp

11
推荐指数
2
解决办法
2万
查看次数

如何在XML Schema中为fractionDigits限制指定最小值?

我有以下XML Schema:

<xsd:simpleType name="fractionalSalary">
    <xsd:restriction base="xsd:decimal">
        <xsd:fractionDigits value="2" />
        <xsd:minExclusive value="0" />
    </xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud)

有没有选项指定最小数量xsd:fractionDigits为2?因为我对薪水有下列限制:positive number with 2 decimal places precision, e.g. 10000.50和验证失败应该像输入1000.545214582.0001也对输入1000.510000.

PS:使用XML Schema 1.0

xml xsd xsd-1.0

7
推荐指数
1
解决办法
1万
查看次数

JavaFX 8对话框内部元素的本地化

我目前正在开发一个带有斯洛伐克语本地化的JavaFX应用程序,在应用程序内部,我正在使用一个Alert对话框来显示可扩展内容窗格的异常,如下图所示:

显示详细信息 - 警报屏幕 隐藏详细信息 - 警报屏幕

我想有这样的对话翻译完成其与进展顺利Header,TitleContent但我不能找到一种方法如何在翻译Show/Hide details的扩张区的标签.

所以我的问题可以有点概括:如何更改/翻译JavaFX内部元素的文本?

在此先感谢您的帮助.

PS:为了为异常创建此Alert对话框,我使用的代码在code.makery.ch找到

java localization javafx javafx-8

7
推荐指数
1
解决办法
1648
查看次数

从IDE加载.properties文件,也从JAR外部加载.properties文件

app.properties在我的maven项目下有一个文件,resources如下所示(简化):

myApp
  |----src
  |     |
  |     |--main
  |         |--java
  |         |    |--ApplicationInitializer.java
  |         |
  |         |--resources
  |              |--app.properties
  |
  |---target
        |--myApp.jar
        |--app.properties     

ApplicationInitializer类中,我想app.properties用以下代码从文件加载属性:

Properties props = new Properties();

String path = "/app.properties";

try {
    props.load(ApplicationInitializer.class.getResourceAsStream(path));
} catch (IOException e) {
    e.printStackTrace();
}

System.out.println(props.getProperty("property"));
Run Code Online (Sandbox Code Playgroud)

当我从IDE内部运行它时,这段代码正确地加载属性但是异常失败

Exception in thread "main" java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Properties.java:434)
    at java.util.Properties.load0(Properties.java:353)
    at java.util.Properties.load(Properties.java:341)
    at cz.muni.fi.fits.ApplicationInitializer.main(ApplicationInitializer.java:18)
Run Code Online (Sandbox Code Playgroud)

当试图作为JAR文件运行时.

用于创建我使用的组合的jar文件maven-shade-plugin,maven-jar-plugin(用于排除属性文件的JAR的外部)和maven-resources-plugin(用于复制属性文件来特定文件夹)在pom.xml如下所示的文件:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions> …
Run Code Online (Sandbox Code Playgroud)

java jar properties maven

5
推荐指数
1
解决办法
1545
查看次数

将 NuGet contentFiles 传递地复制到引用的项目

我有一个NuGet包中,被打包成一个额外的文件内容contentFiles文件夹。

然后,我有两个C#项目SDK风格的.csproj - A和B,其中项目B引用项目AProjectReference,有一个经典的PackageReference一个的NuGet包A计划是这样的:

NuGet 包?项目A?项目B

我的问题是额外的文件被正确复制到项目 A 的构建输出中,但除非我手动执行,否则它不会被复制到项目 B 的输出中。

有没有办法强制将额外文件从 NuGet 依赖项传递到项目 B 构建输出?

我能想到的唯一方法是使用命令自定义构建后事件xcopy但这更像是一种解决方法,而不是真正的解决方案。

感谢您提前提供任何建议!

.net c# nuget nuget-package

5
推荐指数
1
解决办法
273
查看次数

如何根据另一个JSON属性有条件地反序列化JSON对象?

假设我有以下模型类:

public class Action
{
    public enum Type
    {
        Open,
        Close,
        Remove,
        Delete,
        Reverse,
        Alert,
        ScaleInOut,
        Nothing
    }

    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("active")]
    [JsonConverter(typeof(IntToBoolConverter))]
    public bool Active { get; set; }

    [JsonProperty("type")]
    [JsonConverter(typeof(ActionTypeConverter))]
    public Type ActionType { get; set; }

    [JsonProperty("result")]
    [JsonConverter(typeof(ActionResultConverter))]
    public ActionResult Result { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想将JSON反序列化到该类中:

{
    "name":"test1",
    "id":"aa0832f0508bb580ce7f0506132c1c13",
    "active":"1",
    "type":"open",
    "result":{
        "property1":"buy",
        "property2":"123.123",
        "property3":"2016-07-16T23:00:00",
        "property4":"768",
        "property5":true
     }
}
Run Code Online (Sandbox Code Playgroud)

结果对象每次都可以不同(6个模型中的一个),其类型取决于JSON属性type.

我已经创建了自定义 …

c# json json.net

4
推荐指数
1
解决办法
3329
查看次数

Socket.IO - 如何在客户端上替换事件监听器

我想知道在Node.js的Socket.IO客户端库中是否有一个选项可以替换特定事件的侦听器函数.

我有这个简单的功能:

var Service = module.exports = function(address) {
    var _socket = require('socket.io-client')(address);

    this.connectAccount = function(account, callback) {
        _socket.on('account/connected', function (response) {
            callback(response.data, response.message);
        });

        _socket.emit('account/connect', account.getParameters());
    };
}
Run Code Online (Sandbox Code Playgroud)

问题是,当我connectAccount()多次调用函数时,我每次都会传递所有匿名函数on()函数get中也被调用,并且在短时间内达到限制并抛出错误.

所以我的问题是,是否有一种方法如何更换每次听众,所以每次只调用一次?

提前致谢.

javascript events node.js socket.io

3
推荐指数
1
解决办法
2659
查看次数

ExecutorService - 如何以非阻塞样式等待所有任务的完成

我使用ExecutorServiceJava的Web服务器应用程序的并行执行风格的一些计算任务,然后调用shutdown()awaitTermination()等待做的所有任务.整个计算有时可能需要几十分钟.

awaitTermination()方法是阻塞主线程,直到超时(或中断),但我只是想启动任务并立即响应客户端,并在所有任务竞争后关闭服务(遵循约定总是关闭线程池).

所以我的问题是,有什么方法可以在完成所有任务后通知我,以便我可以调用该shutdown()方法?听者还是什么..

谢谢!

java multithreading web-applications executorservice

1
推荐指数
1
解决办法
886
查看次数

使用线程管道通信

我有两个可执行文件:client.exeserver.exe.

它们通过使用命名管道相互通信.当服务器仅侦听客户端请求并向客户端发送响应时,它们可以正常工作.

但现在要求是exes包含客户端管道和服务器管道.所以每个exe包含两个方法:serverpipe()clientpipe().这些方法在一个线程中,不相互通信.

第一个客户端和服务器正常通信

Client.EXE:

public static void Main(string[] Args)
{
    PipeClient obj=new PipeClient();
    obj.client();
    Thread startserver = new Thread(new ThreadStart(obj.server));
    startserver.Start();
}

public void client()
{
    int cnt =0;
    while (true)
    {
       System.IO.Pipes.NamedPipeClientStream pipeClient = new System.IO.Pipes.NamedPipeClientStream(".", "\\\\.\\pipe\\SamplePipe1", System.IO.Pipes.PipeDirection.InOut, System.IO.Pipes.PipeOptions.None);

        if (pipeClient.IsConnected != true) { pipeClient.Connect(); }

        StreamReader sr = new StreamReader(pipeClient);
        StreamWriter sw = new StreamWriter(pipeClient);

        string temp;
        temp = sr.ReadLine();

        if (temp == "Waiting")
        {
            try
            { …
Run Code Online (Sandbox Code Playgroud)

c# ipc named-pipes

0
推荐指数
1
解决办法
4402
查看次数