/// <summary>
        /// Gets the process data fields
        /// </summary>
        /// <param name="processinstanceId"></param>
        /// <returns></returns>
        public List <dataField> GetProcessDataFields(int processinstanceId)
        {
            List <dataField> list = new List <dataField>();

            SourceCode.Workflow.Client.Connection K2Conn = new SourceCode.Workflow.Client.Connection();
            K2Conn.Open(servername);
            try
            {
                SourceCode.Workflow.Client.ProcessInstance K2Proc = K2Conn.OpenProcessInstance(processinstanceId);
                foreach (SourceCode.Workflow.Client.DataField datafield in K2Proc.DataFields)
                {
                    list.Add(new dataField {
                        Name      = datafield.Name,
                        Value     = datafield.Value.ToString(),
                        valueType = datafield.ValueType.ToString()
                    });
                }
            }
            catch (Exception ex)
            {
                list.Add(new dataField
                {
                    Name  = "Error",
                    Value = ex.Message.ToString()
                });
            }
            finally {
                K2Conn.Close();
            }

            return(list);
        }
        /// <summary>
        /// Starts a workflow
        /// </summary>
        /// <param name="Folio"></param>
        /// <param name="ProcessName"></param>
        /// <returns></returns>
        public int StartProcess(string Folio, string ProcessName)
        {
            var con = ConfigurationManager.AppSettings;


            int ProcessInstanceId = 0;

            SourceCode.Workflow.Client.Connection K2Conn = new SourceCode.Workflow.Client.Connection();
            K2Conn.Open(servername);
            try
            {
                SourceCode.Workflow.Client.ProcessInstance K2Proc = K2Conn.CreateProcessInstance(ProcessName);

                K2Proc.Folio = Folio;
                K2Conn.ImpersonateUser(ServiceAccount);
                K2Conn.StartProcessInstance(K2Proc);
                ProcessInstanceId = K2Proc.ID;
            }
            catch (Exception EX)
            {
                ProcessInstanceId = 0;
            }

            finally
            {
                K2Conn.Close();
            }
            return(ProcessInstanceId);
        }
Beispiel #3
0
 public static ProcessInstance FromApi(SourceCode.Workflow.Client.ProcessInstance processInstance)
 {
     return(new ProcessInstance {
         Description = processInstance.Description,
         ExpectedDuration = (long)processInstance.ExpectedDuration,
         Folder = processInstance.Folder,
         Folio = processInstance.Folio,
         FullName = processInstance.FullName,
         Guid = processInstance.Guid.ToString(),
         ID = (long)processInstance.ID,
         Metadata = processInstance.MetaData,
         Name = processInstance.Name,
         Priority = processInstance.Priority,
         StartDate = processInstance.StartDate.ToUniversalTime(),
         Status = (ProcessStatus)processInstance.Status1,
         ViewFlow = processInstance.ViewFlow
     });
 }
Beispiel #4
0
 public void ToApi(SourceCode.Workflow.Client.ProcessInstance pi)
 {
     if (this.DataFields != null)
     {
         this.DataFields.ToApi(pi.DataFields);
     }
     if (this.XmlFields != null)
     {
         this.XmlFields.ToApi(pi.XmlFields);
     }
     if (!string.IsNullOrEmpty(this.Folio))
     {
         pi.Folio = this.Folio;
     }
     if (this.Priority != -1)
     {
         pi.Priority = this.Priority;
     }
     if (this.ExpectedDuration != 0L)
     {
         pi.ExpectedDuration = (int)this.ExpectedDuration;
     }
 }
        /// <summary>
        /// Gets the current status of the workflow
        /// </summary>
        /// <param name="processinstanceId"></param>
        /// <returns></returns>
        public string GetWorkflowStatus(int processinstanceId)
        {
            string Result = string.Empty;

            SourceCode.Workflow.Client.Connection K2Conn = new SourceCode.Workflow.Client.Connection();
            K2Conn.Open(servername);
            try
            {
                SourceCode.Workflow.Client.ProcessInstance K2Proc = K2Conn.OpenProcessInstance(processinstanceId);


                switch (K2Proc.Status1)
                {
                case SourceCode.Workflow.Client.ProcessInstance.Status.Active:
                {
                    Result = SourceCode.Workflow.Client.ProcessInstance.Status.Active.ToString();
                    break;
                }

                case SourceCode.Workflow.Client.ProcessInstance.Status.Completed:
                {
                    Result = SourceCode.Workflow.Client.ProcessInstance.Status.Completed.ToString();
                    break;
                }

                case SourceCode.Workflow.Client.ProcessInstance.Status.Deleted:
                {
                    Result = SourceCode.Workflow.Client.ProcessInstance.Status.Deleted.ToString();
                    break;
                }

                case SourceCode.Workflow.Client.ProcessInstance.Status.Error:
                {
                    Result = SourceCode.Workflow.Client.ProcessInstance.Status.Error.ToString();
                    break;
                }

                case SourceCode.Workflow.Client.ProcessInstance.Status.New:
                {
                    Result = SourceCode.Workflow.Client.ProcessInstance.Status.New.ToString();
                    break;
                }

                case SourceCode.Workflow.Client.ProcessInstance.Status.Running:
                {
                    Result = SourceCode.Workflow.Client.ProcessInstance.Status.Running.ToString();
                    break;
                }

                case SourceCode.Workflow.Client.ProcessInstance.Status.Stopped:
                {
                    Result = SourceCode.Workflow.Client.ProcessInstance.Status.Stopped.ToString();
                    break;
                }
                }
            }
            catch (Exception ex)
            { Result = ex.Message; }
            finally
            {
                K2Conn.Close();
            }

            return(Result);
        }