public Entities.SdkMessageProcessingStep[] Cleanup(Entities.SdkMessageProcessingStep[] steps, Models.Plugin[] plugins) { List <Entities.SdkMessageProcessingStep> remains = new List <SdkMessageProcessingStep>(); foreach (var plugin in plugins) { if (plugin.CurrentCrmInstance != null) { foreach (var step in plugin.Steps) { var name = plugin.NameOf(step.Stage, step.Message, step.IsAsync, step.PrimaryEntityLogicalName); var exists = (from s in steps where s.Name == name select s).ToArray(); if (exists.Length > 0) { remains.Add(exists[0]); } } } } var removes = (from s in steps where !remains.Contains(s) && s.Stage.Value != 30 select s).ToArray(); foreach (var remove in removes) { uow.Delete(remove); this.messageService.Inform($"Removed step {remove.Name} on {remove.LogicalName}."); } return(remains.ToArray()); }
private void Delete(Entities.PluginType pluginType) { var steps = (from s in uow.SdkMessageProcessingSteps.GetQuery() where s.EventHandler.Id == pluginType.PluginTypeId select s).ToArray(); foreach (var step in steps) { var images = (from i in uow.SdkMessageProcessingStepImages.GetQuery() where i.SdkMessageProcessingStepId.Id == step.SdkMessageProcessingStepId select i).ToArray(); foreach (var img in images) { uow.Delete(img); } uow.Delete(step); } uow.Delete(pluginType); messageService.Inform($"Removed plugin: {pluginType.Name}"); }