//============================================================ // ICOMPARABLE IMPLEMENTATION //============================================================ #region CompareTo(object obj) /// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns> /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception> public int CompareTo(object obj) { //------------------------------------------------------------ // If target is a null reference, instance is greater //------------------------------------------------------------ if (obj == null) { return(1); } //------------------------------------------------------------ // Determine comparison result using property state of objects //------------------------------------------------------------ RsdApplicationInterface value = obj as RsdApplicationInterface; if (value != null) { int result = Uri.Compare(this.Documentation, value.Documentation, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | this.IsPreferred.CompareTo(value.IsPreferred); result = result | Uri.Compare(this.Link, value.Link, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Name, value.Name, StringComparison.OrdinalIgnoreCase); result = result | String.Compare(this.Notes, value.Notes, StringComparison.OrdinalIgnoreCase); result = result | ComparisonUtility.CompareSequence(this.Settings, value.Settings, StringComparison.Ordinal); result = result | String.Compare(this.WeblogId, value.WeblogId, StringComparison.OrdinalIgnoreCase); return(result); } else { throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj"); } }
/// <summary> /// Adds the supplied <see cref="RsdApplicationInterface"/> to the current instance's <see cref="Interfaces"/> collection. /// </summary> /// <param name="api">The <see cref="RsdApplicationInterface"/> to be added.</param> /// <returns><b>true</b> if the <see cref="RsdApplicationInterface"/> was added to the <see cref="Interfaces"/> collection, otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="api"/> is a null reference (Nothing in Visual Basic).</exception> public bool AddInterface(RsdApplicationInterface api) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasAdded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(api, "api"); //------------------------------------------------------------ // Add application interface to collection //------------------------------------------------------------ ((Collection<RsdApplicationInterface>)this.Interfaces).Add(api); wasAdded = true; return wasAdded; }
/// <summary> /// Removes the supplied <see cref="RsdApplicationInterface"/> from the current instance's <see cref="Interfaces"/> collection. /// </summary> /// <param name="api">The <see cref="RsdApplicationInterface"/> to be removed.</param> /// <returns><b>true</b> if the <see cref="RsdApplicationInterface"/> was removed from the <see cref="Interfaces"/> collection, otherwise <b>false</b>.</returns> /// <remarks> /// If the <see cref="Interfaces"/> collection of the current instance does not contain the specified <see cref="RsdApplicationInterface"/>, will return <b>false</b>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="api"/> is a null reference (Nothing in Visual Basic).</exception> public bool RemoveInterface(RsdApplicationInterface api) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasRemoved = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(api, "api"); //------------------------------------------------------------ // Remove application interface from collection //------------------------------------------------------------ if (((Collection<RsdApplicationInterface>)this.Interfaces).Contains(api)) { ((Collection<RsdApplicationInterface>)this.Interfaces).Remove(api); wasRemoved = true; } return wasRemoved; }
/// <summary> /// Modifies the <see cref="RsdDocument"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="RsdDocument"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(RsdDocument resource) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = RsdUtility.CreateNamespaceManager(this.Navigator.NameTable); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ XPathNavigator serviceNavigator = RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd/rsd:service", manager); if (serviceNavigator == null) { // dasBlog places an empty default XML namespace on the <service> element, this is a hack/compromise serviceNavigator = RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd/service", manager); } if (serviceNavigator != null) { XPathNavigator engineNameNavigator = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:engineName", manager); XPathNavigator engineLinkNavigator = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:engineLink", manager); XPathNavigator homePageLinkNavigator = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:homePageLink", manager); XPathNodeIterator apiIterator = RsdUtility.SelectSafe(serviceNavigator, "rsd:apis/rsd:api", manager); if (engineNameNavigator != null && !String.IsNullOrEmpty(engineNameNavigator.Value)) { resource.EngineName = engineNameNavigator.Value; } if (engineLinkNavigator != null) { Uri link; if (Uri.TryCreate(engineLinkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { resource.EngineLink = link; } } if (homePageLinkNavigator != null) { Uri homepage; if (Uri.TryCreate(homePageLinkNavigator.Value, UriKind.RelativeOrAbsolute, out homepage)) { resource.Homepage = homepage; } } if (apiIterator != null && apiIterator.Count > 0) { int counter = 0; while (apiIterator.MoveNext()) { RsdApplicationInterface api = new RsdApplicationInterface(); counter++; Uri link; string rpcLinkAttribute = apiIterator.Current.GetAttribute("rpcLink", String.Empty); if (Uri.TryCreate(rpcLinkAttribute, UriKind.RelativeOrAbsolute, out link)) { api.Link = link; } if (api.Load(apiIterator.Current, this.Settings) || api.Link != null) { if (this.Settings.RetrievalLimit != 0 && counter > this.Settings.RetrievalLimit) { break; } ((Collection<RsdApplicationInterface>)resource.Interfaces).Add(api); } } } } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd", manager), this.Settings); adapter.Fill(resource, manager); }