private List <StepHandler> BuildChain(string processTypeId)
        {
            StepHandler prevStep = null;

            List <StepHandler> auxSteps = new List <StepHandler>();
            string             jsonTxt  = ReadChainConfig(processTypeId);
            //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");
                        CloudBlockBlob      blockBlob      = container.GetBlockBlobReference(item.AssemblyName);
                        using (var fileStream = System.IO.File.OpenWrite(@".\" + item.AssemblyName))
                        {
                            blockBlob.DownloadToStream(fileStream);
                        }
                    }
                    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);
        }
Exemplo n.º 2
0
        private List <StepHandler> BuildChain(string processTypeId)
        {
            StepHandler prevStep = null;

            List <StepHandler> auxSteps = new List <StepHandler>();
            string             jsonTxt;

            try
            {
                //processTypeId + ".ChainConfig", this.GetType().FullName,

                jsonTxt = ReadConfig(processTypeId + ".ChainConfig");
            }
            catch (Exception)
            {
                throw new Exception("[Error at BuildChain] Process " + processTypeId + " Not Found, check ButlerConfiguration Table");
            }

            //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");
                        //CloudBlockBlob blockBlob = container.GetBlockBlobReference(item.AssemblyName);
                        //using (var fileStream = System.IO.File.OpenWrite(@".\" + item.AssemblyName))
                        //{
                        //    blockBlob.DownloadToStream(fileStream);
                        //}
                        //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);
        }