/// <summary> /// Returns the conflict preservation identifier for the supplied <see cref="FeedSynchronizationConflictPreservationDirective"/>. /// </summary> /// <param name="directive">The <see cref="FeedSynchronizationConflictPreservationDirective"/> to get the conflict preservation identifier for.</param> /// <returns>The conflict preservation identifier for the supplied <paramref name="vocabulary"/>, otherwise returns an empty string.</returns> public static string ConflictPreservationAsString(FeedSynchronizationConflictPreservationDirective directive) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ string name = String.Empty; //------------------------------------------------------------ // Return alternate value based on supplied protocol //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(FeedSynchronizationConflictPreservationDirective).GetFields()) { if (fieldInfo.FieldType == typeof(FeedSynchronizationConflictPreservationDirective)) { FeedSynchronizationConflictPreservationDirective preservationDirective = (FeedSynchronizationConflictPreservationDirective)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (preservationDirective == directive) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; name = enumerationMetadata.AlternateValue; break; } } } } return(name); }
/// <summary> /// Returns the <see cref="FeedSynchronizationConflictPreservationDirective"/> enumeration value that corresponds to the specified conflict preservation name. /// </summary> /// <param name="name">The name of the conflict preservation.</param> /// <returns>A <see cref="FeedSynchronizationConflictPreservationDirective"/> enumeration value that corresponds to the specified string, otherwise returns <b>FeedSynchronizationConflictPreservationDirective.None</b>.</returns> /// <remarks>This method disregards case of specified conflict preservation name.</remarks> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception> public static FeedSynchronizationConflictPreservationDirective ConflictPreservationByName(string name) { FeedSynchronizationConflictPreservationDirective preservationDirective = FeedSynchronizationConflictPreservationDirective.None; Guard.ArgumentNotNullOrEmptyString(name, "name"); foreach (System.Reflection.FieldInfo fieldInfo in typeof(FeedSynchronizationConflictPreservationDirective).GetFields()) { if (fieldInfo.FieldType == typeof(FeedSynchronizationConflictPreservationDirective)) { FeedSynchronizationConflictPreservationDirective directive = (FeedSynchronizationConflictPreservationDirective)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0) { preservationDirective = directive; break; } } } } return(preservationDirective); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="FeedSynchronizationItem"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="FeedSynchronizationItem"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="FeedSynchronizationItem"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Create namespace manager to resolve prefixed elements //------------------------------------------------------------ FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension(); XmlNamespaceManager manager = extension.CreateNamespaceManager(source); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string idAttribute = source.GetAttribute("id", String.Empty); string updatesAttribute = source.GetAttribute("updates", String.Empty); string deletedAttribute = source.GetAttribute("deleted", String.Empty); string noConflictsAttribute = source.GetAttribute("noconflicts", String.Empty); if (!String.IsNullOrEmpty(idAttribute)) { this.Id = idAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(updatesAttribute)) { int updates; if (Int32.TryParse(updatesAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out updates)) { this.Updates = updates; wasLoaded = true; } } if (!String.IsNullOrEmpty(deletedAttribute)) { FeedSynchronizationTombstoneStatus status = FeedSynchronizationItem.TombstoneStatusByName(deletedAttribute); if (status != FeedSynchronizationTombstoneStatus.None) { this.TombstoneStatus = status; wasLoaded = true; } } if (!String.IsNullOrEmpty(noConflictsAttribute)) { FeedSynchronizationConflictPreservationDirective directive = FeedSynchronizationItem.ConflictPreservationByName(noConflictsAttribute); if (directive != FeedSynchronizationConflictPreservationDirective.None) { this.ConflictPreservation = directive; wasLoaded = true; } } } if (source.HasChildren) { XPathNodeIterator historyIterator = source.Select("sx:history", manager); XPathNavigator conflictsNavigator = source.SelectSingleNode("sx:conflicts", manager); if (historyIterator != null && historyIterator.Count > 0) { while (historyIterator.MoveNext()) { FeedSynchronizationHistory history = new FeedSynchronizationHistory(); if (history.Load(historyIterator.Current)) { this.Histories.Add(history); wasLoaded = true; } } } if (conflictsNavigator != null && conflictsNavigator.HasChildren) { XPathNodeIterator childrenIterator = conflictsNavigator.SelectChildren(XPathNodeType.Element); if (childrenIterator != null && childrenIterator.Count > 0) { this.Conflicts.Add(childrenIterator.Current); wasLoaded = true; } } } return(wasLoaded); }