We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

qrist0ph on 05/15/08


Tagged

comos


Versions (?)


Direktzugriff auf Comos


Published in: C# 


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Plt;
  6. using Comos.Wrapper;
  7.  
  8. namespace Comos.Visualization
  9. {
  10. public class ForTesting
  11. {
  12. public void testEins(Comos.Wrapper.Task task)
  13. {
  14. //Task t = task.GetSubTasks()[0];
  15. //t.GetPlannedWorkingHours(null,System.DateTime.Now);
  16. //t.setWorkloadXmlString(Tools.WorkloadXmlGenerator.generateSampleWorkloadXml());
  17. //Tools.ProjectTraversalAlgorithms.preOrderTaskTraversal(task, setWorkloadXmlString);
  18.  
  19.  
  20. /* WrapperDebug.WriteLine("testEins");
  21.   WrapperDebug.WriteLine((task.GetComosObject().XMLString));
  22.   task.GetComosObject().XMLString = "<ueberWrapper>ddd</ueberWrapper>";
  23.   task.GetComosObject().spec("SYS.US").XMLString = "<ueberWrapper>ddd</ueberWrapper>";
  24.   //WrapperDebug.WriteLine(task.GetComosObject()
  25.   * */
  26. }
  27.  
  28.  
  29. public static void calledWhenStarting(IComosDDevice device, IComosDWorkset workset)
  30. {
  31. Task task = new Task(device.SystemUID());
  32. Tools.ProjectTraversalAlgorithms.preOrderTaskTraversal(task, visitorGetPlannedWhTest);
  33.  
  34.  
  35. //listAllUsers(workset);
  36. }
  37.  
  38. private static void listAllUsers(IComosDWorkset workset)
  39. {
  40. IComosDOwnCollection allUsers = workset.GetAllUsers();
  41. new ComosObjectCollection<User>(allUsers);
  42.  
  43. for (int i = 1; i <= allUsers.Count(); i++)
  44. {
  45. // IComosDSpecification spec = (IComosDSpecification)allUsers.Item(i);
  46. // IComosBaseObject lObject = (IComosBaseObject)spec.LinkObject;
  47. //ODER
  48. IComosDDevice dev = (IComosDDevice)allUsers.Item(i);
  49. Console.WriteLine(dev.Name);
  50.  
  51.  
  52. }
  53.  
  54. //return new ComosObjectCollection<User>(resourceColl);
  55. /*
  56.   foreach (IComosDDevice device in allUsers)
  57.   {
  58.   Wrapper.User user = (User)ComosObjectFactory.Create(device);
  59.   //WrapperDebug(user.Name);
  60.   }
  61.   */
  62. }
  63.  
  64. public void setWorkload(Comos.Wrapper.Task task)
  65. {
  66. //task.GetSp
  67. }
  68.  
  69.  
  70. /// <summary>
  71. /// Used as visitor (GoF Pattern) for ProjectTraversalAlgorithms.preOrderTaskTraversal
  72. /// </summary>
  73. /// <param name="t"></param>
  74. private void myTaskVisitor(Task t)
  75. {
  76. WrapperDebug.WriteLine(t.Name);
  77. Tools.WorkloadXmlGenerator.generateSampleWorkloadXml();
  78. }
  79.  
  80. /// <summary>
  81. /// Used as visitor (GoF Pattern) for ProjectTraversalAlgorithms.preOrderTaskTraversal
  82. /// </summary>
  83. /// <param name="t"></param>
  84. private void setWorkloadXmlString(Task t)
  85. {
  86. t.setWorkloadXmlString(Tools.WorkloadXmlGenerator.generateSampleWorkloadXml());
  87. }
  88.  
  89. /// <summary>
  90. /// Testing Method
  91. /// Prints the planned workload for Users and all days of this task
  92. /// </summary>
  93. /// <param name="t">the Task that is visited</param>
  94. private static void visitorGetPlannedWhTest(Task t)
  95. {
  96. foreach (User u in t.OwnResources)
  97. {
  98. 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());
  99. }
  100.  
  101. }
  102.  
  103.  
  104. public static void comosDirekt(){
  105.  
  106.  
  107.  
  108. IComosDWorkset workset = null;
  109.  
  110. Comos.Wrapper.Task wrapperProject = null;
  111. Comos.Wrapper.Task wrapperTask = null;
  112. Comos.Wrapper.Task wrapperWorkflow = null;
  113. Comos.Wrapper.Milestone wrapperMilestone = null;
  114. Comos.Wrapper.Role wrapperRole = null;
  115. Comos.Wrapper.User wrapperUser = null;
  116. Comos.Wrapper.Document wrapperDocument = null;
  117. Comos.Wrapper.Task wrapperProcess = null;
  118. Comos.Wrapper.ComosObjectSubstitute wrapperComosObjectSubstitute = null;
  119.  
  120. #region Konstanten
  121.  
  122. const string PATH_TO_DB = @"Z:\ComosT6\T6DevelopmentDB\Comos.mdb";
  123. const string PROJECT_NAME = "SO1";
  124. const int WORKING_LAYER_ID = 236;
  125. const string PROJECT_UID = "A2C2073YIX";
  126.  
  127. const string A_PROJECT_UID = "A2C2073YIX";
  128. const string A_TASK_UID = "A2C7452SBI";
  129. const string A_MASSTASK_UID = "A2C745JQBI";
  130. const string A_WORKFLOW_UID = "A2C745XCBI";
  131. const string A_ACTIVITY_UID = "A2C7460EBI";
  132. const string A_MILESTONE_UID = "A2C745BOBI";
  133. const string A_ROLE_UID = "A2AUCH72UG";
  134. const string A_USER_UID = "A20SMTGIAY";
  135. const string A_DOCUMENT_UID = "A2C5IWJ2HF";
  136. const string A_NO_WRAPPER_UID = "A2B93VJ0TN";
  137.  
  138. #endregion
  139.  
  140.  
  141.  
  142.  
  143.  
  144. IComosDProject project = null;
  145.  
  146. System.Console.WriteLine("Connecting to COMOS DB...");
  147.  
  148. string username = System.Environment.UserName.ToUpper();
  149. /*
  150.   try
  151.   {
  152.   System.Console.WriteLine("Getting Comos object...");
  153.   workset = (IComosDWorkset)Marshal.GetActiveObject("Comos");
  154.   }
  155.   catch
  156.   {
  157.   System.Console.WriteLine("Getting Comos Object failed.");
  158.   }
  159.   */
  160. if (workset == null)
  161. {
  162. System.Console.WriteLine("Trying to create Comos object...");
  163. workset = (IComosDWorkset)Activator.CreateInstance(Type.GetTypeFromProgID("Comos"));
  164. }
  165.  
  166. if (workset != null)
  167. {
  168. if (workset.Init("", "", PATH_TO_DB)) //TODO: Handle Exceptions
  169. {
  170. if (workset.GetAllUsers() != null)
  171. {
  172.  
  173. if (workset.GetAllUsers().Item(username) != null)
  174. {
  175. workset.SetCurrentUser(workset.GetAllUsers().Item(username));
  176. System.Console.WriteLine("User " + username + " logged in.");
  177.  
  178. }
  179. else
  180. {
  181. throw new ApplicationException("User " + username + " doesn't exist.");
  182. }
  183.  
  184. if (workset.GetAllProjects() != null)
  185. {
  186. if (workset.GetAllProjects().ItemExist(PROJECT_NAME))
  187. {
  188. project = (IComosDProject)workset.GetAllProjects().Item(PROJECT_NAME);
  189. System.Console.WriteLine("Setting working layer to " + WORKING_LAYER_ID + ".");
  190. IComosDWorkingOverlay workingLayer = project.GetWorkingOverlay(WORKING_LAYER_ID);
  191. if (workingLayer == null)
  192. {
  193. throw new ApplicationException("The working layer with ID " + WORKING_LAYER_ID + " doesn't exist.");
  194. }
  195. workset.SetCurrentProject(project);
  196. project.CurrentWorkingOverlay = workingLayer;
  197. //IComosDCDevice projectDevice = project.GetCDeviceBySystemFullname(projectFullName, 1);
  198. //IComosDDevice projectDevice = project.GetObjectByPathFullName(
  199. IComosDDevice projectDevice = workset.LoadObjectByType(ComosSystemTypes.SystemTypeDevice, PROJECT_UID) as IComosDDevice;
  200.  
  201. if (projectDevice == null)
  202. {
  203. throw new ApplicationException("Getting the project device failed. Check the device UID string.");
  204. }
  205. System.Console.WriteLine("Project " + PROJECT_NAME + " loaded.");
  206.  
  207. Comos.Wrapper.ComosObjectSubstitute.Init(workset);
  208. wrapperTask = new Comos.Wrapper.Task("A2CDOWCK78");
  209. Console.WriteLine(wrapperTask.Name);
  210. }
  211. else
  212. {
  213. throw new ApplicationException("ProjectName " + PROJECT_NAME + " doesn't exist.");
  214. }
  215. }
  216. }
  217. }
  218. }
  219. else
  220. {
  221. throw new ApplicationException("Workset is still NULL!");
  222. }
  223. }
  224.  
  225. }
  226. }

Report this snippet 

You need to login to post a comment.