public static ProcessInstance ConvertToWFProcessInstance(Client.ProcessInstance origObj, bool loadDataFields)
 {
     if (origObj == null)
     {
         return null;
     }
     ProcessInstance procInst = new ProcessInstance();
     procInst.ID = origObj.ID;
     //procInst.ProcID = origObj.ProcID;
     //procInst.ProcSetID = origObj.ProcSetID;
     procInst.FullName = origObj.FullName;
     //procInst.DisplayName = origObj.DisplayName;
     //procInst.FlowNumber = origObj.FlowNumber;
     procInst.Folio = origObj.Folio;
     procInst.Originator = origObj.Originator.Name;
     ///procInst.Status = (ProcInstStatus)(int)origObj.Status1;
     procInst.Priority = origObj.Priority;
     procInst.ExpectedDuration = origObj.ExpectedDuration;
     procInst.StartDate = origObj.StartDate.ToString("yyyy-MM-dd HH:mm");
     if (loadDataFields)
     {
         if (origObj.DataFields != null)
         {
             Dictionary<string, DataField> dicFields = new Dictionary<string, DataField>();
             foreach (Client.DataField field1 in origObj.DataFields)
             {
                 DataField field = new DataField();
                 field.Name = field1.Name;
                 //field.Type = origObj.DataFields[fieldName].Type.ToString();
                 field.Value = field1.Value;
                 //field.Category = origObj.DataFields[fieldName].Category;
                 dicFields.Add(field.Name, field);
             }
             procInst.DataFields = dicFields;
         }
         if (origObj.XmlFields != null)
         {
             Dictionary<string, XmlField> dicXmlFields = new Dictionary<string, XmlField>();
             foreach (Client.XmlField field1 in origObj.XmlFields)
             {
                 XmlField field = new XmlField();
                 field.Name = field1.Name;
                 field.Value = field1.Value;
                 field.Category = field1.Category;
                 field.Hidden = field1.Hidden;
                 field.MetaData = field1.MetaData;
                 field.Schema = field1.Schema;
                 field.Xsl = field1.Xsl;
                 dicXmlFields.Add(field.Name, field);
             }
             procInst.XmlFields = dicXmlFields;
         }
     }
     return procInst;
 }
        private Tasks.Service.Dto.ProcessInstance ToProcessInstance(Client.ProcessInstance inst, bool includeInstanceDataFields = false)
        {
            if (inst == null) return null;

            var procInst = new Tasks.Service.Dto.ProcessInstance();

            procInst.ID = inst.ID;
            procInst.FullName = inst.FullName;
            procInst.Folio = inst.Folio;
            procInst.Originator = K2User.DelApplySecurityLabel(inst.Originator.FQN);
            procInst.Priority = inst.Priority;
            procInst.ExpectedDuration = inst.ExpectedDuration;
            procInst.StartDate = inst.StartDate.ToString("yyyy-MM-dd HH:mm");

            if (includeInstanceDataFields)
            {
                if (inst.DataFields != null)
                {
                    Dictionary<string, Tasks.Service.Dto.DataField> dicFields = new Dictionary<string, Tasks.Service.Dto.DataField>();
                    foreach (Client.DataField field1 in inst.DataFields)
                    {
                        Tasks.Service.Dto.DataField field = new Tasks.Service.Dto.DataField();

                        try
                        {
                            field.Name = field1.Name;
                            field.Value = field1.Value;
                            dicFields.Add(field.Name, field);
                        }
                        catch (Exception)
                        {

                            continue;
                        }

                    }
                    procInst.DataFields = dicFields;
                }

                if (inst.XmlFields != null)
                {
                    Dictionary<string, XmlField> dicXmlFields = new Dictionary<string, XmlField>();
                    foreach (Client.XmlField field1 in inst.XmlFields)
                    {
                        XmlField field = new XmlField();
                        try
                        {
                            field.Name = field1.Name;
                            field.Value = field1.Value;
                            field.Category = field1.Category;
                            field.Hidden = field1.Hidden;
                            field.MetaData = field1.MetaData;
                            field.Schema = field1.Schema;
                            field.Xsl = field1.Xsl;
                            dicXmlFields.Add(field.Name, field);
                        }
                        catch (Exception)
                        {
                            continue;
                        }


                    }
                    procInst.XmlFields = dicXmlFields;
                }
            }

            return procInst;
        }