protected virtual void OnWritingDetail(XmlTextWriter xtw, N2.Details.ContentDetail detail) { xtw.WriteStartElement("detail"); xtw.WriteAttributeString("name", detail.Name); xtw.WriteAttributeString("typeName", SerializationUtility.GetTypeAndAssemblyName(detail.ValueType)); if (detail.ValueType == typeof(object)) { BinaryFormatter bf = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); bf.Serialize(stream, detail.Value); xtw.WriteString(Convert.ToBase64String(stream.ToArray())); } else if (detail.ValueType == typeof(ContentItem)) { xtw.WriteString(detail.LinkedItem.ID.ToString()); } else if (detail.Value == typeof(string)) { xtw.WriteCData(detail.StringValue); } else { xtw.WriteString(detail.Value.ToString()); } xtw.WriteEndElement(); }
private static void WriteSingleDetail <T>(XmlTextWriter writer, string key, T detail) { var type = SerializationUtility.GetTypeAndAssemblyName(typeof(T)); using (var td = new ElementWriter("li", writer)) { td.WriteAttribute("data-key", key); td.WriteAttribute("data-type", type); try { td.WriteCData(detail.ToString()); } catch { td.Write("NULL"); } } }
protected virtual void OnWritingDefaultAttributes(N2.ContentItem item, XmlTextWriter xtw) { xtw.WriteAttributeString("id", item.ID.ToString()); xtw.WriteAttributeString("name", item.Name); xtw.WriteAttributeString("title", item.Title); xtw.WriteAttributeString("zoneName", item.ZoneName); xtw.WriteAttributeString("created", GetDateTimeString(item.Created)); xtw.WriteAttributeString("updated", GetDateTimeString(item.Updated)); xtw.WriteAttributeString("published", (item.Published.HasValue) ? GetDateTimeString(item.Published.Value) : string.Empty); xtw.WriteAttributeString("expires", (item.Expires.HasValue) ? GetDateTimeString(item.Expires.Value) : string.Empty); xtw.WriteAttributeString("sortOrder", item.SortOrder.ToString()); xtw.WriteAttributeString("url", engine.UrlParser.BuildUrl(item)); xtw.WriteAttributeString("visible", item.Visible.ToString()); xtw.WriteAttributeString("savedBy", item.SavedBy); xtw.WriteAttributeString("typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); xtw.WriteAttributeString("discriminator", engine.Definitions.GetDefinition(item).Discriminator); }
public virtual void WriteSingleItem(ContentItem item, ExportOptions options, XmlTextWriter writer) { var authorizedRolesList = String.Join("|", from x in item.AuthorizedRoles let y = x.ToString() select y); using (var properties = new ElementWriter("ul", writer)) { properties.WriteAttribute("class", "n2-itemproperties"); properties.WriteAttribute("id", "n2-item" + item.ID); WriteSingleDetail(writer, "id", item.ID); WriteSingleDetail(writer, "name", item.ID.ToString() == item.Name ? "" : item.Name); if (item.Parent != null) { if (item.Parent.ID != 0) { WriteSingleDetail(writer, "parent", item.Parent.ID.ToString()); } else { WriteSingleDetail(writer, "parent", item.Parent.VersionOf.ID.ToString()); if (item.Parent.GetVersionKey() != null) { WriteSingleDetail(writer, "parentVersionKey", item.Parent.GetVersionKey()); } } } WriteSingleDetail(writer, "title", item.Title); WriteSingleDetail(writer, "zoneName", item.ZoneName); WriteSingleDetail(writer, "templateKey", item.TemplateKey); WriteSingleDetail(writer, "translationKey", item.TranslationKey ?? 0); WriteSingleDetail(writer, "state", item.State.ToString()); WriteSingleDetail(writer, "created", item.Created); WriteSingleDetail(writer, "updated", item.Updated); WriteSingleDetail(writer, "published", item.Published); WriteSingleDetail(writer, "expires", item.Expires); WriteSingleDetail(writer, "sortOrder", item.SortOrder); WriteSingleDetail(writer, "url", item.Url); WriteSingleDetail(writer, "visible", item.Visible); WriteSingleDetail(writer, "savedBy", item.SavedBy); WriteSingleDetail(writer, "typeName", SerializationUtility.GetTypeAndAssemblyName(item.GetContentType())); WriteSingleDetail(writer, "discriminator", _definitions.GetDefinition(item).Discriminator); WriteSingleDetail(writer, "versionIndex", item.VersionIndex); WriteSingleDetail(writer, "ancestralTrail", item.AncestralTrail); WriteSingleDetail(writer, "alteredPermissions", item.AlteredPermissions.ToString()); WriteSingleDetail(writer, "childState", item.ChildState.ToString()); if (item.VersionOf.HasValue) { Debug.Assert(item.VersionOf.ID != null, "item.VersionOf.ID != null"); WriteSingleDetail(writer, "versionOf", item.VersionOf.ID.Value); } WriteSingleDetail(writer, "authorizedRoles", authorizedRolesList); //WriteSingleDetail(writer, "Extension", item.Extension); //WriteSingleDetail(writer, "IconUrl", item.IconUrl); //WriteSingleDetail(writer, "IsExpired", item.IsExpired()); //WriteSingleDetail(writer, "IsPage", item.IsPage); //WriteSingleDetail(writer, "Path", item.Path); //foreach (ContentDetail d in item.Details) // using (var html = new ElementWriter(C_PROPERTYTAG, writer)) // { // html.WriteAttribute("data-type", d.ValueTypeKey); // html.WriteAttribute("data-name", d.Name); // html.WriteCData(d.Value.ToString()); // } } dw.Write(item, writer); dww.Write(item, writer); }