Пример #1
0
 public static void AddToBlockedContacts(ContactItem c)
 {
     bool added = false;
     int retries = 0;
     do
     {
         try
         {
             StreamWriter sw = new StreamWriter(GoogleMutexFile,true);
             try
             {
                 sw.WriteLine(c.FullName+ "," + c.Email1Address+","+c.Email2Address+","+c.Email3Address);
             }
             finally
             {
                 sw.Close();
             }
             added = true;
         }
         catch (System.Exception)
         {
             System.Threading.Thread.Sleep(500);
             retries++;
         }
     } while (!added && retries <= 3);
 }
 public void Replace (ContactItem inner)
 {
   if (inner != Inner)
   {
     DisposeInner();
     Inner = inner;
   }
 }
 public void SaveAndReload()
 {
   Inner.Save();
   var entryId = Inner.EntryID;
   DisposeInner();
   Thread.MemoryBarrier();
   Inner = _load (entryId);
 }
Пример #4
0
        public WrappedContactItem(ContactItem c)
        {
            item = c;

            ((ItemEvents_10_Event)item).Open += WrappedContactItem_Open;
            ((ItemEvents_10_Event)item).Close += WrappedContactItem_Close;
            ((ItemEvents_10_Event)item).Write += WrappedContactItem_Write; //this is the save event
        }
Пример #5
0
 public SkypeContactDetailItem(ContactItem owner, string handle)
 {
     this.Handle = handle;
     this.status = Skype.ContactStatus (this.Handle);
     //if offline was returned, query to see if the user has a phone number set, maybe the user's status is really "SKYPEOUT"
     if (this.status == Skype.Statuses [OnlineStatus.Offline]) {
         foreach (string detail in owner.Details.Where (d => d.Contains ("phone"))) {
             Console.WriteLine ("Checking {0} :: {1}", detail, owner [detail]);
             if (Skype.ContactStatus (Skype.StripPhoneChars (owner [detail])) == Skype.Statuses [OnlineStatus.SkypeOut])
                 this.status = Skype.Statuses [OnlineStatus.SkypeOut];
         }
     }
 }
Пример #6
0
		void loadContact()
		{
			int contactID = Intent.GetIntExtra("ContactID", 0);
			if (contactID > 0)
			{
				contact = ContactManager.GetContact(contactID);
				nameEdit.Text = contact.Name;
				surnameEdit.Text = contact.Surname;
				numberEdit.Text = contact.Number;
			}
			else
			{
				contact = new ContactItem();
			}
		}
Пример #7
0
 public ContactItem GetItem(int id)
 {
     var t = new ContactItem ();
     lock (locker)
     {
         connection = new SqliteConnection ("Data Source=" + path);
         connection.Open ();
         using (var command = connection.CreateCommand ())
         {
             command.CommandText = "SELECT [_id], [Name], [Surname], [Number], [Path] from [Items] WHERE [_id] = ?";
             command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = id });
             var r = command.ExecuteReader ();
             while (r.Read ())
             {
                 t = FromReader (r);
                 break;
             }
         }
         connection.Close ();
     }
     return t;
 }
Пример #8
0
        public override void UpdateItems()
        {
            items.Clear();

            // iterate over address book files
            foreach (string addressBook in AddressBookFiles)
            {
                try {
                    XmlDocument xmldoc = new XmlDocument();
                    // read adress book by StreamReader. Without: error:Encoding name '...' not supported
                    using (StreamReader reader = new StreamReader(addressBook)) {
                        xmldoc.Load(reader);
                    }

                    XmlNodeList people = xmldoc.SelectNodes("/address-book/person");
                    if (people == null)
                    {
                        continue;
                    }

                    foreach (XmlNode person in people)
                    {
                        // contact name from "cn" attribute
                        string personCn = person.Attributes ["cn"].InnerText;
                        if (string.IsNullOrEmpty(personCn))
                        {
                            continue;
                        }

                        // load emails
                        XmlNodeList addresses = person.SelectNodes("address-list/address");
                        if ((addresses == null) || (addresses.Count == 0))                           // no childs == no emails -> skip
                        {
                            continue;
                        }

                        ContactItem buddy        = ContactItem.CreateWithName(personCn);
                        int         emailCounter = 0;

                        foreach (XmlNode address in addresses)
                        {
                            string email = address.Attributes ["email"].InnerText;
                            if (!string.IsNullOrEmpty(email))
                            {
                                string remarks = address.Attributes ["remarks"].InnerText;
                                string id      = ClawsKeyPrefix + emailCounter + "." + remarks;
                                buddy [id] = email;
                                emailCounter++;
                            }
                        }

                        if (emailCounter > 0)
                        {
                            items.Add(buddy);
                        }
                    }
                } catch (Exception e) {
                    Log.Error("ClawsContactsItemSource: file:{0} error:{1}", addressBook, e.Message);
                    Log.Debug("ClawsContactsItemSource: file:{0}: {1}", addressBook, e.ToString());
                }
            }
        }
Пример #9
0
        private static void MapTelephoneNumber2To1(vCard source, ContactItem target)
        {
            target.HomeTelephoneNumber     = string.Empty;
            target.BusinessTelephoneNumber = string.Empty;

            foreach (var phoneNumber in source.Phones)
            {
                if (phoneNumber.IsMain)
                {
                    target.PrimaryTelephoneNumber = phoneNumber.FullNumber;
                }
                else if (phoneNumber.IsCellular)
                {
                    target.MobileTelephoneNumber = phoneNumber.FullNumber;
                }
                else if (phoneNumber.IsHome && !phoneNumber.IsFax)
                {
                    if (string.IsNullOrEmpty(target.HomeTelephoneNumber))
                    {
                        target.HomeTelephoneNumber = phoneNumber.FullNumber;
                    }
                    else
                    {
                        target.Home2TelephoneNumber = phoneNumber.FullNumber;
                    }
                }
                else if (phoneNumber.IsWork && !phoneNumber.IsFax)
                {
                    if (string.IsNullOrEmpty(target.BusinessTelephoneNumber))
                    {
                        target.BusinessTelephoneNumber = phoneNumber.FullNumber;
                    }
                    else
                    {
                        target.Business2TelephoneNumber = phoneNumber.FullNumber;
                    }
                }
                else if (phoneNumber.IsFax)
                {
                    if (phoneNumber.IsHome)
                    {
                        target.HomeFaxNumber = phoneNumber.FullNumber;
                    }
                    else
                    {
                        target.BusinessFaxNumber = phoneNumber.FullNumber;
                    }
                }
                else if (phoneNumber.IsPager)
                {
                    target.PagerNumber = phoneNumber.FullNumber;
                }
                else if (phoneNumber.IsCar)
                {
                    target.CarTelephoneNumber = phoneNumber.FullNumber;
                }
                else if (phoneNumber.IsISDN)
                {
                    target.ISDNNumber = phoneNumber.FullNumber;
                }
                else
                {
                    if (phoneNumber.IsPreferred && string.IsNullOrEmpty(target.HomeTelephoneNumber))
                    {
                        target.HomeTelephoneNumber = phoneNumber.FullNumber;
                    }
                    else
                    {
                        target.OtherTelephoneNumber = phoneNumber.FullNumber;
                    }
                }
            }
        }
Пример #10
0
        private static void CreateMail(string[] salaryRecord, ContactItem contactItem,
            string[] title, string contentStr, Dictionary<int, long> colorDic)
        {
            var oMail =
                (Microsoft.Office.Interop.Outlook.MailItem)Globals.ThisAddIn.Application.CreateItem(
                    Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            oMail.Subject = "工资条";

            if (contactItem != null)
                oMail.To = contactItem.Email1Address;


            var titleRow = ToTableRow(title, null);
            var salaryRow = ToTableRow(salaryRecord, colorDic);
            var body = new StringBuilder(1024);
            body.Append(string.Format("<h1>{0}</h1>\n", contentStr));
            body.Append("<table border=1><tr>");
            body.Append(titleRow);
            body.Append("</tr><tr>");
            body.Append(salaryRow);
            body.Append("</tr></table>");
            oMail.HTMLBody = body.ToString();
            oMail.DeferredDeliveryTime = DateTime.Now;
            oMail.Save();

            oMail = null;
        }
Пример #11
0
 public static int SaveTask(ContactItem item)
 {
     return me.db.SaveItem(item);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ActionLinkContentResult" /> class.
 /// </summary>
 public ActionLinkContentResult(IActionLinkService actionLinkService, ActionItem action, ContactItem contact, string customUri, ApiController controller)
 {
     ActionLinkService = actionLinkService;
     Action            = action;
     Contact           = contact;
     CustomUri         = customUri;
     Controller        = controller;
 }
 public static string ContactItemDisplay(ContactItem item)
 {
     return item.FullName == null ? item.Email1Address : item.FullName;
 }
 public void getDisplayFromDB(ContactItem contact)
 {
     string photo;
     Log<EmeseneContactItemSource>.Debug ("Tryng to get display from DB for: {0}...", contact["email"]);
     photo = Emesene.get_last_display_picture(contact["email"], false);
     if (photo != "noImage")
     {
         //Log<EmeseneContactItemSource>.Debug ("Display found! in: {0}", photo);
         contact["photo"] = photo;
     }
     else
     {
         //Log<EmeseneContactItemSource>.Debug ("No display picture in DB for: {0}", contact["email"]);
         if(this.lastContact == -1)
         {
             this.lastContact = this.contactsRelation[contact["email"]];
         }
         do
         {
             ContactItem newContact = (ContactItem)this.contacts[lastContact];
             string p = newContact["photo"];
             if(p != "")
             {
                 this.lastContact--;
                 continue;
             }
             //Log<EmeseneContactItemSource>.Debug ("Now tryng to get display from DB for: {0}", newContact["email"]);
             photo = Emesene.get_last_display_picture(newContact["email"], false);
             if (photo != "noImage")
             {
                 //Log<EmeseneContactItemSource>.Debug ("Display found! in: {0}", photo);
                 newContact["photo"] = photo;
                 //Log<EmeseneContactItemSource>.Debug ("Display picture of user: {0} : {1}", newContact["email"], newContact["photo"]);
             }
             else
             {
                 //Log<EmeseneContactItemSource>.Debug ("No display picture in DB for user: {0}", newContact["email"]);
             }
             this.lastContact--;
             //Log<EmeseneContactItemSource>.Debug ("lastContact: {0}", this.lastContact);
         }while(photo == "noImage" && this.lastContact > 0);
     }
 }
Пример #15
0
        /// <summary>
        /// Returns an array of ContactItems
        /// </summary>
        /// <returns>ContactItem[]</returns>
        public ContactItem[] getAllContactItems()
        {
            sqlConnection = null;
            sqlConnection = TimeTableDatabase.getConnection();
            try
            {
                using (sqlConnection)
                {
                    ContactItem SQLItem = new ContactItem();
                    SQLItem.Course = new StudyCourse();
                    SQLItem.Type   = new UserType();
                    List <ContactItem> ContactItemList = new List <ContactItem>();
                    string             SQL             = "SELECT [contactid],[lastname],[firstname],[titel],[mail],[phonenumber],[roomnumber], " +
                                                         "[contact].relationtypid,[relationtyp].relationtypname,[contact].coursetypid,[coursetyp].[shortname],[coursetyp].[longname], [responsibility] " +
                                                         " FROM[contact]" +
                                                         " LEFT JOIN[coursetyp]" +
                                                         " ON[coursetyp].[coursetypid] =[contact].[coursetypid]" +
                                                         " LEFT JOIN[relationtyp]" +
                                                         " ON[relationtyp].[relationtypid] = [contact].relationtypid;";

                    sqlConnection.Open();
                    SqlDataReader myReader  = null;
                    SqlCommand    myCommand = new SqlCommand(SQL, sqlConnection);
                    myReader = myCommand.ExecuteReader();
                    while (myReader.Read())
                    {
                        SQLItem.ContactID = Convert.ToInt32(myReader["contactid"]);
                        SQLItem.FirstName = myReader["firstname"].ToString();
                        SQLItem.LastName  = myReader["lastname"].ToString();
                        SQLItem.Title     = myReader["titel"].ToString();
                        SQLItem.TelNumber = myReader["phonenumber"].ToString();
                        SQLItem.Email     = myReader["mail"].ToString();
                        SQLItem.Room      = myReader["roomnumber"].ToString();

                        SQLItem.Responsibility = myReader["responsibility"].ToString();


                        if (myReader["coursetypid"].ToString() != "")
                        {
                            SQLItem.Course.ID        = Convert.ToInt32(myReader["coursetypid"]);
                            SQLItem.Course.LongText  = myReader["longname"].ToString();
                            SQLItem.Course.ShortText = myReader["shortname"].ToString();
                        }


                        SQLItem.Type.ID   = Convert.ToInt32(myReader["relationtypid"]);
                        SQLItem.Type.Name = myReader["relationtypname"].ToString();


                        ContactItemList.Add(SQLItem);

                        SQLItem        = new ContactItem();
                        SQLItem.Type   = new UserType();
                        SQLItem.Course = new StudyCourse();
                    }
                    sqlConnection.Close();
                    sqlConnection = null;
                    return(ContactItemList.ToArray());
                }
            }
            catch (System.Exception ex)
            {
                return(null);
            }
        }
        //========================================================================================================================================
        //  PRIVATE METHODS
        //========================================================================================================================================
        /// <summary>
        /// This method parses the contacts and builds two strings to store in our ContactItem class. We get the names of the contact
        /// and then loop through their numbers and add an entry for each number.  Because we want to style the output a bit
        /// we use NSMutableAttributedText classes to help style our text to show up the way we want it to. We also check for
        /// each number what type of number it is and assign a prefix to it so that we mimick the way the iOS contacts filter works
        /// on the default iOS messages app.
        /// </summary>
        /// <returns>The contacts.</returns>
        /// <param name="contacts">Contacts.</param>
        private List <ContactItem> parseContacts(List <CNContact> contacts)
        {
            var ContactItemList = new List <ContactItem> ();

            foreach (CNContact contact in contacts)
            {
                var fName        = contact.GivenName;
                var lName        = contact.FamilyName;
                var fullName     = "";
                var number       = "";
                var phoneNumbers = contact.PhoneNumbers.ToList();

                if (String.IsNullOrEmpty(fName))
                {
                    fName = "";
                }
                if (String.IsNullOrEmpty(lName))
                {
                    lName = "";
                }

                fullName = fName + " " + lName;


                foreach (CNLabeledValue <CNPhoneNumber> phoneNumber in phoneNumbers)
                {
                    int range = 0;
                    if (phoneNumber.Label == CNLabelPhoneNumberKey.iPhone)
                    {
                        number = "iPhone: " + (phoneNumber.Value as CNPhoneNumber).StringValue;
                        range  = 7;
                    }
                    else if (phoneNumber.Label == CNLabelPhoneNumberKey.Mobile)
                    {
                        number = "Mobile: " + (phoneNumber.Value as CNPhoneNumber).StringValue;
                        range  = 7;
                    }
                    else if (phoneNumber.Label == CNLabelPhoneNumberKey.Main)
                    {
                        number = "Main: " + (phoneNumber.Value as CNPhoneNumber).StringValue;
                        range  = 5;
                    }
                    else if (phoneNumber.Label == CNLabelPhoneNumberExtd.Home)
                    {
                        number = "Home: " + (phoneNumber.Value as CNPhoneNumber).StringValue;
                        range  = 5;
                    }
                    else
                    {
                        break;
                    }

                    var attributedStringFullName    = new NSMutableAttributedString(fullName);
                    var attributedStringPhoneNumber = new NSMutableAttributedString(number);



                    attributedStringFullName.SetAttributes(new UIStringAttributes()
                    {
                        Font = UIFont.BoldSystemFontOfSize(UIFont.LabelFontSize)
                    }, new NSRange(0, attributedStringFullName.Length));

                    attributedStringPhoneNumber.SetAttributes(new UIStringAttributes()
                    {
                        Font = UIFont.BoldSystemFontOfSize(UIFont.SystemFontSize)
                    }.Dictionary, new NSRange(0, range));

                    var contactItem = new ContactItem(attributedStringFullName, attributedStringPhoneNumber);
                    ContactItemList.Add(contactItem);
                }
            }
            return(ContactItemList);
        }
Пример #17
0
 public OutlookContactInfo(ContactItem item, ContactsSynchronizer sync)
 {
     UserProperties = new UserPropertiesHolder();
     Update(item, sync);
 }
Пример #18
0
 internal static string GetTitleFirstLastAndSuffix(ContactItem outlookContactItem)
 {
     return(GetTitleFirstLastAndSuffix(outlookContactItem.Title, outlookContactItem.FirstName, outlookContactItem.MiddleName, outlookContactItem.LastName, outlookContactItem.Suffix));
 }
Пример #19
0
 public static void Call(ContactItem contact)
 {
     Skype.Call(contact ["handle.skype"]);
 }
        private void CreateData()
        {
            if (this._groupData == null)
            {
                return;
            }
            Group group = this._groupData.group;

            if (!string.IsNullOrEmpty(this._groupData.Activity) || this._groupData.AdminLevel > 1)
            {
                this.InfoSections.Add(new ProfileInfoSectionItem()
                {
                    Items = new List <ProfileInfoItem>()
                    {
                        (ProfileInfoItem) new StatusItem((IProfileData)this._groupData)
                    }
                });
            }
            List <ProfileInfoItem> profileInfoItemList1 = new List <ProfileInfoItem>();

            if (!string.IsNullOrEmpty(group.description))
            {
                profileInfoItemList1.Add((ProfileInfoItem) new CustomItem(CommonResources.ProfilePage_Info_Description, group.description, null, ProfileInfoItemType.RichText));
            }
            if (group.start_date > 0 && group.GroupType == GroupType.Event)
            {
                profileInfoItemList1.Add((ProfileInfoItem) new CustomItem(CommonResources.ProfilePage_Info_StartDate, UIStringFormatterHelper.FormatDateTimeForUI(group.start_date), (Action)(() => this.CreateAppointment(group.start_date, group.finish_date, group.name, group.place != null ? group.place.address : "")), ProfileInfoItemType.RichText));
            }
            if (group.finish_date > 0)
            {
                profileInfoItemList1.Add((ProfileInfoItem) new CustomItem(CommonResources.ProfilePage_Info_FinishDate, UIStringFormatterHelper.FormatDateTimeForUI(group.finish_date), (Action)(() => this.CreateAppointment(group.start_date, group.finish_date, group.name, group.place != null ? group.place.address : "")), ProfileInfoItemType.RichText));
            }
            string description = "";

            if (group.place != null && !string.IsNullOrEmpty(group.place.address))
            {
                description = group.place.address;
            }
            if (group.city != null && !string.IsNullOrEmpty(group.city.title))
            {
                if (!string.IsNullOrEmpty(description))
                {
                    description += ", ";
                }
                description += group.city.title;
            }
            if (group.country != null && !string.IsNullOrEmpty(group.country.title))
            {
                if (!string.IsNullOrEmpty(description))
                {
                    description += ", ";
                }
                description += group.country.title;
            }
            if (!string.IsNullOrEmpty(description))
            {
                Action navigationAction = null;
                if (group.place != null && group.place.latitude != 0.0 && group.place.longitude != 0.0)
                {
                    navigationAction = (Action)(() => Navigator.Current.NavigateToMap(false, group.place.latitude, group.place.longitude));
                }
                profileInfoItemList1.Add((ProfileInfoItem) new CustomItem(CommonResources.ProfilePage_Info_Location.ToLowerInvariant(), description, navigationAction, ProfileInfoItemType.RichText));
            }
            if (profileInfoItemList1.Count > 0)
            {
                this.InfoSections.Add(new ProfileInfoSectionItem()
                {
                    Items = profileInfoItemList1
                });
            }
            List <ProfileInfoItem> profileInfoItemList2 = new List <ProfileInfoItem>()
            {
                (ProfileInfoItem) new VKSocialNetworkItem((IProfileData)this._groupData)
            };

            if (!string.IsNullOrEmpty(group.site))
            {
                profileInfoItemList2.Add((ProfileInfoItem) new SiteItem(group.site));
            }
            if (profileInfoItemList2.Count > 0)
            {
                this.InfoSections.Add(new ProfileInfoSectionItem(CommonResources.ProfilePage_Info_ContactInformation)
                {
                    Items = profileInfoItemList2
                });
            }
            List <ProfileInfoItem> profileInfoItemList3 = new List <ProfileInfoItem>();

            if (!group.links.IsNullOrEmpty())
            {
                profileInfoItemList3.AddRange((IEnumerable <ProfileInfoItem>)LinkItem.GetLinkItems(group.links));
                if (profileInfoItemList3.Count > 0)
                {
                    this.InfoSections.Add(new ProfileInfoSectionItem(CommonResources.ProfilePage_Info_Links)
                    {
                        Items = profileInfoItemList3
                    });
                }
            }
            List <ProfileInfoItem> profileInfoItemList4 = new List <ProfileInfoItem>();

            if (!group.contacts.IsNullOrEmpty())
            {
                profileInfoItemList4.AddRange((IEnumerable <ProfileInfoItem>)ContactItem.GetContactItems(group.contacts, this._groupData.contactsUsers));
                if (profileInfoItemList4.Count > 0)
                {
                    this.InfoSections.Add(new ProfileInfoSectionItem(CommonResources.ProfilePage_Info_Contacts)
                    {
                        Items = profileInfoItemList4
                    });
                }
            }
            if (this.InfoSections.Count <= 0)
            {
                return;
            }
            ((ProfileInfoSectionItem)Enumerable.Last <ProfileInfoSectionItem>(this.InfoSections)).DividerVisibility = Visibility.Collapsed;
        }
Пример #21
0
 private void CreateGoogleContact(ContactItem item)
 {
     googleAdapter.CreateContactFromOutlook(item);
 }
Пример #22
0
 private void OContactFetched(object sender, ContactItem contact)
 {
 }
Пример #23
0
        // Returns a ContactItem based on the given ID (Typ=1) or E-Mail-Address(typ=2)
        private ContactItem GetContactItemByValue(string value, int typ)
        {
            sqlConnection = null;
            sqlConnection = TimeTableDatabase.getConnection();
            try
            {
                using (sqlConnection)
                {
                    string      SQL     = "";
                    ContactItem SQLItem = new ContactItem();
                    SQLItem.Course = new StudyCourse();
                    SQLItem.Type   = new UserType();

                    SQL = "SELECT [contactid],[lastname],[firstname],[titel],[mail],[phonenumber],[roomnumber], " +
                          "[contact].relationtypid,[relationtyp].relationtypname,[contact].coursetypid,[coursetyp].[shortname],[coursetyp].[longname], [responsibility] " +
                          " FROM[contact]" +
                          " LEFT JOIN[coursetyp]" +
                          " ON[coursetyp].[coursetypid] =[contact].[coursetypid]" +
                          " LEFT JOIN[relationtyp]" +
                          " ON[relationtyp].[relationtypid] = [contact].relationtypid ";
                    if (typ == 1)
                    {
                        //Innerjoin fehlt
                        SQL += " WHERE [contactid]='" + value + "';";
                    }
                    if (typ == 2)
                    {
                        //Innerjoin fehlt
                        SQL += " WHERE [mail]='" + value + "';";
                    }

                    sqlConnection.Open();
                    SqlDataReader myReader  = null;
                    SqlCommand    myCommand = new SqlCommand(SQL, sqlConnection);
                    myReader = myCommand.ExecuteReader();

                    if (myReader.Read())
                    {
                        SQLItem.ContactID = Convert.ToInt32(myReader["contactid"]);
                        SQLItem.FirstName = myReader["firstname"].ToString();
                        SQLItem.LastName  = myReader["lastname"].ToString();
                        SQLItem.Title     = myReader["titel"].ToString();
                        SQLItem.TelNumber = myReader["phonenumber"].ToString();
                        SQLItem.Email     = myReader["mail"].ToString();
                        SQLItem.Room      = myReader["roomnumber"].ToString();

                        SQLItem.Responsibility = myReader["responsibility"].ToString();


                        if (myReader["coursetypid"].ToString() != "")
                        {
                            SQLItem.Course.ID        = Convert.ToInt32(myReader["coursetypid"]);
                            SQLItem.Course.LongText  = myReader["longname"].ToString();
                            SQLItem.Course.ShortText = myReader["shortname"].ToString();
                        }


                        SQLItem.Type.ID   = Convert.ToInt32(myReader["relationtypid"]);
                        SQLItem.Type.Name = myReader["relationtypname"].ToString();
                        sqlConnection.Close();
                        sqlConnection = null;
                        return(SQLItem);
                    }
                    else
                    {
                        sqlConnection.Close();
                        sqlConnection = null;
                        return(null);
                    }
                }
            }
            catch (System.Exception)
            {
                return(null);
            }
        }
Пример #24
0
        private void ContactItem_DoubleClick(object sender, EventArgs e)
        {
            ContactItem ci = (ContactItem)sender;

            InstantMessageMenuItem_Clicked(XmppGlobal.Roster[new jabber.JID((string)ci.Tag)].GetContextMenuItem(DefaultContextMenu.InstantMessage), null);
        }
Пример #25
0
        public String GetRecipientEmail(Recipient recipient)
        {
            String  retEmail       = "";
            Boolean builtFakeEmail = false;

            log.Fine("Determining email of recipient: " + recipient.Name);
            AddressEntry addressEntry     = null;
            String       addressEntryType = "";

            try {
                try {
                    addressEntry = recipient.AddressEntry;
                } catch {
                    log.Warn("Can't resolve this recipient!");
                    addressEntry = null;
                }
                if (addressEntry == null)
                {
                    log.Warn("No AddressEntry exists!");
                    retEmail = EmailAddress.BuildFakeEmailAddress(recipient.Name, out builtFakeEmail);
                }
                else
                {
                    try {
                        addressEntryType = addressEntry.Type;
                    } catch {
                        log.Warn("Cannot access addressEntry.Type!");
                    }
                    log.Fine("AddressEntry Type: " + addressEntryType);
                    if (addressEntryType == "EX")   //Exchange
                    {
                        log.Fine("Address is from Exchange");
                        if (addressEntry.AddressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry ||
                            addressEntry.AddressEntryUserType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                        {
                            ExchangeUser eu = null;
                            try {
                                eu = addressEntry.GetExchangeUser();
                                if (eu != null && eu.PrimarySmtpAddress != null)
                                {
                                    retEmail = eu.PrimarySmtpAddress;
                                }
                                else
                                {
                                    log.Warn("Exchange does not have an email for recipient: " + recipient.Name);
                                    Microsoft.Office.Interop.Outlook.PropertyAccessor pa = null;
                                    try {
                                        //Should I try PR_EMS_AB_PROXY_ADDRESSES next to cater for cached mode?
                                        pa       = recipient.PropertyAccessor;
                                        retEmail = pa.GetProperty(OutlookNew.PR_SMTP_ADDRESS).ToString();
                                        log.Debug("Retrieved from PropertyAccessor instead.");
                                    } catch {
                                        log.Warn("Also failed to retrieve email from PropertyAccessor.");
                                        retEmail = EmailAddress.BuildFakeEmailAddress(recipient.Name, out builtFakeEmail);
                                    } finally {
                                        pa = (Microsoft.Office.Interop.Outlook.PropertyAccessor)OutlookCalendar.ReleaseObject(pa);
                                    }
                                }
                            } finally {
                                eu = (ExchangeUser)OutlookCalendar.ReleaseObject(eu);
                            }
                        }
                        else if (addressEntry.AddressEntryUserType == OlAddressEntryUserType.olOutlookContactAddressEntry)
                        {
                            log.Fine("This is an Outlook contact");
                            ContactItem contact = null;
                            try {
                                try {
                                    contact = addressEntry.GetContact();
                                } catch {
                                    log.Warn("Doesn't seem to be a valid contact object. Maybe this account is no longer in Exchange.");
                                    retEmail = EmailAddress.BuildFakeEmailAddress(recipient.Name, out builtFakeEmail);
                                }
                                if (contact != null)
                                {
                                    if (contact.Email1AddressType == "EX")
                                    {
                                        log.Fine("Address is from Exchange.");
                                        log.Fine("Using PropertyAccessor to get email address.");
                                        Microsoft.Office.Interop.Outlook.PropertyAccessor pa = null;
                                        try {
                                            pa       = contact.PropertyAccessor;
                                            retEmail = pa.GetProperty(EMAIL1ADDRESS).ToString();
                                        } finally {
                                            pa = (Microsoft.Office.Interop.Outlook.PropertyAccessor)OutlookCalendar.ReleaseObject(pa);
                                        }
                                    }
                                    else
                                    {
                                        retEmail = contact.Email1Address;
                                    }
                                }
                            } finally {
                                contact = (ContactItem)OutlookCalendar.ReleaseObject(contact);
                            }
                        }
                        else
                        {
                            log.Fine("Exchange type: " + addressEntry.AddressEntryUserType.ToString());
                            log.Fine("Using PropertyAccessor to get email address.");
                            Microsoft.Office.Interop.Outlook.PropertyAccessor pa = null;
                            try {
                                pa       = recipient.PropertyAccessor;
                                retEmail = pa.GetProperty(OutlookNew.PR_SMTP_ADDRESS).ToString();
                            } finally {
                                pa = (Microsoft.Office.Interop.Outlook.PropertyAccessor)OutlookCalendar.ReleaseObject(pa);
                            }
                        }
                    }
                    else if (addressEntryType.ToUpper() == "NOTES")
                    {
                        log.Fine("From Lotus Notes");
                        //Migrated contacts from notes, have weird "email addresses" eg: "James T. Kirk/US-Corp03/enterprise/US"
                        retEmail = EmailAddress.BuildFakeEmailAddress(recipient.Name, out builtFakeEmail);
                    }
                    else
                    {
                        log.Fine("Not from Exchange");
                        try {
                            if (string.IsNullOrEmpty(addressEntry.Address))
                            {
                                log.Warn("addressEntry.Address is empty.");
                                retEmail = EmailAddress.BuildFakeEmailAddress(recipient.Name, out builtFakeEmail);
                            }
                            else
                            {
                                retEmail = addressEntry.Address;
                            }
                        } catch (System.Exception ex) {
                            log.Error("Failed accessing addressEntry.Address");
                            log.Error(ex.Message);
                            retEmail = EmailAddress.BuildFakeEmailAddress(recipient.Name, out builtFakeEmail);
                        }
                    }
                }

                if (retEmail != null && retEmail.IndexOf("<") > 0)
                {
                    retEmail = retEmail.Substring(retEmail.IndexOf("<") + 1);
                    retEmail = retEmail.TrimEnd(Convert.ToChar(">"));
                }
                log.Fine("Email address: " + retEmail, retEmail);
                if (!EmailAddress.IsValidEmail(retEmail) && !builtFakeEmail)
                {
                    retEmail = EmailAddress.BuildFakeEmailAddress(recipient.Name, out builtFakeEmail);
                    if (!EmailAddress.IsValidEmail(retEmail))
                    {
                        MainForm.Instance.Logboxout("ERROR: Recipient \"" + recipient.Name + "\" with email address \"" + retEmail + "\" is invalid.", notifyBubble: true);
                        MainForm.Instance.Logboxout("This must be manually resolved in order to sync this appointment.");
                        throw new ApplicationException("Invalid recipient email for \"" + recipient.Name + "\"");
                    }
                }
                return(retEmail);
            } finally {
                addressEntry = (AddressEntry)OutlookCalendar.ReleaseObject(addressEntry);
            }
        }
Пример #26
0
 public static void Call(ContactItem contact)
 {
     Skype.Call (contact ["handle.skype"]);
 }
Пример #27
0
 //ContactItem extension method for Skype to conditionally add details
 private void MaybeAddDetail(ContactItem contact, string key, string detail)
 {
     if (!string.IsNullOrEmpty (detail))
         contact [key + ".skype"] = detail;
 }
Пример #28
0
 public void AddBusinessCard(ContactItem contact)
 {
     _item.AddBusinessCard(contact);
 }
Пример #29
0
 public void UpdateForm(ContactItem Contact)
 {
     m_Contact       = Contact;
     txtDetails.Text = Contact.Details;
     txtReason.Text  = Contact.Reason;
 }
Пример #30
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="theItem"></param>
        /// <returns></returns>
        public static Hashtable getPhoneList(ContactItem theItem)
        {
            Hashtable phoneList = new Hashtable();

            try
            {
                if ((theItem.BusinessTelephoneNumber != null) && (theItem.BusinessTelephoneNumber != String.Empty))
                {
                    phoneList.Add(Constants.KEY_BUSINESS_PHONE, normalizeNumber(theItem.BusinessTelephoneNumber));
                }

                if ((theItem.Business2TelephoneNumber != null) && (theItem.Business2TelephoneNumber != String.Empty))
                {
                    phoneList.Add(Constants.KEY_BUSINESS_PHONE_2, normalizeNumber(theItem.Business2TelephoneNumber));
                }

                if ((theItem.CompanyMainTelephoneNumber != null) && (theItem.CompanyMainTelephoneNumber != String.Empty))
                {
                    phoneList.Add(Constants.KEY_COMPANY_PHONE, normalizeNumber(theItem.CompanyMainTelephoneNumber));
                }

                if ((theItem.HomeTelephoneNumber != null) && (theItem.HomeTelephoneNumber != String.Empty))
                {
                    phoneList.Add(Constants.KEY_HOME_PHONE, normalizeNumber(theItem.HomeTelephoneNumber));
                }

                if ((theItem.MobileTelephoneNumber != null) && (theItem.MobileTelephoneNumber != String.Empty))
                {
                    phoneList.Add(Constants.KEY_MOBILE_PHONE, normalizeNumber(theItem.MobileTelephoneNumber));
                }

                if ((theItem.CarTelephoneNumber != null) && (theItem.CarTelephoneNumber != String.Empty))
                {
                    phoneList.Add(Constants.KEY_CAR_PHONE, normalizeNumber(theItem.CarTelephoneNumber));
                }

                if (phoneList.Count == 0)
                {
                    return null;
                }
                else
                {
                    return phoneList;
                }
            }
            catch (System.Exception ex)
            {
                Logger.WriteEntry(LogLevel.Error, ex.GetType() + " : " + ex.Message);
                return null;
            }

        }
        public ContactItem Create(ContactItem item)
        {
            var contactItem = _iRepo.Create(item);

            return(contactItem);
        }
Пример #32
0
        private static void MapEmailAddresses1To2(ContactItem source, vCard target, IEntityMappingLogger logger)
        {
            target.EmailAddresses.Clear();
            if (!string.IsNullOrEmpty(source.Email1Address))
            {
                string email1Address = string.Empty;

                if (source.Email1AddressType == "EX")
                {
                    try
                    {
                        email1Address = source.GetPropertySafe(PR_EMAIL1ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Warn("Could not get property PR_EMAIL1ADDRESS for Email1Address", ex);
                        logger.LogMappingWarning("Could not get property PR_EMAIL1ADDRESS for Email1Address", ex);
                    }
                }
                else
                {
                    email1Address = source.Email1Address;
                }
                if (!string.IsNullOrEmpty(email1Address))
                {
                    target.EmailAddresses.Add(new vCardEmailAddress(email1Address, vCardEmailAddressType.Internet, ItemType.WORK));
                }
            }

            if (!string.IsNullOrEmpty(source.Email2Address))
            {
                string email2Address = string.Empty;

                if (source.Email2AddressType == "EX")
                {
                    try
                    {
                        email2Address = source.GetPropertySafe(PR_EMAIL2ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Warn("Could not get property PR_EMAIL2ADDRESS for Email2Address", ex);
                        logger.LogMappingWarning("Could not get property PR_EMAIL2ADDRESS for Email2Address", ex);
                    }
                }
                else
                {
                    email2Address = source.Email2Address;
                }
                if (!string.IsNullOrEmpty(email2Address))
                {
                    target.EmailAddresses.Add(new vCardEmailAddress(email2Address, vCardEmailAddressType.Internet, ItemType.HOME));
                }
            }

            if (!string.IsNullOrEmpty(source.Email3Address))
            {
                string email3Address = string.Empty;

                if (source.Email3AddressType == "EX")
                {
                    try
                    {
                        email3Address = source.GetPropertySafe(PR_EMAIL3ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Warn("Could not get property PR_EMAIL3ADDRESS for Email3Address", ex);
                        logger.LogMappingWarning("Could not get property PR_EMAIL3ADDRESS for Email3Address", ex);
                    }
                }
                else
                {
                    email3Address = source.Email3Address;
                }
                if (!string.IsNullOrEmpty(email3Address))
                {
                    target.EmailAddresses.Add(new vCardEmailAddress(email3Address));
                }
            }
        }
Пример #33
0
        private static void MapEmailAddresses1To2(ContactItem source, vCard target)
        {
            if (!string.IsNullOrEmpty(source.Email1Address))
            {
                string email1Address = string.Empty;

                if (source.Email1AddressType == "EX")
                {
                    try
                    {
                        email1Address = source.GetPropertySafe(PR_EMAIL1ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Error("Could not get property PR_EMAIL1ADDRESS for Email1Address", ex);
                    }
                }
                else
                {
                    email1Address = source.Email1Address;
                }
                if (!string.IsNullOrEmpty(email1Address))
                {
                    target.EmailAddresses.Add(new vCardEmailAddress(email1Address));
                }
            }

            if (!string.IsNullOrEmpty(source.Email2Address))
            {
                string email2Address = string.Empty;

                if (source.Email2AddressType == "EX")
                {
                    try
                    {
                        email2Address = source.GetPropertySafe(PR_EMAIL2ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Error("Could not get property PR_EMAIL2ADDRESS for Email2Address", ex);
                    }
                }
                else
                {
                    email2Address = source.Email2Address;
                }
                if (!string.IsNullOrEmpty(email2Address))
                {
                    target.EmailAddresses.Add(new vCardEmailAddress(email2Address));
                }
            }

            if (!string.IsNullOrEmpty(source.Email3Address))
            {
                string email3Address = string.Empty;

                if (source.Email3AddressType == "EX")
                {
                    try
                    {
                        email3Address = source.GetPropertySafe(PR_EMAIL3ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Error("Could not get property PR_EMAIL3ADDRESS for Email3Address", ex);
                    }
                }
                else
                {
                    email3Address = source.Email3Address;
                }
                if (!string.IsNullOrEmpty(email3Address))
                {
                    target.EmailAddresses.Add(new vCardEmailAddress(email3Address));
                }
            }
        }
Пример #34
0
        private async Task MapPhoto2To1(vCard source, ContactItem target, IEntityMappingLogger logger)
        {
            if (source.Photos.Count > 0)
            {
                if (target.HasPicture && _configuration.KeepOutlookPhoto)
                {
                    return;
                }

                vCardPhoto contactPhoto = source.Photos[0];

                string picturePath = Path.GetTempPath() + @"\Contact_" + target.EntryID + ".jpg";
                try
                {
                    if (!contactPhoto.IsLoaded && contactPhoto.Url != null)
                    {
                        using (var client = HttpUtility.CreateWebClient())
                        {
                            await client.DownloadFileTaskAsync(contactPhoto.Url, picturePath);
                        }
                    }
                    else if (contactPhoto.IsLoaded)
                    {
                        File.WriteAllBytes(picturePath, contactPhoto.GetBytes());
                    }
                    else
                    {
                        s_logger.Warn("Could not load picture for contact.");
                        logger.LogMappingWarning("Could not load picture for contact.");
                        return;
                    }
                    try
                    {
                        target.AddPicture(picturePath);
                    }
                    catch (COMException x)
                    {
                        s_logger.Warn("Could not add picture for contact.", x);
                        logger.LogMappingWarning("Could not add picture for contact.", x);
                    }
                    File.Delete(picturePath);
                }
                catch (Exception ex)
                {
                    s_logger.Warn("Could not add picture for contact.", ex);
                    logger.LogMappingWarning("Could not add picture for contact.", ex);
                }
            }
            else
            {
                if (target.HasPicture)
                {
                    try
                    {
                        target.RemovePicture();
                    }
                    catch (COMException x)
                    {
                        s_logger.Warn("Could not remove picture for contact.", x);
                        logger.LogMappingWarning("Could not remove picture for contact.", x);
                    }
                }
            }
        }
Пример #35
0
 private static void MapPhoneNumbers1To2(ContactItem source, vCard target)
 {
     target.Phones.Clear();
     if (!string.IsNullOrEmpty(source.PrimaryTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.PrimaryTelephoneNumber, vCardPhoneTypes.Main);
         phoneNumber.IsPreferred = true;
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.MobileTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.MobileTelephoneNumber, vCardPhoneTypes.Cellular);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.HomeTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.HomeTelephoneNumber, vCardPhoneTypes.Home);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.Home2TelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.Home2TelephoneNumber, vCardPhoneTypes.HomeVoice);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.HomeFaxNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.HomeFaxNumber, vCardPhoneTypes.Fax | vCardPhoneTypes.Home);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.BusinessTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.BusinessTelephoneNumber, vCardPhoneTypes.Work);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.Business2TelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.Business2TelephoneNumber, vCardPhoneTypes.WorkVoice);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.BusinessFaxNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.BusinessFaxNumber, vCardPhoneTypes.WorkFax);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.PagerNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.PagerNumber, vCardPhoneTypes.Pager);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.CarTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.CarTelephoneNumber, vCardPhoneTypes.Car);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.ISDNNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.ISDNNumber, vCardPhoneTypes.ISDN);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.OtherTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.OtherTelephoneNumber, vCardPhoneTypes.Voice);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.OtherFaxNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.OtherFaxNumber, vCardPhoneTypes.Fax);
         target.Phones.Add(phoneNumber);
     }
 }
 public ContactItemWrapper (ContactItem inner, Func<string, ContactItem> load)
 {
   _load = load;
   Inner = inner;
 }
Пример #37
0
        private void MapTelephoneNumber2To1(vCard source, ContactItem target)
        {
            target.HomeTelephoneNumber     = string.Empty;
            target.BusinessTelephoneNumber = string.Empty;
            target.BusinessFaxNumber       = string.Empty;
            target.PrimaryTelephoneNumber  = string.Empty;
            target.MobileTelephoneNumber   = string.Empty;

            // if no PhoneTypes are set (e.g. Yandex drops the types)
            // assume a default ordering of cell,work,home to avoid data loss of the first 3 numbers

            if (source.Phones.Count >= 1 && source.Phones.All(p => p.PhoneType == vCardPhoneTypes.Default))
            {
                var phoneNumber1 = source.Phones[0].FullNumber;
                target.MobileTelephoneNumber = _configuration.FixPhoneNumberFormat
          ? FixPhoneNumberFormat(phoneNumber1)
          : phoneNumber1;

                if (source.Phones.Count >= 2)
                {
                    var phoneNumber2 = source.Phones[1].FullNumber;
                    target.BusinessTelephoneNumber = _configuration.FixPhoneNumberFormat
             ? FixPhoneNumberFormat(phoneNumber2)
             : phoneNumber2;
                    if (source.Phones.Count >= 3)
                    {
                        var phoneNumber3 = source.Phones[2].FullNumber;
                        target.HomeTelephoneNumber = _configuration.FixPhoneNumberFormat
               ? FixPhoneNumberFormat(phoneNumber3)
               : phoneNumber3;
                    }
                }
                return;
            }

            foreach (var phoneNumber in source.Phones)
            {
                string sourceNumber = _configuration.FixPhoneNumberFormat ?
                                      FixPhoneNumberFormat(phoneNumber.FullNumber) : phoneNumber.FullNumber;
                if (phoneNumber.IsMain)
                {
                    target.PrimaryTelephoneNumber = sourceNumber;
                }
                else if (phoneNumber.IsCellular)
                {
                    target.MobileTelephoneNumber = sourceNumber;
                }
                else if (phoneNumber.IsiPhone && string.IsNullOrEmpty(target.MobileTelephoneNumber))
                {
                    target.MobileTelephoneNumber = sourceNumber;
                }
                else if (phoneNumber.IsHome && !phoneNumber.IsFax)
                {
                    if (string.IsNullOrEmpty(target.HomeTelephoneNumber))
                    {
                        target.HomeTelephoneNumber = sourceNumber;
                    }
                    else
                    {
                        target.Home2TelephoneNumber = sourceNumber;
                    }
                }
                else if (phoneNumber.IsWork && !phoneNumber.IsFax)
                {
                    if (string.IsNullOrEmpty(target.BusinessTelephoneNumber))
                    {
                        target.BusinessTelephoneNumber = sourceNumber;
                    }
                    else
                    {
                        target.Business2TelephoneNumber = sourceNumber;
                    }
                }
                else if (phoneNumber.IsFax)
                {
                    if (phoneNumber.IsHome)
                    {
                        target.HomeFaxNumber = sourceNumber;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(target.BusinessFaxNumber))
                        {
                            target.BusinessFaxNumber = sourceNumber;
                        }
                        else
                        {
                            target.OtherFaxNumber = sourceNumber;
                        }
                    }
                }
                else if (phoneNumber.IsPager)
                {
                    target.PagerNumber = sourceNumber;
                }
                else if (phoneNumber.IsCar)
                {
                    target.CarTelephoneNumber = sourceNumber;
                }
                else if (phoneNumber.IsISDN)
                {
                    target.ISDNNumber = sourceNumber;
                }
                else
                {
                    if (phoneNumber.IsPreferred && string.IsNullOrEmpty(target.PrimaryTelephoneNumber))
                    {
                        target.PrimaryTelephoneNumber = sourceNumber;
                    }
                    else if (phoneNumber.IsPreferred && string.IsNullOrEmpty(target.HomeTelephoneNumber))
                    {
                        target.HomeTelephoneNumber = sourceNumber;
                    }
                    else
                    {
                        target.OtherTelephoneNumber = sourceNumber;
                    }
                }
            }
        }
 private void DisposeInner()
 {
   Marshal.FinalReleaseComObject (Inner);
   Inner = null;
 }
Пример #39
0
        private static void MapPostalAdresses2To1(vCard source, ContactItem target)
        {
            target.HomeAddress              = string.Empty;
            target.HomeAddressStreet        = string.Empty;
            target.HomeAddressCity          = string.Empty;
            target.HomeAddressPostalCode    = string.Empty;
            target.HomeAddressCountry       = string.Empty;
            target.HomeAddressState         = string.Empty;
            target.HomeAddressPostOfficeBox = string.Empty;

            target.BusinessAddress              = string.Empty;
            target.BusinessAddressStreet        = string.Empty;
            target.BusinessAddressCity          = string.Empty;
            target.BusinessAddressPostalCode    = string.Empty;
            target.BusinessAddressCountry       = string.Empty;
            target.BusinessAddressState         = string.Empty;
            target.BusinessAddressPostOfficeBox = string.Empty;

            target.OtherAddress              = string.Empty;
            target.OtherAddressStreet        = string.Empty;
            target.OtherAddressCity          = string.Empty;
            target.OtherAddressPostalCode    = string.Empty;
            target.OtherAddressCountry       = string.Empty;
            target.OtherAddressState         = string.Empty;
            target.OtherAddressPostOfficeBox = string.Empty;

            target.SelectedMailingAddress = OlMailingAddress.olNone;

            foreach (var sourceAddress in source.DeliveryAddresses)
            {
                if (sourceAddress.IsHome)
                {
                    target.HomeAddressCity       = sourceAddress.City;
                    target.HomeAddressCountry    = sourceAddress.Country;
                    target.HomeAddressPostalCode = sourceAddress.PostalCode;
                    target.HomeAddressState      = sourceAddress.Region;
                    target.HomeAddressStreet     = sourceAddress.Street;
                    if (!string.IsNullOrEmpty(sourceAddress.ExtendedAddress))
                    {
                        target.HomeAddressStreet += "\r\n" + sourceAddress.ExtendedAddress;
                    }
                    target.HomeAddressPostOfficeBox = sourceAddress.PoBox;
                    if (sourceAddress.IsPreferred)
                    {
                        target.SelectedMailingAddress = OlMailingAddress.olHome;
                    }
                }
                else if (sourceAddress.IsWork)
                {
                    target.BusinessAddressCity       = sourceAddress.City;
                    target.BusinessAddressCountry    = sourceAddress.Country;
                    target.BusinessAddressPostalCode = sourceAddress.PostalCode;
                    target.BusinessAddressState      = sourceAddress.Region;
                    target.BusinessAddressStreet     = sourceAddress.Street;
                    if (!string.IsNullOrEmpty(sourceAddress.ExtendedAddress))
                    {
                        target.BusinessAddressStreet += "\r\n" + sourceAddress.ExtendedAddress;
                    }
                    target.BusinessAddressPostOfficeBox = sourceAddress.PoBox;
                    if (sourceAddress.IsPreferred)
                    {
                        target.SelectedMailingAddress = OlMailingAddress.olBusiness;
                    }
                }
                else
                {
                    target.OtherAddressCity       = sourceAddress.City;
                    target.OtherAddressCountry    = sourceAddress.Country;
                    target.OtherAddressPostalCode = sourceAddress.PostalCode;
                    target.OtherAddressState      = sourceAddress.Region;
                    target.OtherAddressStreet     = sourceAddress.Street;
                    if (!string.IsNullOrEmpty(sourceAddress.ExtendedAddress))
                    {
                        target.OtherAddressStreet += "\r\n" + sourceAddress.ExtendedAddress;
                    }
                    target.OtherAddressPostOfficeBox = sourceAddress.PoBox;
                    if (sourceAddress.IsPreferred)
                    {
                        target.SelectedMailingAddress = OlMailingAddress.olOther;
                    }
                }
            }
        }
Пример #40
0
 public static bool IsBlocked(ContactItem item)
 {
     if (!File.Exists(OutlookMutexFile))
         return false;
     StreamReader sr = new StreamReader(OutlookMutexFile);
     try
     {
         while (!sr.EndOfStream)
         {
             List<string> data = new List<string>(sr.ReadLine().Split(','));
             if (data[0] == item.FullName)
             {
                 return true;
             }
             data.RemoveAt(0);
             if ((data.Contains(item.Email1Address)) ||
                 (data.Contains(item.Email2Address)) ||
                 (data.Contains(item.Email3Address)))
                 return true;
         }
     }
     finally
     {
         sr.Close();
     }
     return false;
 }
Пример #41
0
 public bool AddFavorite(ContactItem item)
 {
     return(true);
 }
Пример #42
0
        public static void ClearBlockedContact(ContactItem item)
        {
            int retries = 0;
            bool saved = false;
            bool found = false;
            List<string> lines = new List<string>();
            List<string> linesToSave;
            string FilePath = OutlookMutexFile;

            if (!File.Exists(FilePath))
                return;
            StreamReader sr = new StreamReader(FilePath);
            while (!sr.EndOfStream)
            {
                lines.Add(sr.ReadLine());
            }
            sr.Close();
            linesToSave = new List<string>(lines);
            foreach (string line in lines)
            {
                List<string> data = new List<string>(line.Split(','));
                if (data[0] == item.FullName)
                {
                    found = true;
                }
                else
                {
                    data.RemoveAt(0);
                    if ((data.Contains(item.Email1Address)) ||
                        (data.Contains(item.Email2Address)) ||
                        (data.Contains(item.Email3Address)))
                        found = true;
                }
                if (found)
                {
                    linesToSave.Remove(line);
                    //don't break... may have multiple instances
                    //break;
                }
            }
            if (found)
            {
                do
                {
                    try
                    {
                        StreamWriter sw = new StreamWriter(FilePath);
                        try
                        {
                            foreach (string line in linesToSave)
                            {
                                sw.WriteLine(line);
                            }
                        }
                        finally
                        {
                            sw.Close();
                        }
                        saved = true;
                    }
                    catch (System.Exception)
                    {
                        System.Threading.Thread.Sleep(500);
                        retries++;
                    }
                }
                while (!saved && retries <= 3);
            }
        }
Пример #43
0
        private static void MapPostalAddresses2To1(Contact source, ContactItem target)
        {
            target.HomeAddress              = string.Empty;
            target.HomeAddressStreet        = string.Empty;
            target.HomeAddressCity          = string.Empty;
            target.HomeAddressPostalCode    = string.Empty;
            target.HomeAddressCountry       = string.Empty;
            target.HomeAddressState         = string.Empty;
            target.HomeAddressPostOfficeBox = string.Empty;

            target.BusinessAddress              = string.Empty;
            target.BusinessAddressStreet        = string.Empty;
            target.BusinessAddressCity          = string.Empty;
            target.BusinessAddressPostalCode    = string.Empty;
            target.BusinessAddressCountry       = string.Empty;
            target.BusinessAddressState         = string.Empty;
            target.BusinessAddressPostOfficeBox = string.Empty;

            target.OtherAddress              = string.Empty;
            target.OtherAddressStreet        = string.Empty;
            target.OtherAddressCity          = string.Empty;
            target.OtherAddressPostalCode    = string.Empty;
            target.OtherAddressCountry       = string.Empty;
            target.OtherAddressState         = string.Empty;
            target.OtherAddressPostOfficeBox = string.Empty;

            target.SelectedMailingAddress = OlMailingAddress.olNone;

            foreach (var sourceAddress in source.PostalAddresses)
            {
                if (sourceAddress.Rel == ContactsRelationships.IsHome)
                {
                    target.HomeAddressCity          = sourceAddress.City;
                    target.HomeAddressCountry       = sourceAddress.Country;
                    target.HomeAddressPostalCode    = sourceAddress.Postcode;
                    target.HomeAddressState         = sourceAddress.Region;
                    target.HomeAddressStreet        = sourceAddress.Street;
                    target.HomeAddressPostOfficeBox = sourceAddress.Pobox;
                    if (string.IsNullOrEmpty(target.HomeAddress))
                    {
                        target.HomeAddress = sourceAddress.FormattedAddress;
                    }
                    if (sourceAddress.Primary)
                    {
                        target.SelectedMailingAddress = OlMailingAddress.olHome;
                    }
                }
                else if (sourceAddress.Rel == ContactsRelationships.IsWork)
                {
                    target.BusinessAddressCity          = sourceAddress.City;
                    target.BusinessAddressCountry       = sourceAddress.Country;
                    target.BusinessAddressPostalCode    = sourceAddress.Postcode;
                    target.BusinessAddressState         = sourceAddress.Region;
                    target.BusinessAddressStreet        = sourceAddress.Street;
                    target.BusinessAddressPostOfficeBox = sourceAddress.Pobox;
                    if (string.IsNullOrEmpty(target.BusinessAddress))
                    {
                        target.BusinessAddress = sourceAddress.FormattedAddress;
                    }
                    if (sourceAddress.Primary)
                    {
                        target.SelectedMailingAddress = OlMailingAddress.olBusiness;
                    }
                }
                else
                {
                    target.OtherAddressCity          = sourceAddress.City;
                    target.OtherAddressCountry       = sourceAddress.Country;
                    target.OtherAddressPostalCode    = sourceAddress.Postcode;
                    target.OtherAddressState         = sourceAddress.Region;
                    target.OtherAddressStreet        = sourceAddress.Street;
                    target.OtherAddressPostOfficeBox = sourceAddress.Pobox;
                    if (string.IsNullOrEmpty(target.OtherAddress))
                    {
                        target.OtherAddress = sourceAddress.FormattedAddress;
                    }
                    if (sourceAddress.Primary)
                    {
                        target.SelectedMailingAddress = OlMailingAddress.olOther;
                    }
                }
            }
        }
Пример #44
0
 private void SyncContact(Contact gContact, ContactItem item, Config.Direction dir)
 {
     if (dir == Config.Direction.dirToGoogle)
     {
         googleAdapter.UpdateContactFromOutlook(item, gContact);
     }
     else
     {
         outlookAdapter.UpdateContactFromGoogle(gContact, item);
     }
 }
Пример #45
0
        private static void MapEmailAddresses1To2(ContactItem source, Contact target, IEntityMappingLogger logger)
        {
            target.Emails.Clear();

            if (!string.IsNullOrEmpty(source.Email1Address))
            {
                string email1Address = string.Empty;

                if (source.Email1AddressType == "EX")
                {
                    try
                    {
                        email1Address = source.GetPropertySafe(PR_EMAIL1ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Warn("Could not get property PR_EMAIL1ADDRESS for Email1Address", ex);
                        logger.LogMappingWarning("Could not get property PR_EMAIL1ADDRESS for Email1Address", ex);
                    }
                }
                else
                {
                    email1Address = source.Email1Address;
                }
                if (!string.IsNullOrEmpty(email1Address))
                {
                    target.Emails.Add(new EMail()
                    {
                        Primary = true,
                        Address = email1Address,
                        Rel     = ContactsRelationships.IsWork,
                    });
                }
            }

            if (!string.IsNullOrEmpty(source.Email2Address))
            {
                string email2Address = string.Empty;

                if (source.Email2AddressType == "EX")
                {
                    try
                    {
                        email2Address = source.GetPropertySafe(PR_EMAIL2ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Warn("Could not get property PR_EMAIL2ADDRESS for Email2Address", ex);
                        logger.LogMappingWarning("Could not get property PR_EMAIL2ADDRESS for Email2Address", ex);
                    }
                }
                else
                {
                    email2Address = source.Email2Address;
                }
                if (!string.IsNullOrEmpty(email2Address))
                {
                    target.Emails.Add(new EMail()
                    {
                        Primary = (target.Emails.Count == 0),
                        Address = email2Address,
                        Rel     = ContactsRelationships.IsHome,
                    });
                }
            }

            if (!string.IsNullOrEmpty(source.Email3Address))
            {
                string email3Address = string.Empty;

                if (source.Email3AddressType == "EX")
                {
                    try
                    {
                        email3Address = source.GetPropertySafe(PR_EMAIL3ADDRESS);
                    }
                    catch (COMException ex)
                    {
                        s_logger.Warn("Could not get property PR_EMAIL3ADDRESS for Email3Address", ex);
                        logger.LogMappingWarning("Could not get property PR_EMAIL3ADDRESS for Email3Address", ex);
                    }
                }
                else
                {
                    email3Address = source.Email3Address;
                }
                if (!string.IsNullOrEmpty(email3Address))
                {
                    target.Emails.Add(new EMail()
                    {
                        Primary = (target.Emails.Count == 0),
                        Address = email3Address,
                        Rel     = ContactsRelationships.IsOther,
                    });
                }
            }
        }
Пример #46
0
 public void OutlookSynched(object sender, ContactItem contact, int current, int total)
 {
     ntfIcon.Text = "Google->Outlook " + current.ToString() + " of " + total.ToString();
     //logger ("Google->Outlook " + current.ToString() + " of " + total.ToString());
 }
Пример #47
0
        private static void MapPhoneNumbers1To2(ContactItem source, Contact target)
        {
            target.Phonenumbers.Clear();

            if (!string.IsNullOrEmpty(source.PrimaryTelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.PrimaryTelephoneNumber,
                    Rel     = ContactsRelationships.IsMain,
                    Primary = true,
                });
            }
            if (!string.IsNullOrEmpty(source.MobileTelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.MobileTelephoneNumber,
                    Rel     = ContactsRelationships.IsMobile,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.HomeTelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.HomeTelephoneNumber,
                    Rel     = ContactsRelationships.IsHome,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.Home2TelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.Home2TelephoneNumber,
                    Rel     = ContactsRelationships.IsHome,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.HomeFaxNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.HomeFaxNumber,
                    Rel     = ContactsRelationships.IsHomeFax,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.BusinessTelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.BusinessTelephoneNumber,
                    Rel     = ContactsRelationships.IsWork,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.Business2TelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.Business2TelephoneNumber,
                    Rel     = ContactsRelationships.IsWork,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.BusinessFaxNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.BusinessFaxNumber,
                    Rel     = ContactsRelationships.IsWorkFax,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.PagerNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.PagerNumber,
                    Rel     = ContactsRelationships.IsPager,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.CarTelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.CarTelephoneNumber,
                    Rel     = ContactsRelationships.IsCar,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.ISDNNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.ISDNNumber,
                    Rel     = ContactsRelationships.IsISDN,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.OtherTelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.OtherTelephoneNumber,
                    Rel     = ContactsRelationships.IsOther,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.OtherFaxNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.OtherFaxNumber,
                    Rel     = ContactsRelationships.IsOtherFax,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
            if (!string.IsNullOrEmpty(source.AssistantTelephoneNumber))
            {
                target.Phonenumbers.Add(new PhoneNumber()
                {
                    Value   = source.AssistantTelephoneNumber,
                    Rel     = ContactsRelationships.IsAssistant,
                    Primary = target.Phonenumbers.Count == 0,
                });
            }
        }
Пример #48
0
 public static int SaveContact(ContactItem item)
 {
     return ContactItemRepositoryADO.SaveTask(item);
 }
Пример #49
0
        /// <summary>
        /// Merges the with.
        /// </summary>
        /// <param name="googleContact">The google contact.</param>
        /// <param name="outlookContact">The outlook contact.</param>
        /// <param name="googleGroups">The google groups.</param>
        /// <returns>
        /// True if Changed.
        /// </returns>
        public static bool MergeWith(this Contact googleContact, ContactItem outlookContact, IEnumerable<Group> googleGroups)
        {
            var result = false;

            result |= googleContact.Name.ApplyProperty(c => c.FullName, outlookContact.FullName);
            result |= googleContact.Name.ApplyProperty(c => c.GivenName, outlookContact.FirstName);
            result |= googleContact.Name.ApplyProperty(c => c.FamilyName, outlookContact.LastName);

            if (outlookContact.Email1AddressType != "EX") result |= googleContact.Emails.Merge(new EMail { Address = outlookContact.Email1Address, Rel = ContactsRelationships.IsOther });
            if (outlookContact.Email2AddressType != "EX") result |= googleContact.Emails.Merge(new EMail { Address = outlookContact.Email2Address, Rel = ContactsRelationships.IsOther });
            if (outlookContact.Email3AddressType != "EX") result |= googleContact.Emails.Merge(new EMail { Address = outlookContact.Email3Address, Rel = ContactsRelationships.IsOther });

            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.HomeTelephoneNumber, Rel = ContactsRelationships.IsHome });
            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.Home2TelephoneNumber, Rel = ContactsRelationships.IsHome });
            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.HomeFaxNumber, Rel = ContactsRelationships.IsHomeFax });
            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.BusinessTelephoneNumber, Rel = ContactsRelationships.IsWork });
            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.Business2TelephoneNumber, Rel = ContactsRelationships.IsWork });
            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.BusinessFaxNumber, Rel = ContactsRelationships.IsWorkFax });
            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.OtherTelephoneNumber, Rel = ContactsRelationships.IsOther });
            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.OtherFaxNumber, Rel = ContactsRelationships.IsFax });
            result |= googleContact.Phonenumbers.Merge(new PhoneNumber { Value = outlookContact.MobileTelephoneNumber, Rel = ContactsRelationships.IsMobile });
            if (!googleContact.Phonenumbers.Any(p => p.Primary)) googleContact.Phonenumbers.FirstOrInstance(p => p.Value == outlookContact.PrimaryTelephoneNumber).Primary = true;

            result |= googleContact.ContactEntry.PostalAddresses.Merge(new StructuredPostalAddress { Street = outlookContact.HomeAddressStreet, City = outlookContact.HomeAddressCity, Country = outlookContact.HomeAddressCountry, Pobox = outlookContact.HomeAddressPostOfficeBox, Postcode = outlookContact.HomeAddressPostalCode, Region = outlookContact.HomeAddressState, Rel = ContactsRelationships.IsHome });
            result |= googleContact.ContactEntry.PostalAddresses.Merge(new StructuredPostalAddress { Street = outlookContact.BusinessAddressStreet, City = outlookContact.BusinessAddressCity, Country = outlookContact.BusinessAddressCountry, Pobox = outlookContact.BusinessAddressPostOfficeBox, Postcode = outlookContact.BusinessAddressPostalCode, Region = outlookContact.BusinessAddressState, Rel = ContactsRelationships.IsWork });
            result |= googleContact.ContactEntry.PostalAddresses.Merge(new StructuredPostalAddress { Street = outlookContact.OtherAddressStreet, City = outlookContact.OtherAddressCity, Country = outlookContact.OtherAddressCountry, Pobox = outlookContact.OtherAddressPostOfficeBox, Postcode = outlookContact.OtherAddressPostalCode, Region = outlookContact.OtherAddressState, Rel = ContactsRelationships.IsOther });
            if (!googleContact.PostalAddresses.Any(p => p.Primary))
            {
                googleContact.PostalAddresses.FirstOrInstance(p => outlookContact.MailingAddressStreet.StartsWith(p.Street) && p.City == outlookContact.MailingAddressCity && p.Country == outlookContact.MailingAddressCountry && p.Pobox == outlookContact.MailingAddressPostOfficeBox && p.Postcode == outlookContact.MailingAddressPostalCode && p.Region == outlookContact.MailingAddressState).Primary = true;
            }

            if (outlookContact.Birthday != default(DateTime) && outlookContact.Birthday.Year > 1000 && outlookContact.Birthday.Year < 2500)
            {
                var birth = outlookContact.Birthday.Year == default(DateTime).Year
                            ? outlookContact.Birthday.ToString(DateFormats[1], CultureInfo.InvariantCulture)
                            : outlookContact.Birthday.ToString(DateFormats[0], CultureInfo.InvariantCulture);
                result |= googleContact.ContactEntry.ApplyProperty(c => c.Birthday, birth);
            }

            result |= googleContact.ContactEntry.ApplyProperty(c => c.BillingInformation, outlookContact.BillingInformation);
            result |= googleContact.IMs.Merge(new IMAddress { Address = outlookContact.IMAddress, Rel = ContactsRelationships.IsOther });
            result |= googleContact.ContactEntry.ApplyProperty(c => c.Initials, outlookContact.Initials);
            result |= googleContact.ContactEntry.ApplyProperty(c => c.Language, outlookContact.Language);
            result |= googleContact.ContactEntry.ApplyProperty(c => c.Mileage, outlookContact.Mileage);
            result |= googleContact.ContactEntry.ApplyProperty(c => c.Nickname, outlookContact.NickName);
            result |= googleContact.ContactEntry.Websites.Merge(new Website { Href = outlookContact.PersonalHomePage, Rel = "home-page" });
            result |= googleContact.ContactEntry.Websites.Merge(new Website { Href = outlookContact.BusinessHomePage, Rel = "work" });
            result |= googleContact.ContactEntry.Websites.Merge(new Website { Href = outlookContact.WebPage, Rel = "other" });

            result |= googleContact.ContactEntry.Organizations.Merge(new Organization { Name = outlookContact.CompanyName, Department = outlookContact.Department, Title = outlookContact.Profession, Rel = ContactsRelationships.IsWork });

            // Syncing Groups/Categories
            if (!string.IsNullOrEmpty(outlookContact.Categories))
            {
                result |= googleContact.GroupMembership.Merge(outlookContact.Categories.Split(';').Select(c => c.Trim()), googleGroups);
            }

            return result;
        }
        private void UpdateContactDataFromGoogle(Contact gContact, ContactItem oContact)
        {
            if (gContact.Organizations.Count > 0)
            {
                oContact.CompanyName = gContact.Organizations[0].Name;
                oContact.JobTitle = gContact.Organizations[0].Title;
            }

            //oContact.WebPage = gContact.weex
            var qryBusinessAddress = gContact.PostalAddresses.Where(p => !p.Home);
            if (qryBusinessAddress.Count() > 0)
            {
                oContact.BusinessAddress = qryBusinessAddress.First().Value;
            }
            else
                oContact.BusinessAddress = "";
            var qryHomeAddress = gContact.PostalAddresses.Where(p => p.Home);
            if (qryHomeAddress.Count() > 0)
            {
                oContact.HomeAddress = qryHomeAddress.First().Value;
            }
            else
                oContact.HomeAddress = "";
            try
            {
                oContact.Email1Address = gContact.Emails[0].Address;
                oContact.Email1DisplayName = gContact.Title;
            }
            catch
            {
                oContact.Email1Address = "";
                oContact.Email1DisplayName = "";
            }
            try
            {
                oContact.Email2Address = gContact.Emails[1].Address;
                oContact.Email2DisplayName = gContact.Title;
            }
            catch
            {
                oContact.Email2Address = "";
                oContact.Email2DisplayName = "";
            }
            try
            {
                oContact.Email3Address = gContact.Emails[2].Address;
                oContact.Email3DisplayName = gContact.Title;
            }
            catch
            {
                oContact.Email3Address = "";
                oContact.Email3DisplayName = "";
            }
            if (gContact.PrimaryEmail != null)
            {
                if (gContact.Title != gContact.PrimaryEmail.Address)
                {
                    oContact.FullName = gContact.Title;
                }
            }
            else
            {
                oContact.FullName = gContact.Title;
            }
            var qryBusinessPhone = gContact.Phonenumbers.Where(p => p.Work);
            if (qryBusinessPhone.Count() > 0)
            {
                oContact.BusinessTelephoneNumber = qryBusinessPhone.First().Value;
            }
            else
                oContact.BusinessTelephoneNumber = "";
            var qryHomePhone = gContact.Phonenumbers.Where(p => p.Home);
            if (qryHomePhone.Count() > 0)
            {
                oContact.HomeTelephoneNumber = qryHomePhone.First().Value;
            }
            else
                oContact.HomeTelephoneNumber = "";
            var qryWorkFax = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsWorkFax);
            if (qryWorkFax.Count() > 0)
            {
                oContact.BusinessFaxNumber = qryWorkFax.First().Value;
            }
            else
                oContact.BusinessFaxNumber = "";
            var qryHomeFax = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsHomeFax);
            if (qryHomeFax.Count() > 0)
            {
                oContact.HomeFaxNumber = qryHomeFax.First().Value;
            }
            else
                oContact.HomeFaxNumber = "";
            var qryMobile = gContact.Phonenumbers.Where(p => p.Rel == ContactsRelationships.IsMobile);
            if (qryMobile.Count() > 0)
            {
                oContact.MobileTelephoneNumber = qryMobile.First().Value;
            }
            else
                oContact.MobileTelephoneNumber = "";
            oContact.Save();
        }
Пример #51
0
        public int SaveItem(ContactItem item)
        {
            int r;
            lock (locker)
            {
                if (item.ID != 0)
                {
                    connection = new SqliteConnection ("Data Source=" + path);
                    connection.Open ();
                    using (var command = connection.CreateCommand ())
                    {
                        command.CommandText = "UPDATE [Items] SET [Name] = ?, [Surname] = ?, [Number] = ?, [Path] = ? WHERE [_id] = ?;";
                        command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Name });
                        command.Parameters.Add(new SqliteParameter(DbType.String) { Value = item.Surname });
                        command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Number });
                        command.Parameters.Add(new SqliteParameter(DbType.String) { Value = item.Path });
                        command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.ID });
                        r = command.ExecuteNonQuery ();
                    }
                    connection.Close ();
                    return r;
                }
                else
                {
                    connection = new SqliteConnection ("Data Source=" + path);
                    connection.Open ();
                    using (var command = connection.CreateCommand ())
                    {
                        command.CommandText = "INSERT INTO [Items] ([Name], [Surname], [Number], [Path]) VALUES (? ,?, ?, ?)";
                        command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Name });
                        command.Parameters.Add(new SqliteParameter(DbType.String) { Value = item.Surname });
                        command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Number });
                        command.Parameters.Add (new SqliteParameter(DbType.String) { Value = item.Path });
                        r = command.ExecuteNonQuery ();
                    }
                    connection.Close ();
                    return r;
                }

            }
        }
 public void UpdateContactFromGoogle(Contact gContact, ContactItem oContact)
 {
     if (oContact == null)
     {
         var qryC = Contacts.Where(c => c.FullName == gContact.Title ||
             gContact.Emails.Contains(new EMail(c.Email1Address), new EmailComparer()) ||
             gContact.Emails.Contains(new EMail(c.Email2Address), new EmailComparer()) ||
             gContact.Emails.Contains(new EMail(c.Email3Address), new EmailComparer()));
         if (qryC.Count() > 0)
         {
             oContact = qryC.First();
         }
         else
         {
             CreateContactFromGoogle(gContact);
             return;
         }
     }
     UpdateContactDataFromGoogle(gContact, oContact);
 }
Пример #53
0
 /// <summary>Convert from DataReader to Task object</summary>
 ContactItem FromReader(SqliteDataReader r)
 {
     var t = new ContactItem();
     t.ID = Convert.ToInt32(r ["_id"]);
     t.Name = r ["Name"].ToString();
     t.Surname = r["Surname"].ToString();
     t.Number = r ["Number"].ToString();
     t.Path = r["Path"].ToString();
     return t;
 }
Пример #54
0
        /// <summary>
        /// Syncs the outlook contact.
        /// </summary>
        /// <param name="outlookContact">The outlook contact.</param>
        /// <param name="googleContacts">The google contacts.</param>
        private void SyncOutlookContact(ContactItem outlookContact, IEnumerable<Contact> googleContacts)
        {
            var mergeables = googleContacts.Mergeable(outlookContact).ToList();

            // continue with next, if modificationdate is older then other side.
            if (ApplicationData.ContactBehavior == ContactBehavior.Automatic && mergeables.Any() &&
                outlookContact.LastModificationTime < mergeables.First().ContactEntry.Edited.DateValue)
                return;

            // Get or Create Contact and merge informations
            Contact googleContact;
            var googleGroups = Repository.GoogleData.GetGroups();
            if (mergeables.Any())
            {
                googleContact = mergeables.First();
                var changed = googleContact.MergeWith(outlookContact, googleGroups);
                if (changed)
                    this.Repository.GoogleData.ContactsRequest.Update(googleContact);
            }
            else
            {
                googleContact = new Contact();
                googleContact.MergeWith(outlookContact, googleGroups);
                this.Repository.GoogleData.ContactsRequest.Insert(ApplicationData.GoogleContactsUri, googleContact);
            }

            // Set GoogleId and Picture
            var outlookChanged = outlookContact.UserProperties.SetProperty("GoogleId", googleContact.Id);
            if (ApplicationData.ContactBehavior != ContactBehavior.GoogleOverOutlook && outlookContact.HasNewPicture())
            {
                try
                {
                    this.Repository.GoogleData.ContactsRequest.SetPhoto(googleContact, outlookContact.GetPicture(), "image/jpg");
                    googleContact = this.Repository.GoogleData.ContactsRequest.Retrieve(googleContact);
                    outlookChanged |= outlookContact.UserProperties.SetProperty("GooglePicture", googleContact.PhotoEtag);
                }
                catch (IOException ex)
                {
                    Debug.Write(ex.Message);
                    new EventLogPermission(EventLogPermissionAccess.Administer, ".").PermitOnly();
                    EventLog.WriteEntry("GoogleSync Addin", ex.ToString(), EventLogEntryType.Warning);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Debug.Write(ex.Message);
                    new EventLogPermission(EventLogPermissionAccess.Administer, ".").PermitOnly();
                    EventLog.WriteEntry("GoogleSync Addin", ex.ToString(), EventLogEntryType.Warning);
                }
            }

            if (outlookChanged) outlookContact.Save();
        }
Пример #55
0
        /// <summary>
        /// Asynchronously sends invitation to each of the users specified.
        /// </summary>
        private async Task InviteAsync(
            ActionLink actionLink,
            AuthTicket authTicket,
            ContactItem contact,
            WorkflowInvitationDto model,
            CancellationToken cancellationToken)
        {
            if (actionLink == null)
            {
                throw new ArgumentNullException(nameof(actionLink));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (model.Action == null)
            {
                throw new InvalidOperationException("An action link with the given ID was not found.");
            }
            if (model.To == null || model.To.Length == 0)
            {
                throw new InvalidOperationException("At least one person is required for invitation.");
            }
            var invActionLinkParams = _actionLinkService.DecodeLink(model.Action);

            var action = await _projectManager.GetActionByIdAsync(invActionLinkParams.ActionId, cancellationToken);

            if (action == null)
            {
                throw new InvalidOperationException($"The specified action link was not found: {invActionLinkParams.ToString()}");
            }

            var project = await _projectManager.FindByIdAsync(action.Project.Id, cancellationToken);

            var context    = Request.Properties["MS_HttpContext"] as HttpContextWrapper;
            var logEvent   = context.Request.CreateEvent();
            var invitation = new ProjectInvitation {
                From = contact, Message = model.Message, To = model.To.Select(c => c.ToContact())
            };
            var properties = new PropertyDictionary {
                { "Invitation", invitation }
            };

            foreach (var to in invitation.To.Where(to => to != null))
            {
                var eventItem = new EventItem
                {
                    AnonymId       = logEvent.AnonymId,
                    Project        = project,
                    ClientId       = logEvent.ClientId,
                    CustomUri      = actionLink.CustomUri,
                    BrowserBrand   = logEvent.BrowserBrand,
                    BrowserVersion = logEvent.BrowserVersion,
                    MobileDevice   = logEvent.MobileDevice,
                    ReferrerUrl    = logEvent.ReferrerUrl
                };
                await _workflowInvoker.InvokeAsync(new ActionActivityContext(
                                                       project : project,
                                                       action : action,
                                                       authTicket : authTicket,
                                                       contact : to,
                                                       contactState : ObjectState.Unchanged,
                                                       properties : properties,
                                                       eventItem : eventItem), cancellationToken);
            }
        }