1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Collections;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Data.Linq;
|
---|
6 | using System.Data.Linq.Mapping;
|
---|
7 | using System.Text;
|
---|
8 |
|
---|
9 | using HeuristicLab.Services.Authentication.DataAccess;
|
---|
10 | using HeuristicLab.Services.Authentication.DataTransfer;
|
---|
11 | using HeuristicLab.Services.Authentication;
|
---|
12 | using DA = HeuristicLab.Services.Authentication.DataAccess;
|
---|
13 | using DT = HeuristicLab.Services.Authentication.DataTransfer;
|
---|
14 | using HLSA = HeuristicLab.Services.Authentication;
|
---|
15 |
|
---|
16 | namespace HeuristicLab.Services.Authentication.AdminMethods {
|
---|
17 |
|
---|
18 | public enum eResource {
|
---|
19 | ResourceID = 1, Name = 2, Description = 3, ResourceType = 4,
|
---|
20 | ProcessorType = 5, NumberOfProcessors = 6, NumberOfThreads = 7,
|
---|
21 | MemorySize = 8, IPAdress = 9, OperatingSystem = 10, ResourceNameGroup, ResourceIDGroup,
|
---|
22 | GroupGroupID, GroupGroupName
|
---|
23 | };
|
---|
24 |
|
---|
25 | public abstract class ResourceAdmin {
|
---|
26 |
|
---|
27 | public abstract HashSet<Hashtable> Get(Hashtable values);
|
---|
28 | public abstract bool Create(Hashtable values);
|
---|
29 | public abstract bool Update(Hashtable values);
|
---|
30 |
|
---|
31 | public bool RemoveRRGEntry(ClientManagmentDataContext cmdc, Guid resID) {
|
---|
32 | ResourceResourceGroup rrgEntity = cmdc.GetTable<ResourceResourceGroup>().FirstOrDefault(
|
---|
33 | x => x.ResourceID == resID);
|
---|
34 | //ResourceResourceGroup rrgEntityGroup = cmdc.GetTable<ResourceResourceGroup>().FirstOrDefault(
|
---|
35 | // x => x.ResourceGroupID == resID);
|
---|
36 | if (rrgEntity != null) { // && (rrgEntityGroup == null)) {
|
---|
37 | cmdc.GetTable<ResourceResourceGroup>().DeleteOnSubmit(rrgEntity);
|
---|
38 | return true;
|
---|
39 | }
|
---|
40 | return false;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void CreateRRGEntry(ClientManagmentDataContext cmdc, Guid clientID, Guid groupID) {
|
---|
44 | ResourceResourceGroup rrgEntity = new ResourceResourceGroup();
|
---|
45 | rrgEntity.ResourceGroupID = groupID;
|
---|
46 | rrgEntity.ResourceID = clientID;
|
---|
47 | cmdc.GetTable<ResourceResourceGroup>().InsertOnSubmit(rrgEntity);
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void GetGroupIDandName(ref String groupID, ref String groupName, ClientManagmentDataContext cmdc, Guid clientID) {
|
---|
51 | ResourceResourceGroup rrgEntity = cmdc.GetTable<ResourceResourceGroup>().FirstOrDefault(
|
---|
52 | x => x.ResourceID == clientID);
|
---|
53 | if (rrgEntity != null) {
|
---|
54 | groupID = (rrgEntity.ResourceGroupID).ToString();
|
---|
55 | DA.Resource groupEntity = cmdc.GetTable<DA.Resource>().FirstOrDefault(
|
---|
56 | x => x.ResourceID == rrgEntity.ResourceGroupID);
|
---|
57 | groupName = groupEntity.Name;
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | public void CreateQueryStringExtension(List<String> compareValues, ref String QueryStringExtension, Hashtable ht) {
|
---|
62 | int i = 0;
|
---|
63 | foreach (DictionaryEntry kvp in ht) {
|
---|
64 | if (((string)kvp.Value != "") &&
|
---|
65 | (kvp.Key.Equals(eResource.ResourceNameGroup) == false) &&
|
---|
66 | (kvp.Key.Equals(eResource.ResourceIDGroup) == false)) {
|
---|
67 | compareValues.Add(String.Format("%" + (ht[kvp.Key]).ToString() + "%"));
|
---|
68 | if (i == 0)
|
---|
69 | QueryStringExtension += (kvp.Key.ToString() + " LIKE {" + i + "}");
|
---|
70 | else
|
---|
71 | QueryStringExtension += " AND " + (kvp.Key.ToString() + " LIKE {" + i + "}");
|
---|
72 | i++;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | public bool Delete(Hashtable values) {
|
---|
78 | string idStr = (string)values[eResource.ResourceID];
|
---|
79 | if ((idStr == "") || (!IsIDString(idStr))) {
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 |
|
---|
83 | using (ClientManagmentDataContext cmdc = new ClientManagmentDataContext()) {
|
---|
84 | Guid clientID = new Guid(idStr);
|
---|
85 |
|
---|
86 | if (cmdc.DatabaseExists()) {
|
---|
87 | // remove entry in ResourceResourcGroup
|
---|
88 | //if (!(RemoveRRGEntry(cmdc, clientID)))
|
---|
89 | // return false;
|
---|
90 | RemoveRRGEntry(cmdc, clientID);
|
---|
91 | // check if resource is member of a group
|
---|
92 | DA.Resource Entity = cmdc.GetTable<DA.Resource>().FirstOrDefault(x => x.ResourceID == new Guid(idStr));
|
---|
93 |
|
---|
94 | // only allow removing if group is not still in use
|
---|
95 | DA.ResourceResourceGroup rrgEntity = cmdc.GetTable<DA.ResourceResourceGroup>()
|
---|
96 | .FirstOrDefault(x => x.ResourceGroupID == new Guid(idStr));
|
---|
97 | if ((Entity != null) && (rrgEntity == null)) {
|
---|
98 | cmdc.GetTable<DA.Resource>().DeleteOnSubmit(Entity);
|
---|
99 | cmdc.SubmitChanges();
|
---|
100 | return true;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | } return false;
|
---|
104 | }
|
---|
105 |
|
---|
106 | public bool IsIDString (string idString){
|
---|
107 | try{
|
---|
108 | Guid gid = new Guid(idString);
|
---|
109 | return true;
|
---|
110 | }
|
---|
111 | catch (Exception e) {return false;}
|
---|
112 | }
|
---|
113 |
|
---|
114 | }
|
---|
115 | }
|
---|