示例#1
0
        public void RetryWorkflow()
        {
            SmartObjectClientServer soServer = this.NewSmartObjectClientServer();

            try
            {
                using (soServer.Connection)
                {
                    SmartObject soError = soServer.GetSmartObject("com_K2_System_Workflow_SmartObject_ErrorLog");
                    //set method we want to execute.
                    soError.MethodToExecute = "GetErrorLogs";
                    soError.Properties["ErrorProfileName"].Value = "All";

                    //get the list of SmartObjects returned by the method
                    SmartObjectList soListError = soServer.ExecuteList(soError);
                    //iterate over the collection

                    List <K2ErrorLog> listK2ErrorLog = new List <K2ErrorLog>();
                    string[]          workflowNames  = this.AppConfig.WorkflowNames.Split(';');
                    foreach (SmartObject soItem in soListError.SmartObjectsList)
                    {
                        for (int i = 0; i < workflowNames.Length; i++)
                        {
                            if (soItem.Properties["ProcessName"].Value == workflowNames[i])
                            {
                                string soDescription = soItem.Properties["Description"].Value.ToString();
                                if (soDescription.Contains("was deadlocked on lock resources with another process") ||
                                    soDescription.Contains("SQL") ||
                                    soDescription.Contains("IIF"))
                                {
                                    listK2ErrorLog.Add(new K2ErrorLog(soItem));
                                }
                            }
                        }
                        //ambil hanya transaksi deadlocked saja
                    }

                    foreach (K2ErrorLog k2ErrorLog in listK2ErrorLog)
                    {
                        SmartObject errorSO = soServer.GetSmartObject("com_K2_System_Workflow_SmartObject_ErrorLog");
                        //set method we want to execute.
                        errorSO.MethodToExecute = "RetryError";

                        errorSO.Properties["Id"].Value         = k2ErrorLog.Id.ToString();
                        errorSO.Properties["ProcInstId"].Value = k2ErrorLog.ProcInstID.ToString();
                        errorSO.Properties["TypeId"].Value     = k2ErrorLog.TypeID.ToString();
                        errorSO.Properties["ObjectId"].Value   = k2ErrorLog.ObjectID.ToString();
                        errorSO.Properties["UserName"].Value   = "System";

                        this.Logger.Info("K2 Retry ProcInstId = " + k2ErrorLog.ProcInstID.ToString());

                        //get the list of SmartObjects returned by the method
                        Thread.Sleep(1000); //delay 1 detik
                        soServer.ExecuteScalar(errorSO);
                    }
                }
            }
            finally
            {
                soServer.DeleteConnection();
            }
        }