public void SimpleProcessSerializationTest()
        {
            WfClientJsonConverterHelper.Instance.RegisterConverters();

            WfClientUser[] users = new WfClientUser[] { Consts.Users["Requestor"] };

            IWfProcess process = ProcessHelper.CreateFreeStepsProcessInstance(users.ToOguObjects<WfClientUser, IUser>().ToArray());

            WfClientProcess client = null;

            WfClientProcessConverter.InstanceWithoutActivityBindings.ServerToClient(process, ref client);

            Assert.IsNull(client.InitialActivity);
            Assert.IsNull(client.CompletedActivity);
            Assert.IsNull(client.MainStream);

            string data = JSONSerializerExecute.Serialize(client);

            Console.WriteLine(data);

            WfClientProcess deserializedProcess = JSONSerializerExecute.Deserialize<WfClientProcess>(data);

            Assert.IsNotNull(deserializedProcess.InitialActivity);
            Assert.IsNotNull(deserializedProcess.CompletedActivity);

            Assert.AreEqual(deserializedProcess.InitialActivity.ID, deserializedProcess.CurrentActivity.ID);
        }
        public WfClientAuthorizationInfo GetAuthorizationInfo(IWfProcess process, IWfActivity originalActivity, WfClientUser user)
        {
            string userID = user.IsNotNullOrEmpty() ? user.ID : string.Empty;
            string originalActivityID = originalActivity != null ? originalActivity.ID : string.Empty;

            return GetAuthorizationInfo(process, originalActivityID, userID);
        }
        public bool IsSameUser(WfClientUser user)
        {
            bool result = false;

            if (this.User != null && user != null)
                result = string.Compare(this.User.ID, user.ID, true) == 0;

            return result;
        }
        private static WfProcessDescriptorInfo PrepareServerData()
        {

            WfClientUser[] users = new WfClientUser[] { Consts.Users["Requestor"] };

            IWfProcessDescriptor processDesp = ProcessHelper.CreateFreeStepsProcess(users.ToOguObjects<WfClientUser, IUser>().ToArray());

            WfSqlProcessDescriptorManager manager = new WfSqlProcessDescriptorManager();
            manager.SaveDescriptor(processDesp);
            WfProcessDescriptorInfo server = WfProcessDescriptorInfoAdapter.Instance.Load(processDesp.Key);

            return server;
        }
        private static IWfProcess PrepareProcess()
        {
            WfClientUser[] users = new WfClientUser[] { Consts.Users["Requestor"] };

            IWfProcessDescriptor processDesp = ProcessHelper.CreateFreeStepsProcess(users.ToOguObjects<WfClientUser, IUser>().ToArray());

            WfProcessStartupParams startupParams = ProcessHelper.GetInstanceOfWfProcessStartupParams(processDesp);

            IWfProcess process = WfRuntime.StartWorkflow(startupParams);

            WfRuntime.PersistWorkflows();

            return process;
        }
        /// <summary>
        /// 得到在当前活动的意见信息
        /// </summary>
        /// <param name="originalActivity"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public WfClientOpinion GetUserActivityOpinion(IWfActivity originalActivity, WfClientUser user)
        {
            WfClientOpinion opinion = null;

            if (originalActivity != null && user != null)
            {
                WhereSqlClauseBuilder builder = new WhereSqlClauseBuilder();

                builder.AppendItem("ACTIVITY_ID", originalActivity.ID);
                builder.AppendItem("ISSUE_PERSON_ID", user.ID);

                GenericOpinion serverOpinion = GenericOpinionAdapter.Instance.LoadByBuilder(builder).FirstOrDefault();

                if (serverOpinion != null)
                    WfClientOpinionConverter.Instance.ServerToClient(serverOpinion, ref opinion);
            }

            return opinion;
        }
        public void SimpleProcessServerInstanceToClientTest()
        {
            WfClientUser[] users = new WfClientUser[] { Consts.Users["Requestor"] };

            IWfProcessDescriptor processDesp = ProcessHelper.CreateFreeStepsProcess(users.ToOguObjects<WfClientUser, IUser>().ToArray());

            WfProcessStartupParams startupParams = ProcessHelper.GetInstanceOfWfProcessStartupParams(processDesp);

            IWfProcess process = WfRuntime.StartWorkflow(startupParams);

            process.Context["Context"] = "This is a context";

            WfClientProcess client = null;

            WfClientProcessConverter.Instance.ServerToClient(process, ref client);

            Console.WriteLine(client.InitialActivity.ID);
            Console.WriteLine(client.CompletedActivity.ID);
            Console.WriteLine(client.Descriptor.Url);

            Assert.AreEqual(startupParams.DefaultUrl, client.Descriptor.Url);
            Assert.AreEqual(process.Context["Context"], client.ProcessContext["Context"]);
        }
        public static WfClientOguObjectBase CreateWrapperObject(string id, string name, ClientOguSchemaType schemaType)
        {
            WfClientOguObjectBase result = null;

            switch (schemaType)
            {
            case ClientOguSchemaType.Organizations:
                result = new WfClientOrganization(id, name);
                break;

            case ClientOguSchemaType.Users:
                result = new WfClientUser(id, name);
                break;

            case ClientOguSchemaType.Groups:
                result = new WfClientGroup(id, name);
                break;

            default:
                throw new ApplicationException(string.Format("schemaType错误{0}", schemaType));
            }

            return(result);
        }
        /// <summary>
        /// 把当前环节的信息填充到意见当中
        /// </summary>
        /// <param name="opinion"></param>
        /// <param name="originalActivity"></param>
        /// <param name="user"></param>
        /// <param name="delegatedUser"></param>
        public void FillOpinionInfoByProcessByActivity(WfClientOpinion opinion, IWfActivity originalActivity, WfClientUser user, WfClientUser delegatedUser)
        {
            if (opinion != null && originalActivity != null)
            {
                if (opinion.ID.IsNullOrEmpty())
                    opinion.ID = UuidHelper.NewUuidString();

                opinion.ResourceID = originalActivity.Process.ResourceID;
                opinion.ProcessID = originalActivity.Process.ID;
                opinion.ActivityID = originalActivity.ID;

                IWfActivity rootActivity = originalActivity.OpinionRootActivity;

                if (rootActivity.Process.MainStream != null && rootActivity.MainStreamActivityKey.IsNotEmpty())
                {
                    opinion.LevelName = rootActivity.MainStreamActivityKey;
                }
                else
                {
                    if (string.IsNullOrEmpty(rootActivity.Descriptor.AssociatedActivityKey))
                        opinion.LevelName = rootActivity.Descriptor.Key;
                    else
                        opinion.LevelName = rootActivity.Descriptor.AssociatedActivityKey;
                }

                if (rootActivity.Process.MainStream != null)
                    opinion.LevelDesp = rootActivity.Process.MainStream.Activities[opinion.LevelName].Name;
                else
                    opinion.LevelDesp = rootActivity.Descriptor.Process.Activities[opinion.LevelName].Name;

                if (user != null)
                {
                    opinion.IssuePersonID = user.ID;
                    opinion.IssuePersonName = user.DisplayName;

                    if (originalActivity != null)
                    {
                        IUser delegator = originalActivity.Assignees.FindDelegator((IUser)user.ToOguObject());

                        opinion.IssuePersonID = delegator.ID;
                        opinion.IssuePersonName = delegator.DisplayName;
                    }

                    if (delegatedUser == null)
                        delegatedUser = user;

                    opinion.AppendPersonID = delegatedUser.ID;
                    opinion.AppendPersonName = delegatedUser.DisplayName;
                }
            }
        }
        public WfClientProcess GetProcessByActivityID(string activityID, WfClientUser user, WfClientProcessInfoFilter filter)
        {
            activityID.CheckStringIsNullOrEmpty("activityID");

            OperationContext.Current.FillContextToOguServiceContext();

            IWfProcess process = WfRuntime.GetProcessByActivityID(activityID);

            WfClientProcess client = null;

            new WfClientProcessConverter(filter).ServerToClient(process, ref client);

            IWfActivity originalActivity = process.Activities[activityID];

            client.AuthorizationInfo = WfClientProcessInfoBaseConverter.Instance.GetAuthorizationInfo(process, originalActivity, user);

            if ((filter & WfClientProcessInfoFilter.CurrentOpinion) == WfClientProcessInfoFilter.CurrentOpinion)
                client.FillCurrentOpinion(originalActivity, user);

            return client;
        }
        public List<WfClientProcess> GetProcessesByResourceID(string resourceID, WfClientUser user, WfClientProcessInfoFilter filter)
        {
            resourceID.CheckStringIsNullOrEmpty("resourceID");

            OperationContext.Current.FillContextToOguServiceContext();

            WfProcessCollection processes = WfRuntime.GetProcessByResourceID(resourceID).SortByUserRelativity((IUser)user.ToOguObject());

            WfClientProcessConverter converter = new WfClientProcessConverter(filter);

            List<WfClientProcess> result = new List<WfClientProcess>();

            foreach (IWfProcess process in processes)
            {
                WfClientProcess client = null;

                converter.ServerToClient(process, ref client);

                client.AuthorizationInfo = WfClientProcessInfoBaseConverter.Instance.GetAuthorizationInfo(process, process.CurrentActivity, user);

                if ((filter & WfClientProcessInfoFilter.CurrentOpinion) == WfClientProcessInfoFilter.CurrentOpinion)
                    client.FillCurrentOpinion(process.CurrentActivity, user);

                result.Add(client);
            }

            return result;
        }
        public static WfClientOguObjectBase CreateWrapperObject(string id, string name, ClientOguSchemaType schemaType)
        {
            WfClientOguObjectBase result = null;

            switch (schemaType)
            {
                case ClientOguSchemaType.Organizations:
                    result = new WfClientOrganization(id, name);
                    break;
                case ClientOguSchemaType.Users:
                    result = new WfClientUser(id, name);
                    break;
                case ClientOguSchemaType.Groups:
                    result = new WfClientGroup(id, name);
                    break;
                default:
                    throw new ApplicationException(string.Format("schemaType错误{0}", schemaType));
            }

            return result;
        }
        public void SimpleProcessWithAppParametersSerializationTest()
        {
            WfClientJsonConverterHelper.Instance.RegisterConverters();

            WfClientUser[] users = new WfClientUser[] { Consts.Users["Requestor"] };

            IWfProcess process = ProcessHelper.CreateFreeStepsProcessInstance(users.ToOguObjects<WfClientUser, IUser>().ToArray());

            WfClientProcess client = null;

            new WfClientProcessConverter(WfClientProcessInfoFilter.Descriptor | WfClientProcessInfoFilter.ApplicationRuntimeParameters | WfClientProcessInfoFilter.BindActivityDescriptors).ServerToClient(process, ref client);

            Assert.IsNotNull(client.InitialActivity);
            Assert.IsNotNull(client.CompletedActivity);
            Assert.IsNull(client.MainStream);
            Assert.IsTrue(client.ApplicationRuntimeParameters.Count > 0);

            string data = JSONSerializerExecute.Serialize(client);

            Console.WriteLine(data);

            WfClientProcess deserializedProcess = JSONSerializerExecute.Deserialize<WfClientProcess>(data);

            Assert.IsNotNull(deserializedProcess.InitialActivity);
            Assert.IsNotNull(deserializedProcess.CompletedActivity);
            Assert.IsNull(deserializedProcess.MainStream);
            Assert.IsTrue(deserializedProcess.ApplicationRuntimeParameters.Count > 0);
            Assert.IsTrue(deserializedProcess.ProcessContext.Count > 0);

            Assert.AreEqual(deserializedProcess.InitialActivity.ID, deserializedProcess.CurrentActivity.ID);
        }
        public WfClientProcessInfo ReplaceAssignees(string activityID, WfClientUser originalUser, List<WfClientUser> targetUsers, WfClientRuntimeContext runtimeContext)
        {
            OperationContext.Current.FillContextToOguServiceContext();

            IWfProcess process = WfRuntime.GetProcessByActivityID(activityID);
            IWfActivity targetActivity = process.Activities[activityID];

            ExecuteExecutor(process, runtimeContext,
                (p) => new WfReplaceAssigneesExecutor(targetActivity, targetActivity, (IUser)originalUser.ToOguObject(), targetUsers.ToOguObjects<WfClientUser, IUser>()));

            return process.ToClientProcessInfo(runtimeContext.Operator).FillCurrentOpinion(process.CurrentActivity, runtimeContext.Operator);
        }
        public WfClientProcessInfo GetProcessInfoByActivityID(string activityID, WfClientUser user)
        {
            activityID.CheckStringIsNullOrEmpty("activityID");

            OperationContext.Current.FillContextToOguServiceContext();

            IWfProcess process = WfRuntime.GetProcessByActivityID(activityID);
            IWfActivity activity = process.Activities[activityID];

            return process.ToClientProcessInfo(activity, user).FillCurrentOpinion(activity, user);
        }
 public WfClientUserResourceDescriptor(WfClientUser user)
 {
     this.User = user;
 }
        public List<WfClientProcessInfo> GetProcessesInfoByResourceID(string resourceID, WfClientUser user)
        {
            resourceID.CheckStringIsNullOrEmpty("resourceID");

            OperationContext.Current.FillContextToOguServiceContext();

            WfProcessCollection processes = WfRuntime.GetProcessByResourceID(resourceID).SortByUserRelativity((IUser)user.ToOguObject());

            List<WfClientProcessInfo> result = new List<WfClientProcessInfo>();

            processes.ForEach(process => result.Add(process.ToClientProcessInfo(user).FillCurrentOpinion(process.CurrentActivity, user)));

            return result;
        }
        public WfClientProcessInfo GetProcessInfoByID(string processID, WfClientUser user)
        {
            processID.CheckStringIsNullOrEmpty("processID");

            OperationContext.Current.FillContextToOguServiceContext();

            IWfProcess process = WfRuntime.GetProcessByProcessID(processID);

            return process.ToClientProcessInfo(user).FillCurrentOpinion(process.CurrentActivity, user);
        }