我有以下代码,作为 POST 请求按预期工作(给定正确的 URL 等)。似乎我在读取状态代码时遇到了问题(我收到了成功的 201,根据该数字,我需要继续处理)。知道如何获取状态代码吗?
static async Task CreateConsentAsync(Uri HTTPaddress, ConsentHeaders cconsentHeaders, ConsentBody cconsent)
{
HttpClient client = new HttpClient();
try
{
client.BaseAddress = HTTPaddress;
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
client.DefaultRequestHeaders.Add("Connection", "keep-alive");
client.DefaultRequestHeaders.Add("Cache-Control", "no-cache");
client.DefaultRequestHeaders.Add("otherHeader", myValue);
//etc. more headers added, as needed...
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, client.BaseAddress);
request.Content = new StringContent(JsonConvert.SerializeObject(cconsent, Formatting.Indented), System.Text.Encoding.UTF8, "application/json");
Console.WriteLine("\r\n" + "POST Request:\r\n" + client.DefaultRequestHeaders + "\r\nBody:\r\n" + JsonConvert.SerializeObject(cconsent, Formatting.Indented) + "\r\n");
await client.SendAsync(request).ContinueWith
(
responseTask =>
{
Console.WriteLine("Response: {0}", responseTask.Result + "\r\nBody:\r\n" + responseTask.Result.Content.ReadAsStringAsync().Result); …
Run Code Online (Sandbox Code Playgroud) 这是我ComboBox
在 XAML 中实例化的
<Combobox ItemsSource="{Binding Path=Delimiters}" DisplayMemberPath="Key"
SelectedValue="{Binding Path=SelectedDelimiter, UpdateSourceTrigger=PropertyChanged}" />
Run Code Online (Sandbox Code Playgroud)
以下是视图模型中相应的绑定,并Dictionary
在构造函数中填充:
private IDictionary<string,string> _delimiters;
public IDictionary<string,string> Delimiters
{
get{return _delimiters;}
set{_delimiters = value; RaisePropertyChanged("Delimiters");}
}
private KeyValuePair <string, string> _selectedDelimiter;
public KeyValuePair <string, string> SelectedDelimiter
{
get{return _selectedDelimiter;}
set{
if(value.Key != _selectedDelimiter.Key || value.Value != _selectedDelimiter.Value)
{
var prevDelimiter = _selectedDelimiter;
_selectedDelimiter = value;
if(IllegalDelimiter.Contains(_selectedDelimiter)
{
MessageBox.Show("errror", "error");
_selectedDelmiter = prevDelimiter;
}
RaisePropertyChanged("SelectedDelimiter");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在绑定所选值时遇到问题。正在Dictionary
绑定,当我对 UI 进行更改时ComboBox
,该设置被正确触发。在 if 语句中检查其是否为非法分隔符,它确实将所选值设置回其后面代码中的原始值,但它不会填充到 …
我的表单有大约20个文本框控件,我想激发Text_Changed事件,而不是为每个单独的文本框添加事件.有没有办法循环文本框来触发此事件?我想要做的是在文本更改时清除标签控件.我没有显示消息框,而是使用标签控件来显示消息.我还设置了如果文本框包含无效数据的地方,我选择所有文本并将焦点放在该文本框中,这样当用户重新输入信息时,标签控件就会清除消息.
编辑:
为了解决一些困惑,这里是我的验证方法中的一些代码
if (txtBentLeadsQty.Text == "")
{
//ValidData = true;
BentLeadsCount = 0;
}
else
{
if (int.TryParse(txtBentLeadsQty.Text.Trim(), out BentLeadsCount))
ValidData = true;
else
{
ValidData = false;
lblError.Text = "Bent Lead Qty must be a numeric value";
txtBentLeadsQty.SelectAll();
txtBentLeadsQty.Focus();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经有办法检查数值,并且我输入代码来选择输入的所有文本,如果值不是数字则给予焦点,我只想在文本更改时清除标签控件如果用户点击退格键或开始输入错误发生的原因,我会突出显示该文本框中的所有文本(如果它无效).如果我在每个文本框TextChanged事件中放置代码,我可以这样做,但是为了保存编码,我想知道是否有办法清除标签控件,如果任何文本框从我的验证方法抛出错误而不是添加单个事件20个文本框.注意:并非所有文本框都会输入数据,这些是我放入代码的数量文本框,如果文本框为null,则为变量赋值0.
我是 linux 用户,我使用 Visual Studio Code 进行编程,问题是 VS 代码是文本编辑器而不是 IDE,所以我无法打开.sln
文件。有没有办法在任何 Linux 发行版上安装 VS 2019?
我在这里所做的是通过 for-each 和索引方法在多个线程中导航只读列表。结果看起来线程安全,但我不相信。
有人可以告诉下面的代码(从只读列表中读取)是否是线程安全的吗?如果是的话为什么?
public class ThreadTest
{
readonly List<string> port;
public ThreadTest()
{
port = new List<string>() { "1", "2", "3", "4", "5", "6" };
}
private void Print()
{
foreach (var itm in port)
{
Thread.Sleep(50);
Console.WriteLine(itm+"----"+Thread.CurrentThread.ManagedThreadId);
}
}
private void Printi()
{
for(int i=0;i<5;i++)
{
Thread.Sleep(100);
Console.WriteLine(port[i] + "--iiiii--" + Thread.CurrentThread.ManagedThreadId);
}
}
public void StartThread()
{
Task[] tsks = new Task[10];
tsks[0] = new Task(Print);
tsks[1] = new Task(Print);
tsks[2] = new Task(Print);
tsks[3] = new …
Run Code Online (Sandbox Code Playgroud) 我有某种包含笔记的级联容器,其中有一个主容器包含所有笔记。笔记容器以树状层次结构形式制作,树结构越深入,笔记容器就越具体。我只有一个列表的原因与非常复杂的数据管理有关,但这不是问题的一部分。
\n\n主注释容器有一个ObservableCollection
,所有子注释容器都绑定到ObservableCollection
via CollectionView
。子注释容器有一个过滤器,可以过滤掉它们的注释。在常规代码中,一切正常,视图始终显示元素,但是当我将它们绑定到 eg 时ListBox
,元素不会被过滤,并且主列表中的所有元素都会显示而不进行过滤。当然我知道有一个ListCollectionView
,但是由于 CollectionView 来自IEnumerable
,我很好奇如果它ListBox
不从 访问 ,那么它如何访问主SourceCollection
列表CollectionView
。
换句话说,我不太确定为什么我需要应该适合的ListCollectionView
非常基本的行为ColletionView
。在我看来, 是ListCollectionView
强制性的,而不是其他观点真正适合ListBox
?
这是一个小样本
\n\nXAML:
\n\n<Window x:Class="ListCollection.MainWindow"\n xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\n xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\n Title="MainWindow" Height="350" Width="525">\n <StackPanel Orientation="Horizontal">\n <ListBox Width="100" ItemsSource="{Binding Model}"></ListBox>\n <ListBox Width="100" ItemsSource="{Binding View1}"></ListBox>\n <ListBox Width="100" ItemsSource="{Binding View2}"></ListBox>\n </StackPanel>\n</Window>\n
Run Code Online (Sandbox Code Playgroud)\n\nC#:
\n\nusing System.Collections.ObjectModel;\nusing System.ComponentModel;\nusing System.Windows;\nusing System.Windows.Data;\n\nnamespace ListCollection\n{\n /// <summary>\n /// Interaktionslogik f\xc3\xbcr MainWindow.xaml\n …
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我正在检查某个项目是否存在于 an 中ObservableCollection
,如果存在,我想获取它的索引,以便我可以将该项目移动到顶部,但我无法弄清楚。
我的对象:
public class RecentFile
{
public string FileName { get; set; }
public string DateAdded { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
用于查找项目索引的代码:
if (recentFilesObservableCollection.Any(f => f.FileName == "MyFileName")) {
foreach (RecentFile file in recentFilesObservableCollection) {
if (file.FileName == "MyFileName") {
var x = RecentFilesDataGrid[(recentFilesObservableCollection.IndexOf(file)];
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果项目存在,获取索引号的最佳方法是什么?
最终我需要做的是......
日志查看器
未知错误图像
在 GCP (Python) 中执行云函数时遇到未知错误。脚步:
有没有办法优雅地做到这一点?我需要做的就是List<List<int>>
用另一个数组的值存储一个新变量ICollection<ICollection<int>>
,但我找不到任何方法来做到这一点。
编码:
ICollection<ICollection<int>> mycollection = // instantiate with some numbers
List<List<int>> myList = myCollection;
Run Code Online (Sandbox Code Playgroud) 我对LINQ“ order by”有一个非常奇怪的问题,并且 Parallel.Foreach
具体来说,此代码有效:
IList<IEntitaAssociabile> result = new List<IEntitaAssociabile>();
foreach(PraticheAperteNonAssegnate pratica in praticheAperteNonAssegnate)
{
result.Add(new EntitaAssociabile
{
Id = pratica.ID_Prat,
TipologiaEntita = TipologiaEntita.Pratica,
DataApertura = pratica.DataAper.Value,
TipologiaPratica = pratica.Cod_TpPrat,
NomeCliente = pratica.Nominativo,
NumeroPraticheDaAssociare = null,
TipologiaEntitaPadre = GetEntitaPadre(pratica, praticheLotti, praticheSottolotti),
IdEntitaPadre = GetIdEntitaPadre(pratica, praticheLotti, praticheSottolotti)
});
}
return result.OrderBy(x => x.Id).ToList();
Run Code Online (Sandbox Code Playgroud)
如果我只是用以下命令更改foreach
语句Parallel.Foreach
:
IList<IEntitaAssociabile> result = new List<IEntitaAssociabile>();
Parallel.ForEach(praticheAperteNonAssegnate, (pratica) =>
{
result.Add(new EntitaAssociabile
{
Id = pratica.ID_Prat,
TipologiaEntita = TipologiaEntita.Pratica,
DataApertura = pratica.DataAper.Value,
TipologiaPratica = …
Run Code Online (Sandbox Code Playgroud) 我正在 Repl.it 上使用TkInter并且遇到了一个问题,这是我的代码:
from tkinter import *
import tkinter as tk
root = tk.Tk()
root.geometry('400x400')
Run Code Online (Sandbox Code Playgroud)
我遇到了这个错误:
Traceback (most recent call last):
File "main.py", line 4, in <module>
root = tk.Tk()
File "/usr/local/lib/python3.7/tkinter/__init__.py", line 202
3, in __init__
self.tk = _tkinter.create(screenName, baseName, className,
interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment
variable
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
无论代码是否失败,我都必须运行它。我在用着ExplicitException
。以下是我的代码:
try:
G.add_edge(data1[0][0],data1[1][0],weight=data1[2+i][0])
except ExplicitException:
pass
try:
G.add_edge(data1[0][0],data1[5][0],weight=data1[6+i][0])
except ExplicitException:
pass
try:
G.add_edge(data1[0][0],data1[9][0],weight=data1[10+i][0])
except ExplicitException:
pass
try:
G.add_edge(data1[0][0],data1[13][0],weight=data1[14+i][0])
except ExplicitException:
pass
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
NameError:名称“ExplicitException”未定义
希望得到一些帮助