Ejemplo n.º 1
0
        /// <summary>
        /// Add one contact to Google
        /// </summary>
        /// <param name="c">Outlook contact to add</param>
        /// <returns>true if add success</returns>
        internal bool AddNewGoogleContact(OneContact c)
        {
            Google.Contacts.Contact goContact = null;
#warning There is a problem with add google contact with Image
#if (!SIMULATE_SAVE)
            Google.Contacts.Contact goContactNew = null;
            OneContact hlp = null;
#endif

            try
            {
                goContact = c.GetGoogle();
            }
            catch (Exception e)
            {
                /// Can't create Google Entity from OneContacs Class
                LoggerProvider.Instance.Logger.Error("Problem to read Google.Contacts.Contact from GoogleSynchronizer.OneContact");
                LoggerProvider.Instance.Logger.Error(e);
                return(false);;
            }
            if (goContact == null)
            {
                LoggerProvider.Instance.Logger.Error("Can't insert NULL object");
                return(false);
            }
#if (!SIMULATE_SAVE)
            goContactNew = GoogleProvider.GetProvider.Insert(goContact);
            // If don't insert new contact to Google need continue
            if (goContactNew == null)
            {
                return(false);
            }
#endif

#if (!SIMULATE_SAVE)
            hlp           = new OneContact(goContactNew);
            c.ReferenceID = hlp.ContactID;
            goContacts.Add(hlp.ContactID, hlp);
            c.UpdateRefInOutlook(hlp.CreateReferenceID());
#endif
            LoggerProvider.Instance.Logger.Debug("Save update to Outlook");

            #region DEBUG infos
#if (DEBUG1)
            LoggerProvider.Instance.Logger.Debug("Source contact MD5/Count MD5: {0}/{1}", c.MD5selfCount, Utils.CountMD5(c.SummAllData()));
            LoggerProvider.Instance.Logger.Debug(c.SummAllData());
            LoggerProvider.Instance.Logger.Debug("Destination contact MD5/Count MD5: {0}/{1}", hlp.MD5selfCount, Utils.CountMD5(hlp.SummAllData()));
            LoggerProvider.Instance.Logger.Debug(hlp.SummAllData());
            hlp = null;
#endif

            #endregion
            return(true);
        }
Ejemplo n.º 2
0
        private void Step7Update()
        {
            LoggerProvider.Instance.Logger.Debug("Start step 7 update contacts");
            syncinfo.WorkOnMax = goContacts.Count; // nastaveni prochazenych odkazu
            syncinfo.WorkOnNextStep();
            int updateGo  = 0;
            int updateOut = 0;
            int i         = 0;

            if (ouContacts.Count != goContacts.Count)
            {
                LoggerProvider.Instance.Logger.Error("Problem in check Update - number of contacts are different Outlook/Google: {0}/{1}",
                                                     ouContacts.Count, goContacts.Count);
                return;
            }
            OneContact    outItem = null;
            OneContact    goItem  = null;
            StringBuilder sb      = new StringBuilder();
            ArrayList     keys    = new ArrayList(goContacts.Keys);

            foreach (string s in keys)
            {
                syncinfo.WorkOn = ++i;
                syncinfo.WorkOnNextStep();
                goItem = (OneContact)goContacts[s];
                if (!ouContacts.ContainsKey(goItem.ReferenceID))
                {
                    LoggerProvider.Instance.Logger.Error("Contacts don't found in table");
                    continue;
                }
                outItem = (OneContact)ouContacts[goItem.ReferenceID];

                if (outItem.MD5selfCount != goItem.MD5selfCount)
                {
                    sb.Remove(0, sb.ToString().Length);
                    sb.AppendLine(string.Format("Update contact Outlook - Google: {0} - {1}", outItem._MyID, goItem._MyID));
                    sb.AppendLine(string.Format("User name: {0} {1}", outItem.FirstName, outItem.LastName));
                    sb.AppendLine(string.Format("MD5 Oulook/Google: {0} / {1}", outItem.MD5selfCount, goItem.MD5selfCount));
                    sb.AppendLine(string.Format("MD5 source:\r\n{0}\r\n{1}", outItem.SummAllData(), goItem.SummAllData()));
                    sb.AppendLine(string.Format("Last Update Outlook/Google:  {0} / {1}", outItem.UpdateTime, goItem.UpdateTime));
                    if (outItem.UpdateTime < goItem.UpdateTime) // What is olders
                    {
                        if (SettingsProvider.Instance.IsUpdateToOutlook)
                        {
                            sb.AppendLine("Update on Outlook");
                            updateOut += UpdateOutlookFromGoogle(goItem, outItem) ? 1 : 0;
                        }
                        else
                        {
                            sb.AppendLine("Update on Google thru configurate way to update");
                            updateGo += UpdateGoogleFromOutlook(outItem, goItem) ? 1 : 0;
                        }
                    }
                    else
                    {
                        if (SettingsProvider.Instance.IsUpdateToGoogle)
                        {
                            sb.AppendLine("Update on Google");
                            updateGo += UpdateGoogleFromOutlook(outItem, goItem) ? 1 : 0;
                        }
                        else
                        {
                            sb.AppendLine("Update on Outlook thru configurate way to update");
                            updateOut += UpdateOutlookFromGoogle(goItem, outItem) ? 1 : 0;
                        }
                    }
                    LoggerProvider.Instance.Logger.Debug(sb.ToString());
                }
            }
            _lastStatistic.goUpdateContacts += updateGo;
            _lastStatistic.ouUpdateContacts += updateOut;
        }