小编Chr*_*emm的帖子

在.NET中使用Firebase

我想在我的.NET WPF桌面应用程序中实现Firebase.我在互联网上找不到有关这个主题的任何有用信息,似乎它完全不受支持.只有一个Xamarin NuGet包.有没有可能这样做?目标是为用户在应用程序中执行的多项操作实施Firebas Analytics.如果我能找到它们,我甚至会采用正常的REST端点 - 它们隐藏在某个地方......

.net c# firebase firebase-analytics

19
推荐指数
3
解决办法
5万
查看次数

在.NET 4.5.2中引用.NET Core库

是否可以在.NET 4.5.2项目中引用.NET Core库?我正在使用最新的.NET Core,并希望为我的WPF项目和我的.NET Core Web API使用相同的库.如果我想添加对项目的引用,则会显示以下窗口:

在此输入图像描述

我还尝试将我的WPF项目升级到4.6.1但这并没有改变任何东西.

更新
现在可以使用Core 2.0

.net .net-core

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

C#WebClient - 下载文件后LOH大幅增加

我有一个班负责在下载管理器中下载文件.该类负责下载文件并将其写入给定路径.

要下载的文件大小通常在1到5 MB之间变化,但也可能更大.我正在使用WebClient类的实例从Internet获取文件.

public class DownloadItem
{
    #region Events
    public delegate void DownloadItemDownloadCompletedEventHandler(object sender, DownloadCompletedEventArgs args);

    public event DownloadItemDownloadCompletedEventHandler DownloadItemDownloadCompleted;

    protected virtual void OnDownloadItemDownloadCompleted(DownloadCompletedEventArgs e)
    {
        DownloadItemDownloadCompleted?.Invoke(this, e);
    }

    public delegate void DownloadItemDownloadProgressChangedEventHandler(object sender, DownloadProgressChangedEventArgs args);

    public event DownloadItemDownloadProgressChangedEventHandler DownloadItemDownloadProgressChanged;

    protected virtual void OnDownloadItemDownloadProgressChanged(DownloadProgressChangedEventArgs e)
    {
        DownloadItemDownloadProgressChanged?.Invoke(this, e);
    }
    #endregion

    #region Fields
    private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
    private WebClient _client;
    #endregion

    #region Properties
    public PlaylistItem Item { get; }
    public string SavePath { get; }
    public bool Overwrite …
Run Code Online (Sandbox Code Playgroud)

c# memory garbage-collection memory-leaks webclient

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

WebSocket安全连接自签名证书

目标是一个Web应用程序,它与安装在用户PC上的C#应用​​程序交换信息.客户端应用程序是websocket服务器,浏览器是websocket客户端.

最后,用户浏览器中的websocket客户端通过Angular持久创建,应用程序在PC上运行并执行某些操作.

使用的C#库是WebSocket-Sharp.websocket客户端是普通的javascript.

显然,此连接仅在本地发生,因此客户端连接到localhost.由于网站是通过HTTPS保护的,因此websocket也必须得到保护.为此,C#应用程序在启动时创建证书(实际上仅用于测试目的).

连接不起作用,因为证书不受信任.禁用客户端的所有服务器检查,但不建立连接.

这是创建服务器的部分

_server = new WebSocketServer($"wss://localhost:4649")
{
    SslConfiguration =
    {
        ServerCertificate = Utils.Certificate.CreateSelfSignedCert(),
        ClientCertificateRequired = false,
        CheckCertificateRevocation = false,
        ClientCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
    }
};
_server.AddWebSocketService<CommandsBehaviour>("/commands");
_server.AddWebSocketService<NotificationsBehaviour>("/notifications");

_server.Start();
Run Code Online (Sandbox Code Playgroud)

这是使用BouncyCastle创建证书的方式

private static AsymmetricKeyParameter CreatePrivateKey(string subjectName = "CN=root")
{
    const int keyStrength = 2048;

    // Generating Random Numbers
    var randomGenerator = new CryptoApiRandomGenerator();
    var random = new SecureRandom(randomGenerator);

    // The Certificate Generator
    var certificateGenerator = new X509V3CertificateGenerator();

    // Serial Number
    var serialNumber …
Run Code Online (Sandbox Code Playgroud)

c# websocket websocket-sharp

7
推荐指数
2
解决办法
4135
查看次数

将数据从Guard传递给组件

我的子路由组件正在查询API中的一些数据.目前我正在检查组件,如果通过检查API返回的数据,作为路由参数提供的id是有效的.

我认为这是一种糟糕的风格,并希望将检查放入一个警卫,在组件被激活之前检查提供的参数是否有效.

但是,我也想节省时间和资源.这将需要两个API请求.因此,我想知道是否有可能将数据从防护装置传递给组件.我想过传递路线参数,但canActivate只提供一个ActivatedRouteSnapshot只读的.

因此我的问题是:是否可以将数据从防护组件传递到组件?或者在这种情况下是否有另一种(甚至更好的)方法来节省资源并防止多个API请求?

canactivate angular

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

输入字符串不是有效数字 - JSON 反序列化

我有这个数组:

{
    "AssemblyVersion":"0.1.333.5973",
    "Exception":
    {
        // [...]
    }
}
Run Code Online (Sandbox Code Playgroud)

它是从此类序列化的:

public class ErrorData
{
    public string AssemblyVersion { get; private set; }
    public Exception Exception { get; private set; }

    public ErrorData(string assemblyVersion, Exception ex)
    {
        AssemblyVersion = assemblyVersion;
        Exception = ex;
    }

    public override string ToString()
    {
        return JsonConvert.SerializeObject(this);
    }
}
Run Code Online (Sandbox Code Playgroud)

将其序列化回对象会产生以下异常:

Newtonsoft.Json.JsonReaderException: Input string '0.1.335.5973' is not a valid number. Path 'AssemblyVersion', line 1, position 29.
    at Newtonsoft.Json.JsonTextReader.ParseNumber(ReadType readType)
    at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)
    at Newtonsoft.Json.JsonTextReader.ReadAsString()
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract …
Run Code Online (Sandbox Code Playgroud)

c# json.net

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

如何将图标放入按钮(MahApps)

我想将MahApps库中的图标放入普通按钮.我这样试过:

<Button Height="20" Width="25" Background="Transparent" Foreground="White" Content="{StaticResource appbar_close}"/>
Run Code Online (Sandbox Code Playgroud)

结尾如下:

那么如何在适当的位置将此图标集成到此按钮中?

wpf mahapps.metro

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

构建错误:无法解析参考PresentationCore

我有一个托管在 GitHub 上并附加到 Travis 的 WPF C# 应用程序。我这样配置我的 .travis-ci.yml :

language: csharp
solution: FaceDetection/FaceDetection.sln

script:
    - xbuild /p:Configuration=Debug /p:Platform=x86 /p:TargetFrameworkVersion="v4.0" FaceDetection/FaceDetection.sln
Run Code Online (Sandbox Code Playgroud)

但是,当 travis 即将编译该项目时,我收到这些错误:

/usr/lib/mono/4.5/Microsoft.Common.targets:  warning : Reference 'PresentationCore' not resolved
/usr/lib/mono/4.5/Microsoft.Common.targets:  warning : Reference 'PresentationFramework' not resolved
Run Code Online (Sandbox Code Playgroud)

在我的 Windows 机器上的 VS 本地编译项目工作正常。因此,我包含了该项目所需的所有参考资料。

这也发生在其他一些参考文献上:

Views/Converters/BitmapConverter.cs(5,28): error CS0234: The type or namespace name `Imaging' does not exist in the namespace `System.Windows.Media'. Are you missing an assembly reference?
Views/UserControls/FaceDatabaseEntry.xaml.cs(7,22): error CS0234: The type or namespace name `Controls' does not exist in the …
Run Code Online (Sandbox Code Playgroud)

c# msbuild wpf travis-ci

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

获取引用项目的程序集名称

假设我有项目A和项目B。在相同的解决方案中有它们,并且A引用B并将B用作一种从属进程。我不想对B的程序集名称进行硬编码,但我想知道如何在项目A中查询程序集名称,以便可以执行项目B的程序集。

c# reference assembly-name

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