/// <summary>
        /// Remove synchronize keys from Outlook contact. In same delete all cache data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOutlokSync_Click(object sender, EventArgs e)
        {
            LoggerProvider.Instance.Logger.Info("User request for clear synchronize keys in Outlook. I remove all cache data for Google and Outlook.");
            Utils.RemoveCacheFile(false);
            Utils.RemoveCacheFile(true);
            pBar.Value = 1;
            pBar.Update();
            pBar.Refresh();
            OutlookProvider op = OutlookProvider.Instance;

            Outlook.Items it             = op.OutlookItems();
            int           _ouMaxContacts = op.CountContact();
            object        works          = null;

            Outlook.ContactItem oci = null;
            int counter             = 0;

            for (int i = 0; i < _ouMaxContacts; i++)
            {
                pBar.Value = counter;
                pBar.PerformStep();
                pBar.Refresh();
                if (counter > pBar.Maximum)
                {
                    counter = 0;
                }
                if (i == 0)
                {
                    works = it.GetFirst();
                }
                else
                {
                    works = it.GetNext();
                }
                if (works is Outlook.DistListItem)
                {
                    continue;
                }
                oci = works as Outlook.ContactItem;
                if (works == null)
                {
                    continue;
                }
                if (!string.IsNullOrEmpty(oci.User3))
                {
                    oci.User3 = string.Empty;
                    oci.Save();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Step first - read all outlook contacts
        /// </summary>
        private void Step1ReadOutlook()
        {
            bool          IsNeedReadAllData = true;
            bool          IsNeedReadNewData = false;
            List <string> toread            = new List <string>(); /// list EntryID for reading
            List <string> todelete          = new List <string>(); /// list EntryID for delete

            if (SettingsProvider.Instance.IsUseOutlookCache)
            {
                LoggerProvider.Instance.Logger.Debug("Read data from cache for Outlook");
                ouCacheTime = Utils.LoadCacheDate(true);
                ouContacts  = Utils.ReadOutlookFromCache(ref ouCacheTime);
                if ((ouCacheTime > DateTime.MinValue) && (ouCacheTime < DateTime.Now) && (ouContacts.Count > 0)) // Data read from cache is good
                {
                    //_lastStatistic.ouReadContacts = ouContacts.Count;
                    Dictionary <string, DateTime> ouall = OutlookProvider.Instance.GetTableFilter(ouCacheTime);
                    DateTime ouDate;

                    foreach (string s in ouContacts.Keys)
                    {
                        todelete.Add(s);
                    }

                    foreach (string EntID in ouall.Keys)
                    {
                        ouDate = ouall[EntID];
                        if (ouContacts.ContainsKey(EntID)) /// is EntID found in current cached data
                        {
                            todelete.Remove(EntID);
                            if (((OneContact)ouContacts[EntID])._ModifyDateTime < ouDate) //date from curent select is
                            {
                                ouContacts.Remove(EntID);
                                toread.Add(EntID);
                            }
                        }
                        else
                        {
                            toread.Add(EntID);
                        }
                    }
                    /// in toread now only new EntryID
                    /// in todelete now only contact deleted in outlook, this need clear from cache, because in last two steps it delete from google to
                    foreach (string s in todelete)
                    {
                        ouContacts.Remove(s);
                    }
                    IsNeedReadNewData = toread.Count > 0;
                }
                else
                {
                    LoggerProvider.Instance.Logger.Debug("Data from Outlook cache isn't valid");
                }
            }
            if (IsNeedReadNewData) // need read new contact data to cache
            {
                LoggerProvider.Instance.Logger.Debug("Read only new data from Outlook");
                Outlook.Items it = op.OutlookItems();
                //_ouMaxContacts = op.CountContact();
                syncinfo.OutlookContacts = toread.Count;
                syncinfo.WorkOnMax       = toread.Count;
                Outlook.ContactItem oci = null;
                OneContact          oc  = null;
                object works            = null;
                int    i    = 0;
                int    read = 0;

                syncinfo.WorkOnNextStep();
                for (; i < toread.Count; i++)
                {
                    syncinfo.WorkOn = i + 1;
                    syncinfo.WorkOnNextStep();

                    works = OutlookProvider.Instance.FindItemfromID(toread[i]);

                    //if (i == 0)
                    //    works = it.GetFirst();
                    //else
                    //    works = it.GetNext();
                    if (works is Outlook.DistListItem)
                    {
                        continue;
                    }
                    oci = works as Outlook.ContactItem;
                    if (works == null)
                    {
                        continue;
                    }
                    if (toread.Contains(oci.EntryID))
                    {
                        oc = new OneContact(oci);
                        if (SettingsProvider.Instance.IsFirstTime)
                        {
                            oc.ClearReference();
                        }
                        ouContacts.Add(oci.EntryID, oc);
                    }
                    read++;
                }
                _lastStatistic.ouReadContacts += read;
                syncinfo.OutlookContacts       = ouContacts.Count;
                IsNeedReadAllData              = false;
            }
            if (IsNeedReadAllData)
            {
                /// because need read all data. Before this need remove all cached data
                ouContacts.Clear();
                /// start read all data
                ouCacheTime = DateTime.MinValue;
                LoggerProvider.Instance.Logger.Debug("Read all data from Outlook");
                Outlook.Items it = op.OutlookItems();
                _ouMaxContacts           = op.CountContact();
                syncinfo.OutlookContacts = _ouMaxContacts;
                syncinfo.WorkOnMax       = _ouMaxContacts;
                Outlook.ContactItem oci = null;
                OneContact          oc  = null;
                object works            = null;
                int    i    = 0;
                int    read = 0;

                syncinfo.WorkOnNextStep();
                for (; i < _ouMaxContacts; i++)
                {
                    syncinfo.WorkOn = i + 1;
                    syncinfo.WorkOnNextStep();
                    if (i == 0)
                    {
                        works = it.GetFirst();
                    }
                    else
                    {
                        works = it.GetNext();
                    }
                    if (works is Outlook.DistListItem)
                    {
                        continue;
                    }
                    oci = works as Outlook.ContactItem;
                    if (works == null)
                    {
                        continue;
                    }
                    oc = new OneContact(oci);
                    if (SettingsProvider.Instance.IsFirstTime)
                    {
                        oc.ClearReference();
                    }
                    ouContacts.Add(oci.EntryID, oc);
                    read++;
                }
                _lastStatistic.ouReadContacts += read;
                syncinfo.OutlookContacts       = ouContacts.Count;
            }
        }