public static WorklistItem ConvertToWFWorklistItem(Client.WorklistItem origObj)
        {
            if (origObj == null)
            {
                return null;
            }
            WorklistItem wlItem = new WorklistItem();
            wlItem.ID = origObj.ID;
            wlItem.ProcInstID = origObj.ProcessInstance.ID;
            wlItem.ActInstDestID = origObj.ActivityInstanceDestination.ID;
            wlItem.ActInstID = origObj.ActivityInstanceDestination.ActInstID;
            //wlItem.ProcID = origObj.ProcID;
            wlItem.ActID = origObj.ActivityInstanceDestination.ActID;
            wlItem.EventID = origObj.EventInstance.ID;
            wlItem.Destination = origObj.AllocatedUser;
            wlItem.AssignedDate = origObj.ActivityInstanceDestination.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.StartDate = origObj.ProcessInstance.StartDate.ToString("yyyy-MM-dd HH:mm");
            //wlItem.FinishDate = origObj.FinishDate;
            wlItem.Status = (WorklistStatus)(int)origObj.Status;
            //wlItem.ProfileID = origObj.ProfileID;
            //wlItem.TenantID = origObj.TenantID;
            wlItem.ActivityName = origObj.ActivityInstanceDestination.Name;
            wlItem.ActivityDispName = origObj.ActivityInstanceDestination.Name;
            wlItem.FullName = origObj.ProcessInstance.FullName;
            wlItem.ProcDispName = origObj.ProcessInstance.Name;
            //wlItem.Originator = origObj.;
            wlItem.Folio = origObj.ProcessInstance.Folio;
            //wlItem.FlowNumber = origObj.ProcessInstance.;
            wlItem.ProcInstStatus = (ProcInstStatus)(int)origObj.ProcessInstance.Status1;
            wlItem.ProcStartDate = origObj.ProcessInstance.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.SN = origObj.SerialNumber;
            wlItem.Data = origObj.Data;

            if (origObj.ProcessInstance != null)
            {
                wlItem.ProcessInstance = ConvertToWFProcessInstance(origObj.ProcessInstance, true);
            }

            foreach (Client.Action origAction in origObj.Actions)
            {
                ApproveAction action = new ApproveAction();
                action.Name = origAction.Name;
                action.MetaData = origAction.MetaData;
                //action.WorklistItem = wlItem;
                wlItem.Actions.Add(action);
            }
            return wlItem;
        }
        private WorklistItem ToWorklistItem(string k2User, Client.WorklistItem item, bool includeInstanceDataFields = false, bool includeActivityDataFields = false, bool includeItemActions = false)
        {
            if (item == null) return null;

            var wlItem = new Tasks.Service.Dto.WorklistItem();

            wlItem.ID = item.ID;
            wlItem.ProcInstID = item.ProcessInstance.ID;
            wlItem.ActInstDestID = item.ActivityInstanceDestination.ID;
            wlItem.ActInstID = item.ActivityInstanceDestination.ActInstID;
            wlItem.ActID = item.ActivityInstanceDestination.ActID;
            wlItem.EventID = item.EventInstance.ID;
            wlItem.Destination = K2User.DelApplySecurityLabel(item.AllocatedUser);
            wlItem.AssignedDate = item.ActivityInstanceDestination.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.StartDate = item.EventInstance.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.Status = (Tasks.Service.Dto.WorklistStatus)(int)item.Status;
            wlItem.ActivityName = item.ActivityInstanceDestination.Name;
            wlItem.ActivityDispName = item.ActivityInstanceDestination.Name;
            wlItem.FullName = item.ProcessInstance.FullName;
            wlItem.ProcDispName = item.ProcessInstance.Name;
            wlItem.Folio = item.ProcessInstance.Folio;
            wlItem.ProcInstStatus = (ProcInstStatus)(int)item.ProcessInstance.Status1;
            wlItem.ProcStartDate = item.ProcessInstance.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.SN = item.SerialNumber;
            wlItem.Data = item.Data;
            wlItem.Originator = K2User.DelApplySecurityLabel(item.ProcessInstance.Originator.FQN);

            if (!item.AllocatedUser.Equals(k2User, StringComparison.OrdinalIgnoreCase))
            {
                wlItem.Data += "&SharedUser=" + item.AllocatedUser;
            }

            if (item.ProcessInstance != null)
            {
                wlItem.ProcessInstance = ToProcessInstance(item.ProcessInstance, includeInstanceDataFields);
            }

            if (includeActivityDataFields)
            {
                var actDataFields = new Dictionary<string, object>();

                foreach (Client.DataField field in item.ActivityInstanceDestination.DataFields)
                {
                    try
                    {
                        if (actDataFields.ContainsKey(field.Name))
                            actDataFields[field.Name] = field.Value;
                        else
                            actDataFields.Add(field.Name, field.Value);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                }
                wlItem.ActivityDataFields = actDataFields;
            }

            if (includeItemActions)
            {
                foreach (Client.Action act in item.Actions)
                {
                    var action = new ApproveAction();

                    action.Name = act.Name;
                    action.MetaData = act.MetaData;
                    //action.WorklistItem = wlItem;
                    wlItem.Actions.Add(action);
                }
            }

            return wlItem;
        }
        public static WorklistItem ConvertToWFWorklistItem(Mgt.WorklistItem origObj)
        {
            if (origObj == null)
            {
                return null;
            }
            WorklistItem wlItem = new WorklistItem();
            wlItem.ID = origObj.ID;

            wlItem.ProcInstID = origObj.ProcInstID;
            wlItem.ActInstDestID = origObj.ActInstDestID;
            wlItem.ActInstID = origObj.ActInstID;
            wlItem.ActID = origObj.ActID;
            wlItem.EventID = origObj.EventID;
            wlItem.Destination = origObj.Destination;
            wlItem.StartDate = origObj.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.Status = (WorklistStatus)(int)origObj.Status;
            wlItem.ActivityName = origObj.ActivityName;
            wlItem.ActivityDispName = origObj.ActivityName;
            wlItem.FullName = origObj.ProcName;
            wlItem.ProcDispName = origObj.ProcName;
            wlItem.Folio = origObj.Folio;
            wlItem.ProcInstStatus = (ProcInstStatus)(int)origObj.ProcessInstanceStatus;

            return wlItem;
        }
        public static WorklistItem ConvertToWFWorklistItem(ServiceContext context, Client.WorklistItem origObj)
        {
            if (origObj == null)
            {
                return null;
            }
            WorklistItem wlItem = new WorklistItem();
            wlItem.ID = origObj.ID;
            wlItem.ProcInstID = origObj.ProcessInstance.ID;
            wlItem.ActInstDestID = origObj.ActivityInstanceDestination.ID;
            wlItem.ActInstID = origObj.ActivityInstanceDestination.ActInstID;
            //wlItem.ProcID = origObj.ProcID;
            wlItem.ActID = origObj.ActivityInstanceDestination.ActID;
            wlItem.EventID = origObj.EventInstance.ID;
            wlItem.Destination = origObj.AllocatedUser;
            wlItem.AssignedDate = origObj.ActivityInstanceDestination.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.StartDate = origObj.ProcessInstance.StartDate.ToString("yyyy-MM-dd HH:mm");
            //wlItem.FinishDate = origObj.FinishDate;
            wlItem.Status = (WorklistStatus)(int)origObj.Status;
            //wlItem.ProfileID = origObj.ProfileID;
            //wlItem.TenantID = origObj.TenantID;
            wlItem.ActivityName = origObj.ActivityInstanceDestination.Name;
            wlItem.ActivityDispName = origObj.ActivityInstanceDestination.Name;
            wlItem.FullName = origObj.ProcessInstance.FullName;
            wlItem.ProcDispName = origObj.ProcessInstance.Name;
            //Added By:BingYi 2014-07-17 Fixed:The Originator should be included in worklist item.
            wlItem.Originator = origObj.ProcessInstance.Originator.Name;
            wlItem.Folio = origObj.ProcessInstance.Folio;
            //wlItem.FlowNumber = origObj.ProcessInstance.;
            wlItem.ProcInstStatus = (ProcInstStatus)(int)origObj.ProcessInstance.Status1;
            wlItem.ProcStartDate = origObj.ProcessInstance.StartDate.ToString("yyyy-MM-dd HH:mm");
            wlItem.SN = origObj.SerialNumber;
            wlItem.Data = origObj.Data;
            if (origObj.AllocatedUser.ToLower() != (K2User.ApplySecurityLabel(context.UserName)).ToLower())
            {
                wlItem.Data += "&SharedUser=" + origObj.AllocatedUser;
            }

            if (origObj.ProcessInstance != null)
            {
                wlItem.ProcessInstance = ConvertToWFProcessInstance(origObj.ProcessInstance, true);
            }

            var activityDataFields = new Dictionary<string, object>();
            foreach (Client.DataField item in origObj.ActivityInstanceDestination.DataFields)
            {
                if (activityDataFields.ContainsKey(item.Name))
                    activityDataFields[item.Name] = item.Value;
                else
                    activityDataFields.Add(item.Name, item.Value);
            }
            wlItem.ActivityDataFields = activityDataFields;

            foreach (Client.Action origAction in origObj.Actions)
            {
                ApproveAction action = new ApproveAction();
                action.Name = origAction.Name;
                action.MetaData = origAction.MetaData;
                //action.WorklistItem = wlItem;
                wlItem.Actions.Add(action);
            }
            return wlItem;
        }