private void UpdateInfo() { Dictionary <string, int> counts = new Dictionary <string, int>(); foreach (TreeNode fileNode in this.AssetTree.Nodes) { foreach (TreeNode typeNode in fileNode.Nodes) { AddCount(counts, typeNode.Name, typeNode.Nodes.Count); } } counts.Sort(); StringBuilder text = new StringBuilder("Total stats" + Environment.NewLine); string curLine; foreach (string key in counts.Keys) { curLine = key + ": " + counts[key]; if (Enum.IsDefined(typeof(Limits), key)) { Limits limit = (Limits)Enum.Parse(typeof(Limits), key); curLine += "/" + (int)limit; } text.Append(curLine + Environment.NewLine); } text.Append(Environment.NewLine); text.Append("Overwrites: " + this.totalOverwrites); this.TotalInfoTextBox.Text = text.ToString(); }
public void Sort_NullSource() { Dictionary <int, string> testValue = null; var result = testValue.Sort(); Assert.IsTrue(false, "If we've reached here, we didn't get expected exception"); }
public void Sort_NullSourceWithComparer() { Dictionary <int, string> testValue = null; var result = testValue.Sort(new ComparableExtensions.AscendingComparer <int>()); Assert.IsTrue(false, "If we've reached here, we didn't get expected exception"); }
public void Sort_NullComparer() { var testValue = new Dictionary <int, string>(); IComparer <int> comparer = null; var result = testValue.Sort(comparer); Assert.IsTrue(false, "If we've reached here, we didn't get expected exception"); }
public void Generate() { _anyError = false; var reflectedMethods = new Dictionary<string, MethodInfo>(); foreach (var type in typeof(RubyOps).Assembly.GetExportedTypes()) { if (type.IsDefined(typeof(ReflectionCachedAttribute), false)) { Console.WriteLine(type); ReflectMethods(reflectedMethods, type); } } var methods = reflectedMethods.Sort((m1, m2) => m1.Key.CompareTo(m2.Key)); if (_anyError) { Environment.ExitCode = 1; return; } using (TextWriter writer = new StreamWriter(File.Open(_outFile, FileMode.Create, FileAccess.Write))) { _output = new IndentedTextWriter(writer, " "); _output.NewLine = "\r\n"; WriteLicenseStatement(writer); _output.WriteLine("using System.Reflection;"); _output.WriteLine("using System.Diagnostics;"); _output.WriteLine("using IronRuby.Runtime;"); _output.WriteLine("using IronRuby.Builtins;"); _output.WriteLine("using Microsoft.Scripting.Utils;"); _output.WriteLine(); _output.WriteLine("namespace {0} {{", MethodCacheType.Namespace); _output.Indent++; _output.WriteLine("public static partial class {0} {{", MethodCacheType.Name); _output.Indent++; GenerateOps(methods); _output.WriteLine(); GenerateStringFactoryOps("CreateRegex"); GenerateStringFactoryOps("CreateMutableString"); GenerateStringFactoryOps("CreateSymbol"); GenerateOptimizedOps("Yield", BlockDispatcher.MaxBlockArity); GenerateOptimizedOps("YieldSplat", BlockDispatcher.MaxBlockArity); _output.Indent--; _output.WriteLine("}"); _output.Indent--; _output.WriteLine("}"); Debug.Assert(_output.Indent == 0); } }
/** * 生成饿了么请求的Signature * <p> * 代码copy并修改自:https://coding.net/u/napos_openapi/p/eleme-openapi-java-sdk/git/blob/master/src/main/java/eleme/openapi/sdk/utils/SignatureUtil.java * * @param appKey 平台应用的授权key * @param secret 平台应用的授权密钥 * @param timestamp 时间戳,单位秒。API服务端允许客户端请求最大时间误差为正负5分钟。 * @param action 饿了么请求的api方法 * @param token 用户授权的token * @param parameters 加密参数 * @return Signature */ public string generateElemeSignature(long timestamp, string action, string token) { Dictionary <string, object> dicList = new Dictionary <string, object>(); dicList.Add("app_key", config.ClientId); dicList.Add("timestamp", timestamp); var signStr = dicList.Sort().SpellParams(); string splice = $"{action}{token}{signStr}{config.ClientSecret}"; string calculatedSignature = hashMd5String(splice); return(calculatedSignature); }
public void SortTest_002() { var d = new Dictionary <int, string>(); d.Add(30, "Chris"); d.Add(54, "Rick"); d.Add(28, "Steve"); var actual = d.Sort(new SortTestComparer()); Assert.AreEqual("Steve", actual.Last().Value); Assert.AreEqual(54, actual.First().Key); }
public void Test_Sort() { var dictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); dictionary.Add("XYZ", "XYZVALUE"); dictionary.Add("ABC", "ABCVALUE"); var sortedDictionary = dictionary.Sort <string, string>(StringComparer.OrdinalIgnoreCase); var sortedDictionaryKeys = sortedDictionary.Keys.ToList(); Assert.AreEqual(sortedDictionaryKeys[0], "ABC"); Assert.AreEqual(sortedDictionaryKeys[1], "XYZ"); }
public void SortTest() { IDictionary<string, int> Test = new Dictionary<string, int>(); Test.Add("Q", 4); Test.Add("Z", 2); Test.Add("C", 3); Test.Add("A", 1); Test = Test.Sort(); string Value = ""; foreach (string Key in Test.Keys) Value += Key; Assert.Equal("ACQZ", Value); }
public void SortByValueTest() { IDictionary<string, int> Test = new Dictionary<string, int>(); Test.Add("Q", 4); Test.Add("Z", 2); Test.Add("C", 3); Test.Add("A", 1); Test = Test.Sort(x => x.Value); string Value = ""; foreach (string Key in Test.Keys) Value += Test[Key].ToString(); Assert.Equal("1234", Value); }
public void TestSort() { // Arrange var notSortedDictionary = new Dictionary <int, string> { { 1, "a" }, { 3, "c" }, { 2, "b" } }; var sortedDictionary = new Dictionary <int, string> { { 1, "a" }, { 2, "b" }, { 3, "c" }, }; // Act var result = notSortedDictionary.Sort(); var sortByCompareResult = notSortedDictionary.Sort(new ComparableExtensions.AscendingComparer <int>()); // Assert result.Should().Equal(sortedDictionary); result.Should().Not.Equal(notSortedDictionary); sortByCompareResult.Should().Equal(sortedDictionary); }
static async Task <Dictionary <string, int> > ClassNamesFromCss(string cssFile) { var css = await File.ReadAllTextAsync(cssFile); var classNames = new Dictionary <string, int>(); Parser.ParseCSS(css) .Where(c => c.CharacterCategorisation == CharacterCategorisationOptions.SelectorOrStyleProperty && c.Value.StartsWith('.')) .SelectMany(c => c.Value.Split('.', StringSplitOptions.RemoveEmptyEntries)) .Select(c => c.Split(':').First()) // Remove elemant state: btn:hover .Select(c => Regex.Replace(c, "\\[.+?\\]", "")) // Remove attribute selector: btn-default[disabled] .ToList() .ForEach(name => classNames.AppendCount(name.TrimEnd(','))); return(classNames.Sort()); }
public void SortTest() { IDictionary <string, int> Test = new Dictionary <string, int>(); Test.Add("Q", 4); Test.Add("Z", 2); Test.Add("C", 3); Test.Add("A", 1); Test = Test.Sort(); string Value = ""; foreach (string Key in Test.Keys) { Value += Key; } Assert.Equal("ACQZ", Value); }
private static void Test() { IDictionary <string, string> dic = new Dictionary <string, string> { { "call", "3" }, { "bitch", "2" }, { "away", "1" } }; var sortedDic = dic.Sort <string, string>(); sortedDic.Print(); Console.WriteLine("OldVersion"); var sortedDic2 = dic.SortOldVersion <string, string>(); sortedDic2.Print(); }
public void SortByValueTest() { IDictionary <string, int> Test = new Dictionary <string, int>(); Test.Add("Q", 4); Test.Add("Z", 2); Test.Add("C", 3); Test.Add("A", 1); Test = Test.Sort(x => x.Value); string Value = ""; foreach (string Key in Test.Keys) { Value += Test[Key].ToString(); } Assert.Equal("1234", Value); }
public void Sort_CollectionNull() { Dictionary <int, int> dictionary = null; dictionary.Sort(new Comparison <KeyValuePair <int, int> >( (kvp1, kvp2) => { if (kvp1.Value < kvp2.Value) { return(-1); } if (kvp1.Value > kvp2.Value) { return(1); } return(0); })); }
/// <summary> /// 获取JS-SDK配置信息 /// </summary> /// <param name="AppId">AppId为空时默认取配置文件appSettings节点key=WeChatAppId</param> /// <param name="jsapi_ticket">jsapi_ticket</param> /// <param name="url">url(当前网页的URL,不包含#及其后面部分,要用Request.Url.AbsoluteUri,否则会存在编码问题)</param> /// <returns></returns> public static Models.JSSDK.JSSDKConfig GetConfig(string AppId, string jsapi_ticket, string url) { if (string.IsNullOrWhiteSpace(jsapi_ticket)) { throw new ArgumentNullException(nameof(jsapi_ticket)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException(nameof(url)); } AppId = string.IsNullOrWhiteSpace(AppId) ? Privacy.AppId : AppId; Models.JSSDK.JSSDKConfig config = new Models.JSSDK.JSSDKConfig(); config.appId = AppId; url = Common.CleanUrl(url); //移除url里面#及#后面的部分 config.timestamp = Common.ConvertTime(DateTime.Now); config.nonceStr = RandomCode.createRandomCode(16, true); //生成16位随机字符串,数字,大写英文字母,小写英文字母 /* * 关于URL编码导致签名错误的问题: * 微信建议:确认url是页面完整的url(请在当前页面alert(location.href.split('#')[0])确认),包括'http(s)://'部分,以及'?'后面的GET参数部分,但不包括'#'hash后面的部分。 * 注意必须以http://或https://开头,分别支持80端口和443端口。其它协议或端口都不行! */ /* * 对所有待签名参数按照字段名的ASCII 码从小到大排序(字典序)后,使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串string1。 * 这里需要注意的是所有参数名均为小写字符。对string1作sha1加密,字段名和字段值都采用原始值,不进行URL 转义。 */ Dictionary <string, string> WeiXinUrlParameters = new Dictionary <string, string>(); WeiXinUrlParameters.Add("jsapi_ticket", jsapi_ticket); WeiXinUrlParameters.Add("noncestr", config.nonceStr); WeiXinUrlParameters.Add("timestamp", config.timestamp.ToString()); WeiXinUrlParameters.Add("url", url); string stringTemp = WeiXinUrlParameters.Sort().ToURLParameter(); /* * 对string1进行sha1签名,得到signature */ config.signature = Common.SHA1Encrypt(stringTemp); return(config); }
public void SortTest() { IDictionary <string, int> Test = new Dictionary <string, int> { { "Q", 4 }, { "Z", 2 }, { "C", 3 }, { "A", 1 } }; Test = Test.Sort(); var Value = ""; foreach (var Key in Test.Keys) { Value += Key; } Assert.Equal("ACQZ", Value); }
public void SortByValueTest() { IDictionary <string, int> Test = new Dictionary <string, int> { { "Q", 4 }, { "Z", 2 }, { "C", 3 }, { "A", 1 } }; Test = Test.Sort(x => x.Value); var Value = ""; foreach (var Key in Test.Keys) { Value += Test[Key].ToString(); } Assert.Equal("1234", Value); }
public void Should_Sort_Processor_Chains_Even_When_Added_Out_Of_Order() { Dictionary<int, IEventProcessor> unsortedChain = new Dictionary<int, IEventProcessor>(); // mock a few processors var procMock1 = new Mock<IEventProcessor>(); var procMock2 = new Mock<IEventProcessor>(); var procMock3 = new Mock<IEventProcessor>(); // add them out of order unsortedChain.Add(2, procMock2.Object); unsortedChain.Add(3, procMock3.Object); unsortedChain.Add(1, procMock1.Object); IEnumerable<IEventProcessor> sortedChain = unsortedChain.Sort(); Assert.AreSame(procMock1.Object, sortedChain.ElementAt(0)); Assert.AreSame(procMock2.Object, sortedChain.ElementAt(1)); Assert.AreSame(procMock3.Object, sortedChain.ElementAt(2)); }
public void Should_Sort_Processor_Chains_Even_When_Added_Out_Of_Order() { var unsortedChain = new Dictionary <int, IEnvelopeProcessor>(); // mock a few processors var procMock1 = new Mock <IEnvelopeProcessor>(); var procMock2 = new Mock <IEnvelopeProcessor>(); var procMock3 = new Mock <IEnvelopeProcessor>(); // add them out of order unsortedChain.Add(2, procMock2.Object); unsortedChain.Add(3, procMock3.Object); unsortedChain.Add(1, procMock1.Object); IEnumerable <IEnvelopeProcessor> sortedChain = unsortedChain.Sort(); Assert.AreSame(procMock1.Object, sortedChain.ElementAt(0)); Assert.AreSame(procMock2.Object, sortedChain.ElementAt(1)); Assert.AreSame(procMock3.Object, sortedChain.ElementAt(2)); }
private void Test() { UrlEncode("https://mws.amazonservices.com/a+b*c%7e/"); IDictionary <string, string> dic = new Dictionary <string, string> { { "call", "3" }, { "bitch", "2" }, { "away", "1" } }; CaculateStringToSignV2(dic, "https://mws.amazonservices.com/"); var sortedDic = dic.Sort <string, string>(); sortedDic.Print(); Console.WriteLine("next"); var sortedDic2 = dic.SortOldVersion <string, string>(); sortedDic2.Print(); }
public static void Save_stage_position_csv() { string path = "Assets/Game/Config/stage_position.csv"; Dictionary <int, List <StagePositionConfig> > stagePositionConfigs = War.model.stagePositionConfigs; stagePositionConfigs.Sort <List <StagePositionConfig> >(); if (File.Exists(path)) { File.Delete(path); } FileStream fs = new FileStream(path, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); string head1 = "关卡编号;建筑编号;X坐标;Y坐标;人口配置;势力ID;单位类型;建筑类型;建筑等级;建筑参数;英雄上阵优先级;备注;备注"; string head2 = "stageId;buldIndex;X;y;hp;legionId;unitType;buildType;buldLeve;typeUid;settledPriority;ps2;ps1"; sw.WriteLine(head1); sw.WriteLine(head2); foreach (var stagePositionList in stagePositionConfigs) { foreach (StagePositionConfig positionConfig in stagePositionList.Value) { sw.WriteLine(positionConfig.ToCsv()); } } sw.Close(); fs.Close(); // AssetDatabase.Refresh(); Debug.Log(path); }
/// <summary> /// 微信反馈的支付通知参数的支付签名 /// AppSignature 依然是根据 2.7 节支付签名 (paySign) 签名方式生成, 参与签名的字段为:appid、appkey、timestamp、noncestr、openid、issubscribe。 /// </summary> /// <param name="timestamp"></param> /// <param name="noncestr"></param> /// <param name="openid"></param> /// <param name="issubscribe"></param> /// <param name="signType"></param> /// <returns></returns> public static string GetNotifyAppSignature(string timestamp, string noncestr, string openid, string issubscribe, string signType = "SHA1") { /* * 参与 paySign 签名的字段包括:appid、timestamp、noncestr、package 以及 appkey(即paySignkey) 。这里 signType 并不参与签名。 */ Dictionary <string, string> paySignParams = new Dictionary <string, string>() { { "appid", Common.AppId }, { "timestamp", timestamp }, { "noncestr", noncestr }, { "openid", openid }, { "issubscribe", issubscribe }, { "appkey", Privacy.AppKey } }; /* * a.对所有待签名参数按照字段名的 ASCII 码从小到大排序(字典序)后, * 使用 URL 键值对的格式(即 key1=value1&key2=value2…)拼接成字符串 string1。 * 这里需要注意的是所有参数名均为小写字符,例如 appId 在排序后字符串则为 appid; */ string string1 = paySignParams.Sort().ToURLParameter(); /* * b.对 string1 作签名算法, 字段名和字段值都采用原始值 (此时 package 的 value 就对应了使用 2.6 中描述的方式生成的 package),不进行 URL 转义。 * 具体签名算法为 paySign = SHA1(string)。 */ string paySign = string.Empty; if (signType.ToUpper() == "SHA1") { paySign = Common.SHA1Encrypt(string1); } else { paySign = Common.MD5Encrypt(string1); } return(paySign); }
/// <summary> /// 签名参数 /// </summary> /// <param name="param"></param> /// <param name="appKey"></param> /// <param name="signType"></param> /// <returns></returns> public static string SignParam(Dictionary <string, string> param, string appKey, string signType) { if (param == null || param.Count == 0) { return(""); } if (signType.Equals(SignTypeValue.MD5.ToString())) { param.Add("key", appKey); // 去除空值并排序之后组装 var blankStr = param.Sort <string>().BuildUrlQuery <string>(); return(Md5Encrypt(blankStr)); } else if (signType.Equals(SignTypeValue.RSA.ToString())) { var str = param.BuildUrlQuery <string>(); return(Encrypt(str, appKey, RSAEncryptionPadding.Pkcs1)); } else { return(""); } }
public WeChatJsConfiguration GenerateWeChatJsConfigurationWithSignature(string jsTicket, string url) { var jsConfig = new WeChatJsConfiguration { NonceString = NonceString(), Timestamp = TimeStamp() }; var dataList = new Dictionary<string, string> { {"noncestr", jsConfig.NonceString}, {"timestamp", jsConfig.Timestamp.ToString() }, {"jsapi_ticket", jsTicket}, {"url", url} }.ToList(); dataList.Sort(ParameterKeyComparison); var queryString = dataList.Aggregate(string.Empty, (query, item) => string.Concat(query, "&", item.Key, "=", item.Value)).TrimStart('&'); using (var sha1 = new SHA1CryptoServiceProvider()) { var hashed = sha1.ComputeHash(Encoding.Default.GetBytes(queryString)); jsConfig.Signature = HexStringFromBytes(hashed); return jsConfig; } }
public WeChatJsConfiguration GenerateWeChatJsConfigurationWithSignature(string jsTicket, string url) { var jsConfig = new WeChatJsConfiguration { NonceString = NonceString(), Timestamp = TimeStamp() }; var dataList = new Dictionary <string, string> { { "noncestr", jsConfig.NonceString }, { "timestamp", jsConfig.Timestamp.ToString() }, { "jsapi_ticket", jsTicket }, { "url", url } }.ToList(); dataList.Sort(ParameterKeyComparison); var queryString = dataList.Aggregate(string.Empty, (query, item) => string.Concat(query, "&", item.Key, "=", item.Value)).TrimStart('&'); using (var sha1 = SHA1.Create()) { var hashed = sha1.ComputeHash(Encoding.GetEncoding(0).GetBytes(queryString)); jsConfig.Signature = HexStringFromBytes(hashed); return(jsConfig); } }
internal int Generate(Crossword crossword, Dictionary dictionary) { if (dictionary.DictionaryWords.Length == 0) { return -1; } int blankIterations = 0; int wordsHaveBeenAdded = 0; dictionary.Sort(new DictionaryWordComparator(DictionaryWordComparator.SortDirection.Descending, DictionaryWordComparator.SortBy.LetterCount)); int iterationNumber = 0; while (blankIterations < 100) { iterationNumber++; var dictionaryWord = dictionary.GetRandomDictionaryWord(iterationNumber < 10 ? 0.3 : 1); var positions = crossword.GetPreviewsPositions(dictionaryWord); if (positions != null) { if (positions.Count == 0) { blankIterations++; continue; } var position = positions[random.Next(0, positions.Count)]; // range: [0; positions.Count - 1] var crosswordWord = new CrosswordWord(crossword, dictionaryWord, position.Position, false); crossword.AddWord(crosswordWord); wordsHaveBeenAdded = 1; } else { Orientation orientation = random.Next(2) > 0 ? Orientation.Horizontal : Orientation.Vertical; crossword.AddWord(new CrosswordWord(crossword, dictionaryWord, new CrosswordWordPosition(0, 0, orientation), false)); wordsHaveBeenAdded = 1; } blankIterations = 0; } return wordsHaveBeenAdded; }
public void Sort_ComparisonNull() { Dictionary <int, int> dictionary = new Dictionary <int, int>(); dictionary.Sort(null); }
public void Sort_ComparisonNull() { Dictionary<int, int> dictionary = new Dictionary<int, int>(); dictionary.Sort(null); }
static async Task WriteCsv(Dictionary <string, int> classNames, string file) { var names = classNames.Sort().Select(pair => $"{pair.Key},{pair.Value}"); var lines = names.Prepend("class,count"); await File.WriteAllLinesAsync(file, lines); }
static async Task WriteCsv(Dictionary <string, Pair> join, string file, string leftLabel, string rightLabel) { var names = join.Sort().Select(pair => $"{pair.Key},{pair.Value.Left},{pair.Value.Right}"); var lines = names.Prepend($"class,{leftLabel},{rightLabel}"); await File.WriteAllLinesAsync(file, lines); }