/// <summary> /// Set the next Step in the process /// </summary> /// <param name="nextStep">Nest Step in the process</param> public void SetSuccessor(StepHandler nextStep) { this.nextStep = nextStep; }
/// <summary> /// Build process step chaing base on process type configuration /// </summary> /// <param name="processTypeId"></param> /// <returns></returns> private List <StepHandler> BuildChain(string processTypeId) { StepHandler prevStep = null; List <StepHandler> auxSteps = new List <StepHandler>(); string jsonTxt; try { jsonTxt = ReadConfigOrDefault(processTypeId + ".ChainConfig"); if (string.IsNullOrEmpty(jsonTxt)) { throw new Exception(processTypeId + " Not Found, check ButlerConfiguration Table"); } } catch (Exception X) { throw new Exception("[Error at BuildChain] Process " + X.Message); } //Sensible config manually List <stepTypeInfo> StepList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <stepTypeInfo> >(jsonTxt); foreach (stepTypeInfo item in StepList) { //Build the chain //1. is the Assembly in bin? if (!File.Exists(item.AssemblyName)) { //try to download from storage try { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(myProcessConfigConn); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("mediabutlerbin"); //TODO: fix this is DLL exis and is it on use foreach (IListBlobItem dll in container.ListBlobs(null, false)) { Uri myUri = dll.Uri; int seg = myUri.Segments.Length - 1; string name = myUri.Segments[seg]; CloudBlockBlob blockBlob = container.GetBlockBlobReference(name); using (var fileStream = System.IO.File.OpenWrite(@".\" + name)) { blockBlob.DownloadToStream(fileStream); } } if (!File.Exists(item.AssemblyName)) { throw new Exception(item.AssemblyName + " don't exist"); } } catch (Exception X) { string txt = string.Format("[{0}] Error BuildChain Assembly {1} error: {2}", this.GetType().FullName, item.AssemblyName, X.Message); Trace.TraceError(txt); throw X; } } StepHandler obj = (StepHandler)Activator.CreateComInstanceFrom(item.AssemblyName, item.TypeName).Unwrap(); if ((item.ConfigKey != null) && (item.ConfigKey != "")) { //LOAD STRING CONFIGURATION FOR CONFIG TABLE obj.StepConfiguration = this.ReadConfigOrDefault(item.ConfigKey + ".StepConfig"); } auxSteps.Add(obj); if (prevStep != null) { prevStep.SetSuccessor(obj); } prevStep = obj; } return(auxSteps); }