public override void ToStream(Stream output) { output.Write(TLUtils.SignatureToBytes(Signature)); Flags.ToStream(output); QueryId.ToStream(output); ToStream(output, NextOffset, Flags, (int)BotResultsFlags.NextOffset); ToStream(output, SwitchPM, Flags, (int)BotResultsFlags.SwitchPM); Results.ToStream(output); CacheTime.ToStream(output); Users.ToStream(output); }
private static int UpdateBatch(IEntity obj, String action, String condition, EntityInfo entityInfo) { if (obj == null) { throw new ArgumentNullException(); } if (strUtil.IsNullOrEmpty(action)) { logger.Info("no sql is executed : action String is empty"); return(0); } //action = action.Trim().ToLower(); //if (!action.StartsWith( "set" )) { // action = "set " + action; //} if (!action.Trim().ToLower().StartsWith("set")) { action = "set " + action; } condition = condition.Trim().ToLower(); if (!condition.StartsWith("where")) { condition = "where " + condition; } String sql = String.Format("update {0} {1} {2}", entityInfo.TableName, action, condition); logger.Info(LoggerUtil.SqlPrefix + "update sql : " + sql); List <IInterceptor> ilist = MappingClass.Instance.InterceptorList; for (int i = 0; i < ilist.Count; i++) { ilist[i].BeforUpdateBatch(obj.GetType(), action, condition); } IDbCommand cmd = DataFactory.GetCommand(sql, DbContext.getConnection(entityInfo)); int rowAffected = cmd.ExecuteNonQuery(); logger.Info("update : " + rowAffected + " records affected"); for (int i = 0; i < ilist.Count; i++) { ilist[i].AfterUpdateBatch(obj.GetType(), action, condition); } // update cache timestamp CacheTime.updateTable(entityInfo.Type); return(rowAffected); }
public override byte[] ToBytes() { return(TLUtils.Combine( TLUtils.SignatureToBytes(Signature), Flags.ToBytes(), QueryId.ToBytes(), ToBytes(NextOffset, Flags, (int)BotResultsFlags.NextOffset), ToBytes(SwitchPM, Flags, (int)BotResultsFlags.SwitchPM), Results.ToBytes(), CacheTime.ToBytes(), Users.ToBytes())); }
public static int DeleteBatch(String condition, EntityInfo entityInfo) { if (strUtil.IsNullOrEmpty(condition)) { return(0); } String deleteSql = new SqlBuilder(entityInfo).GetDeleteSql(condition); logger.Info(LoggerUtil.SqlPrefix + "delete sql : " + deleteSql); List <IInterceptor> ilist = MappingClass.Instance.InterceptorList; for (int i = 0; i < ilist.Count; i++) { ilist[i].BeforDeleteBatch(entityInfo.Type, condition); } var conn = DbContext.getConnection(entityInfo); if (conn.State == System.Data.ConnectionState.Closed) { conn.Open(); OrmHelper.initCount++; LogManager.GetLogger("Class:System.ORM.Operation.DeleteOperation Method:DeleteBatch").Info("数据库连接已开启【" + OrmHelper.initCount + "】"); } IDbCommand cmd = DataFactory.GetCommand(deleteSql, conn); int rowAffected = cmd.ExecuteNonQuery(); logger.Info("delete : " + rowAffected + " records affected"); cmd.Connection.Close(); if (!DbContext.shouldTransaction()) { if (conn.State == ConnectionState.Open) { conn.Close(); conn.Dispose(); OrmHelper.clostCount++; LogManager.GetLogger("Class:System.ORM.Operation.DeleteOperation Method:DeleteBatch").Info("数据库连接已关闭【" + OrmHelper.clostCount + "】"); } } for (int i = 0; i < ilist.Count; i++) { ilist[i].AfterDeleteBatch(entityInfo.Type, condition); } // update cache timestamp CacheTime.updateTable(entityInfo.Type); return(rowAffected); }
private static Result Insert(IEntity obj, EntityInfo entityInfo, Boolean isInsertParent) { Result result = Validator.Validate(obj, "insert"); if (result.HasErrors) { return(result); } if (isInsertParent && entityInfo.Parent != null) { IEntity objP = Entity.New(entityInfo.Type.BaseType.FullName); List <EntityPropertyInfo> eplist = Entity.GetInfo(objP).SavedPropertyList; foreach (EntityPropertyInfo info in eplist) { if (info.IsList) { continue; } objP.set(info.Name, obj.get(info.Name)); } ObjectDB.Insert(objP); obj.Id = objP.Id; } List <IInterceptor> ilist = MappingClass.Instance.InterceptorList; for (int i = 0; i < ilist.Count; i++) { ilist[i].BeforInsert(obj); } IDbCommand cmd = DataFactory.GetCommand(getInsertSql(entityInfo), DbContext.getConnection(entityInfo)); OrmHelper.SetParameters(cmd, "insert", obj, entityInfo); lock (objLock) { executeCmd(cmd, entityInfo, ref obj); } for (int i = 0; i < ilist.Count; i++) { ilist[i].AfterInsert(obj); } CacheUtil.CheckCountCache("insert", obj, entityInfo); result.Info = obj; CacheTime.updateTable(obj.GetType()); return(result); }
/// <summary> /// Save the Search settings to the settings file /// </summary> /// <param name="menuNode">XML-node for the search settings</param> public void Save(XmlNode searchNode) { string xpath; xpath = "./cacheTime"; SettingsHelper.SetSettingValue(xpath, searchNode, CacheTime.ToString()); xpath = "./resultListLength"; SettingsHelper.SetSettingValue(xpath, searchNode, ResultListLength.ToString()); xpath = "./defaultOperator"; SettingsHelper.SetSettingValue(xpath, searchNode, DefaultOperator.ToString()); }
private void ApplyCacheHeaders(HttpResponseMessage response, CacheTime cacheTime) { if (cacheTime.ClientTimeSpan > TimeSpan.Zero || MustRevalidate) { var cachecontrol = new CacheControlHeaderValue { MaxAge = cacheTime.ClientTimeSpan, MustRevalidate = MustRevalidate }; response.Headers.CacheControl = cachecontrol; } }
public static void Add <T>(string key, T value, CacheTime cacheTime, CacheExpiresType cacheExpiresType, CacheDependency dependencies, CacheItemPriority cacheItemPriority, CacheItemRemovedCallback callback) { //Remove(key); DateTime absoluteExpiration = GetAbsoluteExpiration(cacheTime, cacheExpiresType); TimeSpan slidingExpiration = GetSlidingExpiration(cacheTime, cacheExpiresType); if (cacheTime == CacheTime.NotRemovable) { cacheItemPriority = CacheItemPriority.NotRemovable; } HttpRuntime.Cache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration, cacheItemPriority, callback); }
private static TimeSpan GetSlidingExpiration(CacheTime cacheTime, CacheExpiresType cacheExpiresType) { if ((cacheTime == CacheTime.NotRemovable) || (cacheExpiresType == CacheExpiresType.Absolute)) { return(Cache.NoSlidingExpiration); } switch (cacheTime) { case CacheTime.Short: return(TimeSpan.FromMinutes(2.0)); case CacheTime.Long: return(TimeSpan.FromMinutes(20.0)); } return(TimeSpan.FromMinutes(5.0)); }
private static DateTime GetAbsoluteExpiration(CacheTime cacheTime, CacheExpiresType cacheExpiresType) { if ((cacheTime == CacheTime.NotRemovable) || (cacheExpiresType == CacheExpiresType.Sliding)) { return(Cache.NoAbsoluteExpiration); } switch (cacheTime) { case CacheTime.Short: return(DateTime.Now.AddMinutes(2.0)); case CacheTime.Long: return(DateTime.Now.AddMinutes(20.0)); } return(DateTime.Now.AddMinutes(5.0)); }
private void ApplyCacheHeaders(HttpResponseMessage response, CacheTime cacheTime) { if (cacheTime.ClientTimeSpan > TimeSpan.Zero || MustRevalidate || Private) { var cachecontrol = new CacheControlHeaderValue { MaxAge = cacheTime.ClientTimeSpan, MustRevalidate = MustRevalidate, Private = Private }; response.Headers.CacheControl = cachecontrol; } else if (NoCache) { response.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; response.Headers.Add("Pragma", "no-cache"); } }
public void SetCacheItem <T>(T item, string key, CacheTime cacheTime) { if (cacheTime <= 0 || key.Trim() == string.Empty) { throw new Exception(nameof(cacheTime) + " must be > 0 and " + nameof(key) + " can't be empty."); } var cacheEntryOptions = new DistributedCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromMinutes((int)cacheTime)); byte[] obj; using (MemoryStream ms = new MemoryStream()) { _binaryFormatter.Serialize(ms, item); obj = ms.ToArray(); } _distributedCache.Set(key, obj, cacheEntryOptions); }
public override int GetHashCode() { int hash = 1; if (passThroughMode_ != null) { hash ^= PassThroughMode.GetHashCode(); } if (cacheTime_ != null) { hash ^= CacheTime.GetHashCode(); } hash ^= ClusterMinHealthyPercentages.GetHashCode(); hash ^= headers_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private static DateTime GetAbsoluteExpiration(CacheTime cacheTime, CacheExpiresType cacheExpiresType) { if (cacheTime == CacheTime.NotRemovable || cacheExpiresType == CacheExpiresType.Sliding) { return(System.Web.Caching.Cache.NoAbsoluteExpiration); } switch (cacheTime) { case CacheTime.Short: return(DateTime.Now.AddMinutes(20)); default: case CacheTime.Default: case CacheTime.Normal: return(DateTime.Now.AddMinutes(60 * 24)); //一天 case CacheTime.Long: return(DateTime.Now.AddMinutes(60 * 24 * 365)); //一年 } }
private static DateTime GetAbsoluteExpiration(CacheTime cacheTime, CacheExpiresType cacheExpiresType) { if (cacheTime == CacheTime.NotRemovable || cacheExpiresType == CacheExpiresType.Sliding) { return(Cache.NoAbsoluteExpiration); } switch (cacheTime) { case CacheTime.Short: return(DateTime.Now.AddMinutes(2)); default: case CacheTime.Default: case CacheTime.Normal: return(DateTime.Now.AddMinutes(5)); case CacheTime.Long: return(DateTime.Now.AddMinutes(20)); } }
private static TimeSpan GetSlidingExpiration(CacheTime cacheTime, CacheExpiresType cacheExpiresType) { if (cacheTime == CacheTime.NotRemovable || cacheExpiresType == CacheExpiresType.Absolute) { return(System.Web.Caching.Cache.NoSlidingExpiration); } switch (cacheTime) { case CacheTime.Short: return(TimeSpan.FromMinutes(20)); default: case CacheTime.Default: case CacheTime.Normal: return(TimeSpan.FromMinutes(60 * 24)); //一天 case CacheTime.Long: return(TimeSpan.FromMinutes(60 * 24 * 365)); //一年 } }
public async Task Set <T>(string key, T item, CacheTime time = CacheTime.Normal, Provider?provider = null) { try { if (string.IsNullOrWhiteSpace(key) || EqualityComparer <T> .Default.Equals(item, default(T))) { return; } var itemStr = JsonSerializer.Serialize(item); key = GetKeyName(item.GetType(), key); await _cache.Set(provider ?? _initProject.Provider, key, new SetCacheModel() { Item = itemStr, ExpireTime = TimeSpan.FromSeconds((int)time) }); } catch (Exception e) { //_logger.Error(e); } }
protected virtual void ApplyCacheHeaders(HttpResponseMessage response, CacheTime cacheTime) { if (cacheTime.ClientTimeSpan > TimeSpan.Zero || MustRevalidate || AllowedCacheLocation != AllowedCacheLocation.Undefined) { var cachecontrol = new CacheControlHeaderValue { MaxAge = cacheTime.ClientTimeSpan, MustRevalidate = MustRevalidate, Private = AllowedCacheLocation == AllowedCacheLocation.Private, Public = AllowedCacheLocation == AllowedCacheLocation.Public }; response.Headers.CacheControl = cachecontrol; } else if (NoCache) { response.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; response.Headers.Add("Pragma", "no-cache"); } }
public static void AddCachingsProfiles(this MvcOptions mvcOptions, CacheTime cacheTime) { mvcOptions.CacheProfiles.Add("GetActions", new CacheProfile() { Duration = cacheTime.GetActions }); mvcOptions.CacheProfiles.Add("ActionsFilters", new CacheProfile() { Duration = cacheTime.ActionsFilters }); mvcOptions.CacheProfiles.Add("GetAlerts", new CacheProfile() { Duration = cacheTime.GetAlerts }); mvcOptions.CacheProfiles.Add("GetAlertById", new CacheProfile() { Duration = cacheTime.GetAlertById }); mvcOptions.CacheProfiles.Add("AlertsFilters", new CacheProfile() { Duration = cacheTime.AlertsFilters }); mvcOptions.CacheProfiles.Add("Dashboard", new CacheProfile() { Duration = cacheTime.Dashboard }); mvcOptions.CacheProfiles.Add("GetSecureScores", new CacheProfile() { Duration = cacheTime.GetSecureScores }); mvcOptions.CacheProfiles.Add("GetSecureDetails", new CacheProfile() { Duration = cacheTime.GetSecureDetails }); mvcOptions.CacheProfiles.Add("GetSubscriptions", new CacheProfile() { Duration = cacheTime.GetSubscriptions }); }
private static Result Update(IEntity obj, EntityInfo entityInfo) { Result result = Validator.Validate(obj, "update"); if (result.IsValid == false) { return(result); } List <IInterceptor> ilist = MappingClass.Instance.InterceptorList; for (int i = 0; i < ilist.Count; i++) { ilist[i].BeforUpdate(obj); } updateSingle(obj, entityInfo); if (entityInfo.Parent != null) { IEntity objParent = Entity.New(entityInfo.Parent.Type.FullName); setParentValueFromChild(objParent, obj); updateSingle(objParent, Entity.GetInfo(objParent)); } CacheUtil.CheckCountCache("insert", obj, entityInfo); for (int i = 0; i < ilist.Count; i++) { ilist[i].AfterUpdate(obj); } result.Info = obj; // update cache timestamp CacheTime.updateTable(entityInfo.Type); return(result); }
/// <summary> /// 添加缓存 /// </summary> /// <param name="cacheKey">关键字</param> /// <param name="context">Http上下文</param> /// <param name="obj">数据</param> /// <param name="ct">缓存时间</param> public void CacherCache(string cacheKey, HttpContext context, object obj, CacheTime ct) { if (obj != null) { context.Cache.Insert(cacheKey, obj, null, DateTime.Now.AddSeconds((int)ct), TimeSpan.Zero, CacheItemPriority.Normal, null); } }
public static void Set <T>(string key, T value, CacheTime cacheTime) { Set <T>(key, value, cacheTime, CacheExpiresType.Sliding, null, CacheItemPriority.NotRemovable, null); }
public string GetProperty(string propertyName, string format, CultureInfo formatProvider, UserInfo accessingUser, Scope currentScope, ref bool propertyNotFound) { string outputFormat = string.Empty; if (format == string.Empty) { outputFormat = "g"; } if (currentScope == Scope.NoSettings) { propertyNotFound = true; return(PropertyAccess.ContentLocked); } propertyNotFound = true; string result = string.Empty; bool isPublic = true; switch (propertyName.ToLowerInvariant()) { case "portalid": propertyNotFound = false; result = (PortalID.ToString(outputFormat, formatProvider)); break; case "displayportalid": propertyNotFound = false; result = (OwnerPortalID.ToString(outputFormat, formatProvider)); break; case "tabid": propertyNotFound = false; result = (TabID.ToString(outputFormat, formatProvider)); break; case "tabmoduleid": propertyNotFound = false; result = (TabModuleID.ToString(outputFormat, formatProvider)); break; case "moduleid": propertyNotFound = false; result = (ModuleID.ToString(outputFormat, formatProvider)); break; case "moduledefid": isPublic = false; propertyNotFound = false; result = (ModuleDefID.ToString(outputFormat, formatProvider)); break; case "moduleorder": isPublic = false; propertyNotFound = false; result = (ModuleOrder.ToString(outputFormat, formatProvider)); break; case "panename": propertyNotFound = false; result = PropertyAccess.FormatString(PaneName, format); break; case "moduletitle": propertyNotFound = false; result = PropertyAccess.FormatString(ModuleTitle, format); break; case "cachetime": isPublic = false; propertyNotFound = false; result = (CacheTime.ToString(outputFormat, formatProvider)); break; case "cachemethod": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(CacheMethod, format); break; case "alignment": propertyNotFound = false; result = PropertyAccess.FormatString(Alignment, format); break; case "color": propertyNotFound = false; result = PropertyAccess.FormatString(Color, format); break; case "border": propertyNotFound = false; result = PropertyAccess.FormatString(Border, format); break; case "iconfile": propertyNotFound = false; result = PropertyAccess.FormatString(IconFile, format); break; case "alltabs": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(AllTabs, formatProvider)); break; case "isdeleted": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(IsDeleted, formatProvider)); break; case "header": propertyNotFound = false; result = PropertyAccess.FormatString(Header, format); break; case "footer": propertyNotFound = false; result = PropertyAccess.FormatString(Footer, format); break; case "startdate": isPublic = false; propertyNotFound = false; result = (StartDate.ToString(outputFormat, formatProvider)); break; case "enddate": isPublic = false; propertyNotFound = false; result = (EndDate.ToString(outputFormat, formatProvider)); break; case "containersrc": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(ContainerSrc, format); break; case "displaytitle": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(DisplayTitle, formatProvider)); break; case "displayprint": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(DisplayPrint, formatProvider)); break; case "displaysyndicate": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(DisplaySyndicate, formatProvider)); break; case "iswebslice": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(IsWebSlice, formatProvider)); break; case "webslicetitle": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(WebSliceTitle, format); break; case "websliceexpirydate": isPublic = false; propertyNotFound = false; result = (WebSliceExpiryDate.ToString(outputFormat, formatProvider)); break; case "webslicettl": isPublic = false; propertyNotFound = false; result = (WebSliceTTL.ToString(outputFormat, formatProvider)); break; case "inheritviewpermissions": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(InheritViewPermissions, formatProvider)); break; case "isshareable": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(IsShareable, formatProvider)); break; case "isshareableviewonly": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(IsShareableViewOnly, formatProvider)); break; case "desktopmoduleid": isPublic = false; propertyNotFound = false; result = (DesktopModuleID.ToString(outputFormat, formatProvider)); break; case "friendlyname": propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.FriendlyName, format); break; case "foldername": propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.FolderName, format); break; case "description": propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.Description, format); break; case "version": propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.Version, format); break; case "ispremium": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(DesktopModule.IsPremium, formatProvider)); break; case "isadmin": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(DesktopModule.IsAdmin, formatProvider)); break; case "businesscontrollerclass": propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.BusinessControllerClass, format); break; case "modulename": propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.ModuleName, format); break; case "supportedfeatures": isPublic = false; propertyNotFound = false; result = (DesktopModule.SupportedFeatures.ToString(outputFormat, formatProvider)); break; case "compatibleversions": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.CompatibleVersions, format); break; case "dependencies": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.Dependencies, format); break; case "permissions": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.Permissions, format); break; case "defaultcachetime": isPublic = false; propertyNotFound = false; result = (ModuleDefinition.DefaultCacheTime.ToString(outputFormat, formatProvider)); break; case "modulecontrolid": isPublic = false; propertyNotFound = false; result = (ModuleControlId.ToString(outputFormat, formatProvider)); break; case "controlsrc": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(ModuleControl.ControlSrc, format); break; case "controltitle": propertyNotFound = false; result = PropertyAccess.FormatString(ModuleControl.ControlTitle, format); break; case "helpurl": propertyNotFound = false; result = PropertyAccess.FormatString(ModuleControl.HelpURL, format); break; case "supportspartialrendering": propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(ModuleControl.SupportsPartialRendering, formatProvider)); break; case "containerpath": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(ContainerPath, format); break; case "panemoduleindex": isPublic = false; propertyNotFound = false; result = (PaneModuleIndex.ToString(outputFormat, formatProvider)); break; case "panemodulecount": isPublic = false; propertyNotFound = false; result = (PaneModuleCount.ToString(outputFormat, formatProvider)); break; case "isdefaultmodule": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(IsDefaultModule, formatProvider)); break; case "allmodules": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(AllModules, formatProvider)); break; case "isportable": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(DesktopModule.IsPortable, formatProvider)); break; case "issearchable": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(DesktopModule.IsSearchable, formatProvider)); break; case "isupgradeable": isPublic = false; propertyNotFound = false; result = (PropertyAccess.Boolean2LocalizedYesNo(DesktopModule.IsUpgradeable, formatProvider)); break; case "adminpage": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.AdminPage, format); break; case "hostpage": isPublic = false; propertyNotFound = false; result = PropertyAccess.FormatString(DesktopModule.HostPage, format); break; } if (!isPublic && currentScope != Scope.Debug) { propertyNotFound = true; result = PropertyAccess.ContentLocked; } return(result); }
public static void Add <T>(string key, T value, CacheTime cacheTime, CacheExpiresType cacheExpiresType) { Add <T>(key, value, cacheTime, cacheExpiresType, null, CacheItemPriority.NotRemovable, null); }
public static ICache GetRuntimeCache(CacheTime cacheTime) { return new RuntimeCache(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { AzureConfiguration _azureConfiguration = new AzureConfiguration(); Configuration.Bind("AzureAd", _azureConfiguration); CacheTime _cacheTime = new CacheTime(); Configuration.Bind("CacheTime", _cacheTime); services.AddCors(options => { options.AddPolicy("AllowAllOrigins", builder => { builder.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin(); }); }); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddAzureAdBearer(options => Configuration.Bind("AzureAd", options)); services.AddMvc(options => { /// add custom binder to beginning of collection options.ModelBinderProviders.Insert(0, new AlertFilterValueBinderProvider()); /// add cach profiles from appsettings.json options.AddCachingsProfiles(_cacheTime); }) .AddJsonOptions(opt => opt.SerializerSettings .ContractResolver = new CamelCasePropertyNamesContractResolver()) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMemoryCache(); services.AddScoped <ITokenProvider, TokenProvider>(); services.AddScoped <IAlertService, AlertService>(); services.AddScoped <IActionService, ActionService>(); services.AddScoped <INotificationService, NotificationService>(); services.AddSingleton <IDemoExample>(instance => { return(new DemoExample(Convert.ToBoolean(Configuration["UseMockFilters"]))); }); services.AddScoped <IGraphServiceProvider>(instance => { return(new GraphServiceProvider(azureConfiguration: _azureConfiguration)); });; services.AddSingleton <IMemoryCacheHelper, MemoryCacheHelper>(); services.AddSignalR(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "wwwroot"; }); services.AddSwaggerGen(c => { c.SwaggerDoc("v3", new Info { Title = "MicrosoftGraph_Security_API_Sample", Version = "v3" }); c.AddSecurityDefinition("Bearer", new ApiKeyScheme() { Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = "header", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", new string[] { } } }); }); }
internal RuntimeCache(CacheTime cacheTime) : this((double)cacheTime) { }
public static void Add <T>(string key, T value, CacheTime cacheTime, CacheExpiresType cacheExpiresType, CacheDependency dependencies, CacheItemPriority cacheItemPriority) { Add <T>(key, value, cacheTime, cacheExpiresType, dependencies, CacheItemPriority.NotRemovable, null); }
private static void GetCacheType(ThreadOrderType orderType, out CacheTime? cacheTime, out CacheExpiresType expiresType, out int? minute) { minute = null; switch (orderType) { case ThreadOrderType.AllForumTopWeekViewThreads: case ThreadOrderType.ForumTopWeekViewThreads: cacheTime = null; minute = AllSettings.Current.CacheSettings.WeekPostCacheTime; expiresType = CacheExpiresType.Absolute; break; case ThreadOrderType.ForumTopDayViewThreads: case ThreadOrderType.AllForumTopDayViewThreads: cacheTime = null; minute = AllSettings.Current.CacheSettings.DayPostCacheTime; expiresType = CacheExpiresType.Absolute; break; case ThreadOrderType.MovedThreads: cacheTime = null; minute = 20; expiresType = CacheExpiresType.Absolute; break; default: cacheTime = CacheTime.Default; expiresType = CacheExpiresType.Sliding; break; } }
public static void Update(IEntity obj, String[] arrPropertyName, EntityInfo entityInfo) { if (obj == null) { throw new ArgumentNullException(); } StringBuilder builder = new StringBuilder(String.Empty); builder.Append("update "); builder.Append(entityInfo.TableName); builder.Append(" set "); for (int i = 0; i < arrPropertyName.Length; i++) { String columnName = entityInfo.GetColumnName(arrPropertyName[i]); builder.Append(columnName); builder.Append("="); builder.Append(entityInfo.Dialect.GetParameter(columnName)); builder.Append(","); } builder.Append(" where Id="); builder.Append(entityInfo.Dialect.GetParameter("Id")); String commandText = builder.ToString().Replace(", where", " where"); logger.Info(LoggerUtil.SqlPrefix + entityInfo.Name + "[" + entityInfo.TableName + "] Update Sql:" + commandText); List <IInterceptor> ilist = MappingClass.Instance.InterceptorList; for (int i = 0; i < ilist.Count; i++) { ilist[i].BeforUpdate(obj); } var conn = DbContext.getConnection(entityInfo); if (conn.State == System.Data.ConnectionState.Closed) { conn.Open(); OrmHelper.initCount++; LogManager.GetLogger("Class:System.ORM.Operation.UpdateOperation Method:Update").Info("数据库连接已开启【" + OrmHelper.initCount + "】"); } IDbCommand cmd = DataFactory.GetCommand(commandText, conn); for (int i = 0; i < arrPropertyName.Length; i++) { Object parameterValue = obj.get(arrPropertyName[i]); String columnName = entityInfo.GetColumnName(arrPropertyName[i]); DataFactory.SetParameter(cmd, columnName, parameterValue); } int id = obj.Id; DataFactory.SetParameter(cmd, "Id", id); cmd.ExecuteNonQuery(); if (!DbContext.shouldTransaction()) { if (conn.State == ConnectionState.Open) { conn.Close(); conn.Dispose(); OrmHelper.clostCount++; LogManager.GetLogger("Class:System.ORM.Operation.UpdateOperation Method:Update").Info("数据库连接已关闭【" + OrmHelper.clostCount + "】"); } } for (int i = 0; i < ilist.Count; i++) { ilist[i].AfterUpdate(obj); } // update cache timestamp CacheTime.updateTable(entityInfo.Type); CacheUtil.CheckCountCache("insert", obj, entityInfo); }
public static void Set <T>(string key, T value, CacheTime cacheTime, CacheExpiresType cacheExpiresType, CacheDependency dependencies, CacheItemPriority cacheItemPriority) { Set <T>(key, value, cacheTime, cacheExpiresType, dependencies, cacheItemPriority, null); }
private static Result Insert(IEntity obj, EntityInfo entityInfo, Boolean isInsertParent) { Result result = Validator.Validate(obj, "insert"); if (result.HasErrors) { return(result); } if (isInsertParent && entityInfo.Parent != null) { IEntity objP = Entity.New(entityInfo.Type.BaseType.FullName); List <EntityPropertyInfo> eplist = Entity.GetInfo(objP).SavedPropertyList; foreach (EntityPropertyInfo info in eplist) { if (info.IsList) { continue; } objP.set(info.Name, obj.get(info.Name)); } ObjectDb.Insert(objP); obj.Id = objP.Id; } List <IInterceptor> ilist = MappingClass.Instance.InterceptorList; for (int i = 0; i < ilist.Count; i++) { ilist[i].BeforInsert(obj); } var conn = DbContext.getConnection(entityInfo); if (conn.State == System.Data.ConnectionState.Closed) { conn.Open(); OrmHelper.initCount++; LogManager.GetLogger("Class:System.Data.InsertOperation Method:Insert").Info("数据库连接已开启【" + OrmHelper.initCount + "】"); } IDbCommand cmd = DataFactory.GetCommand(getInsertSql(entityInfo), conn); OrmHelper.SetParameters(cmd, "insert", obj, entityInfo); obj.Id = executeCmd(cmd, entityInfo); if (!DbContext.shouldTransaction()) { if (conn.State == ConnectionState.Open) { conn.Close(); conn.Dispose(); OrmHelper.clostCount++; LogManager.GetLogger("Class:System.ORM.Operation.InsertOperation Method:Insert").Info("数据库连接已关闭【" + OrmHelper.clostCount + "】"); } } for (int i = 0; i < ilist.Count; i++) { ilist[i].AfterInsert(obj); } CacheUtil.CheckCountCache("insert", obj, entityInfo); result.Info = obj; CacheTime.updateTable(obj.GetType()); return(result); }
protected virtual string CreateEtag(HttpActionExecutedContext actionExecutedContext, string cachekey, CacheTime cacheTime) { return(Guid.NewGuid().ToString()); }
public static void Set <T>(string key, T value, CacheTime cacheTime, CacheExpiresType cacheExpiresType, CacheDependency dependencies, CacheItemPriority cacheItemPriority, CacheItemRemovedCallback callback) { Add <T>(key, value, cacheTime, cacheExpiresType, dependencies, cacheItemPriority, callback); }