/// <summary> /// Constructor /// </summary> /// <param name="Mappings">The mappings.</param> /// <param name="Services">The services.</param> /// <param name="Modules">The workflow modules.</param> /// <param name="WorkflowManager">The workflow manager.</param> public Manager(IEnumerable<IAPIMapping> Mappings, IEnumerable<IService> Services, IEnumerable<IWorkflowModule> Modules, Utilities.Workflow.Manager.Manager WorkflowManager) { Contract.Requires<ArgumentNullException>(Mappings != null); Contract.Requires<ArgumentNullException>(Services != null); Contract.Requires<ArgumentNullException>(Modules != null); Contract.Requires<ArgumentNullException>(WorkflowManager != null); this.WorkflowManager = WorkflowManager; this.Services = new Dictionary<int, ServiceHolder>(); this.Mappings = new Dictionary<int, MappingHolder>(); if (Mappings == null) return; foreach (IAPIMapping Mapping in Mappings) { foreach (int Version in Mapping.Versions) { if (!this.Mappings.ContainsKey(Version)) this.Mappings.Add(Version, new MappingHolder()); this.Mappings[Version].Mappings.Add(Mapping.Name, Mapping); } } if (Services == null) return; foreach (IService Service in Services) { foreach (int Version in Service.Versions) { if (!this.Services.ContainsKey(Version)) this.Services.Add(Version, new ServiceHolder()); this.Services[Version].Services.Add(Service.Name, Service); } } if (AppDomain.CurrentDomain.GetAssemblies() .Where(x => !x.FullName.Contains("vshost32") && !x.IsDynamic && !string.IsNullOrEmpty(x.Location)) .Any(x => new System.IO.FileInfo(x.Location).LastWriteTime <= WorkflowManager.LastModified)) return; foreach (int Version in this.Mappings.Keys) { foreach (IWorkflowModule Module in Modules.Where(x => x.Versions.Contains(Version))) { foreach (IAPIMapping Mapping in this.Mappings[Version]) { foreach (WorkflowType ActionType in Enum.GetValues(typeof(WorkflowType)) .OfType<WorkflowType>() .Where(x => !x.HasFlag(WorkflowType.PreService) && !x.HasFlag(WorkflowType.PostService) && Module.ActionsTypes.HasFlag(x))) { Module.Setup(Mapping.Name, WorkflowManager.CreateWorkflow<WorkflowInfo>(Mapping.Name + "_" + ActionType.ToString() + "_" + Version)); } } } } foreach (int Version in this.Services.Keys) { foreach (IWorkflowModule Module in Modules.Where(x => x.Versions.Contains(Version))) { foreach (IService Service in this.Services[Version]) { foreach (WorkflowType ActionType in new WorkflowType[] { WorkflowType.PreService, WorkflowType.PostService } .Where(x => Module.ActionsTypes.HasFlag(x))) { Module.Setup(Service.Name, WorkflowManager.CreateWorkflow<WorkflowInfo>(Service.Name + "_" + ActionType.ToString() + "_" + Version)); } } } } }