小编Jam*_*s B的帖子

ReactiveX JS 和 TypeScript - 如何取消订阅?

我一直在尝试Observable使用 TypeScript 在 Angular 2 组件中实现一个新的 rxjs 。我创建了一个服务,MyService它在其中一种方法中返回一个可观察的对象,例如,

export class MyService {

    getMyObs(){
        return new Observable(observer => {
            observer.next(42);
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的 Angular 2 组件中,我在 OnInit 中订阅了这个 observable,例如,

export class MyComponent implements OnInit {
obs: any;

constructor(private myService: MyService){};    

    ngOnInit {
        this.obs = myService.getMyObs().subscribe(data => {
            // Do stuff here...
        });
    }    
}
Run Code Online (Sandbox Code Playgroud)

RxJs文档讨论了取消订阅您的 observable 以便您的 observable 知道不再向您的观察者发送消息。因此,我认为当我的组件被销毁时,我应该取消订阅 observable,例如

export class MyComponent implements OnInit, OnDestroy {
obs: any;

constructor(private myService: MyService){};    

    ngOnInit { …
Run Code Online (Sandbox Code Playgroud)

rxjs angularjs typescript angular

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

PowerShell Azure Cmdlet无法识别

运行PowerShell ISE(V4),我按如下方式安装AzureRM模块

Import-Module AzureRM
Run Code Online (Sandbox Code Playgroud)

然后我查看版本

(get-module azurerm).Version
Run Code Online (Sandbox Code Playgroud)

返回

Major  Minor  Build  Revision
3      4      0      -1
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用登录cmdlet

Login-AzureRmAccount
Run Code Online (Sandbox Code Playgroud)

但得到错误

Login-AzureRmAccount : The term 'Login-AzureRmAccount' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Login-AzureRmAccount
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Login-AzureRmAccount:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

注意 …

powershell azure

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

在实体框架迁移上执行原始 SQL

我需要使用实体框架执行原始 SQL 作为数据库初始化的一部分。需要 SQL 来设置列的排序规则,当给定上下文时,代码如下所示

context.Database.ExecuteSqlCommand("ALTER TABLE my_table ALTER COLUMN my_column nvarchar(200) COLLATE Latin1_General_CS_AS");
Run Code Online (Sandbox Code Playgroud)

问题是这个代码应该放在哪里呢?如果我将它放入EF 创建的Seed方法中,它会起作用,但如果我决定稍后删除迁移和重新设定基准,我将失去执行 SQL 的所有知识。理想情况下,我希望将此 SQL 执行抽象为 EF 知道在每次启用迁移和更新数据库时执行的另一个类。Configuration.csenable-migrations

我考虑过使用数据库初始值设定项,但进一步阅读后发现,这些仅由调用应用程序调用:这不应该是调用应用程序的责任 - 我希望它在实体框架创建数据库时设置排序规则。

我如何确保将原始 SQL 作为 EF 初始/基线配置的一部分执行,这样我就不会丢失将来所做的事情的知识(即不只是将其全部集中到 default 的种子方法中Configuration.cs

entity-framework

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

启用 Xamarins.Forms 应用程序以信任 IIS Express 开发证书

我正在开发我的第一个 Xamarin.Forms 应用程序,并且有一个使用 ASP.Net Core 构建的后端 API。我希望对 API 的所有调用都通过 HTTPS 进行,因此请按照本指南设置 HTTPS 以在 ASP.NET Core 中进行开发。我相信,这会让我在 Visual Studio 中使用 IIS Express 开发证书。

到目前为止,我一直在使用HttpClient以下 http uri通过模拟器从我的 Xamarin.Forms Android 应用程序对 API 进行所有调用

http://10.0.2.2:44321/api/User
Run Code Online (Sandbox Code Playgroud)

但是现在为我的 API 启用了 SSL,我需要使用以下 uri 从应用程序进行调用

https://10.0.2.2:44321/api/User
Run Code Online (Sandbox Code Playgroud)

但是,简单地更改httphttps会出现以下错误

{Javax.Net.Ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. ---> Java.Security.Cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. ---> Java.Security.Cert.CertPathValidatorException: Trust anchor for certification path not found.
   --- End of inner exception …
Run Code Online (Sandbox Code Playgroud)

ssl android iis-express xamarin

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

将模型绑定到ViewModel(WPF)

我正在从MVP转会MVVM,和一点点困惑,如何最好绑定ViewModelModel.我理解我们如何利用WPF的数据绑定基础设施来路由ViewViewModel使用ICommandINotifyPropertyChanged接口之间的事件,例如View:

public class MyView
{
    public MyView()
    {
        InitializeComponent();
        DataContext = new MyViewModel();
    }
}
Run Code Online (Sandbox Code Playgroud)

ViewModel:

public class MyViewModel : INotifyPropertyChanged
{
    public MyViewModel(){}

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        var handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }

    public ICommand MyCommand ... 
}
Run Code Online (Sandbox Code Playgroud)

这很棒!

现在,通常使用MVP我会Presenter持有对Modelvia构造函数注入的引用,并在其中引发Model来自Presenter更新数据的事件 …

wpf prism ioc-container inversion-of-control mvvm

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

Angular 2和Firebase SDK

我一直在努力让Angular2 快速启动应用程序与Firebase一起使用(请参阅此存储库).我安装了最新版本的Firebase,尝试使用SystemJS加载firebase(请参阅systemjs.config.js)并尝试导入firebase并使用该函数initializeApp(请参阅app.component.ts).但是,我一直firebase.initializeApp is not a function在浏览器控制台中收到错误.我是否正确使用SystemJS加载firebase.js

注意:要复制错误,您应该能够执行npm install后跟npm start.

firebase systemjs angular

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

打字稿标记联合类型

我想根据我的函数接收的接口来区分一些逻辑。为此,我尝试使用标记联合类型,例如,

someFunction(arg: TypeA | TypeB): void {
    if (arg.kind === "TypeA")
    {
        // do this
    }
    else
    {
        // do that
    }
}
Run Code Online (Sandbox Code Playgroud)

在哪里

interface TypeA {
    kind: "TypeA";
    propertyA: string;
}

interface TypeB {
    kind: "TypeB";
    propertyB: string;
}
Run Code Online (Sandbox Code Playgroud)

但是如果我想调用这个函数,Typescript 会抱怨我不提供 kind 的值,即,

let typeA: TypeA;
typeA = {propertyA: ""}
someFunction(typeA);
Run Code Online (Sandbox Code Playgroud)

TS2322: Type '{ propertyA: string; }' is not assignable to type 'TypeA'.
  Property 'kind' is missing in type '{ propertyA: string; }'.
Run Code Online (Sandbox Code Playgroud)

所以我不明白如果kind每次我想区分时都必须实现标签(在上面的例子中),标签类型是如何工作的。我只能假设我使用它们是错误的?

discriminated-union typescript

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

Promise 无法通过 TypeMoq Mock 解决

我定义MyService如下

export interface MyService {
    doStuff(): Promise<any>;
}
Run Code Online (Sandbox Code Playgroud)

MyClass消耗为MyService

import {MyService} from "./my.service";
import {Observable} from "rxjs/Observable";
export class MyClass {

    constructor(private myService: MyService) {}

    useMyService(): Observable<boolean> {
        return Observable.create(obs => {
            this.myService.doStuff()
                .then((res: any) => {
                    console.log("Promise resolved!");
                    obs.next(true);
                })
                .catch((err: any) => {
                    console.log("Promise rejected!");
                    obs.error(false);
                })
        });
    };    
}
Run Code Online (Sandbox Code Playgroud)

另外,我有一个接口MyModel定义为

export interface MyModel {
    someProperty: string;
}
Run Code Online (Sandbox Code Playgroud)

现在我想编写一个测试,以便可以MyService使用 TypeMoq 进行模拟。所以我做了以下事情

describe('MyClass', () => {

    it('useMyService returns true when …
Run Code Online (Sandbox Code Playgroud)

promise jasmine typescript typemoq

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

Web API是否需要CSP?

我是Web开发的新手,只是了解如何使用内容安全策略(CSP)来检测和缓解某些类型的攻击,包括跨站点脚本(XSS)和数据注入攻击。对于发布Web应用程序的Web应用程序,这对我来说很有意义。我是否仍需要为仅用数据(json,xml等)响应的Web API实施CSP?

asp.net asp.net-web-api content-security-policy

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

Xamarin.Auth(Android) - Chrome自定义标签在重定向时不会关闭

我已经实现了Xamarin.Auth 示例代码,以便在Android上使用google的身份提供程序进行身份验证.我已成功使用设备的Chrome浏览器导航到Google登录页面,我可以在其中输入我的凭据.我已成功向Google授权,但Chrome自定义标签在重定向回我的应用时并未关闭,即我在Chrome浏览器中查看谷歌搜索.如果我关闭浏览器,我会再次看到我的应用,并显示从谷歌身份提供商返回的用户详细信息.

为什么Chrome的自定义标签不会从Google身份提供商重定向关闭,如何使用Xamarin Forms和Xamarin.Auth关闭它?

android google-chrome xamarin.auth xamarin.forms

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