protected virtual void WriteRole(XmlTextWriter writer, AuthorizedRole ar) { using (ElementWriter role = new ElementWriter("role", writer)) { role.Write(ar.Role); } }
protected virtual void WriteChild(XmlTextWriter writer, ContentItem child) { using (ElementWriter childElement = new ElementWriter("child", writer)) { childElement.WriteAttribute("id", child.ID); } }
public void Write(ContentItem item, System.Xml.XmlTextWriter writer) { using (ElementWriter propertiesElement = new ElementWriter("properties", writer)) { foreach (var persistable in definitions.GetDefinition(item).NamedOperators.OfType<PersistableAttribute>()) { string name = ((IUniquelyNamed)persistable).Name; object value = item[name]; if(value == null) continue; using (ElementWriter detailElement = new ElementWriter("property", writer)) { detailElement.WriteAttribute("name", name); Type type = value.GetType(); if (type == typeof(string)) Write(detailElement, type, (string)value, true); else if (type == typeof(short) || type == typeof(int) || type == typeof(long) || type == typeof(double) || type == typeof(decimal)) Write(detailElement, type, value.ToString(), false); else if (type == typeof(DateTime)) Write(detailElement, type, SerializationUtility.ToUniversalString(((DateTime)value)), false); else if (type.IsEnum) Write(detailElement, type, ((int)value).ToString(), false); else if (typeof(ContentItem).IsAssignableFrom(type)) Write(detailElement, typeof(ContentItem), (((ContentItem)value).ID).ToString(), false); else Write(detailElement, typeof(object), SerializationUtility.ToBase64String(value), false); } } } }
private void WriteProperty(System.Xml.XmlTextWriter writer, string name, object value) { using (ElementWriter propertyElement = new ElementWriter("property", writer)) { propertyElement.WriteAttribute("name", name); if (value == null) return; Type type = value.GetType(); if (type == typeof(string)) Write(propertyElement, type, (string)value, true); else if (type == typeof(short) || type == typeof(int) || type == typeof(long) || type == typeof(double) || type == typeof(decimal) || type == typeof(bool)) Write(propertyElement, type, value.ToString(), false); else if (type == typeof(DateTime)) Write(propertyElement, type, SerializationUtility.ToUniversalString(((DateTime)value)), false); else if (type.IsEnum) Write(propertyElement, type, ((int)value).ToString(), false); else if (typeof(ContentItem).IsAssignableFrom(type)) WriteItem(propertyElement, (ContentItem)value); else if (type.IsContentItemEnumeration()) WriteItems(propertyElement, (IEnumerable)value); else Write(propertyElement, typeof(object), SerializationUtility.ToBase64String(value), false); } }
public virtual void WriteDetail(ContentItem item, ContentDetail detail, XmlTextWriter writer) { using (ElementWriter detailElement = new ElementWriter("detail", writer)) { detailElement.WriteAttribute("name", detail.Name); detailElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(detail.ValueType)); detailElement.WriteAttribute("meta", detail.Meta); var prop = item.GetType().GetProperty(detail.Name); if (prop != null) { if (Attribute.IsDefined(prop, typeof(N2.Details.XMLTranslateAttribute))) { string translate = "Value"; //if (options.HasFlag(ExportOptions.TranslateDetailName)) // translate += ",Name"; //if (options.HasFlag(ExportOptions.TranslateDetailTitle)) // translate += ",Title"; detailElement.WriteAttribute("xmlTranslate", translate); } } WriteInnerContents(item, detail, detail.ValueTypeKey, detailElement); } }
private void Write(ElementWriter detailElement, Type type, string contents, bool cdata) { detailElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(type)); if(cdata) detailElement.WriteCData(contents); else detailElement.Write(contents); }
private void WriteInnerContents(ContentItem item, ContentDetail detail, string valueTypeKey, ElementWriter element) { switch (valueTypeKey) { case ContentDetail.TypeKeys.BoolType: element.Write(detail.BoolValue.HasValue ? detail.BoolValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.DateTimeType: element.Write(SerializationUtility.ToUniversalString(detail.DateTimeValue)); return; case ContentDetail.TypeKeys.DoubleType: element.Write(detail.DoubleValue.HasValue ? detail.DoubleValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.IntType: element.Write(detail.IntValue.HasValue ? detail.IntValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.LinkType: element.Write(detail.LinkValue.HasValue ? detail.LinkValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.MultiType: WriteMultiValue(item, detail, ContentDetail.TypeKeys.BoolType, detail.BoolValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.DateTimeType, detail.DateTimeValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.DoubleType, detail.DoubleValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.IntType, detail.IntValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.LinkType, detail.LinkedItem, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.ObjectType, detail.ObjectValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.StringType, SerializationUtility.RemoveInvalidCharacters(detail.StringValue), element.Writer); return; case ContentDetail.TypeKeys.ObjectType: string base64representation = SerializationUtility.ToBase64String(detail.ObjectValue); element.Write(base64representation); return; case ContentDetail.TypeKeys.EnumType: /* TODO: Do we need to write out the 'meta' value here? */ case ContentDetail.TypeKeys.StringType: string value = detail.StringValue; if (!string.IsNullOrEmpty(value)) { value = ExecuteRelativityTransformers(item, detail.Name, value); element.WriteAttribute("encoded", true); value = HttpUtility.HtmlEncode(SerializationUtility.RemoveInvalidCharacters(value)); element.WriteCData(value); } return; default: throw new InvalidOperationException("Invalid detail type: " + valueTypeKey); } }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { if (itemElement == null) { throw new ArgumentNullException("itemElement"); } if (item == null) { throw new ArgumentNullException("item"); } itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name); if (item.Parent != null) { if (item.Parent.ID != 0) { itemElement.WriteAttribute("parent", item.Parent.ID.ToString()); } else { itemElement.WriteAttribute("parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) { itemElement.WriteAttribute("parentVersionKey", item.Parent.GetVersionKey()); } } } itemElement.WriteAttribute("title", item.Title); itemElement.WriteAttribute("zoneName", item.ZoneName); itemElement.WriteAttribute("templateKey", item.TemplateKey); if (item.TranslationKey.HasValue) { itemElement.WriteAttribute("translationKey", item.TranslationKey.Value); } itemElement.WriteAttribute("state", (int)item.State); itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); itemElement.WriteAttribute("sortOrder", item.SortOrder); itemElement.WriteAttribute("url", parser == null ? item.Url : (string)parser.BuildUrl(item)); itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item).Discriminator); itemElement.WriteAttribute("versionIndex", item.VersionIndex); itemElement.WriteAttribute("ancestralTrail", item.AncestralTrail); itemElement.WriteAttribute("alteredPermissions", (int)item.AlteredPermissions); itemElement.WriteAttribute("childState", (int)item.ChildState); if (item.VersionOf.HasValue) { Debug.Assert(item.VersionOf.ID != null, "item.VersionOf.ID != null"); itemElement.WriteAttribute("versionOf", item.VersionOf.ID.Value); } }
public virtual void WriteDetail(ContentItem item, ContentDetail detail, XmlTextWriter writer) { using (ElementWriter detailElement = new ElementWriter("detail", writer)) { detailElement.WriteAttribute("name", detail.Name); detailElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(detail.ValueType)); WriteInnerContents(item, detail, detail.ValueTypeKey, detailElement); } }
protected virtual void WriteDetailCollection(ContentItem item, XmlTextWriter writer, DetailCollection collection) { using (ElementWriter collectionElement = new ElementWriter("collection", writer)) { collectionElement.WriteAttribute("name", collection.Name); foreach (ContentDetail detail in collection.Details) { WriteDetail(item, detail, writer); } } }
public virtual void WriteSingleItem(ContentItem item, ExportOptions options, XmlTextWriter writer) { using (ElementWriter itemElement = new ElementWriter("item", writer)) { WriteDefaultAttributes(itemElement, item); foreach (IXmlWriter xmlWriter in GetWriters(options)) { xmlWriter.Write(item, writer); } } }
private void WriteItems(ElementWriter propertyElement, IEnumerable enumerable) { propertyElement.WriteAttribute("typeName", "System.Collections.Generic.IEnumerable`1[[N2.ContentItem, N2]]"); foreach (ContentItem item in enumerable) { using (ElementWriter itemElement = new ElementWriter("item", propertyElement.Writer)) { itemElement.WriteAttribute("versionKey", item.GetVersionKey()); itemElement.Write(item.ID.ToString()); } } }
public virtual void WriteSingleItem(ContentItem item, ExportOptions options, XmlTextWriter writer) { using (ElementWriter itemElement = new ElementWriter("item", writer)) { WriteDefaultAttributes(itemElement, item); foreach(IXmlWriter xmlWriter in GetWriters(options)) { xmlWriter.Write(item, writer); } } }
private void Write(ElementWriter propertyElement, Type type, string contents, bool cdata) { propertyElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(type)); if (cdata) { propertyElement.WriteCData(contents); } else { propertyElement.Write(contents); } }
public virtual void WriteDetail(ContentItem item, ContentDetail detail, XmlTextWriter writer) { using (ElementWriter detailElement = new ElementWriter("detail", writer)) { detailElement.WriteAttribute("name", detail.Name); detailElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(detail.ValueType)); if (detail.ValueType == typeof(object)) { string base64representation = SerializationUtility.ToBase64String(detail.Value); detailElement.Write(base64representation); } else if (detail.ValueType == typeof(ContentItem)) { detailElement.Write(detail.LinkValue.HasValue ? detail.LinkValue.Value.ToString() : "0"); } else if (detail.ValueType == typeof(string)) { string value = detail.StringValue; if (!string.IsNullOrEmpty(value)) { if (value.StartsWith(applicationPath, StringComparison.InvariantCultureIgnoreCase)) { var pi = item.GetContentType().GetProperty(detail.Name); if (pi != null) { var transformers = pi.GetCustomAttributes(typeof(IRelativityTransformer), false); foreach (IRelativityTransformer transformer in transformers) { if (transformer.RelativeWhen == RelativityMode.Always || transformer.RelativeWhen == RelativityMode.ImportingOrExporting) { value = transformer.Rebase(value, applicationPath, "~/"); } } } } detailElement.WriteCData(value); } } else if (detail.ValueType == typeof(DateTime)) { detailElement.Write(ElementWriter.ToUniversalString(detail.DateTimeValue)); } else { detailElement.Write(detail.Value.ToString()); } } }
private void WriteMultiValue(ContentItem item, ContentDetail detail, string valueTypeKey, object value, XmlTextWriter writer) { if (value == null) { return; } using (ElementWriter multiElement = new ElementWriter("value", writer)) { multiElement.WriteAttribute("key", valueTypeKey); WriteInnerContents(item, detail, valueTypeKey, multiElement); } }
protected virtual void WriteChild(XmlTextWriter writer, ContentItem child) { using (ElementWriter childElement = new ElementWriter("child", writer)) { childElement.WriteAttribute("id", child.ID); childElement.WriteAttribute("name", child.Name); childElement.WriteAttribute("versionIndex", child.VersionIndex); if (child.VersionOf.HasValue) childElement.WriteAttribute("versionOf", child.VersionOf.Value.ID); if (child.GetVersionKey() != null) childElement.WriteAttribute("versionKey", child.GetVersionKey()); } }
public virtual void WriteDetail(ContentItem item, ContentDetail detail, XmlTextWriter writer) { using (ElementWriter detailElement = new ElementWriter("detail", writer)) { detailElement.WriteAttribute("name", detail.Name); detailElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(detail.ValueType)); if (detail.ValueType == typeof(object)) { string base64representation = SerializationUtility.ToBase64String(detail.Value); detailElement.Write(base64representation); } else if (detail.ValueType == typeof(ContentItem)) { detailElement.Write(detail.LinkValue.HasValue ? detail.LinkValue.Value.ToString() : "0"); } else if (detail.ValueType == typeof(string)) { string value = detail.StringValue; if (!string.IsNullOrEmpty(value)) { if (value.StartsWith(applicationPath, StringComparison.InvariantCultureIgnoreCase)) { var pi = item.GetContentType().GetProperty(detail.Name); if (pi != null) { var transformers = pi.GetCustomAttributes(typeof(IRelativityTransformer), false); foreach (IRelativityTransformer transformer in transformers) { if (transformer.RelativeWhen == RelativityMode.Always || transformer.RelativeWhen == RelativityMode.ImportingOrExporting) value = transformer.Rebase(value, applicationPath, "~/"); } } } detailElement.WriteCData(value); } } else if(detail.ValueType == typeof(DateTime)) { detailElement.Write(ElementWriter.ToUniversalString(detail.DateTimeValue)); } else { detailElement.Write(detail.Value.ToString()); } } }
public void Write(ContentItem item, System.Xml.XmlTextWriter writer) { using (ElementWriter propertiesElement = new ElementWriter("properties", writer)) { foreach (var persistable in definitions.GetDefinition(item).NamedOperators.OfType <PersistableAttribute>()) { string name = ((IUniquelyNamed)persistable).Name; object value = item[name]; if (value == null) { continue; } using (ElementWriter detailElement = new ElementWriter("property", writer)) { detailElement.WriteAttribute("name", name); Type type = value.GetType(); if (type == typeof(string)) { Write(detailElement, type, (string)value, true); } else if (type == typeof(short) || type == typeof(int) || type == typeof(long) || type == typeof(double) || type == typeof(decimal)) { Write(detailElement, type, value.ToString(), false); } else if (type == typeof(DateTime)) { Write(detailElement, type, SerializationUtility.ToUniversalString(((DateTime)value)), false); } else if (type.IsEnum) { Write(detailElement, type, ((int)value).ToString(), false); } else if (typeof(ContentItem).IsAssignableFrom(type)) { Write(detailElement, typeof(ContentItem), (((ContentItem)value).ID).ToString(), false); } else { Write(detailElement, typeof(object), SerializationUtility.ToBase64String(value), false); } } } } }
public virtual void Export(ContentItem item, ExportOptions options, TextWriter output) { var xmlOutput = new XmlTextWriter(output) {Formatting = XmlFormatting}; xmlOutput.WriteStartDocument(); using (var envelope = new ElementWriter("n2", xmlOutput)) { envelope.WriteAttribute("version", GetType().Assembly.GetName().Version.ToString()); envelope.WriteAttribute("exportVersion", 2); envelope.WriteAttribute("exportDate", Utility.CurrentTime()); itemWriter.Write(item, options, xmlOutput); } xmlOutput.WriteEndDocument(); xmlOutput.Flush(); }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name); itemElement.WriteAttribute("parent", item.Parent != null ? item.Parent.ID.ToString() : string.Empty); itemElement.WriteAttribute("title", item.Title); itemElement.WriteAttribute("zoneName", item.ZoneName); itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); itemElement.WriteAttribute("sortOrder", item.SortOrder); itemElement.WriteAttribute("url", parser.BuildUrl(item)); itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item.GetContentType()).Discriminator); }
public void Write(ContentItem item, XmlTextWriter writer) { IList<IAttachmentHandler> attachments = explorer.Find<IAttachmentHandler>(item.GetContentType()); if(attachments.Count > 0) { using(new ElementWriter("attachments", writer)) { foreach(IAttachmentHandler attachment in attachments) { using (ElementWriter attachmentElement = new ElementWriter("attachment", writer)) { attachmentElement.WriteAttribute("name", attachment.Name); attachment.Write(fs, item, writer); } } } } }
public void Write(ContentItem item, XmlTextWriter writer) { IList<IAttachmentHandler> attachments = explorer.Find<IAttachmentHandler>(item.GetContentType()); if(attachments.Count > 0) { using(new ElementWriter("attachments", writer)) { foreach(IAttachmentHandler attachment in attachments) { using (ElementWriter attachmentElement = new ElementWriter("attachment", writer)) { attachmentElement.WriteAttribute("name", attachment.Name); attachment.Write(item, writer); } } } } }
protected virtual void WriteChild(XmlTextWriter writer, ContentItem child) { using (ElementWriter childElement = new ElementWriter("child", writer)) { childElement.WriteAttribute("id", child.ID); childElement.WriteAttribute("name", child.Name); childElement.WriteAttribute("versionIndex", child.VersionIndex); if (child.VersionOf.HasValue) { childElement.WriteAttribute("versionOf", child.VersionOf.Value.ID); } if (child.GetVersionKey() != null) { childElement.WriteAttribute("versionKey", child.GetVersionKey()); } } }
public virtual void Export(ContentItem item, ExportOptions options, TextWriter output) { XmlTextWriter xmlOutput = new XmlTextWriter(output); xmlOutput.Formatting = XmlFormatting; xmlOutput.WriteStartDocument(); using (ElementWriter envelope = new ElementWriter("n2", xmlOutput)) { envelope.WriteAttribute("version", GetType().Assembly.GetName().Version.ToString()); envelope.WriteAttribute("exportVersion", 2); envelope.WriteAttribute("exportDate", N2.Utility.CurrentTime()); itemWriter.Write(item, options, xmlOutput); } xmlOutput.WriteEndDocument(); xmlOutput.Flush(); }
public void Write(ContentItem item, XmlTextWriter writer) { string url = item[Name] as string; if(!string.IsNullOrEmpty(url)) { string path = MapPath(url); if(File.Exists(path)) { using(ElementWriter ew = new ElementWriter("file", writer)) { ew.WriteAttribute("url", url); byte[] fileContents = File.ReadAllBytes(path); string base64representation = Convert.ToBase64String(fileContents); ew.Write(base64representation); } } } }
public void Write(IFileSystem fs, ContentItem item, XmlTextWriter writer) { string url = item[Name] as string; if(!string.IsNullOrEmpty(url)) { string path = url; if(fs.FileExists(path)) { using(ElementWriter ew = new ElementWriter("file", writer)) { ew.WriteAttribute("url", url); byte[] fileContents = ReadFully(fs.OpenFile(path)); string base64representation = Convert.ToBase64String(fileContents); ew.Write(base64representation); } } } }
private void WriteProperty(System.Xml.XmlTextWriter writer, string name, object value) { using (ElementWriter propertyElement = new ElementWriter("property", writer)) { propertyElement.WriteAttribute("name", name); if (value == null) { return; } Type type = value.GetType(); if (type == typeof(string)) { Write(propertyElement, type, (string)value, true); } else if (type == typeof(short) || type == typeof(int) || type == typeof(long) || type == typeof(double) || type == typeof(decimal)) { Write(propertyElement, type, value.ToString(), false); } else if (type == typeof(DateTime)) { Write(propertyElement, type, SerializationUtility.ToUniversalString(((DateTime)value)), false); } else if (type.IsEnum) { Write(propertyElement, type, ((int)value).ToString(), false); } else if (typeof(ContentItem).IsAssignableFrom(type)) { WriteItem(propertyElement, (ContentItem)value); } else if (type.IsContentItemEnumeration()) { WriteItems(propertyElement, (IEnumerable)value); } else { Write(propertyElement, typeof(object), SerializationUtility.ToBase64String(value), false); } } }
public void Write(ContentItem item, XmlTextWriter writer) { string url = item[Name] as string; if (!string.IsNullOrEmpty(url)) { string path = MapPath(url); if (File.Exists(path)) { using (ElementWriter ew = new ElementWriter("file", writer)) { ew.WriteAttribute("url", url); byte[] fileContents = File.ReadAllBytes(path); string base64representation = Convert.ToBase64String(fileContents); ew.Write(base64representation); } } } }
public void Write(ContentItem item, System.Xml.XmlTextWriter writer) { using (ElementWriter propertiesElement = new ElementWriter("properties", writer)) { foreach (var persistable in definitions.GetDefinition(item).NamedOperators.OfType<PersistableAttribute>()) { string name = ((IUniquelyNamed)persistable).Name; object value = item[name]; if(value == null) continue; WriteProperty(writer, name, value); } //foreach (var property in item.GetContentType().GetProperties().Where(pi => pi.IsInterceptable())) //{ // WriteProperty(writer, property.Name, item[property.Name]); //} } }
public void Write(ContentItem item, System.Xml.XmlTextWriter writer) { using (ElementWriter propertiesElement = new ElementWriter("properties", writer)) { foreach (var persistable in definitions.GetDefinition(item).NamedOperators.OfType <PersistableAttribute>()) { string name = ((IUniquelyNamed)persistable).Name; object value = item[name]; if (value == null) { continue; } WriteProperty(writer, name, value); } //foreach (var property in item.GetContentType().GetProperties().Where(pi => pi.IsInterceptable())) //{ // WriteProperty(writer, property.Name, item[property.Name]); //} } }
public virtual void Write(TextWriter output, IFeed feed) { XmlTextWriter xtw = new XmlTextWriter(output); xtw.Formatting = Formatting.Indented; xtw.WriteStartDocument(); using (ElementWriter rssElement = new ElementWriter("rss", xtw)) { rssElement.WriteAttribute("version", "2.0"); rssElement.WriteAttribute("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema"); using (new ElementWriter("channel", xtw)) { IEnumerable<ISyndicatable> items = feed.GetItems(); WriteChannelInfo(xtw, feed); foreach (ISyndicatable item in items) { WriteItem(item, xtw); } } } xtw.WriteEndDocument(); }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name); if (item.Parent != null) { if (item.Parent.ID != 0) itemElement.WriteAttribute("parent", item.Parent.ID.ToString()); else { itemElement.WriteAttribute("parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) itemElement.WriteAttribute("parentVersionKey", item.Parent.GetVersionKey()); } } itemElement.WriteAttribute("title", item.Title); itemElement.WriteAttribute("zoneName", item.ZoneName); itemElement.WriteAttribute("templateKey", item.TemplateKey); if (item.TranslationKey.HasValue) itemElement.WriteAttribute("translationKey", item.TranslationKey.Value); itemElement.WriteAttribute("state", (int)item.State); itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); itemElement.WriteAttribute("sortOrder", item.SortOrder); itemElement.WriteAttribute("url", parser.BuildUrl(item)); itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item).Discriminator); itemElement.WriteAttribute("versionIndex", item.VersionIndex); itemElement.WriteAttribute("ancestralTrail", item.AncestralTrail); itemElement.WriteAttribute("alteredPermissions", (int)item.AlteredPermissions); itemElement.WriteAttribute("childState", (int)item.ChildState); if(item.VersionOf.HasValue) itemElement.WriteAttribute("versionOf", item.VersionOf.ID.Value); }
public void Write(IFileSystem fs, ContentItem item, XmlTextWriter writer) { string url = item[Name] as string; if (!string.IsNullOrEmpty(url)) { string path = url; if (fs.FileExists(path)) { using (ElementWriter ew = new ElementWriter("file", writer)) { ew.WriteAttribute("url", url); using (var s = fs.OpenFile(path)) { byte[] fileContents = ReadFully(s); string base64representation = Convert.ToBase64String(fileContents); ew.Write(base64representation); } } } } }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { if (itemElement == null) throw new ArgumentNullException("itemElement"); if (item == null) throw new ArgumentNullException("item"); itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString(CultureInfo.InvariantCulture) == item.Name ? "" : item.Name); if (item.Parent != null) { if (item.Parent.ID != 0) itemElement.WriteAttribute("parent", item.Parent.ID.ToString(CultureInfo.InvariantCulture)); else { itemElement.WriteAttribute("parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) itemElement.WriteAttribute("parentVersionKey", item.Parent.GetVersionKey()); } } string typeAndAssemblyName = null; try { typeAndAssemblyName = SerializationUtility.GetTypeAndAssemblyName(item.GetContentType()); } catch (Exception ex) { throw new Exception("Couldn't get type/assembly name.", ex); } itemElement.WriteAttribute("title", item.Title); itemElement.WriteAttribute("zoneName", item.ZoneName); itemElement.WriteAttribute("templateKey", item.TemplateKey); if (item.TranslationKey.HasValue) itemElement.WriteAttribute("translationKey", item.TranslationKey.Value); itemElement.WriteAttribute("state", (int)item.State); itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); itemElement.WriteAttribute("sortOrder", item.SortOrder); itemElement.WriteAttribute("url", item.Url); itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", typeAndAssemblyName); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item).Discriminator); itemElement.WriteAttribute("versionIndex", item.VersionIndex); itemElement.WriteAttribute("ancestralTrail", item.AncestralTrail); itemElement.WriteAttribute("alteredPermissions", (int)item.AlteredPermissions); itemElement.WriteAttribute("childState", (int)item.ChildState); if(item.VersionOf.HasValue) { Debug.Assert(item.VersionOf.ID != null, "item.VersionOf.ID != null"); itemElement.WriteAttribute("versionOf", item.VersionOf.ID.Value); } }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { if (itemElement == null) throw new ArgumentNullException("itemElement"); if (item == null) throw new ArgumentNullException("item"); itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name, true); if (item.Parent != null) { if (item.Parent.ID != 0) itemElement.WriteAttribute("parent", item.Parent.ID.ToString()); else { itemElement.WriteAttribute("parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) itemElement.WriteAttribute("parentVersionKey", item.Parent.GetVersionKey()); } } itemElement.WriteAttribute("title", item.Title, true); itemElement.WriteAttribute("zoneName", item.ZoneName, true); itemElement.WriteAttribute("templateKey", item.TemplateKey, true); if (item.TranslationKey.HasValue) itemElement.WriteAttribute("translationKey", item.TranslationKey.Value); itemElement.WriteAttribute("state", Enum.GetName(typeof(ContentState), item.State)); // use textual state to avoid future import trouble itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); // TODO expired items could be excluded itemElement.WriteAttribute("sortOrder", item.SortOrder); if (item.IsPage && item.IsPublished()) itemElement.WriteAttribute("url", (parser != null) ? (string) parser.BuildUrl(item) : item.Url); // generated itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item).Discriminator); itemElement.WriteAttribute("ancestralTrail", item.AncestralTrail); // generated if (item.AlteredPermissions != 0) itemElement.WriteAttribute("alteredPermissions", (int)item.AlteredPermissions); itemElement.WriteAttribute("childState", (int)item.ChildState); if (item.VersionOf.HasValue && item.VersionOf.ID != null) { itemElement.WriteAttribute("versionIndex", item.VersionIndex); // write only if versioned itemElement.WriteAttribute("versionOf", item.VersionOf.ID.Value); } }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item, ExportOptions options) { if (itemElement == null) throw new ArgumentNullException("itemElement"); if (item == null) throw new ArgumentNullException("item"); string translate=""; itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name); if (item.Parent != null) { if (item.Parent.ID != 0) itemElement.WriteAttribute("parent", item.Parent.ID.ToString()); else { itemElement.WriteAttribute("parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) itemElement.WriteAttribute("parentVersionKey", item.Parent.GetVersionKey()); } } itemElement.WriteAttribute("title", item.Title); itemElement.WriteAttribute("zoneName", item.ZoneName); itemElement.WriteAttribute("templateKey", item.TemplateKey); if (item.TranslationKey.HasValue) itemElement.WriteAttribute("translationKey", item.TranslationKey.Value); itemElement.WriteAttribute("state", (int)item.State); itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); itemElement.WriteAttribute("sortOrder", item.SortOrder); itemElement.WriteAttribute("url", parser == null ? item.Url : (string)parser.BuildUrl(item)); itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item).Discriminator); itemElement.WriteAttribute("versionIndex", item.VersionIndex); itemElement.WriteAttribute("ancestralTrail", item.AncestralTrail); itemElement.WriteAttribute("alteredPermissions", (int)item.AlteredPermissions); itemElement.WriteAttribute("childState", (int)item.ChildState); if(item.VersionOf.HasValue) { Debug.Assert(item.VersionOf.ID != null, "item.VersionOf.ID != null"); itemElement.WriteAttribute("versionOf", item.VersionOf.ID.Value); } if (item.IsPage) { if (options.HasFlag(ExportOptions.TranslatePageName)) translate += "Name,"; if (options.HasFlag(ExportOptions.TranslatePageTitle)) translate += "Title,"; if (options.HasFlag(ExportOptions.TranslatePageURL)) translate += "URL,"; if (translate != "") { if (translate.EndsWith(",")) translate = translate.Remove(translate.Length-1); itemElement.WriteAttribute("xmlTranslate", translate); } } else { //if (options.HasFlag(ExportOptions.TranslatePartName)) // translate += "Name,"; if (options.HasFlag(ExportOptions.TranslatePartTitle)) translate += "Title,"; if (translate != "") { if (translate.EndsWith(",")) translate = translate.Remove(translate.Length - 1); itemElement.WriteAttribute("xmlTranslate", translate); } } }
protected virtual void WriteDefaultAttributes(ElementWriter itemElement, ContentItem item) { if (itemElement == null) { throw new ArgumentNullException("itemElement"); } if (item == null) { throw new ArgumentNullException("item"); } itemElement.WriteAttribute("id", item.ID); itemElement.WriteAttribute("name", item.ID.ToString() == item.Name ? "" : item.Name, true); if (item.Parent != null) { if (item.Parent.ID != 0) { itemElement.WriteAttribute("parent", item.Parent.ID.ToString()); } else { itemElement.WriteAttribute("parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) { itemElement.WriteAttribute("parentVersionKey", item.Parent.GetVersionKey()); } } } itemElement.WriteAttribute("title", item.Title, true); itemElement.WriteAttribute("zoneName", item.ZoneName, true); itemElement.WriteAttribute("templateKey", item.TemplateKey, true); if (item.TranslationKey.HasValue) { itemElement.WriteAttribute("translationKey", item.TranslationKey.Value); } itemElement.WriteAttribute("state", Enum.GetName(typeof(ContentState), item.State)); // use textual state to avoid future import trouble itemElement.WriteAttribute("created", item.Created); itemElement.WriteAttribute("updated", item.Updated); itemElement.WriteAttribute("published", item.Published); itemElement.WriteAttribute("expires", item.Expires); // TODO expired items could be excluded itemElement.WriteAttribute("sortOrder", item.SortOrder); if (item.IsPage && item.IsPublished()) { itemElement.WriteAttribute("url", (parser != null) ? (string)parser.BuildUrl(item) : item.Url); // generated } itemElement.WriteAttribute("visible", item.Visible); itemElement.WriteAttribute("savedBy", item.SavedBy); itemElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); itemElement.WriteAttribute("discriminator", definitions.GetDefinition(item).Discriminator); itemElement.WriteAttribute("ancestralTrail", item.AncestralTrail); // generated if (item.AlteredPermissions != 0) { itemElement.WriteAttribute("alteredPermissions", (int)item.AlteredPermissions); } itemElement.WriteAttribute("childState", (int)item.ChildState); if (item.VersionOf.HasValue && item.VersionOf.ID != null) { itemElement.WriteAttribute("versionIndex", item.VersionIndex); // write only if versioned itemElement.WriteAttribute("versionOf", item.VersionOf.ID.Value); } }
private void WriteInnerContents(ContentItem item, ContentDetail detail, string valueTypeKey, ElementWriter element) { switch (valueTypeKey) { case ContentDetail.TypeKeys.BoolType: element.Write(detail.BoolValue.HasValue ? detail.BoolValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.DateTimeType: element.Write(SerializationUtility.ToUniversalString(detail.DateTimeValue)); return; case ContentDetail.TypeKeys.DoubleType: element.Write(detail.DoubleValue.HasValue ? detail.DoubleValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.IntType: element.Write(detail.IntValue.HasValue ? detail.IntValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.LinkType: element.Write(detail.LinkValue.HasValue ? detail.LinkValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.MultiType: WriteMultiValue(item, detail, ContentDetail.TypeKeys.BoolType, detail.BoolValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.DateTimeType, detail.DateTimeValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.DoubleType, detail.DoubleValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.IntType, detail.IntValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.LinkType, detail.LinkedItem, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.ObjectType, detail.ObjectValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.StringType, detail.StringValue, element.Writer); return; case ContentDetail.TypeKeys.ObjectType: string base64representation = SerializationUtility.ToBase64String(detail.ObjectValue); element.Write(base64representation); return; case ContentDetail.TypeKeys.StringType: string value = detail.StringValue; if (!string.IsNullOrEmpty(value)) { var pi = item.GetContentType().GetProperty(detail.Name); if (pi != null) { var transformers = pi.GetCustomAttributes(typeof(IRelativityTransformer), false); foreach (IRelativityTransformer transformer in transformers) { if (transformer.RelativeWhen == RelativityMode.Always || transformer.RelativeWhen == RelativityMode.ImportingOrExporting) { value = transformer.Rebase(value, applicationPath, "~/"); } } } element.WriteCData(value); } return; default: throw new InvalidOperationException("Invalid detail type: " + valueTypeKey); } }
private void WriteItem(ElementWriter propertyElement, ContentItem item) { propertyElement.WriteAttribute("typeName", SerializationUtility.GetTypeAndAssemblyName(typeof(ContentItem))); propertyElement.WriteAttribute("versionKey", item.GetVersionKey()); propertyElement.Write(item.ID.ToString()); }
private void WriteInnerContents(ContentItem item, ContentDetail detail, string valueTypeKey, ElementWriter element) { switch (valueTypeKey) { case ContentDetail.TypeKeys.BoolType: element.Write(detail.BoolValue.HasValue ? detail.BoolValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.DateTimeType: element.Write(SerializationUtility.ToUniversalString(detail.DateTimeValue)); return; case ContentDetail.TypeKeys.DoubleType: element.Write(detail.DoubleValue.HasValue ? detail.DoubleValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.IntType: element.Write(detail.IntValue.HasValue ? detail.IntValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.LinkType: element.Write(detail.LinkValue.HasValue ? detail.LinkValue.Value.ToString() : "0"); return; case ContentDetail.TypeKeys.MultiType: WriteMultiValue(item, detail, ContentDetail.TypeKeys.BoolType, detail.BoolValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.DateTimeType, detail.DateTimeValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.DoubleType, detail.DoubleValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.IntType, detail.IntValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.LinkType, detail.LinkedItem, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.ObjectType, detail.ObjectValue, element.Writer); WriteMultiValue(item, detail, ContentDetail.TypeKeys.StringType, detail.StringValue, element.Writer); return; case ContentDetail.TypeKeys.ObjectType: string base64representation = SerializationUtility.ToBase64String(detail.ObjectValue); element.Write(base64representation); return; case ContentDetail.TypeKeys.StringType: string value = detail.StringValue; if (!string.IsNullOrEmpty(value)) { var pi = item.GetContentType().GetProperty(detail.Name); if (pi != null) { var transformers = pi.GetCustomAttributes(typeof(IRelativityTransformer), false); foreach (IRelativityTransformer transformer in transformers) { if (transformer.RelativeWhen == RelativityMode.Always || transformer.RelativeWhen == RelativityMode.ImportingOrExporting) value = transformer.Rebase(value, applicationPath, "~/"); } } element.WriteCData(value); } return; default: throw new InvalidOperationException("Invalid detail type: " + valueTypeKey); } }
private void WriteMultiValue(ContentItem item, ContentDetail detail, string valueTypeKey, object value, XmlTextWriter writer) { if (value == null) return; using (ElementWriter multiElement = new ElementWriter("value", writer)) { multiElement.WriteAttribute("key", valueTypeKey); WriteInnerContents(item, detail, valueTypeKey, multiElement); } }