static ContentNamingProvider() { var className = Providers.ContentNamingProviderClassName; ContentNamingProvider instance = null; if (string.IsNullOrEmpty(className)) { instance = new CharReplacementContentNamingProvider(); } else { try { instance = (ContentNamingProvider)TypeResolver.CreateInstance(className); } catch (Exception) { SnLog.WriteWarning("Error loading ContentNamingProvider type: " + className, EventId.RepositoryLifecycle); } } if (instance == null) { instance = new CharReplacementContentNamingProvider(); } SnLog.WriteInformation("ContentNamingProvider created: " + instance); __instance = instance; }
public static Content CreateTemplated(Node parent, Node template, string nameBase) { if (parent == null) { throw new ArgumentNullException("parent"); } if (template == null) { throw new ArgumentNullException("template"); } using (var op = SnTrace.ContentOperation.StartOperation("Content.CreateTemplated")) { var name = ContentNamingProvider.GetNewName(nameBase, ((GenericContent)template).GetContentType(), parent); var content = Content.Create(ContentTemplate.CreateFromTemplate(parent, template, name)); var realUser = (User)User.LoggedInUser; var now = DateTime.UtcNow; var node = content.ContentHandler; node.CreatedBy = realUser; node.VersionCreatedBy = realUser; node.NodeOperation = NodeOperation.TemplateCreation; op.Successful = true; return(content); } }
public void Execute() { if (this.Node.IsNew) { var gc = Node.Parent as GenericContent; if (gc != null) { gc.AssertAllowedChildType(Node); } } ContentNamingProvider.ValidateName(this.Node.Name); var autoNamingAllowed = false; if (this.Node.AllowIncrementalNaming.HasValue) { autoNamingAllowed = this.Node.AllowIncrementalNaming.Value; } else { autoNamingAllowed = this.Node.Id == 0 && ContentType.GetByName(this.Node.NodeType.Name).AllowIncrementalNaming; } while (true) { try { Node.Save(this); break; } catch (AggregateException ae) { if (!autoNamingAllowed) { throw; } if (!(ae.InnerException is Storage.Data.NodeAlreadyExistsException)) { throw; } } catch (Storage.Data.NodeAlreadyExistsException) { if (!autoNamingAllowed) { throw; } } this.Node.Name = ContentNamingProvider.IncrementNameSuffixToLastName(Node.Name, Node.ParentId); } }
public void Execute() { if (this.Node.IsNew) { var gc = Node.Parent as GenericContent; if (gc != null) { gc.AssertAllowedChildType(Node); } } // Assert SharedLock //UNDONE: uncomment when SharedLock storage is implemented //if (null != SharedLock.GetLock(this.Node.Id)) // throw new InvalidContentActionException(InvalidContentActionReason.CheckedOutToSomeoneElse, // this.Node.Path); ContentNamingProvider.ValidateName(this.Node.Name); var autoNamingAllowed = false; if (this.Node.AllowIncrementalNaming.HasValue) { autoNamingAllowed = this.Node.AllowIncrementalNaming.Value; } else { autoNamingAllowed = this.Node.Id == 0 && ContentType.GetByName(this.Node.NodeType.Name).AllowIncrementalNaming; } while (true) { try { Node.Save(this); break; } catch (Storage.Data.NodeAlreadyExistsException) { if (!autoNamingAllowed) { throw; } this.Node.Name = ContentNamingProvider.IncrementNameSuffixToLastName(Node.Name, Node.ParentId); } } }
public static void Restore(TrashBag trashBag, string targetPath, bool addNewName) { if (trashBag == null || string.IsNullOrEmpty(targetPath)) { throw new RestoreException(RestoreResultType.Nonedefined); } targetPath = targetPath.TrimEnd(new [] { '/' }); var node = trashBag.DeletedContent; if (node == null) { throw new InvalidOperationException("TrashBag is empty"); } var targetContentPath = RepositoryPath.Combine(targetPath, node.Name); var targetParent = Node.Load <GenericContent>(targetPath); if (targetParent == null) { throw new RestoreException(RestoreResultType.NoParent, RepositoryPath.GetParentPath(targetPath)); } // assert permissions if (!targetParent.Security.HasPermission(PermissionType.Open)) { throw new RestoreException(RestoreResultType.PermissionError, targetContentPath); } // target type check: ContentTypes field AssertRestoreContentType(targetParent, node); if (Node.Exists(targetContentPath)) { var newName = ContentNamingProvider.IncrementNameSuffixToLastName(node.Name, targetParent.Id); targetContentPath = RepositoryPath.Combine(targetPath, newName); if (addNewName) { try { // there is no other way right now (rename and move cannot be done at the same time) node.Name = newName; node.Save(); } catch (SenseNetSecurityException ex) { SnLog.WriteException(ex); throw new RestoreException(RestoreResultType.PermissionError, targetContentPath, ex); } catch (Exception ex) { SnLog.WriteException(ex); throw new RestoreException(RestoreResultType.UnknownError, targetContentPath, ex); } } else { throw new RestoreException(RestoreResultType.ExistingName, targetContentPath); } } var originalUser = User.Current; try { node.MoveTo(targetParent); AccessProvider.Current.SetCurrentUser(User.Administrator); trashBag.KeepUntil = DateTime.Today.AddDays(-1); trashBag.ForceDelete(); } catch (SenseNetSecurityException ex) { SnLog.WriteException(ex); throw new RestoreException(RestoreResultType.PermissionError, targetContentPath, ex); } catch (Exception ex) { SnLog.WriteException(ex); throw new RestoreException(RestoreResultType.UnknownError, targetContentPath, ex); } finally { AccessProvider.Current.SetCurrentUser(originalUser); } }