Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/CalendarHub.cs @ 13768

Last change on this file since 13768 was 13768, checked in by jlodewyc, 8 years ago

#2582 Saving calendars to server, update not working

File size: 3.9 KB
Line 
1using HeuristicLab.Clients.Access.Administration;
2using HeuristicLab.Clients.Hive.WebJobManager.Services;
3using Microsoft.AspNet.SignalR;
4using Newtonsoft.Json;
5using System;
6using System.Collections.Generic;
7using System.Linq;
8using System.Threading;
9using System.Threading.Tasks;
10
11namespace HeuristicLab.Clients.Hive.WebJobManager.Hubs
12{
13    public class CalendarHub : Hub
14    {
15        private WebLoginService weblog;
16        private Guid userId;
17        private HiveAdminClientWeb adminClient;
18        private void loader()
19        {
20            weblog = WebLoginService.Instance;
21            string uid = Context.QueryString["userid"];
22            if (uid == null || uid == "" || Guid.Parse(uid) == Guid.Empty)
23            {
24                userId = Guid.Empty;
25            }
26            else
27            {
28                userId = Guid.Parse(uid);
29                adminClient = weblog.getAdminClient(userId);
30            }
31        }
32        public void requestInfo()
33        {
34            loader();
35            adminClient.Refresh();
36           
37            var res = JsonConvert.SerializeObject(adminClient.Resources);
38            Clients.Caller.processData(res);
39        }
40        public void requestDownTime(string id)
41        {
42            loader();
43            adminClient.Refresh();
44            Guid t = Guid.Parse(id);
45            adminClient.DowntimeForResourceId = t;
46            adminClient.RefreshCalendar();
47            var down = JsonConvert.SerializeObject(adminClient.Downtimes);
48            Clients.Caller.processDowntime(id, down);
49        }
50        public void saveCalendar(string id, string[] del, string[][] add, string[][] upd, bool fresh, bool last)
51        {
52            loader();
53            var calid = Guid.Parse(id);
54            adminClient.Refresh();
55            adminClient.DowntimeForResourceId = calid;
56            adminClient.RefreshCalendar();
57            var downlist = adminClient.Downtimes.ToList();
58            foreach(var s in del)
59            {
60                var gu = Guid.Parse(s);
61                var el = downlist.Find(x => x.Id == gu);
62                adminClient.Delete(el);
63            }
64            foreach (var s in add)
65            {
66                var obj = new Downtime();
67                obj.Id = Guid.Empty;
68                if (s[0] == "Unavailable")
69                    obj.DowntimeType = DowntimeType.Offline;
70                else
71                    obj.DowntimeType = DowntimeType.Shutdown;
72                obj.StartDate = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[1]));
73                obj.EndDate = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[2]));
74                if (s[3] == "true")
75                    obj.AllDayEvent = true;
76                else
77                    obj.AllDayEvent = false;
78                obj.ResourceId = Guid.Parse(s[4]);
79                adminClient.Store(obj, CancellationToken.None);
80            }
81            foreach(var s in upd)
82            {
83                 var obj = downlist.Find(x => x.Id == Guid.Parse(s[0]));
84                if (s[1] == "Unavailable")
85                    obj.DowntimeType = DowntimeType.Offline;
86                else
87                    obj.DowntimeType = DowntimeType.Shutdown;
88                obj.StartDate = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[2]));
89                obj.EndDate = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[3]));
90                if (s[4] == "true")
91                    obj.AllDayEvent = true;
92                else
93                    obj.AllDayEvent = false;
94                 //adminClient.Store(obj, CancellationToken.None); Throws error
95            }
96            if( last)
97            {
98                Clients.Caller.savingAllDone();
99            }
100            else if (fresh)
101            {
102                Clients.Caller.savingCurrentDone();
103            }
104        }
105    }
106}
Note: See TracBrowser for help on using the repository browser.