public APIAccess(String Appkey, String HMkey, String x2chua, String sidUA, String datUA, String RID, String RPW, String proxy) { //必要なキー等を初期化 this.AppKey = HttpUtility.UrlEncode(AppKey); this.HMKey = HttpUtility.UrlEncode(HMKey); this.X2chUA = X2chUA; this.SidUA = SidUA; this.DatUA = DatUA; this.Proxy = Proxy; m_HoboCheck = new Timer((o) => { //更新回数2回以下のデータを削除 var rmkey = from db in m_HoboCache.ToArray().AsParallel() where db.Value.Count < 2 select db.Key; HoboData value; foreach (var key in rmkey) { m_HoboCache.TryRemove(key, out value); } //更新回数5回以下のデータをリセット var rkey = from db in m_HoboCache.ToArray().AsParallel() where db.Value.Count <= 5 select db.Key; foreach (var key in rkey) { m_HoboCache[key].Count = 0; } //更新回数6回以上のデータを5にセット var skey = from db in m_HoboCache.ToArray().AsParallel() where db.Value.Count > 5 select db.Key; foreach (var key in skey) { m_HoboCache[key].Count = 5; } sidup += 8; if (sidup >= 24) { try { GetSid(); if (!GetSIDFailed) { ViewModel.OnModelNotice("SessionIDを更新しました。(自動更新)"); } GetSIDFailed = false; } catch (Exception err) { ViewModel.OnModelNotice("SessionIDの更新に失敗しました。\n" + err.ToString()); } sidup = 0; } m_HoboCheck.Change(3600000 * 8, Timeout.Infinite); }, null, 3600000 * 8, Timeout.Infinite); UpdateKey(HttpUtility.UrlEncode(Appkey), HttpUtility.UrlEncode(HMkey), x2chua, sidUA, datUA, RID, RPW, proxy); GetSIDFailed = false; }
private void CleanCache() { long[] remove = _cache .ToArray() .Where(kv => kv.Value.LastAccess < DateTime.Now.AddSeconds(-60)) .Select(kv => kv.Key) .ToArray(); if (remove.Any()) { RuntimeLog.Write("Removing {0} compressed files from cache: ", remove.Length); CacheEntry _; foreach (long r in remove) _cache.TryRemove(r, out _); } }
/// <summary> /// Method to cancel the working queue, see http://dotspatial.codeplex.com/discussions/473428 /// </summary> public void Clear() { _threadPool.Cancel(false); foreach (var request in _activeTileRequests.ToArray()) { int one; if (!_openTileRequests.ContainsKey(request.Key)) { if (!_activeTileRequests.TryRemove(request.Key, out one)) { _activeTileRequests.TryRemove(request.Key, out one); } } } _openTileRequests.Clear(); }
private void CleanCache() { long[] remove = _cache .ToArray() .Where(kv => kv.Value.LastAccess < DateTime.Now.AddSeconds(-60)) .Select(kv => kv.Key) .ToArray(); if (remove.Any()) { DebugLogger.DetailedWriteLine($"Removing {remove.Length} compressed files from cache: "); CacheEntry _; foreach (long r in remove) { _cache.TryRemove(r, out _); } } }
public void SerializeTest() { var obj1 = new FormatModel { Age = 18, Name = "老九" }; var formatter = new WebApiClient.Defaults.KeyValueFormatter(); var kvs = formatter.Serialize("pName", obj1, null) .ToDictionary(item => item.Key, item => item.Value); Assert.True(kvs.Count == 2); Assert.True(kvs["Name"] == "老九"); Assert.True(kvs["Age"] == "18"); kvs = formatter.Serialize("pName", 30, null) .ToDictionary(item => item.Key, item => item.Value); Assert.True(kvs.Count == 1); Assert.True(kvs["pName"] == "30"); var dic = new System.Collections.Concurrent.ConcurrentDictionary <string, object>(); dic.TryAdd("Key", "Value"); var formatter2 = new WebApiClient.Defaults.KeyValueFormatter(); var kvs2 = formatter2.Serialize("dic", dic, new FormatOptions { UseCamelCase = true }); var kvs3 = formatter2.Serialize("dic", dic.ToArray(), new FormatOptions { UseCamelCase = true }); Assert.True(kvs2.First().Key == "key"); Assert.True(kvs3.First().Key == "key"); Assert.True(formatter2.Serialize("null", null, null).Any()); }
public void TestLiteStringBuilderThreaded() { var list = new System.Collections.Concurrent.ConcurrentDictionary <int, string>(); System.Threading.Tasks.Parallel.For(0, 1000, (i) => { var fs = new StringHelper.LiteStringBuilder(1); fs.Append(GetString((char)(48 + (i % 10)))); list.TryAdd(i, fs.ToString()); }); var dic = list.ToArray(); for (var i = 0; i < 1000; i++) { var key = dic[i].Key; var value = dic[i].Value; var str = GetString((char)(48 + (key % 10))); if (string.Compare(str, value) != 0) { Assert.Fail("Not thread safe"); } } }
public void Update() { SoulProxy[] souls = _Souls.ToArray().Select(kv => kv.Value).ToArray(); foreach (SoulProxy soul in souls) { IPropertyIdValue change; while (soul.TryGetPropertyChange(out change)) { _LoadProperty(soul.Id, change.Id, change.Instance); } } lock (_EventFilter) { foreach (byte[] filter in _EventFilter) { _Queue.Push(ServerToClientOpCode.InvokeEvent, filter); } _EventFilter.Clear(); } }
static int _m_ToArray(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); System.Collections.Concurrent.ConcurrentDictionary <long, ulong> gen_to_be_invoked = (System.Collections.Concurrent.ConcurrentDictionary <long, ulong>)translator.FastGetCSObj(L, 1); { System.Collections.Generic.KeyValuePair <long, ulong>[] gen_ret = gen_to_be_invoked.ToArray( ); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }