Ejemplo n.º 1
0
        public object GetIndex(Guid?threadTaskID = null, Guid?stepID = null, Guid?applicationPageId = null, Guid?formId = null, Guid?threadId = null)
        {
            SingleActionSettingDTO setting = base.GetSetting();

            try
            {
                if (setting.ProcessID.HasValue)
                {
                    #region .:: Thread ::.
                    //If bpms engine is in different domain.
                    EngineProcessProxy engineProcessProxy = null;
                    if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                    {
                        engineProcessProxy = new EngineProcessProxy(setting.WebApiAddress, setting.WebServicePass, base.ClientUserName, ApiUtility.GetIPAddress(), base.ApiSessionId, this.IsEncrypted);
                    }

                    if (!threadTaskID.HasValue && !threadId.HasValue)
                    {
                        //begin Process
                        BeginTaskResponseModel beginTaskResponseVM = null;
                        //If bpms engine is in different domain.
                        if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                        {
                            beginTaskResponseVM = engineProcessProxy.BeginTask(setting.ProcessID.Value, base.MyRequest.GetList(false, string.Empty).ToList());
                        }
                        else
                        {
                            beginTaskResponseVM = this.BeginTask(setting.ProcessID.Value);
                        }

                        threadTaskID = beginTaskResponseVM.ThreadTaskID;
                        if (!beginTaskResponseVM.Result)
                        {
                            return(new
                            {
                                MessageList = new List <PostMethodMessage>()
                                {
                                    new PostMethodMessage(beginTaskResponseVM.Message, DisplayMessageType.error)
                                },
                                Result = false,
                                setting.ShowCardBody
                            });
                        }
                    }

                    if (!threadTaskID.HasValue && threadId.HasValue)
                    {
                        //If bpms engine is in different domain.
                        if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                        {
                            threadTaskID = engineProcessProxy.GetAccessibleThreadTasks(threadId.Value).FirstOrDefault();
                        }
                        else
                        {
                            threadTaskID = this.GetAccessibleThreadTasks(threadId.Value).FirstOrDefault();
                        }

                        if (!threadTaskID.HasValue || threadTaskID == Guid.Empty)
                        {
                            ThreadDetailDTO threadDetailDTO = null;
                            //show history
                            //If bpms engine is in different domain.
                            if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                            {
                                threadDetailDTO = engineProcessProxy.GetThreadDetails(threadId.Value);
                            }
                            else
                            {
                                threadDetailDTO = this.GetThreadDetails(threadId.Value);
                            }
                            return(new
                            {
                                ThreadDetailModel = threadDetailDTO,
                                Result = true,
                                setting.ShowCardBody
                            });
                        }
                    }
                    GetTaskFormResponseModel responseVM = null;
                    //If it must load end process form.
                    if (formId.HasValue)
                    {
                        //If bpms engine is in different domain.
                        if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                        {
                            responseVM = engineProcessProxy.GetForm(threadTaskID.Value, formId.Value, base.MyRequest.GetList(false, string.Empty).ToList(), false);
                        }
                        else
                        {
                            //if engine is in same domain, call it directly.
                            using (ThreadTaskService threadTaskService = new ThreadTaskService())
                            {
                                sysBpmsThreadTask threadTask = new ThreadTaskService().GetInfo(threadTaskID.Value, new string[] { nameof(sysBpmsThreadTask.Thread) });
                                using (ProcessEngine ProcessEngine = new ProcessEngine(new EngineSharedModel(threadTask.ThreadID, threadTask.Thread.ProcessID, base.MyRequest.GetList(this.IsEncrypted, base.ApiSessionId).ToList(), base.ClientUserName, base.ApiSessionId)))
                                    responseVM = ProcessEngine.GetForm(threadTask.ID, formId.Value, false);
                            }
                        }

                        if (responseVM.EngineFormModel != null)
                        {
                            responseVM.EngineFormModel.FormModel.HasSubmitButton = true;
                        }
                    }
                    else
                    {
                        if (threadTaskID.HasValue)
                        {
                            //If bpms engine is in different domain.
                            if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                            {
                                engineProcessProxy.GetTaskForm(threadTaskID.Value, stepID, base.MyRequest.GetList(false, string.Empty).ToList());
                            }
                            else
                            {
                                //If engine is in same domain, call it directly.
                                using (ThreadTaskService threadTaskService = new ThreadTaskService())
                                {
                                    sysBpmsThreadTask threadTask = new ThreadTaskService().GetInfo(threadTaskID.Value, new string[] { nameof(sysBpmsThreadTask.Thread) });
                                    using (ProcessEngine ProcessEngine = new ProcessEngine(new EngineSharedModel(threadTask.ThreadID, threadTask.Thread.ProcessID, base.MyRequest.GetList(this.IsEncrypted, base.ApiSessionId).ToList(), base.ClientUserName, base.ApiSessionId)))
                                        responseVM = ProcessEngine.GetTaskForm(threadTaskID.Value, stepID);
                                }
                            }
                        }
                        else
                        {
                            responseVM = null;
                        }
                    }
                    if (responseVM?.EngineFormModel != null)
                    {
                        string popUpUrl = UrlUtility.GetSingleActionApiUrl(base.MyRequest, base.TabModuleID, base.PortalSettings.DefaultPortalAlias, nameof(SingleActionWorkerController.GetPopUp), nameof(SingleActionWorkerController), "", "threadTaskID=" + threadTaskID);
                        string postUrl  = UrlUtility.GetSingleActionApiUrl(base.MyRequest, base.TabModuleID, base.PortalSettings.DefaultPortalAlias, nameof(SingleActionWorkerController.PostIndex), nameof(SingleActionWorkerController), "", UrlUtility.GetParamsAsArray(new HttpRequestWrapper(base.MyRequest), new string[] { $"threadTaskID={threadTaskID}", $"stepID={responseVM.EngineFormModel.FormModel.StepID}" }).ToArray());

                        //If bpms engine is in different domain.
                        if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                        {
                            responseVM.EngineFormModel.SetUrlsForSingleAction(base.PortalSettings.DefaultPortalAlias, new HttpRequestWrapper(base.MyRequest), popUpUrl, postUrl, FormTokenUtility.GetFormToken(base.ApiSessionId, responseVM?.EngineFormModel?.FormModel?.ContentHtml?.DynamicFormID ?? Guid.Empty, responseVM?.EngineFormModel?.FormModel?.IsEncrypted ?? false), base.TabModuleID);
                        }
                        else
                        {
                            responseVM.EngineFormModel.SetUrls(popUpUrl, postUrl, new HttpRequestWrapper(base.MyRequest), base.PortalSettings.DefaultPortalAlias, FormTokenUtility.GetFormToken(base.ApiSessionId, responseVM?.EngineFormModel?.FormModel?.ContentHtml?.DynamicFormID ?? Guid.Empty, responseVM?.EngineFormModel?.FormModel?.IsEncrypted ?? false));
                        }

                        return(new
                        {
                            Model = responseVM?.EngineFormModel,
                            MessageList = responseVM?.ListMessageModel.Select(c => new PostMethodMessage(c.Message, c.DisplayMessageType)),
                            RedirectUrl = base.GetRedirectUrl(responseVM?.RedirectUrlModel),
                            Result = true,
                            setting.ShowCardBody
                        });
                    }
                    else
                    {
                        return new
                               {
                                   MessageList = new List <PostMethodMessage>()
                                   {
                                       new PostMethodMessage("Error in getting information", DisplayMessageType.error)
                                   },
                                   Result = false,
                                   setting.ShowCardBody
                               }
                    };

                    #endregion
                }
                else
                {
                    #region .:: Application Page ::.
                    applicationPageId = applicationPageId ?? setting.ApplicationPageID;
                    GetFormResponseModel responseVM = null;

                    //if bpms engine is in different domain
                    if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                    {
                        EngineApplicationProxy engineApplicationProxy = new EngineApplicationProxy(setting.WebApiAddress, setting.WebServicePass, base.ClientUserName, ApiUtility.GetIPAddress(), base.ApiSessionId, this.IsEncrypted);

                        responseVM = engineApplicationProxy.GetForm(applicationPageId, null, base.MyRequest.GetList(false, string.Empty).ToList());
                    }
                    else
                    {
                        EngineSharedModel engineSharedModel = new EngineSharedModel(applicationPageId.Value, base.MyRequest.GetList(this.IsEncrypted, base.ApiSessionId).ToList(), base.ClientUserName, base.ApiSessionId);
                        using (ApplicationPageEngine applicationPageEngine = new ApplicationPageEngine(engineSharedModel))
                            responseVM = applicationPageEngine.GetForm();
                    }
                    if (responseVM?.EngineFormModel != null)
                    {
                        string popUpUrl = UrlUtility.GetSingleActionApiUrl(base.MyRequest, base.TabModuleID, base.PortalSettings.DefaultPortalAlias, nameof(SingleActionWorkerController.GetPopUp), nameof(SingleActionWorkerController), "");
                        string postUrl  = UrlUtility.GetSingleActionApiUrl(base.MyRequest, base.TabModuleID, base.PortalSettings.DefaultPortalAlias, nameof(SingleActionWorkerController.PostIndex), nameof(SingleActionWorkerController), "", UrlUtility.GetParamsAsArray(new HttpRequestWrapper(base.MyRequest), new string[] { $"applicationPageId={applicationPageId}" }).ToArray());

                        if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                        {
                            responseVM.EngineFormModel.SetUrlsForSingleAction(base.PortalSettings.DefaultPortalAlias, new HttpRequestWrapper(base.MyRequest), popUpUrl, postUrl, FormTokenUtility.GetFormToken(base.ApiSessionId, responseVM?.EngineFormModel?.FormModel?.ContentHtml?.DynamicFormID ?? Guid.Empty, responseVM?.EngineFormModel?.FormModel?.IsEncrypted ?? false), base.TabModuleID);
                        }
                        else
                        {
                            responseVM.EngineFormModel.SetUrls(popUpUrl, postUrl, new HttpRequestWrapper(base.MyRequest), base.PortalSettings.DefaultPortalAlias, FormTokenUtility.GetFormToken(base.ApiSessionId, responseVM?.EngineFormModel?.FormModel?.ContentHtml?.DynamicFormID ?? Guid.Empty, responseVM?.EngineFormModel?.FormModel?.IsEncrypted ?? false));
                        }

                        return(new
                        {
                            Model = responseVM?.EngineFormModel,
                            MessageList = responseVM?.ListMessageModel.Select(c => new PostMethodMessage(c.Message, c.DisplayMessageType)),
                            RedirectUrl = base.GetRedirectUrl(responseVM?.RedirectUrlModel),
                            Result = true,
                            setting.ShowCardBody
                        });
                    }
                    else
                    {
                        return new
                               {
                                   MessageList = new List <PostMethodMessage>()
                                   {
                                       new PostMethodMessage("Error while getting information", DisplayMessageType.error)
                                   },
                                   Result = false,
                                   setting.ShowCardBody
                               }
                    };
                    #endregion
                }
            }
            catch
            {
                return(new
                {
                    MessageList = new List <PostMethodMessage>()
                    {
                        new PostMethodMessage("Setting is not complete", DisplayMessageType.error)
                    },
                    Result = false,
                    setting.ShowCardBody
                });
            }
        }
Ejemplo n.º 2
0
        public object GetPopUp(Guid formID, Guid?threadTaskID = null)
        {
            SingleActionSettingDTO setting = base.GetSetting();

            if (setting.ProcessID.HasValue)
            {
                #region .:: Thread ::.
                GetTaskFormResponseModel responseVM = null;
                //If bpms engine is in different domain.
                if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                {
                    responseVM = new EngineProcessProxy(setting.WebApiAddress, setting.WebServicePass, base.ClientUserName, ApiUtility.GetIPAddress(), base.ApiSessionId, this.IsEncrypted).GetForm(threadTaskID.Value, formID, base.MyRequest.GetList(false, string.Empty).ToList());
                }
                else
                {
                    //if engine is in same domain, call it directly.
                    using (ThreadTaskService threadTaskService = new ThreadTaskService())
                    {
                        sysBpmsThreadTask threadTask = new ThreadTaskService().GetInfo(threadTaskID.Value, new string[] { nameof(sysBpmsThreadTask.Thread) });

                        using (ProcessEngine ProcessEngine = new ProcessEngine(new EngineSharedModel(threadTask.ThreadID, threadTask.Thread.ProcessID, base.MyRequest.GetList(this.IsEncrypted, base.ApiSessionId).ToList(), base.ClientUserName, base.ApiSessionId)))
                            responseVM = ProcessEngine.GetForm(threadTask.ID, formID, null);
                    }
                }
                if (responseVM.EngineFormModel != null)
                {
                    string popUpUrl = UrlUtility.GetSingleActionApiUrl(base.MyRequest, base.TabModuleID, base.PortalSettings.DefaultPortalAlias, nameof(SingleActionWorkerController.GetPopUp), nameof(SingleActionWorkerController), "", "threadTaskID=" + threadTaskID);
                    string postUrl  = UrlUtility.GetSingleActionApiUrl(base.MyRequest, base.TabModuleID, base.PortalSettings.DefaultPortalAlias, nameof(SingleActionWorkerController.PostPopUp), nameof(SingleActionWorkerController), "", UrlUtility.GetParamsAsArray(new HttpRequestWrapper(base.MyRequest), new string[] { $"formID={formID}", $"threadTaskID={threadTaskID}", $"stepID={responseVM.EngineFormModel.FormModel.StepID}" }).ToArray());

                    if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                    {
                        responseVM.EngineFormModel.SetUrlsForSingleAction(base.PortalSettings.DefaultPortalAlias, new HttpRequestWrapper(base.MyRequest), popUpUrl, postUrl, FormTokenUtility.GetFormToken(base.ApiSessionId, responseVM?.EngineFormModel?.FormModel?.ContentHtml?.DynamicFormID ?? Guid.Empty, responseVM?.EngineFormModel?.FormModel?.IsEncrypted ?? false), base.TabModuleID);
                    }
                    else
                    {
                        responseVM.EngineFormModel.SetUrls(popUpUrl, postUrl, new HttpRequestWrapper(base.MyRequest), base.PortalSettings.DefaultPortalAlias, FormTokenUtility.GetFormToken(base.ApiSessionId, responseVM?.EngineFormModel?.FormModel?.ContentHtml?.DynamicFormID ?? Guid.Empty, responseVM?.EngineFormModel?.FormModel?.IsEncrypted ?? false));
                    }
                }
                return(new
                {
                    Model = responseVM?.EngineFormModel,
                    MessageList = responseVM?.ListMessageModel.Select(c => new PostMethodMessage(c.Message, c.DisplayMessageType)),
                    RedirectUrl = base.GetRedirectUrl(responseVM?.RedirectUrlModel),
                    Result = true,
                });

                #endregion
            }
            else
            {
                #region .:: Application ::.
                GetFormResponseModel responseVM = null;
                //if bpms engine is in different domain
                if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                {
                    EngineApplicationProxy engineApplicationProxy = new EngineApplicationProxy(setting.WebApiAddress, setting.WebServicePass, base.ClientUserName, ApiUtility.GetIPAddress(), base.ApiSessionId, this.IsEncrypted);
                    responseVM = engineApplicationProxy.GetForm(null, formID, new HttpRequestWrapper(base.MyRequest).GetList(false, string.Empty).ToList());
                }
                else
                {
                    using (DynamicFormService dynamicFormService = new DynamicFormService())
                    {
                        EngineSharedModel engineSharedModel = new EngineSharedModel(dynamicFormService.GetInfo(formID).ApplicationPageID.Value, base.MyRequest.GetList(false, string.Empty).ToList(), base.ClientUserName, base.ApiSessionId);
                        using (ApplicationPageEngine applicationPageEngine = new ApplicationPageEngine(engineSharedModel))
                            responseVM = applicationPageEngine.GetForm();
                    }
                }

                if (responseVM.EngineFormModel != null)
                {
                    string popUpUrl = UrlUtility.GetSingleActionApiUrl(base.MyRequest, base.TabModuleID, base.PortalSettings.DefaultPortalAlias, nameof(SingleActionWorkerController.GetPopUp), nameof(SingleActionWorkerController), "");
                    string postUrl  = UrlUtility.GetSingleActionApiUrl(base.MyRequest, base.TabModuleID, base.PortalSettings.DefaultPortalAlias, nameof(SingleActionWorkerController.PostPopUp), nameof(SingleActionWorkerController), "", UrlUtility.GetParamsAsArray(new HttpRequestWrapper(base.MyRequest), new string[] { $"applicationPageId={responseVM.EngineFormModel.ApplicationID}" }).ToArray());
                    if (!string.IsNullOrWhiteSpace(setting.WebApiAddress))
                    {
                        responseVM.EngineFormModel.SetUrlsForSingleAction(base.PortalSettings.DefaultPortalAlias, new HttpRequestWrapper(base.MyRequest), popUpUrl, postUrl, FormTokenUtility.GetFormToken(base.ApiSessionId, responseVM?.EngineFormModel?.FormModel?.ContentHtml?.DynamicFormID ?? Guid.Empty, responseVM?.EngineFormModel?.FormModel?.IsEncrypted ?? false), base.TabModuleID);
                    }
                    else
                    {
                        responseVM.EngineFormModel.SetUrls(popUpUrl, postUrl, new HttpRequestWrapper(base.MyRequest), base.PortalSettings.DefaultPortalAlias, FormTokenUtility.GetFormToken(base.ApiSessionId, responseVM?.EngineFormModel?.FormModel?.ContentHtml?.DynamicFormID ?? Guid.Empty, responseVM?.EngineFormModel?.FormModel?.IsEncrypted ?? false));
                    }
                }
                return(new
                {
                    Model = responseVM?.EngineFormModel,
                    MessageList = responseVM?.ListMessageModel.Select(c => new PostMethodMessage(c.Message, c.DisplayMessageType)),
                    RedirectUrl = base.GetRedirectUrl(responseVM?.RedirectUrlModel),
                    Result = true,
                });

                #endregion
            }
        }