Beispiel #1
0
        protected virtual void ReadDefaultAttributes(Dictionary <string, string> attributes, ContentItem item, ReadingJournal journal)
        {
            item.Created = ToNullableDateTime(attributes["created"]).Value;
            item.Expires = ToNullableDateTime(attributes["expires"]);
            item.ID      = Convert.ToInt32(attributes["id"]);
            item.Name    = attributes["name"];
            if (item.ID.ToString() == item.Name)
            {
                item.Name = null;
            }
            item.Published = ToNullableDateTime(attributes["published"]);
            item.SavedBy   = attributes["savedBy"];
            item.SortOrder = Convert.ToInt32(attributes["sortOrder"]);
            item.Title     = attributes["title"];
            item.Updated   = ToNullableDateTime(attributes["updated"]).Value;
            item.Visible   = Convert.ToBoolean(attributes["visible"]);
            if (!string.IsNullOrEmpty(attributes["zoneName"]))
            {
                item.ZoneName = attributes["zoneName"];
            }
            if (attributes.ContainsKey("templateKey") && !string.IsNullOrEmpty(attributes["templateKey"]))
            {
                item.TemplateKey = attributes["templateKey"];
            }
            if (attributes.ContainsKey("translationKey") && !string.IsNullOrEmpty(attributes["translationKey"]))
            {
                item.TranslationKey = Convert.ToInt32(attributes["translationKey"]);
            }
            if (attributes.ContainsKey("ancestralTrail"))
            {
                item.AncestralTrail = attributes["ancestralTrail"];
            }
            if (attributes.ContainsKey("alteredPermissions"))
            {
                item.AlteredPermissions = (Permission)Convert.ToInt32(attributes["alteredPermissions"]);
            }
            if (attributes.ContainsKey("childState"))
            {
                item.ChildState = (Collections.CollectionState)Convert.ToInt32(attributes["childState"]);
            }
            if (attributes.ContainsKey("versionIndex"))
            {
                item.VersionIndex = Convert.ToInt32(attributes["versionIndex"]);
            }
            if (attributes.ContainsKey("versionOf"))
            {
                item.VersionOf.ID            = Convert.ToInt32(attributes["versionOf"]);
                item.VersionOf.ValueAccessor = repository.Get;
            }

            if (attributes.ContainsKey("parent"))
            {
                var parentVersionKey = attributes.ContainsKey("parentVersionKey") ? attributes["parentVersionKey"] : null;
                HandleParentRelation(item, attributes["parent"], parentVersionKey, journal);
            }

            if (attributes.ContainsKey("state") && !string.IsNullOrEmpty(attributes["state"]))
            {
                item.State = (ContentState)Convert.ToInt32(attributes["state"]);
            }
            else
            {
                item.State = SerializationUtility.RecaulculateState(item);
            }
        }
Beispiel #2
0
        protected virtual void ReadDefaultAttributes(Dictionary <string, string> attributes, ContentItem item, ReadingJournal journal)
        {
            item.Created = ToDateTime(attributes["created"]);
            item.Expires = attributes.ContainsKey("expires") ? ToNullableDateTime(attributes["expires"]) : null;
            item.ID      = Convert.ToInt32(attributes["id"]);
            item.Name    = GetStringOrNull(attributes, "name");
            if (item.ID.ToString() == item.Name)
            {
                item.Name = null;
            }

            item.Published = attributes.ContainsKey("published") ? ToNullableDateTime(attributes["published"]) : null;
            item.SavedBy   = attributes.ContainsKey("savedBy") ? attributes["savedBy"] : null;
            item.SortOrder = Convert.ToInt32(attributes["sortOrder"]);
            item.Title     = attributes.ContainsKey("title") ? attributes["title"] : "";
            item.Updated   = ToDateTime(attributes["updated"]);
            item.Visible   = Convert.ToBoolean(attributes["visible"]);

            item.ZoneName    = GetStringOrNull(attributes, "zoneName"); // empty string must get converted to null for code to work, see  PersistentContentItemList<T>.FindPages()
            item.TemplateKey = GetStringOrNull(attributes, "templateKey");
            if (attributes.ContainsKey("translationKey") && !string.IsNullOrEmpty(attributes["translationKey"]))
            {
                item.TranslationKey = Convert.ToInt32(attributes["translationKey"]);
            }
            if (attributes.ContainsKey("ancestralTrail"))
            {
                item.AncestralTrail = attributes["ancestralTrail"];
            }
            if (attributes.ContainsKey("alteredPermissions"))
            {
                item.AlteredPermissions = (Permission)Convert.ToInt32(attributes["alteredPermissions"]);
            }
            if (attributes.ContainsKey("childState"))
            {
                item.ChildState = (Collections.CollectionState)Convert.ToInt32(attributes["childState"]);
            }
            if (attributes.ContainsKey("versionIndex"))
            {
                item.VersionIndex = Convert.ToInt32(attributes["versionIndex"]);
            }
            if (attributes.ContainsKey("versionOf"))
            {
                item.VersionOf.ID = Convert.ToInt32(attributes["versionOf"]);
                if (repository != null)
                {
                    item.VersionOf.ValueAccessor = repository.Get;
                }
            }

            if (attributes.ContainsKey("parent"))
            {
                var parentVersionKey = attributes.ContainsKey("parentVersionKey") ? attributes["parentVersionKey"] : null;
                HandleParentRelation(item, attributes["parent"], parentVersionKey, journal);
            }

            if (attributes.ContainsKey("state") && !string.IsNullOrEmpty(attributes["state"]))
            {
                // be tolerant to read both old numeric and new textual state
                var          val = attributes["state"];
                int          intval;
                ContentState newstate;
                if (int.TryParse(val, out intval))
                {
                    newstate = (ContentState)intval;
                }
                else if (!Enum.TryParse(val, true, out newstate))
                {
                    newstate = SerializationUtility.RecaulculateState(item);
                }

                item.State = newstate;
            }
            else         // TODO: dangerous migration code
            {
                item.State = SerializationUtility.RecaulculateState(item);
            }
        }