Пример #1
0
        protected virtual SchedulePostProcessingAction ProcessLocalServiceSource(ScheduledItem scheduledItem, Activity activity,
                                                                                 string transactionId)
        {
            DataService dataService =
                ServiceManager.ValidateDataService(scheduledItem.SourceId, ServiceType.QueryOrSolicitOrExecuteOrTask);

            // Load the service plugin
            ISolicitProcessor            solicitPlugin = null;
            IQueryProcessor              queryPlugin   = null;
            IExecuteProcessor            executePlugin = null;
            ITaskProcessor               taskPlugin    = null;
            IPluginDisposer              disposer;
            string                       flowName = FlowManager.GetDataFlowNameById(dataService.FlowId);
            RequestType                  requestType;
            SchedulePostProcessingAction postProcessingAction = SchedulePostProcessingAction.ContinueNormally;

            try
            {
                if ((dataService.Type & ServiceType.Task) == ServiceType.Task)
                {
                    disposer    = PluginLoader.LoadTaskProcessor(dataService, out taskPlugin);
                    requestType = RequestType.Task;
                }
                else if ((dataService.Type & ServiceType.Execute) == ServiceType.Execute)
                {
                    disposer    = PluginLoader.LoadExecuteProcessor(dataService, out executePlugin);
                    requestType = RequestType.Execute;
                }
                else if ((dataService.Type & ServiceType.Solicit) == ServiceType.Solicit)
                {
                    disposer    = PluginLoader.LoadSolicitProcessor(dataService, out solicitPlugin);
                    requestType = RequestType.Solicit;
                }
                else
                {
                    disposer    = PluginLoader.LoadQueryProcessor(dataService, out queryPlugin);
                    requestType = RequestType.Query;
                }
            }
            catch (Exception e)
            {
                throw new NotImplementedException(string.Format("Failed to load the service \"{0}\" for the scheduled item \"{1}\"",
                                                                dataService.Name, scheduledItem.Name), e);
            }
            using (disposer)
            {
                string requestId =
                    RequestManager.CreateDataRequest(transactionId, dataService.Id, 0, -1,
                                                     requestType, activity.ModifiedById,
                                                     scheduledItem.SourceArgs);

                if (taskPlugin != null)
                {
                    LogActivity(activity, "Calling ProcessTask()");
                    try
                    {
                        ITaskProcessorEx taskPluginEx = taskPlugin as ITaskProcessorEx;
                        if (taskPluginEx != null)
                        {
                            postProcessingAction = taskPluginEx.ProcessTask(requestId, scheduledItem.Id);
                        }
                        else
                        {
                            taskPlugin.ProcessTask(requestId);
                        }
                    }
                    finally
                    {
                        activity.Append(taskPlugin.GetAuditLogEvents());
                    }
                    LogActivity(activity, "Called ProcessTask()");
                }
                else if (executePlugin != null)
                {
                    LogActivity(activity, "Calling ProcessExecute()");
                    ExecuteContentResult result;
                    try
                    {
                        result = executePlugin.ProcessExecute(requestId);
                    }
                    finally
                    {
                        activity.Append(executePlugin.GetAuditLogEvents());
                    }
                    if (result.Content != null)
                    {
                        _documentManager.AddDocument(transactionId, result);
                    }
                    LogActivity(activity, "Called ProcessExecute()");
                }
                else if (solicitPlugin != null)
                {
                    LogActivity(activity, "Calling ProcessSolicit()");
                    try
                    {
                        solicitPlugin.ProcessSolicit(requestId);
                    }
                    finally
                    {
                        activity.Append(solicitPlugin.GetAuditLogEvents());
                    }
                    LogActivity(activity, "Called ProcessSolicit()");
                }
                else
                {
                    LogActivity(activity, "Calling ProcessQuery()");
                    PaginatedContentResult result;
                    try
                    {
                        result = queryPlugin.ProcessQuery(requestId);
                    }
                    finally
                    {
                        activity.Append(queryPlugin.GetAuditLogEvents());
                    }
                    LogActivity(activity, "Called ProcessQuery()");
                }
            }
            return(postProcessingAction);
        }