是否有可能使用 gRPC 作为具有扇出功能的推送服务?在Google给出的示例中,服务器端(C#)有以下代码:
public override async Task ListFeatures(Rectangle request, IServerStreamWriter<Feature> responseStream, ServerCallContext context)
{
var responses = features.FindAll( (feature) => feature.Exists() && request.Contains(feature.Location) );
foreach (var response in responses)
{
await responseStream.WriteAsync(response);
}
}
Run Code Online (Sandbox Code Playgroud)
问题就在这里:
我想我需要的是:
编辑: 根据卡尔的建议,我现在有以下内容:
原型:
service PubSub {
rpc Subscribe(Subscription) returns (stream Event) {}
rpc Unsubscribe(Subscription) returns (Unsubscription) {}
}
message Event
{
string Value = 1;
}
message Subscription
{
string Id = 1;
}
message Unsubscription
{
string …Run Code Online (Sandbox Code Playgroud) 如果使用 .Net < 4.7 元组不受支持。如果我安装了 NuGet“System.ValueTuple”,我就可以编写如下代码
public static (string Name, int Age) GetFoo()
{
return ("Bar", 99);
}
Run Code Online (Sandbox Code Playgroud)
使用 .Net 4.6.2。这怎么可能?NuGet (DLL) 如何更改我的可用语言功能?有没有关于这里发生的事情的可用文件?我找不到任何。
我有一个 History 组件,其中包含一个HistoryEntries.
HistoryComponent 好像:
@Component({
selector: 'history',
template: `
<div>
<historyEntry *ngFor='let entry of historyentries'></historyEntry>
</div> `,
directives : [HistoryEntryComponent]
})
Run Code Online (Sandbox Code Playgroud)
HistoryComponent 类看起来像:
export class HistoryComponent{
public historyentries = [
new HistoryEntryComponent(1, "lalala"),
new HistoryEntryComponent(2, "xxxxx")
];
}
Run Code Online (Sandbox Code Playgroud)
然后我有一个 HistoryEntryComponent:
@Component({
selector: 'historyentry',
template: `
<div>
<h1>ID: {{Id}} , Descr.: {{Description}}</h1>
</div>
`
})
Run Code Online (Sandbox Code Playgroud)
和一个班级:
export class HistoryEntryComponent {
constructor(public Id : Number, public Description : string)
{}
}
Run Code Online (Sandbox Code Playgroud)
如果我渲染它,什么都没有出现。我已经使用 a<li>来显示 id 和描述,它的工作原理与预期一致。但是当然HistoryEntry它本身可能会变得非常复杂并且需要它自己的逻辑等等。所以必须有一种方法可以 …
我将事件(按钮的分页事件)转换为IObservable,并异步接收来自服务的结果。
作为副作用,我必须更新子视图。我有两种解决方案:
选择中的副作用:
//Converting events to a "stream" of search results.
IObservable<SearchResult> resultsFromPageChange = Observable.FromEventPattern<EventArgs>(this,
"PageChangedEvent")
.Throttle(TimeSpan.FromMilliseconds(500))
.Select(async ev =>
{
var input = new SearchResultInput()
{
PageSize = PageSize,
PageIndex = PageIndex,
SearchOptions = _currentSearchOptions,
SearchText = SearchText.Value
};
var result = await GetPagedComponents(input);
//Side effect
ActivateAttributesView(result.Components.FirstOrDefault());
return result;
}).Switch(); //flatten and take most recent.
Run Code Online (Sandbox Code Playgroud)在subsribe中做副作用:
//Converting events to a "stream" of search results.
IObservable<SearchResult> resultsFromPageChange = Observable.FromEventPattern<EventArgs>(this,
"PageChangedEvent")
.Throttle(TimeSpan.FromMilliseconds(500))
.Select(async ev =>
{
var input = new SearchResultInput() …Run Code Online (Sandbox Code Playgroud)我有一个对象列表。这些对象有一个属性,例如“值”。
var lst = new List<TestNode>();
var c1 = new TestNode()
{
Value = "A",
};
lst.Add(c1);
var c2 = new TestNode()
{
Value = "A",
};
lst.Add(c2);
var c3 = new TestNode()
{
Value = "B",
};
lst.Add(c3);
var c4 = new TestNode()
{
Value = "B",
};
lst.Add(c4);
Run Code Online (Sandbox Code Playgroud)
我想这样说:
lst.PartialDistinct(x => x.Value == "A")
Run Code Online (Sandbox Code Playgroud)
这应该仅通过谓词来区分,并且在打印结果 IEnumerable 的“值”时,结果应该是:
A
B
B
Run Code Online (Sandbox Code Playgroud)
我已经找到了 DistinctBy 的解决方案,可以在其中定义键选择器。但结果当然是:
A
B
Run Code Online (Sandbox Code Playgroud)
Cyral 的第一个答案完成了这项工作。所以我接受了。但 Scott 的回答确实是一个 PartialDistinct() 方法,看起来它解决了我所有的问题。
好吧,以为用 Scott 的解决方案解决了,但事实并非如此。也许我在单元测试时犯了一个错误……或者我不知道。问题是:
if(seen.Add(item))
Run Code Online (Sandbox Code Playgroud)
这不会过滤掉值为“A”的其他对象。我认为这是因为它在放入哈希集时依赖于引用相等性。
我最终得到了以下解决方案:
public …Run Code Online (Sandbox Code Playgroud) 我有:
type Id = Id of int
let mutable IdInt = 0
let idGenerator =
fun _ ->
IdInt <- IdInt + 1
IdInt |> Id
Run Code Online (Sandbox Code Playgroud)
然后被称为例如:
printfn "%A" (idGenerator())
Run Code Online (Sandbox Code Playgroud)
在 F# 中生成简单的增量 ID 的最佳实践是什么?
我有一个像这样的列表视图:
<ListView ItemsSource="{Binding Components}"
BorderThickness="0"
Margin="0,2,0,0"
HorizontalAlignment="Stretch"
MinHeight="150"
SelectionMode="Single"
<ListView.View>
<GridView>
<GridViewColumn Header="Component Name">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="{x:Type viewModels:ComponentViewModel}">
<TextBox Text="{Binding Name}"
Style="{StaticResource TextBoxInListViewStyle}">
</TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)
这呈现如下所示:

如您所见,使用了 TextBox(我可以选择文本),但 ListViewItemContainer 给了我我不想要的玻璃选择外观。
然后我为 ListView 定义了一个 ItemContainerStyle (ListViewItemStyle) ,其使用方式如下(第 7 行):
<ListView ItemsSource="{Binding Components}"
BorderThickness="0"
Margin="0,2,0,0"
HorizontalAlignment="Stretch"
MinHeight="150"
SelectionMode="Single"
ItemContainerStyle="{StaticResource ListViewItemStyle}"
<ListView.View>
<GridView>
<GridViewColumn Header="Component Name">
<GridViewColumn.CellTemplate>
<DataTemplate DataType="{x:Type viewModels:ComponentViewModel}">
<TextBox Text="{Binding Name}"
Style="{StaticResource TextBoxInListViewStyle}">
</TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)
这是我的 ListViewItemStyle:
<Style x:Key="ListViewItemStyle"
TargetType="{x:Type ListViewItem}"> …Run Code Online (Sandbox Code Playgroud)