public void Execute()
        {
            // Read task body
            string taskMessageBody;

            using (var receiveStream = this.Request.Body)
            {
                using (var sr = new StreamReader(receiveStream, Encoding.UTF8))
                {
                    taskMessageBody = sr.ReadToEnd();
                }
            }

            // Since we expect all the VSTS properties to be in the request headers, fetch them from the headers
            //
            var taskProperties = GetTaskProperties(this.Request.Headers);

            // Create my own task execution handler. You should replace it with your task execution handler.
            ITaskExecutionHandler myTaskExecutionHandler = new MyTaskExecutionHandler();

            var executionHandler = new ExecutionHandler(myTaskExecutionHandler, taskMessageBody, taskProperties);
            var executionThread  = new Thread(() => executionHandler.Execute(CancellationToken.None));

            executionThread.Start();
        }
        /// <summary>
        ///     获取任务列表
        /// </summary>
        /// <param name="incedentId">事件编号</param>
        /// <returns>任务列表</returns>
        public List <ITask> GetTasks(string incedentId)
        {
            IExecutionHandler executionHandler = new ExecutionHandler();
            IList             taskIList        = executionHandler.GetTaskListFlowLog(incedentId);

            return(taskIList.Cast <ITask>().ToList());
        }
        public void NewExecutionSimulated_CreateNewTradeProcessor_OneTradeProcessorInExecutionHandlerForSimulated()
        {
            // Create new Execution Processor Object
            ExecutionHandler executionHandler = new ExecutionHandler();

            // Create Order Object
            Order order = new Order(OrderExecutionProvider.Simulated);

            // Create Fill Object
            Fill fill = new Fill(new Security()
            {
                Symbol = "GOOG"
            }, OrderExecutionProvider.Simulated, "1");

            fill.ExecutionId   = "1";
            fill.ExecutionSide = OrderSide.BUY;
            fill.ExecutionSize = 40;
            // Create Execution Object
            Execution execution = new Execution(fill, order);

            // Add new execution to the Execution Processor
            executionHandler.NewExecutionArrived(execution);

            var tradeFactories = executionHandler.TradeProcessorMap;

            Assert.AreEqual(1, tradeFactories.Count, "Trade Factory Count");
            Assert.AreEqual(OrderExecutionProvider.Simulated, tradeFactories[OrderExecutionProvider.Simulated][new Security()
                                                                                                               {
                                                                                                                   Symbol = "GOOG"
                                                                                                               }].ExecutionProvider, "Execution of Trade Factory");
        }
        /// <summary>
        ///     返回特定节点
        /// </summary>
        /// <param name="taskId">任务编号</param>
        /// <param name="stepId">要返回的节点编号</param>
        /// <param name="hashVariation">流程变量</param>
        /// <param name="desc">审核意见</param>
        public void ReturnTaskToStep(string taskId, string stepId, Hashtable hashVariation, string desc)
        {
            ITask task = GetTask(taskId);

            if (task == null)
            {
                throw new Exception(string.Format("无法获取taskId:{0}的任务", taskId));
            }
            task.Desc = desc;
            IExecutionHandler executionHandler = new ExecutionHandler();

            if (hashVariation == null)
            {
                hashVariation = new Hashtable();
            }
            ITask returnTask = GetRetrunTask(task.IncidentId, stepId);

            if (returnTask == null)
            {
                throw new ArgumentNullException("returnTask");
            }
            var returnTaskIds = new List <string> {
                returnTask.Id
            };
            int result = executionHandler.ReturnTaskToStepSelected(task, returnTaskIds, hashVariation);

            if (result != 0)
            {
                throw new Exception(string.Format("SubmitTask出错:{0}", result));
            }

            var mailHandler = new ExecutionHandler();

            mailHandler.SendMail(task, task.NextStepType);
        }
        /// <summary>
        ///     退回上一步
        /// </summary>
        /// <param name="taskId">任务编号</param>
        /// <param name="hashVariation">流程变量</param>
        /// <param name="desc">审核意见</param>
        public void ReturnPrevStep(string taskId, Hashtable hashVariation, string desc)
        {
            ITask task = GetTask(taskId);

            if (task == null)
            {
                throw new Exception(string.Format("无法获取taskId:{0}的任务", taskId));
            }
            task.Desc = desc;
            IExecutionHandler executionHandler = new ExecutionHandler();

            if (hashVariation == null)
            {
                hashVariation = new Hashtable();
            }
            int result = executionHandler.ReturnTaskToPrevious(task, hashVariation);

            if (result != 0)
            {
                throw new Exception(string.Format("SubmitTask出错:{0}", result));
            }

            var mailHandler = new ExecutionHandler();

            mailHandler.SendMail(task, task.NextStepType);
        }
Example #6
0
 public static ExecutionHandler getInstance()
 {
     if (ExecutionHandler.instance == null)
     {
         ExecutionHandler.instance = new ExecutionHandler();
     }
     return ExecutionHandler.instance;
 }
        public void AbortIncident(string taskId)
        {
            IExecutionHandler executionHandler = new ExecutionHandler();
            ITask             task             = GetTask(taskId);
            bool result = executionHandler.AbortIncident(task);

            if (!result)
            {
                throw new Exception("撤销出错");
            }
        }
        public void NewExecutionSimulatedAndBlackwood_CreateNewTradeProcessor_TwoTradeProcessorInExecutionProcessorOneForSimulatedOneForBlackwood()
        {
            // Create new Execution Processor Object
            ExecutionHandler executionHandler = new ExecutionHandler();

            {
                // Create Order Object
                Order order = new Order(OrderExecutionProvider.Simulated);

                // Create Fill Object
                Fill fill = new Fill(new Security()
                {
                    Symbol = "GOOG"
                }, OrderExecutionProvider.Simulated, "1");
                fill.ExecutionId   = "1";
                fill.ExecutionSide = OrderSide.BUY;
                fill.ExecutionSize = 40;
                // Create Execution Object
                Execution execution = new Execution(fill, order);
                // Add new execution to the Execution Processor
                executionHandler.NewExecutionArrived(execution);
            }

            {
                // Create Order Object
                Order order = new Order(OrderExecutionProvider.Blackwood);

                // Create Fill Object
                Fill fill = new Fill(new Security()
                {
                    Symbol = "GOOG"
                }, OrderExecutionProvider.Blackwood, "1");
                fill.ExecutionId   = "1";
                fill.ExecutionSide = OrderSide.BUY;
                fill.ExecutionSize = 40;
                // Create Execution Object
                Execution execution = new Execution(fill, order);
                // Add new execution to the Execution Processor
                executionHandler.NewExecutionArrived(execution);
            }

            var tradeProcessorMap = executionHandler.TradeProcessorMap;

            Assert.AreEqual(2, tradeProcessorMap.Count, "Trade Processor Count");
            Assert.AreEqual(OrderExecutionProvider.Simulated, tradeProcessorMap[OrderExecutionProvider.Simulated][new Security()
                                                                                                                  {
                                                                                                                      Symbol = "GOOG"
                                                                                                                  }].ExecutionProvider, "Execution Provider of Trade Processor");
            Assert.AreEqual(OrderExecutionProvider.Blackwood, tradeProcessorMap[OrderExecutionProvider.Blackwood][new Security()
                                                                                                                  {
                                                                                                                      Symbol = "GOOG"
                                                                                                                  }].ExecutionProvider, "Execution Provider of Trade Processor");
        }
Example #9
0
        public async Task ReceiveAsync(ServiceBusMessage message, CancellationToken cancellationToken)
        {
            try
            {
                var executionHandler = new ExecutionHandler(taskExecutionHandler, message.GetBody(), message.GetMyProperties());
                await executionHandler.Execute(cancellationToken).ConfigureAwait(false);

                await this.queueClient.CompleteAsync(message.GetLockToken()).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Trace.TraceError("{0}", ex);

                // You can add code to abandon the service bus message or put the message in dead letter queue
            }
        }
        /// <summary>
        ///     获取任务列表(可用于显示审核信息)
        /// </summary>
        /// <param name="incedentId">事件编号</param>
        /// <returns>任务列表</returns>
        public List <TaskEntity> GetTaskData(string incedentId)
        {
            IExecutionHandler executionHandler = new ExecutionHandler();
            IList             taskIList        = executionHandler.GetTaskListFlowLog(incedentId);

            return((from ITask task in taskIList
                    select new TaskEntity
            {
                Status = GetTaskStatus(task.Status),
                StepName = task.StepName,
                Assigner = EDoc2Helper.GetUserNameById(task.Assigner),
                Owner = EDoc2Helper.GetUserNameById(task.Owner),
                EndTime = FormatHelper.GetNonNullIsoDateString(task.EndTime),
                Desc = task.Desc
            }).ToList());
        }
        /// <summary>
        ///     发起流程
        /// </summary>
        /// <param name="processId">流程编号</param>
        /// <param name="incidentId">事件编号</param>
        /// <param name="remark">流程备注</param>
        /// <param name="hashVariation">流程变量</param>
        /// <returns></returns>
        public ITask Start(string processId, string incidentId, string remark, Hashtable hashVariation)
        {
            EDoc2UserInfo userInfo    = WebsiteUtility.CurrentUser;
            string        startUserId = userInfo.UserId.ToString(CultureInfo.InvariantCulture);
            IProcess      process     = GetProcess(processId);

            if (process == null)
            {
                throw new Exception(string.Format("无法获取processId:{0}的流程", processId));
            }
            IStep startStep = GetStartStep(processId);

            if (startStep == null)
            {
                throw new Exception(string.Format("无法获取processId:{0}的开始步骤", processId));
            }

            var task = new Task
            {
                Remark      = remark,
                IncidentId  = incidentId,
                ProcessId   = processId,
                ProcessName = process.Name,
                TaskStarter = startUserId,
                StepId      = startStep.Id
            };
            IExecutionHandler handler = new ExecutionHandler();

            if (hashVariation == null)
            {
                hashVariation = new Hashtable();
            }
            int result = handler.StartProcessInstance(task, hashVariation);

            if (result != 0)
            {
                throw new Exception(string.Format("SubmitTask出错:{0}", result));
            }

            var mailHandler = new ExecutionHandler();

            mailHandler.SendMail(task, task.NextStepType);
            return(task);
        }
Example #12
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            // Get request body
            var messageBody = await req.Content.ReadAsStringAsync().ConfigureAwait(false);

            // Since we expect all the VSTS properties to be in the request headers, fetch them from the headers
            //
            var taskProperties = GetTaskProperties(req.Headers);

            // Create my own task execution handler. You should replace it with your task execution handler.
            ITaskExecutionHandler myTaskExecutionHandler = new MyTaskExecutionHandler();

            var executionHandler = new ExecutionHandler(myTaskExecutionHandler, messageBody, taskProperties);
            var executionThread  = new Thread(() => executionHandler.Execute(CancellationToken.None));

            executionThread.Start();

            return(req.CreateResponse(HttpStatusCode.OK, "Request accepted!"));
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            TypeDescriptor.AddAttributes(typeof(IdentityDescriptor), new TypeConverterAttribute(typeof(IdentityDescriptorConverter).FullName));
            TypeDescriptor.AddAttributes(typeof(SubjectDescriptor), new TypeConverterAttribute(typeof(SubjectDescriptorConverter).FullName));
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            // Get request body
            var messageBody = await req.Content.ReadAsStringAsync().ConfigureAwait(false);

            // Since we expect all the VSTS properties to be in the request headers, fetch them from the headers
            //
            var taskProperties = GetTaskProperties(req.Headers);

            // Create my own task execution handler. You should replace it with your task execution handler.
            ITaskExecutionHandler myAzureFunctionSampleHandler = new MyTaskExecutionHandler();

            var executionHandler = new ExecutionHandler(myAzureFunctionSampleHandler, messageBody, taskProperties);

            Task.Run(() => executionHandler.Execute(CancellationToken.None));

            return(req.CreateResponse(HttpStatusCode.OK, "Request accepted!"));
        }
Example #14
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            TypeDescriptor.AddAttributes(typeof(IdentityDescriptor), new TypeConverterAttribute(typeof(IdentityDescriptorConverter).FullName));
            TypeDescriptor.AddAttributes(typeof(SubjectDescriptor), new TypeConverterAttribute(typeof(SubjectDescriptorConverter).FullName));
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            // Get request body
            var messageBody = await req.Content.ReadAsStringAsync().ConfigureAwait(false);

            // Fetch all the VSTS properties from the headers
            var taskProperties = GetTaskProperties(req.Headers);

            // Created task execution handler
            ITaskExecutionHandler myTaskExecutionHandler = new MyTaskExecutionHandler();

            var executionHandler = new ExecutionHandler(myTaskExecutionHandler, messageBody, taskProperties);
            var executionThread  = new Thread(() => executionHandler.Execute(CancellationToken.None));

            executionThread.Start();

            return(req.CreateResponse(HttpStatusCode.OK, "Request accepted!"));
        }
        public void Execute(CancellationToken cancellationToken)
        {
            var executionHandler = new ExecutionHandler(taskExecutionHandler, taskProperties);

            executionHandler.Execute(cancellationToken);
        }
        public ITask GetTask(string taskId)
        {
            IExecutionHandler handler = new ExecutionHandler();

            return(handler.GetTaskByTaskId(taskId));
        }