小编Kri*_*ett的帖子

lodash debounce不能在匿名函数中工作

您好我无法弄清楚为什么当直接传递给keyup事件时debounce函数按预期工作; 但如果我将它包装在匿名函数中,它就不起作用.

我有问题:http : //jsfiddle.net/6hg95/1/

编辑:添加了我尝试过的所有东西.

HTML

<input id='anonFunction'/>
<input id='noReturnAnonFunction'/>
<input id='exeDebouncedFunc'/>
<input id='function'/>
<div id='output'></div>
Run Code Online (Sandbox Code Playgroud)

JAVASCRIPT

$(document).ready(function(){
    $('#anonFunction').on('keyup', function () {
        return _.debounce(debounceIt, 500, false); //Why does this differ from #function
    });
    $('#noReturnAnonFunction').on('keyup', function () {
        _.debounce(debounceIt, 500, false); //Not being executed
    });
    $('#exeDebouncedFunc').on('keyup', function () {
        _.debounce(debounceIt, 500, false)(); //Executing the debounced function results in wrong behaviour
    });
    $('#function').on('keyup', _.debounce(debounceIt, 500, false)); //This is working.
});

function debounceIt(){
    $('#output').append('debounced');
}
Run Code Online (Sandbox Code Playgroud)

anonFunction并且noReturnAnonFunction不会启动去抖功能; 但是最后一次function …

javascript jquery lodash

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

WPF MVVM导航视图

我有一个包含多个视图的WPF应用程序.我想从视图1到视图2的toswitch,从那里我可以切换到多个视图.所以我想在视图1上有一个按钮,它在同一窗口中加载view2.

我试过这些东西,但不能让它发挥作用.

从第一个链接问题是我不理解viewmodellocator代码.他们调用CreateMain(); 函数但是这个定义在哪里,以及如何从视图内部切换到另一个视图.

c# navigation wpf mvvm

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

Mongo更新数组元素(.NET驱动程序2.0)

编辑:不寻找这样做的javascript方式.我正在寻找MongoDB C#2.0驱动程序的方法(我知道它可能不可能;但我希望有人知道解决方案).

我试图在我的mongodb中更新主文档中数组中嵌入的项的值.

我正在寻找一种强有力的方式来做到这一点.我正在使用Mongodb c#2.0驱动程序

我可以通过弹出元素,更新值,然后重新插入来实现.这感觉不对劲; 因为我正在覆盖可能在此期间写的内容.

这是我到目前为止尝试但没有运气:

private readonly IMongoCollection<TempAgenda> _collection;

void Main()
{
    var collectionName = "Agenda";
    var client = new MongoClient("mongodb://localhost:27017");
    var db = client.GetDatabase("Test");
    _collection = db.GetCollection<TempAgenda>(collectionName);
    UpdateItemTitle(1, 1, "hello");
}

public void UpdateItemTitle(string agendaId, string itemId, string title){
    var filter = Builders<TempAgenda>.Filter.Eq(x => x.AgendaId, agendaId);
    var update = Builders<TempAgenda>.Update.Set(x => x.Items.Single(p => p.Id.Equals(itemId)).Title, title);
    var result = _collection.UpdateOneAsync(filter, update).Result;
}
Run Code Online (Sandbox Code Playgroud)

.net c# mongodb

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

ASP.NET Identity(使用IdentityServer4)获取外部资源oauth访问令牌

我已经浏览了identityServer4的文档,并且我将其设置为使用Microsoft Office 365作为登录提供程序.当用户登录后我想创建一个按钮,他可以让我的应用程序使用graph.microsoft.com的webhooks api订阅他的日历事件

startup.cs中的代码

app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions
{
     AuthenticationScheme = "Microsoft",
     DisplayName = "Microsoft",
     SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,

     ClientId = "CLIENT ID",
     ClientSecret = "CLIENT SECRET",
     CallbackPath = new PathString("/signin-microsoft"),
     Events = new OAuthEvents
     {
         OnCreatingTicket = context =>
         {
             redisCache.Set("AccessToken", context.AccessToken.GetBytes(), new DistributedCacheEntryOptions
             {
                 AbsoluteExpiration = DateTimeOffset.UtcNow.AddDays(3)
             });
             return Task.FromResult(context);
         }
     }
     Scope =
     {
         "Calendars.Read",
         "Calendars.Read.Shared",
     },
     SaveTokens = true
});
Run Code Online (Sandbox Code Playgroud)

但这显然不是一条可行的道路.我只是为了测试目的而做了这个,并制作了所需订阅的PoC.

现在我想知道是否有更聪明的方式与identityServer通信,允许我获得这个外部访问令牌,以便我可以代表我的登录用户使用microsoft api?

或者,我唯一的选择是直接从此OAuthEvent获取Microsoft AccessToken并将其直接存储在链接到登录用户的数据库中?

我真的需要这个,因为我的大部分功能都是基于来自第三方的数据.

c# oauth asp.net-identity asp.net-identity-3 identityserver4

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

Visual Studio 2017 csproj .NET Core构建 - 未正确复制视图

我有一个在.NET Core中运行的项目,我使用VS2017作为IDE.

当我通过Visual Studio 2017构建我的项目时,它不会自动将Views文件夹和wwwroot文件夹添加到[projectRoot]/bin/Debug/netcoreapp1.1/win10-x64(BuildDir)中的输出.这意味着如果我尝试直接从.exe filebin文件夹中创建的网站运行我的网站,我会得到一个错误的错误viewswwwroot.如果我手动将这些文件夹复制到BuildDir那么视图加载正确.

我可以在我的.csproj文件中设置以下内容:

<Content Update="Views\**">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Run Code Online (Sandbox Code Playgroud)

然后Views工作,但现在我的布局文件没有被编译,所以我得到以下内容:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - FirstAgenda</title>

    <environment names="Development">
        <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
        <link rel="stylesheet" href="~/css/site.css"/>
        <link rel="stylesheet" href="~/css/overwrite.css" asp-append-version="true" />
    </environment>
    <environment names="Staging,Production">
        <link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css"
              asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
        <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
        <link rel="stylesheet" href="~/css/overwrite.css" asp-append-version="true" />
    </environment>
</head>
Run Code Online (Sandbox Code Playgroud)

这意味着我的根文件夹未正确定位.还有点告诉我,只是将文件复制到输出目录是不正确的.

如果我发布我的应用程序(也没有添加到.csproj文件),以上所有工作都有效.我只有一个项目运行器,我希望能够指向我的网站可执行文件的调试版本,因为与仅使用VS2017构建项目相比,很容易忘记进行发布.

我只是不知道从哪里去,任何帮助将不胜感激?

编辑:

添加了csproj的精简版本(不起作用): …

msbuild visual-studio asp.net-core-mvc .net-core visual-studio-2017

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

IdentityServer4和Azure AD在登录页面上自动选择用户

最近,当人们试图通过我们的服务使用其Microsoft帐户登录时,Microsoft似乎改变了行为。

我们有一个设置,其中我们将IdentityServer4和Azure AD用于Microsoft帐户。当人们现在尝试登录时,他们只需单击我们网页上的登录按钮,便转到Microsoft登录。在这里,Microsoft似乎会自动选择已登录的用户,并继续进行登录。

这导致两个问题。

  1. 用户很难理解他们的帐户是自动选择的。
  2. 如果用户足够快,则可以单击其用户,这会将两个回调发送到我们的服务器,并且发生争用情况,这导致OperationCancelledException一半的时间。

我们的设置非常接近IdentityServer4s快速入门指南中给出的示例:

serviceCollection
    .AddAuthentication(o =>
    {
        o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        o.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    })
    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddMicrosoftAccount("Microsoft", "Microsoft", o =>
    {
        o.SignInScheme = IdentityConstants.ExternalScheme;
        o.ClientId = _externalKeysOptions.MicrosoftClientId;
        o.ClientSecret = _externalKeysOptions.MicrosoftClientSecret;
        o.CallbackPath = new PathString("/signin-microsoft");
        new[]
        {
            "offline_access",
            "Calendars.Read.Shared",
            "Calendars.ReadWrite",
            "Tasks.Readwrite"
        }.ForEach(scope => o.Scope.Add(scope));
        o.SaveTokens = true;
    })
Run Code Online (Sandbox Code Playgroud)

我们如上所述设置认证方案。然后,我们对提供者进行正常的挑战:

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
[Route("externallogin")]
public IActionResult ExternalLogin(ExternalLoginModel model)
{
    var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { model.ReturnUrl, termsOfServiceAccepted = model.AgreeToTerms, platform = model.Platform });
    var properties = …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-active-directory openid-connect identityserver4

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

AWS Dynamodb 文档客户端 UpdateCommand

AWS DynamoDB文档UpdateCommand中的 没有很好的记录并且难以使用。

我想使用 update 命令只获取一个 Javascript 对象,并将该对象中的所有键插入到与主键匹配的对象上。

看着InsertCommand我认为它会很简单,如下所示:

async updateItem(tableName: string, primaryKeyName: string, id: string, item: { [key: string]: any }) {
    const input: UpdateCommandInput = {
      Key: {
        [primaryKeyName]: id,
      },
      AttributeUpdates: item,
      TableName: tableName,
    };

    const command = new UpdateCommand(input);

    return await this.client.send(command);
  }
Run Code Online (Sandbox Code Playgroud)

但这似乎失败了。

amazon-web-services node.js amazon-dynamodb typescript

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

ABCPDF:将PDF文件拆分为单页PDF文件

我正在使用ABCpdf工具,我试图将1TB的PDF文件(因此效率问题)分成单页PDF文件.

我尝试过以下方法:

Doc theSrc = new Doc();
theSrc.Read("C://development//pdfSplitter//Bxdfbc91ca-fc05-4315-8c40-798a77431ee0xP.pdf");

for (int i = 1; i <= theSrc.PageCount; i++)
{   
    Doc singlePagePdf = new Doc();
    singlePagePdf.Rect.String = singlePagePdf.MediaBox.String = theSrc.MediaBox.String;
    singlePagePdf.AddPage();
    singlePagePdf.AddImageDoc(theSrc, i, null);
    singlePagePdf.FrameRect();
    singlePagePdf.Save("C://development//pdfSplitter//singlePDF//singlePage"+i+".pdf");
    singlePagePdf.Clear();
}
theSrc.Clear();
Run Code Online (Sandbox Code Playgroud)

这一个非常快,但它不保留旋转的页面,他们需要.我试图手动旋转它们,但这很快就变得有点混乱,并且它们没有像原始文档中那样精确地出现.

我也尝试过:

Doc theSrc = new Doc();
theSrc.Read("C://development//pdfSplitter//Bxdfbc91ca-fc05-4315-8c40-798a77431ee0xP.pdf");
for (int i = 1; i <= theSrc.PageCount; i++)
{  
    Doc singlePagePdf = new Doc();
    singlePagePdf.Append(theSrc);
    singlePagePdf.RemapPages(i.ToString());
    singlePagePdf.Save("C://development//pdfSplitter//singlePDF//singlePage"+i+".pdf");
    singlePagePdf.Clear();
}
theSrc.Clear();
Run Code Online (Sandbox Code Playgroud)

这个比第一个慢大约6倍(在大型文档上)但它保持旋转页面的格式,这很重要.这个问题是我必须附加整个文档并再次删除所有不需要的页面.这对文件中的所有页面都是非常低效的.

有人可以帮我解决这个问题吗?

c# abcpdf

4
推荐指数
2
解决办法
4322
查看次数