/// <summary> /// 定时清除无效的缓存 /// </summary> private static void CleanCache() { lock (syncLocker) { var oldCache = Cache.Values.OrderBy(o => o.LastCallDateTime) .ThenBy(o => o.CallCount) .Take(20) .Where(o => (DateTime.Now - o.LastCallDateTime).TotalMinutes > 5).ToArray(); foreach (var type in oldCache) { Cache.Remove(type.TypeGuid); } } }
/// <summary> /// Call this function if text is added to the temp file (the one that is compiled). /// Automatically clears itself when called with LineNumber==0. /// Note: PositionOfAddedLine==1 means at the very top was something inserted. /// </summary> /// <param name="LineNumber">indicates where lines are added</param> /// <param name="LineCount">indicates how many line are added at that location</param> public void AddOffset(int PositionOfAddedLine, int NumberOfAddedLines) { //if there are offsets below the just inserted one, then all lower offsets have to be shifted down accordingly. System.Collections.Generic.SortedDictionary <int, int> TempDict = new SortedDictionary <int, int>(); List <int> DeleteKeyList = new List <int>(); foreach (System.Collections.Generic.KeyValuePair <int, int> entry in LineOffsetDict) { if (PositionOfAddedLine <= entry.Key) { TempDict[entry.Key + NumberOfAddedLines] = LineOffsetDict[entry.Key] + NumberOfAddedLines; DeleteKeyList.Add(entry.Key); } else if (PositionOfAddedLine > entry.Key) { break; } } foreach (int key in DeleteKeyList) { LineOffsetDict.Remove(key); } foreach (System.Collections.Generic.KeyValuePair <int, int> entry in TempDict) { LineOffsetDict[entry.Key] = TempDict[entry.Key]; } LineOffsetDict.Add(PositionOfAddedLine, NumberOfAddedLines); }
public void ClearDirty(int attributeIndex) { DirtyAttributes.Remove(attributeIndex); if (OnChange != null) { OnChange(this, false, attributeIndex, null); } }
public override void Put(object Key, object Value) { if (Get(Key) == null) { TimeStamp++; Data.Add(Key, new LRUCacheValueEntry(TimeStamp, Value)); TimeStamps.Add(TimeStamp, Key); if (Data.Count > Capacity) { SortedDictionary <long, object> .Enumerator enumTimeStamps = TimeStamps.GetEnumerator(); enumTimeStamps.MoveNext(); long key = enumTimeStamps.Current.Key; Data.Remove(TimeStamps[key]); TimeStamps.Remove(key); } } }
void Scoreboard_RemoveWarlock(int _iSlotID) { if (!mPlayers.ContainsKey(_iSlotID)) { Debug.LogError("Attempted to remove player " + _iSlotID + ", but they do not exist!"); return; } mPlayers.Remove(_iSlotID); }
public static System.Collections.Generic.SortedDictionary <string, string> GetSortedParams(System.Web.HttpContext context) { System.Collections.Generic.SortedDictionary <string, string> sortedDictionary = new System.Collections.Generic.SortedDictionary <string, string>(); System.Collections.Specialized.NameValueCollection nameValueCollection = new System.Collections.Specialized.NameValueCollection { context.Request.Form, context.Request.QueryString }; string[] allKeys = nameValueCollection.AllKeys; for (int i = 0; i < allKeys.Length; i++) { sortedDictionary.Add(allKeys[i], nameValueCollection[allKeys[i]]); } sortedDictionary.Remove("HIGW"); return(sortedDictionary); }
//private static HttpSessionState session { get { return HttpContext.Current.Session; } } public static void CheckXSRF(Page page, HiddenField antiforgery) { string antiforgeryToken = string.Empty; antiforgeryToken = GenerateCustomizedCSRFToken(); System.Collections.Generic.SortedDictionary <string, string> l_CSRFTokenCollection = new System.Collections.Generic.SortedDictionary <string, string>(); if (!page.IsPostBack) { if (l_CSRFTokenCollection.ContainsKey(page.AppRelativeVirtualPath.ToUpper())) { l_CSRFTokenCollection.Remove(page.AppRelativeVirtualPath.ToUpper()); } l_CSRFTokenCollection.Add(page.AppRelativeVirtualPath.ToUpper(), antiforgeryToken); page.Session.Add("CSRFTokens", l_CSRFTokenCollection); antiforgery.Value = antiforgeryToken; antiforgeryToken = string.Empty; } else { if (page.Session["CSRFTokens"] == null) { throw new HttpException("Validation of Anti-XSRF token failed."); } l_CSRFTokenCollection = (System.Collections.Generic.SortedDictionary <string, string>)page.Session["CSRFTokens"]; if (!l_CSRFTokenCollection.ContainsKey(page.AppRelativeVirtualPath.ToUpper())) { throw new HttpException("Validation of Anti-XSRF token failed."); } if ((antiforgery.Value != l_CSRFTokenCollection[page.AppRelativeVirtualPath.ToUpper()])) { throw new HttpException("Validation of Anti-XSRF token failed."); } //l_CSRFTokenCollection.Remove(page.AppRelativeVirtualPath); //l_CSRFTokenCollection.Add(page.AppRelativeVirtualPath, antiforgeryToken); //page.Session.Add("CSRFTokens", l_CSRFTokenCollection); //antiforgery.Value = antiforgeryToken; } }
public static int LargestUniqueNumber(int[] A) { try { int ret = -1; ArrayList dummy = new ArrayList(); var m = new System.Collections.Generic.SortedDictionary <int, int>(); //taking a sorted dict Array.Sort(A); int n = A.Length; int[] arr = new int[A.Length]; for (int i = 0; i < n; i++) { if (!m.ContainsKey(A[i])) { m.Add(A[i], i); //adding char of string in key and index to value in dict } else { dummy.Add(A[i]);//if any repeated element hits it will be added to dummy lit } } foreach (int d in dummy) // for each repeated element in dummy loop remove the corresponding element from dict { if (m.ContainsKey(d)) { m.Remove(d); } } ret = m.Keys.Last();//returns the max i.e last key as it is sorted dict return(ret); } catch { return(-1); } }
public void ClearDirty(int attributeIndex) { DirtyAttributes.Remove(attributeIndex); OnChange?.Invoke(this, false, attributeIndex, null); }
public void RemoveState(IState <T> state) { stateDict_.Remove(state.Name); }