コード例 #1
0
ファイル: SyncHelpers.cs プロジェクト: JoeyVinc/CopyO2O
        /// <summary>
        /// Analyse and collect all sync jobs for the local Outlook instance.
        /// </summary>
        /// <param name="syncCache">The sync cache stored on disk</param>
        /// <param name="NewOutlookIds">All Ids which were added after the last sync job</param>
        /// <param name="ModifiedOutlookIds">All Ids which were modified after the last sync job</param>
        /// <param name="DeletedOutlookIds">All Ids which were removed after the last sync job</param>
        /// <param name="NewO365Ids">All Ids of Office 365 which were added after the last sync job</param>
        /// <param name="ModifiedO365Ids">All Ids of Office 365 which were modified after the last sync job</param>
        /// <param name="DeletedO365Ids">All Ids of Office 365 which were removed after the last sync job</param>
        /// <param name="Type">Type of the items to be processed (e.g. events or contacts)</param>
        /// <param name="clrNotExisting">If TRUE all items which were identified in O365 but not exist in Outlook will be removed as well</param>
        /// <returns>A list of sync jobs FROM Outlook TO Office365.</returns>
        ///
        private static List <SyncHelpers.SyncInfo> CollectOutlookSyncTasks(
            List <SyncHelpers.SyncInfo> syncCache,
            List <string> NewOutlookIds, List <string> ModifiedOutlookIds, List <string> DeletedOutlookIds,
            List <string> NewO365Ids, List <string> ModifiedO365Ids, List <string> DeletedO365Ids,
            SyncHelpers.ID_type Type,
            bool clrNotExisting)
        {
            List <SyncHelpers.SyncInfo> result = new List <SyncHelpers.SyncInfo>();

            //1st OUTLOOK is the leading system, 2nd only sync to O365
            //add new outlook-elemente to sync list
            NewOutlookIds.ForEach((id) => result.Add(new SyncHelpers.SyncInfo {
                OutlookID = id, Type = Type, SyncDirection = SyncHelpers.SyncDirection.ToRight, SyncWorkMethod = SyncHelpers.SyncMethod.CREATE
            }));

            //add modified outlook-elemente to sync list
            ModifiedOutlookIds.ForEach((id) =>
            {
                result.Add(new SyncHelpers.SyncInfo {
                    OutlookID = id, Type = Type, SyncDirection = SyncHelpers.SyncDirection.ToRight, SyncWorkMethod = SyncHelpers.SyncMethod.CREATE
                });
                result.Add(new SyncHelpers.SyncInfo {
                    O365ID = syncCache.Find(x => (x.OutlookID == id)).O365ID, Type = Type, SyncDirection = SyncHelpers.SyncDirection.ToRight, SyncWorkMethod = SyncHelpers.SyncMethod.DELETE
                });
            });

            //remove deleted outlook elements from o365
            DeletedOutlookIds.ForEach((id) => result.Add(new SyncHelpers.SyncInfo {
                O365ID = syncCache.Find(x => (x.OutlookID == id)).O365ID, Type = Type, SyncDirection = SyncHelpers.SyncDirection.ToRight, SyncWorkMethod = SyncHelpers.SyncMethod.DELETE
            }));

            //restore from Office 365 deleted outlook-contacts again
            DeletedO365Ids.ForEach((id) =>
            {
                result.Add(new SyncHelpers.SyncInfo {
                    OutlookID = syncCache.Find(x => (x.O365ID == id)).OutlookID, Type = Type, SyncDirection = SyncHelpers.SyncDirection.ToRight, SyncWorkMethod = SyncHelpers.SyncMethod.CREATE
                });
                SyncHelpers.syncCache.RemoveAll(x => (x.O365ID == id) && (x.Type == Type));
            });

            //if all items which does not exist in outlook should be removed from O365
            if (clrNotExisting)
            {
                NewO365Ids.ForEach((id) => result.Add(new SyncHelpers.SyncInfo {
                    O365ID = id, Type = Type, SyncDirection = SyncHelpers.SyncDirection.ToRight, SyncWorkMethod = SyncHelpers.SyncMethod.DELETE
                }));
            }

            return(result);
        }
コード例 #2
0
ファイル: SyncHelpers.cs プロジェクト: JoeyVinc/CopyO2O
        /// <summary>
        /// Creates items to O365
        /// </summary>
        /// <param name="syncWork">List of sync jobs to identify the items to create</param>
        /// <param name="o365_graphcontainer">The Office365 container of the items to create (e.g. calendar or contactfolder)</param>
        /// <param name="Type">Type of the items to be processed (e.g. events or contacts)</param>
        /// <returns>Returns count of jobs run.</returns>
        ///
        public static int CreateItems(List <SyncHelpers.SyncInfo> syncWork, IEnumerable <SyncElement> srcItems, Office365.IGraphContainer o365_graphcontainer, SyncHelpers.ID_type Type)
        {
            List <Task> createTasks = new List <Task>();

            syncWork.Where(x => ((x.SyncWorkMethod == SyncHelpers.SyncMethod.CREATE) && (x.Type == Type))).ToList().ForEach(
                (item) =>
            {
                createTasks.Add(o365_graphcontainer.AddAsync(srcItems.ToList().Find(x => (x.OriginId == item.OutlookID)))
                                .ContinueWith((i) => { if (i.Result != null)
                                                       {
                                                           SyncHelpers.O365_Item_Added(i.Result, item);
                                                       }
                                              }));
            });
            Task.WaitAll(createTasks.ToArray());
            return(createTasks.Count);
        }
コード例 #3
0
ファイル: SyncHelpers.cs プロジェクト: JoeyVinc/CopyO2O
        /// <summary>
        /// Removes items from O365
        /// </summary>
        /// <param name="syncWork">List of sync job to identify the items to remove.</param>
        /// <param name="o365_graphcontainer">The Office365 container of the items to delete (e.g. calendar or contactfolder)</param>
        /// <param name="Type">Type of the items to be processed (e.g. events or contacts)</param>
        /// <returns>Returns count of jobs run.</returns>
        ///
        public static int RemoveItems(List <SyncHelpers.SyncInfo> syncWork, Office365.IGraphContainer o365_graphcontainer, SyncHelpers.ID_type Type)
        {
            List <Task> deleteTasks = new List <Task>();

            syncWork.Where(x => ((x.SyncWorkMethod == SyncHelpers.SyncMethod.DELETE) && (x.Type == Type))).ToList().ForEach(
                (item) =>
            {
                deleteTasks.Add(o365_graphcontainer.RemoveAsync(item.O365ID)
                                .ContinueWith((i) => { if (i != null)
                                                       {
                                                           SyncHelpers.O365_Item_Removed(item);
                                                       }
                                              }));
            });
            Task.WaitAll(deleteTasks.ToArray());
            return(deleteTasks.Count);
        }
コード例 #4
0
ファイル: SyncHelpers.cs プロジェクト: JoeyVinc/CopyO2O
        /// <summary>
        /// Analyse all known items and systems and prepare all required information.
        /// </summary>
        /// <param name="clrNotExisting">If TRUE all items which were identified in O365 but not exist in Outlook will be removed as well</param>
        /// <param name="syncWork">The queue for sync jobs.</param>
        /// <param name="srcItems">All items of the source system (Outlook)</param>
        /// <param name="destItems">All items of the destination system (Office 365)</param>
        /// <param name="Type">Type of the items to be processed (e.g. events or contacts)</param>
        ///
        public static void AnalyseSyncJobs(bool clrNotExisting, List <SyncHelpers.SyncInfo> syncWork, IEnumerable <SyncElement> srcItems, IEnumerable <SyncElement> destItems, SyncHelpers.ID_type Type)
        {
            //get all events which are stored in the sync cache
            List <SyncHelpers.SyncInfo> syncCache_filtered = SyncHelpers.syncCache.Where(x => x.Type == Type).ToList();

            //define NEW, MODIFIED and DELETED events of the local Outlook
            List <string> tmpNewOutlookIds      = SyncHelpers.GetIDsOfNewItems(srcItems, syncCache_filtered, OriginSystemEnum.Outlook);      //all Outlook-ids which are NOT contained in sync cache => all NEW outlook ids
            List <string> tmpModifiedOutlookIds = SyncHelpers.GetIDsOfModifiedItems(srcItems, syncCache_filtered, OriginSystemEnum.Outlook); //all Outlook-ids which were modified AFTER the last sync
            List <string> tmpDeletedOutlookIds  = SyncHelpers.GetIDsOfDeletedItems(srcItems, syncCache_filtered, OriginSystemEnum.Outlook);  //all Outlook-ids which are synced but does not exist anymore => all DELETED outlook ids

            //define NEW, MODIFIED and DELETED events of Office 365
            List <string> tmpNewO365Ids      = SyncHelpers.GetIDsOfNewItems(destItems, syncCache_filtered, OriginSystemEnum.Office365);      //all O365-ids which are NOT contained in sync cache => all NEW O365 ids
            List <string> tmpModifiedO365Ids = SyncHelpers.GetIDsOfModifiedItems(destItems, syncCache_filtered, OriginSystemEnum.Office365); //all O365-ids which were modified AFTER the last sync
            List <string> tmpDeletedO365Ids  = SyncHelpers.GetIDsOfDeletedItems(destItems, syncCache_filtered, OriginSystemEnum.Office365);  //all ids of sync cache which does NOT exist in O365 anymore => all DELETED o365 ids

            syncWork.AddRange(SyncHelpers.CollectOutlookSyncTasks(
                                  syncCache: syncCache_filtered,
                                  NewOutlookIds: tmpNewOutlookIds, ModifiedOutlookIds: tmpModifiedOutlookIds, DeletedOutlookIds: tmpDeletedOutlookIds,
                                  NewO365Ids: tmpNewO365Ids, ModifiedO365Ids: tmpModifiedO365Ids, DeletedO365Ids: tmpDeletedO365Ids,
                                  Type: Type,
                                  clrNotExisting: clrNotExisting
                                  ));
        }