mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Refactoring Import methods
This commit is contained in:
@@ -42,6 +42,11 @@ namespace Orchard.AntiSpam.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(SpamFilterPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var status = context.Attribute(part.PartDefinition.Name, "Status");
|
||||
|
||||
if (status != null) {
|
||||
|
@@ -92,10 +92,14 @@ namespace Orchard.ArchiveLater.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ArchiveLaterPart part, ImportContentContext context) {
|
||||
var scheduledUtc = context.Attribute(part.PartDefinition.Name, "ScheduledArchiveUtc");
|
||||
if (scheduledUtc != null) {
|
||||
part.ScheduledArchiveUtc.Value = XmlConvert.ToDateTime(scheduledUtc, XmlDateTimeSerializationMode.Utc);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "ScheduledArchiveUtc", scheduledUtc =>
|
||||
part.ScheduledArchiveUtc.Value = XmlConvert.ToDateTime(scheduledUtc, XmlDateTimeSerializationMode.Utc)
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(ArchiveLaterPart part, ExportContentContext context) {
|
||||
|
@@ -110,20 +110,22 @@ namespace Orchard.Autoroute.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(AutoroutePart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var displayAlias = context.Attribute(part.PartDefinition.Name, "Alias");
|
||||
if (displayAlias != null) {
|
||||
part.DisplayAlias = displayAlias;
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var customPattern = context.Attribute(part.PartDefinition.Name, "CustomPattern");
|
||||
if (customPattern != null) {
|
||||
part.CustomPattern = customPattern;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Alias", displayAlias =>
|
||||
part.DisplayAlias = displayAlias
|
||||
);
|
||||
|
||||
var useCustomPattern = context.Attribute(part.PartDefinition.Name, "UseCustomPattern");
|
||||
if (useCustomPattern != null) {
|
||||
part.UseCustomPattern = bool.Parse(useCustomPattern);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "CustomPattern", customPattern =>
|
||||
part.CustomPattern = customPattern
|
||||
);
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "UseCustomPattern", useCustomPattern =>
|
||||
part.UseCustomPattern = bool.Parse(useCustomPattern)
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(AutoroutePart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
|
@@ -53,10 +53,14 @@ namespace Orchard.Blogs.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(BlogArchivesPart part, ImportContentContext context) {
|
||||
var blog = context.Attribute(part.PartDefinition.Name, "Blog");
|
||||
if (blog != null) {
|
||||
part.BlogId = context.GetItemFromSession(blog).Id;
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Blog", blog =>
|
||||
part.BlogId = context.GetItemFromSession(blog).Id
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(BlogArchivesPart part, ExportContentContext context) {
|
||||
|
@@ -45,20 +45,22 @@ namespace Orchard.Blogs.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(BlogPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var description = context.Attribute(part.PartDefinition.Name, "Description");
|
||||
if (description != null) {
|
||||
part.Description = description;
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var postCount = context.Attribute(part.PartDefinition.Name, "PostCount");
|
||||
if (postCount != null) {
|
||||
part.PostCount = Convert.ToInt32(postCount);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Description", description =>
|
||||
part.Description = description
|
||||
);
|
||||
|
||||
var feedProxyUrl = context.Attribute(part.PartDefinition.Name, "FeedProxyUrl");
|
||||
if (feedProxyUrl != null) {
|
||||
part.FeedProxyUrl = feedProxyUrl;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "PostCount", postCount =>
|
||||
part.PostCount = Convert.ToInt32(postCount)
|
||||
);
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "FeedProxyUrl", feedProxyUrl =>
|
||||
part.FeedProxyUrl = feedProxyUrl
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(BlogPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
|
@@ -66,22 +66,25 @@ namespace Orchard.Blogs.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(RecentBlogPostsPart part, ImportContentContext context) {
|
||||
var blog = context.Attribute(part.PartDefinition.Name, "Blog");
|
||||
if (blog != null) {
|
||||
part.BlogId = context.GetItemFromSession(blog).Id;
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var count = context.Attribute(part.PartDefinition.Name, "Count");
|
||||
if (count != null) {
|
||||
part.Count = Convert.ToInt32(count);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Blog", blog =>
|
||||
part.BlogId = context.GetItemFromSession(blog).Id
|
||||
);
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Count", count =>
|
||||
part.Count = Convert.ToInt32(count)
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(RecentBlogPostsPart part, ExportContentContext context) {
|
||||
var blog = _contentManager.Get(part.BlogId);
|
||||
var blogIdentity = _contentManager.GetItemMetadata(blog).Identity;
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
|
||||
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Blog", blogIdentity);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count);
|
||||
}
|
||||
}
|
||||
|
@@ -134,71 +134,65 @@ namespace Orchard.Comments.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(CommentPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var author = context.Attribute(part.PartDefinition.Name, "Author");
|
||||
if (author != null) {
|
||||
part.Record.Author = author;
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siteName = context.Attribute(part.PartDefinition.Name, "SiteName");
|
||||
if (siteName != null) {
|
||||
part.Record.SiteName = siteName;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Author", author =>
|
||||
part.Record.Author = author
|
||||
);
|
||||
|
||||
var userName = context.Attribute(part.PartDefinition.Name, "UserName");
|
||||
if (userName != null) {
|
||||
part.Record.UserName = userName;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "SiteName", siteName =>
|
||||
part.Record.SiteName = siteName
|
||||
);
|
||||
|
||||
var email = context.Attribute(part.PartDefinition.Name, "Email");
|
||||
if (email != null) {
|
||||
part.Record.Email = email;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "UserName", userName =>
|
||||
part.Record.UserName = userName
|
||||
);
|
||||
|
||||
var position = context.Attribute(part.PartDefinition.Name, "Position");
|
||||
if (position != null) {
|
||||
part.Record.Position = decimal.Parse(position, CultureInfo.InvariantCulture);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Email", email =>
|
||||
part.Record.Email = email
|
||||
);
|
||||
|
||||
var status = context.Attribute(part.PartDefinition.Name, "Status");
|
||||
if (status != null) {
|
||||
part.Record.Status = (CommentStatus)Enum.Parse(typeof(CommentStatus), status);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Position", position =>
|
||||
part.Record.Position = decimal.Parse(position, CultureInfo.InvariantCulture)
|
||||
);
|
||||
|
||||
var commentDate = context.Attribute(part.PartDefinition.Name, "CommentDateUtc");
|
||||
if (commentDate != null) {
|
||||
part.Record.CommentDateUtc = XmlConvert.ToDateTime(commentDate, XmlDateTimeSerializationMode.Utc);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Status", status =>
|
||||
part.Record.Status = (CommentStatus)Enum.Parse(typeof(CommentStatus), status)
|
||||
);
|
||||
|
||||
var text = context.Attribute(part.PartDefinition.Name, "CommentText");
|
||||
if (text != null) {
|
||||
part.Record.CommentText = text;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "CommentDateUtc", commentDate =>
|
||||
part.Record.CommentDateUtc = XmlConvert.ToDateTime(commentDate, XmlDateTimeSerializationMode.Utc)
|
||||
);
|
||||
|
||||
var commentedOn = context.Attribute(part.PartDefinition.Name, "CommentedOn");
|
||||
if (commentedOn != null) {
|
||||
context.ImportAttribute(part.PartDefinition.Name, "CommentText", text =>
|
||||
part.Record.CommentText = text
|
||||
);
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "CommentedOn", commentedOn => {
|
||||
var contentItem = context.GetItemFromSession(commentedOn);
|
||||
if (contentItem != null) {
|
||||
part.Record.CommentedOn = contentItem.Id;
|
||||
}
|
||||
|
||||
contentItem.As<CommentsPart>().Record.CommentPartRecords.Add(part.Record);
|
||||
}
|
||||
});
|
||||
|
||||
var repliedOn = context.Attribute(part.PartDefinition.Name, "RepliedOn");
|
||||
if (repliedOn != null) {
|
||||
context.ImportAttribute(part.PartDefinition.Name, "RepliedOn", repliedOn => {
|
||||
var contentItem = context.GetItemFromSession(repliedOn);
|
||||
if (contentItem != null) {
|
||||
part.Record.RepliedOn = contentItem.Id;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var commentedOnContainer = context.Attribute(part.PartDefinition.Name, "CommentedOnContainer");
|
||||
if (commentedOnContainer != null) {
|
||||
context.ImportAttribute(part.PartDefinition.Name, "CommentedOnContainer", commentedOnContainer => {
|
||||
var container = context.GetItemFromSession(commentedOnContainer);
|
||||
if (container != null) {
|
||||
part.Record.CommentedOnContainer = container.Id;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Exporting(CommentPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
|
@@ -113,20 +113,22 @@ namespace Orchard.Comments.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(CommentsPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var commentsShown = context.Attribute(part.PartDefinition.Name, "CommentsShown");
|
||||
if (commentsShown != null) {
|
||||
part.CommentsShown = Convert.ToBoolean(commentsShown);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var commentsActive = context.Attribute(part.PartDefinition.Name, "CommentsActive");
|
||||
if (commentsActive != null) {
|
||||
part.CommentsActive = Convert.ToBoolean(commentsActive);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "CommentsShown", commentsShown =>
|
||||
part.CommentsShown = Convert.ToBoolean(commentsShown)
|
||||
);
|
||||
|
||||
var threadedComments = context.Attribute(part.PartDefinition.Name, "ThreadedComments");
|
||||
if (threadedComments != null) {
|
||||
part.ThreadedComments = Convert.ToBoolean(threadedComments);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "CommentsActive", commentsActive =>
|
||||
part.CommentsActive = Convert.ToBoolean(commentsActive)
|
||||
);
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "ThreadedComments", threadedComments =>
|
||||
part.ThreadedComments = Convert.ToBoolean(threadedComments)
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(CommentsPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
|
@@ -163,6 +163,11 @@ namespace Orchard.ContentPermissions.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ContentPermissionsPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Enabled", s => part.Enabled = XmlConvert.ToBoolean(s));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "ViewContent", s => part.ViewContent = s);
|
||||
context.ImportAttribute(part.PartDefinition.Name, "EditContent", s => part.EditContent = s);
|
||||
|
@@ -62,14 +62,18 @@ namespace Orchard.ContentPicker.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ContentMenuItemPart part, ImportContentContext context) {
|
||||
var contentItemId = context.Attribute(part.PartDefinition.Name, "ContentItem");
|
||||
if (contentItemId != null) {
|
||||
var contentItem = context.GetItemFromSession(contentItemId);
|
||||
part.Content = contentItem;
|
||||
}
|
||||
else {
|
||||
part.Content = null;
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "ContentItem",
|
||||
contentItemId => {
|
||||
var contentItem = context.GetItemFromSession(contentItemId);
|
||||
part.Content = contentItem;
|
||||
}, () =>
|
||||
part.Content = null
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(ContentMenuItemPart part, ExportContentContext context) {
|
||||
|
@@ -59,21 +59,20 @@ namespace Orchard.CustomForms.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(CustomFormPart part, ImportContentContext context) {
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "ContentType"), x => part.Record.ContentType = x);
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "SaveContentItem"), x => part.Record.SaveContentItem = Boolean.Parse(x));
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "CustomMessage"), x => part.Record.CustomMessage = Boolean.Parse(x));
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "Message"), x => part.Record.Message = x);
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "Redirect"), x => part.Record.Redirect = Boolean.Parse(x));
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "RedirectUrl"), x => part.Record.RedirectUrl = x);
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "SubmitButtonText"), x => part.Record.SubmitButtonText = x);
|
||||
}
|
||||
|
||||
private static void IfNotNull<T>(T value, Action<T> then) {
|
||||
if (value != null) {
|
||||
then(value);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "ContentType", x => part.Record.ContentType = x);
|
||||
context.ImportAttribute(part.PartDefinition.Name, "SaveContentItem", x => part.Record.SaveContentItem = Boolean.Parse(x));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "CustomMessage", x => part.Record.CustomMessage = Boolean.Parse(x));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Message", x => part.Record.Message = x);
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Redirect", x => part.Record.Redirect = Boolean.Parse(x));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "RedirectUrl", x => part.Record.RedirectUrl = x);
|
||||
context.ImportAttribute(part.PartDefinition.Name, "SubmitButtonText", x => part.Record.SubmitButtonText = x);
|
||||
}
|
||||
|
||||
protected override void Exporting(CustomFormPart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("ContentType", part.Record.ContentType);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("SaveContentItem", part.Record.SaveContentItem);
|
||||
|
@@ -140,6 +140,11 @@ namespace Orchard.Layouts.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(LayoutPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportChildEl(part.PartDefinition.Name, "LayoutData", s => {
|
||||
part.LayoutData = s;
|
||||
_layoutManager.Importing(new ImportLayoutContext {
|
||||
|
@@ -110,16 +110,19 @@ namespace Orchard.Localization.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(LocalizationPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var masterContentItem = context.Attribute(part.PartDefinition.Name, "MasterContentItem");
|
||||
if (masterContentItem != null) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "MasterContentItem", masterContentItem => {
|
||||
var contentItem = context.GetItemFromSession(masterContentItem);
|
||||
if (contentItem != null) {
|
||||
part.MasterContentItem = contentItem;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var culture = context.Attribute(part.PartDefinition.Name, "Culture");
|
||||
if (culture != null) {
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Culture", culture => {
|
||||
var targetCulture = _cultureManager.GetCultureByName(culture);
|
||||
// Add Culture.
|
||||
if (targetCulture == null && _cultureManager.IsValidCulture(culture)) {
|
||||
@@ -127,7 +130,7 @@ namespace Orchard.Localization.Drivers {
|
||||
targetCulture = _cultureManager.GetCultureByName(culture);
|
||||
}
|
||||
part.Culture = targetCulture;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Exporting(LocalizationPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
|
@@ -17,10 +17,14 @@ namespace Orchard.MediaLibrary.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(AudioPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var length = context.Attribute(part.PartDefinition.Name, "Length");
|
||||
if (length != null) {
|
||||
part.Length = int.Parse(length);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Length", length =>
|
||||
part.Length = int.Parse(length)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,10 +17,14 @@ namespace Orchard.MediaLibrary.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(DocumentPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var length = context.Attribute(part.PartDefinition.Name, "Length");
|
||||
if (length != null) {
|
||||
part.Length = int.Parse(length);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Length", length =>
|
||||
part.Length = int.Parse(length)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,15 +20,18 @@ namespace Orchard.MediaLibrary.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ImagePart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var height = context.Attribute(part.PartDefinition.Name, "Height");
|
||||
if (height != null) {
|
||||
part.Height = int.Parse(height);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var width = context.Attribute(part.PartDefinition.Name, "Width");
|
||||
if (width != null) {
|
||||
part.Width = int.Parse(width);
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Height", height =>
|
||||
part.Height = int.Parse(height)
|
||||
);
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Width", width =>
|
||||
part.Width = int.Parse(width)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -36,30 +36,30 @@ namespace Orchard.MediaLibrary.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(MediaPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var mimeType = context.Attribute(part.PartDefinition.Name, "MimeType");
|
||||
if (mimeType != null) {
|
||||
part.MimeType = mimeType;
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var caption = context.Attribute(part.PartDefinition.Name, "Caption");
|
||||
if (caption != null) {
|
||||
part.Caption = caption;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "MimeType", mimeType =>
|
||||
part.MimeType = mimeType
|
||||
);
|
||||
|
||||
var alternateText = context.Attribute(part.PartDefinition.Name, "AlternateText");
|
||||
if (alternateText != null) {
|
||||
part.AlternateText = alternateText;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Caption", caption =>
|
||||
part.Caption = caption
|
||||
);
|
||||
|
||||
var folderPath = context.Attribute(part.PartDefinition.Name, "FolderPath");
|
||||
if (folderPath != null) {
|
||||
part.FolderPath = folderPath;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "AlternateText", alternateText =>
|
||||
part.AlternateText = alternateText
|
||||
);
|
||||
|
||||
var fileName = context.Attribute(part.PartDefinition.Name, "FileName");
|
||||
if (fileName != null) {
|
||||
part.FileName = fileName;
|
||||
}
|
||||
context.ImportAttribute(part.PartDefinition.Name, "FolderPath", folderPath =>
|
||||
part.FolderPath = folderPath
|
||||
);
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "FileName", fileName =>
|
||||
part.FileName = fileName
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(MediaPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
|
@@ -17,10 +17,14 @@ namespace Orchard.MediaLibrary.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(OEmbedPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var source = context.Attribute(part.PartDefinition.Name, "Source");
|
||||
if (source != null) {
|
||||
part.Source = source;
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Source", source =>
|
||||
part.Source = source
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,10 +17,14 @@ namespace Orchard.MediaLibrary.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(VideoPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var length = context.Attribute(part.PartDefinition.Name, "Length");
|
||||
if (length != null) {
|
||||
part.Length = int.Parse(length);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Length", length =>
|
||||
part.Length = int.Parse(length)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -85,6 +85,11 @@ namespace Orchard.MediaProcessing.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ImageProfilePart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var element = context.Data.Element(part.PartDefinition.Name);
|
||||
|
||||
part.Name = element.Attribute("Name").Value;
|
||||
|
@@ -54,8 +54,13 @@ namespace Orchard.Projections.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(NavigationQueryPart part, ImportContentContext context) {
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "Items"), x => part.Record.Items = Int32.Parse(x));
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "Offset"), x => part.Record.Skip = Int32.Parse(x));
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Items", x => part.Record.Items = Int32.Parse(x));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Offset", x => part.Record.Skip = Int32.Parse(x));
|
||||
}
|
||||
|
||||
protected override void Imported(NavigationQueryPart part, ImportContentContext context) {
|
||||
@@ -65,13 +70,7 @@ namespace Orchard.Projections.Drivers {
|
||||
part.Record.QueryPartRecord = context.GetItemFromSession(query).As<QueryPart>().Record;
|
||||
}
|
||||
}
|
||||
|
||||
private static void IfNotNull<T>(T value, Action<T> then) where T : class {
|
||||
if(value != null) {
|
||||
then(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void Exporting(NavigationQueryPart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Items", part.Record.Items);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Offset", part.Record.Skip);
|
||||
|
@@ -294,12 +294,17 @@ namespace Orchard.Projections.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ProjectionPart part, ImportContentContext context) {
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "Items"), x => part.Record.Items = Int32.Parse(x));
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "ItemsPerPage"), x => part.Record.ItemsPerPage = Int32.Parse(x));
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "Offset"), x => part.Record.Skip = Int32.Parse(x));
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "PagerSuffix"), x => part.Record.PagerSuffix = x);
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "MaxItems"), x => part.Record.MaxItems = Int32.Parse(x));
|
||||
IfNotNull(context.Attribute(part.PartDefinition.Name, "DisplayPager"), x => part.Record.DisplayPager = Boolean.Parse(x));
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Items", x => part.Record.Items = Int32.Parse(x));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "ItemsPerPage", x => part.Record.ItemsPerPage = Int32.Parse(x));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Offset", x => part.Record.Skip = Int32.Parse(x));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "PagerSuffix", x => part.Record.PagerSuffix = x);
|
||||
context.ImportAttribute(part.PartDefinition.Name, "MaxItems", x => part.Record.MaxItems = Int32.Parse(x));
|
||||
context.ImportAttribute(part.PartDefinition.Name, "DisplayPager", x => part.Record.DisplayPager = Boolean.Parse(x));
|
||||
}
|
||||
|
||||
protected override void Imported(ProjectionPart part, ImportContentContext context) {
|
||||
@@ -318,13 +323,7 @@ namespace Orchard.Projections.Drivers {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void IfNotNull<T>(T value, Action<T> then) {
|
||||
if(value != null) {
|
||||
then(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void Exporting(ProjectionPart part, ExportContentContext context) {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Items", part.Record.Items);
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("ItemsPerPage", part.Record.ItemsPerPage);
|
||||
|
@@ -103,6 +103,11 @@ namespace Orchard.Projections.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(QueryPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var queryElement = context.Data.Element(part.PartDefinition.Name);
|
||||
|
||||
part.Record.FilterGroups.Clear();
|
||||
|
@@ -110,10 +110,14 @@ namespace Orchard.PublishLater.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(PublishLaterPart part, ImportContentContext context) {
|
||||
var scheduledUtc = context.Attribute(part.PartDefinition.Name, "ScheduledPublishUtc");
|
||||
if (scheduledUtc != null) {
|
||||
part.ScheduledPublishUtc.Value = XmlConvert.ToDateTime(scheduledUtc, XmlDateTimeSerializationMode.Utc);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "ScheduledPublishUtc", scheduledUtc =>
|
||||
part.ScheduledPublishUtc.Value = XmlConvert.ToDateTime(scheduledUtc, XmlDateTimeSerializationMode.Utc)
|
||||
);
|
||||
}
|
||||
|
||||
protected override void Exporting(PublishLaterPart part, ExportContentContext context) {
|
||||
|
@@ -98,29 +98,32 @@ namespace Orchard.Roles.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(UserRolesPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
var roles = context.Attribute(part.PartDefinition.Name, "Roles");
|
||||
if(string.IsNullOrEmpty(roles)) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var userRoles = roles.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Roles", roles => {
|
||||
|
||||
// create new roles
|
||||
foreach (var role in userRoles) {
|
||||
var roleRecord = _roleService.GetRoleByName(role);
|
||||
var userRoles = roles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// create the role if it doesn't already exist
|
||||
if (roleRecord == null) {
|
||||
_roleService.CreateRole(role);
|
||||
// create new roles
|
||||
foreach (var role in userRoles) {
|
||||
var roleRecord = _roleService.GetRoleByName(role);
|
||||
|
||||
// create the role if it doesn't already exist
|
||||
if (roleRecord == null) {
|
||||
_roleService.CreateRole(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var currentUserRoleRecords = _userRolesRepository.Fetch(x => x.UserId == part.ContentItem.Id).ToList();
|
||||
var currentRoleRecords = currentUserRoleRecords.Select(x => x.Role).ToList();
|
||||
var targetRoleRecords = userRoles.Select(x => _roleService.GetRoleByName(x)).ToList();
|
||||
foreach (var addingRole in targetRoleRecords.Where(x => !currentRoleRecords.Contains(x))) {
|
||||
_userRolesRepository.Create(new UserRolesPartRecord { UserId = part.ContentItem.Id, Role = addingRole });
|
||||
}
|
||||
var currentUserRoleRecords = _userRolesRepository.Fetch(x => x.UserId == part.ContentItem.Id).ToList();
|
||||
var currentRoleRecords = currentUserRoleRecords.Select(x => x.Role).ToList();
|
||||
var targetRoleRecords = userRoles.Select(x => _roleService.GetRoleByName(x)).ToList();
|
||||
foreach (var addingRole in targetRoleRecords.Where(x => !currentRoleRecords.Contains(x))) {
|
||||
_userRolesRepository.Create(new UserRolesPartRecord { UserId = part.ContentItem.Id, Role = addingRole });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Exporting(UserRolesPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
|
@@ -68,15 +68,14 @@ namespace Orchard.Search.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(AdminSearchSettingsPart part, ImportContentContext context) {
|
||||
var xElement = context.Data.Element(part.PartDefinition.Name);
|
||||
if (xElement == null) return;
|
||||
|
||||
var searchFields = xElement.Attribute("SearchFields");
|
||||
if (searchFields != null) {
|
||||
searchFields.Remove();
|
||||
|
||||
part.Store("SearchFields", searchFields.Value);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "SearchFields", value => {
|
||||
part.Store("SearchFields", value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -69,15 +69,14 @@ namespace Orchard.Search.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(SearchSettingsPart part, ImportContentContext context) {
|
||||
var xElement = context.Data.Element(part.PartDefinition.Name);
|
||||
if (xElement == null) return;
|
||||
|
||||
var searchFields = xElement.Attribute("SearchFields");
|
||||
if (searchFields != null) {
|
||||
searchFields.Remove();
|
||||
|
||||
part.Store("SearchFields", searchFields.Value);
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "SearchFields", value => {
|
||||
part.Store("SearchFields", value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -36,7 +36,6 @@ namespace Orchard.SecureSocketsLayer.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(SslSettingsPart part, ImportContentContext context) {
|
||||
base.Importing(part, context);
|
||||
_signals.Trigger(SslSettingsPart.CacheKey);
|
||||
}
|
||||
}
|
||||
|
@@ -43,6 +43,11 @@ namespace Orchard.Tags.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(TagCloudPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
part.Slug = context.Attribute(part.PartDefinition.Name, "Slug");
|
||||
part.Buckets = Convert.ToInt32(context.Attribute(part.PartDefinition.Name, "Buckets"));
|
||||
}
|
||||
|
@@ -72,6 +72,11 @@ namespace Orchard.Tags.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(TagsPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tagString = context.Attribute(part.PartDefinition.Name, "Tags");
|
||||
if (tagString != null) {
|
||||
var tags = tagString.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
@@ -101,6 +101,11 @@ namespace Orchard.Taxonomies.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(TaxonomyNavigationPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
part.DisplayContentCount = Boolean.Parse(context.Attribute(part.PartDefinition.Name, "DisplayContentCount"));
|
||||
part.DisplayRootTerm = Boolean.Parse(context.Attribute(part.PartDefinition.Name, "DisplayRootTerm"));
|
||||
part.HideEmptyTerms = Boolean.Parse(context.Attribute(part.PartDefinition.Name, "HideEmptyTerms"));
|
||||
|
@@ -65,6 +65,11 @@ namespace Orchard.Taxonomies.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(TaxonomyPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
part.TermTypeName = context.Attribute(part.PartDefinition.Name, "TermTypeName");
|
||||
}
|
||||
}
|
||||
|
@@ -126,6 +126,11 @@ namespace Orchard.Taxonomies.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(TermPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
part.Count = Int32.Parse(context.Attribute(part.PartDefinition.Name, "Count"));
|
||||
part.Selectable = Boolean.Parse(context.Attribute(part.PartDefinition.Name, "Selectable"));
|
||||
part.Weight = Int32.Parse(context.Attribute(part.PartDefinition.Name, "Weight"));
|
||||
|
@@ -58,6 +58,11 @@ namespace Orchard.Templates.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(ShapePart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var shapeElement = context.Data.Element(part.PartDefinition.Name);
|
||||
|
||||
if (shapeElement != null)
|
||||
|
@@ -11,6 +11,11 @@ namespace Orchard.Users.Drivers {
|
||||
public class UserPartDriver : ContentPartDriver<UserPart> {
|
||||
|
||||
protected override void Importing(UserPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
part.Email = context.Attribute(part.PartDefinition.Name, "Email");
|
||||
part.EmailChallengeToken = context.Attribute(part.PartDefinition.Name, "EmailChallengeToken");
|
||||
part.EmailStatus = (UserStatus)Enum.Parse(typeof(UserStatus), context.Attribute(part.PartDefinition.Name, "EmailStatus"));
|
||||
|
@@ -66,6 +66,11 @@ namespace Orchard.Widgets.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(LayerPart part, ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var name = context.Attribute(part.PartDefinition.Name, "Name");
|
||||
if (name != null) {
|
||||
part.Name = name;
|
||||
|
@@ -67,6 +67,11 @@ namespace Orchard.Widgets.Drivers {
|
||||
}
|
||||
|
||||
protected override void Importing(WidgetPart part, ContentManagement.Handlers.ImportContentContext context) {
|
||||
// Don't do anything if the tag is not specified.
|
||||
if (context.Data.Element(part.PartDefinition.Name) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var title = context.Attribute(part.PartDefinition.Name, "Title");
|
||||
if (title != null) {
|
||||
part.Title = title;
|
||||
|
Reference in New Issue
Block a user