Temporary class for transmitting FOAF attributes
Ejemplo n.º 1
0
        /// <summary>
        /// Write a FOAF:Person and any friends to the output stream
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="person">The person.</param>
        private void WriteFoafPerson(XmlWriter writer, FoafPerson person)
        {
            writer.WriteStartElement("foaf", "Person", null);

            // if (person.ID != "")
            // {
            // writer.WriteAttributeString("rdf", "ID", null, person.ID);
            // }
            writer.WriteElementString("foaf", "name", null, person.Name);
            if (person.Title != string.Empty)
            {
                writer.WriteElementString("foaf", "title", null, person.Title);
            }

            if (person.Firstname != string.Empty)
            {
                writer.WriteElementString("foaf", "givenname", null, person.Firstname);
            }

            if (person.Lastname != string.Empty)
            {
                writer.WriteElementString("foaf", "family_name", null, person.Lastname);
            }

            if (!string.IsNullOrEmpty(person.Email))
            {
                writer.WriteElementString("foaf", "mbox_sha1sum", null, CalculateSha1(person.Email, Encoding.UTF8));
            }

            if (!string.IsNullOrEmpty(person.Homepage))
            {
                writer.WriteStartElement("foaf", "homepage", null);
                writer.WriteAttributeString("rdf", "resource", null, person.Homepage);
                writer.WriteEndElement();
            }

            if (!string.IsNullOrEmpty(person.Blog))
            {
                writer.WriteStartElement("foaf", "weblog", null);
                writer.WriteAttributeString("rdf", "resource", null, person.Blog);
                writer.WriteEndElement();
            }

            if (person.Rdf != string.Empty && person.Rdf != HttpContext.Current.Request.Url.ToString())
            {
                writer.WriteStartElement("rdfs", "seeAlso", null);
                writer.WriteAttributeString("rdf", "resource", null, person.Rdf);
                writer.WriteEndElement();
            }

            if (!string.IsNullOrEmpty(person.Birthday))
            {
                writer.WriteElementString("foaf", "birthday", null, person.Birthday);
            }

            if (!string.IsNullOrEmpty(person.PhotoUrl))
            {
                writer.WriteStartElement("foaf", "depiction", null);
                writer.WriteAttributeString("rdf", "resource", null, person.PhotoUrl);
                writer.WriteEndElement();
            }

            if (!string.IsNullOrEmpty(person.Phone))
            {
                writer.WriteElementString("foaf", "phone", null, person.Phone);
            }

            if (person.Friends != null && person.Friends.Count > 0)
            {
                foreach (var friend in person.Friends)
                {
                    writer.WriteStartElement("foaf", "knows", null);

                    this.WriteFoafPerson(writer, friend);

                    writer.WriteEndElement(); // foaf:knows
                }
            }

            writer.WriteEndElement(); // foaf:Person
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the FOAF.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="name">
        /// The name of the FOAF.
        /// </param>
        private void WriteFoaf(HttpContext context, string name)
        {
            // begin FOAF
            var writer = GetWriter(context.Response.OutputStream);

            // write DOCUMENT
            writer.WriteStartElement("foaf", "PersonalProfileDocument", null);
            writer.WriteAttributeString("rdf", "about", null, string.Empty);
            writer.WriteStartElement("foaf", "maker", null);
            writer.WriteAttributeString("rdf", "resource", null, "#me");
            writer.WriteEndElement(); // foaf:maker
            writer.WriteStartElement("foaf", "primaryTopic", null);
            writer.WriteAttributeString("rdf", "resource", null, "#me");
            writer.WriteEndElement(); // foaf:primaryTopic
            writer.WriteEndElement(); // foaf:PersonalProfileDocument

            // get main person's data
            var ap = AuthorProfile.GetProfile(name);

            if (!ap.Private)
            {
                // main author object
                var me = new FoafPerson("#me", ap)
                {
                    Friends = new List <FoafPerson>()
                };

                // TODO: this really should be it's own data store

                // assume all other authors are friends
                foreach (var user in
                         Membership.GetAllUsers().Cast <MembershipUser>().Where(
                             user => !user.UserName.Equals(name, StringComparison.OrdinalIgnoreCase)))
                {
                    var friend = AuthorProfile.GetProfile(user.UserName);
                    if (friend == null)
                    {
                        continue;
                    }

                    me.Friends.Add(new FoafPerson("#" + user.UserName, friend));
                }

                // assume blog roll = friends
                foreach (var br in BlogRollItem.BlogRolls)
                {
                    var title = br.Title;
                    var url   = br.BlogUrl.ToString();

                    var foaf = new FoafPerson(title)
                    {
                        Name = title, Blog = url
                    };

                    if (context.Cache[string.Format("foaf:{0}", title)] == null)
                    {
                        var docs = Utils.FindSemanticDocuments(new Uri(url), "foaf");
                        if (docs.Count > 0)
                        {
                            foreach (var key in docs.Keys)
                            {
                                context.Cache.Insert(string.Format("foaf:{0}", title), key.ToString());
                                break;
                            }
                        }
                        else
                        {
                            context.Cache.Insert(string.Format("foaf:{0}", title), "0");
                        }
                    }

                    var seeAlso = (string)context.Cache[string.Format("foaf:{0}", title)];
                    if (seeAlso != null && seeAlso.Contains("://"))
                    {
                        foaf.Rdf = seeAlso;
                    }

                    me.Friends.Add(foaf);
                }

                // begin writing FOAF Persons
                this.WriteFoafPerson(writer, me);
            }

            CloseWriter(writer);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Write a FOAF:Person and any friends to the output stream
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="person">The person.</param>
        private void WriteFoafPerson(XmlWriter writer, FoafPerson person)
        {
            writer.WriteStartElement("foaf", "Person", null);

            // if (person.ID != "")
            // {
            // writer.WriteAttributeString("rdf", "ID", null, person.ID);
            // }
            writer.WriteElementString("foaf", "name", null, person.Name);
            if (person.Title != string.Empty)
            {
                writer.WriteElementString("foaf", "title", null, person.Title);
            }

            if (person.Firstname != string.Empty)
            {
                writer.WriteElementString("foaf", "givenname", null, person.Firstname);
            }

            if (person.Lastname != string.Empty)
            {
                writer.WriteElementString("foaf", "family_name", null, person.Lastname);
            }

            if (!string.IsNullOrEmpty(person.Email))
            {
                writer.WriteElementString("foaf", "mbox_sha1sum", null, CalculateSha1(person.Email, Encoding.UTF8));
            }

            if (!string.IsNullOrEmpty(person.Homepage))
            {
                writer.WriteStartElement("foaf", "homepage", null);
                writer.WriteAttributeString("rdf", "resource", null, person.Homepage);
                writer.WriteEndElement();
            }

            if (!string.IsNullOrEmpty(person.Blog))
            {
                writer.WriteStartElement("foaf", "weblog", null);
                writer.WriteAttributeString("rdf", "resource", null, person.Blog);
                writer.WriteEndElement();
            }

            if (person.Rdf != string.Empty && person.Rdf != HttpContext.Current.Request.Url.ToString())
            {
                writer.WriteStartElement("rdfs", "seeAlso", null);
                writer.WriteAttributeString("rdf", "resource", null, person.Rdf);
                writer.WriteEndElement();
            }

            if (!string.IsNullOrEmpty(person.Birthday))
            {
                writer.WriteElementString("foaf", "birthday", null, person.Birthday);
            }

            if (!string.IsNullOrEmpty(person.PhotoUrl))
            {
                writer.WriteStartElement("foaf", "depiction", null);
                writer.WriteAttributeString("rdf", "resource", null, person.PhotoUrl);
                writer.WriteEndElement();
            }

            if (!string.IsNullOrEmpty(person.Phone))
            {
                writer.WriteElementString("foaf", "phone", null, person.Phone);
            }

            if (person.Friends != null && person.Friends.Count > 0)
            {
                foreach (var friend in person.Friends)
                {
                    writer.WriteStartElement("foaf", "knows", null);

                    this.WriteFoafPerson(writer, friend);

                    writer.WriteEndElement(); // foaf:knows
                }
            }

            writer.WriteEndElement(); // foaf:Person
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes the FOAF.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="name">
        /// The name of the FOAF.
        /// </param>
        private void WriteFoaf(HttpContext context, string name)
        {
            // begin FOAF
            var writer = GetWriter(context.Response.OutputStream);

            // write DOCUMENT
            writer.WriteStartElement("foaf", "PersonalProfileDocument", null);
            writer.WriteAttributeString("rdf", "about", null, string.Empty);
            writer.WriteStartElement("foaf", "maker", null);
            writer.WriteAttributeString("rdf", "resource", null, "#me");
            writer.WriteEndElement(); // foaf:maker
            writer.WriteStartElement("foaf", "primaryTopic", null);
            writer.WriteAttributeString("rdf", "resource", null, "#me");
            writer.WriteEndElement(); // foaf:primaryTopic
            writer.WriteEndElement(); // foaf:PersonalProfileDocument

            // get main person's data
            var ap = AuthorProfile.GetProfile(name);

            if (!ap.Private)
            {
                // main author object
                var me = new FoafPerson("#me", ap) { Friends = new List<FoafPerson>() };

                // TODO: this really should be it's own data store

                // assume all other authors are friends
                foreach (var user in
                    Membership.GetAllUsers().Cast<MembershipUser>().Where(
                        user => !user.UserName.Equals(name, StringComparison.OrdinalIgnoreCase)))
                {
                    var friend = AuthorProfile.GetProfile(user.UserName);
                    if (friend == null)
                    {
                        continue;
                    }

                    me.Friends.Add(new FoafPerson("#" + user.UserName, friend));
                }

                // assume blog roll = friends
                var blogroll = new Data.ViewModels.BlogRollVM();
                foreach (var br in blogroll.BlogRolls)
                {
                    var title = br.Title;
                    var url = br.BlogUrl.ToString();

                    var foaf = new FoafPerson(title) { Name = title, Blog = url };

                    if (Blog.CurrentInstance.Cache[string.Format("foaf:{0}", title)] == null)
                    {
                        var docs = Utils.FindSemanticDocuments(new Uri(url), "foaf");
                        if (docs.Count > 0)
                        {
                            foreach (var key in docs.Keys)
                            {
                                Blog.CurrentInstance.Cache.Insert(string.Format("foaf:{0}", title), key.ToString());
                                break;
                            }
                        }
                        else
                        {
                            Blog.CurrentInstance.Cache.Insert(string.Format("foaf:{0}", title), "0");
                        }
                    }

                    var seeAlso = (string)Blog.CurrentInstance.Cache[string.Format("foaf:{0}", title)];
                    if (seeAlso != null && seeAlso.Contains("://"))
                    {
                        foaf.Rdf = seeAlso;
                    }

                    me.Friends.Add(foaf);
                }

                // begin writing FOAF Persons
                this.WriteFoafPerson(writer, me);
            }

            CloseWriter(writer);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes FOAF data to the output stream
        /// </summary>
        /// <param name="context"></param>
        /// <param name="name"></param>
        private void WriteFoaf(HttpContext context, string name)
        {
            // begin FOAF
            XmlWriter writer = GetWriter(context.Response.OutputStream);

            // write DOCUMENT
            writer.WriteStartElement("foaf", "PersonalProfileDocument", null);
            writer.WriteAttributeString("rdf", "about", null, "");
            writer.WriteStartElement("foaf", "maker", null);
            writer.WriteAttributeString("rdf", "resource", null, "#me");
            writer.WriteEndElement();             // foaf:maker
            writer.WriteStartElement("foaf", "primaryTopic", null);
            writer.WriteAttributeString("rdf", "resource", null, "#me");
            writer.WriteEndElement();             // foaf:primaryTopic
            writer.WriteEndElement();             // foaf:PersonalProfileDocument


            // get main person's data
            AuthorProfile ap = AuthorProfile.GetProfile(name);

            if (!ap.IsPrivate)
            {
                // main author object
                FoafPerson me = new FoafPerson("#me", ap);
                me.Friends = new List <FoafPerson>();


                // TODO: this really should be it's own data store

                // assume all other authors are friends
                foreach (MembershipUser user in Membership.GetAllUsers())
                {
                    if (!user.UserName.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        AuthorProfile friend = AuthorProfile.GetProfile(user.UserName);
                        if (friend != null)
                        {
                            me.Friends.Add(new FoafPerson("#" + user.UserName, friend));
                        }
                    }
                }

                // assume blog roll = friends
                foreach (BlogRollItem br in BlogRollItem.BlogRolls)
                {
                    string title = br.Title;
                    string url   = br.BlogUrl.ToString();

                    FoafPerson foaf = new FoafPerson(title);
                    foaf.Name = title;
                    foaf.Blog = url;

                    if (context.Cache["foaf:" + title] == null)
                    {
                        Dictionary <Uri, XmlDocument> docs = Utils.FindSemanticDocuments(new Uri(url), "foaf");
                        if (docs.Count > 0)
                        {
                            foreach (Uri key in docs.Keys)
                            {
                                context.Cache.Insert("foaf:" + title, key.ToString());
                                break;
                            }
                        }
                        else
                        {
                            context.Cache.Insert("foaf:" + title, "0");
                        }
                    }

                    string seeAlso = (string)context.Cache["foaf:" + title];
                    if (seeAlso != null && seeAlso.Contains("://"))
                    {
                        foaf.Rdf = seeAlso;
                    }

                    me.Friends.Add(foaf);
                }


                // begin writing FOAF Persons
                WriteFoafPerson(writer, me);
            }
            CloseWriter(writer);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Writes FOAF data to the output stream
        /// </summary>
        /// <param name="context"></param>
        /// <param name="name"></param>
        private void WriteFoaf(HttpContext context, string name)
        {
            // begin FOAF
            XmlWriter writer = GetWriter(context.Response.OutputStream);

            // write DOCUMENT
            writer.WriteStartElement("foaf", "PersonalProfileDocument", null);
            writer.WriteAttributeString("rdf", "about", null, "");
            writer.WriteStartElement("foaf", "maker", null);
            writer.WriteAttributeString("rdf", "resource", null, "#me");
            writer.WriteEndElement(); // foaf:maker
            writer.WriteStartElement("foaf", "primaryTopic", null);
            writer.WriteAttributeString("rdf", "resource", null, "#me");
            writer.WriteEndElement(); // foaf:primaryTopic
            writer.WriteEndElement();  // foaf:PersonalProfileDocument

            // get main person's data
            AuthorProfile ap = AuthorProfile.GetProfile(name);

            if (!ap.IsPrivate)
            {

                // main author object
                FoafPerson me = new FoafPerson("#me", ap);
                me.Friends = new List<FoafPerson>();

                // TODO: this really should be it's own data store

                // assume all other authors are friends
                foreach (MembershipUser user in Membership.GetAllUsers())
                {
                    if (!user.UserName.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        AuthorProfile friend = AuthorProfile.GetProfile(user.UserName);
                        if (friend != null)
                        {
                                me.Friends.Add(new FoafPerson("#" + user.UserName, friend));
                        }
                    }
                }

                // assume blog roll = friends
                foreach (BlogRollItem br in BlogRollItem.BlogRolls)
                {
                    string title = br.Title;
                    string url = br.BlogUrl.ToString();

                    FoafPerson foaf = new FoafPerson(title);
                    foaf.Name = title;
                    foaf.Blog = url;

                    if (context.Cache["foaf:" + title] == null)
                    {
                        Dictionary<Uri, XmlDocument> docs = Utils.FindSemanticDocuments(new Uri(url), "foaf");
                        if (docs.Count > 0)
                        {
                            foreach (Uri key in docs.Keys)
                            {
                                context.Cache.Insert("foaf:" + title, key.ToString());
                                break;
                            }
                        }
                        else
                        {
                            context.Cache.Insert("foaf:" + title, "0");
                        }
                    }

                    string seeAlso = (string)context.Cache["foaf:" + title];
                    if (seeAlso != null && seeAlso.Contains("://"))
                        foaf.Rdf = seeAlso;

                    me.Friends.Add(foaf);
                }

                // begin writing FOAF Persons
                WriteFoafPerson(writer, me);
            }
            CloseWriter(writer);
        }