小编Geo*_*vos的帖子

SignalR java无法连接到服务器

我将我的java应用程序连接到SignalR Server时遇到问题.
服务器非常简单,可以在这里找到:https:
//code.msdn.microsoft.com/windowsdesktop/Using-SignalR-in-WinForms-f1ec847b

我可以连接Web客户端(javascript)Windows客户端(C#)但我的java客户端有问题.(https://github.com/SignalR/java-client)

到目前为止,这是我的代码:

package javaapplication2;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import microsoft.aspnet.signalr.client.SignalRFuture;
import microsoft.aspnet.signalr.client.hubs.HubConnection;
import microsoft.aspnet.signalr.client.hubs.HubProxy;

public class JavaApplication2 {
       public static void main(String[] args) throws IOException, InterruptedException, ExecutionException, TimeoutException 
       {
            String ServerURI = "http://localhost:8080/signalr";
            HubConnection Connection = new HubConnection(ServerURI);
            HubProxy HubProxy = Connection.createHubProxy("MyHub");
            HubProxy.on("AddMessage", () -> { System.out.println("Some message");        });

            Connection.error(new ErrorCallback() {
                @Override
                public void onError(Throwable error) {
                    error.printStackTrace(); //<==SocketException
                }
            });

            SignalRFuture<Void> con  =Connection.start();
            con.get(); …
Run Code Online (Sandbox Code Playgroud)

java signalr signalr.client

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

如何在没有互操作程序集的情况下将任何文件类型嵌入到Microsoft Word中

我正在尝试这样做如何使用OpenXml 2.0将任何文件类型嵌入到Microsoft Word中

但只使用OpenXml SDK 2.5(没有互操作程序集)

我可以嵌入其他文字(或办公室)使用下面的代码示例从文件在这里
(我们需要参考的的NuGet和WindowsBase添加到DocumentFormat.OpenXml)

但我无法重构它以接受任何文件类型(pdf,mp3等)

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
using v = DocumentFormat.OpenXml.Vml;
using ovml = DocumentFormat.OpenXml.Vml.Office;
using System.IO;

class Program
{

    static void Main(string[] args)
    {
        //Just update the following 2 variables to point to existng files
        string containingDocumentPath = @"C:\Temp\Word\ContainingDocument.docx";
        string embeddedDocumentPath = @"C:\Temp\Word\EmbeddedDocument.docx";
        CreatePackage(containingDocumentPath, embeddedDocumentPath);
    }

    private static void CreatePackage(string containingDocumentPath, string embeddedDocumentPath)
    {
        using (WordprocessingDocument package = WordprocessingDocument.Create(containingDocumentPath, WordprocessingDocumentType.Document))
        {
            AddParts(package, embeddedDocumentPath);
        }
    }

    private static void AddParts(WordprocessingDocument …
Run Code Online (Sandbox Code Playgroud)

.net c# openxml-sdk

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

"查看详细信息"窗口不会展开"收集

我对visual studio有一个小问题.我有一个抛出CustomException的方法

如果我在try/catch中包装调用此方法的代码,我可以在调试器中看到异常详细信息

在此输入图像描述

如果我删除try/catch我可以看到"errors"属性有Count = 4但是我看不到错误...

在此输入图像描述

这是预期的还是一个错误?
我正在使用vs2015 enterprise和.NET 4.5.2

您可以轻松地重现它:
1)使用它创建一个类库

using System;
using System.Collections.Generic;
using System.Linq;

namespace ClassLibrary1
{
    public static class Class1
    {
        public static void DoSomethingThatThrowsException()
        {
            throw new MyException(Enumerable.Range(1, 4).Select(e => new MyError() { Message = "error " + e.ToString() }).ToList());
       }
    }

    public class MyException : Exception
    {
        public IEnumerable<MyError> errors { get; set; }
        public MyException(IEnumerable<MyError> theErrors) { errors = theErrors; }
    }
    public class MyError { public string Message { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# visual-studio visual-studio-debugging

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

OpenXml Force图像适合父容器

我正在使用以下代码将一段hmtl解析为word文档

//Need the following packages
//<package id="DocumentFormat.OpenXml" version="2.7.2" targetFramework="net471" />
//<package id = "HtmlToOpenXml.dll" version="2.0.1" targetFramework="net471" />

using System.Linq;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;

using DocumentFormat.OpenXml.Wordprocessing;
using HtmlToOpenXml;

namespace ConsoleAppHtmlParse
{
    class Program
    {
        static void Main(string[] args)
        {
            string fileName = @"C:\temp\myDoc.docx";

            using (WordprocessingDocument document = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document))
            {
                document.AddMainDocumentPart();
                document.MainDocumentPart.Document = new Document(new Body());
                HtmlConverter conveter = new HtmlConverter(document.MainDocumentPart);

                var compositeElements = conveter.Parse(Html);

                Paragraph p = compositeElements[0] as Paragraph;
                p.ParagraphProperties = new ParagraphProperties();
                p.ParagraphProperties.FrameProperties = new FrameProperties();
                p.ParagraphProperties.FrameProperties.Width = …
Run Code Online (Sandbox Code Playgroud)

c# ms-word openxml openxml-sdk

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

如果至少有一个Source不可用,则无法安装任何NuGet包

VS2013(Premium)中不存在以下问题,我只能在VS2015(企业版)中重现它

我添加了一个自定义的NuGet包源.如果该源不可用我无法安装任何包(例如EntityFramework)

我收到一条消息

尝试针对项目"ConsoleApplication9"收集程序包"EntityFramework.6.1.3"的依赖关系信息,目标是".NETFramework,Version = v4.5.2"

尝试添加源' http://XXX/FeedService.svc/ ' 时抛出Exception'System.AggregateException .

请验证您的所有在线包源均可用.

从消息的最后一行我认为这不是一个错误,但正如我所说,它适用于VS2013

知道为什么会改变这个吗?
我可以对此做些什么吗?

visual-studio nuget visual-studio-2015

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

序列不包含任何元素

有人可以解释为什么以下LINQ查询抛出InvalidOperationException?
(不要说列表中没有元素,我正在寻找的值总是存在于集合中)

class Program
{
     static int lastNumber;
     static void Main()
     {
          int loopCount = 100; int minValue = 1; int maxValue = 10000;
          var numbers = Enumerable.Range(minValue, maxValue).ToList();//or ToArray();
          Random random = new Random();

          for (int i = 0; i < loopCount; i++)
          {
              //.First() throws the exception but it is obvious that the value exists in the list
              int x = numbers.Where(v => v == NewMethod(minValue, maxValue, random)).First();
          }
          Console.WriteLine("Finished");
          Console.ReadLine();

     }

     private static int NewMethod(int minValue, int …
Run Code Online (Sandbox Code Playgroud)

c# linq random

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

IIS 7.5应用程序初始化1无法安装

我正在使用Web平台安装程序来安装"应用程序初始化1",但我得到一般的"安装期间的致命错误"消息.

在日志文件中我看到:

MSI (s) (9C:24) [14:04:47:315]: Executing op: ActionStart(Name=ExecuteInstallWindowsHotfix,,)
1: IISCA IISExecuteCA : End CA Setup 
MSI (s) (9C:24) [14:04:47:315]: Executing op: CustomActionSchedule(Action=ExecuteInstallWindowsHotfix,
              \Users\GEORGE~1.VOV\AppData\Local\Temp\\HotfixPipeLine{3E0FEF42-B34C-40FE-8387-2EE0F22CE1A6}.msu^)
MSI (s) (9C:A4) [14:04:47:325]: Invoking remote custom action. D
         LL: C:\Windows\Installer\MSI5385.tmp, Entrypoint: ExecuteInstallWindowsHotfixCA
1: IISCA ExecuteInstallWindowsHotfixCA : Begin CA Setup 
1: IISCA ExecuteInstallWindowsHotfixCA : Launching process with command line C:\Windows\system32\wusa.exe 
        /quiet /norestart "C:\Users\GEORGE~1.VOV\AppData\Local\Temp\\HotfixPipeLine{3E0FEF42-B34C-40FE-8387-2EE0F22CE1A6}.msu" 
1: IISCA ExecuteInstallWindowsHotfixCA : Process returned with exit code -2145124329 
1: IISCA ExecuteInstallWindowsHotfixCA : Error in function InstallWindowsHotfixQuietly, hr=0x80070643 


1: IISCA ExecuteInstallWindowsHotfixCA : …
Run Code Online (Sandbox Code Playgroud)

iis failed-installation iis-7.5

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

StringEnumConverter无效的int值

我有一个带有POST方法的简单Controller。
我的模型具有枚举类型的属性。
当我发送有效值时,一切正常

{  "MyProperty": "Option2"}
Run Code Online (Sandbox Code Playgroud)

要么

{  "MyProperty": 2}
Run Code Online (Sandbox Code Playgroud)

如果我发送无效的字符串

{  "MyProperty": "Option15"}
Run Code Online (Sandbox Code Playgroud)

它正确获取默认值(Option1),但是如果我发送无效的int,它将保留无效值

{  "MyProperty": 15}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我可以避免这种情况并获得默认值还是抛出错误?

谢谢

public class ValuesController : ApiController
{
    [HttpPost]
    public void Post(MyModel value) {}
}

public class MyModel
{
    [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
    public MyEnum MyProperty { get; set; }
}

public enum MyEnum
{
    Option1 = 0,
    Option2,
    Option3
}
Run Code Online (Sandbox Code Playgroud)

更新
我知道我可以将任何int强制转换为枚举,这不是问题。
@AakashM的建议解决了我一半的问题,我不知道AllowIntegerValues

现在我在发布无效的int时正确地收到错误

{  "MyProperty": 15} 
Run Code Online (Sandbox Code Playgroud)

现在唯一有问题的情况是当我发布一个数字字符串时(这很奇怪,因为当我发送无效的非数字字符串时,它正确地失败了)

{  "MyProperty": "15"}
Run Code Online (Sandbox Code Playgroud)

c# json.net asp.net-web-api

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