public PersonInfo AddNewPersonOrUpdate(string personName, string account, EAccountType accountType, EPersonNameTrust trust)
        {
            lock (_lockObj)
            {
                PersonInfo person = null;
                if (IsKnownAccount(account, accountType))
                {
                    person = GetPerson(account, accountType);
                    Debug.Assert(person != null, String.Format("PersonInfo is null. The account {0} does not seem to be associated with a contact.", account));
                    person.SetName(personName, trust);
                }
                else
                {
                    Debug.Assert(!String.IsNullOrEmpty(personName), String.Format("Invalid name for the contact with account {0}. Empty name is not valid.", account));
                    Debug.Assert(!String.IsNullOrEmpty(account), String.Format("Invalid account name for contact {0}. Empty account name is not valid.", personName));
                    Debug.Assert(!IsKnownAccount(account, accountType), "The account is already associated with a person.");
                    //Trace.WriteLineIf(account.ToLower() != account, String.Format("!!! Warning: added account {0} was not in lower case. Did you forget to put it in lower case?", account));

                    person = new PersonInfo(MailData, personName, trust);
                    _personIdToPerson[person.PersonId] = person;
                    AssignAccount(account, accountType, person);
                }

                return person;
            }
        }
 public PersonInfo(MailData mailData, string name, EPersonNameTrust nameTrust)
 {
     _mailData = mailData;
     _peopleData = mailData.PeopleData;
     PersonId = _peopleData.SQLAddPerson();
     SetName(name, nameTrust);
 }
 public bool SetName(string name, EPersonNameTrust nameTrust, bool save = true)
 {
     if (String.IsNullOrEmpty(name)) return false;
     if (nameTrust == this.NameTrust && name == Name) return false;
     if (nameTrust >= this.NameTrust)
     {
         Name = name;
         NameTrust = nameTrust;
         if (save)
             SaveContact();
     }
     return true;
 }
 //private string GetNodeInnerHtml(HtmlNode node, string xpath, string noneValue = null)
 //{
 //    var n = node.SelectSingleNode(xpath);
 //    if (n != null)
 //        return n.InnerHtml;
 //    return noneValue;
 //}
 private string GetXmlForPerson(string author, string authorUri, string role = "from", EAccountType type = EAccountType.Custom, EPersonNameTrust trust = EPersonNameTrust.Low)
 {
     if (string.IsNullOrEmpty(author) || string.IsNullOrEmpty(authorUri)) {
         AddEvent(String.Format("Didn't find valid values for person. Name={0}, Uri={1}. Ignoring the person", author, authorUri));
         return "";
     }
     return Templates.BuildPerson(authorUri, author, role, type, trust);
 }
 public static string BuildSetDataNewPersonName(int personId, string newName, EPersonNameTrust nameTrust)
 {
     return String.Format("<data target=\"PeopleData\" content=\"NewName\" personId=\"{0}\" newName=\"{1}\" nameTrust=\"{2}\" />", personId, newName.EncodeXMLString(), (int)nameTrust);
 }
 public static string BuildSetDataAddPerson(string personName, string account, EAccountType accountType, EPersonNameTrust nameTrust)
 {
     return String.Format("<data target=\"PeopleData\" content=\"AddPerson\" personName=\"{0}\" account=\"{1}\" accountType=\"{2}\" nameTrust=\"{3}\" />", personName.EncodeXMLString(), account.EncodeXMLString(), (int)accountType, (int)nameTrust);
 }
 public static string BuildPerson(string account, string name, string role, EAccountType accountType, EPersonNameTrust nameTrust)
 {
     Debug.Assert(!string.IsNullOrEmpty(account));
     Debug.Assert(name != null);
     return String.Format("<person account=\"{0}\" name=\"{1}\" role=\"{2}\" accountType=\"{3}\" nameTrust=\"{4}\" />", account.EncodeXMLString(), name.EncodeXMLString(), role, (int)accountType, (int)nameTrust);
 }