本文整理汇总了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);
}
}
示例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;
}
}
示例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));
}
}
}
}
}
示例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"));
}
//.........这里部分代码省略.........
示例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);
}
示例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);
}
示例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);
}
}
}
}