Example #1
0
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (this.UserName != null)
            {
                Author a = DataBroker.GetAuthor(this.UserName);
                if (a == null)
                {
                    a = new Author();
                    a.DisplayName = this.UserName;
                }

                this.DoLink = a.ID != Guid.Empty;

                //if (this.DoLink)
                //{
                    this.ContentPath = "/authors";
                    this.ContentPathExtra = "/" + HttpContext.Current.Server.UrlEncode(this.UserName.ToLower());
                //}

                if (this.Text == null || this.Text.Length == 0)
                {
                    this.Text = (a.ID != Guid.Empty) ? a.DisplayName : this.UserName;
                }
            }
            base.Render(writer);
        }
Example #2
0
 /// <summary>
 /// Retrieves a list of authors from an array of names.  If there is no author for an associated name, 
 /// a new author instance is created
 /// (but not saved) and added to the list.  If a resulting DisplayName is blank, it's set to the username.
 /// </summary>
 /// <param name="names">An array of author usernames</param>
 /// <returns>A list of authors, including usernames that didn't return a corresponding author.</returns>
 public static List<Author> GetAuthors(params string[] names)
 {
     List<Author> authors = new List<Author>();
     foreach (string a in names)
     {
         Author author = Author.FindFirst(a);
         if (author == null)
         {
             author = new Author();
             author.UserName = a;
         }
         if (author.DisplayName == null) author.DisplayName = author.UserName;
         authors.Add(author);
     }
     return authors;
 }
Example #3
0
 public static Author GetAuthor(string name)
 {
     string displayName = name;
     name = name.ToLower();
     string key = string.Concat("Author[", name, "]");
     Author a = null;
     try
     {
         using (dbLock.Lock(key))
         {
             a = CacheBroker.Get(key) as Author;
             if (a == null)
             {
                 a = Author.FindFirst(name);
                 if (a == null)
                 {
                     a = new Author();
                     a.ID = Guid.Empty;
                 }
                 Cache(a, key);
             }
         }
     }
     catch (NamedLock<string>.TimeoutException)
     {
         log.InfoFormat("Author lock timed out: {0}", key);
     }
     if(a == null) a = new Author();
     if (a.ID == Guid.Empty)
     {
         a = new Author();
         a.UserName = name;
         a.DisplayName = displayName;
     }
     return a;
 }