private void OnCurrentItemChangedAsync(MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args) { var newItem = args.NewItem; if (newItem == null) { return; } ChangeSelectItem(); if (newItem.Source.CustomProperties["Message"] is MusicBoardParameter para) { AppResources.MusicIsCurrent = para; } if (ServiceType == MusicServiceType.MHz) { ActionForMHz?.Invoke(); } CacheItems.Add(newItem); if (CacheItems.Count <= CacheMax || CacheItems.ToList().Exists(i => i.Source.CustomProperties["SHA256"] as string == newItem.Source.CustomProperties["SHA256"] as string)) { return; } CacheItems[0].Source.Reset(); CacheItems.RemoveAt(0); }
public override object Get(string key) { LogAction("Get", string.Format("Key: {0}", key)); DiskOutputCacheItem item = null; CacheItems.TryGetValue(key, out item); // Was the item found? if (item == null) { return(null); } // Has the item expired? if (item.UtcExpiry < DateTime.UtcNow) { // Item has expired this.Remove(key); return(null); } return(GetCacheData(item)); }
public static void FreeGo(CacheItem ir) { if (ir != null) { CacheItems v = GetCacheItem(ir.ResType, ir.ResName); v.SetCacheData(ir); } }
/// <summary> /// 重新取得資料,並判斷若尚未建立ObjectCache則自動新增 /// </summary> /// <returns></returns> public virtual List <MemberInfoModel> GetAllData() { if (!CacheItems.Exists("MemberInfoList")) { CreateSmsAppInfo(); } return(CacheItems.Get <List <MemberInfoModel> >("MemberInfoList")); }
public bool Remove(K key) { lock (lockObject) { if (ContainsKey(key)) { CacheItems.Remove(key); return(true); } return(false); } }
public LoginResponse Any(LoginRequest request) { LoginResponse response = new LoginResponse(); try { AutheticationRepository repository = new AutheticationRepository(); if (string.IsNullOrEmpty(request.EmailAddress)) { ValidationErrors.Errors.Add(new ValidationError { ErrorMessageResourceKey = "Bad Authetication", ErrorDescription = "Username is required" }); } else if (string.IsNullOrEmpty(request.Password)) { ValidationErrors.Errors.Add(new ValidationError { ErrorMessageResourceKey = "Bad Authetication", ErrorDescription = "Password is required" }); } else { var login = repository.CheckAuthetication(request.EmailAddress, request.Password); if (login != null && !repository.ValidationErrors.Errors.Any()) { response.EmailAddress = login.UserName; response.UserTypeID = login.RoleId; var guid = Guid.NewGuid().ToString(); CacheItems cacheItems = new CacheItems { AuthToken = guid }; CacheClient.Add(guid, cacheItems, new TimeSpan(0, 1, 0, 0)); response.AuthToken = guid; response.ResultSuccess = true; } else { response.ResultSuccess = false; } ValidationErrors.AddMany(repository.ValidationErrors); } } catch (Exception ex) { ValidationErrors.Add("LoginFail", "Failed to Login."); } finally { response.ResultMessages = Utility.GetAllValidationErrorCodesAndMessages(ValidationErrors); } return(response); }
/// <summary> /// 获取缓存结构,不存在则创建 /// </summary> /// <param name="resType"></param> /// <param name="resName"></param> /// <returns></returns> public static CacheItems GetCacheItem(string resType, string resName) { string key = resType + "/" + resName; if (pool.ContainsKey(key)) { return(pool[key]); } else { CacheItems v = new CacheItems(resType, resName); pool.Add(key, v); return(v); } }
/// <summary> /// 設定簡訊應用程式列表資料 /// </summary> void CreateSmsAppInfo() { try { DataTable dt = Dao.SelectUSP("dbo.uspSmsPlatformAppInfoList", null, null, Setting.ConnectionString("SmsPlatform")); List <SmsPlatformAppInfoModel> smsAppInfoDataList = new List <SmsPlatformAppInfoModel> { }; List <SmsPlatformAppSmsCorpModel> smsPlatformAppSmsCorpList = GetValidSmsAppSmsCorp(); if (dt != null) { foreach (DataRow cd in dt.Rows) { smsAppInfoDataList.Add(new SmsPlatformAppInfoModel { Id = Convert.ToInt32(cd["Id"].ToString()), ApplicationName = cd["ApplicationName"].ToString(), DepartmentId = Convert.ToInt32(cd["DepartmentId"].ToString()), ApplicationSn = new Guid(cd["ApplicationSn"].ToString()), IsValid = Convert.ToBoolean(cd["Valid"]), IsTest = Convert.ToBoolean(cd["IsTest"]), SentCount = Convert.ToInt32(cd["Count"].ToString()), CreatorId = Convert.ToInt32(cd["CreatorId"].ToString()), CreateOn = Convert.ToDateTime(cd["CreateOn"]).ToString("yyyy/MM/dd HH:mm:ss"), LastEditorId = cd["LastEditorId"] == DBNull.Value ? new int?() : Convert.ToInt32(cd["LastEditorId"]), LastEditOn = cd["LastEditorId"] == DBNull.Value ? "" : Convert.ToDateTime(cd["LastEditOn"]).ToString("yyyy/MM/dd HH:mm:ss"), AppSmsCorps = smsPlatformAppSmsCorpList.FindAll(p => p.AppInfoId == Convert.ToInt32(cd["Id"].ToString())), ActivityCount = Convert.ToInt32(cd["ActivityCount"].ToString()), ActivityEndTime = cd["ActivityEndTime"] == DBNull.Value ? "" : Convert.ToDateTime(cd["ActivityEndTime"]).ToString("yyyy/MM/dd HH:mm:ss"), ActivityUpperLimit = cd["ActivityUpperLimit"] == DBNull.Value ? new int?() : Convert.ToInt32(cd["ActivityUpperLimit"]), Reason = cd["Reason"].ToString() }); } } else { smsAppInfoDataList.Add(_defaultData); } DateTimeOffset policyDay = new DateTimeOffset(DateTime.Now.AddDays(Convert.ToDouble((Setting.GetConfig("CacheItemPolicy", "AbsoluteExpiration", "SmsPlatformAppInfo"))))); CacheItems.Add(smsAppInfoDataList, "SmsAppInfoList", policyDay, true); } catch (Exception ex) { throw new Exception("[SmsPlatformAppInfoDataCache.CreateSmsAppInfo]Error," + ex.Message); } }
/// <summary> /// Gets value from cache /// </summary> /// <typeparam name="T"></typeparam> /// <param name="item"></param> /// <param name="predicate"></param> /// <returns></returns> public T Get <T>(CacheItems item, Func <T> predicate) where T : class { Verify(); var key = item.ToString(); var result = Cache.Get(key) as T; if (result == null) { lock (_lock) { result = predicate(); Cache.Set(key, result); ItemsLastModified[key] = DateTime.Now; } } return(result); }
public async Task <T> GET <T>(string urlArguments, CacheItems cacheItem) { if (_cacheInterface.Exists(cacheItem)) { return(_cacheInterface.Get <T>(cacheItem, urlArguments).ReturnValue); } try { var str = await HC.GetStringAsync($"{BASEURL}{parseUrlArguments(urlArguments)}"); var result = JsonConvert.DeserializeObject <T>(str); _cacheInterface.Add(cacheItem, result, urlArguments); return(result); } catch (Exception ex) { return((T)Activator.CreateInstance(typeof(T), ex, ErrorCodes.HTTP_CLIENT_FAILED_TO_CONNECT)); } }
/// <summary> /// 获取资源缓存。 /// </summary> /// <param name="ResType"></param> /// <param name="ResName"></param> /// <returns></returns> public static GameObject GetCacheGo(string ResType, string ResName) { CacheItems v = FindCacheItem(ResType, ResName); if (v == null || v.Count == 0) { return(null); } CacheItem ir = v.goQueue.Dequeue(); if (ir == null) { return(null); } else { return(ir.gameObject); } }
public override void Remove(string key) { LogAction("Remove", string.Format("Key: {0}", key)); DiskOutputCacheItem item = null; this.CacheItems.TryGetValue(key, out item); if (item != null) { // Attempt to delete the cached content on disk and then remove the item from CacheItems... // If there is a problem, fail silently //try //{ RemoveCacheData(item); CacheItems.Remove(key); //} //catch { } } }
/// <summary> /// 预加载的加载接口 /// </summary> /// <param name="ResType"></param> /// <param name="ResName"></param> /// <param name="Count"></param> public static IEnumerator LoadGoCahce(string ResType, string ResName, int Count) { //包含此对象池,且有对象 CacheItems v = PoolManager.GetCacheItem(ResType, ResName); if (v.Count > 0) { yield return(v.CopyInstantiate(Count)); } else { // 为同步操作 GameObject prefab = null; ResourceManger.LoadPrefab(ResType, ResName, false, true, (g) => { prefab = g as GameObject; }); // 执行分帧加载。 if (prefab != null) { yield return(Yielders.EndOfFrame); GameObject go = GameObject.Instantiate(prefab); // 设置父亲结点 if (null != go) { CacheItem recycle = go.GetComponent <CacheItem>(); if (recycle == null) { recycle = go.AddComponent <CacheItem>(); } recycle.SetCacheKey(ResType, ResName); v.SetCacheData(recycle); yield return(Yielders.EndOfFrame); yield return(v.CopyInstantiate(Count)); } } } }
protected int GetLabelTextWidth(string labelText, Graphics g, Font f) { if (cacheItems == null) { cacheItems = new CacheItems(); } else if (cacheItems.useCompatTextRendering == ownerGrid.UseCompatibleTextRendering && cacheItems.lastLabel == labelText && f.Equals(cacheItems.lastLabelFont)) { return cacheItems.lastLabelWidth; } SizeF textSize = PropertyGrid.MeasureTextHelper.MeasureText( this.ownerGrid, g, labelText, f); cacheItems.lastLabelWidth = (int) textSize.Width; cacheItems.lastLabel = labelText; cacheItems.lastLabelFont = f; cacheItems.useCompatTextRendering = ownerGrid.UseCompatibleTextRendering; return cacheItems.lastLabelWidth; }
protected virtual void Dispose(bool disposing) { // make sure we don't accidentally // check flags in this state... flags |= FL_CHECKED; SetFlag(FLAG_DISPOSED, true); cacheItems = null; converter = null; editor = null; accessibleObject = null; if (disposing) { DisposeChildren(); } }
internal int GetValueTextWidth(string valueString, Graphics g, Font f) { if (this.cacheItems == null) { this.cacheItems = new CacheItems(); } else if (((this.cacheItems.lastValueTextWidth != -1) && (this.cacheItems.lastValueString == valueString)) && f.Equals(this.cacheItems.lastValueFont)) { return this.cacheItems.lastValueTextWidth; } this.cacheItems.lastValueTextWidth = (int) g.MeasureString(valueString, f).Width; this.cacheItems.lastValueString = valueString; this.cacheItems.lastValueFont = f; return this.cacheItems.lastValueTextWidth; }
protected int GetLabelTextWidth(string labelText, Graphics g, Font f) { if (this.cacheItems == null) { this.cacheItems = new CacheItems(); } else if (((this.cacheItems.useCompatTextRendering == this.ownerGrid.UseCompatibleTextRendering) && (this.cacheItems.lastLabel == labelText)) && f.Equals(this.cacheItems.lastLabelFont)) { return this.cacheItems.lastLabelWidth; } SizeF ef = PropertyGrid.MeasureTextHelper.MeasureText(this.ownerGrid, g, labelText, f); this.cacheItems.lastLabelWidth = (int) ef.Width; this.cacheItems.lastLabel = labelText; this.cacheItems.lastLabelFont = f; this.cacheItems.useCompatTextRendering = this.ownerGrid.UseCompatibleTextRendering; return this.cacheItems.lastLabelWidth; }
/// <include file='doc\GridEntry.uex' path='docs/doc[@for="GridEntry.ShouldSerializePropertyValue"]/*' /> /// <devdoc> /// Checks if this value should be persisited. /// </devdoc> internal virtual bool ShouldSerializePropertyValue() { if (cacheItems != null) { if (cacheItems.useShouldSerialize) { return cacheItems.lastShouldSerialize; } else { cacheItems.lastShouldSerialize = NotifyValue(NOTIFY_SHOULD_PERSIST); cacheItems.useShouldSerialize = true; } } else { cacheItems = new CacheItems(); cacheItems.lastShouldSerialize = NotifyValue(NOTIFY_SHOULD_PERSIST); cacheItems.useShouldSerialize = true; } return cacheItems.lastShouldSerialize; }
private string generateKey(CacheItems cacheItem, object objectID = null) => (objectID == null ? cacheItem.ToString() : $"{cacheItem}_{objectID}");
public ReturnSet <T> Get <T>(CacheItems cacheItem, object objectID = null) { return(!Exists(cacheItem) ? new ReturnSet <T>(ErrorCodes.CACHE_KEY_NOT_FOUND) : new ReturnSet <T>((T)HttpContext.Current.Cache[generateKey(cacheItem, objectID)])); }
public void Add <T>(CacheItems cacheItem, T value, object objectID = null) { HttpContext.Current.Cache.Add(generateKey(cacheItem, objectID), value, null, DateTime.MaxValue, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Default, null); }
internal int GetValueTextWidth(string valueString, Graphics g, Font f) { if (cacheItems == null) { cacheItems = new CacheItems(); } else if (cacheItems.lastValueTextWidth != -1 && cacheItems.lastValueString == valueString && f.Equals(cacheItems.lastValueFont)) { return cacheItems.lastValueTextWidth; } // Value text is rendered using GDI directly (No TextRenderer) but measured/adjusted using GDI+ (since previous releases), so don't use MeasureTextHelper. cacheItems.lastValueTextWidth = (int) g.MeasureString(valueString, f).Width; cacheItems.lastValueString = valueString; cacheItems.lastValueFont = f; return cacheItems.lastValueTextWidth; }
public virtual void PaintValue(object val, Graphics g, Rectangle rect, Rectangle clipRect, PaintValueFlags paintFlags) { string lastValueString; PropertyGridView gridEntryHost = this.GridEntryHost; int valuePaintIndent = 0; Color textColor = gridEntryHost.GetTextColor(); if (this.ShouldRenderReadOnly) { textColor = this.GridEntryHost.GrayTextColor; } if ((paintFlags & PaintValueFlags.FetchValue) != PaintValueFlags.None) { if ((this.cacheItems != null) && this.cacheItems.useValueString) { lastValueString = this.cacheItems.lastValueString; val = this.cacheItems.lastValue; } else { val = this.PropertyValue; lastValueString = this.GetPropertyTextValue(val); if (this.cacheItems == null) { this.cacheItems = new CacheItems(); } this.cacheItems.lastValueString = lastValueString; this.cacheItems.useValueString = true; this.cacheItems.lastValueTextWidth = -1; this.cacheItems.lastValueFont = null; this.cacheItems.lastValue = val; } } else { lastValueString = this.GetPropertyTextValue(val); } Brush backgroundBrush = this.GetBackgroundBrush(g); if ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) { backgroundBrush = SystemBrushes.Highlight; textColor = SystemColors.HighlightText; } Brush brush = backgroundBrush; g.FillRectangle(brush, clipRect); if (this.IsCustomPaint) { valuePaintIndent = gridEntryHost.GetValuePaintIndent(); Rectangle a = new Rectangle(rect.X + 1, rect.Y + 1, gridEntryHost.GetValuePaintWidth(), gridEntryHost.GetGridEntryHeight() - 2); if (!Rectangle.Intersect(a, clipRect).IsEmpty) { System.Drawing.Design.UITypeEditor uITypeEditor = this.UITypeEditor; if (uITypeEditor != null) { uITypeEditor.PaintValue(new PaintValueEventArgs(this, val, g, a)); } a.Width--; a.Height--; g.DrawRectangle(SystemPens.WindowText, a); } } rect.X += valuePaintIndent + gridEntryHost.GetValueStringIndent(); rect.Width -= valuePaintIndent + (2 * gridEntryHost.GetValueStringIndent()); bool boldFont = ((paintFlags & PaintValueFlags.CheckShouldSerialize) != PaintValueFlags.None) && this.ShouldSerializePropertyValue(); if ((lastValueString != null) && (lastValueString.Length > 0)) { Font f = this.GetFont(boldFont); if (lastValueString.Length > 0x3e8) { lastValueString = lastValueString.Substring(0, 0x3e8); } int num2 = this.GetValueTextWidth(lastValueString, g, f); bool flag2 = false; if ((num2 >= rect.Width) || this.GetMultipleLines(lastValueString)) { flag2 = true; } if (!Rectangle.Intersect(rect, clipRect).IsEmpty) { if ((paintFlags & PaintValueFlags.PaintInPlace) != PaintValueFlags.None) { rect.Offset(1, 2); } else { rect.Offset(1, 1); } Matrix transform = g.Transform; IntPtr hdc = g.GetHdc(); IntNativeMethods.RECT lpRect = IntNativeMethods.RECT.FromXYWH((rect.X + ((int) transform.OffsetX)) + 2, (rect.Y + ((int) transform.OffsetY)) - 1, rect.Width - 4, rect.Height); IntPtr hfont = this.GetHfont(boldFont); int crColor = 0; int clr = 0; Color color2 = ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) ? SystemColors.Highlight : this.GridEntryHost.BackColor; try { crColor = System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), System.Windows.Forms.SafeNativeMethods.RGBToCOLORREF(textColor.ToArgb())); clr = System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), System.Windows.Forms.SafeNativeMethods.RGBToCOLORREF(color2.ToArgb())); hfont = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont)); int nFormat = 0x2960; if (gridEntryHost.DrawValuesRightToLeft) { nFormat |= 0x20002; } if (this.ShouldRenderPassword) { if (passwordReplaceChar == '\0') { if (Environment.OSVersion.Version.Major > 4) { passwordReplaceChar = '●'; } else { passwordReplaceChar = '*'; } } lastValueString = new string(passwordReplaceChar, lastValueString.Length); } IntUnsafeNativeMethods.DrawText(new HandleRef(g, hdc), lastValueString, ref lpRect, nFormat); } finally { System.Windows.Forms.SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), crColor); System.Windows.Forms.SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), clr); hfont = System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont)); g.ReleaseHdcInternal(hdc); } if (flag2) { this.ValueToolTipLocation = new Point(rect.X + 2, rect.Y - 1); } else { this.ValueToolTipLocation = InvalidPoint; } } } }
/// <include file='doc\GridEntry.uex' path='docs/doc[@for="GridEntry.PaintValue"]/*' /> /// <devdoc> /// Paints the value portion of this GridEntry into the given Graphics object. This /// is called by the GridEntry host (the PropertyGridView) when this GridEntry is /// to be painted. /// </devdoc> public virtual void PaintValue(object val, System.Drawing.Graphics g, Rectangle rect, Rectangle clipRect, PaintValueFlags paintFlags) { PropertyGridView gridHost = this.GridEntryHost; Debug.Assert(gridHost != null, "No propEntryHost"); int cPaint = 0; Color textColor = gridHost.GetTextColor(); if (this.ShouldRenderReadOnly) { textColor = GridEntryHost.GrayTextColor; } string strValue; if ((paintFlags & PaintValueFlags.FetchValue) != PaintValueFlags.None) { if (cacheItems != null && cacheItems.useValueString) { strValue = cacheItems.lastValueString; val = cacheItems.lastValue; } else { val = this.PropertyValue; strValue = GetPropertyTextValue(val); if (cacheItems == null) { cacheItems = new CacheItems(); } cacheItems.lastValueString = strValue; cacheItems.useValueString = true; cacheItems.lastValueTextWidth = -1; cacheItems.lastValueFont = null; cacheItems.lastValue = val; } } else { strValue = GetPropertyTextValue(val); } // paint out the main rect using the appropriate brush Brush bkBrush = this.GetBackgroundBrush(g); Debug.Assert(bkBrush != null, "We didn't find a good background brush for PaintValue"); if ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) { bkBrush = gridHost.GetSelectedItemWithFocusBackBrush(g); textColor = gridHost.GetSelectedItemWithFocusForeColor(); } Brush blank = bkBrush; #if PBRS_PAINT_DEBUG blank = Brushes.Yellow; #endif //g.FillRectangle(blank, rect.X-1, rect.Y, rect.Width+1, rect.Height); g.FillRectangle(blank, clipRect); if (IsCustomPaint) { cPaint = gridHost.GetValuePaintIndent(); Rectangle rectPaint = new Rectangle(rect.X + 1, rect.Y + 1, gridHost.GetValuePaintWidth(), gridHost.GetGridEntryHeight() - 2); if (!Rectangle.Intersect(rectPaint, clipRect).IsEmpty) { UITypeEditor uie = UITypeEditor; if (uie != null) { uie.PaintValue(new PaintValueEventArgs(this, val, g, rectPaint)); } // paint a border around the area rectPaint.Width --; rectPaint.Height--; g.DrawRectangle(SystemPens.WindowText, rectPaint); } } rect.X += cPaint + gridHost.GetValueStringIndent(); rect.Width -= cPaint + 2 * gridHost.GetValueStringIndent(); // bold the property if we need to persist it (e.g. it's not the default value) bool valueModified = ((paintFlags & PaintValueFlags.CheckShouldSerialize) != PaintValueFlags.None) && ShouldSerializePropertyValue(); // If we have text to paint, paint it if (strValue != null && strValue.Length > 0) { Font f = GetFont(valueModified); if (strValue.Length > maximumLengthOfPropertyString) { strValue = strValue.Substring(0, maximumLengthOfPropertyString); } int textWidth = GetValueTextWidth(strValue, g, f); bool doToolTip = false; //subhag (66503) To check if text contains multiple lines // if (textWidth >= rect.Width || GetMultipleLines(strValue)) doToolTip = true; if (Rectangle.Intersect(rect, clipRect).IsEmpty) { return; } // Do actual drawing //strValue = ReplaceCRLF(strValue); // AS/URT 55015 // bump the text down 2 pixels and over 1 pixel. if ((paintFlags & PaintValueFlags.PaintInPlace) != PaintValueFlags.None) { rect.Offset(1, 2); } else { // only go down one pixel when we're painting in the listbox rect.Offset(1, 1); } Matrix m = g.Transform; IntPtr hdc = g.GetHdc(); IntNativeMethods.RECT lpRect = IntNativeMethods.RECT.FromXYWH(rect.X + (int)m.OffsetX + 2, rect.Y + (int)m.OffsetY - 1, rect.Width - 4, rect.Height); IntPtr hfont = GetHfont(valueModified); int oldTextColor = 0; int oldBkColor = 0; Color bkColor = ((paintFlags & PaintValueFlags.DrawSelected) != PaintValueFlags.None) ? GridEntryHost.GetSelectedItemWithFocusBackColor() : GridEntryHost.BackColor; try { oldTextColor = SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), SafeNativeMethods.RGBToCOLORREF(textColor.ToArgb())); oldBkColor = SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), SafeNativeMethods.RGBToCOLORREF(bkColor.ToArgb())); hfont = SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont)); int format = IntNativeMethods.DT_EDITCONTROL | IntNativeMethods.DT_EXPANDTABS | IntNativeMethods.DT_NOCLIP | IntNativeMethods.DT_SINGLELINE | IntNativeMethods.DT_NOPREFIX; if (gridHost.DrawValuesRightToLeft) { format |= IntNativeMethods.DT_RIGHT | IntNativeMethods.DT_RTLREADING; } // For password mode, Replace the string value either with * or a bullet, depending on the OS platform if (ShouldRenderPassword) { if (passwordReplaceChar == (char)0) { if (Environment.OSVersion.Version.Major > 4) { passwordReplaceChar = (char)0x25CF; // Bullet is 2022, but edit box uses round circle 25CF } else { passwordReplaceChar = '*'; } } strValue = new string(passwordReplaceChar, strValue.Length); } IntUnsafeNativeMethods.DrawText(new HandleRef(g, hdc), strValue, ref lpRect, format); } finally { SafeNativeMethods.SetTextColor(new HandleRef(g, hdc), oldTextColor); SafeNativeMethods.SetBkColor(new HandleRef(g, hdc), oldBkColor); hfont = SafeNativeMethods.SelectObject(new HandleRef(g, hdc), new HandleRef(null, hfont)); g.ReleaseHdcInternal(hdc); } #if PBRS_PAINT_DEBUG rect.Width --; rect.Height--; g.DrawRectangle(new Pen(Color.Purple), rect); #endif if (doToolTip) { this.ValueToolTipLocation = new Point(rect.X+2, rect.Y-1); } else { this.ValueToolTipLocation = InvalidPoint; } } return; }
internal virtual bool ShouldSerializePropertyValue() { if (this.cacheItems != null) { if (this.cacheItems.useShouldSerialize) { return this.cacheItems.lastShouldSerialize; } this.cacheItems.lastShouldSerialize = this.NotifyValue(4); this.cacheItems.useShouldSerialize = true; } else { this.cacheItems = new CacheItems(); this.cacheItems.lastShouldSerialize = this.NotifyValue(4); this.cacheItems.useShouldSerialize = true; } return this.cacheItems.lastShouldSerialize; }
/// <summary> /// Application specific configuration /// This method should initialize any IoC resources utilized by your web service classes. /// </summary> public override void Configure(Funq.Container container) { //Set JSON web services to return idiomatic JSON camelCase properties ServiceStack.Text.JsConfig.EmitCamelCaseNames = true; Plugins.Add(new CorsFeature( allowOriginWhitelist: new[] { "http://localhost", "http://localhost:3000" }, allowedHeaders: "Content-Type, Authorization, x-user-id" )); this.PreRequestFilters.Add((req, res) => { if (!req.AbsoluteUri.Contains("metadata")) { if (req.Verb != "OPTIONS") { var apiKey = req.Headers["Authorization"]; //apiKey = "D18F5B97-9FC2-4355-B293-0000044B8088"; if (apiKey == null || !Clients.VerifyKey(apiKey)) { res.StatusCode = 401; res.ContentType = "text/html"; res.Write("Error:" + "Invalid Api-Key"); //HttpResponse httpResponse = res.OriginalResponse as HttpResponse; //httpResponse.SuppressFormsAuthenticationRedirect = true; res.End(); } } } }); this.GlobalRequestFilters.Add((req, res, dto) => { var type = dto.GetType(); if (!req.AbsoluteUri.Contains("metadata") && (dto.GetType() != typeof(LoginRequest))) { var cacheClient = req.TryResolve <ICacheClient>(); string authToken = req.Headers["x-user-id"]; var cacheValue = cacheClient.Get <CacheItems>(authToken); Guid guid; Guid.TryParse(authToken, out guid); string responseMessage = string.Empty; bool IsFailure = false; //Checks Whether They Provided Valid AuthToken or not if (guid.ToString().Equals("00000000-0000-0000-0000-000000000000")) { responseMessage = "Error:Invalid Authentication"; IsFailure = true; } else if (cacheValue != null && authToken != cacheValue.AuthToken) { responseMessage = "Error:Invalid Authentication"; IsFailure = true; } else if (cacheValue == null) { responseMessage = "Error:Invalid Authentication or AuthToken Expired.please login again."; IsFailure = true; } if (IsFailure) { //res.StatusCode = 401; //res.Write(responseMessage); var httpResponse = (HttpResponseBase)res.OriginalResponse; httpResponse.StatusCode = 401; httpResponse.OutputStream.Write(responseMessage); httpResponse.SuppressFormsAuthenticationRedirect = true; res.End(); } } }); this.GlobalResponseFilters.Add((req, res, dto) => { if (!req.AbsoluteUri.Contains("metadata") && (dto.GetType() != typeof(LoginResponse))) { var cacheClient = req.TryResolve <ICacheClient>(); var authToken = req.Headers["x-user-id"]; var cacheValue = cacheClient.Get <CacheItems>(authToken); if (cacheValue != null) { CacheItems cacheItems = new CacheItems { UserType = cacheValue.UserType, AuthToken = cacheValue.AuthToken }; cacheClient.Replace(cacheValue.AuthToken, cacheItems, new TimeSpan(0, 1, 0, 0)); } else { res.StatusCode = 401; res.Write("Error:" + "Session Time Out"); res.End(); } } }); }
protected virtual void Dispose(bool disposing) { this.flags |= -2147483648; this.SetFlag(0x2000, true); this.cacheItems = null; this.converter = null; this.editor = null; this.accessibleObject = null; if (disposing) { this.DisposeChildren(); } }
/// <summary> /// Invalidate cache item /// </summary> /// <param name="key"></param> public void Invalidate(CacheItems key) { Cache.Remove(key.ToString()); }
public bool Exists(CacheItems cacheItem) => HttpContext.Current.Cache[cacheItem.ToString()] != null;