小编Adr*_*mas的帖子

重构库是异步的,我怎么能避免重复自己?

我有一个像这样的方法:

    public void Encrypt(IFile file)
    {
        if (file == null)
            throw new ArgumentNullException(nameof(file));

        string tempFilename = GetFilename(file);
        using (var stream = new FileStream(tempFilename, FileMode.OpenOrCreate))
        {
            this.EncryptToStream(file, stream);
            file.Write(stream);
        }

        File.Delete(tempFilename);
    }
Run Code Online (Sandbox Code Playgroud)

但是,我想要编写另一个非常相似的方法,但它会调用WriteAsync,例如:

    public async Task EncryptAsync(IFile file)
    {
        if (file == null)
            throw new ArgumentNullException(nameof(file));

        string tempFilename = GetFilename(file);
        using (var stream = new FileStream(tempFilename, FileMode.OpenOrCreate))
        {
            this.EncryptToStream(file, stream);
            await file.WriteAsync(stream);
        }

        File.Delete(tempFilename);
    }
Run Code Online (Sandbox Code Playgroud)

但是,我不喜欢有两种方法实际上重复代码.我怎么能避免这个?正确的方法感觉我应该使用Action/Delegate,但签名是不同的....

思考?

.net c# asynchronous dry

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

GitHub的持续部署在Azure中失败(ASP.NET 5和MVC 6)

我在Azure中使用GitHub进行持续部署时遇到问题.我有一个共享定价层,如果我升级到基本定价层,问题就会消失.这适用于ASP.NET MVC 6应用程序(RC1).

基本上我得到以下错误:http: //pastebin.com/PgARgurg

突出的一点是:

Restore failed
There is not enough space on the disk.
Run Code Online (Sandbox Code Playgroud)

如果我直接从Visual Studio发布到共享层,它可以正常工作.只有在使用连续部署的情况下才会失败.

有任何想法吗?

c# github azure asp.net-core-mvc asp.net-core

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

为什么"this"为null,在Angular Directive中的link函数中?

我正在尝试使用TypeScript和Angular编写动态模板,但由于某种原因,'this'关键字始终为null,因此我无法访问我的私有成员$ compile.有任何想法吗?非常感谢!:-)

指示:

namespace ROD.Features.Player {
    "use strict";

    export class VideoDirective implements ng.IDirective {
        public restrict: string = "E";
        public replace: boolean = true;
        public scope = {
            content: "="
        };

        constructor(private $compile: ng.ICompileService) {
        }

        public link(element: JQuery, scope: ng.IScope): any {
            const youtubeTemplate = "<p>Youtube</p>";
            const vimeoTemplate = "<p>Vimeo</p>";

            var linkFn = this.$compile(youtubeTemplate);
            const content: any = linkFn(scope);
            element.append(content);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

App.ts:

namespace ROD {
    "use strict";
    angular.module("rodApp", [])
        .service("Settings", [() => new Settings.DevelopmentSettings()])
        .service("RedditService", [
            "$http", …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs typescript angular-directive

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

使用Visual Studio代码在Docker中远程调试NodeJS

我想使用node我的应用程序的官方docker镜像.但是我无法让远程调试器在主机上运行.我正在使用Visual Studio Code连接到远程调试器.

奇怪的是使用cusspvz/node远程调试器正常工作的非官方图像.

当我docker logcusspvz/node容器的实例运行时,我得到以下输出:

Debugger listening on [::]:5858

但是,当我docker lognode容器的实例运行时,我得到:

Debugger listening on 127.0.0.1:5858

这让我相信调试器正在侦听错误的IP地址(应该是通配符而不是localhost?)

我已经尝试了内置调试器以及nodemon.不幸的是我无法让node-inspector工作,因为它无法安装(看起来构建失败了).

这是我的Dockerfile:

FROM node
WORKDIR /scraper
EXPOSE 5858
ENTRYPOINT ["/bin/bash", "-c", "if [ -z \"$REMOTE_DEBUGGING\" ]; then node --debug index.js; else node --debug-brk index.js; fi"]
COPY . /scraper
RUN npm install
Run Code Online (Sandbox Code Playgroud)

我正在用docker-compose启动容器,使用这个YML文件:

version: '2'

services:
 alt.nphotos.imagescraper:
  container_name: nscraper
  hostname: nscraper
  build:
   context: ./ALT.NPhotos.ImageScraper
   dockerfile: Dockerfile.debug
  environment:
  - REMOTE_DEBUGGING=1
  - AMQP_CONNECTIONSTRING=amqp://guest:guest@nqueue
  ports: …
Run Code Online (Sandbox Code Playgroud)

debugging node.js docker visual-studio-code

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