作为一名C#开发人员,在尝试创建基于T-SQL的纯解决方案时遇到一系列日期范围涉及总结日/月的问题时,我正在摸不着头脑.
我有一组数据看起来像这样:
UserID Department StartDate EndDate
====== ========== ========== ==========
1 A 2011-01-02 2011-01-05
1 A 2011-01-20 2011-01-25
1 A 2011-02-25 2011-03-05
1 B 2011-01-21 2011-01-22
2 A 2011-01-01 2011-01-20
3 C 2011-01-01 2011-02-03
Run Code Online (Sandbox Code Playgroud)
日期范围不重叠,可能跨越几个月,特定用户和部门可能在一个月内存在多个范围.我想要做的是总结每个用户,部门,年和月的天数(包括),像这样(在我的例子中保留任何数学错误......):
UserID Department Year Month Days
====== ========== ==== ===== ====
1 A 2011 01 10
1 A 2011 02 4
1 A 2011 03 5
1 B 2011 01 2
2 A 2011 01 20
3 C 2011 01 31
3 C 2011 02 3 …Run Code Online (Sandbox Code Playgroud) 经过一些阅读,我收集.NET Remoting是一个已弃用的API,已被WCF取代.
我正在编写一个自动化框架,并希望在本地或某些远程机器上引用类型/方法的DLL,并执行它们而不考虑它们执行的位置.
我认为Remoting是要走的路,因为我猜所有功能都是在代理对象上执行的,如果它是本地对象或远程,则无关紧要.
WCF如何执行这种操作(如果有的话)或.NET Remoting是要走的路?
或许还有其他一些我没有想到的选择?
我正在编写ac #project,我正在尝试反序列化具有int []类型字段的对象,并且我想以另一种方式进行反序列化.
说我有一节课:
class Player
{
public string Name;
public int[] Spells;
}
Run Code Online (Sandbox Code Playgroud)
和一个xml文件,我从中反序列化类Player的实例:
<Player>
<Name>John</Name>
<Spells>
<int>1</int>
<int>5</int>
<int>9</int>
</Spells>
</Player>
Run Code Online (Sandbox Code Playgroud)
问题是我不希望xml文件看起来像那样,我希望它更像这样:
<Player>
<Name>John</Name>
<Spells>1 5 9</Spells>
</Player>
Run Code Online (Sandbox Code Playgroud)
我正在使用XmlSerializer,它只在第一个xml读取表单时才反序化字段Spells.我想知道它是否像一个简单字段一样反序列化一个int数组.
我们正在使用protobuf-net来处理 C# 应用程序中的协议缓冲区需求。由于我们与其他非托管应用程序共享我们的 .proto 文件,我们从 .proto 文件生成我们的代码(不使用代码优先的 protobuf-net 方法)。为了尽可能保持DRY,我们在 .proto 文件中保留了大量接口文档。我们通过项目构建目标调用的 protogen.exe 生成 C# 代码。
现在,有没有办法(自动)将这些注释传输到已编译的 C# 代码中?
基本上,给定这样的 .proto:
// This message is used to request a resource from the server
message GetResource
{
// The identifier of the requested resource
required string resourceId = 1;
}
Run Code Online (Sandbox Code Playgroud)
...我想要这样的东西(为了可读性省略了 IExtensible 方法):
/// <summary>
/// This message is used to request a resource from the server
/// </summary>
[global::System.Serializable,global::ProtoBuf.ProtoContract(Name=@"GetResource")]
public partial class GetResource : global::ProtoBuf.IExtensible
{
public …Run Code Online (Sandbox Code Playgroud) .net c# documentation-generation protocol-buffers protobuf-net
我搜索了更改我们使用的ListView的标题颜色:
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Pink, e.Bounds);
e.DrawText();
}
Run Code Online (Sandbox Code Playgroud)
我们使用相同的事件来更改ListView的标题样式:
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
e.DrawBackground();
using (Font headerFont =
new Font("Microsoft Sans Serif", 9, FontStyle.Bold)) //Font size!!!!
{
e.Graphics.DrawString(e.Header.Text, headerFont,
Brushes.Black, e.Bounds, sf);
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是我想要改变标题颜色和标题样式.所以我这样写:
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Pink, e.Bounds);
e.DrawText();
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
e.DrawBackground();
using (Font headerFont =
new Font("Microsoft …Run Code Online (Sandbox Code Playgroud) 我试图在命令行应用程序中取消通过共享HttpClient使用完整框架、.net 4.7.1、C# 7.3、VS 2017 发出的多个异步 Web 请求 (GET)。CancellationTokens
我的示例运行几个并行任务,每个任务都使用异步不断通过 Http 下载一些数据,GetAsync()但ReadAsStringAsync()使用 example 得到相同的结果ReadAsByteArrayAsync()。
终止是通过挂接Console.CancelKeyPress并取消我的CancellationTokenSource.
尽管由于某种原因这看起来很简单,但我无法理解它并想出一个产生可靠结果的解决方案。有时,一切都会按预期关闭,即所有任务都完成(取消),但更常见的是,不关闭只是看似挂起。在不使用调试器(带/不带 DEBUG)的情况下运行会终止应用程序,但不会以我预期的方式终止。任务越少意味着干净关闭的可能性越大。
当处于“挂起”状态时暂停调试中的所有线程似乎表明某些线程被卡住GetAsync(),但很难准确地看到发生了什么。
实际上,应用程序如何退出并不重要,但我想了解这一点,并能够一致地产生干净且受控的关闭,对我来说,使用这种构造似乎是可能的,但我很可能错过了一些细节。
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace HttpClientAsyncTest
{
class Program
{
static async Task<int> Main()
{
using (var cancellationTokenSource = new CancellationTokenSource())
{
Console.CancelKeyPress += (sender, a) =>
{
Console.WriteLine("Stopped by user");
cancellationTokenSource.Cancel();
};
var task = RunAsync(cancellationTokenSource);
Console.WriteLine("Running - …Run Code Online (Sandbox Code Playgroud)