小编Sea*_*y84的帖子

在C#中从Gmail阅读电子邮件

我正在尝试阅读Gmail中的电子邮件.我已经尝试了我能找到的每个API /开源项目,并且不能让它们中的任何一个工作.

有没有人有一个工作代码示例,可以让我从Gmail帐户验证和下载电子邮件?

最终工作版本发布如下:https://stackoverflow.com/a/19570553/550198

.net c# gmail imap

26
推荐指数
3
解决办法
7万
查看次数

Windows服务已启动,然后使用Topshelf停止

我正在使用Quartz.net,我试图让Quartz服务器在Windows服务中启动.我创建了一个Windows服务项目并包含了Quartz.net库.在我的服务类中,我有:

protected override void OnStart(string[] args)
{
    try
    {
        Host host = HostFactory.New(x =>
        {
            x.Service<IQuartzServer>(s =>
            {
                s.SetServiceName("quartz.server");
                s.ConstructUsing(builder =>
                {
                    QuartzServer server = new QuartzServer();
                    server.Initialize();
                    return server;
                });
                s.WhenStarted(server => server.Start());
                s.WhenPaused(server => server.Pause());
                s.WhenContinued(server => server.Resume());
                s.WhenStopped(server => server.Stop());
            });

            x.RunAsLocalService();
            //x.RunAs(@"mydomain\mysusername", "mypassword");

            x.SetDescription(Configuration.ServiceDescription);
            x.SetDisplayName(Configuration.ServiceDisplayName);
            x.SetServiceName(Configuration.ServiceName);
        });

        host.Run();
    }
    catch (Exception ex)
    {
        Log.Error(ex.Message);
        Log.Error(ex.InnerException.Message);
    }

}
Run Code Online (Sandbox Code Playgroud)

我还创建了一个Windows服务安装程序,并使用以下命令在Visual Studio的命令提示符中成功安装了Windows服务:

installutil MyWindowsService.exe

当我在Windows服务列表中查看我的服务并尝试启动该服务时 - 我收到一个消息对话框:

The MyWindowsService service on Local Computer started and the
stopped. Some Services …
Run Code Online (Sandbox Code Playgroud)

c# windows-services quartz.net topshelf

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

在C#中的Parallel.For

我正在尝试转换以下Collat​​z Conjecture算法:

 public class CollatzConjexture
    {
        public static int Calculate(int StartIndex, int MaxSequence)
        {
            int ChainLength = 0;
            int key = 0;
            bool ContinuteCalulating = true;
            int LongestChain = 0;
            Int64 Remainder = 0;

            for (int i = StartIndex; i <= MaxSequence; i++)
            {
                ChainLength = 1;
                Remainder = i;
                ContinuteCalulating = true;

                while (ContinuteCalulating)
                {
                    Remainder = CalculateCollatzConjecture(Remainder);
                    if (Remainder == 1)
                        ContinuteCalulating = false;

                    ChainLength += 1;
                }

                if (ChainLength > LongestChain)
                {
                    LongestChain = ChainLength;
                    key = …
Run Code Online (Sandbox Code Playgroud)

.net c# parallel-processing

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

为 VS2008 解决方案创建 VS2010 解决方案文件

是否可以为现有的 VS2008 解决方案创建 VS2010 解决方案文件?那么我将同时拥有 VS2008 和 VS2010 解决方案文件,并且能够在不运行项目转换器的情况下从 VS2008 或 VS2010 打开解决方案?

我可以复制 2008 .sln,将其重命名为 MyProject2010.sln 并替换:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Run Code Online (Sandbox Code Playgroud)

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 
Run Code Online (Sandbox Code Playgroud)

除了解决方案文件之外,我还需要更改或创建其他任何内容吗?

提前致谢

.net projects-and-solutions visual-studio-2010 visual-studio-2008

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

更新输入的插入符位置并在放置事件中插入文本

背景

我正在尝试使用jQuery UI Draggable和Droppable组件将<div>元素拖放到<input>。目前,我必须将插入符号放置在希望文本出现的位置,然后将其拖放<div>到中<input>

我不确定100%是否可以这样做,但是我想做的是在插入<div>的文本之间拖动插入符时自动更新其位置<input>

jsFiddle示例在这里...

的CSS

.draggable
{
    width: 250px;
    height: 20px;
    background-color: #e6eaff;
    border: 2px solid #3399cc;
    margin-bottom: 1em;
    padding: 4px;
    cursor: default;
}

.active
{
    border: 2px solid #6699ff;
}

#droppable
{
    font-size: 14pt;
    width: 400px;
}

#droppableHolder
{
    margin-top: 5em;
}
Run Code Online (Sandbox Code Playgroud)

的HTML

<div class="draggable">Text 1</div>
<div class="draggable">Text 2</div>
<div class="draggable">Text 3</div>
<div class="draggable">Text 4</div>
<div id="droppableHolder">
    Drop in the text box below:<br …
Run Code Online (Sandbox Code Playgroud)

asp.net jquery jquery-ui jquery-ui-draggable jquery-ui-droppable

5
推荐指数
0
解决办法
1716
查看次数

将一个C#变量添加到javascript中

我的标题中有以下代码块:

 <script type="text/javascript">
        $(document).ready(function () {
            $('#target').readmytweet({
                'color': 'black',
                'search': 'from:' + <%= GetUserName() %>,
                'user': <%= GetUserName() %>,
                'width': 600,
                'tweets': 10,
                'speed': 25
            });
        })
    </script>

protected string GetUsername()
        {
            return "somestring..";
        }
Run Code Online (Sandbox Code Playgroud)

但是,我收到一条错误消息:

无法修改Controls集合,因为控件包含代码块(即<%...%>).

有谁知道如何将我的代码中的C#变量传递给这个jQuery函数而不会出现这个错误?

提前致谢

.net c#

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

无法通过Magento API更新库存可用性/库存价值

背景

我有一个现场和测试Magento商店.我从Magento商店的WSDL生成一个MagentoApi C#类.

问题

我可以通过我的API类更新产品数量而不会出现任何问题.我现在正在尝试Stock Availability从API 设置字段,但它不会改变它的值.

[Test]
public void UpdateIsInStockField()
{
    MagentoStoreConfig storeConfig = GetTestMagentoStore();
    var magentoApiRepo = new MagentoApiRepository(storeConfig);
    catalogInventoryStockItemEntity magentoProduct = magentoApiRepo.GetProductFromSku(new[] { "SKU-123456" });

    var productUpdated = new catalogInventoryStockItemUpdateEntity
                      {
                          is_in_stock = 0,
                          manage_stock = 0,
                          use_config_manage_stock = 0,
                          qty = new Random().Next(50, 100).ToString(CultureInfo.InvariantCulture)
                      };

    magentoApiRepo.UpdateStockQuantity(magentoProduct.product_id, productUpdated);
}
Run Code Online (Sandbox Code Playgroud)

结果

从Magento商店的管理部分,产品的数量值会发生变化,但Stock Availability价值未发生变化.

我正在设置manage_stockuse_config_manage_stock按照Magento API参考指南中的说明进行操作.

.net c# api magento

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

在哪里创建 HostBuilder 并避免“以下构造函数参数没有匹配的夹具数据”

我采用了一个仅包含类库和单元测试项目的旧版 .NET 框架应用程序,并将它们全部转换为 .NET core 3.1。

IHostBuilder我似乎无法使用's 的 .NET core 方法执行或引导单元测试CreateHostBuilder

当我调试任何单元测试时,它会停止执行并收到此错误:

以下构造函数参数没有匹配的装置数据:IOptions`1 appConfig、IServiceX serviceX、ITemplateEngine templateEngine 异常没有堆栈跟踪

单元测试示例:

public class TemplateGenerationTests : BaseTest
{
    private readonly AppConfiguration appConfig;
    private readonly IServiceX serviceX;
    private readonly ITemplateEngine templateEngine;

    public TemplateGenerationTests(IOptions<AppConfiguration> appConfig, IServiceX serviceX, ITemplateEngine templateEngine)
    {
        this.appConfig = appConfig.Value;
        this.serviceX = serviceX;
        this.templateEngine = templateEngine;
    }

    [Fact]
    public void SomeTestIhave()
    {
        //removed for brevity
        serviceX.DoWork(appConfig.SomeAppProp);
        

        Assert.NotNull(result);
        Assert.NotEmpty(result);
    }
}
Run Code Online (Sandbox Code Playgroud)

基类(我感觉这是创建主机构建器的错误方法):

public class BaseTest
{
    public BaseTest()
    {
        var builder …
Run Code Online (Sandbox Code Playgroud)

c# xunit .net-core

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