Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/QueryHub.cs @ 16674

Last change on this file since 16674 was 13862, checked in by jlodewyc, 9 years ago

#2582 Start angular OKB manager, data loaded

File size: 5.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Clients.Hive.WebJobManager.Services;
23using HeuristicLab.Clients.Hive.WebJobManager.Services.Imports;
24using HeuristicLab.Clients.OKB.Query;
25using Microsoft.AspNetCore.SignalR;
26using Newtonsoft.Json;
27using Newtonsoft.Json.Linq;
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Reflection;
32
33namespace HeuristicLab.Clients.Hive.WebJobManager.Hubs
34{
35    public class QueryHub : Hub
36    {
37        private WebLoginService weblog;
38        private Guid userId;
39        private QueryWebClient queryclient;
40        /// <summary>
41        /// Loads up the services for the client (Instance is only created upon a call from a client)
42        /// </summary>
43        private void loader()
44        {
45            weblog = WebLoginService.Instance;
46            string uid = Context.QueryString["userid"];
47            if (uid == null || uid == "" || Guid.Parse(uid) == Guid.Empty)
48            {
49                userId = Guid.Empty;
50            }
51            else
52            {
53                userId = Guid.Parse(uid);
54                queryclient = weblog.getQueryClient(userId);
55            }
56        }
57        /// <summary>
58        /// Initial client request for all user, group and resource information
59        /// </summary>
60        public void requestInfo()
61        {
62            loader();
63            queryclient.Refresh();
64
65            // var values = JsonConvert.SerializeObject(queryclient.ValueNames);
66            var filters = JArray.FromObject(queryclient.Filters);
67            for (int i = 0; i < queryclient.Filters.Count(); i++)
68            {
69                if (queryclient.Filters.ToList()[i].Label != "AND" && queryclient.Filters.ToList()[i].Label != "OR")
70                    ((JObject)filters[i]).Add("CompareType", queryclient.Filters.ToList()[i].GetType().GetProperty("Comparison").PropertyType.ToString());
71            }
72
73            Clients.Caller.processData(filters.ToString());
74        }
75
76        public void runQuery(string content)
77        {
78            loader();
79            JArray data = JArray.Parse(content);
80            CombinedFilter mainFilt = (CombinedFilter)queryclient.Filters.ToList().Find(x => x.Label == "AND").Clone();
81            queryclient.Refresh();
82            mainFilt.Filters = new List<Filter>();
83            for (var i = 0; i < data.Count(); i++)
84            {
85                mainFilt.Filters.Add(jsonParserFilt((JObject)data[i]));
86            }
87            var idcol = queryclient.GetRunIds(mainFilt).ToList();
88
89            foreach (var id in idcol)
90            {
91                Console.WriteLine(id);
92            }
93
94            var json = JsonConvert.SerializeObject(idcol);
95            Clients.Caller.processResults(json);
96        }
97
98        public void fetchResult(string resultId)
99        {
100            loader();
101            long id = long.Parse(resultId);
102            queryclient.Refresh();
103            var dat = queryclient.GetRuns(new List<long> { id }, true).First();
104            var json = JsonConvert.SerializeObject(dat);
105            Clients.Caller.resultLoad(json);
106        }
107        private Filter jsonParserFilt(JObject current)
108        {
109            if (current["name"] == null)
110            {
111                Filter filter = queryclient.Filters.ToList().Find(x => x.Label == current["Label"].ToString()).Clone();
112                Type filterType = filter.GetType();
113                PropertyInfo compareProp = filterType.GetProperty("Comparison");
114                PropertyInfo valueProp = filterType.GetProperty("Value");
115                if ((current["CompareType"].ToString()  != "HeuristicLab.Clients.OKB.Query.EqualityComparison"))
116                {
117                    if (compareProp != null && valueProp != null)
118                    {
119                        Assembly asm = filterType.Assembly;
120                        Type comtype = asm.GetType(current["CompareType"].ToString());
121                        Object comob = Enum.ToObject(comtype, int.Parse(current["Comparison"].ToString()));
122                        Object valob = Convert.ChangeType(current["Value"].ToString(), valueProp.PropertyType);
123                        compareProp.SetValue(filter, comob);
124                        valueProp.SetValue(filter, valob);
125                    }
126                }
127                return filter;
128            }
129            else
130            {
131                return jsonParserComb(current);
132            }
133        }
134        private Filter jsonParserComb(JObject current)
135        {
136            CombinedFilter filt;
137            if (current["name"].ToString() == "AND")
138                filt = (CombinedFilter)queryclient.Filters.ToList().Find(x => x.Label == "AND").Clone();
139            else
140                filt = (CombinedFilter)queryclient.Filters.ToList().Find(x => x.Label == "OR").Clone();
141            for (var i = 0; i < current["columns"][0].Count(); i++)
142            {
143                filt.Filters.Add(jsonParserFilt((JObject)current["columns"][0][i]));
144            }
145            return filt;
146
147        }
148    }
149}
Note: See TracBrowser for help on using the repository browser.