コード例 #1
0
ファイル: DatabaseController.cs プロジェクト: thongvo/myfiles
 public bool SetAccountDefaultListEmailType(EmailType emailType)
 {
     DBManager db = new DBManager();
     return db.SetAccountDefaultListEmailType(emailType);
 }
コード例 #2
0
ファイル: DatabaseController.cs プロジェクト: thongvo/myfiles
 public bool SetPreferredListEmailType(EmailType emailType)
 {
     DBManager db = new DBManager();
     return db.SetPreferredListEmailType(emailType);
 }
コード例 #3
0
        private void GetContacts(string line)
        {
            EmailType VCFemailType = dbManager.GetPreferredEmailTypeByAccountTypeNameEF(AccountTypeDB.TYPE_VCF_STRING);
            string begin = "BEGIN:VCARD";
            string version = "VERSION:4.0";
            string end = "END:VCARD";
            string ms_design = "X-MS-OL-DESIGN";
            string ms_picture = "X-MS-CARDPICTURE";

            if (line.Equals(begin) || line.Equals(end) || line.Equals(version) || line.Contains(ms_picture) || line.Contains(ms_design))
            {
                isVCFFormat = true;
                return;
            }

            if (contactVCF == null)
            {
                List<Email> listEmail = new List<Email>();
                List<Fax> listFax = new List<Fax>();
                var accountvcf = dbManager.GetVCFAccount();
                contactVCF = new CMData.Contact
                {
                    Emails = listEmail,
                    Faxes = listFax,
                    AccountId = accountvcf.Id,
                    Accounts = accountvcf
                };
            }

            if (line.Contains("FN;CHARSET=utf-8:"))
            {
                return;
            }
            else if (line.Contains("N;CHARSET=utf-8:") || line.Contains("LANGUAGE=en-us:") || (line.Contains("N:") && line.Contains(";")))
            {
                var tmp = line.Split(':');
                if (tmp.Count() > 0)
                {
                    try
                    {
                        var name = tmp[1].Split(new string[] { ";" }, StringSplitOptions.None);
                        if (name.Count() > 0)
                        {
                            contactVCF.FirstName = name[1] !=null ? name[1] : "" ;
                            contactVCF.LastName = name[0] != null ? name[0] : "";
                            contactVCF.MiddleName = name[2] != null ? name[2] : "";
                        }
                    }
                    catch {
                        isVCFFormat = false;
                        return;
                    }
                }
            }
            else if (line.Contains("EMAIL;") || line.Contains("EMAIL;type=INTERNET"))
            {
                var prefered = -1;

                Email email = new Email();
                EmailType emType = new EmailType();

                if (line.Contains("type=HOME"))
                {                      
                    emType.Name = EmailTypeDB.VCF_EMAIL_TYPE_HOME_STRING;
                }
                else if (line.Contains("type=WORK"))
                {
                    emType.Name = EmailTypeDB.VCF_EMAIL_TYPE_WORK_STRING;
                }
                else
                {
                    //Others
                    emType.Name = EmailTypeDB.VCF_EMAIL_TYPE_OTHER_STRING;
                }

                if (line.Contains("PREF") || line.Contains("pref") || line.Contains("type=pref") || line.Contains("type=PREF"))
                {
                    prefered = 1;
                    emType.Preferred = prefered;
                    //set Email Type = UI setting of VCF
                    emType.Name = VCFemailType.Name;
                }

                var emailSplit = line.Split(':');
                if (emailSplit.Count() > 0)
                {
                    if (!string.IsNullOrEmpty(emailSplit[1]))
                    {
                        emType.AccountType = new AccountType { Name = AccountTypeDB.TYPE_VCF_STRING };
                        email.Value = emailSplit[1];
                        email.EmailType = emType;
                        email.EmailTypeId = emType.Id;
                        contactVCF.Emails.Add(email);                      
                    }
                }
            }
            else if (line.Contains("TEL") && (line.Contains("FAX:") || line.Contains("type=FAX")))
            {
                Fax fax = new Fax();
                FaxType fxType = new FaxType();
                if (line.Contains("HOME;") || line.Contains("type=HOME"))
                {
                    fxType.Name = FaxTypeDB.VCF_FAX_TYPE_HOME_STRING;
                }
                else if (line.Contains("WORK;") || line.Contains("type=WORK"))
                {
                    fxType.Name = FaxTypeDB.VCF_FAX_TYPE_WORK_STRING;
                }
                else
                {
                    // Others
                    fxType.Name = FaxTypeDB.VCF_FAX_TYPE_OTHER_STRING;
                }
                var tmp = line.Split(':');
                if (tmp.Count() > 0)
                {
                    fxType.AccountType = new AccountType { Name = AccountTypeDB.TYPE_VCF_STRING };
                    fax.Value = tmp[1];
                    fax.FaxType = fxType;
                    contactVCF.Faxes.Add(fax);
                }
            }   
        }
コード例 #4
0
        private void AddOrUpdateContactsToDatabase()
        {
            if (isUserCancel)
            {
                return;
            }
            var list = new List<Contact>();
            int count = listContact.Count();
            LiveContact lContact;
            for (int i = 0; i < count; i++)
            {
                lContact = listContact[i];
                var contact = new Contact();
                contact.AccountId = account.Id;
                contact.Id = -1;
                contact.FirstName = lContact.First_name;
                contact.LastName = lContact.Last_name;

                // add list email
                List<Email> listEmail = new List<Email>();
                List<TypeAndValue> emails = lContact.Emails;
                int size = emails.Count();
                TypeAndValue typeAndValue;
                for (int j = 0; j < size; j++)
                {
                    typeAndValue = emails[j];
                    var emailDB = new Email();
                    emailDB.Value = typeAndValue.Value;
                    EmailType emailType = new EmailType();
                    string type = typeAndValue.Type;
                    if (type.Equals("personal"))
                    {
                        emailType.Name = EmailTypeDB.LIVE_EMAIL_TYPE_PERSONAL_STRING;
                    }
                    else if (type.Equals("business"))
                    {
                        emailType.Name = EmailTypeDB.LIVE_EMAIL_TYPE_BUSINESS_STRING;
                    }
                    else
                    {
                        emailType.Name = EmailTypeDB.LIVE_EMAIL_TYPE_OTHER_STRING;
                    }

                    emailType.AccountType = new AccountType { Name = AccountTypeDB.TYPE_LIVE_HOTMAIL_STRING };
                    emailDB.EmailType = emailType;
                    listEmail.Add(emailDB);
                }
                contact.Emails = listEmail;

                // add list fax
                var listFax = new List<Fax>();
                List<TypeAndValue> phones = lContact.Phones;
                size = phones.Count();
                for (int j = 0; j < size; j++)
                {
                    typeAndValue = phones[j];
                    string type = typeAndValue.Type;
                    if (type.EndsWith("fax"))
                    {
                        var faxDB = new Fax();
                        faxDB.Value = typeAndValue.Value;
                        FaxType faxType = new FaxType();
                        if (type.Equals("home_fax"))
                        {
                            faxType.Name = FaxTypeDB.LIVE_FAX_TYPE_HOME_STRING;
                        }
                        else if (type.Equals("work_fax"))
                        {
                            faxType.Name = FaxTypeDB.LIVE_FAX_TYPE_WORK_STRING;
                        }

                        faxType.AccountType = new AccountType { Name = AccountTypeDB.TYPE_LIVE_HOTMAIL_STRING };
                        faxDB.FaxType = faxType;
                        listFax.Add(faxDB);
                    }
                }
                contact.Faxes = listFax;

                list.Add(contact);
            }

            CheckMaximumAndImport(list);
        }
コード例 #5
0
        private async void AddOrUpdateContactsToDatabase()
        {
            if (isUserCancel)
            {
                return;
            }

            AddOrUpdateAccountWhenImportingFromAccount();

            List<Contact> list = new List<Contact>();
            foreach (GoogleContact gContact in listContact)
            {
                Contact contact = new Contact();
                contact.AccountId = account.Id;
                //contact.AccountTypeName = AccountTypeDB.TYPE_GMAIL_STRING;

                //contact.Id = -1;
                contact.FirstName = gContact.GivenName != null ? gContact.GivenName : string.Empty;
                contact.MiddleName = gContact.MiddleName != null ? gContact.MiddleName : string.Empty;
                contact.LastName = gContact.FamilyName != null ? gContact.FamilyName : string.Empty;

                // add list email
                List<Email> listEmail = new List<Email>();
                var hasHomeEmail = false;
                var hasWorkEmail = false;
                var hasOtherEmail = false;

                foreach (TypeAndValue email in gContact.Emails)
                {
                    Email emailDB = new Email();
                    emailDB.Value = email.Value;
                    EmailType emailType = new EmailType();

                    string type = email.Type;
                    if (String.Compare(type, "home") == 0)
                    {
                        if (!hasHomeEmail)
                        {
                            hasHomeEmail = true;
                            emailType.Name = EmailTypeDB.GMAIL_EMAIL_TYPE_HOME_STRING;
                        }
                    }
                    else if (String.Compare(type, "work") == 0)
                    {
                        if (!hasWorkEmail)
                        {
                            hasWorkEmail = true;
                            emailType.Name = EmailTypeDB.GMAIL_EMAIL_TYPE_WORK_STRING;
                        }
                    }
                    else
                    {
                        if (!hasOtherEmail)
                        {
                            hasOtherEmail = true;
                            emailType.Name = EmailTypeDB.GMAIL_EMAIL_TYPE_OTHER_STRING;
                        }
                    }

                    if (emailType.Name != null)
                    {
                        emailDB.EmailType = emailType;
                        emailType.AccountType = new AccountType { Name = AccountTypeDB.TYPE_GMAIL_STRING };
                        listEmail.Add(emailDB);
                    }
                }
                contact.Emails = listEmail;

                // add list fax
                List<Fax> listFax = new List<Fax>();
                var hasHomeFax = false;
                var hasWorkFax = false;

                foreach (TypeAndValue phone in gContact.Phones)
                {
                    string type = phone.Type;
                    if (type.EndsWith("fax"))
                    {
                        Fax fax = new Fax();
                        fax.Value = phone.Value;
                        FaxType faxType = new FaxType();
                        if (String.Compare(type, "home_fax") == 0)
                        {
                            if (!hasHomeFax)
                            {
                                hasHomeFax = true;
                                faxType.Name = FaxTypeDB.GMAIL_FAX_TYPE_HOME_STRING;
                            }
                        }
                        else if (String.Compare(type, "work_fax") == 0)
                        {
                            if (!hasWorkFax)
                            {
                                hasWorkFax = true;
                                faxType.Name = FaxTypeDB.GMAIL_FAX_TYPE_WORK_STRING;
                            }
                        }

                        if (faxType.Name != null)
                        {
                            faxType.AccountType = new AccountType { Name = AccountTypeDB.TYPE_GMAIL_STRING };
                            //fax.AccountTypeName = AccountTypeDB.TYPE_GMAIL_STRING;
                            fax.FaxType = faxType;
                            listFax.Add(fax);
                        }
                    }
                }

                contact.Faxes = listFax;

                list.Add(contact);
            }
            await Task.Factory.StartNew(() =>
            {
                CheckMaximumAndImport(list);
            });            
        }