本文整理汇总了C#中IContent.ToXml方法的典型用法代码示例。如果您正苦于以下问题:C# IContent.ToXml方法的具体用法?C# IContent.ToXml怎么用?C# IContent.ToXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContent
的用法示例。
在下文中一共展示了IContent.ToXml方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveAndPublishDo
/// <summary>
/// Saves and Publishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise save events.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
private Attempt<PublishStatus> SaveAndPublishDo(IContent content, int userId = 0, bool raiseEvents = true)
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
{
return new Attempt<PublishStatus>(false, new PublishStatus(content, PublishStatusType.FailedCancelledByEvent));
}
}
using (new WriteLock(Locker))
{
//Has this content item previously been published? If so, we don't need to refresh the children
var previouslyPublished = content.HasIdentity && HasPublishedVersion(content.Id); //content might not have an id
var publishStatus = new PublishStatus(content, PublishStatusType.Success); //initially set to success
//Check if parent is published (although not if its a root node) - if parent isn't published this Content cannot be published
publishStatus.StatusType = CheckAndLogIsPublishable(content);
//Content contains invalid property values and can therefore not be published - fire event?
publishStatus.StatusType = CheckAndLogIsValid(content);
//set the invalid properties (if there are any)
publishStatus.InvalidProperties = ((ContentBase) content).LastInvalidProperties;
//if we're still successful, then publish using the strategy
if (publishStatus.StatusType == PublishStatusType.Success)
{
var internalStrategy = (PublishingStrategy)_publishingStrategy;
//Publish and then update the database with new status
var publishResult = internalStrategy.PublishInternal(content, userId);
//set the status type to the publish result
publishStatus.StatusType = publishResult.Result.StatusType;
}
//we are successfully published if our publishStatus is still Successful
bool published = publishStatus.StatusType == PublishStatusType.Success;
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateContentRepository(uow))
{
//Since this is the Save and Publish method, the content should be saved even though the publish fails or isn't allowed
content.WriterId = userId;
repository.AddOrUpdate(content);
uow.Commit();
var xml = content.ToXml();
//Preview Xml
CreateAndSavePreviewXml(xml, content.Id, content.Version, uow.Database);
if (published)
{
//Content Xml
CreateAndSaveContentXml(xml, content.Id, uow.Database);
}
}
if (raiseEvents)
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
//Save xml to db and call following method to fire event through PublishingStrategy to update cache
if (published)
{
_publishingStrategy.PublishingFinalized(content);
}
//We need to check if children and their publish state to ensure that we 'republish' content that was previously published
if (published && previouslyPublished == false && HasChildren(content.Id))
{
var descendants = GetPublishedDescendants(content);
_publishingStrategy.PublishingFinalized(descendants, false);
}
Audit.Add(AuditTypes.Publish, "Save and Publish performed by user", userId, content.Id);
return new Attempt<PublishStatus>(publishStatus.StatusType == PublishStatusType.Success, publishStatus);
}
}
示例2: Move
/// <summary>
/// Moves an <see cref="IContent"/> object to a new location by changing its parent id.
/// </summary>
/// <remarks>
/// If the <see cref="IContent"/> object is already published it will be
/// published after being moved to its new location. Otherwise it'll just
/// be saved with a new parent id.
/// </remarks>
/// <param name="content">The <see cref="IContent"/> to move</param>
/// <param name="parentId">Id of the Content's new Parent</param>
/// <param name="userId">Optional Id of the User moving the Content</param>
public void Move(IContent content, int parentId, int userId = 0)
{
using (new WriteLock(Locker))
{
//This ensures that the correct method is called if this method is used to Move to recycle bin.
if (parentId == -20)
{
MoveToRecycleBin(content, userId);
return;
}
if (Moving.IsRaisedEventCancelled(new MoveEventArgs<IContent>(content, parentId), this))
return;
content.WriterId = userId;
if (parentId == -1)
{
content.Path = string.Concat("-1,", content.Id);
content.Level = 1;
}
else
{
var parent = GetById(parentId);
content.Path = string.Concat(parent.Path, ",", content.Id);
content.Level = parent.Level + 1;
}
//If Content is being moved away from Recycle Bin, its state should be un-trashed
if (content.Trashed && parentId != -20)
{
content.ChangeTrashedState(false, parentId);
}
else
{
content.ParentId = parentId;
}
//If Content is published, it should be (re)published from its new location
if (content.Published)
{
//If Content is Publishable its saved and published
//otherwise we save the content without changing the publish state, and generate new xml because the Path, Level and Parent has changed.
if (IsPublishable(content))
{
SaveAndPublish(content, userId);
}
else
{
Save(content, false, userId, true);
using (var uow = _uowProvider.GetUnitOfWork())
{
var xml = content.ToXml();
var poco = new ContentXmlDto { NodeId = content.Id, Xml = xml.ToString(SaveOptions.None) };
var exists =
uow.Database.FirstOrDefault<ContentXmlDto>("WHERE nodeId = @Id", new { Id = content.Id }) !=
null;
int result = exists
? uow.Database.Update(poco)
: Convert.ToInt32(uow.Database.Insert(poco));
}
}
}
else
{
Save(content, userId);
}
//Ensure that Path and Level is updated on children
var children = GetChildren(content.Id);
if (children.Any())
{
foreach (var child in children)
{
Move(child, content.Id, userId);
}
}
Moved.RaiseEvent(new MoveEventArgs<IContent>(content, false, parentId), this);
Audit.Add(AuditTypes.Move, "Move Content performed by user", userId, content.Id);
}
}
示例3: Save
/// <summary>
/// Saves a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save</param>
/// <param name="changeState">Boolean indicating whether or not to change the Published state upon saving</param>
/// <param name="userId">Optional Id of the User saving the Content</param>
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param>
private void Save(IContent content, bool changeState, int userId = 0, bool raiseEvents = true)
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
return;
}
using (new WriteLock(Locker))
{
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateContentRepository(uow))
{
content.WriterId = userId;
//Only change the publish state if the "previous" version was actually published or marked as unpublished
if (changeState && (content.Published || ((Content)content).PublishedState == PublishedState.Unpublished))
content.ChangePublishedState(PublishedState.Saved);
repository.AddOrUpdate(content);
uow.Commit();
//Preview Xml
var xml = content.ToXml();
CreateAndSavePreviewXml(xml, content.Id, content.Version, uow.Database);
}
if (raiseEvents)
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
Audit.Add(AuditTypes.Save, "Save Content performed by user", userId, content.Id);
}
}
示例4: IndexConent
private static void IndexConent(IContent sender)
{
//only index this content if the indexer supports unpublished content. that is because the
// content.AfterUpdateDocumentCache will handle anything being published and will only index against indexers
// that only support published content.
// NOTE: The events for publishing have changed slightly from 6.0 to 6.1 and are streamlined in 6.1. Before
// this event would fire before publishing, then again after publishing. Now the save event fires once before
// publishing and that is all.
ExamineManager.Instance.ReIndexNode(
sender.ToXml(), "content",
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>()
.Where(x => x.SupportUnpublishedContent && x.EnableDefaultEventHandler));
}
示例5: Save
/// <summary>
/// Saves a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save</param>
/// <param name="changeState">Boolean indicating whether or not to change the Published state upon saving</param>
/// <param name="userId">Optional Id of the User saving the Content</param>
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise events.</param>
private void Save(IContent content, bool changeState, int userId = 0, bool raiseEvents = true)
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
return;
}
using (new WriteLock(Locker))
{
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateContentRepository(uow))
{
content.WriterId = userId;
//Only change the publish state if the "previous" version was actually published or marked as unpublished
if (changeState && (content.Published || ((Content)content).PublishedState == PublishedState.Unpublished))
content.ChangePublishedState(PublishedState.Saved);
repository.AddOrUpdate(content);
uow.Commit();
//Preview Xml
var xml = content.ToXml();
var previewPoco = new PreviewXmlDto
{
NodeId = content.Id,
Timestamp = DateTime.Now,
VersionId = content.Version,
Xml = xml.ToString(SaveOptions.None)
};
var previewExists =
uow.Database.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsPreviewXml WHERE nodeId = @Id AND versionId = @Version",
new { Id = content.Id, Version = content.Version }) != 0;
int previewResult = previewExists
? uow.Database.Update<PreviewXmlDto>(
"SET xml = @Xml, timestamp = @Timestamp WHERE nodeId = @Id AND versionId = @Version",
new
{
Xml = previewPoco.Xml,
Timestamp = previewPoco.Timestamp,
Id = previewPoco.NodeId,
Version = previewPoco.VersionId
})
: Convert.ToInt32(uow.Database.Insert(previewPoco));
}
if (raiseEvents)
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
Audit.Add(AuditTypes.Save, "Save Content performed by user", userId, content.Id);
}
}
示例6: SaveAndPublishDo
/// <summary>
/// Saves and Publishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise save events.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
private bool SaveAndPublishDo(IContent content, bool omitCacheRefresh = false, int userId = 0, bool raiseEvents = true)
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
return false;
}
using (new WriteLock(Locker))
{
//Has this content item previously been published? If so, we don't need to refresh the children
var previouslyPublished = HasPublishedVersion(content.Id);
var validForPublishing = true;
//Check if parent is published (although not if its a root node) - if parent isn't published this Content cannot be published
if (content.ParentId != -1 && content.ParentId != -20 && IsPublishable(content) == false)
{
LogHelper.Info<ContentService>(
string.Format(
"Content '{0}' with Id '{1}' could not be published because its parent is not published.",
content.Name, content.Id));
validForPublishing = false;
}
//Content contains invalid property values and can therefore not be published - fire event?
if (!content.IsValid())
{
LogHelper.Info<ContentService>(
string.Format(
"Content '{0}' with Id '{1}' could not be published because of invalid properties.",
content.Name, content.Id));
validForPublishing = false;
}
//Publish and then update the database with new status
bool published = validForPublishing && _publishingStrategy.Publish(content, userId);
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateContentRepository(uow))
{
//Since this is the Save and Publish method, the content should be saved even though the publish fails or isn't allowed
content.WriterId = userId;
repository.AddOrUpdate(content);
uow.Commit();
var xml = content.ToXml();
//Preview Xml
var previewPoco = new PreviewXmlDto
{
NodeId = content.Id,
Timestamp = DateTime.Now,
VersionId = content.Version,
Xml = xml.ToString(SaveOptions.None)
};
var previewExists =
uow.Database.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsPreviewXml WHERE nodeId = @Id AND versionId = @Version",
new { Id = content.Id, Version = content.Version }) != 0;
int previewResult = previewExists
? uow.Database.Update<PreviewXmlDto>(
"SET xml = @Xml, timestamp = @Timestamp WHERE nodeId = @Id AND versionId = @Version",
new
{
Xml = previewPoco.Xml,
Timestamp = previewPoco.Timestamp,
Id = previewPoco.NodeId,
Version = previewPoco.VersionId
})
: Convert.ToInt32(uow.Database.Insert(previewPoco));
if (published)
{
//Content Xml
var contentPoco = new ContentXmlDto { NodeId = content.Id, Xml = xml.ToString(SaveOptions.None) };
var contentExists = uow.Database.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @Id", new { Id = content.Id }) != 0;
int contentResult = contentExists
? uow.Database.Update(contentPoco)
: Convert.ToInt32(uow.Database.Insert(contentPoco));
}
}
if (raiseEvents)
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
//Save xml to db and call following method to fire event through PublishingStrategy to update cache
if (published && omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(content);
//We need to check if children and their publish state to ensure that we 'republish' content that was previously published
if (published && omitCacheRefresh == false && previouslyPublished == false && HasChildren(content.Id))
//.........这里部分代码省略.........
示例7: IndexContent
private void IndexContent(IContent sender)
{
// Only add to indexes that have SupportUnpublishedContent set to true, this is because any indexer
// that only supports published content will be notified based on the UmbracoExamineManager.content_AfterUpdateDocumentCache
// event handler.
ExamineManager.Instance.ReIndexNode(
sender.ToXml(), "content",
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>()
.Where(x => x.SupportUnpublishedContent && x.EnableDefaultEventHandler));
}
示例8: SaveAndPublishDo
/// <summary>
/// Saves and Publishes a single <see cref="IContent"/> object
/// </summary>
/// <param name="content">The <see cref="IContent"/> to save and publish</param>
/// <param name="omitCacheRefresh">Optional boolean to avoid having the cache refreshed when calling this Publish method. By default this method will update the cache.</param>
/// <param name="userId">Optional Id of the User issueing the publishing</param>
/// <param name="raiseEvents">Optional boolean indicating whether or not to raise save events.</param>
/// <returns>True if publishing succeeded, otherwise False</returns>
private bool SaveAndPublishDo(IContent content, bool omitCacheRefresh = false, int userId = 0, bool raiseEvents = true)
{
if (raiseEvents)
{
if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IContent>(content), this))
return false;
}
using (new WriteLock(Locker))
{
//Has this content item previously been published? If so, we don't need to refresh the children
var previouslyPublished = content.HasIdentity && HasPublishedVersion(content.Id);
var validForPublishing = CheckAndLogIsPublishable(content) && CheckAndLogIsValid(content);
//Publish and then update the database with new status
bool published = validForPublishing && _publishingStrategy.Publish(content, userId);
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateContentRepository(uow))
{
//Since this is the Save and Publish method, the content should be saved even though the publish fails or isn't allowed
content.WriterId = userId;
repository.AddOrUpdate(content);
uow.Commit();
var xml = content.ToXml();
//Preview Xml
CreateAndSavePreviewXml(xml, content.Id, content.Version, uow.Database);
if (published)
{
//Content Xml
CreateAndSaveContentXml(xml, content.Id, uow.Database);
}
}
if (raiseEvents)
Saved.RaiseEvent(new SaveEventArgs<IContent>(content, false), this);
//Save xml to db and call following method to fire event through PublishingStrategy to update cache
if (published && omitCacheRefresh == false)
_publishingStrategy.PublishingFinalized(content);
//We need to check if children and their publish state to ensure that we 'republish' content that was previously published
if (published && omitCacheRefresh == false && previouslyPublished == false && HasChildren(content.Id))
{
var descendants = GetPublishedDescendants(content);
_publishingStrategy.PublishingFinalized(descendants, false);
}
Audit.Add(AuditTypes.Publish, "Save and Publish performed by user", userId, content.Id);
return published;
}
}