/// <summary> /// Copies first name, last name and email address from saved member to Merchello customer. /// </summary> /// <param name="sender"> /// The <see cref="IMemberService"/>. /// </param> /// <param name="e"> /// The saved <see cref="IMember"/>s. /// </param> private static void MemberServiceSaved(IMemberService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IMember> e) { var members = e.SavedEntities.ToArray(); // Allowed member types for Merchello customers var customerMemberTypes = MerchelloConfiguration.Current.CustomerMemberTypes.ToArray(); // Get a reference to Merchello's customer service var customerService = MerchelloContext.Current.Services.CustomerService; foreach (var member in members) { // verify the member is a customer type if (!customerMemberTypes.Contains(member.ContentTypeAlias)) { continue; } var customer = customerService.GetByLoginName(member.Username); if (customer == null) { continue; } customer.FirstName = member.GetValue <string>("firstName") ?? string.Empty; customer.LastName = member.GetValue <string>("lastName") ?? string.Empty; customerService.Save(customer); } }
private void LocalizationService_SavedLanguage(ILocalizationService sender, Umbraco.Core.Events.SaveEventArgs <ILanguage> e) { if (uSync8BackOffice.eventsPaused) { return; } foreach (var item in e.SavedEntities) { if (item.WasPropertyDirty("IsDefault")) { // changeing, this change doesn't trigger a save of the other languages. // so we need to save all language files. this.ExportAll(Path.Combine(rootFolder, DefaultFolder), DefaultConfig, null); } else { var attempt = Export(item, Path.Combine(rootFolder, this.DefaultFolder), DefaultConfig); if (attempt.Success) { this.CleanUp(item, attempt.FileName, Path.Combine(rootFolder, this.DefaultFolder)); } } } }
private static void MemberService_Saved(IMemberService sender, Umbraco.Core.Events.SaveEventArgs <IMember> e) { foreach (var item in e.SavedEntities.Where(x => string.IsNullOrWhiteSpace(x.GetValue <string>("github")) == false)) { UpdatePullRequestExamineIndex(item.Id, item.GetValue <string>("github")); } }
private void ContentService_SavedBlueprint(IContentService sender, Umbraco.Core.Events.SaveEventArgs <IContent> e) { // was is a dtge temp file ? if (e.SavedEntities.Any(x => !x.Name.InvariantStartsWith("dtge temp"))) { EventSavedItem(sender, e); } }
static void MacroService_Saved(Umbraco.Core.Services.IMacroService sender, Umbraco.Core.Events.SaveEventArgs <IMacro> e) { LogHelper.Info <SyncMacros>("Macro saved"); foreach (var macro in e.SavedEntities) { SaveToDisk(macro); } }
public void MediaService_Saved(Umbraco.Core.Services.IMediaService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IMedia> e) { foreach (var item in e.SavedEntities) { var properties = new PropertiesDictionary(item); AsyncUtil.RunSync(() => _messagingService.SendMessageAsync("mediaService", "saved", properties)); } }
public void FilterEvent(IContentService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IContent> e) { //check if this is a valid content type if (e.SavedEntities.Select(c => c.ContentType.Alias).Intersect(ContentTypeAliases).Count() > 0) { MethodToBind.Invoke(null, new object[] { sender, e }); } }
static void ContentTypeService_SavedContentType(IContentTypeService sender, Umbraco.Core.Events.SaveEventArgs <IContentType> e) { LogHelper.Info <ContentType>("Content Type Saved"); foreach (var doctype in e.SavedEntities) { SaveToDisk(doctype); } }
private void MediaServiceSaving(IMediaService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IMedia> e) { UmbracoContext umbContext = ContextHelpers.EnsureUmbracoContext(); if (umbContext.Security.CurrentUser != null && (umbContext.Security.CurrentUser.UserType.Alias != "admin" && umbContext.Security.CurrentUser.StartMediaId == -1)) { BackOfficeUtils.ValidateMediaUploadAccess(umbContext.Security.CurrentUser.Id, sender, e); } }
void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IContent> e) { foreach (var node in e.SavedEntities) { /* calendar - KS.Umbraco7.Calendar */ try { if (node.PropertyTypes.Any(x => x.PropertyEditorAlias == "KS.Umbraco7.Calendar")) { var pt = node.PropertyTypes.First(x => x.PropertyEditorAlias == "KS.Umbraco7.Calendar"); //LogHelper.Info(typeof(CalendarEventHandler), "PropertyTypeAlias Alias: " + pt.Alias + " PropertyEditorAlias: " + pt.PropertyEditorAlias); var dataTypeService = ApplicationContext.Current.Services.DataTypeService; IDictionary <string, PreValue> pvs = dataTypeService.GetPreValuesCollectionByDataTypeId(pt.DataTypeDefinitionId).PreValuesAsDictionary; if (pvs.Any(x => x.Key == "startDateField" && x.Value.Value != null)) { if (node.HasProperty(pvs["startDateField"].Value)) { string calJson = node.GetValue(pt.Alias).ToString(); CalendarEvent cal = Newtonsoft.Json.JsonConvert.DeserializeObject <CalendarEvent>(calJson); var saveToPT = node.PropertyTypes.First(x => x.Alias == pvs["startDateField"].Value); var saveToDT = dataTypeService.GetDataTypeDefinitionById(saveToPT.DataTypeDefinitionId); //if (saveToDT.DatabaseType == DataTypeDatabaseType.Nvarchar || saveToDT.DatabaseType == DataTypeDatabaseType.Ntext) //{ // node.SetValue(pvs["startDateField"].Value, cal.startDate.ToString("yyyy-MM-dd HH:mm")); // sender.SaveAndPublishWithStatus(node, 0, false); //} //else if (saveToDT.DatabaseType == DataTypeDatabaseType.Date) { node.SetValue(saveToPT.Alias, cal.startDate); sender.Save(node, 0, false); } } //LogHelper.Info(typeof(MyEventHandler), "Saved something"); //if (node.Parent().ContentType.Alias != "DateFolderTypeNameFromPreValue") //{ // //move and save //} //else //{ // //if mismatch between startdate and year/month-folder => move and save //} } } } catch (Exception ex) { LogHelper.Info(typeof(CalendarEventHandler), ex.ToString()); } } }
static void DataTypeService_Saved(IDataTypeService sender, Umbraco.Core.Events.SaveEventArgs <IDataTypeDefinition> e) { if (!uSync.EventsPaused) { foreach (var item in e.SavedEntities) { SaveToDisk(item); } } }
private void ContentService_Saved(IContentService sender, Umbraco.Core.Events.SaveEventArgs <IContent> e) { LogHelper.Info <ContentHandler>("Content Save Fired:"); if (uSyncEvents.Paused) { return; } SaveItems(sender, e.SavedEntities); }
static void MacroService_Saved(IMacroService sender, Umbraco.Core.Events.SaveEventArgs <IMacro> e) { if (!uSync.EventsPaused) { foreach (var macro in e.SavedEntities) { SaveToDisk(macro); } } }
static void ContentTypeService_SavedMediaType(IContentTypeService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IMediaType> e) { if (!uSync.EventsPaused) { LogHelper.Debug <SyncMediaTypes>("SaveContent Type Fired for {0} types", () => e.SavedEntities.Count()); foreach (var mediaType in e.SavedEntities) { SaveToDisk(new MediaType(mediaType.Id)); } } }
static void FileService_SavedTemplate(IFileService sender, Umbraco.Core.Events.SaveEventArgs <ITemplate> e) { if (!uSync.EventsPaused) { LogHelper.Info <uSync>("Saving Templates"); foreach (var item in e.SavedEntities) { SaveToDisk(item); } } }
static void ContentTypeService_SavedContentType(IContentTypeService sender, Umbraco.Core.Events.SaveEventArgs <IContentType> e) { if (!uSync.EventsPaused) { LogHelper.Debug <SyncDocType>("SaveContent Type Fired for {0} types", () => e.SavedEntities.Count()); foreach (var docType in e.SavedEntities) { SaveToDisk(docType); } } }
private void ContentService_Saved(IContentService sender, Umbraco.Core.Events.SaveEventArgs <IContent> e) { foreach (IContent content in e.SavedEntities) { string typeAlias = content.ContentType.Alias; if (typeAlias == "Setting") { content.ParentId = content.ContentType.Id; ApplicationContext.Current.Services.ContentService.Save(content, 0, false); } } }
private void MediaService_Saving(Umbraco.Core.Services.IMediaService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IMedia> e) { foreach (var mediaItem in e.SavedEntities) { if (mediaItem.ContentType.Alias == "Image" && mediaItem.VersionId <= 1) { //perhaps send to Azure for AI analysis of image contents or something... AdageMediaService service = new AdageMediaService(); service.HandleImageUpload(mediaItem); } } }
private void LocalizationService_SavedLanguage(ILocalizationService sender, Umbraco.Core.Events.SaveEventArgs <ILanguage> e) { if (uSyncEvents.Paused) { return; } foreach (var item in e.SavedEntities) { LogHelper.Info <LanguageHandler>("Save: Saving uSync file for item: {0}", () => item.CultureName); ExportToDisk(item, uSyncBackOfficeContext.Instance.Configuration.Settings.Folder); uSyncBackOfficeContext.Instance.Tracker.RemoveActions(item.CultureName, typeof(ILanguage)); } }
protected void ContentService_Saved(IContentService sender, Umbraco.Core.Events.SaveEventArgs <IContent> e) { // Remove any cache associated to the modified content nodes var persistentCacheController = new Controllers.PersistentCacheController(); foreach (var entity in e.SavedEntities) { Routing.Helpers.CacheHelper.Remove(string.Format(Routing.Constants.Cache.NodeDependencyCacheIdPattern, entity.Id)); persistentCacheController.Remove(entity.Id); } // Remove all Ulrs cached for which no content node was found Routing.Helpers.CacheHelper.Remove(string.Format(Routing.Constants.Cache.NodeDependencyCacheIdPattern, 0)); persistentCacheController.Remove(0); }
private void ContentService_Saving(IContentService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IContent> e) { foreach (var content in e.SavedEntities) //foreach (var content in e.SavedEntities.Where(x => x.IsNewEntity())) //// A lot more possibilities than that! { if (!content.HasProperty("bodyText") || !content.HasProperty("excerpt")) { continue; } var bodyText = content.GetValue <string>("bodyText"); content.SetValue("excerpt", bodyText == null ? string.Empty : string.Join("", bodyText.StripHtml().StripNewLines().Take(200))); } }
private void MediaService_Saving(IMediaService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IMedia> e) { IEnumerable <string> supportedTypes = _contentSection.ImageFileTypes.ToList(); foreach (IMedia media in e.SavedEntities) { if (media.HasProperty("umbracoFile")) { string info = media.GetValue <string>(Constants.Conventions.Media.File); string path = JsonConvert.DeserializeObject <ImageCropperValue>(info).Src; string extension = Path.GetExtension(path).Substring(1); if (supportedTypes.InvariantContains(extension)) { string fullPath = _mediaFileSystem.GetFullPath(path); Stream inStream = null; int c = 0; do { c++; inStream = sender.GetMediaFileContentStream(fullPath); if (inStream == null) { Thread.Sleep(1000); } else { c = 6; } } while (c < 6); if (inStream != null) { using (var outStream = new MemoryStream()) { using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false)) { var image = imageFactory.Load(inStream).AutoRotate().Save(outStream); sender.SetMediaFileContent(fullPath, outStream); } } } } } } }
private void MediaService_Saved(IMediaService sender, Umbraco.Core.Events.SaveEventArgs <IMedia> e) { if (uSyncEvents.Paused) { return; } foreach (var item in e.SavedEntities) { var path = GetMediaPath(item); var attempt = ExportItem(item, path, uSyncBackOfficeContext.Instance.Configuration.Settings.Folder); if (attempt.Success) { NameChecker.ManageOrphanFiles(SyncFolder, item.Key, attempt.FileName); } } }
private void DataTypeService_Saved(IDataTypeService sender, Umbraco.Core.Events.SaveEventArgs <IDataTypeDefinition> e) { if (uSyncEvents.Paused) { return; } foreach (var item in e.SavedEntities) { LogHelper.Info <DataTypeHandler>("Save: Saving uSync file for item: {0}", () => item.Name); var action = ExportToDisk(item, uSyncBackOfficeContext.Instance.Configuration.Settings.Folder); if (action.Success) { NameChecker.ManageOrphanFiles(SyncFolder, item.Key, action.FileName); } } }
private void LocalizationService_SavingLanguage(ILocalizationService sender, Umbraco.Core.Events.SaveEventArgs <ILanguage> e) { if (uSync8BackOffice.eventsPaused) { return; } foreach (var item in e.SavedEntities) { // if (item.Id == 0) { newLanguages[item.IsoCode] = item.CultureName; // is new, we want to set this as a flag, so we don't do the full content save.n // newLanguages.Add(item.IsoCode); } } }
private void MemberService_Saving(IMemberService sender, Umbraco.Core.Events.SaveEventArgs <Umbraco.Core.Models.IMember> e) { foreach (var member in e.SavedEntities) { var securityStamp = member.GetSecurityStamp(out bool propertyTypeExists); if (!propertyTypeExists) { LogHelper.Warn <UmbracoEventHandlers>($"The {UmbracoIdentityConstants.SecurityStampProperty} does not exist on the member type {member.ContentType.Alias}, see docs on how to fix: https://github.com/Shazwazza/UmbracoIdentity/wiki"); } else { if (securityStamp.IsNullOrWhiteSpace()) { //set one, it shouldn't be empty member.SetValue(UmbracoIdentityConstants.SecurityStampProperty, Guid.NewGuid().ToString()); } } } }
private void LocalizationService_SavedLanguage(ILocalizationService sender, Umbraco.Core.Events.SaveEventArgs <ILanguage> e) { if (uSync8BackOffice.eventsPaused) { return; } foreach (var item in e.SavedEntities) { bool newItem = false; if (newLanguages.Count > 0 && newLanguages.ContainsKey(item.IsoCode)) { newItem = true; newLanguages.TryRemove(item.IsoCode, out string name); } if (item.WasPropertyDirty("IsDefault")) { // changeing, this change doesn't trigger a save of the other languages. // so we need to save all language files. this.ExportAll(Path.Combine(rootFolder, DefaultFolder), DefaultConfig, null); } var attempts = Export(item, Path.Combine(rootFolder, this.DefaultFolder), DefaultConfig); if (!newItem && item.WasPropertyDirty(nameof(ILanguage.IsoCode))) { // The language code changed, this can mean we need to do a full content export. // + we should export the languages again! uSyncTriggers.TriggerExport(rootFolder, new List <string>() { UdiEntityType.Document, UdiEntityType.Language }, null); } // we always clean up languages, because of the way they are stored. foreach (var attempt in attempts.Where(x => x.Success)) { this.CleanUp(item, attempt.FileName, Path.Combine(rootFolder, this.DefaultFolder)); } } }
static void DataTypeService_Saved(IDataTypeService sender, Umbraco.Core.Events.SaveEventArgs <IDataTypeDefinition> e) { if (!uSync.EventsPaused) { if (e.SavedEntities.Count() > 0) { // at the moment this is true for all versions of umbraco 7+ // when a fix appears we will version check this code away. // // whole app only runs on 7.1+ so just check for < 7.5 ? // if ( Umbraco.Core.Configuration.UmbracoVersion.Current.Major == 7 && // Umbraco.Core.Configuration.UmbracoVersion.Current.Minor < 5 ) { if (uSyncSettings.dataTypeSettings.WaitAndSave) { // we lock so saves can't happen while we add to the queue. lock (_saveLock) { // we reset the time, this means if two or more saves // happen close together, then they will be queued up // only when no datatype saves have happened in the // timer elapsed period will saves start to happen. // _saveTimer.Stop(); _saveTimer.Start(); foreach (var item in e.SavedEntities) { _saveQueue.Enqueue(item.Id); } } } else { foreach (var item in e.SavedEntities) { SaveToDisk(item); } } } } }
private void MacroService_Saved(IMacroService sender, Umbraco.Core.Events.SaveEventArgs <IMacro> e) { if (uSyncEvents.Paused) { return; } foreach (var item in e.SavedEntities) { LogHelper.Info <MacroHandler>("Save: Saving uSync file for item: {0}", () => item.Name); var action = ExportToDisk(item, uSyncBackOfficeContext.Instance.Configuration.Settings.Folder); if (action.Success) { // Name checker currently only works on guidkeys. // but it's not needed, when we use Ids to track anyway :) // NameChecker.ManageOrphanFiles(SyncFolder, item.Key, action.FileName); uSyncBackOfficeContext.Instance.Tracker.RemoveActions(item.Alias, typeof(IMacro)); } } }
private void RelationService_SavedRelation(IRelationService sender, Umbraco.Core.Events.SaveEventArgs <IRelation> e) { if (uSync8BackOffice.eventsPaused) { return; } lock (saveLock) { saveTimer.Stop(); saveTimer.Start(); // add each item to the save list (if we haven't already) foreach (var item in e.SavedEntities) { if (!pendingSaveIds.Contains(item.RelationTypeId)) { pendingSaveIds.Add(item.RelationTypeId); } } } }