public void DeleteResourceOnDeleteTask() { IProjectManager <Task, object> manager = new ProjectManager <Task, object>(); var task1 = new Task(); var task2 = new Task(); var r1 = new Task(); manager.Add(task1); manager.Add(task2); // setup: assign resource manager.Assign(task1, r1); manager.Assign(task2, r1); Assert.IsTrue(manager.ResourcesOf(task1).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(task2).Contains(r1)); Assert.IsTrue(manager.TasksOf(r1).Count() == 2); // test: delete task1 manager.Delete(task1); Assert.IsTrue(!manager.ResourcesOf(task1).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(task2).Contains(r1)); Assert.IsTrue(manager.TasksOf(r1).Count() == 1); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.Resources.Contains(r1)); // test: delete task2 manager.Delete(task2); Assert.IsTrue(!manager.ResourcesOf(task1).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(task2).Contains(r1)); Assert.IsTrue(manager.TasksOf(r1).Count() == 0); Assert.IsTrue(manager.Resources.Count() == 0); Assert.IsTrue(!manager.Resources.Contains(r1)); }
public void TransferResourceToSplitTaskOnMerge_ByDeleteInThisCase() { IProjectManager <Task, object> manager = new ProjectManager <Task, object>(); var split = new Task(); var part1 = new Task(); var part2 = new Task(); var r1 = new Task(); manager.Add(split); // setup: create a split task with resources on parts manager.Split(split, part1, part2, 1); manager.Assign(part1, r1); manager.Assign(part2, r1); Assert.IsTrue(!manager.TasksOf(r1).Contains(split)); Assert.IsTrue(manager.TasksOf(r1).Contains(part1)); Assert.IsTrue(manager.TasksOf(r1).Contains(part2)); Assert.IsTrue(!manager.ResourcesOf(split).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(part1).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(part2).Contains(r1)); Assert.IsTrue(manager.Resources.Count() == 1); // test: delete a part, expect a merge and resources transferred to split task manager.Delete(part1); Assert.IsTrue(manager.TasksOf(r1).Contains(split)); Assert.IsTrue(!manager.TasksOf(r1).Contains(part1)); Assert.IsTrue(!manager.TasksOf(r1).Contains(part2)); Assert.IsTrue(manager.ResourcesOf(split).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(part1).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(part2).Contains(r1)); Assert.IsTrue(manager.Resources.Count() == 1); }
private void btnUpdateTask_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { SelectedTask.Name = txtTaskName.Text.Trim(); _mManager.Unassign(_mChart.SelectedTask); foreach (DataGridViewRow row in gridTaskResources.Rows) { if ((bool)row.Cells["IsActive"].Value) { foreach (MyResource myResource in _mManager.GetAllResources()) { if (row.Cells["ID"].Value.ToString() == myResource.ID.ToString()) { _mManager.Assign(_mChart.SelectedTask, myResource); //continue; } } } } _mChart.Invalidate(); } catch (Exception ex) { string errMessage = ex.Message; if (ex.InnerException != null) { errMessage += string.Format("\n{0}", ex.InnerException.Message); } MessageBox.Show(errMessage, "ControlGanttChart::btnUpdateTask_Click", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Default; }
public void DeleteResourcesOnDeleteSplitTask() { IProjectManager <Task, object> manager = new ProjectManager <Task, object>(); var split = new Task(); var part1 = new Task(); var part2 = new Task(); var r1 = new Task(); manager.Add(split); // setup: create a split task with resources on parts manager.Split(split, part1, part2, 1); manager.Assign(part1, r1); manager.Assign(part2, r1); Assert.IsTrue(!manager.TasksOf(r1).Contains(split)); Assert.IsTrue(manager.TasksOf(r1).Contains(part1)); Assert.IsTrue(manager.TasksOf(r1).Contains(part2)); Assert.IsTrue(!manager.ResourcesOf(split).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(part1).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(part2).Contains(r1)); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.Tasks.Count() == 1); // test: delete the split task, everything should go manager.Delete(split); Assert.IsTrue(manager.Resources.Count() == 0); Assert.IsTrue(manager.Tasks.Count() == 0); Assert.IsTrue(!manager.TasksOf(r1).Contains(split)); Assert.IsTrue(!manager.TasksOf(r1).Contains(part1)); Assert.IsTrue(!manager.TasksOf(r1).Contains(part2)); Assert.IsTrue(!manager.ResourcesOf(split).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(part1).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(part2).Contains(r1)); // test: check that they are really deleted by adding them back again manager.Add(split); manager.Add(part1); manager.Add(part2); Assert.IsTrue(manager.Tasks.Count() == 3); }
public void UnassignResourceFromAllTask() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var one = new Task(); var two = new Task(); var r1 = new object(); var r2 = new object(); manager.Add(one); manager.Add(two); // setup: assign some resource manager.Assign(one, r1); manager.Assign(one, r2); manager.Assign(two, r1); manager.Assign(two, r2); Assert.IsTrue(manager.Resources.Count() == 2); Assert.IsTrue(manager.ResourcesOf(one).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(one).Contains(r2)); Assert.IsTrue(manager.ResourcesOf(two).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(two).Contains(r2)); Assert.IsTrue(manager.TasksOf(r1).Contains(one)); Assert.IsTrue(manager.TasksOf(r2).Contains(one)); Assert.IsTrue(manager.TasksOf(r1).Contains(two)); Assert.IsTrue(manager.TasksOf(r2).Contains(two)); manager.Unassign(r1); Assert.IsTrue(manager.Resources.Count() == 1, string.Format("Expected {0} != {1}", 1, manager.Resources.Count())); Assert.IsTrue(!manager.ResourcesOf(one).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(one).Contains(r2)); Assert.IsTrue(!manager.ResourcesOf(two).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(two).Contains(r2)); Assert.IsTrue(!manager.TasksOf(r1).Contains(one)); Assert.IsTrue(manager.TasksOf(r2).Contains(one)); Assert.IsTrue(!manager.TasksOf(r1).Contains(two)); Assert.IsTrue(manager.TasksOf(r2).Contains(two)); }
public void UnassignSpecificResource() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var one = new Task(); var r1 = new Task(); var r2 = new Task(); manager.Add(one); // setup: assign some resource manager.Assign(one, r1); manager.Assign(one, r2); Assert.IsTrue(manager.Resources.Count() == 2); Assert.IsTrue(manager.ResourcesOf(one).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(one).Contains(r2)); Assert.IsTrue(manager.TasksOf(r1).Contains(one)); Assert.IsTrue(manager.TasksOf(r2).Contains(one)); // test: unassign resource manager.Unassign(one, r2); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.ResourcesOf(one).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(one).Contains(r2)); Assert.IsTrue(manager.TasksOf(r1).Contains(one)); Assert.IsTrue(!manager.TasksOf(r2).Contains(one)); }
public void TwoWayResourceLookup() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var one = new Task(); var two = new Task(); var r1 = new Task(); var r2 = new Task(); manager.Add(one); manager.Add(two); // check initializations are correct Assert.IsTrue(manager.ResourcesOf(one) != null); Assert.IsTrue(manager.ResourcesOf(one).Count() == 0); Assert.IsTrue(manager.ResourcesOf(two) != null); Assert.IsTrue(manager.ResourcesOf(two).Count() == 0); // assign resource manager.Assign(one, r1); Assert.IsTrue(manager.ResourcesOf(one) != null); Assert.IsTrue(manager.ResourcesOf(one).Count() == 1); Assert.IsTrue(manager.ResourcesOf(one).FirstOrDefault().Equals(r1)); Assert.IsTrue(manager.TasksOf(r1).Count() == 1); Assert.IsTrue(manager.TasksOf(r1).FirstOrDefault().Equals(one)); // assign another resource manager.Assign(one, r2); Assert.IsTrue(manager.ResourcesOf(one) != null); Assert.IsTrue(manager.ResourcesOf(one).Count() == 2); Assert.IsTrue(manager.ResourcesOf(one).ElementAtOrDefault(1).Equals(r2)); Assert.IsTrue(manager.TasksOf(r2).Count() == 1); Assert.IsTrue(manager.TasksOf(r2).FirstOrDefault().Equals(one)); // assign resource to another task manager.Assign(two, r2); Assert.IsTrue(manager.ResourcesOf(two) != null); Assert.IsTrue(manager.ResourcesOf(two).Count() == 1); Assert.IsTrue(manager.ResourcesOf(two).FirstOrDefault().Equals(r2)); Assert.IsTrue(manager.TasksOf(r2).Count() == 2); Assert.IsTrue(manager.TasksOf(r2).ElementAtOrDefault(1).Equals(two)); }
public void UnassignAllResourceFromTask() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var one = new Task(); var two = new Task(); var r1 = new Task(); var r2 = new Task(); manager.Add(one); manager.Add(two); // setup: assign some resource manager.Assign(one, r1); manager.Assign(one, r2); manager.Assign(two, r1); manager.Assign(two, r2); Assert.IsTrue(manager.Resources.Count() == 2); Assert.IsTrue(manager.ResourcesOf(one).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(one).Contains(r2)); Assert.IsTrue(manager.ResourcesOf(two).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(two).Contains(r2)); Assert.IsTrue(manager.TasksOf(r1).Contains(one)); Assert.IsTrue(manager.TasksOf(r2).Contains(one)); Assert.IsTrue(manager.TasksOf(r1).Contains(two)); Assert.IsTrue(manager.TasksOf(r2).Contains(two)); manager.Unassign(one); Assert.IsTrue(manager.Resources.Count() == 2); Assert.IsTrue(!manager.ResourcesOf(one).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(one).Contains(r2)); Assert.IsTrue(manager.ResourcesOf(two).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(two).Contains(r2)); Assert.IsTrue(!manager.TasksOf(r1).Contains(one)); Assert.IsTrue(!manager.TasksOf(r2).Contains(one)); Assert.IsTrue(manager.TasksOf(r1).Contains(two)); Assert.IsTrue(manager.TasksOf(r2).Contains(two)); }
public void AssignSameResourceToDifferentTask() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var one = new Task(); var two = new Task(); var res = new Task() { Name = "Resource" }; manager.Add(one); manager.Add(two); // setup: assign resource manager.Assign(one, res); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.ResourcesOf(one).Count() == 1); Assert.IsTrue(manager.TasksOf(res).Count() == 1); Assert.IsTrue(manager.Resources.Contains(res)); Assert.IsTrue(manager.ResourcesOf(one).Contains(res)); Assert.IsTrue(manager.TasksOf(res).Contains(one)); // setup: assign resource. no extra resource should be created. resource reference shared by 2 tasks manager.Assign(two, res); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.ResourcesOf(one).Count() == 1); Assert.IsTrue(manager.ResourcesOf(two).Count() == 1); Assert.IsTrue(manager.TasksOf(res).Count() == 2); Assert.IsTrue(manager.Resources.Contains(res)); Assert.IsTrue(manager.ResourcesOf(one).Contains(res)); Assert.IsTrue(manager.ResourcesOf(two).Contains(res)); Assert.IsTrue(manager.TasksOf(res).Contains(one)); Assert.IsTrue(manager.TasksOf(res).Contains(two)); }
public void AssignSameResourceToSameTask() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var one = new Task(); var res = new Task() { Name = "Resource" }; manager.Add(one); // setup: assign resource manager.Assign(one, res); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.ResourcesOf(one).Count() == 1); Assert.IsTrue(manager.TasksOf(res).Count() == 1); Assert.IsTrue(manager.Resources.Contains(res)); Assert.IsTrue(manager.ResourcesOf(one).Contains(res)); Assert.IsTrue(manager.TasksOf(res).Contains(one)); // test: assign the same resource to the same task (no effect, as resource is already assigned) manager.Assign(one, res); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.ResourcesOf(one).Count() == 1); Assert.IsTrue(manager.TasksOf(res).Count() == 1); Assert.IsTrue(manager.Resources.Contains(res)); Assert.IsTrue(manager.ResourcesOf(one).Contains(res)); Assert.IsTrue(manager.TasksOf(res).Contains(one)); }
public void GetGantChar() { _mManager = new ProjectManager(); var work = new MyTask(_mManager) { Name = "创建APP" }; var wake = new MyTask(_mManager) { Name = "框架搭建" }; var teeth = new MyTask(_mManager) { Name = "数据库创建" }; var shower = new MyTask(_mManager) { Name = "自定义控件" }; var clothes = new MyTask(_mManager) { Name = "功能实现" }; var hair = new MyTask(_mManager) { Name = "功能测试" }; var pack = new MyTask(_mManager) { Name = "产品上架" }; var wake1 = new MyTask(_mManager) { Name = "框架搭建1" }; var wake2 = new MyTask(_mManager) { Name = "框架搭建2" }; _mManager.Add(work); _mManager.Add(wake1); _mManager.Add(wake2); _mManager.Add(wake); _mManager.Add(teeth); _mManager.Add(shower); _mManager.Add(clothes); _mManager.Add(hair); _mManager.Add(pack); // Create another 1000 tasks for stress testing Random rand = new Random(); //for (int i = 0; i < 1000; i++) //{ // var task = new MyTask(_mManager) { Name = string.Format("New Task {0}", i.ToString()) }; // _mManager.Add(task); // _mManager.SetStart(task, TimeSpan.FromDays(rand.Next(300))); // _mManager.SetDuration(task, TimeSpan.FromDays(rand.Next(50))); //} // Set task durations, e.g. using ProjectManager methods _mManager.SetDuration(wake, TimeSpan.FromDays(3)); _mManager.SetDuration(teeth, TimeSpan.FromDays(5)); _mManager.SetDuration(shower, TimeSpan.FromDays(7)); _mManager.SetDuration(clothes, TimeSpan.FromDays(4)); _mManager.SetDuration(hair, TimeSpan.FromDays(3)); _mManager.SetDuration(pack, TimeSpan.FromDays(5)); _mManager.SetDuration(wake1, TimeSpan.FromDays(2)); _mManager.SetDuration(wake2, TimeSpan.FromDays(4)); _mManager.SetStart(wake, TimeSpan.FromDays(10)); // _mManager.SetDuration(wake, TimeSpan.FromDays(40)); // demostrate splitting a task _mManager.Split(pack, new MyTask(_mManager), new MyTask(_mManager), TimeSpan.FromDays(2)); // Set task complete status, e.g. using newly created properties wake.Complete = 0.9f; teeth.Complete = 0.5f; shower.Complete = 0.4f; // Give the Tasks some organisation, setting group and precedents _mManager.Group(work, wake); _mManager.Group(work, teeth); _mManager.Group(work, shower); _mManager.Group(work, clothes); _mManager.Group(work, hair); _mManager.Group(work, pack); _mManager.Group(wake, wake1); _mManager.Group(wake, wake2); //_mManager.Relate(wake, teeth); //_mManager.Relate(wake, shower); //_mManager.Relate(shower, clothes); //_mManager.Relate(shower, hair); //_mManager.Relate(hair, pack); //_mManager.Relate(clothes, pack); // Create and assign Resources. // MyResource is just custom user class. The API can accept any object as resource. var jake = new MyResource() { Name = "张三" }; var peter = new MyResource() { Name = "李四" }; var john = new MyResource() { Name = "王五" }; var lucas = new MyResource() { Name = "赵六" }; var james = new MyResource() { Name = "李琦" }; var mary = new MyResource() { Name = "孙斌" }; // Add some resources _mManager.Assign(wake, jake); _mManager.Assign(wake, peter); _mManager.Assign(wake, john); _mManager.Assign(wake1, john); _mManager.Assign(wake2, jake); _mManager.Assign(teeth, jake); _mManager.Assign(teeth, james); _mManager.Assign(pack, james); _mManager.Assign(pack, lucas); _mManager.Assign(shower, mary); _mManager.Assign(shower, lucas); _mManager.Assign(shower, john); // Initialize the Chart with our ProjectManager and CreateTaskDelegate _mChart.Init(_mManager); _mChart.CreateTaskDelegate = delegate() { return(new MyTask(_mManager)); }; // Attach event listeners for events we are interested in //_mChart.TaskMouseOver += new EventHandler<TaskMouseEventArgs>(_mChart_TaskMouseOver); //_mChart.TaskMouseOut += new EventHandler<TaskMouseEventArgs>(_mChart_TaskMouseOut); //_mChart.TaskSelected += new EventHandler<TaskMouseEventArgs>(_mChart_TaskSelected); //_mChart.PaintOverlay += _mOverlay.ChartOverlayPainter; //_mChart.AllowTaskDragDrop = true; // set some tooltips to show the resources in each task _mChart.SetToolTip(wake, string.Join(", ", _mManager.ResourcesOf(wake).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(teeth, string.Join(", ", _mManager.ResourcesOf(teeth).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(pack, string.Join(", ", _mManager.ResourcesOf(pack).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(shower, string.Join(", ", _mManager.ResourcesOf(shower).Select(x => (x as MyResource).Name))); // Set Time information var span = DateTime.Today - _mManager.Start; _mManager.Now = span; // set the "Now" marker at the correct date _mChart.TimeResolution = TimeResolution.Day; // Set the chart to display in days in header host.Child = _mChart as System.Windows.Forms.Control; grd.Children.Add(host); }
public void AssignResourceForUnknownTasks() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var one = new Task(); var res = new Task() { Name = "Resource" }; // setup: confirm there is no resource Assert.IsTrue(manager.Resources.Count() == 0); Assert.IsTrue(manager.ResourcesOf(one).Count() == 0); Assert.IsTrue(manager.TasksOf(res).Count() == 0); // test: assign resource manager.Assign(one, res); Assert.IsTrue(manager.Resources.Count() == 0); Assert.IsTrue(manager.ResourcesOf(one).Count() == 0); Assert.IsTrue(manager.TasksOf(res).Count() == 0); }
public void TransferResourceToSplitTaskOnMerge_ByDeleteInThisCase() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var split = new Task(); var part1 = new Task(); var part2 = new Task(); var r1 = new Task(); manager.Add(split); // setup: create a split task with resources on parts manager.Split(split, part1, part2, 1); manager.Assign(part1, r1); manager.Assign(part2, r1); Assert.IsTrue(!manager.TasksOf(r1).Contains(split)); Assert.IsTrue(manager.TasksOf(r1).Contains(part1)); Assert.IsTrue(manager.TasksOf(r1).Contains(part2)); Assert.IsTrue(!manager.ResourcesOf(split).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(part1).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(part2).Contains(r1)); Assert.IsTrue(manager.Resources.Count() == 1); // test: delete a part, expect a merge and resources transferred to split task manager.Delete(part1); Assert.IsTrue(manager.TasksOf(r1).Contains(split)); Assert.IsTrue(!manager.TasksOf(r1).Contains(part1)); Assert.IsTrue(!manager.TasksOf(r1).Contains(part2)); Assert.IsTrue(manager.ResourcesOf(split).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(part1).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(part2).Contains(r1)); Assert.IsTrue(manager.Resources.Count() == 1); }
/// <summary> /// Example starts here /// </summary> public ExampleFull() { InitializeComponent(); // Create a Project and some Tasks _mManager = new ProjectManager(); var work = new MyTask(_mManager) { Name = "Prepare for Work" }; var wake = new MyTask(_mManager) { Name = "Wake Up" }; var teeth = new MyTask(_mManager) { Name = "Brush Teeth" }; var shower = new MyTask(_mManager) { Name = "Shower" }; var clothes = new MyTask(_mManager) { Name = "Change into New Clothes" }; var hair = new MyTask(_mManager) { Name = "Blow My Hair" }; var pack = new MyTask(_mManager) { Name = "Pack the Suitcase" }; _mManager.Add(work); _mManager.Add(wake); _mManager.Add(teeth); _mManager.Add(shower); _mManager.Add(clothes); _mManager.Add(hair); _mManager.Add(pack); // Create another 1000 tasks for stress testing Random rand = new Random(); for (int i = 0; i < 1000; i++) { var task = new MyTask(_mManager) { Name = string.Format("New Task {0}", i.ToString()) }; _mManager.Add(task); _mManager.SetStart(task, TimeSpan.FromDays(rand.Next(300))); _mManager.SetDuration(task, TimeSpan.FromDays(rand.Next(50))); } // Set task durations, e.g. using ProjectManager methods _mManager.SetDuration(wake, TimeSpan.FromDays(3)); _mManager.SetDuration(teeth, TimeSpan.FromDays(5)); _mManager.SetDuration(shower, TimeSpan.FromDays(7)); _mManager.SetDuration(clothes, TimeSpan.FromDays(4)); _mManager.SetDuration(hair, TimeSpan.FromDays(3)); _mManager.SetDuration(pack, TimeSpan.FromDays(5)); // demostrate splitting a task _mManager.Split(pack, new MyTask(_mManager), new MyTask(_mManager), TimeSpan.FromDays(2)); // Set task complete status, e.g. using newly created properties wake.Complete = 0.9f; teeth.Complete = 0.5f; shower.Complete = 0.4f; // Give the Tasks some organisation, setting group and precedents _mManager.Group(work, wake); _mManager.Group(work, teeth); _mManager.Group(work, shower); _mManager.Group(work, clothes); _mManager.Group(work, hair); _mManager.Group(work, pack); _mManager.Relate(wake, teeth); _mManager.Relate(wake, shower); _mManager.Relate(shower, clothes); _mManager.Relate(shower, hair); _mManager.Relate(hair, pack); _mManager.Relate(clothes, pack); // Create and assign Resources. // MyResource is just custom user class. The API can accept any object as resource. var jake = new MyResource() { Name = "Jake" }; var peter = new MyResource() { Name = "Peter" }; var john = new MyResource() { Name = "John" }; var lucas = new MyResource() { Name = "Lucas" }; var james = new MyResource() { Name = "James" }; var mary = new MyResource() { Name = "Mary" }; // Add some resources _mManager.Assign(wake, jake); _mManager.Assign(wake, peter); _mManager.Assign(wake, john); _mManager.Assign(teeth, jake); _mManager.Assign(teeth, james); _mManager.Assign(pack, james); _mManager.Assign(pack, lucas); _mManager.Assign(shower, mary); _mManager.Assign(shower, lucas); _mManager.Assign(shower, john); // Initialize the Chart with our ProjectManager and CreateTaskDelegate _mChart.Init(_mManager); _mChart.CreateTaskDelegate = delegate() { return(new MyTask(_mManager)); }; // Attach event listeners for events we are interested in _mChart.TaskMouseOver += new EventHandler <TaskMouseEventArgs>(_mChart_TaskMouseOver); _mChart.TaskMouseOut += new EventHandler <TaskMouseEventArgs>(_mChart_TaskMouseOut); _mChart.TaskSelected += new EventHandler <TaskMouseEventArgs>(_mChart_TaskSelected); _mChart.PaintOverlay += _mOverlay.ChartOverlayPainter; _mChart.AllowTaskDragDrop = true; // set some tooltips to show the resources in each task _mChart.SetToolTip(wake, string.Join(", ", _mManager.ResourcesOf(wake).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(teeth, string.Join(", ", _mManager.ResourcesOf(teeth).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(pack, string.Join(", ", _mManager.ResourcesOf(pack).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(shower, string.Join(", ", _mManager.ResourcesOf(shower).Select(x => (x as MyResource).Name))); // Set Time information var span = DateTime.Today - _mManager.Start; _mManager.Now = span; // set the "Now" marker at the correct date _mChart.TimeResolution = TimeResolution.Day; // Set the chart to display in days in header // Init the rest of the UI _InitExampleUI(); }
/// <summary> /// Example starts here /// </summary> public ExampleFull() { InitializeComponent(); // Create a Project and some Tasks _mManager = new ProjectManager(); var work = new MyTask(_mManager) { Name = "Prepare for Work" }; var wake = new MyTask(_mManager) { Name = "Wake Up" }; var teeth = new MyTask(_mManager) { Name = "Brush Teeth" }; var shower = new MyTask(_mManager) { Name = "Shower" }; var clothes = new MyTask(_mManager) { Name = "Change into New Clothes" }; var hair = new MyTask(_mManager) { Name = "Blow My Hair" }; var pack = new MyTask(_mManager) { Name = "Pack the Suitcase" }; _mManager.Add(work); _mManager.Add(wake); _mManager.Add(teeth); _mManager.Add(shower); _mManager.Add(clothes); _mManager.Add(hair); _mManager.Add(pack); // Create another 1000 tasks for stress testing Random rand = new Random(); for (int i = 0; i < 1000; i++) { var task = new MyTask(_mManager) { Name = string.Format("New Task {0}", i.ToString()) }; _mManager.Add(task); _mManager.SetStart(task, rand.Next(300)); _mManager.SetDuration(task, rand.Next(50)); } // Set task durations, e.g. using ProjectManager methods _mManager.SetDuration(wake, 3); _mManager.SetDuration(teeth, 5); _mManager.SetDuration(shower, 7); _mManager.SetDuration(clothes, 4); _mManager.SetDuration(hair, 3); _mManager.SetDuration(pack, 5); // demostrate splitting a task _mManager.Split(pack, new MyTask(_mManager), new MyTask(_mManager), 2); // Set task complete status, e.g. using newly created properties wake.Complete = 0.9f; teeth.Complete = 0.5f; shower.Complete = 0.4f; // Give the Tasks some organisation, setting group and precedents _mManager.Group(work, wake); _mManager.Group(work, teeth); _mManager.Group(work, shower); _mManager.Group(work, clothes); _mManager.Group(work, hair); _mManager.Group(work, pack); _mManager.Relate(wake, teeth); _mManager.Relate(wake, shower); _mManager.Relate(shower, clothes); _mManager.Relate(shower, hair); _mManager.Relate(hair, pack); _mManager.Relate(clothes, pack); // Create and assign Resources. // MyResource is just custom user class. The API can accept any object as resource. var jake = new MyResource() { Name = "Jake" }; var peter = new MyResource() { Name = "Peter" }; var john = new MyResource() { Name = "John" }; var lucas = new MyResource() { Name = "Lucas" }; var james = new MyResource() { Name = "James" }; var mary = new MyResource() { Name = "Mary" }; // Add some resources _mManager.Assign(wake, jake); _mManager.Assign(wake, peter); _mManager.Assign(wake, john); _mManager.Assign(teeth, jake); _mManager.Assign(teeth, james); _mManager.Assign(pack, james); _mManager.Assign(pack, lucas); _mManager.Assign(shower, mary); _mManager.Assign(shower, lucas); _mManager.Assign(shower, john); // Initialize the Chart with our ProjectManager and CreateTaskDelegate _mChart.Init(_mManager); _mChart.CreateTaskDelegate = delegate() { return new MyTask(_mManager); }; // Attach event listeners for events we are interested in _mChart.TaskMouseOver += new EventHandler<TaskMouseEventArgs>(_mChart_TaskMouseOver); _mChart.TaskMouseOut += new EventHandler<TaskMouseEventArgs>(_mChart_TaskMouseOut); _mChart.TaskSelected += new EventHandler<TaskMouseEventArgs>(_mChart_TaskSelected); _mChart.PaintOverlay += _mOverlay.ChartOverlayPainter; _mChart.AllowTaskDragDrop = true; // set some tooltips to show the resources in each task _mChart.SetToolTip(wake, string.Join(", ", _mManager.ResourcesOf(wake).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(teeth, string.Join(", ", _mManager.ResourcesOf(teeth).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(pack, string.Join(", ", _mManager.ResourcesOf(pack).Select(x => (x as MyResource).Name))); _mChart.SetToolTip(shower, string.Join(", ", _mManager.ResourcesOf(shower).Select(x => (x as MyResource).Name))); // Set Time information _mManager.TimeScale = TimeScale.Day; var span = DateTime.Today - _mManager.Start; _mManager.Now = (int)Math.Round(span.TotalDays); // set the "Now" marker at the correct date _mChart.TimeScaleDisplay = TimeScaleDisplay.DayOfWeek; // Set the chart to display days of week in header // Init the rest of the UI _InitExampleUI(); }
public void DeleteResourcesOnDeleteSplitTask() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var split = new Task(); var part1 = new Task(); var part2 = new Task(); var r1 = new Task(); manager.Add(split); // setup: create a split task with resources on parts manager.Split(split, part1, part2, 1); manager.Assign(part1, r1); manager.Assign(part2, r1); Assert.IsTrue(!manager.TasksOf(r1).Contains(split)); Assert.IsTrue(manager.TasksOf(r1).Contains(part1)); Assert.IsTrue(manager.TasksOf(r1).Contains(part2)); Assert.IsTrue(!manager.ResourcesOf(split).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(part1).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(part2).Contains(r1)); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.Tasks.Count() == 1); // test: delete the split task, everything should go manager.Delete(split); Assert.IsTrue(manager.Resources.Count() == 0); Assert.IsTrue(manager.Tasks.Count() == 0); Assert.IsTrue(!manager.TasksOf(r1).Contains(split)); Assert.IsTrue(!manager.TasksOf(r1).Contains(part1)); Assert.IsTrue(!manager.TasksOf(r1).Contains(part2)); Assert.IsTrue(!manager.ResourcesOf(split).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(part1).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(part2).Contains(r1)); // test: check that they are really deleted by adding them back again manager.Add(split); manager.Add(part1); manager.Add(part2); Assert.IsTrue(manager.Tasks.Count() == 3); }
public void DeleteResourceOnDeleteTask() { IProjectManager<Task, object> manager = new ProjectManager<Task, object>(); var task1 = new Task(); var task2 = new Task(); var r1 = new Task(); manager.Add(task1); manager.Add(task2); // setup: assign resource manager.Assign(task1, r1); manager.Assign(task2, r1); Assert.IsTrue(manager.ResourcesOf(task1).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(task2).Contains(r1)); Assert.IsTrue(manager.TasksOf(r1).Count() == 2); // test: delete task1 manager.Delete(task1); Assert.IsTrue(!manager.ResourcesOf(task1).Contains(r1)); Assert.IsTrue(manager.ResourcesOf(task2).Contains(r1)); Assert.IsTrue(manager.TasksOf(r1).Count() == 1); Assert.IsTrue(manager.Resources.Count() == 1); Assert.IsTrue(manager.Resources.Contains(r1)); // test: delete task2 manager.Delete(task2); Assert.IsTrue(!manager.ResourcesOf(task1).Contains(r1)); Assert.IsTrue(!manager.ResourcesOf(task2).Contains(r1)); Assert.IsTrue(manager.TasksOf(r1).Count() == 0); Assert.IsTrue(manager.Resources.Count() == 0); Assert.IsTrue(!manager.Resources.Contains(r1)); }