小编use*_*945的帖子

在C#中计算Cron下一次运行时间

我有类似crontab的调度程序.时间定义"MM HH WD MD M":

MM-分钟
HH-小时
WD-星期
MD - 月日
M - 月

WD,MD和M允许多个条目,每个参数可以为空,例如:

^ ^  0, 1  ^ ^      means exucution every minute, every hour, at sunday and mondey, every day<br>

35 15 ^ ^ ^    execution every day at 15.35<br>
Run Code Online (Sandbox Code Playgroud)

如果您知道上次执行日期,问题是如何计算下一次运行时间.我知道如何使用循环(只需加1分钟直到它符合条件),但必须有更好的方法.

c# algorithm crontab

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

C#linq Sum()扩展为大数字

我有一个简单的Sum扩展:

public static int? SumOrNull<TSource>(this IEnumerable<TSource> source, Func<TSource, int> projection)
{
    return source.Any()
        ? source.Sum(projection)
        : (int?)null;
}
Run Code Online (Sandbox Code Playgroud)

但它会导致 System.OverflowException: Arithmetic operation resulted in an overflow.

我想要做的是这样的事情:

public static ulong? SumOrNull<TSource>(this IEnumerable<TSource> source, Func<TSource, int> projection)
{
    return source.Any()
        ? source.Sum(projection)
        : (ulong?)null;
}
Run Code Online (Sandbox Code Playgroud)

但Linq Sum没有超载,因此返回ulong和编译错误.任何方式使这项工作?

.net c# linq

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

C# OpenXML:未应用数字格式

我正在尝试在我的 .xlsx 文件中格式化十进制和整数,如“1,000.00”。

生成样式表的代码:

private Stylesheet GenerateStylesheet()
{
    //styling and formatting
    var cellFormats = new CellFormats();
    uint iExcelIndex = 164;

    //number formats
    var numericFormats = new NumberingFormats();
    var nformat4Decimal = new NumberingFormat
    {
        NumberFormatId = UInt32Value.FromUInt32(iExcelIndex++),
        FormatCode = StringValue.FromString("#,##0.00")
    };
    numericFormats.Append(nformat4Decimal);    

    //cell formats
    var cellFormat = new CellFormat
    {
        NumberFormatId = nformat4Decimal.NumberFormatId,
        FontId = 0,
        FillId = 0,
        BorderId = 0,
        FormatId = 0,
        ApplyNumberFormat = BooleanValue.FromBoolean(true)
    };
    cellFormats.Append(cellFormat);

    numericFormats.Count = UInt32Value.FromUInt32((uint)numericFormats.ChildElements.Count);
    cellFormats.Count = UInt32Value.FromUInt32((uint)cellFormats.ChildElements.Count);

    var stylesheet = new Stylesheet(); …
Run Code Online (Sandbox Code Playgroud)

c# formatting openxml number-formatting openxml-sdk

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

LDAP SearchResult 不包含用户属性

我正在使用DirectorySearcher.FindOne()方法。

Mobile在我的 Active Directory 用户属性中指定了数字。我的搜索过滤器看起来像这样

(&(ObjectClass=User)(mobile=+11111111111))
Run Code Online (Sandbox Code Playgroud)

有了这个过滤器,我就能找到合适的用户。

我还在我的 AD 用户属性中指定了传真号码,但SearchResult不包含传真属性。实际上SearchResult只包含一个属性,但我期望返回所有用户属性,包括传真号码。

我应该修改我的查询以返回传真号码吗?也许需要更改我的 AD 用户或 LDAP 服务器?

c# directoryservices ldap active-directory

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

通用列表包含()性能和替代品

我需要存储大量键值对,其中键值不唯一。这两个都是字符串。项目数约为 500 万。

我的目标是只持有唯一的对。

我尝试使用List<KeyValuePair<string, string>>,但Contains()速度非常慢。LINQAny()看起来有点快,但仍然太慢。

是否有任何替代方法可以在通用列表上更快地执行搜索?或者我应该使用另一个存储?

c# generics performance

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

立即运行任务 Microsoft.Win32.TaskScheduler

我正在使用Codeplex 的 Task Scheduler Managed Wrapper,我需要尽快并且只触发一次任务。我没有找到任何可以立即执行创建任务的 API(我可能是错的)。那么我怎样才能创建一个只触发一次并尽快触发的触发器呢?

codeplex scheduled-tasks

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

Outlook VSTO 插件:未应用 AutoFormatRule 筛选器

我正在尝试以编程方式将自动格式规则应用于 Outlook 2016。首先,我手动创建了一条规则并读取了过滤器属性,我得到了这样的过滤器:

"(\"urn:schemas:httpmail:read\" = 0 AND \" http://schemas.microsoft.com/mapi/proptag/0x001a001e \" = 'IPM.Note.MyMessage')"

然后我尝试以编程方式应用它:

Dictionary<string, OlColor> colorizationRules = new Dictionary<string, OlColor>()
        {
            {Resources.MsgClass1, OlColor.olColorRed},
            {Resources.MsgClass2, OlColor.olColorYellow},
            {Resources.MsgClass3, OlColor.olColorGreen}
        };

        Explorer explorer = Application.ActiveExplorer();

        if (explorer != null)
        {
            TableView tableView = explorer.CurrentView as TableView;

            if (tableView != null)
            {
                IEnumerable<AutoFormatRule> rules = tableView.AutoFormatRules.Cast<AutoFormatRule>();

                foreach (KeyValuePair<string, OlColor> coloriztionRule in colorizationRules)
                {                       
                    AutoFormatRule newRule = tableView.AutoFormatRules.Add(coloriztionRule.Key);

                    newRule.Filter = $"(\"urn:schemas:httpmail:read\"=0 AND \"http://schemas.microsoft.com/mapi/proptag/0x001a001e\"='{coloriztionRule.Key}')";
                    newRule.Font.Color = coloriztionRule.Value;
                    newRule.Enabled = true;

                    tableView.AutoFormatRules.Save();
                    tableView.Save();
                    tableView.Apply();
                }
            }
        } …
Run Code Online (Sandbox Code Playgroud)

outlook vsto outlook-addin

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