c#-4.0

Save File in DocumentDb with custom name

ⅰ亾dé卋堺 提交于 2020-01-05 11:04:26
问题 I'm trying to save a XML file in DocumentDb in Json format. I have no problem in converting it and saving. All the conversion and saving are working fine. However when I store my Xml file the DocumentDB provides its own file name to the file. Eg; 8756b9b9-41ac-47ca-9f4c-abec60b318be . But I want to save the file with my own custom name Eg; MyXmlFile1 or MyXmlFile2 etc; How do I pass my custom name when saving the file? That is MyXmlFile1 or MyXmlFile2. "jsontoStore" has the content of the

How to make class truly Immutable? [duplicate]

那年仲夏 提交于 2020-01-05 10:16:13
问题 This question already has answers here : How do I create an immutable Class? (6 answers) Closed 6 years ago . I just looked into IReadOnlyList<T> to create readonly list. But I think it is not 100% readonly. I can not add/remove the item from the list but I can still modify the members. Consider this example. class Program { static void Main(string[] args) { List<Test> list = new List<Test>(); list.Add(new Test() { MyProperty = 10 }); list.Add(new Test() { MyProperty = 20 }); IReadOnlyList

Property value returned by DirectorySearcher and SearchResponse are of different type System._comobject and Byte array

左心房为你撑大大i 提交于 2020-01-05 10:08:41
问题 I am working on a website to manage active directory. I want to check that whether user has permission to change password or not. So I have to find "ntSecurityDescriptor" property value after that I have to cast it into IADsSecurityDescriptor. Now if I use DirectorySearcher class then property value is of type System._ComObject and easily casted to IADsSecurityDescriptor . But when I use LdapConnection and SearchResponse I get property value of type. byte[] array which is unale to cast to

Encrypting passwords in ASP.NET MVC 3

若如初见. 提交于 2020-01-05 09:03:07
问题 I'm trying to create a custom membership system in ASP.NET MVC3 . I know there are many free and open source providers, but I'm doing this to learn more. My question is about encrypting passwords. Which algorithm do you suggest I use: SHA1 , SHA256 , MD5 , BCrypt , or something else? Also, which way do you suggest to create a password salt? 回答1: BCrypt if you need really strong hash. As far as generating the salt is concerned, you could use the RNGCryptoServiceProvider class. Here's an

Passing dynamic arguments breaks fluent interfaces

跟風遠走 提交于 2020-01-05 08:43:15
问题 I have a set of so called fluent interfaces, so I can use syntax like this: a.With("abc").Do("this").Then("that); Each method returns an object cast to a corresponding interface. At design time I can use Intellisense to easily navigate between API methods. However I can no longer do it if I cast one of the arguments to a dynamic: a.With((dynamic)"abc").Do("this").Then("that); Not only I lose Intellisense at design time, this cast affects runtime execution: all subsequent calls after With

Input URL like http://example.com changes to http:/example.com in action input

混江龙づ霸主 提交于 2020-01-05 07:10:02
问题 I asked a question to get URL as action input here. Now I have a new problem. The passed URL to action changes from http://example.com to http:/example.com . I want to know why and how can I resolve the problem. P.S: I added this code to resolve but I think there may be another problems in future! the code is: if ((url.Contains(":/")) && !(url.Contains("://"))) { url = url.Replace(":/", "://"); } 回答1: The browser (or server) is replacing a double slash (illegal) with a single one. Try it,

Issue with Mutex getting lock before it was released and how to distribute locks equally?

丶灬走出姿态 提交于 2020-01-05 07:04:51
问题 The method GetItemSearchResponse will be called by multiple console application. But I wanted to call this method one by one. So I applied mutex. So that this method will be locked for other threads. public class AWSItemSearchClient : IDisposable { // the name of the global mutex; private const string MutexName = "FAA9569-7DFE-4D6D-874D-19123FB16CBC-8739827-[SystemSpecicString]"; private Mutex _globalMutex; private bool _owned = false; //This method call should be synchronized public

How to convert given data into IEnumerable object using LINQ

时光总嘲笑我的痴心妄想 提交于 2020-01-05 07:00:48
问题 I have below code in c# 4, where I am trying to use linq for ordering, grouping. IList<Component> components = Component.OrganizationalItem.OrganizationalItem.Components(true); IEnumerable<Component> baggage = components.Where(x => x.IsBasedOnSchema(Constants.Schemas.BaggageAllowance.ToString())) .OrderBy(x => x.ComponentValue("name").StringValue("Code")) .GroupBy(x => x.ComponentValue("name").StringValue("Code")); In above sample when I am trying to use GroupBy it is giving error, please see

Why client config shows wsHttpBinding when I have customBinding on server?

喜你入骨 提交于 2020-01-05 06:54:19
问题 I am using customBinding on my WCF web-service. But when I add service reference from Visual-Studio 2012, the configuration of the client shows wsHttpBinding as shown below: <bindings> <wsHttpBinding> <binding name="CustomBinding_IService1" /> </wsHttpBinding> </bindings> What is the reason behind this? My full server config can be found here:How to make WCF service server-client time difference independent? 回答1: Probably your custom binding is configured in a way that macthed the

“Unable to cast object” while looping through programatically created textboxes

百般思念 提交于 2020-01-05 05:35:30
问题 I have some Textboxes that are created dynamically -- int i = 1; while (reader.Read()) { System.Web.UI.WebControls.TextBox textBox = new System.Web.UI.WebControls.TextBox(); textBox.ID = reader["field_id"].ToString(); textBox.Enabled = false; HtmlGenericControl div = new HtmlGenericControl("div"); if(i%2 != 0) div.Attributes.Add("style", "margin-right:120px;padding-bottom:20px;"); if (i % 2 == 0) div.Attributes.Add("style", "padding-bottom:20px;"); div.Attributes.Add("class", "inline fourcol"