private void MoveNode(string encodedSourcePath, string encodedTargetPath, SystemFolder testRoot, bool clearTarget = false) { string sourcePath = DecodePath(testRoot, encodedSourcePath); string targetPath = DecodePath(testRoot, encodedTargetPath); int sourceId = Node.LoadNode(sourcePath).Id; int targetId = Node.LoadNode(targetPath).Id; //make sure target does not contain the source node if (clearTarget) { var sourceName = RepositoryPath.GetFileNameSafe(sourcePath); if (!string.IsNullOrEmpty(sourceName)) { var targetPathWithName = RepositoryPath.Combine(targetPath, sourceName); if (Node.Exists(targetPathWithName)) { Node.ForceDelete(targetPathWithName); } } } Node.Move(sourcePath, targetPath); Node parentNode = Node.LoadNode(targetId); Node childNode = Node.LoadNode(sourceId); Assert.IsTrue(childNode.ParentId == parentNode.Id, "Source was not moved."); }
public static Handlers.ViewBase CopyViewLocal(string listPath, string viewPath, bool setAsDefault) { if (string.IsNullOrEmpty(listPath)) { throw new ArgumentNullException("listPath"); } if (string.IsNullOrEmpty(viewPath)) { throw new ArgumentNullException("viewPath"); } var viewName = RepositoryPath.GetFileNameSafe(viewPath); var viewsFolderPath = RepositoryPath.Combine(listPath, ViewManager.VIEWSFOLDERNAME); var views = Content.Load(viewsFolderPath) ?? Tools.CreateStructure(viewsFolderPath, "SystemFolder"); Node.Copy(viewPath, viewsFolderPath); var localView = Node.Load <Handlers.ViewBase>(RepositoryPath.Combine(viewsFolderPath, viewName)); if (setAsDefault) { var cl = Node.Load <ContentList>(listPath); if (cl != null) { cl.DefaultView = viewName; cl.Save(); } } return(localView); }
public string RepositoryPathToUrl(string repositoryPath) { var repoPath = repositoryPath; var domain = Protocol + Host; if (string.IsNullOrEmpty(repoPath)) { return(domain); } var parentPath = RepositoryPath.GetParentPath(repositoryPath); var name = RepositoryPath.GetFileNameSafe(repositoryPath); // encode the filename return(RepositoryPath.Combine(domain, parentPath, Uri.EscapeUriString(name))); }
public static Handlers.ViewBase CopyViewLocal(string listPath, string viewPath, bool setAsDefault) { if (string.IsNullOrEmpty(listPath)) { throw new ArgumentNullException("listPath"); } if (string.IsNullOrEmpty(viewPath)) { throw new ArgumentNullException("viewPath"); } var viewName = RepositoryPath.GetFileNameSafe(viewPath); var viewsFolderPath = RepositoryPath.Combine(listPath, ViewManager.VIEWSFOLDERNAME); var views = Content.Load(viewsFolderPath) ?? Tools.CreateStructure(viewsFolderPath, "SystemFolder"); var viewsGc = views != null ? views.ContentHandler as GenericContent : null; //set at least the ListView type as allowed content type if (viewsGc != null && viewsGc.GetAllowedChildTypes().Count() == 0) { using (new SystemAccount()) { viewsGc.AllowedChildTypes = new[] { ContentType.GetByName("ListView") }; viewsGc.Save(SavingMode.KeepVersion); } } Node.Copy(viewPath, viewsFolderPath); var localView = Node.Load <Handlers.ViewBase>(RepositoryPath.Combine(viewsFolderPath, viewName)); if (setAsDefault) { var cl = Node.Load <ContentList>(listPath); if (cl != null) { cl.DefaultView = viewName; cl.Save(); } } return(localView); }
private static ContentType GetContentType(ActionBase action) { var parameters = action.GetParameteres(); var contentTypeName = parameters.ContainsKey("ContentTypeName") ? parameters["ContentTypeName"] as string ?? string.Empty : string.Empty; if (string.IsNullOrEmpty(contentTypeName)) { return(null); } var contentType = ContentType.GetByName(contentTypeName); if (contentType == null) { contentTypeName = RepositoryPath.GetFileNameSafe(RepositoryPath.GetParentPath(contentTypeName)); contentType = ContentType.GetByName(contentTypeName); } return(contentType); }
protected void BuildResultScreen(RestoreException rex) { ClearControls(); if (this.RestoreResult == RestoreResultType.Nonedefined) { return; } var trashBag = GetContextNode() as TrashBag; if (trashBag == null) { return; } var view = this.InfoViewPath; var messageTitle = string.Empty; var messageDesc = string.Empty; switch (this.RestoreResult) { case RestoreResultType.UnknownError: view = this.ErrorViewPath; break; } var c = Page.LoadControl(view); if (c == null) { return; } this.Controls.Add(c); if (rex != null) { //build UI info from the exception var folderName = string.IsNullOrEmpty(rex.ContentPath) ? "{folder}" : RepositoryPath.GetFileNameSafe(RepositoryPath.GetParentPath(rex.ContentPath)); var contentName = string.IsNullOrEmpty(rex.ContentPath) ? "{content}" : RepositoryPath.GetFileNameSafe(rex.ContentPath); switch (rex.ResultType) { case RestoreResultType.Nonedefined: case RestoreResultType.UnknownError: messageTitle = rex.Message; messageDesc = rex.ToString(); break; case RestoreResultType.PermissionError: messageTitle = "Not enough permissions to complete the operation"; messageDesc = rex.Message; break; case RestoreResultType.ForbiddenContentType: messageTitle = "Cannot restore this type of content to the selected target"; break; case RestoreResultType.ExistingName: messageTitle = "Content with this name already exists in the folder " + folderName; messageDesc = string.Format( "You can restore it with a new name (<strong>{0}</strong>) or please choose a different destination", contentName); break; case RestoreResultType.NoParent: messageTitle = "Destination folder is missing"; messageDesc = "Please choose a different destination"; break; } } if (this.MessageControl != null) { this.MessageControl.ButtonsAction += MessageControl_ButtonsAction; if (this.NewNameButton != null) { this.NewNameButton.Command += MessageControl_ButtonsAction; } if (this.MessageLabel != null) { this.MessageLabel.Text = messageTitle; } if (this.MessageDescLabel != null) { this.MessageDescLabel.Text = messageDesc; } } if (this.ContentLabel != null) { var lc = trashBag.DeletedContent; if (lc != null) { this.ContentLabel.Text = HttpUtility.HtmlEncode(SNSR.GetString(lc.DisplayName)); } } ShowHideControls(); }
public string GetParentNameSafe() { return(RepositoryPath.GetFileNameSafe(RepositoryPath.GetParentPath(ContentPath))); }
public static string GetFileNameSafe(string path) { return(RepositoryPath.GetFileNameSafe(path)); }