Пример #1
0
        /// <summary>
        /// Provides example code for the Load(XmlReader) method
        /// </summary>
        public static void LoadXmlReaderExample()
        {
            ApmlDocument document = new ApmlDocument();

            using (Stream stream = new FileStream("ApmlDocument.xml", FileMode.Open, FileAccess.Read))
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments   = true;
                settings.IgnoreWhitespace = true;

                using (XmlReader reader = XmlReader.Create(stream, settings))
                {
                    document.Load(reader);

                    foreach (ApmlProfile profile in document.Profiles)
                    {
                        if (profile.Name == document.DefaultProfileName)
                        {
                            //  Perform some processing on the attention profile
                            break;
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Provides example code for the LoadAsync(Uri, Object) method
        /// </summary>
        public static void LoadAsyncExample()
        {
            ApmlDocument document = new ApmlDocument();

            document.Loaded += new EventHandler <SyndicationResourceLoadedEventArgs>(ResourceLoadedCallback);

            document.LoadAsync(new Uri("http://aura.darkstar.sunlabs.com/AttentionProfile/apml/web/Oppositional"), null);
        }
Пример #3
0
        /// <summary>
        /// Provides example code for the Save(Stream) method
        /// </summary>
        public static void SaveStreamExample()
        {
            ApmlDocument document = new ApmlDocument();

            //  Modify document state using public properties and methods

            using (Stream stream = new FileStream("ApmlDocument.xml", FileMode.Create, FileAccess.Write))
            {
                document.Save(stream);
            }
        }
Пример #4
0
        /// <summary>
        /// Provides example code for the ApmlDocument.Create(Uri) method
        /// </summary>
        public static void CreateExample()
        {
            ApmlDocument document = ApmlDocument.Create(new Uri("http://aura.darkstar.sunlabs.com/AttentionProfile/apml/web/Oppositional"));

            foreach (ApmlProfile profile in document.Profiles)
            {
                if (profile.Name == document.DefaultProfileName)
                {
                    //  Perform some processing on the attention profile
                    break;
                }
            }
        }
Пример #5
0
        //============================================================
        //	ASYNC METHODS
        //============================================================
        /// <summary>
        /// Provides example code for the LoadAsync(Uri, Object) method
        /// </summary>
        public static void LoadAsyncExample()
        {
            #region LoadAsync(Uri source, Object userToken)
            //------------------------------------------------------------
            //	Load resource asynchronously using event-based notification
            //------------------------------------------------------------
            ApmlDocument document = new ApmlDocument();

            document.Loaded += new EventHandler <SyndicationResourceLoadedEventArgs>(ResourceLoadedCallback);

            document.LoadAsync(new Uri("http://aura.darkstar.sunlabs.com/AttentionProfile/apml/web/Oppositional"), null);
            #endregion
        }
        /// <summary>
        /// Modifies the <see cref="ISyndicationResource"/> to match the data source.
        /// </summary>
        /// <param name="resource">The Attention Profiling Markup Language (APML) <see cref="ISyndicationResource"/> to be filled.</param>
        /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception>
        private void FillApmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata)
        {
            Guard.ArgumentNotNull(resource, "resource");
            Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata");

            ApmlDocument apmlDocument = resource as ApmlDocument;

            if (resourceMetadata.Version == new Version("0.6"))
            {
                Apml06SyndicationResourceAdapter apml06Adapter = new Apml06SyndicationResourceAdapter(this.Navigator, this.Settings);
                apml06Adapter.Fill(apmlDocument);
            }
        }
Пример #7
0
        /// <summary>
        /// Provides example code for the Load(Uri, ICredentials, IWebProxy) method
        /// </summary>
        public static void LoadUriExample()
        {
            ApmlDocument document = new ApmlDocument();
            Uri          source   = new Uri("http://aura.darkstar.sunlabs.com/AttentionProfile/apml/web/Oppositional");

            document.Load(source, CredentialCache.DefaultNetworkCredentials, null);

            foreach (ApmlProfile profile in document.Profiles)
            {
                if (profile.Name == document.DefaultProfileName)
                {
                    //  Perform some processing on the attention profile
                    break;
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Provides example code for the Save(XmlWriter) method
        /// </summary>
        public static void SaveXmlWriterExample()
        {
            ApmlDocument document = new ApmlDocument();

            //  Modify document state using public properties and methods

            using (Stream stream = new FileStream("ApmlDocument.xml", FileMode.Create, FileAccess.Write))
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;

                using (XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    document.Save(writer);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Provides example code for the Load(IXPathNavigable) method
        /// </summary>
        public static void LoadIXPathNavigableExample()
        {
            XPathDocument source = new XPathDocument("http://aura.darkstar.sunlabs.com/AttentionProfile/apml/web/Oppositional");

            ApmlDocument document = new ApmlDocument();

            document.Load(source);

            foreach (ApmlProfile profile in document.Profiles)
            {
                if (profile.Name == document.DefaultProfileName)
                {
                    //  Perform some processing on the attention profile
                    break;
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Provides example code for the Load(Stream) method
        /// </summary>
        public static void LoadStreamExample()
        {
            ApmlDocument document = new ApmlDocument();

            using (Stream stream = new FileStream("ApmlDocument.xml", FileMode.Open, FileAccess.Read))
            {
                document.Load(stream);

                foreach (ApmlProfile profile in document.Profiles)
                {
                    if (profile.Name == document.DefaultProfileName)
                    {
                        //  Perform some processing on the attention profile
                        break;
                    }
                }
            }
        }
        //============================================================
        //	PRIVATE METHODS
        //============================================================
        #region FillApmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata)
        /// <summary>
        /// Modifies the <see cref="ISyndicationResource"/> to match the data source.
        /// </summary>
        /// <param name="resource">The Attention Profiling Markup Language (APML) <see cref="ISyndicationResource"/> to be filled.</param>
        /// <param name="resourceMetadata">A <see cref="SyndicationResourceMetadata"/> object that represents the meta-data describing the <paramref name="resource"/>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="resourceMetadata"/> is a null reference (Nothing in Visual Basic).</exception>
        private void FillApmlResource(ISyndicationResource resource, SyndicationResourceMetadata resourceMetadata)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");
            Guard.ArgumentNotNull(resourceMetadata, "resourceMetadata");

            //------------------------------------------------------------
            //	Fill syndication resource using appropriate data adapter
            //------------------------------------------------------------
            ApmlDocument apmlDocument = resource as ApmlDocument;

            if (resourceMetadata.Version == new Version("0.6"))
            {
                Apml06SyndicationResourceAdapter apml06Adapter = new Apml06SyndicationResourceAdapter(this.Navigator, this.Settings);
                apml06Adapter.Fill(apmlDocument);
            }
        }
Пример #12
0
        /// <summary>
        /// Instantiates a <see cref="ISyndicationResource"/> that conforms to the specified <see cref="SyndicationContentFormat"/> using the supplied <see cref="Stream"/>.
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> used to load the syndication resource.</param>
        /// <param name="format">A <see cref="SyndicationContentFormat"/> enumeration value that indicates the type syndication resource the <paramref name="stream"/> represents.</param>
        /// <returns>
        ///     An <see cref="ISyndicationResource"/> object that conforms to the specified <paramref name="format"/>, initialized using the supplied <paramref name="stream"/>.
        ///     If the <paramref name="format"/> is not supported by the provider, returns a <b>null</b> reference.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception>
        private static ISyndicationResource BuildResource(SyndicationContentFormat format, Stream stream)
        {
            Guard.ArgumentNotNull(stream, "stream");

            if (format == SyndicationContentFormat.Apml)
            {
                ApmlDocument document = new ApmlDocument();
                document.Load(stream);
                return(document);
            }
            else if (format == SyndicationContentFormat.Atom)
            {
                XPathDocument  document  = new XPathDocument(stream);
                XPathNavigator navigator = document.CreateNavigator();
                navigator.MoveToRoot();
                navigator.MoveToChild(XPathNodeType.Element);

                if (String.Compare(navigator.LocalName, "entry", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AtomEntry entry = new AtomEntry();
                    entry.Load(navigator);
                    return(entry);
                }
                else if (String.Compare(navigator.LocalName, "feed", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AtomFeed feed = new AtomFeed();
                    feed.Load(navigator);
                    return(feed);
                }
                else
                {
                    return(null);
                }
            }
            else if (format == SyndicationContentFormat.BlogML)
            {
                BlogMLDocument document = new BlogMLDocument();
                document.Load(stream);
                return(document);
            }
            else if (format == SyndicationContentFormat.Opml)
            {
                OpmlDocument document = new OpmlDocument();
                document.Load(stream);
                return(document);
            }
            else if (format == SyndicationContentFormat.Rsd)
            {
                RsdDocument document = new RsdDocument();
                document.Load(stream);
                return(document);
            }
            else if (format == SyndicationContentFormat.Rss)
            {
                RssFeed feed = new RssFeed();
                feed.Load(stream);
                return(feed);
            }
            else
            {
                return(null);
            }
        }
Пример #13
0
        /// <summary>
        /// Provides example code for the ApmlDocument class.
        /// </summary>
        public static void ClassExample()
        {
            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);

            ApmlProfile homeProfile = new ApmlProfile();

            homeProfile.Name = "Home";

            //  Provide the implicit data associated with this profile
            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);

            //  Provide the explicit data associated with this profile
            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);

            ApmlProfile workProfile = new ApmlProfile();

            workProfile.Name = "Work";

            //  Provide the explicit data associated with this profile
            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);
        }
        /// <summary>
        /// Returns a date-time indicating the most recent instant in time when the resource was last modified.
        /// </summary>
        /// <param name="resource">The <see cref="ISyndicationResource"/> to determine the modification date for.</param>
        /// <returns>
        ///     A <see cref="DateTime"/> indicating the most recent instant in time when the <see cref="ISyndicationResource"/> was last modified.
        ///     If the <see cref="ISyndicationResource"/> conforms to a format that does not support modification tracking, or if otherwise unable
        ///     to determine the modification date, returns <see cref="DateTime.MinValue"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        private static DateTime GetLastModificationDate(ISyndicationResource resource)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            DateTime lastModifiedOn = DateTime.MinValue;

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

            //------------------------------------------------------------
            //	Determine modification date based on format specific details
            //------------------------------------------------------------
            switch (resource.Format)
            {
            case SyndicationContentFormat.Apml:
                ApmlDocument apmlDocument = resource as ApmlDocument;
                if (apmlDocument != null && apmlDocument.Head != null)
                {
                    lastModifiedOn = apmlDocument.Head.CreatedOn;
                }
                break;

            case SyndicationContentFormat.Atom:
                XPathNavigator rootNavigator = resource.CreateNavigator();
                if (String.Compare(rootNavigator.LocalName, "entry", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AtomEntry entry = resource as AtomEntry;
                    if (entry != null)
                    {
                        lastModifiedOn = entry.UpdatedOn;
                    }
                }
                else if (String.Compare(rootNavigator.LocalName, "feed", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AtomFeed atomFeed = resource as AtomFeed;
                    if (atomFeed != null)
                    {
                        lastModifiedOn = atomFeed.UpdatedOn;
                    }
                }
                break;

            case SyndicationContentFormat.BlogML:
                BlogMLDocument blogDocument = resource as BlogMLDocument;
                if (blogDocument != null)
                {
                    lastModifiedOn = blogDocument.GeneratedOn;
                }
                break;

            case SyndicationContentFormat.Opml:
                OpmlDocument opmlDocument = resource as OpmlDocument;
                if (opmlDocument != null && opmlDocument.Head != null)
                {
                    lastModifiedOn = opmlDocument.Head.ModifiedOn;
                }
                break;

            case SyndicationContentFormat.Rsd:
                //  RSD 1.0 does not provide last modified information
                lastModifiedOn = DateTime.MinValue;
                break;

            case SyndicationContentFormat.Rss:
                RssFeed rssFeed = resource as RssFeed;
                if (rssFeed != null && rssFeed.Channel != null)
                {
                    lastModifiedOn = rssFeed.Channel.LastBuildDate;
                }
                break;

            default:
                lastModifiedOn = DateTime.MinValue;
                break;
            }

            return(lastModifiedOn);
        }
Пример #15
0
        /// <summary>
        /// Modifies the <see cref="ApmlDocument"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="ApmlDocument"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(ApmlDocument resource)
        {
            Guard.ArgumentNotNull(resource, "resource");

            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(this.Navigator.NameTable);

            XPathNavigator headNavigator = this.Navigator.SelectSingleNode("apml:APML/apml:Head", manager);

            if (headNavigator != null)
            {
                resource.Head.Load(headNavigator, this.Settings);
            }

            XPathNavigator bodyNavigator = this.Navigator.SelectSingleNode("apml:APML/apml:Body", manager);

            if (bodyNavigator != null)
            {
                if (bodyNavigator.HasAttributes)
                {
                    string defaultProfileAttribute = bodyNavigator.GetAttribute("defaultprofile", String.Empty);
                    if (!String.IsNullOrEmpty(defaultProfileAttribute))
                    {
                        resource.DefaultProfileName = defaultProfileAttribute;
                    }
                }

                XPathNodeIterator profileIterator = bodyNavigator.Select("apml:Profile", manager);
                if (profileIterator != null && profileIterator.Count > 0)
                {
                    int counter = 0;
                    while (profileIterator.MoveNext())
                    {
                        ApmlProfile profile = new ApmlProfile();
                        counter++;

                        if (profile.Load(profileIterator.Current, this.Settings))
                        {
                            if (this.Settings.RetrievalLimit != 0 && counter > this.Settings.RetrievalLimit)
                            {
                                break;
                            }

                            ((Collection <ApmlProfile>)resource.Profiles).Add(profile);
                        }
                    }
                }

                XPathNodeIterator applicationIterator = bodyNavigator.Select("apml:Applications/apml:Application", manager);
                if (applicationIterator != null && applicationIterator.Count > 0)
                {
                    while (applicationIterator.MoveNext())
                    {
                        ApmlApplication application = new ApmlApplication();
                        if (application.Load(applicationIterator.Current, this.Settings))
                        {
                            resource.Applications.Add(application);
                        }
                    }
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(this.Navigator.SelectSingleNode("apml:APML", manager), this.Settings);

            adapter.Fill(resource, manager);
        }