/// <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); }
/// <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); }