- Timestamp:
- 04/27/16 16:48:35 (9 years ago)
- Location:
- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/CalendarHub.cs
r13795 r13805 12 12 namespace HeuristicLab.Clients.Hive.WebJobManager.Hubs 13 13 { 14 /// <summary> 15 /// SignalR Hub that manages all resource management. 16 /// </summary> 14 17 public class CalendarHub : Hub 15 18 { … … 19 22 private HiveServiceLocatorWeb servloc; 20 23 private AccessAdministrationClient accessClient; 24 /// <summary> 25 /// Loads up the services for the client (Instance is only created upon a call from a client) 26 /// </summary> 21 27 private void loader() 22 28 { … … 35 41 } 36 42 } 43 /// <summary> 44 /// Initial client request for all user, group and resource information 45 /// </summary> 37 46 public void requestInfo() 38 47 { … … 40 49 adminClient.Refresh(); 41 50 UserViewModel vm = new UserViewModel(accessClient).refreshAll(); 51 42 52 var users = JsonConvert.SerializeObject(vm.users); 43 53 var groups = JsonConvert.SerializeObject(vm.ugroups); … … 45 55 Clients.Caller.processData(res, users, groups); 46 56 } 57 /// <summary> 58 /// Request for the downtimes of a specific resource 59 /// </summary> 60 /// <param name="id">Resource ID</param> 47 61 public void requestDownTime(string id) 48 62 { … … 50 64 adminClient.Refresh(); 51 65 Guid t = Guid.Parse(id); 66 67 //Loads up the downtimes for the set resource ID 52 68 adminClient.DowntimeForResourceId = t; 53 69 adminClient.RefreshCalendar(); 70 54 71 var down = JsonConvert.SerializeObject(adminClient.Downtimes); 55 72 Clients.Caller.processDowntime(id, down); 56 73 } 74 /// <summary> 75 /// Request for permissions of a specific resource (refreshable by recall) 76 /// </summary> 77 /// <param name="id">Resource ID</param> 57 78 public void requestPermissions(string id) 58 79 { … … 63 84 } 64 85 86 /// <summary> 87 /// Edit permissions for a resource 88 /// </summary> 89 /// <param name="perms">Permissions ID's</param> 90 /// <param name="idresource">Resource ID</param> 65 91 public void changePermissions(string[] perms, string idresource) 66 92 { 67 93 loader(); 68 94 var res = Guid.Parse(idresource); 95 96 //Collect current permissions 69 97 var exist = servloc.CallHiveService(x => x.GetResourcePermissions(res)); 98 99 //Separate list for new and to remove permissions 70 100 List<Guid> newPerms = new List<Guid>(); 71 101 List<Guid> revokePerms = new List<Guid>(); 102 72 103 for (var i = 0; i < perms.Length; i++) 73 104 { … … 75 106 var elemid = exist.FindIndex(x => x.GrantedUserId == p); 76 107 if (elemid != -1) 77 { 108 {//If it already exists => Scramble up Guid (checked further) 78 109 exist[elemid].GrantedUserId = Guid.Empty; 79 110 } 80 111 else 81 { 112 {//If it's not in the list, add to new permissions 82 113 newPerms.Add(p); 83 114 } 84 115 } 116 //Adds the new permissions to the resource 85 117 servloc.CallHiveService(x => x.GrantResourcePermissions(res, newPerms)); 86 118 foreach (var ex in exist) 87 { 119 {//Checks for intact ID's and adds them to the revoke list 88 120 if(ex.GrantedUserId != Guid.Empty) 89 121 { … … 91 123 } 92 124 } 125 //Revokes all permissions that were deselected by the user 93 126 servloc.CallHiveService(x => x.RevokeResourcePermissions(res, revokePerms)); 127 //Live reload the view for the resource 94 128 requestPermissions(idresource); 95 129 } 130 /// <summary> 131 /// Toggles the disposable setting for a resource 132 /// </summary> 133 /// <param name="id">Resource ID</param> 96 134 public void toggleDisposable(string id) 97 135 { … … 100 138 Guid c = Guid.Parse(id); 101 139 var obj = adminClient.Resources.ToList().Find(x => x.Id == c); 140 141 //Toggle 102 142 ((Slave)(obj)).IsDisposable = !((Slave)(obj)).IsDisposable; 143 103 144 adminClient.Store(obj, CancellationToken.None); 145 146 //Notify client of successful saving 104 147 Clients.Caller.processDispose( ((Slave)(obj)).IsDisposable); 105 148 106 149 } 150 /// <summary> 151 /// Saves changes to a resource calendar 152 /// </summary> 153 /// <param name="id">Resource id</param> 154 /// <param name="del">To delete downtimes</param> 155 /// <param name="add">New downtimes</param> 156 /// <param name="upd">Downtimes to update</param> 157 /// <param name="fresh">Check if refresh should be sent (Save all current graph or Save current graph)</param> 158 /// <param name="last">Check for last request (Save all)</param> 107 159 public void saveCalendar(string id, string[] del, string[][] add, string[][] upd, bool fresh, bool last) 108 160 { 109 161 loader(); 110 162 var calid = Guid.Parse(id); 163 164 //Load up calendar 111 165 adminClient.Refresh(); 112 166 adminClient.DowntimeForResourceId = calid; 113 167 adminClient.RefreshCalendar(); 168 114 169 var downlist = adminClient.Downtimes.ToList(); 115 170 foreach(var s in del) 116 { 171 {//Deletes downtimes 117 172 var gu = Guid.Parse(s); 118 173 var el = downlist.Find(x => x.Id == gu); … … 120 175 } 121 176 foreach (var s in add) 122 { 177 {//Adds new downtimes 178 //init 123 179 var obj = new Downtime(); 124 180 obj.Id = Guid.Empty; … … 134 190 obj.AllDayEvent = false; 135 191 obj.ResourceId = Guid.Parse(s[4]); 192 193 //Recurrency check 136 194 if (s[5] == "true") 137 { 195 {//Recurrency set 138 196 obj.Recurring = true; 139 197 if (s[6] == "0") 140 { 198 {//new Recur 141 199 var dayarr = s[9].Split(','); 142 200 var start = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[7])); 143 201 var end = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[8])); 144 loopAddDowns(start, end, dayarr, obj); 202 loopAddDowns(start, end, dayarr, obj);//Loop creation of recurrency. Start to end date 145 203 } 146 204 else 147 { 205 {//Existing recurrency (only edits current element, client handles the creation of the other events) 148 206 obj.RecurringId = Guid.Parse(s[6]); 149 207 adminClient.Store(obj, CancellationToken.None); 150 208 } 151 209 } 152 else { 210 else { //No recurrency 153 211 obj.Recurring = false; 154 212 adminClient.Store(obj, CancellationToken.None); … … 158 216 } 159 217 foreach(var s in upd) 160 { 218 {//Update existing downtime 161 219 var obj = downlist.Find(x => x.Id == Guid.Parse(s[0])); 162 220 if (s[1] == "Unavailable") … … 171 229 obj.AllDayEvent = false; 172 230 if (s[5] == "true" && !obj.Recurring) 173 { 231 {//Recurrence set 174 232 obj.Recurring = true; 175 233 if (s[6] == "00000000-0000-0000-0000-000000000000") 176 { 234 {//Creates new recurrence 177 235 var dayarr = s[9].Split(','); 178 236 var start = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[7])); 179 237 var end = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[8])); 180 //loopAddDowns(start, end, dayarr, obj); 238 loopAddDowns(start, end, dayarr, obj); 239 adminClient.Delete(obj); 240 //Delete needed to prevent doubles in the creation of the recurrency 241 //Why: event could be on not included day of the week => loop cannot find that. 181 242 } 182 243 else … … 194 255 } 195 256 if( last) 196 { 257 {//Last element from save all => Notify client 197 258 Clients.Caller.savingAllDone(); 198 259 } 199 260 else if (fresh) 200 { 261 {//Refresh for graph needed 201 262 Clients.Caller.savingCurrentDone(); 202 263 } 203 264 } 265 /// <summary> 266 /// Creates downtimes for a new recurrency 267 /// </summary> 268 /// <param name="start">Start date</param> 269 /// <param name="end">End date</param> 270 /// <param name="dayarr">Boolean day array (sun = 0,...)</param> 271 /// <param name="obj">Downtime to recur</param> 204 272 private void loopAddDowns(DateTime start, DateTime end, string[] dayarr, Downtime obj) 205 273 { 206 274 var rid = Guid.NewGuid(); 207 for (; start < end;)275 while (start < end) 208 276 { 209 277 if (dayarr[(int)(start.DayOfWeek)] == "true") 210 { 278 {//Check for day of the week 279 //Set setting for the downtime to add 211 280 var temp = new Downtime(); 212 temp.StartDate = start.AddHours(obj.StartDate.Hour - start.Hour).AddMinutes(obj.StartDate.Minute - start.Minute); 213 temp.EndDate = start.AddHours(obj.EndDate.Hour - start.Hour).AddMinutes(obj.EndDate.Minute - start.Minute); 214 temp.Id = obj.Id; 281 temp.StartDate = start.AddHours(obj.StartDate.Hour - start.Hour) 282 .AddMinutes(obj.StartDate.Minute - start.Minute); 283 temp.EndDate = start.AddHours(obj.EndDate.Hour - start.Hour) 284 .AddMinutes(obj.EndDate.Minute - start.Minute); 285 temp.Id = Guid.Empty; 215 286 temp.DowntimeType = obj.DowntimeType; 216 287 temp.AllDayEvent = obj.AllDayEvent; -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/UserInfoHub.cs
r13741 r13805 1 1 using HeuristicLab.Clients.Access.Administration; 2 using HeuristicLab.Clients.Hive.WebJobManager.Controllers; 2 3 using HeuristicLab.Clients.Hive.WebJobManager.Services; 3 4 using HeuristicLab.Clients.Hive.WebJobManager.ViewModels.User; … … 10 11 namespace HeuristicLab.Clients.Hive.WebJobManager.Hubs 11 12 { 13 /// <summary> 14 /// Small SignalR hub to change the password from a user 15 /// </summary> 12 16 public class UserInfoHub: Hub 13 17 { … … 15 19 private Guid userId; 16 20 private AccessAdministrationClient aac; 21 /// <summary> 22 /// Loads required services 23 /// </summary> 17 24 private void loader() 18 25 { … … 29 36 } 30 37 } 31 38 /// <summary> 39 /// Request to change pass 40 /// </summary> 41 /// <param name="user">User id</param> 32 42 public void resetPassword(string user) 33 43 { … … 36 46 Access.User u = new UserViewModel(aac).refreshUsers().getUserById(userid); 37 47 var pass = aac.resetPassword(userid); 48 UserController.sendPassmail(u, pass);//Send mail + show pass 38 49 Clients.Caller.showNewPass(pass); 39 50 }
Note: See TracChangeset
for help on using the changeset viewer.