public override void ClientToServer(WfClientResourceDescriptor client, ref WfResourceDescriptor server)
 {
     if (server == null)
         server = new WfDepartmentResourceDescriptor((IOrganization)((WfClientDepartmentResourceDescriptor)client).Department.ToOguObject());
     else
         ((WfDepartmentResourceDescriptor)server).Department = (IOrganization)((WfClientDepartmentResourceDescriptor)client).Department.ToOguObject();
 }
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            WfDepartmentResourceDescriptor deptResourceDesp = (WfDepartmentResourceDescriptor)base.Deserialize(dictionary, type, serializer);
            IOrganization orga = JSONSerializerExecute.Deserialize <OguOrganization>(dictionary["Department"]);

            deptResourceDesp.Department = orga;
            return(deptResourceDesp);
        }
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            WfDepartmentResourceDescriptor deptResourceDesp = (WfDepartmentResourceDescriptor)obj;

            IDictionary <string, object> dictionary = base.Serialize(obj, serializer);

            dictionary.Add("Department", deptResourceDesp.Department);
            return(dictionary);
        }
		public void WfDepartmentResourceDescriptorConveterTest()
		{
			WfConverterHelper.RegisterConverters();

			IUser user = (IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object;

			IOrganization orga = user.Parent;
			WfDepartmentResourceDescriptor deptResuDesp = new WfDepartmentResourceDescriptor(orga);

			string result = JSONSerializerExecute.Serialize(deptResuDesp);

			Console.WriteLine(result);

			WfDepartmentResourceDescriptor deserializedDeptDesp = JSONSerializerExecute.Deserialize<WfDepartmentResourceDescriptor>(result);

			string reSerialized = JSONSerializerExecute.Serialize(deserializedDeptDesp);

			Assert.AreEqual(result, reSerialized);

			ResourceConverterTest(deptResuDesp);

		}
		public void SimpleProcessDescriptorWithDeptResSerializeTest()
		{
			WfConverterHelper.RegisterConverters();

			WfProcessDescriptor processDesp = (WfProcessDescriptor)WfProcessTestCommon.CreateSimpleProcessDescriptor();

			IUser user = (IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object;
			IOrganization orga = user.Parent;
			WfDepartmentResourceDescriptor deptResuDesp = new WfDepartmentResourceDescriptor(orga);

			processDesp.InitialActivity.Resources.Add(deptResuDesp);

			string result = JSONSerializerExecute.Serialize(processDesp);

			processDesp = JSONSerializerExecute.Deserialize<WfProcessDescriptor>(result);

			XElementFormatter formatter = new XElementFormatter();

			XElement root = formatter.Serialize(processDesp);

			Console.WriteLine(root.ToString());

			IWfProcessDescriptor clonedProcessDesp = (IWfProcessDescriptor)formatter.Deserialize(root);

		}
		public void BuildStartBranchProcessTaskProcessTest()
		{
			IWfProcessDescriptor processDesp = CreateProcessWithAutoMaintainProperty();

			IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp);

			MoveToExecutor(process);

			process = WfRuntime.GetProcessByProcessID(process.ID);
			IWfActivity ownerActivity = process.CurrentActivity;

			Console.WriteLine("OwnerActivityID: {0}", ownerActivity.ID);

			//在Template设置资源为一个组织,用于后续分发分支流程的测试
			IWfBranchProcessTemplateDescriptor template = ownerActivity.Descriptor.BranchProcessTemplates[0];

			IUser userInTemplate = template.Resources.ToUsers().FirstOrDefault();

			WfDepartmentResourceDescriptor deptResourceDesp = new WfDepartmentResourceDescriptor(userInTemplate.Parent);

			template.Resources.Clear();
			template.Resources.Add(deptResourceDesp);

			SysTaskAdapter.Instance.ClearAll();

			StartBranchProcessSysTaskProcessBuilder builder = new StartBranchProcessSysTaskProcessBuilder(ownerActivity.ID, template, true);

			SysTaskProcess sysTaskProcess = builder.Build();

			SysTaskProcessRuntime.ClearCache();

			sysTaskProcess = SysTaskProcessRuntime.GetProcessByID(sysTaskProcess.ID);

			Console.WriteLine("SysTaskProcess ID: {0}", sysTaskProcess.ID);
			Console.WriteLine("SysTaskProcess Activities: {0}", sysTaskProcess.Activities.Count);

			Assert.AreEqual(template.Resources.ToUsers().Count + 1, sysTaskProcess.Activities.Count);
		}
		public void DispatchStartBranchProcessTaskTest()
		{
			IWfProcessDescriptor processDesp = CreateProcessWithAutoMaintainProperty();

			IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp);

			MoveToExecutor(process);

			process = WfRuntime.GetProcessByProcessID(process.ID);
			IWfActivity ownerActivity = process.CurrentActivity;

			Console.WriteLine("OwnerActivityID: {0}", ownerActivity.ID);

			//在Template设置资源为一个组织,用于后续分发分支流程的测试
			IWfBranchProcessTemplateDescriptor template = ownerActivity.Descriptor.BranchProcessTemplates[0];

			IUser userInTemplate = template.Resources.ToUsers().FirstOrDefault();

			WfDepartmentResourceDescriptor deptResourceDesp = new WfDepartmentResourceDescriptor(userInTemplate.Parent);

			template.Resources.Clear();
			template.Resources.Add(deptResourceDesp);

			SysTaskAdapter.Instance.ClearAll();

			SysTaskCommon.ExecuteAndAssertTask(DispatchStartBranchProcessTask.SendTask(ownerActivity.ID, template, true));

			WfRuntime.ClearCache();

			process = WfRuntime.GetProcessByProcessID(process.ID);

			int startedTaskCount = (int)WfServiceInvoker.InvokeContext["returnValue"];

			Console.WriteLine("Started Branch Task Count: {0}", startedTaskCount);

			Assert.IsTrue(startedTaskCount > 0);

			int executedTaskCount = SysTaskCommon.ExecuteAllTasks();

			Assert.AreEqual(startedTaskCount, executedTaskCount);

			WfRuntime.ClearCache();

			process = WfRuntime.GetProcessByProcessID(process.ID);

			Assert.AreEqual(WfProcessStatus.Running, process.Status);
			Assert.IsTrue(process.CurrentActivity.BranchProcessGroups.Count > 0);

			Assert.AreEqual(startedTaskCount - 1, process.CurrentActivity.BranchProcessGroups[0].Branches.Count);
		}