Ejemplo n.º 1
0
 /// <summary>
 /// Deal, in CRM, with items deleted in Outlook.
 /// </summary>
 protected void RemoveDeletedItems()
 {
     if (IsCurrentView && PropagatesLocalDeletions)
     {
         // Make a copy of the list to avoid mutation error while iterating:
         var syncStatesCopy = new List <SyncState <OutlookItemType> >(ItemsSyncState);
         foreach (var oItem in syncStatesCopy)
         {
             var shouldDeleteFromCrm = oItem.IsDeletedInOutlook || !oItem.ShouldSyncWithCrm;
             if (shouldDeleteFromCrm)
             {
                 RemoveFromCrm(oItem);
             }
             if (oItem.IsDeletedInOutlook)
             {
                 ItemsSyncState.Remove(oItem);
             }
         }
     }
     else
     {
         var items = ItemsSyncState.Where(x => x.IsDeletedInOutlook).Count();
         if (items > 0)
         {
             Log.Error($"Possibly bug #95: was attempting to delete {items} items from CRM");
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Synchronise items in the specified folder with the specified SuiteCRM module.
        /// </summary>
        /// <remarks>
        /// TODO: candidate for refactoring upwards, in concert with AppointmentSyncing.SyncFolder.
        /// </remarks>
        /// <param name="folder">The folder.</param>
        private void SyncFolder(Outlook.MAPIFolder folder)
        {
            Log.Info($"ContactSyncing.SyncFolder: '{folder}'");
            try
            {
                if (HasAccess("Contacts", "export"))
                {
                    var untouched  = new HashSet <SyncState <Outlook.ContactItem> >(ItemsSyncState);
                    int nextOffset = -1; // offset of the next page of entries, if any.

                    for (int iOffset = 0; iOffset != nextOffset; iOffset = nextOffset)
                    {
                        eGetEntryListResult entriesPage = clsSuiteCRMHelper.GetEntryList("Contacts",
                                                                                         "contacts.assigned_user_id = '" + clsSuiteCRMHelper.GetUserId() + "'",
                                                                                         0, "date_entered DESC", iOffset, false, clsSuiteCRMHelper.GetSugarFields("Contacts"));
                        nextOffset = entriesPage.next_offset;
                        if (iOffset != nextOffset)
                        {
                            UpdateItemsFromCrmToOutlook(entriesPage.entry_list, folder, untouched);
                        }
                    }
                    try
                    {
                        // Create the lists first, because deleting items changes the value of 'ExistedInCrm'.
                        var syncableButNotOnCrm = untouched.Where(s => s.ShouldSyncWithCrm);
                        var toDeleteFromOutlook = syncableButNotOnCrm.Where(a => a.ExistedInCrm).ToList();
                        var toCreateOnCrmServer = syncableButNotOnCrm.Where(a => !a.ExistedInCrm).ToList();

                        foreach (var item in toDeleteFromOutlook)
                        {
                            LogItemAction(item.OutlookItem, "ContactSyncing.SyncFolder, deleted item");
                            item.OutlookItem.Delete();
                            ItemsSyncState.Remove(item);
                        }

                        foreach (var oItem in toCreateOnCrmServer)
                        {
                            AddOrUpdateItemFromOutlookToCrm(oItem.OutlookItem);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("ContactSyncing.SyncContacts", ex);
                    }
                }
                else
                {
                    Log.Warn("ContactSyncing.SyncContacts: CRM server denied access to export Contacts");
                }
            }
            catch (Exception ex)
            {
                Log.Error("ContactSyncing.SyncContacts", ex);
            }
        }
Ejemplo n.º 3
0
 protected void RemoveDeletedItems()
 {
     if (IsCurrentView && PropagatesLocalDeletions)
     {
         // Make a copy of the list to avoid mutation error while iterating:
         var syncStatesCopy = new List <SyncState <OutlookItemType> >(ItemsSyncState);
         foreach (var oItem in syncStatesCopy)
         {
             var shouldDeleteFromCrm = oItem.IsDeletedInOutlook || !oItem.ShouldSyncWithCrm;
             if (shouldDeleteFromCrm)
             {
                 RemoveFromCrm(oItem);
             }
             if (oItem.IsDeletedInOutlook)
             {
                 ItemsSyncState.Remove(oItem);
             }
         }
     }
 }
Ejemplo n.º 4
0
        private void SyncFolder(Outlook.MAPIFolder tasksFolder)
        {
            Log.Warn("SyncTasks");
            Log.Warn("My UserId= " + clsSuiteCRMHelper.GetUserId());
            try
            {
                var untouched = new HashSet <SyncState <Outlook.TaskItem> >(ItemsSyncState);
                int iOffset   = 0;
                while (true)
                {
                    eGetEntryListResult _result2 = clsSuiteCRMHelper.GetEntryList("Tasks", String.Empty,
                                                                                  0, "date_start DESC", iOffset, false, clsSuiteCRMHelper.GetSugarFields("Tasks"));
                    var nextOffset = _result2.next_offset;
                    if (iOffset == nextOffset)
                    {
                        break;
                    }

                    foreach (var oResult in _result2.entry_list)
                    {
                        try
                        {
                            var state = UpdateFromCrm(tasksFolder, oResult);
                            if (state != null)
                            {
                                untouched.Remove(state);
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error("ThisAddIn.SyncTasks", ex);
                        }
                    }

                    iOffset = nextOffset;
                    if (iOffset == 0)
                    {
                        break;
                    }
                }
                try
                {
                    var lItemToBeDeletedO = untouched.Where(a => a.ExistedInCrm);
                    foreach (var oItem in lItemToBeDeletedO)
                    {
                        oItem.OutlookItem.Delete();
                        ItemsSyncState.Remove(oItem);
                    }

                    var lItemToBeAddedToS = untouched.Where(a => !a.ExistedInCrm);
                    foreach (var oItem in lItemToBeAddedToS)
                    {
                        AddToCrm(oItem.OutlookItem);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("ThisAddIn.SyncTasks", ex);
                }
            }
            catch (Exception ex)
            {
                Log.Error("ThisAddIn.SyncTasks", ex);
            }
        }