[13733] | 1 | using HeuristicLab.Clients.Hive.WebJobManager.Services;
|
---|
| 2 | using HeuristicLab.Optimization;
|
---|
| 3 | using Microsoft.AspNet.SignalR;
|
---|
| 4 | using System;
|
---|
| 5 | using System.Collections.Generic;
|
---|
| 6 | using System.Linq;
|
---|
| 7 | using System.Threading.Tasks;
|
---|
| 8 |
|
---|
| 9 | namespace HeuristicLab.Clients.Hive.WebJobManager
|
---|
| 10 | {
|
---|
| 11 | /// <summary>
|
---|
| 12 | /// SignalR Hub for displaying the progress when uploading a Job.
|
---|
| 13 | /// Also used to change child distribution and priority for inner tasks.
|
---|
| 14 | /// </summary>
|
---|
| 15 | public class ProgressHub : Hub
|
---|
| 16 | {
|
---|
[13739] | 17 | private WebLoginService weblog;
|
---|
| 18 | private Guid userId;
|
---|
| 19 | private FileOpeningService fileopener;
|
---|
| 20 | private void loader()
|
---|
| 21 | {
|
---|
| 22 | weblog = WebLoginService.Instance;
|
---|
| 23 | string uid = Context.QueryString["userid"];
|
---|
| 24 | if (uid == null || uid == "" || Guid.Parse(uid) == Guid.Empty)
|
---|
| 25 | {
|
---|
| 26 | userId = Guid.Empty;
|
---|
| 27 | }
|
---|
| 28 | else {
|
---|
| 29 | userId = Guid.Parse(uid);
|
---|
| 30 | fileopener = weblog.getFileOpener(userId);
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[13733] | 34 | /// <summary>
|
---|
| 35 | /// First message from client
|
---|
| 36 | /// </summary>
|
---|
| 37 | /// <param name="receivedString">Client message</param>
|
---|
| 38 | public void HandleMessage(string receivedString)
|
---|
| 39 | {
|
---|
[13739] | 40 | loader();
|
---|
[13735] | 41 | Clients.Caller.processMessage("Connection Established");
|
---|
[13739] | 42 | fileopener.Job.Progress.StatusChanged += runHub;
|
---|
[13733] | 43 | }
|
---|
| 44 | /// <summary>
|
---|
| 45 | /// Changes name for the current job to be created
|
---|
| 46 | /// </summary>
|
---|
| 47 | /// <param name="name">Job name</param>
|
---|
[13735] | 48 | public void ChangeNameResource(string name, string resource)
|
---|
[13733] | 49 | {
|
---|
[13739] | 50 | loader();
|
---|
[13733] | 51 | if (name != null)
|
---|
[13739] | 52 | fileopener.Job.Job.Name = name;
|
---|
[13735] | 53 | if(resource != null && resource != "")
|
---|
| 54 | {
|
---|
[13739] | 55 | fileopener.Job.Job.ResourceNames += "/" + resource;
|
---|
[13735] | 56 | }
|
---|
[13733] | 57 | }
|
---|
| 58 | /// <summary>
|
---|
| 59 | /// Toggles distribute child task for a current task
|
---|
| 60 | /// </summary>
|
---|
| 61 | /// <param name="arr">2-dimensional int array.
|
---|
| 62 | /// First dimension is depth (arr.length == 4 means the item is 4 nodes deep)
|
---|
| 63 | /// Second contains expirement info or batch info. (arr[][0] contains index to select the right experiment sub task,
|
---|
| 64 | /// arr[][1] contains index to select right batch run subtask)</param>
|
---|
| 65 | public void ToggleChild(int[][] arr)
|
---|
| 66 | {
|
---|
[13739] | 67 | loader();
|
---|
| 68 | HiveTask current = fileopener.Job.HiveTasks.ToList()[0];
|
---|
[13733] | 69 | if (arr.Length == 0)
|
---|
| 70 | {//check if upper job
|
---|
| 71 | current.ItemTask.ComputeInParallel = !current.ItemTask.ComputeInParallel;
|
---|
| 72 |
|
---|
| 73 | }
|
---|
| 74 | else {
|
---|
| 75 | for (var i = 0; i < arr.Length; i++)
|
---|
| 76 | {
|
---|
| 77 | //loop for depth
|
---|
| 78 |
|
---|
| 79 | if (i == arr.Length - 1)//end of depth loop, right current is selected
|
---|
| 80 | {
|
---|
| 81 | if (current.ItemTask.Item is BatchRun)
|
---|
| 82 | {
|
---|
| 83 | current.ChildHiveTasks[arr[i][1]].ItemTask.ComputeInParallel = !current.ChildHiveTasks[arr[i][1]].ItemTask.ComputeInParallel;
|
---|
| 84 | }
|
---|
| 85 | else if (current.ItemTask.Item is Experiment)
|
---|
| 86 | {
|
---|
| 87 | current.ChildHiveTasks[arr[i][0]].ItemTask.ComputeInParallel = !current.ChildHiveTasks[arr[i][0]].ItemTask.ComputeInParallel;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | }
|
---|
| 91 | else {//not deep enough, select right path
|
---|
| 92 | if (current.ItemTask.Item is BatchRun)
|
---|
| 93 | current = current.ChildHiveTasks[arr[i][1]]; // select right batch
|
---|
| 94 | else if (current.ItemTask.Item is Experiment)
|
---|
| 95 | current = current.ChildHiveTasks[arr[i][0]]; // select right sub task from experiment
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | /// <summary>
|
---|
| 101 | /// Change priority for a node
|
---|
| 102 | /// </summary>
|
---|
| 103 | /// <param name="arr">2-dimensional int array.
|
---|
| 104 | /// First dimension is depth (arr.length == 4 means the item is 4 nodes deep)
|
---|
| 105 | /// Second contains expirement info or batch info. (arr[][0] contains index to select the right experiment sub task,
|
---|
| 106 | /// arr[][1] contains index to select right batch run subtask)</param>
|
---|
| 107 | /// <param name="prior">Selected priority</param>
|
---|
| 108 | public void ChangePriority(int[][] arr, int prior)
|
---|
| 109 | {
|
---|
[13739] | 110 | loader();
|
---|
| 111 | HiveTask current = fileopener.Job.HiveTasks.ToList()[0];
|
---|
[13733] | 112 | if (arr.Length == 0)
|
---|
| 113 | {//check if upper job
|
---|
| 114 | current.Task.Priority = prior;
|
---|
| 115 |
|
---|
| 116 | }
|
---|
| 117 | else {
|
---|
| 118 | for (var i = 0; i < arr.Length; i++)
|
---|
| 119 | {//loop for depth
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | if (i == arr.Length - 1)
|
---|
| 123 | {//Right depth reached, change priority for current
|
---|
| 124 | if (current.ItemTask.Item is BatchRun)
|
---|
| 125 | {
|
---|
| 126 | current.ChildHiveTasks[arr[i][1]].Task.Priority = prior;
|
---|
| 127 | }
|
---|
| 128 | else if (current.ItemTask.Item is Experiment)
|
---|
| 129 | {
|
---|
| 130 | current.ChildHiveTasks[arr[i][0]].Task.Priority = prior;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | }
|
---|
| 134 | else {//not deep enough, choose right path
|
---|
| 135 | if (current.ItemTask.Item is BatchRun)
|
---|
| 136 | current = current.ChildHiveTasks[arr[i][1]]; // select right batch
|
---|
| 137 | else if (current.ItemTask.Item is Experiment)
|
---|
| 138 | current = current.ChildHiveTasks[arr[i][0]]; // select right sub task from experiment
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | /// <summary>
|
---|
| 144 | /// Used by event 'ProgressChanged' from current uploading Job
|
---|
| 145 | /// </summary>
|
---|
| 146 | /// <param name="sender"></param>
|
---|
| 147 | /// <param name="e"></param>
|
---|
| 148 | public void runHub(object sender, EventArgs e)
|
---|
| 149 | {
|
---|
[13739] | 150 | loader();
|
---|
[13733] | 151 | int value = 0;
|
---|
| 152 |
|
---|
[13739] | 153 | switch (fileopener.Job.Progress.Status)
|
---|
[13733] | 154 | {
|
---|
| 155 | case "Connecting to server...":
|
---|
| 156 | value = 0;
|
---|
| 157 | break;
|
---|
| 158 | case "Uploading Job...":
|
---|
| 159 | value = 10;
|
---|
| 160 | break;
|
---|
| 161 | case "Uploading plugins...":
|
---|
| 162 | value = 30;
|
---|
| 163 | break;
|
---|
| 164 | case "Uploading tasks...":
|
---|
| 165 | value = 50;
|
---|
| 166 | break;
|
---|
| 167 | case "Upload finished":
|
---|
| 168 | value = 100;
|
---|
| 169 | break;
|
---|
| 170 | default://Tasks are uploading individually
|
---|
[13739] | 171 | value = (int)(50 + (40 * fileopener.Job.Progress.ProgressValue));
|
---|
[13733] | 172 | break;
|
---|
| 173 |
|
---|
| 174 | }
|
---|
| 175 | //send info to client
|
---|
[13739] | 176 | Clients.Caller.processMessage(fileopener.Job.Progress.Status, value);
|
---|
[13733] | 177 |
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | }
|
---|
| 181 | }
|
---|