小编adv*_*api的帖子

'ColorAnimation' 动画对象不能用于为属性 'Background' 设置动画,因为它是不兼容的类型 'System.Windows.Media.Brush'

我想以编程方式使用 ColorAnimation 来为单元格设置动画,但是我在执行时得到了这个 storyboard.Begin()

'System.Windows.Media.Animation.ColorAnimation' animation object cannot be used to animate property 'Background' because it is of incompatible type 'System.Windows.Media.Brush'.
Run Code Online (Sandbox Code Playgroud)

我已经定义了我ColorAnimation

var storyBoard = new  Storyboard();
ColorAnimation colorAnimation = new ColorAnimation
{
    From = Colors.Red,
    To = Colors.CornflowerBlue,
    Duration = TimeSpan.FromSeconds(1),
    FillBehavior = FillBehavior.Stop
};
Run Code Online (Sandbox Code Playgroud)

和它的用法我做

if (column.UniqueName != "_ID")
{
    var animation = animationMapping[column.UniqueName].Animation;
    var storyboard = animationMapping[column.UniqueName].Storyboard;

    Storyboard.SetTarget(animation, cell.Content as TextBlock);
    //Storyboard.SetTargetProperty(animation,
    //    new PropertyPath((TextBlock.Foreground).Color"));

    PropertyPath colorTargetPath = new PropertyPath(TextBlock.BackgroundProperty);
    Storyboard.SetTargetProperty(animation, colorTargetPath);

    storyboard.Begin();
}
Run Code Online (Sandbox Code Playgroud)

我必须将什么参数传递给新的 …

c# wpf wpf-animation

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

使用 HTTPCLient 下载文件时减少内存占用

我想知道是否有一种方法可以避免获取所有缓冲区,然后使用 HttpClient 和 File.WriteAllBytes 将它们写入文件。

这是我使用的代码片段

public async Task<byte[]> DownloadAsByteArray(string filename)
{
    _logger.LogDebug($"Start downloading {filename} file at {DateTime.Now}");
    
    var result = await _httpClient.GetByteArrayAsync(filename);
    
    return result;
}
Run Code Online (Sandbox Code Playgroud)
var bytes = await _downloadFileService.DownloadAsByteArray(fileDownload);

await File.WriteAllBytesAsync(fullFlePathName, bytes);
Run Code Online (Sandbox Code Playgroud)

对于相当大的文件,应用程序内存增长得非常快。

.net c# stream async-await dotnet-httpclient

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

异步操作和UI更新

在使用caliburn micro和telerik控件制作的wpf应用程序中,我有不同的屏幕,从远程服务加载数据,然后在gridview /填充组合框中显示数据.我正在使用sync/await运算符来进行负载检索操作,但我几乎可以肯定它有一些瓶颈.等待我有主UI线程等待与工作线程同步...考虑这个示例

Public class MyViewModel:Screen
{
  [omiss]

Public bool IsBusy {get;set;}  
 Public list<Foo> DropDownItems1 {get;set;}
Public  list<Foo2> DropDownItems2 {get;set;}

  Public async Void Load()
  {
    IsBusy =true;
     DropDownItems1 = await repository.LoadStates();
     DropDownItems2 = await repository.LoadInstitutes();
     IsBusy = false;
  }

}
Run Code Online (Sandbox Code Playgroud)

在那种情况下,我首先加载任务然后加载第二个没有并行性...我该如何优化它?关于我的IsBusy属性,它通过约定绑定到繁忙指示器,如何正确设置?谢谢

更新#1:

我是真正的代码

public async Task InitCacheDataTables()
    {
        var taskPortolio = GetPortfolio();
        var taskInstitutes = GetInstitutes();
        var taskStatus = GetStatus();
        var taskCounterparts = GetCounterparts();
        var taskCrosses = GetCrosses();
        var taskCurrencies = GetCurrencies();
        var taskSigns = GetSigns();

        await TaskEx.WhenAll(new[] { taskPortolio, …
Run Code Online (Sandbox Code Playgroud)

c# wpf multithreading caliburn.micro async-await

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

RabbitMq以异步方式处理收到的消息

RabbitMq用来处理我在公共汽车上收到的消息。我想知道是否有更好的方法来处理我收到的消息(也许使用async/await模式)

这是我的代码片段

connection = connectionFactory.CreateConnection();

channel = connection.CreateModel();

channel.QueueDeclare(queue: Constants.RabbitListeningQueue,durable: false,exclusive: false,autoDelete: false,arguments: null);
channel.QueueDeclare(queue: Constants.RabbitMqRequestInsertedQueue,durable: false,exclusive: false,autoDelete: false,arguments: null);

var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
    log.Debug($"[x] Received message :{ea}");
    var body = ea.Body;
    var message = Encoding.UTF8.GetString(body);

    var dynamicObject = JObject.Parse(message);

    queueMessageHandler.HandleMessage(dynamicObject);
};
Run Code Online (Sandbox Code Playgroud)

queueMessageHandler实现如下

public class QueueMessageHandler : IQueueMessageHandler
{
    private readonly IImportNucleoManager importNucleoManager;

    public QueueMessageHandler(IImportNucleoManager importNucleoManager)
    {
        this.importNucleoManager = importNucleoManager;
    }

    public void HandleMessage(dynamic message)
    {
        switch …
Run Code Online (Sandbox Code Playgroud)

c# task rabbitmq async-await

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

从 .NET Core 应用程序使用 IBMMQ amqmdnet.dll

我使用最新的 IBM amqmdnet.dll 程序集 9.1.3 开发了一个库

当我运行 .NET Core 控制台应用程序 (2.2) 时,出现以下异常

TypeLoadException: Could not load type 'System.Web.Configuration.WebConfigurationManager' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

我用 dotPeek 反汇编了文件,它引用了 System.Web

在此处输入图片说明

站在文档上,它支持 .NET Core。我创建的程序集是一个标准的 .NET 类库,当被 .NET Full Framework 控制台应用程序引用时,它可以工作。

有什么建议吗?谢谢

c# ibm-mq

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

遍历带有子节点的IEnumerable <T>以查找特定条目

在mvc应用程序中,我有一个由以下结构组成的菜单

public class MenuItem
{
    public string Action {get;set;}
    public string Controller {get;set;}
    public string Text {get;set;}
    public List<MenuItem> Children {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

考虑一个简单的compisition

Root
\-Item1
\-Item2
  \-Item2_1
  \-Item2_2
    \-Item_2_2_1
    \-Item_2_2_2
\-Item3
Run Code Online (Sandbox Code Playgroud)

我想获取项目Item_2_2_2(认为它有Action ="Index",Controller ="ABC")

我如何编写一个函数(或更好的T的扩展方法)来迭代收集并获得与该条件匹配的项目?

谢谢

c#

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

简单的注射器追踪时间

有没有办法可以跟踪通过Simple Injector和Constructor的IoC解析实例需要多长时间?

我的意思是跟踪级别的东西

谢谢

c# dependency-injection ioc-container simple-injector

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

转换为base64会添加返回字符

我正在尝试将字典转换为字符串结尾,然后将其转换为Base64,以便将其保存到另一个字符串.

这是我的代码

public class StringBase64Helper
{
    public static string Base64Encode(string plainText)
    {
        var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
        return Convert.ToBase64String(plainTextBytes, Base64FormattingOptions.InsertLineBreaks);
    }

    public static string Base64Decode(string base64EncodedData)
    {
        var base64EncodedBytes = Convert.FromBase64String(base64EncodedData);
        return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
    }
}
Run Code Online (Sandbox Code Playgroud)

我使用servicestack来序列化它

var dictionary = new Dictionary<string,object>();

dictionary.Add("VM","XX.XXXXXXXXX.Client.WPF.ViewModels.PortfolioManager");

var rr =ServiceStack.Text.JsonSerializer.SerializeToString(dictionary);

var str = StringBase64Helper.Base64Encode(rr);
Run Code Online (Sandbox Code Playgroud)

输出我是

eyJWTSI6IlhYLlhYWFhYWFhYWC5DbGllbnQuV1BGLlZpZXdNb2RlbHMuUG9ydGZvbGlvTWFuYWdl
ciJ9
Run Code Online (Sandbox Code Playgroud)

请注意,c1J9是一个新行,因为它在将字符串存储在我的主文件中时放置了字符.

来自Serializer的json是"{"VM":"XX.XXXXXXXXX.Client.WPF.ViewModels.PortfolioManager"}"

当我解码我得到的字符串

{"VM":"XX.XXXXXXXXX.Client.WPF.ViewModels.PortfolioManage
Run Code Online (Sandbox Code Playgroud)

在我获得新线之后

r"}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

c# serialization

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

Publish a .NET Core Console application with right transformation settings

I'm quite new to .NET Core application, and I was wondering if there's a simple way to deploy the right application.json based on the profile. In .NET Standard application it was quite simple since we have web.config transformation/Slowcheeta but It doesn't seems to work with .NET Core Console app.

I've also read online that with ASP.NET Core application, we can use

var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) <--this
.AddEnvironmentVariables();
Configuration = …
Run Code Online (Sandbox Code Playgroud)

c# .net-core

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

MQQueueManager消息池

我过去使用RabbitMq作为MessageQueue,在收到消息时触发事件真的很简单。

我查看了IBM安装程序随附的.NET源,但是发现一种不好的方法来处理它。查看示例SimpleSubscribe可以完成这样的工作

// getting messages continuously
for (int i = 1; i <= numberOfMsgs; i++)
{
    // creating a message object
    message = new MQMessage();

    try
    {
        topic.Get(message);
        Console.WriteLine("Message " + i + " got = " + message.ReadString(message.MessageLength));
        message.ClearMessage();
    }
    catch (MQException mqe)
    {
        if (mqe.ReasonCode == 2033)
        {
            ++time;
            --i;
            Console.WriteLine("No message available");
            Thread.Sleep(1000);
            //waiting for 10sec
            if (time > 10)
            {
                Console.WriteLine("Timeout : No message available");
                break;
            }
            continue;
        }
        else
        {
            Console.WriteLine("MQException caught: {0} - {1}", …
Run Code Online (Sandbox Code Playgroud)

.net c# ibm-mq

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

Linq2DB 并插入具有标识的新项目

我已将旧代码部分从 EF 移至 linq2db,当我必须添加一个具有内部元素引用的标识的新项目时,我必须执行以下代码

     if (axAnag == null)
     {
                    axAnag = new DataModels.AX();
                    var idAnag= context.InsertWithInt32Identity(axAnag);

                    axAnag.IdAnagrafica = idAnag;
     }
Run Code Online (Sandbox Code Playgroud)

和下面的代码

        fk.AxAnagraficaAssicurati = axAnag;
        fk.StatusProtocollo = statusProtocollo;
        fk.DataEsclusione = newAnagrafica.DataEsclusione ?? condizione.DataAnnullamento;
        fk.DataInclusione = newAnagrafica.DataInclusione;
        fk.DerogaEta = newAnagrafica.DerogaEta;
        fk.ProgrCategoria = condizione.ProgessivoCategoria;
        fk.IdCondizione = condizione.Id;
        fk.IdCategoria = condizione.IdCategoria;
        fk.DataOperazioneInclusione = DateTime.Now;
        fk.HYPER = newAnagrafica.HyperService;
        //GPA ticket  2017-0017962
        fk.LimiteEtaSuperato = newAnagrafica.IsLimiteEtaSuperato;
        //GPA cr24
        fk.FlagConteggioRegolazionePremio = newAnagrafica.FlagConteggioRegolazionePremio;
        fk.IdAnagrafica = axAnag.IdAnagrafica;
Run Code Online (Sandbox Code Playgroud)

我不太清楚的是为什么我必须添加 id 和整个引用的项目?

fk.AxAnagraficaAssicurati = axAnag;
fk.IdAnagrafica = axAnag.IdAnagrafica;
Run Code Online (Sandbox Code Playgroud)

在脚手架模型中,我

    [Association(ThisKey = "IdAnagrafica", …
Run Code Online (Sandbox Code Playgroud)

linq2db

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

避免通过依赖注入注册每一个服务

我有一个应用程序,其中有很多通过 DI 注册的服务,我想知道是否有以这种方式注册的最佳方法

      services.AddScoped<IDestinationService, DestinationService>();
        services.AddScoped<IAttractionService, AttractionService>();
        services.AddScoped<ICartService, CartService>();
        services.AddScoped<IPersonalService, PersonalService>();
        services.AddScoped<IUserService, UserService>();
        services.AddScoped<IEncryptionHelper, EncryptionHelper>();
        services.AddScoped<IAddressService, AddressService>();
        services.AddScoped<IUserRegistrationService, UserRegistrationService>();
        services.AddScoped<IUserRoleService, UserRoleService>();
        services.AddScoped<IEmailSender, EmailSender>();
        services.AddScoped<IUserRolesService, UserRolesService>();
        services.AddScoped<IProductAvailabilityService, ProductAvailabilityService>();
Run Code Online (Sandbox Code Playgroud)

我想过创建一个属性并将其放入类中,但我不知道这是否是一个好的做法..有什么建议吗?

.net c# dependency-injection

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

在ASP.Net应用程序中引用.NET标准库

我有一个引用网络标准应用程序的奇怪问题(FW Full 4.5.2)

我收到此错误targets 'netstandard2.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.5.2'.,是不是.NET标准应该允许来自Core和Framework项目的引用?

c# .net-4.5 .net-standard

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