public void ShouldWrapExceptionInDispatchingException() { var raisedException = new InvalidOperationException("Update not possible"); ISynchronizationAction <LocalTestResource> action = new SynchronizationAction <LocalTestResource, string>( "bogus" , (resource, s) => { throw raisedException; } , new LocalTestResource(1) , "TestAction"); try { _stepUnderTest.Process(action); Assert.Fail("Expecting DispatchingException"); } catch (DispatchingException ex) { Assert.AreEqual(raisedException, ex.InnerException); Assert.AreEqual($"Failed executing action TestAction on {action.Applicant}!", ex.Message); } }
public void ShouldWrapExceptionInDispatchingException() { var raisedException = new InvalidOperationException("Update not possible"); ISynchronizationAction<LocalTestResource> action = new SynchronizationAction<LocalTestResource, string>( "bogus" , (resource, s) => { throw raisedException; } , new LocalTestResource(1) , "TestAction"); try { _stepUnderTest.Process(action); Assert.Fail("Expecting DispatchingException"); } catch (DispatchingException ex) { Assert.AreEqual(raisedException, ex.InnerException); Assert.AreEqual($"Failed executing action TestAction on {action.Applicant}!", ex.Message); } }
private void PublishSynchronizationNotification(string fileName, ServerInfo sourceServer, SynchronizationType type, SynchronizationAction action) { Publisher.Publish(new SynchronizationUpdate { FileName = fileName, SourceServerUrl = sourceServer.Url, SourceServerId = sourceServer.Id, Type = type, Action = action, SynchronizationDirection = SynchronizationDirection.Incoming }); }
private void PublishSynchronizationNotification(string fileSystemName, string fileName, ServerInfo sourceServer, SynchronizationType type, SynchronizationAction action) { Publisher.Publish(new SynchronizationUpdateNotification { FileName = fileName, SourceFileSystemUrl = sourceServer.FileSystemUrl, SourceServerId = sourceServer.Id, Type = type, Action = action, Direction = SynchronizationDirection.Incoming }); }
private static async Task <ICollection <Tuple <ICollection <ItemRelationPreview>, IItemSideRunner> > > ProcessRelations(ICollection <ItemRelationPreview> relations, IItemSideRunner runItemSide, SynchronizationAction action, int level = 1) { if (!relations.Any()) { return(Enumerable.Empty <Tuple <ICollection <ItemRelationPreview>, IItemSideRunner> >().ToList()); } List <Tuple <ICollection <ItemRelationPreview>, IItemSideRunner> > nextLevels = new List <Tuple <ICollection <ItemRelationPreview>, IItemSideRunner> >(); foreach (var rel in relations) { var runSubItem = runItemSide.SubItems.Single(si => si.Id == rel.Id); var runSubItemSide = runSubItem.SideRunners.First(); var runSubSide = runSubItemSide.Side; var subMap = new Func <IItemRunner, IItemSideRunner, object>((i, s) => { if (runSubSide.Comparator.GetItemTypes().Item1.GetTypeInfo().IsAssignableFrom(runSubItem.MasterItem.GetType().GetTypeInfo())) { // Master is A in this comparator if (runSubItem.MasterItem != null) { return(runSubSide.Comparator.MapAToB(i.MasterItem, s.SideItem)); } } else { // Master is B in this comparator if (runSubItem.MasterItem != null) { return(runSubSide.Comparator.MapBToA(i.MasterItem, s.SideItem)); } } return(null); }); if (rel.IsEnabled && rel.Action == action && rel.Action == SynchronizationAction.Insert) { var newItem = subMap(runSubItem, runSubItemSide); await runSubSide.InsertAsync(newItem); foreach (var subItem in runSubItemSide.SubItems) { subItem.SideRunners.First().Side.Source = newItem; } } else if (rel.IsEnabled && rel.Action == action && rel.Action == SynchronizationAction.Update) { var newItem = subMap(runSubItem, runSubItemSide); await runSubSide.UpdateAsync(newItem); foreach (var subItem in runSubItemSide.SubItems) { subItem.SideRunners.First().Side.Source = newItem; } } else if (rel.IsEnabled && rel.Action == action && rel.Action == SynchronizationAction.Delete) { await runSubSide.DeleteAsync(runSubItemSide.SideItem); } if (rel.Relations.Any()) { nextLevels.Add(new Tuple <ICollection <ItemRelationPreview>, IItemSideRunner>(rel.Relations, runSubItemSide)); } } return(nextLevels); }
private static async Task <ICollection <Tuple <ICollection <ItemRelationPreview>, IItemSideRunner> > > ProcessWork(ICollection <ItemPreview> items, WorkRunner runner, SynchronizationAction action) { ICollection <Tuple <ICollection <ItemRelationPreview>, IItemSideRunner> > levels = new List <Tuple <ICollection <ItemRelationPreview>, IItemSideRunner> >(); foreach (var item in items) { var runItem = runner.Items.Single(i => i.Id == item.Id); foreach (var side in item.Sides) { var runSide = runner.Sides.Single(s => s.Id == side.Id); var runItemSide = runItem.SideRunners.Single(s => s.Side.Id == side.Id); var map = new Func <IItemRunner, IItemSideRunner, object>((i, s) => { if (runSide.Comparator.GetItemTypes().Item1 == runner.MasterSide.GetItemType()) { // Master is A in this comparator if (item.MasterItemExist) { return(runSide.Comparator.MapAToB(i.MasterItem, s.SideItem)); } } else { // Master is B in this comparator if (item.MasterItemExist) { return(runSide.Comparator.MapBToA(i.MasterItem, s.SideItem)); } } return(null); }); if (side.IsEnabled && side.Action == action && side.Action == SynchronizationAction.Insert) { var newItem = map(runItem, runItemSide); await runSide.InsertAsync(newItem); foreach (var subItem in runItemSide.SubItems) { subItem.SideRunners.First().Side.Source = newItem; } } else if (side.IsEnabled && side.Action == action && side.Action == SynchronizationAction.Update) { var newItem = map(runItem, runItemSide); await runSide.UpdateAsync(newItem); foreach (var subItem in runItemSide.SubItems) { subItem.SideRunners.First().Side.Source = newItem; } } else if (side.IsEnabled && side.Action == action && side.Action == SynchronizationAction.Delete) { await runSide.DeleteAsync(runItemSide.SideItem); } levels.Add(new Tuple <ICollection <ItemRelationPreview>, IItemSideRunner>(side.Relations, runItemSide)); } } return(levels); }
string getAction(SynchronizationAction a) { switch (a) { case SynchronizationAction.Nothing: return "<font color=\"gray\">None</font>"; case SynchronizationAction.Download: return "Download"; case SynchronizationAction.Upload: return "Upload"; case SynchronizationAction.DeleteLocal: return "Deleted locally"; case SynchronizationAction.DeleteExternal: return "Deleted externally"; default: return Utils.GetFriendlyName(a.ToString()); } }
ProcessRelations(ICollection <ItemRelationPreview> relations, IItemSideRunner runItemSide, SynchronizationAction action) { if (!relations.Any()) { return(Enumerable.Empty <(ICollection <ItemRelationPreview>, IItemSideRunner)>().ToList(), () => Task.FromResult(0)); } var levels = new List <(ICollection <ItemRelationPreview>, IItemSideRunner)>(); var processActions = new List <Func <Task> >(); foreach (var rel in relations) { var runSubItem = runItemSide.SubItems.Single(si => si.Id == rel.Id); var runSubItemSide = runSubItem.SideRunners.First(); // ----- processActions.Add(new Func <Task>(async() => { var runSubSide = runSubItemSide.Side; var subMap = new Func <IItemRunner, IItemSideRunner, object>((i, s) => { if (runSubSide.Comparator.GetItemTypes().typeA.GetTypeInfo().IsAssignableFrom(runSubItem.MasterItem.GetType().GetTypeInfo())) { // Master is A in this comparator if (runSubItem.MasterItem != null) { return(runSubSide.Comparator.MapAToB(i.MasterItem, s.SideItem)); } } else { // Master is B in this comparator if (runSubItem.MasterItem != null) { return(runSubSide.Comparator.MapBToA(i.MasterItem, s.SideItem)); } } return(null); }); if (rel.IsEnabled && rel.Action == action && rel.Action == SynchronizationAction.Insert) { var newItem = subMap(runSubItem, runSubItemSide); await runSubSide.InsertAsync(newItem); foreach (var subItem in runSubItemSide.SubItems) { subItem.SideRunners.First().Side.Source = newItem; } } else if (rel.IsEnabled && rel.Action == action && rel.Action == SynchronizationAction.Update) { var newItem = subMap(runSubItem, runSubItemSide); await runSubSide.UpdateAsync(newItem); foreach (var subItem in runSubItemSide.SubItems) { subItem.SideRunners.First().Side.Source = newItem; } } else if (rel.IsEnabled && rel.Action == action && rel.Action == SynchronizationAction.Delete) { await runSubSide.DeleteAsync(runSubItemSide.SideItem); } })); // ----- if (rel.Relations.Any()) { levels.Add((rel.Relations, runSubItemSide)); } } return(levels, processActions.Transform(acts => new Func <Task>(async() => { foreach (var act in acts) { await act(); } }))); }
ProcessWork(ICollection <ItemPreview> items, WorkRunner runner, SynchronizationAction action) { var levels = new List <(ICollection <ItemRelationPreview>, IItemSideRunner)>(); var processActions = new List <Func <Task> >(); foreach (var item in items) { var runItem = runner.Items.Single(i => i.Id == item.Id); foreach (var side in item.Sides) { var runSide = runner.Sides.Single(s => s.Id == side.Id); var runItemSide = runItem.SideRunners.Single(s => s.Side.Id == side.Id); // ---- processActions.Add(new Func <Task>(async() => { var map = new Func <IItemRunner, IItemSideRunner, object>((i, s) => { if (runSide.Comparator.GetItemTypes().typeA == runner.MasterSide.GetItemType()) { // Master is A in this comparator if (item.MasterItemExist) { return(runSide.Comparator.MapAToB(i.MasterItem, s.SideItem)); } } else { // Master is B in this comparator if (item.MasterItemExist) { return(runSide.Comparator.MapBToA(i.MasterItem, s.SideItem)); } } return(null); }); if (side.IsEnabled && side.Action == action && side.Action == SynchronizationAction.Insert) { var newItem = map(runItem, runItemSide); await runSide.InsertAsync(newItem); foreach (var subItem in runItemSide.SubItems) { subItem.SideRunners.First().Side.Source = newItem; } } else if (side.IsEnabled && side.Action == action && side.Action == SynchronizationAction.Update) { var newItem = map(runItem, runItemSide); await runSide.UpdateAsync(newItem); foreach (var subItem in runItemSide.SubItems) { subItem.SideRunners.First().Side.Source = newItem; } } else if (side.IsEnabled && side.Action == action && side.Action == SynchronizationAction.Delete) { await runSide.DeleteAsync(runItemSide.SideItem); } })); // ---- levels.Add((side.Relations, runItemSide)); } } return(levels, processActions.Transform(acts => new Func <Task>(async() => { foreach (var act in acts) { await act(); } }))); }