我试图了解如何在Angular 2中使用Observables.我有这个服务:
import {Injectable, EventEmitter, ViewChild} from '@angular/core';
import {Observable} from "rxjs/Observable";
import {Subject} from "rxjs/Subject";
import {BehaviorSubject} from "rxjs/Rx";
import {Availabilities} from './availabilities-interface'
@Injectable()
export class AppointmentChoiceStore {
public _appointmentChoices: BehaviorSubject<Availabilities> = new BehaviorSubject<Availabilities>({"availabilities": [''], "length": 0})
constructor() {}
getAppointments() {
return this.asObservable(this._appointmentChoices)
}
asObservable(subject: Subject<any>) {
return new Observable(fn => subject.subscribe(fn));
}
}
Run Code Online (Sandbox Code Playgroud)
此BehaviorSubject从另一个服务推送新值:
that._appointmentChoiceStore._appointmentChoices.next(parseObject)
Run Code Online (Sandbox Code Playgroud)
我在组件中以可观察的形式订阅它,我希望将其显示在:
import {Component, OnInit, AfterViewInit} from '@angular/core'
import {AppointmentChoiceStore} from '../shared/appointment-choice-service'
import {Observable} from 'rxjs/Observable'
import {Subject} from 'rxjs/Subject'
import {BehaviorSubject} from "rxjs/Rx"; …Run Code Online (Sandbox Code Playgroud) 我想构建自己的JSON,并让服务返回一个字符串,这里是代码
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)]
public string GetCurrentCart()
{
//Code ommited
string jsonClient = null;
var j = new { Content = response.Content, Display=response.Display, SubTotal=response.SubTotal};
var s = new JavaScriptSerializer();
jsonClient = s.Serialize(j);
return jsonClient;
}
Run Code Online (Sandbox Code Playgroud)
我得到的响应包含c#中字符串中的"用于创建".
以下是回复.
"{\"Content\":\"\\r\\n\\u003cdiv\\u003e\\r\\n\\u003cinput type=\\\"hidden\\\" name=\\\"__VIEWSTATE\\\" id=\\\"__VIEWSTATE\\\" value=\\\"\/wEPDwUBMA9kFgJmD2QWAmYPZBYGAgMPFgIeBFRleHQFKFlvdSBoYXZlIG5vIGl0ZW1zIGluIHlvdXIgc2hvcHBpbmcgY2FydC5kAgUPFgIeB1Zpc2libGVoZAIHDxQrAAIPFgIfAWhkZGQYAQUMY3RsMDEkbHZDYXJ0D2dkoWijqBUJaUxmDgFrkGdWUM0mLpgQmTOe8R8hc8bZco4=\\\" \/\\u003e\\r\\n\\u003c\/div\\u003e\\r\\n\\r\\n\\u003cdiv class=\\\"block block-shoppingcart\\\"\\u003e\\r\\n \\u003cdiv class=\\\"title\\\"\\u003e\\r\\n \\u003cspan\\u003eShopping Cart\\u003c\/span\\u003e\\r\\n \\u003c\/div\\u003e\\r\\n \\u003cdiv class=\\\"clear\\\"\\u003e\\r\\n \\u003c\/div\\u003e\\r\\n \\u003cdiv class=\\\"listbox\\\"\\u003e\\r\\n You have no items in your shopping cart.\\r\\n \\r\\n \\r\\n \\u003c\/div\\u003e\\r\\n\\u003c\/div\\u003e\\r\\n\",\"Display\":\"You have no items in your shopping cart.\",\"SubTotal\":null}" …Run Code Online (Sandbox Code Playgroud) 我有2个类,它们有一些相同的属性.我从第一类库存到列表属性,然后,我想获取一些所需的属性并将它们放入第二类类型的列表中.我已经通过C#制作了强制转换序列并运行正常,但我必须使用LINQ.我试图做一些事但没有好结果.请给我一些建议.
第一类:
public class ServiceInfo {
private long _id;
public long ID {
get { return this._id; }
set { _id = value; }
}
private string _name;
public string Name {
get { return this._name; }
set { _name = value; }
}
private long _qty;
public long Quantity {
get { return this._qty; }
set { _qty = value; }
}
private double _amount;
public double Amount {
get { return this._amount; }
set { _amount = value; …Run Code Online (Sandbox Code Playgroud) 我有一个列表,其中包含一些字符串类型的项目.
List<string> lstOriginal;
Run Code Online (Sandbox Code Playgroud)
我有另一个列表,其中包含应从第一个列表中删除的id.
List<int> lstIndices;
Run Code Online (Sandbox Code Playgroud)
我试图用RemoveAt()方法完成这项工作,
foreach(int indice in lstIndices)
{
lstOriginal.RemoveAt(indice);
}
Run Code Online (Sandbox Code Playgroud)
但它崩溃并且说我"索引超出范围".
我有一个web api方法,如下所示:
[HttpPost]
[Route("messages")]
public IHttpActionResult Post(IEnumerable<Email> email)
{
AddToQueue(email);
return Ok("message added to queue");
}
Run Code Online (Sandbox Code Playgroud)
我的电子邮件类目前看起来像这样:
public string Body { get; set; }
public string From { get; set; }
public string Template { get; set; }
public string To { get; set; }
public string Type { get; set; }
Run Code Online (Sandbox Code Playgroud)
我正在使用fiddler发布到我的Post方法,如下所示:
User-Agent: Fiddler
Host: localhost:3994
Content-Length: 215
Content-Type: application/json; charset=utf-8
[
{"Body":"body","From":"from","To":"to","Template":"template"},
{"Body":"body1","From":"from1","To":"to1","Template":"template1"},
{"Body":"body2","From":"from2","To":"to2","Template":"template2"}
]
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,我希望能够将Dictionary添加到我的Email类中,所以它看起来像这样:
public string Body { get; set; }
public string From { get; …Run Code Online (Sandbox Code Playgroud) 我需要验证SQL列的名称,该列以编程方式创建...
那里应该有2个验证规则:
第一条规则的解决方案很好:
该CSharpCodeProvider类有IsValidIdentifier方法使验证容易的实现.
(例如:
string myColumnName = "blabla";
var isValid = _cSharpCodeProvider.IsValidIdentifier(myColumnName);
Run Code Online (Sandbox Code Playgroud)
)
第二条规则的解决方案是一个愚蠢的冗长:
我发现谷歌搜索的唯一方法是从MSDN中获取关键字- 保留关键字(Transact-SQL)SQL Server 2008 R2
要构建一个string []属性,它将返回所有这些关键字......
(例如:
public static class SqlReservedKeywords {
public static string[] SqlServerReservedKeywords {
get { return SqlServerKeywords; }
}
private static readonly string[] SqlServerKeywords = new[] {
"ADD","EXISTS","PRECISION",
//. . .
"EXEC","PIVOT","WITH",
"EXECUTE","PLAN","WRITETEXT"
};
}
Run Code Online (Sandbox Code Playgroud)
//外部代码
var isValid = SqlReservedKeywords.SqlServerReservedKeywords.Contains(myColumnName);
Run Code Online (Sandbox Code Playgroud)
) …
环境:.Net Core 3.1REST API EntityFrameworkCore.InMemory 3.1.6//XUnit 2.4.1
在 Database First Setup 中,我有一个映射到Sql View的模型。在代码生成期间(使用EF Core PowerTools 2.4.51),该实体被标记DbContext为.HasNoKey()
当我尝试测试访问DbSet映射到Sql 视图的端点时,它抛出异常:
Unable to track an instance of type '*' because it does not have a primary key. Only entity types with primary keys may be tracked.
遵循一些代码片段,其中包含我迄今为止尝试过的重点。
自动生成的DbContext:ViewDemoAccountInfo是映射到Sql 视图的实体。其他实体映射到常规Sql表
// <auto-generated> This file has been auto generated by EF Core Power …Run Code Online (Sandbox Code Playgroud) 我正在尝试从SharePoint库获取所有文件夹和文件,并执行一个请求。
CamlQuery query = new CamlQuery();
query.ViewXml = "<View Scope='RecursiveAll' />";
var libraryName = "Specific Documents";
ListItemCollection itemsRaw = clientContext.Web.Lists.GetByTitle(libraryName).GetItems(query);
clientContext.Load(itemsRaw);
clientContext.ExecuteQuery();
Run Code Online (Sandbox Code Playgroud)
这段代码运行良好,因此,我在指定的库中列出了所有文件夹和文件。
似乎文件详细信息以惰性方式加载。仅细节层次结构中的第一级。但是我不知道如何,FieldValues集合充满了Data。

我看到ListItem ContentType.Name尚未初始化。

是否有可能以某种方式更新查询,该方式将在此单个调用中加载ContentType的数据。
还是唯一的办法是遍历所有文件并对特定文件进行ContentType加载?
我以以下方式执行此操作:
foreach(var listItem in listItemCollection)
{
context.Load(listItem, k => k.ContentType);
context.ExecuteQuery();
var contentTypeName = listItem.ContentType.Name;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果可能的话,我将在一次调用中获取此信息,而无需在集合中进行迭代并开始对ClientContext进行多次调用。
PS:我是SharePoint编程的新手。我只想修复一个错误。
谢谢!
我正在尝试将 Worldpay 集成到 angular2 应用程序中。
我正在使用自己的表单(own-form)方法,需要将其脚本包含在页面中:
<script src="https://cdn.worldpay.com/v1/worldpay.js"></script>
为某些输入添加特定属性:data-worldpay并将Worldpay.js逻辑附加到表单中...
我设法完成以下步骤:
1. 在您的页面中包含 Worldpay.js
2. 创建具有相关属性的付款表单
我怎样才能继续进行下一步......我陷入了这个问题:
5. 将 Worldpay.js 附加到您的表单:
<script type="text/javascript">
var form = document.getElementById('paymentForm');
Worldpay.useOwnForm({
'clientKey': 'your-test-client-key',
'form': form,
'reusable': false,
'callback': function(status, response) {
document.getElementById('paymentErrors').innerHTML = '';
if (response.error) {
Worldpay.handleError(form, document.getElementById('paymentErrors'), response.error);
} else {
var token = response.token;
Worldpay.formBuilder(form, 'input', 'hidden', 'token', token);
form.submit();
}
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
为什么?
angular2 从模板中删除所有标签<script。
假设有一个解决方法,可以在ngAfterViewInit()方法中的页面中注入一些脚本(就像我在第一步中所做的那样)
ngAfterViewInit(): …Run Code Online (Sandbox Code Playgroud) Asp.Net Core 3.0
我正在使用ASP.NET Core web application with Angular and Authentication(个人用户帐户)模板(来自 Visual Studio 2019)。
我的目的是在生成的内容中添加一些自定义声明JWT并在浏览器中使用它们。
为了做到这一点,我延长了UserClaimsPrincipalFactory
public class MyCustomClaimsInjector : UserClaimsPrincipalFactory<ApplicationUser>
{
public MyCustomClaimsFactory(UserManager<ApplicationUser> userManager, IOptions<IdentityOptions> optionsAccessor) : base(userManager, optionsAccessor)
{
}
protected override async Task<ClaimsIdentity> GenerateClaimsAsync(ApplicationUser user)
{
var id = await base.GenerateClaimsAsync(user);
id.AddClaim(new Claim("my_claim1", "AdditionalClaim1"));
id.AddClaim(new Claim("my_claim2", "AdditionalClaim2"));
return id;
}
}
Run Code Online (Sandbox Code Playgroud)
同样,我已经在 Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<ApplicationUser>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddClaimsPrincipalFactory<MyCustomClaimsFactory>();
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
services.AddControllersWithViews();
services.AddRazorPages();
// …Run Code Online (Sandbox Code Playgroud) c# authentication jwt asp.net-core-identity asp.net-core-3.0
c# ×6
angular ×2
list ×2
typescript ×2
.net-3.5 ×1
casting ×1
dictionary ×1
ef-core-3.1 ×1
json ×1
jwt ×1
keyword ×1
linq ×1
observable ×1
payment ×1
rxjs ×1
sharepoint ×1
splistitem ×1
sql ×1
wcf ×1
worldpay ×1
xunit ×1