天道酬勤,学无止境

c#

Accessing object parameters added in an array

I want to know how to access ListArray 1 and print one of the parameters of the object added to that ListArray Main Program: namespace ConsoleApp1 { class Program { static void Main(string[] args) { UserDetails ud = new UserDetails(); List<TaskDetails> taskDetails = new List<TaskDetails>(); Console.Write("Please enter User ID: "); string i = Console.ReadLine(); Console.Write("Please enter username: "); string s = Console.ReadLine(); ud.SetDetails(i, s); int cnt = int.Parse(Console.ReadLine()); for (int x=1; x <= cnt; x++) { Console.Write("Please enter title for Task: " + x + " "); string title

2022-01-25 05:42:46    分类:问答    c#

Entity Framework 4.0 更新 POCO 关系(Entity Framework 4.0 Update POCO relationship)

问题 我已经创建了 POCO 类,它在 edmx 文件中等效(只有一种方式导航属性父级的类别实体) public class Category { public int ID {get;set;} public string Name {get;set;} public Category Parent {get;set;} } 我对影响 Parent 属性的 CRUD 操作有疑问: 检索看起来像: public void CanRetrieve() { var category = context.Categories.Where(x => x.ID == id).FirstOrDefault(); cotext.LoadProperty<Category> (category, c => c.Parent); } ant 工作正常(我得到了填充了 Parent 属性的 Category 对象) 添加看起来像: public void CanAdd() { Category cat = new Category(); cat.Name = "cat 1"; cat.Parent = new Category() {ID = 12}; //assuming that in the database there is a record with ID 12 context

2022-01-25 05:41:09    分类:技术分享    c#   entity-framework

How to verify if localization is working correctly in Bot framework

I have used RView and MAT tools to create resource files for french language as described in https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-formflow-localize to localize the form flow. How can I verify if the localization is working correctly. Basically I need a way to test the form flow in my emulator in French language. What's the best/right way to set the CurrentUICulture or to test this out?

2022-01-25 05:40:59    分类:问答    c#   botframework   formflow

Pass ValueTuple instead of arguments [duplicate]

This question already has answers here: In C# 7 is it possible to deconstruct tuples as method arguments (7 answers) Closed 2 years ago. Is it possible to do in this way (or maybe I need specific version of C#)? Function<int,int,int,int> triSum = (a,b,c) => {return a+b+c;}; var tup = (1,2,3); triSum(tup); //passing one tuple instead of multiple args Update: I mean passing tuple instead of separate arguments. public void DoWrite(string s1, string s2) { Console.WriteLine(s1+s2); } public (string,string) GetTuple() { //return some of them } //few lines later DoWrite(GetTuple());

2022-01-25 05:40:48    分类:问答    c#   tuples   parameter-passing   valuetuple

.NET 在复制操作后拒绝访问目录(.NET Denying Access to Directories After Copy Operations)

问题 我正在对另一个目录执行目录的“安全”副本,如下所示: 给定源 C:\Source 和目标 C:\Target 复制 C:\Source 到 C:\Target-incoming 将 C:\Target(如果存在)移动到 C:\Target-outgoing 将 C:\Target-incoming 移动到 C:\Target 删除 C:\Target-outgoing(如果存在) 如果前三个步骤中的任何一个失败,我会尝试将它们恢复原状以防止数据丢失。 但是,C:\Target-incoming 到 C:\Target 的移动在大多数情况下都会失败,并显示“拒绝访问路径 C:\Target-incoming”。 目前,在移动操作之前插入 Thread.Sleep(100) 可以解决我的问题。 然而,等待 0.1 秒对我来说似乎很荒谬。 Thread.Sleep(10) 不足以修复它。 我也有种下沉的感觉,我必须等待的值取决于磁盘 IO 的速度。 所以,我的问题: 我可以防止这种情况发生吗? 如果没有,有没有办法在复制后找出目录上的锁何时释放? 编辑:为清楚起见,我在一个线程上以一种方法执行所有这些操作,我只是使用 Thread.Sleep() 暂停代码流片刻。 移动和复制是使用标准的 .NET Directory.Move()、Directory.CreateDirectory

2022-01-25 05:40:21    分类:技术分享    c#   .net   .net-4.0

How to pass string data from Master-Detail Page in Xamarin Forms

I am trying to make a Master-Detail Navigation using help of this github example. The relevant code sample from my project is - MasterPageItem.cs namespace Demo.MenuItems { public class MasterPageItem { public string Title { get; set; } public string IconSource { get; set; } public Type TargetType { get; set; } } } MainPage.Xaml.cs public partial class MainPage : MasterDetailPage { public MainPage() { InitializeComponent(); masterPage.ListView.ItemSelected += OnItemSelected; if (Device.RuntimePlatform == Device.UWP) { MasterBehavior = MasterBehavior.Popover; } Detail = new NavigationPage(new

2022-01-25 05:39:00    分类:问答    c#   xaml   xamarin   xamarin.forms   master-detail

根据某些条件,在运行时 c# Winforms 中的 PropertyGrid 中使具有特定类别名称的所有属性不可见(Make all properties with specific Category name invisible in PropertyGrid in c# Winforms at Runtime based on some condition)

问题 我的应用程序中有一个属性 Grid,它在运行时显示所选控件的属性。 最近需要向现有控件添加一些额外的属性。 为了适应这一点,引入了一个新类别,在该类别下添加了较新的属性。 现在我正在寻找一种机制来根据应用程序中的运行时条件在运行时隐藏这些新添加的属性。 但我对此没有适当的解决方案。 新增代码: [ReadOnly(true)] [Browsable(true)] [Category("Extra")] public int? FormID { get; set; } [Browsable(true)] [Category("Extra")] public int? jrxml_Id { get; set; } 我期望的工作: [ReadOnly(true)] [Browsable(matchSomeRunTimeCondition)] [Category("Extra")] public int? FormID { get; set; } [Browsable(matchSomeRunTimeCondition)] [Category("Extra")] public int? jrxml_Id { get; set; } 为什么它不起作用? 因为Browsable Attribute 只能接受 Constant。

2022-01-25 05:38:44    分类:技术分享    c#   winforms   propertygrid

将值文本框插入mysql数据库(insert value textbox into mysql database)

问题 我在将文本框值插入 mysql 数据库时遇到问题 - 没有错误消息,也没有插入。 我究竟做错了什么 private void RegisterCustomer() { string firstname = txtfirstname.ToString(); OdbcConnection conn; conn = new OdbcConnection(ConfigurationManager.ConnectionStrings["jConnString"].ConnectionString); conn.Open(); string sql = "insert into klant (firstname) values (@firstname)"; OdbcCommand cmd = new OdbcCommand(sql, conn); cmd.Parameters.Add("@firstname", OdbcType.VarChar).Value = firstname; try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Check.Text += ex.ToString() + sql; } finally { conn.Close(); conn.Dispose(); Check.Text += "OK"; } }

2022-01-25 05:37:11    分类:技术分享    c#   mysql

将聚合写入 Azure 表存储(使用 Azure 函数)时出现“实体已存在”错误(Getting "Entity already exists" error writing aggregates to Azure Table Storage (with Azure Function))

问题 在 Azure 函数中,我试图聚合一些数据并将聚合写入表中。 我有一个汇总数据的查询: var query = recs .GroupBy(r => new { r.Category, r.Account, r.Record }) .Select(r => new ts_webhitaggregate_account { PartitionKey = partition, // Constant RowKey = $"{r.Key.Category}:{r.Key.Account}:{r.Key.Record}", // Group By rawDate = intervaldate, // Constant epochDate = intervalepoch, // Constant Category = r.Key.Category, // Group By Account = r.Key.Account, // Group By Record = r.Key.Record, // Group By Hits = r.Count(), // Aggregate Users = r.Select(t => t.User).Distinct().Count(), // Aggregate Devices = r.Select(t => t.Device).Distinct()

2022-01-25 05:36:46    分类:技术分享    c#   azure-table-storage   azure-functions

AWS Server-Side Encryption C#

Hi we are trying to use AWS S3 to upload and get files URL with Encryption . We are using this code to Upload: using (var client = GetS3ClientConnection(AccessKey, SecretKey, RegionEndpoint)) { var request = new PutObjectRequest { BucketName = FilePathInS3, Key = FileNameInS3, ServerSideEncryptionCustomerMethod = ServerSideEncryptionCustomerMethod.AES256, ServerSideEncryptionCustomerProvidedKey = base64Key //= "Is this ServerSideEncryptionKeyManagementServiceKeyId?" }; using (var ms = new MemoryStream(fileByteArray)) { request.InputStream = ms; client.PutObject(request); } } And this to Get

2022-01-25 05:36:09    分类:问答    c#   amazon-web-services   amazon-s3