Example #1
0
        //============================================================
        //	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
            //------------------------------------------------------------
            ApmlSource value = obj as ApmlSource;

            if (value != null)
            {
                int result = ApmlSource.CompareSequence(this.Authors, value.Authors);
                result = result | String.Compare(this.From, value.From, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Key, value.Key, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.MimeType, value.MimeType, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Name, value.Name, StringComparison.OrdinalIgnoreCase);
                result = result | this.UpdatedOn.CompareTo(value.UpdatedOn);
                result = result | this.Value.CompareTo(value.Value);

                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");
            }
        }
Example #2
0
        /// <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 (obj == null)
            {
                return(1);
            }
            ApmlSource value = obj as ApmlSource;

            if (value != null)
            {
                int result = ApmlSource.CompareSequence(this.Authors, value.Authors);
                result = result | String.Compare(this.From, value.From, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Key, value.Key, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.MimeType, value.MimeType, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Name, value.Name, StringComparison.OrdinalIgnoreCase);
                result = result | this.UpdatedOn.CompareTo(value.UpdatedOn);
                result = result | this.Value.CompareTo(value.Value);

                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");
            }
        }
Example #3
0
        /// <summary>
        /// Loads this <see cref="ApmlProfile"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <returns><b>true</b> if the <see cref="ApmlProfile"/> 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="ApmlProfile"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(settings, "settings");
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            if (source.HasAttributes)
            {
                string nameAttribute = source.GetAttribute("name", String.Empty);
                if (!String.IsNullOrEmpty(nameAttribute))
                {
                    this.Name = nameAttribute;
                    wasLoaded = true;
                }
            }

            if (source.HasChildren)
            {
                XPathNavigator implicitDataNavigator = source.SelectSingleNode("apml:ImplicitData", manager);
                XPathNavigator explicitDataNavigator = source.SelectSingleNode("apml:ExplicitData", manager);

                if (implicitDataNavigator != null)
                {
                    XPathNodeIterator conceptsIterator = implicitDataNavigator.Select("apml:Concepts/apml:Concept", manager);
                    if (conceptsIterator != null && conceptsIterator.Count > 0)
                    {
                        while (conceptsIterator.MoveNext())
                        {
                            ApmlConcept concept = new ApmlConcept();
                            if (concept.Load(conceptsIterator.Current, settings))
                            {
                                this.ImplicitConcepts.Add(concept);
                                wasLoaded = true;
                            }
                        }
                    }

                    XPathNodeIterator sourcesIterator = implicitDataNavigator.Select("apml:Sources/apml:Source", manager);
                    if (sourcesIterator != null && sourcesIterator.Count > 0)
                    {
                        while (sourcesIterator.MoveNext())
                        {
                            ApmlSource attentionSource = new ApmlSource();
                            if (attentionSource.Load(sourcesIterator.Current, settings))
                            {
                                this.ImplicitSources.Add(attentionSource);
                                wasLoaded = true;
                            }
                        }
                    }
                }

                if (explicitDataNavigator != null)
                {
                    XPathNodeIterator conceptsIterator = explicitDataNavigator.Select("apml:Concepts/apml:Concept", manager);
                    if (conceptsIterator != null && conceptsIterator.Count > 0)
                    {
                        while (conceptsIterator.MoveNext())
                        {
                            ApmlConcept concept = new ApmlConcept();
                            if (concept.Load(conceptsIterator.Current, settings))
                            {
                                this.ExplicitConcepts.Add(concept);
                                wasLoaded = true;
                            }
                        }
                    }

                    XPathNodeIterator sourcesIterator = explicitDataNavigator.Select("apml:Sources/apml:Source", manager);
                    if (sourcesIterator != null && sourcesIterator.Count > 0)
                    {
                        while (sourcesIterator.MoveNext())
                        {
                            ApmlSource attentionSource = new ApmlSource();
                            if (attentionSource.Load(sourcesIterator.Current, settings))
                            {
                                this.ExplicitSources.Add(attentionSource);
                                wasLoaded = true;
                            }
                        }
                    }
                }
            }
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);

            adapter.Fill(this);

            return(wasLoaded);
        }
Example #4
0
        //============================================================
        //    CLASS SUMMARY
        //============================================================
        /// <summary>
        /// Provides example code for the ApmlProfile class.
        /// </summary>
        public static void ClassExample()
        {
            #region ApmlProfile
            ApmlDocument document       = new ApmlDocument();
            document.DefaultProfileName = "Work";

            document.Head.Title         = "Example APML file for apml.org";
            document.Head.Generator     = "Written by Hand";
            document.Head.EmailAddress  = "*****@*****.**";
            document.Head.CreatedOn     = new DateTime(2007, 3, 11, 13, 55, 0);

            //  Create home attention profile
            ApmlProfile homeProfile     = new ApmlProfile();
            homeProfile.Name            = "Home";

            homeProfile.ImplicitConcepts.Add(new ApmlConcept("attention", 0.99m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("content distribution", 0.97m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("information", 0.95m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("business", 0.93m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("alerting", 0.91m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("intelligent agents", 0.89m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("development", 0.87m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("service", 0.85m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("user interface", 0.83m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("experience design", 0.81m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("site design", 0.79m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("television", 0.77m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("management", 0.75m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));
            homeProfile.ImplicitConcepts.Add(new ApmlConcept("media", 0.73m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));

            ApmlSource apmlSpecSource   = new ApmlSource();
            apmlSpecSource.Key          = "http://feeds.feedburner.com/apmlspec";
            apmlSpecSource.Name         = "APML.org";
            apmlSpecSource.Value        = 1.00m;
            apmlSpecSource.MimeType     = "application/rss+xml";
            apmlSpecSource.From         = "GatheringTool.com";
            apmlSpecSource.UpdatedOn    = new DateTime(2007, 3, 11, 13, 55, 0);
            apmlSpecSource.Authors.Add(new ApmlAuthor("Sample", 0.5m, "GatheringTool.com", new DateTime(2007, 3, 11, 13, 55, 0)));

            homeProfile.ImplicitSources.Add(apmlSpecSource);

            homeProfile.ExplicitConcepts.Add(new ApmlConcept("direct attention", 0.99m));

            ApmlSource techCrunchSource = new ApmlSource();
            techCrunchSource.Key        = "http://feeds.feedburner.com/TechCrunch";
            techCrunchSource.Name       = "Techcrunch";
            techCrunchSource.Value      = 0.4m;
            techCrunchSource.MimeType   = "application/rss+xml";
            techCrunchSource.Authors.Add(new ApmlAuthor("ExplicitSample", 0.5m));

            homeProfile.ExplicitSources.Add(techCrunchSource);

            document.AddProfile(homeProfile);

            //  Create work attention profile
            ApmlProfile workProfile     = new ApmlProfile();
            workProfile.Name            = "Work";

            homeProfile.ExplicitConcepts.Add(new ApmlConcept("Golf", 0.2m));

            ApmlSource workTechCrunchSource = new ApmlSource();
            workTechCrunchSource.Key        = "http://feeds.feedburner.com/TechCrunch";
            workTechCrunchSource.Name       = "Techcrunch";
            workTechCrunchSource.Value      = 0.4m;
            workTechCrunchSource.MimeType   = "application/atom+xml";
            workTechCrunchSource.Authors.Add(new ApmlAuthor("ProfessionalBlogger", 0.5m));

            homeProfile.ExplicitSources.Add(workTechCrunchSource);

            document.AddProfile(workProfile);

            ApmlApplication sampleApplication   = new ApmlApplication("sample.com");
            sampleApplication.Data              = "<SampleAppEl />";

            document.Applications.Add(sampleApplication);
            #endregion
        }
Example #5
0
        /// <summary>
        /// Loads this <see cref="ApmlProfile"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <returns><b>true</b> if the <see cref="ApmlProfile"/> 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="ApmlProfile"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded              = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string nameAttribute    = source.GetAttribute("name", String.Empty);
                if (!String.IsNullOrEmpty(nameAttribute))
                {
                    this.Name   = nameAttribute;
                    wasLoaded   = true;
                }
            }

            if(source.HasChildren)
            {
                XPathNavigator implicitDataNavigator    = source.SelectSingleNode("apml:ImplicitData", manager);
                XPathNavigator explicitDataNavigator    = source.SelectSingleNode("apml:ExplicitData", manager);

                if (implicitDataNavigator != null)
                {
                    XPathNodeIterator conceptsIterator  = implicitDataNavigator.Select("apml:Concepts/apml:Concept", manager);
                    if (conceptsIterator != null && conceptsIterator.Count > 0)
                    {
                        while (conceptsIterator.MoveNext())
                        {
                            ApmlConcept concept = new ApmlConcept();
                            if (concept.Load(conceptsIterator.Current, settings))
                            {
                                this.ImplicitConcepts.Add(concept);
                                wasLoaded       = true;
                            }
                        }
                    }

                    XPathNodeIterator sourcesIterator   = implicitDataNavigator.Select("apml:Sources/apml:Source", manager);
                    if (sourcesIterator != null && sourcesIterator.Count > 0)
                    {
                        while (sourcesIterator.MoveNext())
                        {
                            ApmlSource attentionSource  = new ApmlSource();
                            if (attentionSource.Load(sourcesIterator.Current, settings))
                            {
                                this.ImplicitSources.Add(attentionSource);
                                wasLoaded               = true;
                            }
                        }
                    }
                }

                if (explicitDataNavigator != null)
                {
                    XPathNodeIterator conceptsIterator  = explicitDataNavigator.Select("apml:Concepts/apml:Concept", manager);
                    if (conceptsIterator != null && conceptsIterator.Count > 0)
                    {
                        while (conceptsIterator.MoveNext())
                        {
                            ApmlConcept concept = new ApmlConcept();
                            if (concept.Load(conceptsIterator.Current, settings))
                            {
                                this.ExplicitConcepts.Add(concept);
                                wasLoaded       = true;
                            }
                        }
                    }

                    XPathNodeIterator sourcesIterator   = explicitDataNavigator.Select("apml:Sources/apml:Source", manager);
                    if (sourcesIterator != null && sourcesIterator.Count > 0)
                    {
                        while (sourcesIterator.MoveNext())
                        {
                            ApmlSource attentionSource  = new ApmlSource();
                            if (attentionSource.Load(sourcesIterator.Current, settings))
                            {
                                this.ExplicitSources.Add(attentionSource);
                                wasLoaded               = true;
                            }
                        }
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
Example #6
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="ApmlProfile"/> 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="ApmlProfile"/> 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="ApmlProfile"/>.
        /// </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");

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string nameAttribute = source.GetAttribute("name", String.Empty);
                if (!String.IsNullOrEmpty(nameAttribute))
                {
                    this.Name = nameAttribute;
                    wasLoaded = true;
                }
            }

            if (source.HasChildren)
            {
                XPathNavigator implicitDataNavigator = source.SelectSingleNode("apml:ImplicitData", manager);
                XPathNavigator explicitDataNavigator = source.SelectSingleNode("apml:ExplicitData", manager);

                if (implicitDataNavigator != null)
                {
                    XPathNodeIterator conceptsIterator = implicitDataNavigator.Select("apml:Concepts/apml:Concept", manager);
                    if (conceptsIterator != null && conceptsIterator.Count > 0)
                    {
                        while (conceptsIterator.MoveNext())
                        {
                            ApmlConcept concept = new ApmlConcept();
                            if (concept.Load(conceptsIterator.Current))
                            {
                                this.ImplicitConcepts.Add(concept);
                                wasLoaded = true;
                            }
                        }
                    }

                    XPathNodeIterator sourcesIterator = implicitDataNavigator.Select("apml:Sources/apml:Source", manager);
                    if (sourcesIterator != null && sourcesIterator.Count > 0)
                    {
                        while (sourcesIterator.MoveNext())
                        {
                            ApmlSource attentionSource = new ApmlSource();
                            if (attentionSource.Load(sourcesIterator.Current))
                            {
                                this.ImplicitSources.Add(attentionSource);
                                wasLoaded = true;
                            }
                        }
                    }
                }

                if (explicitDataNavigator != null)
                {
                    XPathNodeIterator conceptsIterator = explicitDataNavigator.Select("apml:Concepts/apml:Concept", manager);
                    if (conceptsIterator != null && conceptsIterator.Count > 0)
                    {
                        while (conceptsIterator.MoveNext())
                        {
                            ApmlConcept concept = new ApmlConcept();
                            if (concept.Load(conceptsIterator.Current))
                            {
                                this.ExplicitConcepts.Add(concept);
                                wasLoaded = true;
                            }
                        }
                    }

                    XPathNodeIterator sourcesIterator = explicitDataNavigator.Select("apml:Sources/apml:Source", manager);
                    if (sourcesIterator != null && sourcesIterator.Count > 0)
                    {
                        while (sourcesIterator.MoveNext())
                        {
                            ApmlSource attentionSource = new ApmlSource();
                            if (attentionSource.Load(sourcesIterator.Current))
                            {
                                this.ExplicitSources.Add(attentionSource);
                                wasLoaded = true;
                            }
                        }
                    }
                }
            }

            return(wasLoaded);
        }