예제 #1
0
        protected virtual XElement SerializeSchedule(IContent item, SyncSerializerOptions options)
        {
            var node      = new XElement("Schedule");
            var schedules = contentService.GetContentScheduleByContentId(item.Id);

            var cultures = options.GetCultures();

            if (schedules != null)
            {
                foreach (var schedule in schedules.FullSchedule
                         .OrderBy(x => x.Action.ToString())
                         .ThenBy(x => x.Culture))
                {
                    // only export if its a blank culture or one of the ones we have set.
                    if (cultures.IsValidOrBlank(schedule.Culture))
                    {
                        node.Add(new XElement("ContentSchedule",
                                              // new XAttribute("Key", schedule.Id),
                                              new XElement("Culture", schedule.Culture),
                                              new XElement("Action", schedule.Action),
                                              new XElement("Date", schedule.Date.ToString("s"))));
                    }
                }
            }

            return(node);
        }
예제 #2
0
        /// <summary>
        ///  Serialize the Info - (Item Attributes) Node
        /// </summary>
        protected virtual XElement SerializeInfo(TObject item, SyncSerializerOptions options)
        {
            var info = new XElement("Info");

            // find parent.
            var parentKey  = Guid.Empty;
            var parentName = "";

            if (item.ParentId != -1)
            {
                var cachedItem = GetCachedName(item.ParentId);
                if (cachedItem != null)
                {
                    parentKey  = cachedItem.Key;
                    parentName = cachedItem.Name;
                }
                else
                {
                    var parent = FindItem(item.ParentId);
                    if (parent != null)
                    {
                        parentKey  = parent.Key;
                        parentName = parent.Name;
                    }
                }
            }

            info.Add(new XElement("Parent", new XAttribute("Key", parentKey), parentName));
            info.Add(new XElement("Path", GetItemPath(item)));
            info.Add(GetTrashedInfo(item));
            info.Add(new XElement("ContentType", item.ContentType.Alias));
            info.Add(new XElement("CreateDate", item.CreateDate.ToString("s")));

            var cultures = options.GetCultures();

            var title = new XElement("NodeName", new XAttribute("Default", item.Name));

            foreach (var culture in item.AvailableCultures)
            {
                if (cultures.IsValidOrBlank(culture))
                {
                    title.Add(new XElement("Name", item.GetCultureName(culture),
                                           new XAttribute("Culture", culture)));
                }
            }
            info.Add(title);

            info.Add(new XElement("SortOrder", item.SortOrder));

            return(info);
        }
예제 #3
0
        protected override SyncAttempt <XElement> SerializeCore(IDictionaryItem item, SyncSerializerOptions options)
        {
            var node = InitializeBaseNode(item, item.ItemKey, GetLevel(item));

            // if we are serializing by culture, then add the culture attribute here.
            var cultures = options.GetSetting(uSyncConstants.CultureKey, string.Empty);

            if (!string.IsNullOrWhiteSpace(cultures))
            {
                node.Add(new XAttribute(uSyncConstants.CultureKey, cultures));
            }

            var info = new XElement("Info");

            if (item.ParentId.HasValue)
            {
                var parent = FindItem(item.ParentId.Value);
                if (parent != null)
                {
                    info.Add(new XElement("Parent", parent.ItemKey));
                }
            }

            var activeCultures = options.GetCultures();

            var translationsNode = new XElement("Translations");

            foreach (var translation in item.Translations
                     .SafeDistinctBy(x => x.Language.IsoCode)
                     .OrderBy(x => x.Language.IsoCode))
            {
                if (activeCultures.IsValid(translation.Language.IsoCode))
                {
                    translationsNode.Add(new XElement("Translation", translation.Value,
                                                      new XAttribute("Language", translation.Language.IsoCode)));
                }
            }

            node.Add(info);
            node.Add(translationsNode);

            return(SyncAttempt <XElement> .Succeed(
                       item.ItemKey, node, typeof(IDictionaryItem), ChangeType.Export));
        }
예제 #4
0
        private XElement SerailizePublishedStatus(IContent item, SyncSerializerOptions options)
        {
            // get the list of cultures we are serializing from the config
            var activeCultures = options.GetCultures();

            var published = new XElement("Published");

            // to make this a non-breaking change, we say default = item.published, but when
            // dealing with cultures it isn't used.
            published.Add(new XAttribute("Default", item.Published));

            foreach (var culture in item.AvailableCultures.OrderBy(x => x))
            {
                if (activeCultures.IsValid(culture))
                {
                    published.Add(new XElement("Published", item.IsCulturePublished(culture),
                                               new XAttribute("Culture", culture)));
                }
            }
            return(published);
        }
예제 #5
0
        /// <summary>
        ///  serialize all the properties for the item
        /// </summary>
        protected virtual XElement SerializeProperties(TObject item, SyncSerializerOptions options)
        {
            var cultures        = options.GetCultures();
            var segments        = options.GetSegments();
            var includeDefaults = (cultures.Count == 0 && segments.Count == 0) ||
                                  options.GetSetting(uSyncConstants.DefaultsKey, false);

            var node = new XElement("Properties");

            foreach (var property in item.Properties
                     .Where(x => !dontSerialize.InvariantContains(x.Alias))
                     .OrderBy(x => x.Alias))
            {
                var propertyNode = new XElement(property.Alias);

                // this can cause us false change readings
                // but we need to preserve the values if they are blank
                // because we have to be able to set them to blank on deserialization
                foreach (var value in property.Values)
                {
                    var valueNode = new XElement("Value");

                    // valid if there is no culture, or segment and
                    // we are includeing default values
                    var validNode = string.IsNullOrWhiteSpace(value.Culture) &&
                                    string.IsNullOrWhiteSpace(value.Segment) &&
                                    includeDefaults;


                    // or b) it is a valid culture/segment.
                    if (!string.IsNullOrWhiteSpace(value.Culture) && cultures.IsValid(value.Culture))
                    {
                        valueNode.Add(new XAttribute("Culture", value.Culture ?? string.Empty));
                        validNode = true;
                    }


                    if (!string.IsNullOrWhiteSpace(value.Segment) && segments.IsValid(value.Segment))
                    {
                        valueNode.Add(new XAttribute("Segment", value.Segment ?? string.Empty));
                        validNode = true;
                    }

                    if (validNode)
                    {
                        valueNode.Add(new XCData(GetExportValue(GetPropertyValue(value), property.PropertyType, value.Culture, value.Segment)));
                        propertyNode.Add(valueNode);
                    }
                }

                if (property.Values == null || property.Values.Count == 0 && includeDefaults)
                {
                    // add a blank one, for change clarity
                    // we do it like this because then it doesn't get collapsed in the XML serialization
                    var emptyValue = new XElement("Value");
                    emptyValue.Add(new XCData(string.Empty));

                    propertyNode.Add(emptyValue);
                }

                if (propertyNode.HasElements)
                {
                    node.Add(propertyNode);
                }
            }

            return(node);
        }