protected virtual void ReadDetail(XPathNavigator navigator, PropertyCollection collection, ReadingJournal journal)
        {
            Dictionary<string, string> attributes = GetAttributes(navigator);
            Type type = attributes["typeName"].ToType();

            if (type != typeof(ContentItem))
            {
                collection.Add(Parse(navigator.Value, type));
            }
            else
            {
                int referencedItemID = int.Parse(navigator.Value);
                ContentItem referencedItem = journal.Find(referencedItemID);
                if (referencedItem != null)
                    collection.Add(referencedItem);
                else
                    journal.ItemAdded += (sender, e) =>
            {
                if (e.AffectedItem.ID == referencedItemID)
                {
                    collection.Add(e.AffectedItem);
                }
            };
            }
        }
Example #2
0
        protected virtual void ReadDetail(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
        {
            Dictionary<string, string> attributes = GetAttributes(navigator);
            Type type = attributes["typeName"].ToType();

            string name = attributes["name"];

            if (!typeof(ContentItem).IsAssignableFrom(type))
            {
                item[name] = Parse(navigator.Value, type);
            }
            else
            {
                int referencedItemID = int.Parse(navigator.Value);
                ContentItem referencedItem = journal.Find(referencedItemID);
                if (referencedItem != null)
                    item[name] = referencedItem;
                else
                    journal.ItemAdded += (sender, e) =>
            {
                if (e.AffectedItem.ID == referencedItemID)
                    item[name] = e.AffectedItem;
            };
            }
        }
        protected void ReadDetailCollection(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
        {
            Dictionary<string, string> attributes = GetAttributes(navigator);
            string name = attributes["name"];

            foreach (XPathNavigator detailElement in EnumerateChildren(navigator))
                ReadDetail(detailElement, item.GetDetailCollection(name, true), journal);
        }
 public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
 {
     foreach (XPathNavigator languageSettingElement in EnumerateChildren(navigator))
     {
         Dictionary<string, string> attributes = GetAttributes(languageSettingElement);
         string language = attributes["language"];
         string fallbackLanguage = attributes["fallbackLanguage"];
         item.LanguageSettings.Add(new LanguageSetting(item, language, fallbackLanguage));
     }
 }
 public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
 {
     foreach (XPathNavigator authorizationElement in EnumerateChildren(navigator))
     {
         Dictionary<string, string> attributes = GetAttributes(authorizationElement);
         string operation = attributes["operation"];
         string role = attributes["role"];
         string user = attributes["user"];
         bool allowed = Convert.ToBoolean(attributes["allowed"]);
         item.AuthorizationRules.Add(new AuthorizationRule(item, operation, role, user, allowed));
     }
 }
Example #6
0
        public virtual ContentItem ReadSingleItem(XPathNavigator navigator, ReadingJournal journal)
        {
            if (navigator.LocalName != "item") throw new DeserializationException("Expected element 'item' but was '" + navigator.LocalName + "'");

            Dictionary<string, string> attributes = GetAttributes(navigator);
            ContentItem item = CreateInstance(attributes);
            ReadDefaultAttributes(attributes, item, journal);

            foreach (XPathNavigator current in EnumerateChildren(navigator))
                if (readers.ContainsKey(current.LocalName))
                    readers[current.LocalName].Read(current, item, journal);

            return item;
        }
Example #7
0
        public virtual IImportRecord Read(XPathNavigator navigator)
        {
            if (navigator == null)
                throw new ArgumentNullException("navigator");

            ReadingJournal journal = new ReadingJournal();
            foreach (XPathNavigator itemElement in EnumerateChildren(navigator))
            {
                try
                {
                    ContentItem item = ReadSingleItem(itemElement, journal);
                    journal.Report(item);
                }
                catch (ContentTypeNotFoundException ex)
                {
                    journal.Error(ex);
                    if (!IgnoreMissingTypes)
                        throw;
                }
            }
            return journal;
        }
 public void Read(XPathNavigator navigator, ContentItem item, ReadingJournal journal)
 {
     foreach (XPathNavigator detailCollectionElement in EnumerateChildren(navigator))
         ReadDetailCollection(detailCollectionElement, item, journal);
 }
Example #9
0
 private static IImportRecord CreateRecord(ContentItem item)
 {
     ReadingJournal rj = new ReadingJournal();
     rj.Report(item);
     return rj;
 }
Example #10
0
 protected virtual void HandleParentRelation(ContentItem item, string parent, ReadingJournal journal)
 {
     if (!string.IsNullOrEmpty(parent))
     {
         int parentID = int.Parse(parent);
         ContentItem parentItem = journal.Find(parentID);
         item.AddTo(parentItem);
     }
 }
Example #11
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"];
     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 (attributes.ContainsKey("zoneName"))
         ((WidgetContentItem) item).ZoneName = attributes["zoneName"];
     HandleTranslationRelation(item, attributes["translationOf"], journal);
     if (!string.IsNullOrEmpty(attributes["language"]))
         item.Language = attributes["language"];
     HandleParentRelation(item, attributes["parent"], journal);
 }
Example #12
0
 protected virtual void HandleTranslationRelation(ContentItem item, string translationOf, ReadingJournal journal)
 {
     if (!string.IsNullOrEmpty(translationOf))
     {
         int translationOfID = int.Parse(translationOf);
         ContentItem masterItem = journal.Find(translationOfID);
         item.TranslationOf = masterItem;
     }
 }