当前位置: 首页>>代码示例>>C#>>正文


C# Document.Copy方法代码示例

本文整理汇总了C#中umbraco.cms.businesslogic.web.Document.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Copy方法的具体用法?C# Document.Copy怎么用?C# Document.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在umbraco.cms.businesslogic.web.Document的用法示例。


在下文中一共展示了Document.Copy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyDocument

 /// <summary>Copy document under another document.</summary>
 public static void CopyDocument(Document cmsSourceDocument, int cmsTargetDocumentId, bool relateToOriginal = false)
 {
     // Validate dependencies.
     if(cmsSourceDocument != null && cmsTargetDocumentId >= 0) {
     cmsSourceDocument.Copy(cmsTargetDocumentId, cmsSourceDocument.User, relateToOriginal);
     }
 }
开发者ID:williamchang,项目名称:umbraco-labs,代码行数:8,代码来源:CmsDocumentHelper.cs

示例2: Detach

 public override GridItem Detach(string moduleId)
 {
     var parent = new Document(Convert.ToInt32(_referenceId));
     var source = new Document(Convert.ToInt32(moduleId));
     var author = umbraco.BusinessLogic.User.GetUser(0);
     var modulesFolder = GetModulesFolder(parent, author);
     var destination = source.Copy(modulesFolder.Id, author);
     umbraco.library.UpdateDocumentCache(destination.Id);
     using (CmsContext.Editing)
     {
         var entity = CmsService.Instance.GetItem<Entity>(new Id(destination.Id));
         var result = GetGridItem(entity);
         result.IsLocal = true;
         return result;
     }
 }
开发者ID:Psolow,项目名称:Umbraco-Public,代码行数:16,代码来源:UmbracoGridModuleProvider.cs

示例3: Document_AfterPublish

        /// <summary>On event, after publishing document.</summary>
        /// <param name="sender">The sender (a document object).</param>
        /// <param name="e">The <see cref="umbraco.cms.businesslogic.PublishEventArgs"/> instance containing the event data.</param>
        protected void Document_AfterPublish(Document sender, PublishEventArgs e)
        {
            var isCopied = false;

            // Validate document have a relation.
            if(sender.Relations.Length > 0 && sender.Level > 1) {
            foreach(var r in sender.Parent.Relations) {
                // Validate document has been copied by relation type.
                if(r.RelType.Alias == "relateDocumentOnCopy") {
                    isCopied = true;
                    break;
                }
            }
            }
            // Validate document is new.
            if(!isCopied && sender.Level > 1) {
            var parent = new Document(sender.Parent.Id);
            // Validate document's parent have a relation.
            if(parent.Relations.Length > 0) {
                foreach(var r in parent.Relations) {
                    // Validate document's parent is from "Main Site" sender's parent and relation type.
                    if(r.Parent.Id == sender.ParentId && r.RelType.Alias == "relateDocumentOnCopy") {
                        // Copy document (including current data) under parent of related child.
                        sender.Copy(r.Child.Id, sender.User, true);
                        // Append log, audit trail.
                        Log.Add(LogTypes.Copy, sender.Id, String.Format("Copy related document under parent document (name:{0} id:{1})", r.Child.Text, r.Child.Id));
                    }
                }
            }
            }
        }
开发者ID:williamchang,项目名称:umbraco-labs,代码行数:34,代码来源:RelationBackofficeEvent.cs

示例4: HandleDocumentMoveOrCopy

        private void HandleDocumentMoveOrCopy()
        {
            if (Request.GetItemAsString("copyTo") != "" && Request.GetItemAsString("id") != "")
            {
                // Check if the current node is allowed at new position
                var nodeAllowed = false;

                IContentBase currContent;
                IContentBase parentContent = null;
                IContentTypeBase parentContentType = null;
                if (CurrentApp == "content")
                {
                    currContent = Services.ContentService.GetById(Request.GetItemAs<int>("id"));
                    if (Request.GetItemAs<int>("copyTo") != -1)
                    {
                        parentContent = Services.ContentService.GetById(Request.GetItemAs<int>("copyTo"));
                        if (parentContent != null)
                        {
                            parentContentType = Services.ContentTypeService.GetContentType(parentContent.ContentTypeId);
                        }   
                    }    
                }
                else
                {
                    currContent = Services.MediaService.GetById(Request.GetItemAs<int>("id"));
                    if (Request.GetItemAs<int>("copyTo") != -1)
                    {
                        parentContent = Services.MediaService.GetById(Request.GetItemAs<int>("copyTo"));
                        if (parentContent != null)
                        {
                            parentContentType = Services.ContentTypeService.GetMediaType(parentContent.ContentTypeId);
                        }
                    }                    
                }

                // Check on contenttypes
                if (parentContentType == null)
                {
                    //check if this is allowed at root
                    IContentTypeBase currContentType;
                    if (CurrentApp == "content")
                    {
                        currContentType = Services.ContentTypeService.GetContentType(currContent.ContentTypeId);
                    }
                    else
                    {
                        currContentType = Services.ContentTypeService.GetMediaType(currContent.ContentTypeId);
                    }
                    nodeAllowed = currContentType.AllowedAsRoot;
                    if (!nodeAllowed)
                    {
                        feedback.Text = ui.Text("moveOrCopy", "notAllowedAtRoot", UmbracoUser);
                        feedback.type = uicontrols.Feedback.feedbacktype.error;
                    }
                }
                else
                {
                    var allowedChildContentTypeIds = parentContentType.AllowedContentTypes.Select(x => x.Id).ToArray();
                    if (allowedChildContentTypeIds.Any(x => x.Value == currContent.ContentTypeId))
                    {
                        nodeAllowed = true;
                    }

                    if (nodeAllowed == false)
                    {
                        feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", UmbracoUser);
                        feedback.type = uicontrols.Feedback.feedbacktype.error;
                    }
                    else
                    {
                        // Check on paths
                        if ((string.Format(",{0},", parentContent.Path)).IndexOf(string.Format(",{0},", currContent.Id)) > -1)
                        {
                            nodeAllowed = false;
                            feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", UmbracoUser);
                            feedback.type = uicontrols.Feedback.feedbacktype.error;
                        }
                    }
                }

                if (nodeAllowed)
                {
                    pane_form.Visible = false;
                    pane_form_notice.Visible = false;
                    panel_buttons.Visible = false;

                    var newNodeCaption = parentContent == null 
                        ? ui.Text(CurrentApp) 
                        : parentContent.Name;

                    string[] nodes = { currContent.Name, newNodeCaption };

                    if (Request["mode"] == "cut")
                    {
                        if (CurrentApp == Constants.Applications.Content)
                        {
                            //Backwards comp. change, so old events are fired #U4-2731
                            var doc = new Document(currContent as IContent);
                            doc.Move(Request.GetItemAs<int>("copyTo"));
                        }
//.........这里部分代码省略.........
开发者ID:saciervo,项目名称:Umbraco-CMS,代码行数:101,代码来源:moveOrCopy.aspx.cs

示例5: Document_Copy_And_Relate

        public void Document_Copy_And_Relate()
        {
            //System.Diagnostics.Debugger.Break();
            Document target = new Document(GetExistingNodeId());
            int parentId = target.ParentId;
            bool RelateToOrignal = true;

            //get children ids            
            var childrenIds = GetChildNodesOfParent(target).Select(x => x.Id);

            target.Copy(parentId, m_User, RelateToOrignal);

            var parentChildNodes = GetChildNodesOfParent(target);
            Assert.AreEqual(childrenIds.Count() + 1, parentChildNodes.Count());
           
            //get the children difference which should be the new node
            var diff = parentChildNodes.Select(x => x.Id).Except(childrenIds);

            Assert.AreEqual(1, diff.Count());

            Document newDoc = new Document(diff.First());

            RecycleAndDelete(newDoc);
        }
开发者ID:elrute,项目名称:Triphulcas,代码行数:24,代码来源:DocumentTest.cs

示例6: Document_Copy

        public void Document_Copy()
        {
            //System.Diagnostics.Debugger.Break();
            Document target = new Document(GetExistingNodeId());
            int parentId = target.ParentId;
            bool RelateToOrignal = false;

            //get children ids for the current parent
            var childrenIds = GetChildNodesOfParent(target).Select(x => x.Id);

            //copy the node
            target.Copy(parentId, m_User, RelateToOrignal);

            //test that the child id count + 1 is equal to the total child count
            Assert.AreEqual(childrenIds.Count() + 1, GetChildNodesOfParent(target).Count(), "Child node counts do not match");

            //get the list of new child ids from the parent
            var newChildIds = GetChildNodesOfParent(target).Select(x => x.Id);
            //get the children difference which should be the new node
            var diff = newChildIds.Except(childrenIds);
            
            Assert.AreEqual(1, diff.Count());

            //get the node that is the difference to compare
            Document newDoc = new Document(diff.First());
            Assert.AreEqual<int>(parentId, newDoc.ParentId);

            RecycleAndDelete(newDoc);
        }
开发者ID:elrute,项目名称:Triphulcas,代码行数:29,代码来源:DocumentTest.cs

示例7: HandleDocumentMoveOrCopy

        private void HandleDocumentMoveOrCopy()
        {
            if (helper.Request("copyTo") != "" && helper.Request("id") != "")
            {
                // Check if the current node is allowed at new position
                var nodeAllowed = false;

                var currentNode = new cms.businesslogic.Content(int.Parse(helper.Request("id")));

				var newNode = new cms.businesslogic.Content(int.Parse(helper.Request("copyTo")));

                // Check on contenttypes
                if (int.Parse(helper.Request("copyTo")) == -1)
                {
                    nodeAllowed = true;
                }
                else
                {
                    if (newNode.ContentType.AllowedChildContentTypeIDs.Where(c => c == currentNode.ContentType.Id).Any())
                    {
                        nodeAllowed = true;
                    }

                    if (nodeAllowed == false)
                    {
                        feedback.Text = ui.Text("moveOrCopy", "notAllowedByContentType", base.getUser());
                        feedback.type = uicontrols.Feedback.feedbacktype.error;
                    }
                    else
                    {
                        // Check on paths
                        if ((string.Format(",{0},", newNode.Path)).IndexOf(string.Format(",{0},", currentNode.Id)) > -1)
                        {
                            nodeAllowed = false;
                            feedback.Text = ui.Text("moveOrCopy", "notAllowedByPath", base.getUser());
                            feedback.type = uicontrols.Feedback.feedbacktype.error;
                        }
                    }
                }

                if (nodeAllowed)
                {
                    pane_form.Visible = false;
                    pane_form_notice.Visible = false;
                    panel_buttons.Visible = false;

                    var newNodeCaption = newNode.Id == -1 ? ui.Text(CurrentApp) : newNode.Text;

                    string[] nodes = { currentNode.Text, newNodeCaption };

                    if (Request["mode"] == "cut")
                    {
                        if (CurrentApp == "content")
                        {
                            //PPH changed this to document instead of cmsNode to handle republishing.
                            var documentId = int.Parse(helper.Request("id"));
                            var document = new Document(documentId);
                            document.Move(int.Parse(helper.Request("copyTo")));
                            library.RefreshContent();
                        }
                        else
                        {
                            var media = new Media(int.Parse(UmbracoContext.Current.Request["id"]));
                            media.Move(int.Parse(UmbracoContext.Current.Request["copyTo"]));
                            media = new Media(int.Parse(UmbracoContext.Current.Request["id"]));
                            media.XmlGenerate(new XmlDocument());
                            library.ClearLibraryCacheForMedia(media.Id);
                        }

                        feedback.Text = ui.Text("moveOrCopy", "moveDone", nodes, getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>";
                        feedback.type = uicontrols.Feedback.feedbacktype.success;

                        // refresh tree
                        ClientTools.MoveNode(currentNode.Id.ToString(), newNode.Path);
                    }
                    else
                    {
                        var document = new Document(int.Parse(helper.Request("id")));
                        document.Copy(int.Parse(helper.Request("copyTo")), this.getUser(), RelateDocuments.Checked);
                        feedback.Text = ui.Text("moveOrCopy", "copyDone", nodes, base.getUser()) + "</p><p><a href='#' onclick='" + ClientTools.Scripts.CloseModalWindow() + "'>" + ui.Text("closeThisWindow") + "</a>";
                        feedback.type = uicontrols.Feedback.feedbacktype.success;
                        ClientTools.CopyNode(currentNode.Id.ToString(), newNode.Path);
                    }
                }
            }
        }
开发者ID:phaniarveti,项目名称:Experiments,代码行数:86,代码来源:moveOrCopy.aspx.cs


注:本文中的umbraco.cms.businesslogic.web.Document.Copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。