private void execute(CloudQueueMessage currentMessage)
        {
            ProcessRequest myRequest = null;
            string         txt;

            try
            {
                lock (myLock)
                {
                    currentProcessRunning += 1;
                }
                MediaButler.Common.ButlerRequest watcherRequest = Newtonsoft.Json.JsonConvert.DeserializeObject <ButlerRequest>(currentMessage.AsString);
                List <StepHandler> mysteps = BuildChain(watcherRequest.WorkflowName);
                myRequest = GetCurrentContext(watcherRequest.WorkflowName);
                myRequest.CurrentMessage    = currentMessage;
                myRequest.ProcessTypeId     = watcherRequest.WorkflowName;
                myRequest.ProcessInstanceId = watcherRequest.MessageId.ToString();
                myRequest.ProcessConfigConn = this.myProcessConfigConn;
                myRequest.IsResumeable      = (this.ReadConfigOrDefault(myRequest.ProcessTypeId + ".IsResumeable") == "1");
                //2.Execute Chain

                //lock (myLock)
                //{
                //    currentProcessRunning += 1;
                //}
                txt = string.Format("[{0}] Starting new Process, type {1} and ID {2}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId);
                Trace.TraceInformation(txt);
                mysteps.FirstOrDefault().HandleRequest(myRequest);
                //FinishProcess();
                txt = string.Format("[{0}] Finish Process, type {1} and ID {2}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId);
                Trace.TraceInformation(txt);
                lock (myLock)
                {
                    currentProcessRunning -= 1;
                }
            }
            catch (Exception xxx)
            {
                if (myRequest != null)
                {
                    foreach (Exception item in myRequest.Exceptions)
                    {
                        //Full Rollback?
                        txt = string.Format("[{0}] Error list process {1} intance {2} error: {3}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId, item.Message);
                        Trace.TraceError(txt);
                    }
                }
                else
                {
                    txt = string.Format("[{0}] Error {1} without context Request yet", this.GetType().FullName, xxx.Message);
                    Trace.TraceError(xxx.Message);
                }
                //Exception no Managed

                lock (myLock)
                {
                    currentProcessRunning -= 1;
                }
                // throw(X);
            }
            //3.return control
            if (myRequest != null)
            {
                myRequest.DisposeRequest();
            }
            else
            {
                Trace.TraceError("myRequest is null raw message " + currentMessage.AsString);
            }
            myRequest = null;

            Trace.Flush();
        }
Exemple #2
0
        private void execute(CloudQueueMessage currentMessage)
        {
            ProcessRequest myRequest = null;
            string         txt;

            Common.ResourceAccess.IButlerStorageManager storageManager = null;

            try
            {
                lock (myLock)
                {
                    currentProcessRunning += 1;
                }
                MediaButler.Common.ButlerRequest watcherRequest = Newtonsoft.Json.JsonConvert.DeserializeObject <ButlerRequest>(currentMessage.AsString);
                //Load Workflow's steps
                List <StepHandler> mysteps = BuildChain(watcherRequest.WorkflowName);

                myRequest = GetCurrentContext(watcherRequest.WorkflowName);
                myRequest.CurrentMessage = currentMessage;
                myRequest.ProcessTypeId  = watcherRequest.WorkflowName;
                //ProcessInstanceId:
                //Single File: MessageID Guid (random)
                //multiFile package: Container folder guid ID (set for client)
                myRequest.ProcessInstanceId = this.getProcessId(watcherRequest.ControlFileUri, watcherRequest.MessageId.ToString());

                myRequest.ProcessConfigConn = this.myProcessConfigConn;
                myRequest.IsResumeable      = (this.ReadConfigOrDefault(myRequest.ProcessTypeId + ".IsResumeable") == "1");

                //Restore Status
                storageManager = Common.ResourceAccess.BlobManagerFactory.CreateBlobManager(myRequest.ProcessConfigConn);
                myRequest      = restoreRequestOrCreateMetadata(myRequest, mysteps);

                //2.Execute Chain
                txt = string.Format("[{0}] Starting new Process, type {1} and ID {2}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId);
                Trace.TraceInformation(txt);
                mysteps.FirstOrDefault().HandleRequest(myRequest);
                //FinishProcess();
                txt = string.Format("[{0}] Finish Process, type {1} and ID {2}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId);
                Trace.TraceInformation(txt);
                //Finish Status
                myRequest.CurrentStepIndex = Configuration.successFinishProcessStep;
                storageManager.PersistProcessStatus(myRequest);

                lock (myLock)
                {
                    currentProcessRunning -= 1;
                }
            }
            catch (Exception xxx)
            {
                if (myRequest != null)
                {
                    //foreach (Exception item in myRequest.Exceptions)
                    foreach (string errorTxt in myRequest.Exceptions)
                    {
                        //Full Rollback?
                        txt = string.Format("[{0}] Error list process {1} intance {2} error: {3}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId, errorTxt);
                        Trace.TraceError(txt);
                    }
                    txt = string.Format("[{0}] Error list process {1} intance {2} error: {3}", this.GetType().FullName, myRequest.ProcessTypeId, myRequest.ProcessInstanceId, xxx.Message);
                    myRequest.Exceptions.Add(txt);

                    //Update Status
                    myRequest.CurrentStepIndex = Configuration.failFinishProcessStep;
                    storageManager.PersistProcessStatus(myRequest);
                }
                else
                {
                    txt = string.Format("[{0}] Error {1} without context Request yet", this.GetType().FullName, xxx.Message);
                    Trace.TraceError(xxx.Message);
                }
                //Exception no Managed

                lock (myLock)
                {
                    currentProcessRunning -= 1;
                }
            }
            //3.return control
            if (myRequest != null)
            {
                myRequest.DisposeRequest();
            }
            else
            {
                Trace.TraceError("myRequest is null raw message " + currentMessage.AsString);
            }
            myRequest = null;

            Trace.Flush();
        }