private Attempt <IPartialView?> SavePartialView(IPartialView partialView, PartialViewType partialViewType, int?userId = null) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new PartialViewSavingNotification(partialView, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) { scope.Complete(); return(Attempt <IPartialView?> .Fail()); } userId ??= Constants.Security.SuperUserId; IPartialViewRepository repository = GetPartialViewRepository(partialViewType); repository.Save(partialView); Audit(AuditType.Save, userId.Value, -1, partialViewType.ToString()); scope.Notifications.Publish( new PartialViewSavedNotification(partialView, eventMessages).WithStateFrom(savingNotification)); scope.Complete(); } return(Attempt.Succeed(partialView)); }
private bool DeletePartialViewMacro(string path, PartialViewType partialViewType, int userId = Constants.Security.SuperUserId) { using (IScope scope = ScopeProvider.CreateScope()) { IPartialViewRepository repository = GetPartialViewRepository(partialViewType); IPartialView partialView = repository.Get(path); if (partialView == null) { scope.Complete(); return(true); } EventMessages eventMessages = EventMessagesFactory.Get(); var deletingNotification = new PartialViewDeletingNotification(partialView, eventMessages); if (scope.Notifications.PublishCancelable(deletingNotification)) { scope.Complete(); return(false); } repository.Delete(partialView); scope.Notifications.Publish(new PartialViewDeletedNotification(partialView, eventMessages).WithStateFrom(deletingNotification)); Audit(AuditType.Delete, userId, -1, partialViewType.ToString()); scope.Complete(); } return(true); }
// Umbraco.Code.MapAll -FileType -Notifications -Path -Snippet private static void Map(IPartialView source, CodeFileDisplay target, MapperContext context) { target.Content = source.Content; target.Id = source.Id.ToString(); target.Name = source.Name; target.VirtualPath = source.VirtualPath; }
public bool ValidatePartialViewMacro(IPartialView partialView) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { return(_partialViewMacroRepository.ValidatePartialView(partialView)); } }
private Attempt <IPartialView> CreatePartialViewMacro(IPartialView partialView, PartialViewType partialViewType, string snippetName = null, int userId = 0) { using (var scope = UowProvider.ScopeProvider.CreateScope()) { scope.Complete(); // always if (scope.Events.DispatchCancelable(CreatingPartialView, this, new NewEventArgs <IPartialView>(partialView, true, partialView.Alias, -1))) { return(Attempt <IPartialView> .Fail()); } } if (snippetName.IsNullOrWhiteSpace() == false) { partialView.Content = GetPartialViewMacroSnippetContent(snippetName, partialViewType); } using (var uow = UowProvider.GetUnitOfWork()) { var repository = GetPartialViewRepository(partialViewType, uow); repository.AddOrUpdate(partialView); uow.Events.Dispatch(CreatedPartialView, this, new NewEventArgs <IPartialView>(partialView, false, partialView.Alias, -1)); Audit(uow, AuditType.Save, string.Format("Save {0} performed by user", partialViewType), userId, -1); uow.Commit(); } return(Attempt <IPartialView> .Succeed(partialView)); }
// Umbraco.Code.MapAll -Trashed -Udi -Icon private static void Map(IPartialView source, EntityBasic target, MapperContext context) { target.Alias = source.Alias; target.Id = source.Id; target.Key = source.Key; target.Name = source.Name; target.ParentId = -1; target.Path = source.Path; }
private Attempt<IPartialView> CreatePartialViewMacro(IPartialView partialView, PartialViewType partialViewType, string snippetName = null, int userId = 0) { if (CreatingPartialView.IsRaisedEventCancelled(new NewEventArgs<IPartialView>(partialView, true, partialView.Alias, -1), this)) return Attempt<IPartialView>.Fail(); string partialViewHeader; switch (partialViewType) { case PartialViewType.PartialView: partialViewHeader = PartialViewHeader; break; case PartialViewType.PartialViewMacro: partialViewHeader = PartialViewMacroHeader; break; default: throw new ArgumentOutOfRangeException("partialViewType"); } if (snippetName.IsNullOrWhiteSpace() == false) { //create the file var snippetPathAttempt = TryGetSnippetPath(snippetName); if (snippetPathAttempt.Success == false) { throw new InvalidOperationException("Could not load snippet with name " + snippetName); } using (var snippetFile = new StreamReader(System.IO.File.OpenRead(snippetPathAttempt.Result))) { var snippetContent = snippetFile.ReadToEnd().Trim(); //strip the @inherits if it's there snippetContent = StripPartialViewHeader(snippetContent); var content = string.Format("{0}{1}{2}", partialViewHeader, Environment.NewLine, snippetContent); partialView.Content = content; } } var uow = _fileUowProvider.GetUnitOfWork(); using (var repository = GetPartialViewRepository(partialViewType, uow)) { repository.AddOrUpdate(partialView); uow.Commit(); CreatedPartialView.RaiseEvent(new NewEventArgs<IPartialView>(partialView, false, partialView.Alias, -1), this); } Audit(AuditType.Save, string.Format("Save {0} performed by user", partialViewType), userId, -1); return Attempt<IPartialView>.Succeed(partialView); }
/// <summary> /// Gets the entity identifier of the entity. /// </summary> /// <param name="entity">The entity.</param> /// <returns>The entity identifier of the entity.</returns> public static StringUdi GetUdi(this IPartialView entity) { if (entity == null) { throw new ArgumentNullException("entity"); } // we should throw on Unknown but for the time being, assume it means PartialView var entityType = entity.ViewType == PartialViewType.PartialViewMacro ? Constants.UdiEntityType.PartialViewMacro : Constants.UdiEntityType.PartialView; return(new StringUdi(entityType, entity.Path.TrimStart('/')).EnsureClosed()); }
public void AttachChild(IPartialView partialView, ISlaveController slaveController) { if ((object)partialView == null) { throw new ArgumentNullException("partialView"); } if ((object)slaveController == null) { throw new ArgumentNullException("slaveController"); } this.ChildMap.Add(partialView, slaveController); }
private Attempt<IPartialView> SavePartialView(IPartialView partialView, PartialViewType partialViewType, int userId = 0) { if (SavingPartialView.IsRaisedEventCancelled(new SaveEventArgs<IPartialView>(partialView), this)) return Attempt<IPartialView>.Fail(); var uow = _fileUowProvider.GetUnitOfWork(); using (var repository = GetPartialViewRepository(partialViewType, uow)) { repository.AddOrUpdate(partialView); uow.Commit(); } Audit(AuditType.Save, string.Format("Save {0} performed by user", partialViewType), userId, -1); SavedPartialView.RaiseEvent(new SaveEventArgs<IPartialView>(partialView, false), this); return Attempt.Succeed(partialView); }
private Attempt <IPartialView> SavePartialView(IPartialView partialView, PartialViewType partialViewType, int userId = 0) { using (var uow = UowProvider.GetUnitOfWork()) { if (uow.Events.DispatchCancelable(SavingPartialView, this, new SaveEventArgs <IPartialView>(partialView))) { uow.Commit(); return(Attempt <IPartialView> .Fail()); } var repository = GetPartialViewRepository(partialViewType, uow); repository.AddOrUpdate(partialView); uow.Events.Dispatch(SavedPartialView, this, new SaveEventArgs <IPartialView>(partialView, false)); Audit(uow, AuditType.Save, string.Format("Save {0} performed by user", partialViewType), userId, -1); uow.Commit(); } return(Attempt.Succeed(partialView)); }
private Attempt <IPartialView> SavePartialView(IPartialView partialView, PartialViewType partialViewType, int userId = 0) { using (var scope = ScopeProvider.CreateScope()) { var saveEventArgs = new SaveEventArgs <IPartialView>(partialView); if (scope.Events.DispatchCancelable(SavingPartialView, this, saveEventArgs)) { scope.Complete(); return(Attempt <IPartialView> .Fail()); } var repository = GetPartialViewRepository(partialViewType); repository.Save(partialView); saveEventArgs.CanCancel = false; Audit(AuditType.Save, userId, -1, partialViewType.ToString()); scope.Events.Dispatch(SavedPartialView, this, saveEventArgs); scope.Complete(); } return(Attempt.Succeed(partialView)); }
public void ExecuteObfuscation(IPartialView sourceView, object actionContext) { ObfuscationConfiguration obfuscationConfiguration; IEnumerable <Message> messages; this.View.ExecutionPartialView.RecordCount = null; this.View.ExecutionPartialView.IsComplete = null; this.View.ExecutionPartialView.DurationSeconds = null; obfuscationConfiguration = new ObfuscationConfiguration() { ConfigurationVersion = ObfuscationConfiguration.CurrentConfigurationVersion, EngineVersion = ObfuscationConfiguration.CurrentEngineVersion }; this.ApplyViewToDocument(obfuscationConfiguration); messages = obfuscationConfiguration.Validate(); if ((object)messages != null && messages.Any()) { this.View.ExecutionPartialView.IsComplete = true; this.View.ShowMessages(messages, "Configuration validation on execution", false); return; } using (IToolHost toolHost = new ToolHost()) { toolHost.Host(obfuscationConfiguration, (count, complete, duration) => { this.View.ExecutionPartialView.RecordCount = count; this.View.ExecutionPartialView.IsComplete = complete; this.View.ExecutionPartialView.DurationSeconds = duration; }); } this.View.ShowAlert("Done."); }
// Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate // Umbraco.Code.MapAll -Id -Key -Alias -Name -OriginalPath -Path private static void Map(CodeFileDisplay source, IPartialView target, MapperContext context) { target.Content = source.Content; target.VirtualPath = source.VirtualPath; }
public Attempt<IPartialView> SavePartialViewMacro(IPartialView partialView, int userId = 0) { return SavePartialView(partialView, PartialViewType.PartialViewMacro, userId); }
public Attempt<IPartialView> CreatePartialViewMacro(IPartialView partialView, string snippetName = null, int userId = 0) { return CreatePartialViewMacro(partialView, PartialViewType.PartialViewMacro, snippetName, userId); }
public Attempt <IPartialView> SavePartialView(IPartialView partialView, int userId = 0) { return(SavePartialView(partialView, PartialViewType.PartialView, userId)); }
private Attempt <IPartialView> CreatePartialViewMacro(IPartialView partialView, PartialViewType partialViewType, string snippetName = null, int userId = 0) { string partialViewHeader; switch (partialViewType) { case PartialViewType.PartialView: partialViewHeader = PartialViewHeader; break; case PartialViewType.PartialViewMacro: partialViewHeader = PartialViewMacroHeader; break; default: throw new ArgumentOutOfRangeException(nameof(partialViewType)); } string partialViewContent = null; if (snippetName.IsNullOrWhiteSpace() == false) { //create the file var snippetPathAttempt = TryGetSnippetPath(snippetName); if (snippetPathAttempt.Success == false) { throw new InvalidOperationException("Could not load snippet with name " + snippetName); } using (var snippetFile = new StreamReader(System.IO.File.OpenRead(snippetPathAttempt.Result))) { var snippetContent = snippetFile.ReadToEnd().Trim(); //strip the @inherits if it's there snippetContent = StripPartialViewHeader(snippetContent); partialViewContent = $"{partialViewHeader}{Environment.NewLine}{snippetContent}"; } } using (var scope = ScopeProvider.CreateScope()) { var newEventArgs = new NewEventArgs <IPartialView>(partialView, true, partialView.Alias, -1); if (scope.Events.DispatchCancelable(CreatingPartialView, this, newEventArgs)) { scope.Complete(); return(Attempt <IPartialView> .Fail()); } var repository = GetPartialViewRepository(partialViewType); if (partialViewContent != null) { partialView.Content = partialViewContent; } repository.Save(partialView); newEventArgs.CanCancel = false; scope.Events.Dispatch(CreatedPartialView, this, newEventArgs); Audit(AuditType.Save, userId, -1, partialViewType.ToString()); scope.Complete(); } return(Attempt <IPartialView> .Succeed(partialView)); }
public Attempt <IPartialView?> SavePartialViewMacro(IPartialView partialView, int?userId = null) => SavePartialView(partialView, PartialViewType.PartialViewMacro, userId);
private Attempt <IPartialView?> CreatePartialViewMacro(IPartialView partialView, PartialViewType partialViewType, string?snippetName = null, int?userId = Constants.Security.SuperUserId) { string partialViewHeader; switch (partialViewType) { case PartialViewType.PartialView: partialViewHeader = PartialViewHeader; break; case PartialViewType.PartialViewMacro: partialViewHeader = PartialViewMacroHeader; break; default: throw new ArgumentOutOfRangeException(nameof(partialViewType)); } string?partialViewContent = null; if (snippetName.IsNullOrWhiteSpace() == false) { //create the file Attempt <string> snippetPathAttempt = TryGetSnippetPath(snippetName); if (snippetPathAttempt.Success == false) { throw new InvalidOperationException("Could not load snippet with name " + snippetName); } using (var snippetFile = new StreamReader(System.IO.File.OpenRead(snippetPathAttempt.Result !))) { var snippetContent = snippetFile.ReadToEnd().Trim(); //strip the @inherits if it's there snippetContent = StripPartialViewHeader(snippetContent); //Update Model.Content. to be Model. when used as PartialView if (partialViewType == PartialViewType.PartialView) { snippetContent = snippetContent.Replace("Model.Content.", "Model."); } partialViewContent = $"{partialViewHeader}{Environment.NewLine}{snippetContent}"; } } using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var creatingNotification = new PartialViewCreatingNotification(partialView, eventMessages); if (scope.Notifications.PublishCancelable(creatingNotification)) { scope.Complete(); return(Attempt <IPartialView?> .Fail()); } IPartialViewRepository repository = GetPartialViewRepository(partialViewType); if (partialViewContent != null) { partialView.Content = partialViewContent; } repository.Save(partialView); scope.Notifications.Publish(new PartialViewCreatedNotification(partialView, eventMessages).WithStateFrom(creatingNotification)); Audit(AuditType.Save, userId !.Value, -1, partialViewType.ToString()); scope.Complete(); } return(Attempt <IPartialView?> .Succeed(partialView)); }
public Attempt <IPartialView?> CreatePartialViewMacro(IPartialView partialView, string?snippetName = null, int?userId = Constants.Security.SuperUserId) => CreatePartialViewMacro(partialView, PartialViewType.PartialViewMacro, snippetName, userId);
public Attempt <IPartialView> SavePartialView(IPartialView partialView, int userId = Constants.Security.SuperUserId) => SavePartialView(partialView, PartialViewType.PartialView, userId);
public Attempt <IPartialView> CreatePartialViewMacro(IPartialView partialView, string snippetName = null, int userId = Constants.Security.SuperUserId) { return(CreatePartialViewMacro(partialView, PartialViewType.PartialViewMacro, snippetName, userId)); }
public Attempt <IPartialView> SavePartialViewMacro(IPartialView partialView, int userId = Constants.Security.SuperUserId) { return(SavePartialView(partialView, PartialViewType.PartialViewMacro, userId)); }