复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Plt;
using Comos.Wrapper;
namespace Comos.Visualization
{
public class ForTesting
{
public void testEins(Comos.Wrapper.Task task)
{
//Task t = task.GetSubTasks()[0];
//t.GetPlannedWorkingHours(null,System.DateTime.Now);
//t.setWorkloadXmlString(Tools.WorkloadXmlGenerator.generateSampleWorkloadXml());
//Tools.ProjectTraversalAlgorithms.preOrderTaskTraversal(task, setWorkloadXmlString);
/* WrapperDebug.WriteLine("testEins");
WrapperDebug.WriteLine((task.GetComosObject().XMLString));
task.GetComosObject().XMLString = "<ueberWrapper>ddd</ueberWrapper>";
task.GetComosObject().spec("SYS.US").XMLString = "<ueberWrapper>ddd</ueberWrapper>";
//WrapperDebug.WriteLine(task.GetComosObject()
* */
}
public static void calledWhenStarting(IComosDDevice device, IComosDWorkset workset)
{
Task task = new Task(device.SystemUID());
Tools.ProjectTraversalAlgorithms.preOrderTaskTraversal(task, visitorGetPlannedWhTest);
//listAllUsers(workset);
}
private static void listAllUsers(IComosDWorkset workset)
{
IComosDOwnCollection allUsers = workset.GetAllUsers();
new ComosObjectCollection<User>(allUsers);
for (int i = 1; i <= allUsers.Count(); i++)
{
// IComosDSpecification spec = (IComosDSpecification)allUsers.Item(i);
// IComosBaseObject lObject = (IComosBaseObject)spec.LinkObject;
//ODER
IComosDDevice dev = (IComosDDevice)allUsers.Item(i);
Console.WriteLine(dev.Name);
}
//return new ComosObjectCollection<User>(resourceColl);
/*
foreach (IComosDDevice device in allUsers)
{
Wrapper.User user = (User)ComosObjectFactory.Create(device);
//WrapperDebug(user.Name);
}
*/
}
public void setWorkload(Comos.Wrapper.Task task)
{
//task.GetSp
}
/// <summary>
/// Used as visitor (GoF Pattern) for ProjectTraversalAlgorithms.preOrderTaskTraversal
/// </summary>
/// <param name="t"></param>
private void myTaskVisitor(Task t)
{
WrapperDebug.WriteLine(t.Name);
Tools.WorkloadXmlGenerator.generateSampleWorkloadXml();
}
/// <summary>
/// Used as visitor (GoF Pattern) for ProjectTraversalAlgorithms.preOrderTaskTraversal
/// </summary>
/// <param name="t"></param>
private void setWorkloadXmlString(Task t)
{
t.setWorkloadXmlString(Tools.WorkloadXmlGenerator.generateSampleWorkloadXml());
}
/// <summary>
/// Testing Method
/// Prints the planned workload for Users and all days of this task
/// </summary>
/// <param name="t">the Task that is visited</param>
private static void visitorGetPlannedWhTest(Task t)
{
foreach (User u in t.OwnResources)
{
WrapperDebug.WriteLine("planned workload: "+ t.Name + ": "+ u.Name +" worked " + t.GetPlannedWorkingHours(u,new DateTime(2008,5,8,10,10,10,10)) +" hours on " +" on " + (new DateTime(2008,5,8,10,10,10,10)).ToShortDateString());
}
}
public static void comosDirekt(){
IComosDWorkset workset = null;
Comos.Wrapper.Task wrapperProject = null;
Comos.Wrapper.Task wrapperTask = null;
Comos.Wrapper.Task wrapperWorkflow = null;
Comos.Wrapper.Milestone wrapperMilestone = null;
Comos.Wrapper.Role wrapperRole = null;
Comos.Wrapper.User wrapperUser = null;
Comos.Wrapper.Document wrapperDocument = null;
Comos.Wrapper.Task wrapperProcess = null;
Comos.Wrapper.ComosObjectSubstitute wrapperComosObjectSubstitute = null;
#region Konstanten
const string PATH_TO_DB = @"Z:\ComosT6\T6DevelopmentDB\Comos.mdb";
const string PROJECT_NAME = "SO1";
const int WORKING_LAYER_ID = 236;
const string PROJECT_UID = "A2C2073YIX";
const string A_PROJECT_UID = "A2C2073YIX";
const string A_TASK_UID = "A2C7452SBI";
const string A_MASSTASK_UID = "A2C745JQBI";
const string A_WORKFLOW_UID = "A2C745XCBI";
const string A_ACTIVITY_UID = "A2C7460EBI";
const string A_MILESTONE_UID = "A2C745BOBI";
const string A_ROLE_UID = "A2AUCH72UG";
const string A_USER_UID = "A20SMTGIAY";
const string A_DOCUMENT_UID = "A2C5IWJ2HF";
const string A_NO_WRAPPER_UID = "A2B93VJ0TN";
#endregion
IComosDProject project = null;
System.Console.WriteLine("Connecting to COMOS DB...");
string username = System.Environment.UserName.ToUpper();
/*
try
{
System.Console.WriteLine("Getting Comos object...");
workset = (IComosDWorkset)Marshal.GetActiveObject("Comos");
}
catch
{
System.Console.WriteLine("Getting Comos Object failed.");
}
*/
if (workset == null)
{
System.Console.WriteLine("Trying to create Comos object...");
workset = (IComosDWorkset)Activator.CreateInstance(Type.GetTypeFromProgID("Comos"));
}
if (workset != null)
{
if (workset.Init("", "", PATH_TO_DB)) //TODO: Handle Exceptions
{
if (workset.GetAllUsers() != null)
{
if (workset.GetAllUsers().Item(username) != null)
{
workset.SetCurrentUser(workset.GetAllUsers().Item(username));
System.Console.WriteLine("User " + username + " logged in.");
}
else
{
throw new ApplicationException("User " + username + " doesn't exist.");
}
if (workset.GetAllProjects() != null)
{
if (workset.GetAllProjects().ItemExist(PROJECT_NAME))
{
project = (IComosDProject)workset.GetAllProjects().Item(PROJECT_NAME);
System.Console.WriteLine("Setting working layer to " + WORKING_LAYER_ID + ".");
IComosDWorkingOverlay workingLayer = project.GetWorkingOverlay(WORKING_LAYER_ID);
if (workingLayer == null)
{
throw new ApplicationException("The working layer with ID " + WORKING_LAYER_ID + " doesn't exist.");
}
workset.SetCurrentProject(project);
project.CurrentWorkingOverlay = workingLayer;
//IComosDCDevice projectDevice = project.GetCDeviceBySystemFullname(projectFullName, 1);
//IComosDDevice projectDevice = project.GetObjectByPathFullName(
IComosDDevice projectDevice = workset.LoadObjectByType(ComosSystemTypes.SystemTypeDevice, PROJECT_UID) as IComosDDevice;
if (projectDevice == null)
{
throw new ApplicationException("Getting the project device failed. Check the device UID string.");
}
System.Console.WriteLine("Project " + PROJECT_NAME + " loaded.");
Comos.Wrapper.ComosObjectSubstitute.Init(workset);
wrapperTask = new Comos.Wrapper.Task("A2CDOWCK78");
Console.WriteLine(wrapperTask.Name);
}
else
{
throw new ApplicationException("ProjectName " + PROJECT_NAME + " doesn't exist.");
}
}
}
}
}
else
{
throw new ApplicationException("Workset is still NULL!");
}
}
}
}