public void Disabled(global::Orchard.Environment.Extensions.Models.Feature feature) { if (feature.Descriptor.Name == "Laser.Orchard.Accessibility") { // imposta la cache in modo che non tenga più conto del cookie "Accessibility" var cacheSettings = _services.WorkContext.CurrentSite.ContentItem.Parts.OfType <CacheSettingsPart>().First(); if (cacheSettings != null) { string vary = cacheSettings.VaryByRequestCookies ?? ""; List <string> cookieList = vary.Split(',').ToList(); if (cookieList.Contains(Utils.AccessibilityCookieName)) { cookieList.Remove(Utils.AccessibilityCookieName); vary = string.Join(",", cookieList); cacheSettings.VaryByRequestCookies = vary; _signals.Trigger(CacheSettings.CacheKey); } } // svuota la cache _cacheStorageProvider.RemoveAll(); } }
public void Sweep() { DateTime?nextUpdate = _cache.Get <string, DateTime?>(NEXT_UPDATE_CACHE_KEY, ctx => { ctx.Monitor(_signals.When(NEXT_UPDATE_CACHE_KEY)); return(_clock.UtcNow.AddHours(6)); }); string oldFiles = _cache.Get <string, string>(MODEL_FILES_HASH_CACHE_KEY, ctx => { ctx.Monitor(_signals.When(MODEL_FILES_HASH_CACHE_KEY)); return(getNewBlockModelFilesHash()); }); if (_clock.UtcNow > nextUpdate.GetValueOrDefault()) { _signals.Trigger(NEXT_UPDATE_CACHE_KEY); _modelService.CheckModels(); //Removes models over 3 months (set in SQL SP) string newfiles = getNewBlockModelFilesHash(); if (oldFiles != newfiles) { _signals.Trigger(MODEL_FILES_HASH_CACHE_KEY); _projectService.EmailAllProjectOwners("New Model Uploaded", "A new model has been uploaded, and is ready for import into a project into NKD."); } Logger.Information(string.Format("Successfully updated old models (synchronisation completed).", DateTime.UtcNow.ToLongDateString())); } }
public void SetIndexSettings(IEnumerable <IndexSettingsModel> settings) { foreach (var item in settings) { var item1 = item; var record = _settingsRepository.Fetch(q => q.ContentType == item1.Name).FirstOrDefault(); if (record == null) { record = new SitemapSettingsRecord(); record.ContentType = item.Name; record.IndexForDisplay = item.IndexForDisplay; record.IndexForXml = item.IndexForXml; record.Priority = item.Priority; record.UpdateFrequency = item.UpdateFrequency; _settingsRepository.Create(record); } else { record.IndexForDisplay = item.IndexForDisplay; record.IndexForXml = item.IndexForXml; record.Priority = item.Priority; record.UpdateFrequency = item.UpdateFrequency; _settingsRepository.Update(record); } } _signals.Trigger("WebAdvanced.Sitemap.IndexSettings"); }
public IdentityResult CreateAdminUser(User user, string password, List <string> roles) { //不是最佳做法,没有事务回滚 user.UserType = UserType.Admin; var result = _userManager.Create(user, password); if (result.Succeeded) { if (roles == null) { roles = new List <string>(); } roles.Add("admin"); foreach (var roleName in roles) { result = _userManager.AddToRole(user.Id, roleName); if (!result.Succeeded) { break; } } Logger.Operation($"添加后台用户-{user.UserName}:{user.Id}", SystemUsersModule.Instance, SecurityLevel.Warning); //更新缓存 _signals.Trigger(_userContainer.UserChangedSignalName); } return(result); }
public async Task CreateCreativeSize(CreativeSize creativeSize) { _creativeSizeRepositoryAsync.Insert(creativeSize); await _brandscreenContext.SaveChangesAsync(); _signals.Trigger(UpdateSignal); }
protected override DriverResult Editor(AdminCultureSettingsPart part, IUpdateModel updater, dynamic shapeHelper) { AdminCultureViewModel model = new AdminCultureViewModel(); if (updater.TryUpdateModel(model, Prefix, null, null)) { bool signal = false; if (model.AdminCulture != null) { part.Priority = model.AdminCulture.Priority; part.Enabled = model.AdminCulture.Enabled; signal = true; } if (model.SelectedCulture != null) { part.AdminCulture = model.SelectedCulture; signal = true; } if (signal) { _signals.Trigger(AdminCultureSettingsPart.CacheKey); } } return(Editor(part, shapeHelper)); }
public void ToggleEnabled(int refId, bool isEnabled) { Repository.UpdateMany(x => x.Id == refId || x.RefId == refId, x => new Page { IsEnabled = isEnabled }); signals.Trigger("Pages_Changed"); }
protected override DriverResult Editor(CookieCultureSettingsPart part, IUpdateModel updater, dynamic shapeHelper) { if (updater.TryUpdateModel(part, Prefix, null, null)) { _signals.Trigger(CookieCultureSettingsPart.CacheKey); } return(Editor(part, shapeHelper)); }
protected override void Published(PublishContentContext context) { var contentTags = context.ContentItem.As <TagsPart>(); if (contentTags != null) { _signals.Trigger(TagCloudService.VandelayTagcloudTagschanged); } base.Published(context); }
protected override void Published(PublishContentContext context) { var contentTags = context.ContentItem.As <TagsPart>(); if (contentTags != null) { _signals.Trigger(LocalizedTagsService._localizedTagcloudTagsChanged); } base.Published(context); }
public ActionResult IndexPost() { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage HTML Minifier - Features"))) { return(new HttpUnauthorizedResult()); } var model = new IndexViewModel(); if (TryUpdateModel(model)) { var settings = Services.WorkContext.CurrentSite.As <MinificationSettingsPart>(); settings.WhitespaceMinificationMode = model.WhitespaceMinificationMode; settings.RemoveHtmlComments = model.RemoveHtmlComments; settings.RemoveHtmlCommentsFromScriptsAndStyles = model.RemoveHtmlCommentsFromScriptsAndStyles; settings.RemoveCdataSectionsFromScriptsAndStyles = model.RemoveCdataSectionsFromScriptsAndStyles; settings.UseShortDoctype = model.UseShortDoctype; settings.PreserveCase = model.PreserveCase; settings.UseMetaCharsetTag = model.UseMetaCharsetTag; settings.EmptyTagRenderMode = model.EmptyTagRenderMode; settings.RemoveOptionalEndTags = model.RemoveOptionalEndTags; settings.PreservableOptionalTagList = model.PreservableOptionalTagList; settings.RemoveTagsWithoutContent = model.RemoveTagsWithoutContent; settings.CollapseBooleanAttributes = model.CollapseBooleanAttributes; settings.RemoveEmptyAttributes = model.RemoveEmptyAttributes; settings.AttributeQuotesRemovalMode = model.AttributeQuotesRemovalMode; settings.RemoveRedundantAttributes = model.RemoveRedundantAttributes; settings.RemoveJsTypeAttributes = model.RemoveJsTypeAttributes; settings.RemoveCssTypeAttributes = model.RemoveCssTypeAttributes; settings.RemoveHttpProtocolFromAttributes = model.RemoveHttpProtocolFromAttributes; settings.RemoveHttpsProtocolFromAttributes = model.RemoveHttpsProtocolFromAttributes; settings.RemoveJsProtocolFromAttributes = model.RemoveJsProtocolFromAttributes; settings.MinifyEmbeddedCssCode = model.MinifyEmbeddedCssCode; settings.MinifyInlineCssCode = model.MinifyInlineCssCode; settings.MinifyEmbeddedJsCode = model.MinifyEmbeddedJsCode; settings.MinifyInlineJsCode = model.MinifyInlineJsCode; settings.ProcessableScriptTypeList = model.ProcessableScriptTypeList; settings.MinifyKnockoutBindingExpressions = model.MinifyKnockoutBindingExpressions; settings.MinifyAngularBindingExpressions = model.MinifyAngularBindingExpressions; settings.CustomAngularDirectiveList = model.CustomAngularDirectiveList; settings.StatisticsInfoWindowPattern = model.StatisticsInfoWindowPattern; signals.Trigger(MinificationSettingsPart.CacheKey); Services.Notifier.Information(T("Feature settings saved successfully.")); } else { Services.Notifier.Error(T("Could not save feature settings.")); } return(RedirectToAction("Index")); }
public void AddCulture(string cultureName) { if (!IsValidCulture(cultureName)) { throw new ArgumentException("cultureName"); } _cultureRepository.Create(new CultureRecord { Culture = cultureName }); _signals.Trigger("culturesChanged"); }
public RedirectRule Update(RedirectRule redirectRule) { //FixRedirect(redirectRule); if (GetSameSourceUrlIds(redirectRule).Any(id => id != redirectRule.Id)) { throw new RedirectRuleDuplicateException(T("Rules with same SourceURL are not valid.")); } _repository.Update(redirectRule); _signals.Trigger("Laser.Orchard.Redirects.Changed"); return(redirectRule); }
protected override DriverResult Editor(SEOSettingsPart part, IUpdateModel updater, dynamic shapeHelper) { if (updater.TryUpdateModel(part, Prefix, null, null)) { ValidateSiteUrl(part, updater); ValidateSiteUrlAndWWWCompatibility(part, updater); ValidateSiteUrlAndForceSSLCompatibility(part, updater); _signals.Trigger(SEOSettingsPart.CacheKey); } return(Editor(part, shapeHelper)); }
public async Task<ActionResult> Login(LoginViewModel model) { if (!ModelState.IsValid) { return View(model); } var signInManager = new DefaultSignInManager(UserManager, Request.GetOwinContext().Authentication); // 1. 利用ASP.NET Identity获取用户对象 var user = await UserManager.FindAsync(model.UserName, model.Password); if (user == null || user.UserType != UserType.Admin) { Logger.Operation($"尝试登录后台失败-{model.UserName}", SystemUsersModule.Instance, SecurityLevel.Warning); model.ErrorMessage = "用户名或者密码错误"; return View(model); } if (user.LockoutEnabled) { Logger.Operation($"尝试登录后台失败-{model.UserName}", SystemUsersModule.Instance, SecurityLevel.Warning); model.ErrorMessage = "账号已经被禁用"; return View(model); } await signInManager.SignInAsync(user, true, model.RememberMe); Logger.Operation($"成功登录后台-{user.UserName}:{user.Id}", SystemUsersModule.Instance); //更新缓存 _signals.Trigger(_userContainer.UserChangedSignalName); return RedirectToLocal(model.ReturnUrl); }
public void SetSiteTheme(string themeName) { //var site = _BoyingServices.WorkContext.CurrentSite; //site.As<ThemeSiteSettingsPart>().CurrentThemeName = themeName; _signals.Trigger(CurrentThemeSignal); }
public bool SavePayment(Payment payment) { _currencyService.Update(payment); _signals.Trigger($"payment_{payment.Id}_changed"); return(true); }
public Guid GetMediaPartType <TKey>(BaseEntity <TKey> entity) { var type = GetFullTypeName(entity.GetType()); var types = cacheManager.Get("MediaPartTypes_GetAllTypes", ctx => { ctx.Monitor(signals.When("MediaPartTypes_Changed")); return(mediaPartTypeRepository.Table.ToList()); }); var part = types.FirstOrDefault(x => x.Type == type); if (part != null) { return(part.Id); } part = new MediaPartType { Id = Guid.NewGuid(), Type = type }; mediaPartTypeRepository.Insert(part); signals.Trigger("MediaPartTypes_Changed"); return(part.Id); }
public ActionResult IndexPost() { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage cache"))) { return(new HttpUnauthorizedResult()); } var model = new IndexViewModel { RouteConfigurations = new List <RouteConfiguration>() }; if (TryUpdateModel(model)) { var settings = Services.WorkContext.CurrentSite.As <CacheSettingsPart>(); settings.DefaultCacheDuration = model.DefaultCacheDuration; settings.DefaultMaxAge = model.DefaultMaxAge; settings.IgnoredUrls = model.IgnoredUrls; settings.DebugMode = model.DebugMode; settings.ApplyCulture = model.ApplyCulture; // invalidates the settings cache _signals.Trigger(CacheSettingsPart.CacheKey); _cacheService.SaveCacheConfigurations(model.RouteConfigurations); Services.Notifier.Information(T("Cache Settings saved successfully.")); } else { Services.Notifier.Error(T("Could not save Cache Settings.")); } return(RedirectToAction("Index")); }
private ContentTypeRecord AcquireContentTypeRecord(string contentType) { var contentTypeId = _cacheManager.Get(contentType + "_Record", ctx => { ctx.Monitor(_signals.When(contentType + "_Record")); var contentTypeRecord = _contentTypeRepository.Get(x => x.Name == contentType); if (contentTypeRecord == null) { //TEMP: this is not safe... ContentItem types could be created concurrently? contentTypeRecord = new ContentTypeRecord { Name = contentType }; _contentTypeRepository.Create(contentTypeRecord); } return(contentTypeRecord.Id); }); // There is a case when a content type record is created locally but the transaction is actually // cancelled. In this case we are caching an Id which is none existent, or might represent another // content type. Thus we need to ensure that the cache is valid, or invalidate it and retrieve it // another time. var result = _contentTypeRepository.Get(contentTypeId); if (result != null && result.Name.Equals(contentType, StringComparison.OrdinalIgnoreCase)) { return(result); } // invalidate the cache entry and load it again _signals.Trigger(contentType + "_Record"); return(AcquireContentTypeRecord(contentType)); }
public ActionResult Edit(int id, ElementDataViewModel model) { var blueprint = _elementBlueprintService.GetBlueprint(id); var describeContext = DescribeElementsContext.Empty; var descriptor = _elementManager.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName); var data = ElementDataHelper.Deserialize(model.ElementData).Combine(Request.Form.ToDictionary()); var element = _elementManager.ActivateElement(descriptor, e => e.Data = data); var context = CreateEditorContext(element, elementData: data); var editorResult = _elementManager.UpdateEditor(context); var viewModel = new EditElementBlueprintViewModel { EditorResult = editorResult, TypeName = model.TypeName, DisplayText = descriptor.DisplayText, Description = descriptor.Description, ElementData = element.Data.Serialize(), Tabs = editorResult.CollectTabs().ToArray(), BaseElement = element }; if (!ModelState.IsValid) { _transactionManager.Cancel(); return(View(viewModel)); } blueprint.BaseElementState = data.Serialize(); _signals.Trigger(Signals.ElementDescriptors); _notifier.Information(T("That blueprint has been saved.")); return(RedirectToAction("Index")); }
public void SaveSetting <T>(T settings) where T : ISettings, new() { foreach (var prop in typeof(T).GetProperties()) { // get properties we can read and write to if (!prop.CanRead || !prop.CanWrite) { continue; } if (!CommonHelper.GetCustomTypeConverter(prop.PropertyType).CanConvertFrom(typeof(string))) { continue; } string key = typeof(T).Name + "." + prop.Name; //Duck typing is not supported in C#. That's why we're using dynamic type dynamic value = prop.GetValue(settings, null); if (value != null) { SetSetting(key, value, false); } else { SetSetting(key, "", false); } } _signals.Trigger(SETTINGS_ALL_KEY); }
public void SaveCacheConfigurations(IEnumerable <RouteConfiguration> routeConfigurations) { // remove all current configurations var configurations = _repository.Fetch(c => true); foreach (var configuration in configurations) { _repository.Delete(configuration); } // save the new configurations foreach (var configuration in routeConfigurations) { if (!configuration.Duration.HasValue) { continue; } _repository.Create(new CacheParameterRecord { Duration = configuration.Duration.Value, RouteKey = configuration.RouteKey }); } // invalidate the cache _signals.Trigger("GetRouteConfigurations"); }
private ApiResult Login(string mobileDevice, User user, string openId = "") { var result = new ApiResult(); if (user != null && user.UserType == UserType.Member) { if (user.LockoutEnabled) { throw new WebApiInnerException("0002", "此用户已经禁止登录"); } var token = KeyGenerator.GetGuidKey().ToString(); user.DynamicToken = token; user.MobileDevice = mobileDevice; var needClearUser = _userManager.Users.Where(u => u.MobileDevice.Equals(mobileDevice, StringComparison.OrdinalIgnoreCase) && !u.Id.Equals(user.Id, StringComparison.OrdinalIgnoreCase)).ToArray(); foreach (var item in needClearUser) { item.MobileDevice = ""; _userManager.Update(item); } _userManager.Update(user); //绑定微信 if (!string.IsNullOrWhiteSpace(openId)) { _currencyService.DeleteByConditon <UserOAuth>(uo => uo.OAuthType == OAuthType.WeiXin && (uo.OAuthId.Equals(openId, StringComparison.OrdinalIgnoreCase) || uo.MemberId.Equals(user.Id, StringComparison.OrdinalIgnoreCase))); _currencyService.Create(new UserOAuth() { Id = KeyGenerator.GetGuidKey(), MemberId = user.Id, OAuthId = openId, OAuthType = OAuthType.WeiXin }); } _signals.Trigger(_userContainer.UserChangedSignalName); _signals.Trigger($"member_{user.Id}_changed"); result.SetData(_memberService.FindMember(user).Simplified()); } else { throw new WebApiInnerException("0003", "用户不存在或密码错误"); } return(result); }
protected override DriverResult Editor(CookieConsentSettingsPart part, IUpdateModel updater, dynamic shapeHelper) { if (updater.TryUpdateModel(part, Prefix, null, null)) { _signals.Trigger("Mod.CookieConsent.Changed"); } return(Editor(part, shapeHelper)); }
public void Save(MerchantDomainAssociationViewModel viewModel) { var merchantDomainAssociationFileRecord = Get(); merchantDomainAssociationFileRecord.FileContent = viewModel.Text; merchantDomainAssociationFileRecord.Enable = viewModel.Enable; _signals.Trigger("MerchantDomainAssociation.SettingsChanged"); }
protected override void Published(PublishContentContext context) { if (context.ContentItem.Has <ImageProfilePart>()) { _signals.Trigger("MediaProcessing_Published_" + context.ContentItem.As <ImageProfilePart>().Name); } base.Published(context); }
// We're providing a public method in our service, public void InvalidateCachedDateTime() { // in which we remove the entry from CacheService, _cacheService.Remove(CacheKey); // and trigger the signal to invalidate the cache entry of CacheManager. _signals.Trigger(InvalidateDateTimeCacheSignal); }
private void SetupLazyFields(ActivatedContentContext context, AuditTrailSettingsPart part) { part._eventProviderSettingsField.Loader(() => _auditTrailManager.DeserializeProviderConfiguration(part.Retrieve <string>("Events"))); part._eventProviderSettingsField.Setter(value => { part.Store("Events", _auditTrailManager.SerializeProviderConfiguration(value)); _signals.Trigger("AuditTrail.EventSettings"); return(value); }); }
public void SetSettings(RedirectSettings settings) { var settingsPart = _orchardServices.WorkContext.CurrentSite.As <RedirectSettingsPart>(); settingsPart.Rules = settings.Rules; settingsPart.Enabled = settings.IsEnabled; // invalidates the cache _signals.Trigger("RedirectSettings"); }
public SitemapContentHandler( ISignals signals, IAdvancedSitemapService sitemapService) { _signals = signals; _sitemapService = sitemapService; OnPublished<ContentItem>((ctx, item) => { var activeContentTypes = _sitemapService.GetIndexSettings() .Where(m => m.IndexForDisplay || m.IndexForXml) .Select(m => m.Name) .ToList(); if (activeContentTypes.Contains(ctx.ContentItem.ContentType)) { _signals.Trigger("WebAdvanced.Sitemap.Refresh"); } }); }