Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/19/11 18:09:40 (14 years ago)
Author:
fruehrli
Message:

#1197
modified and new service methods

Location:
branches/ClientManagement/HeuristicLab.Services.Authentication
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/ClientManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication.DataTransfer/Client.cs

    r4731 r5335  
    11using System.Runtime.Serialization;
    22
    3 namespace HeuristicLab.Services.Authentication.DataTransfer
    4 {
    5     [DataContract]
    6     public class Client : HeuristicLab.Services.Authentication.DataTransfer.Resource
    7     {
    8         [DataMember]
    9         public string ProcessorType { get; set; }
    10         [DataMember]
    11         public string NumberOfProcessors { get; set; }
    12         [DataMember]
    13         public string NumberOfThreads { get; set; }
    14         [DataMember]
    15         public string IPAdress { get; set; }
    16         [DataMember]
    17         public string MemorySize { get; set; }
    18         [DataMember]
    19         public string OperatingSystem { get; set; }
     3namespace HeuristicLab.Services.Authentication.DataTransfer {
     4  [DataContract]
     5  public class Client : HeuristicLab.Services.Authentication.DataTransfer.Resource {
     6    [DataMember]
     7    public string ProcessorType { get; set; }
     8    [DataMember]
     9    public string NumberOfProcessors { get; set; }
     10    [DataMember]
     11    public string NumberOfThreads { get; set; }
     12    [DataMember]
     13    public string IPAdress { get; set; }
     14    [DataMember]
     15    public string MemorySize { get; set; }
     16    [DataMember]
     17    public string OperatingSystem { get; set; }
    2018
    21     }
     19  }
    2220}
  • branches/ClientManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication.DataTransfer/Resource.cs

    r4953 r5335  
    11using System.Runtime.Serialization;
     2using System.Collections.Generic;
    23
    3 namespace HeuristicLab.Services.Authentication.DataTransfer
    4 {
    5     [DataContract]
    6     public abstract class Resource
    7     {
    8         [DataMember]
    9         public System.Guid Id { get; set; }
    10         [DataMember]
    11         public string Name { get; set; }
    12         [DataMember]
    13         public string Description { get; set; }
    14         [DataMember]
    15         public string ResourceType { get; set; }
    16         [DataMember]
    17         public System.Guid ResourceGroup { get; set; }
    18     }
     4namespace HeuristicLab.Services.Authentication.DataTransfer {
     5  [DataContract]
     6  public abstract class Resource {
     7    public enum ResourceTypes { Client, ResourceGroup };
     8
     9    [DataMember]
     10    public System.Guid Id { get; set; }
     11    [DataMember]
     12    public string Name { get; set; }
     13    [DataMember]
     14    public string Description { get; set; }
     15    [DataMember]
     16    public ResourceTypes ResourceType { get; set; }
     17    [DataMember]
     18    public IEnumerable<System.Guid> ResourceGroup { get; set; }
     19  }
    1920}
    2021
  • branches/ClientManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication.DataTransfer/ResourceGroup.cs

    r4731 r5335  
    11using System.Runtime.Serialization;
    22
    3 namespace HeuristicLab.Services.Authentication.DataTransfer
    4 {
    5     [DataContract]
    6     public class ResourceGroup : Resource
    7     {
    8     }
     3namespace HeuristicLab.Services.Authentication.DataTransfer {
     4  [DataContract]
     5  public class ResourceGroup : Resource {
     6  }
    97}
    108
  • branches/ClientManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication/Convert.cs

    r4953 r5335  
    2424using DA = HeuristicLab.Services.Authentication.DataAccess;
    2525using DT = HeuristicLab.Services.Authentication.DataTransfer;
     26using System;
    2627
    27 namespace HeuristicLab.Services.Authentication
    28 {
    29     public static class Convert
    30     {
     28namespace HeuristicLab.Services.Authentication {
     29  public static class Convert {
    3130
    32         #region Client
    33         public static DT.Client ToDto(DA.Client source)
    34         {
    35             if (source == null) return null;
    36             return new DT.Client
    37             {
    38                 Id = source.Id,
    39                 Name = source.Name,
    40                 Description = source.Description,
    41                 ResourceType = source.ResourceType,
    42                 ProcessorType = source.ProcessorType,
    43                 NumberOfProcessors = source.NumberOfProcessors,
    44                 NumberOfThreads = source.NumberOfThreads,
    45                 IPAdress = source.IPAdress,
    46                 MemorySize = source.MemorySize,
    47                 OperatingSystem = source.OperatingSystem
    48             };
    49         }
     31    #region Client
     32    public static DT.Client ToDto(DA.Client source) {
     33      if (source == null) return null;
     34      return new DT.Client {
     35        Id = source.Id,
     36        Name = source.Name,
     37        Description = source.Description,
     38        ResourceType = (DT.Resource.ResourceTypes) Enum.Parse(typeof(DT.Resource.ResourceTypes), source.ResourceType),
     39        ProcessorType = source.ProcessorType,
     40        NumberOfProcessors = source.NumberOfProcessors,
     41        NumberOfThreads = source.NumberOfThreads,
     42        IPAdress = source.IPAdress,
     43        MemorySize = source.MemorySize,
     44        OperatingSystem = source.OperatingSystem
     45      };
     46    }
    5047
    51         public static DA.Client ToEntity(DT.Client source)
    52         {
    53             if (source == null) return null;
    54             return new DA.Client
    55             {
    56                 Id = source.Id,
    57                 Name = source.Name,
    58                 Description = source.Description,
    59                 ResourceType = source.ResourceType,
    60                 ProcessorType = source.ProcessorType,
    61                 NumberOfProcessors = source.NumberOfProcessors,
    62                 NumberOfThreads = source.NumberOfThreads,
    63                 IPAdress = source.IPAdress,
    64                 MemorySize = source.MemorySize,
    65                 OperatingSystem = source.OperatingSystem
    66             };
    67         }
     48    public static DA.Client ToEntity(DT.Client source) {
     49      if (source == null) return null;
     50      return new DA.Client {
     51        Id = source.Id,
     52        Name = source.Name,
     53        Description = source.Description,
     54        ResourceType = source.ResourceType.ToString(),
     55        ProcessorType = source.ProcessorType,
     56        NumberOfProcessors = source.NumberOfProcessors,
     57        NumberOfThreads = source.NumberOfThreads,
     58        IPAdress = source.IPAdress,
     59        MemorySize = source.MemorySize,
     60        OperatingSystem = source.OperatingSystem
     61      };
     62    }
    6863
    69         public static DA.Resource ToEntity(DT.Resource source)
    70         {
    71             if (source == null) return null;
    72             if (source is DT.Client)
    73             {
    74                 DT.Client client = (Client) source;
    75                 return ToEntity(client);
    76             }
    77             if (source is DT.ResourceGroup)
    78             {
    79                 DT.ResourceGroup resourceGroup = (ResourceGroup) source;
    80                 return ToEntity(resourceGroup);
    81             }
    82             return null;
    83         }
     64    public static DA.Resource ToEntity(DT.Resource source) {
     65      if (source == null) return null;
     66      if (source is DT.Client) {
     67        DT.Client client = (Client)source;
     68        return ToEntity(client);
     69      }
     70      if (source is DT.ResourceGroup) {
     71        DT.ResourceGroup resourceGroup = (ResourceGroup)source;
     72        return ToEntity(resourceGroup);
     73      }
     74      return null;
     75    }
    8476
    85         public static void ToEntity(DT.Client source, DA.Client target)
    86         {
    87             if ((source != null) && (target != null))
    88             {
    89                 target.Id = source.Id;
    90                 target.Name = source.Name;
    91                 target.Description = source.Description;
    92                 target.ResourceType = source.ResourceType;
    93                 target.ProcessorType = source.ProcessorType;
    94                 target.NumberOfProcessors = source.NumberOfProcessors;
    95                 target.NumberOfThreads = source.NumberOfThreads;
    96                 target.IPAdress = source.IPAdress;
    97                 target.MemorySize = source.MemorySize;
    98                 target.OperatingSystem = source.OperatingSystem;
    99             }
    100         }
    101         #endregion // Client
     77    public static void ToEntity(DT.Client source, DA.Client target) {
     78      if ((source != null) && (target != null)) {
     79        target.Id = source.Id;
     80        target.Name = source.Name;
     81        target.Description = source.Description;
     82        target.ResourceType = source.ResourceType.ToString();
     83        target.ProcessorType = source.ProcessorType;
     84        target.NumberOfProcessors = source.NumberOfProcessors;
     85        target.NumberOfThreads = source.NumberOfThreads;
     86        target.IPAdress = source.IPAdress;
     87        target.MemorySize = source.MemorySize;
     88        target.OperatingSystem = source.OperatingSystem;
     89      }
     90    }
     91    #endregion // Client
    10292
    103         #region ResourceGroup
    104         public static DT.ResourceGroup ToDto(DA.ResourceGroup source)
    105         {
    106             if (source == null) return null;
    107             return new DT.ResourceGroup
    108             {
    109                 Id = source.Id,
    110                 Name = source.Name,
    111                 Description = source.Description,
    112                 ResourceType = source.ResourceType,
    113             };
    114         }
     93    #region ResourceGroup
     94    public static DT.ResourceGroup ToDto(DA.ResourceGroup source) {
     95      if (source == null) return null;
     96      return new DT.ResourceGroup {
     97        Id = source.Id,
     98        Name = source.Name,
     99        Description = source.Description,
     100        ResourceType = (DT.Resource.ResourceTypes)Enum.Parse(typeof(DT.Resource.ResourceTypes), source.ResourceType)
     101      };
     102    }
    115103
    116         public static DA.ResourceGroup ToEntity(DT.ResourceGroup source)
    117         {
    118             if (source == null) return null;
    119             return new DA.ResourceGroup
    120             {
    121                 Id = source.Id,
    122                 Name = source.Name,
    123                 Description = source.Description,
    124                 ResourceType = source.ResourceType,
    125             };
    126         }
     104    public static DA.ResourceGroup ToEntity(DT.ResourceGroup source) {
     105      if (source == null) return null;
     106      return new DA.ResourceGroup {
     107        Id = source.Id,
     108        Name = source.Name,
     109        Description = source.Description,
     110        ResourceType = source.ResourceType.ToString()
     111      };
     112    }
    127113
    128         public static void ToEntity(DT.ResourceGroup source, DA.ResourceGroup target)
    129         {
    130             if ((source != null) && (target != null))
    131             {
    132                 target.Id = source.Id;
    133                 target.Name = source.Name;
    134                 target.Description = source.Description;
    135                 target.ResourceType = source.ResourceType;
    136             }
    137         }
    138         #endregion // ResourceGroup
     114    public static void ToEntity(DT.ResourceGroup source, DA.ResourceGroup target) {
     115      if ((source != null) && (target != null)) {
     116        target.Id = source.Id;
     117        target.Name = source.Name;
     118        target.Description = source.Description;
     119        target.ResourceType = source.ResourceType.ToString();
     120      }
    139121    }
     122    #endregion // ResourceGroup
     123  }
    140124}
  • branches/ClientManagement/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication/HeuristicLab.Services.Authentication.csproj

    r4802 r5335  
    6464  </ItemGroup>
    6565  <ItemGroup>
    66     <Content Include="ClientService.svc" />
     66    <Content Include="HeuristicLabServicesDemo.sln" />
    6767    <Content Include="Web.config" />
    6868    <Content Include="Web.Debug.config">
     
    7474  </ItemGroup>
    7575  <ItemGroup>
    76     <Compile Include="ClientService.cs" />
     76    <Compile Include="AuthenticationService.cs" />
    7777    <Compile Include="Convert.cs" />
    78     <Compile Include="ClientService.svc.cs">
    79       <DependentUpon>ClientService.svc</DependentUpon>
    80     </Compile>
    81     <Compile Include="Interfaces\IClientService.cs" />
     78    <Compile Include="Interfaces\IAuthenticationService.cs" />
    8279    <Compile Include="Properties\AssemblyInfo.cs" />
    8380  </ItemGroup>
  • branches/ClientManagement/HeuristicLab.Services.Authentication/Test/Program.cs

    r4958 r5335  
    11using System;
     2using System.Text;
    23using System.Collections.Generic;
    34using System.Linq;
    4 using System.Text;
     5
    56using HeuristicLab.Services.Authentication;
     7using HL = HeuristicLab.Services.Authentication;
    68using DA = HeuristicLab.Services.Authentication.DataAccess;
    79using DT = HeuristicLab.Services.Authentication.DataTransfer;
    8 
    9 namespace Test
    10 {
    11     class Program
    12     {
    13         static void Main(string[] args)
    14         {
    15 
    16             //DA.ClientManagmentDataContext dc = new DA.ClientManagmentDataContext(@"Data Source=.\SQL2008;Initial Catalog=HeuristicLab.ClientManagment;Integrated Security=True");
    17             DA.ClientManagmentDataContext dc = new DA.ClientManagmentDataContext();
    18 
    19             //if (dc.DatabaseExists())
    20             //{
    21             //    Console.WriteLine("DB exsits");
    22             //    dc.DeleteDatabase();
    23             //    dc.SubmitChanges();
    24             //    Console.WriteLine("DB deleted");
    25             //}
    26             //Console.WriteLine("DB create");
    27             //dc.CreateDatabase();
    28             //dc.SubmitChanges();
    29             //Console.WriteLine("Finished");
    30 
    31             ClientService cs = new ClientService();
    32 
    33             DT.Client c = new DT.Client();
    34 
    35             c.Id = Guid.NewGuid();
    36             c.Name = "Eagle-Eye";
    37             c.Description = "Development-PC";
    38             c.IPAdress = "192.168.0.1";
    39 
    40             //c.ResourceType = "Client";
    41             DT.ResourceGroup r = new DT.ResourceGroup();
    42             r.Name = "test";
    43 
    44             r.Id = cs.AddResourceGroup(r);
    45 
    46             c.ResourceGroup = r.Id;
    47             c.Id = cs.AddClient(c);
    48            
    49             //ResourceResourceGroup rrg = new ResourceResourceGroup();
    50             //rrg.ResourceGroup = r;
    51             //rrg.Client = c;
    52            
    53            
    54             //dc.GetTable<Resource>().InsertOnSubmit(r);
    55             //dc.GetTable<Resource>().InsertOnSubmit(c);
    56 
    57             //dc.GetTable<ResourceResourceGroup>().InsertOnSubmit(rrg);
    58 
    59             //dc.SubmitChanges();
    60 
    61            
    62            // cs.GetClients();
    63 
    64             //cs.DeleteClient(c);
    65            cs.DeleteResourceGroup(r);
    66 
    67 
    68         }
     10using System.Data;
     11using System.Data.Common;
     12using System.Data.Linq;
     13using System.Collections;
     14
     15namespace Test {
     16  class Program {
     17    static void Main(string[] args) {
     18
     19      //// //DA.ClientManagmentDataContext dc = new DA.ClientManagmentDataContext(@"Data Source=.\SQL2008;Initial Catalog=HeuristicLab.ClientManagment;Integrated Security=True");
     20      //// DA.ClientManagmentDataContext dc = new DA.ClientManagmentDataContext();
     21
     22      //// if (dc.DatabaseExists()) {
     23      ////   Console.WriteLine("DB exsits");
     24      ////   dc.DeleteDatabase();
     25      ////   dc.SubmitChanges();
     26      ////   Console.WriteLine("DB deleted");
     27      //// }
     28      //// Console.WriteLine("DB create");
     29      //// dc.CreateDatabase();
     30      //// dc.SubmitChanges();
     31      //// Console.WriteLine("Finished");
     32
     33      //// AuthenticationService cs = new AuthenticationService();
     34
     35      //// DT.Client c = new DT.Client();
     36
     37      //// c.Id = Guid.NewGuid();
     38      //// c.Name = "Eagle-Eye";
     39      //// c.Description = "Development-PC";
     40      //// c.IPAdress = "192.168.0.1";
     41
     42      //// //c.ResourceType = "Client";
     43      //// DT.ResourceGroup r = new DT.ResourceGroup();
     44      //// r.Name = "test";
     45
     46      //// //r.Id = cs.AddResourceGroup(r);
     47
     48      //// //c.ResourceGroup = r.Id;
     49      //// //c.Id = cs.AddClient(c);
     50
     51      //// //ResourceResourceGroup rrg = new ResourceResourceGroup();
     52      //// //rrg.ResourceGroup = r;
     53      //// //rrg.Client = c;
     54
     55
     56      //// //dc.GetTable<Resource>().InsertOnSubmit(r);
     57      //// //dc.GetTable<Resource>().InsertOnSubmit(c);
     58
     59      //// //dc.GetTable<ResourceResourceGroup>().InsertOnSubmit(rrg);
     60
     61      //// //dc.SubmitChanges();
     62
     63
     64      ////// cs.GetClients();
     65
     66      //// //cs.DeleteClient(c);
     67      ////cs.DeleteResourceGroup(r);
     68      //Guid groupID1 = Guid.NewGuid();
     69      //string groupName1 = "groupName1";
     70      //Guid groupID2 = Guid.NewGuid();
     71      //string groupName2 = "groupName2";
     72      //Guid groupID3 = Guid.NewGuid();
     73      //string groupName3 = "groupName3";
     74
     75      //Guid clientID1 = Guid.NewGuid();
     76      //string clientName1 = "clientName1";
     77      //Guid clientID2 = Guid.NewGuid();
     78      //string clientName2 = "clientName2";
     79
     80      //DA.ClientManagmentDataContext dc = null;
     81
     82      //DT.Client cl1 = null;
     83      //DT.Client cl2 = null;
     84      //DT.Client cl3 = null;
     85
     86      //DT.ResourceGroup rg1 = null;
     87      //DT.ResourceGroup rg2 = null;
     88      //DT.ResourceGroup rg3 = null;
     89
     90      //DA.ResourceResourceGroup rrg1 = null;
     91      //DA.ResourceResourceGroup rrg2 = null;
     92      //DA.ResourceResourceGroup rrg3 = null;
     93
     94      //dc = new DA.ClientManagmentDataContext();
     95      //if (dc.DatabaseExists()) {
     96      //  //dc.DeleteDatabase();
     97      //  dc.ExecuteCommand("delete from ResourceResourceGroup");
     98      //  dc.ExecuteCommand("delete from Resource");
     99      //  dc.SubmitChanges();
     100      //}
     101      //else {
     102      //  dc.CreateDatabase();
     103      //  dc.SubmitChanges();
     104      //}
     105
     106
     107      //// create groups
     108      //rg1 = new DT.ResourceGroup();
     109      //rg1.Name = groupName1;
     110      //rg1.Id = groupID1;
     111      //rg1.Description = "descr rg1";
     112      //dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg1));
     113
     114      //rg2 = new DT.ResourceGroup();
     115      //rg2.Name = groupName2;
     116      //rg2.Id = groupID2;
     117
     118      //IList<Guid> rgList = new List<Guid>();
     119      //rgList.Add(rg1.Id);
     120      //rg2.ResourceGroup = rgList;
     121
     122      //rg2.Description = "descrrg2";
     123      //dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg2));
     124
     125      //rg3 = new DT.ResourceGroup();
     126      //rg3.Name = groupName3;
     127      //rg3.Id = groupID3;
     128      //rg3.Description = "descrrg3";
     129      //dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg3));
     130
     131      //// create clients
     132      //cl1 = new DT.Client();
     133      //cl1.Name = clientName1;
     134      //cl1.Id = clientID1;
     135
     136      //IList<Guid> rgList1 = new List<Guid>();
     137      //rgList.Add(groupID1);
     138      //cl1.ResourceGroup = rgList1;
     139
     140      //cl1.Description = "Test-PC-1";
     141      //cl1.IPAdress = "192.168.0.10";
     142      //cl1.NumberOfProcessors = "2";
     143      //cl1.NumberOfThreads = "4";
     144      //cl1.OperatingSystem = "WINXP";
     145      //cl1.MemorySize = "2048";
     146      //cl1.ProcessorType = "AMD";
     147      //dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(cl1));
     148
     149      //cl2 = new DT.Client();
     150      //cl2.Name = clientName2;
     151      //cl2.Id = clientID2;
     152
     153      //IList<Guid> rgList2 = new List<Guid>();
     154      //rgList.Add(groupID2);
     155      //cl2.ResourceGroup = rgList2;
     156
     157      //cl2.Description = "Test-PC-2";
     158      //cl2.IPAdress = "192.168.0.20";
     159      //cl2.NumberOfProcessors = "4";
     160      //cl2.NumberOfThreads = "4";
     161      //cl2.OperatingSystem = "Vista";
     162      //cl2.MemorySize = "4096";
     163      //cl2.ProcessorType = "Intel";
     164      //dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(cl2));
     165
     166      //// ResourceResourceGroups
     167      //rrg1 = new DA.ResourceResourceGroup();
     168      //rrg1.ResourceId = cl1.Id;
     169      //rrg1.ResourceGroupId = rg1.Id;
     170      //dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg1);
     171
     172      //rrg2 = new DA.ResourceResourceGroup();
     173      //rrg2.ResourceId = cl2.Id;
     174      //rrg2.ResourceGroupId = rg2.Id;
     175      //dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg2);
     176
     177      //rrg3 = new DA.ResourceResourceGroup();
     178      //rrg3.ResourceId = rg1.Id;
     179      //rrg3.ResourceGroupId = rg3.Id;
     180      //dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg3);
     181
     182      //dc.SubmitChanges();
     183
     184
     185     // AuthenticationService cs = new AuthenticationService();
     186
     187     // DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl1.Id);
     188     // DT.Client modClient = HeuristicLab.Services.Authentication.Convert.ToDto(client);
     189
     190     // //cl1.Id ;
     191     // //cl1.ResourceType ;
     192     // modClient.Name = "clientName1_modified";
     193
     194     //// IList<Guid> rgList = new List<Guid>();
     195     //// rgList.Add(groupID3);
     196
     197     // //cl1.ResourceGroup = rgList;
     198
     199     // modClient.Description = "Test-PC-1_modifiet";
     200     // modClient.IPAdress = "192.168.0.11";
     201     // modClient.NumberOfProcessors = "4";
     202     // modClient.NumberOfThreads = "2";
     203     // modClient.OperatingSystem = "Vista";
     204     // modClient.MemorySize = "2196";
     205     // modClient.ProcessorType = "Intel";
     206
     207     // cs.UpdateClient(modClient);
     208
    69209    }
     210  }
    70211}
  • branches/ClientManagement/HeuristicLab.Services.Authentication/TestWebService/TestWebService.csproj

    r4958 r5335  
    3939      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    4040    </Reference>
     41    <Reference Include="System.Data" />
     42    <Reference Include="System.Data.Linq" />
    4143  </ItemGroup>
    4244  <ItemGroup>
     
    5052  </ItemGroup>
    5153  <ItemGroup>
     54    <ProjectReference Include="..\HeuristicLab.Services.Authentication.DataAccess\HeuristicLab.Services.Authentication.DataAccess.csproj">
     55      <Project>{AC7C2117-034E-4301-8A43-C869930D404E}</Project>
     56      <Name>HeuristicLab.Services.Authentication.DataAccess</Name>
     57    </ProjectReference>
     58    <ProjectReference Include="..\HeuristicLab.Services.Authentication.DataTransfer\HeuristicLab.Services.Authentication.DataTransfer.csproj">
     59      <Project>{73E5113E-A293-4384-8B16-3CE38F2CFDC9}</Project>
     60      <Name>HeuristicLab.Services.Authentication.DataTransfer</Name>
     61    </ProjectReference>
    5262    <ProjectReference Include="..\HeuristicLab.Services.Authentication\HeuristicLab.Services.Authentication.csproj">
    5363      <Project>{ED8DC6E8-57C6-49E0-8CDF-25703AC52350}</Project>
  • branches/ClientManagement/HeuristicLab.Services.Authentication/TestWebService/TestWebServiec.cs

    r5004 r5335  
    6868    }
    6969
     70    class ResourceEqualityComparer : IEqualityComparer<DT.Resource> {
     71      public bool Equals(DT.Resource rg1, DT.Resource rg2) {
     72        return (
     73          rg1.Name == rg2.Name &&
     74          rg1.Id == rg2.Id
     75        );
     76      }
     77
     78      public int GetHashCode(DT.Resource obj) {
     79        throw new NotImplementedException();
     80      }
     81    }
     82
    7083    private bool CompareClients(DT.Client c1, DT.Client c2) {
    7184      return (
    7285        c1.Name == c2.Name &&
    7386        c1.Id == c2.Id &&
    74         //c1.ResourceType == c2.ResourceType &&
     87        c1.ResourceType == c2.ResourceType &&
    7588        c1.Description == c2.Description &&
    7689        c1.IPAdress == c2.IPAdress &&
     
    91104    }
    92105
     106    private bool CompareResources(DT.Resource r1, DT.Resource r2) {
     107      return (
     108        r1.Name == r2.Name &&
     109        r1.Id == r2.Id
     110        );
     111    }
     112
    93113    private static int GetNumberOfEntries(string sqlCommand) {
    94114      DA.ClientManagmentDataContext dc = new DA.ClientManagmentDataContext();
     
    117137    public DA.ResourceResourceGroup rrg2 = null;
    118138    public DA.ResourceResourceGroup rrg3 = null;
     139    public DA.ResourceResourceGroup rrg4 = null;
     140    public DA.ResourceResourceGroup rrg5 = null;
    119141    #endregion
    120    
     142
    121143    #region Additional test attributes
    122144    //
     
    142164
    143165    [TestInitialize()]
    144     public void Init() { 
     166    public void Init() {
    145167
    146168      dc = new DA.ClientManagmentDataContext();
     
    156178      }
    157179
    158      
     180
    159181      // create groups
    160182      rg1 = new DT.ResourceGroup();
    161183      rg1.Name = groupName1;
    162       rg1.Id = groupID1;     
     184      rg1.Id = groupID1;
    163185      rg1.Description = "descr rg1";
    164186      dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg1));
     
    167189      rg2.Name = groupName2;
    168190      rg2.Id = groupID2;
    169       rg2.ResourceGroup = rg1.Id;
     191
     192      IList<Guid> rgList = new List<Guid>();
     193      rgList.Add(rg1.Id);
     194      rg2.ResourceGroup = rgList;
     195
    170196      rg2.Description = "descrrg2";
    171197      dc.GetTable<DA.Resource>().InsertOnSubmit(HL.Convert.ToEntity(rg2));
     
    181207      cl1.Name = clientName1;
    182208      cl1.Id = clientID1;
    183       cl1.ResourceGroup = groupID1;
     209
     210      IList<Guid> rgList1 = new List<Guid>();
     211      rgList.Add(groupID1);
     212      cl1.ResourceGroup = rgList1;
     213
    184214      cl1.Description = "Test-PC-1";
    185215      cl1.IPAdress = "192.168.0.10";
     
    194224      cl2.Name = clientName2;
    195225      cl2.Id = clientID2;
    196       cl2.ResourceGroup = groupID2;
     226
     227      IList<Guid> rgList2 = new List<Guid>();
     228      rgList.Add(groupID2);
     229      cl2.ResourceGroup = rgList2;
     230
    197231      cl2.Description = "Test-PC-2";
    198232      cl2.IPAdress = "192.168.0.20";
     
    210244      dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg1);
    211245
     246      // ResourceResourceGroups
     247      rrg5 = new DA.ResourceResourceGroup();
     248      rrg5.ResourceId = cl1.Id;
     249      rrg5.ResourceGroupId = rg2.Id;
     250      dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg5);
     251
    212252      DA.ResourceResourceGroup rrg2 = new DA.ResourceResourceGroup();
    213253      rrg2.ResourceId = cl2.Id;
     
    215255      dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg2);
    216256
    217       DA.ResourceResourceGroup rrg3 = new DA.ResourceResourceGroup();
    218       rrg3.ResourceId = rg1.Id;
    219       rrg3.ResourceGroupId = rg3.Id;
    220       dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg3);
     257      //DA.ResourceResourceGroup rrg3 = new DA.ResourceResourceGroup();
     258      //rrg3.ResourceId = rg3.Id;
     259      //rrg3.ResourceGroupId = rg1.Id;
     260      //dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg3);
     261
     262      rrg4 = new DA.ResourceResourceGroup();
     263      rrg4.ResourceId = rg2.Id;
     264      rrg4.ResourceGroupId = rg1.Id;
     265      dc.GetTable<DA.ResourceResourceGroup>().InsertOnSubmit(rrg4);
    221266
    222267      dc.SubmitChanges();
     
    225270    [TestCleanup()]
    226271    public void CleanUp() {
    227       dc = new DA.ClientManagmentDataContext();
    228       if (dc.DatabaseExists()) {
    229         //dc.DeleteDatabase();
    230         dc.ExecuteCommand("delete from ResourceResourceGroup");
    231         dc.ExecuteCommand("delete from Resource");
    232         dc.SubmitChanges();
    233       }
    234       else {
    235         dc.CreateDatabase();
    236         dc.SubmitChanges();
    237       }
    238     }
    239 
    240     #region TestMethods   
     272      //dc = new DA.ClientManagmentDataContext();
     273      //if (dc.DatabaseExists()) {
     274      //  //dc.DeleteDatabase();
     275      //  dc.ExecuteCommand("delete from ResourceResourceGroup");
     276      //  dc.ExecuteCommand("delete from Resource");
     277      //  dc.SubmitChanges();
     278      //}
     279      //else {
     280      //  dc.CreateDatabase();
     281      //  dc.SubmitChanges();
     282      //}
     283    }
     284
     285    #region TestMethods
    241286
    242287    #region TestGroup
     
    247292    [TestMethod]
    248293    public void TestAddResourceGroup() {
    249       ClientService cs = new ClientService();
     294      AuthenticationService cs = new AuthenticationService();
    250295
    251296      DT.ResourceGroup rg4 = new DT.ResourceGroup();
     
    265310
    266311    /// <summary>
    267     /// TODO
     312
    268313    /// </summary>
    269314    [TestMethod]
    270315    public void TestUpdateResourceGroup() {
     316      AuthenticationService cs = new AuthenticationService();
     317
     318      DA.ResourceGroup group = dc.Resources.OfType<DA.ResourceGroup>().First(x => x.Id == rg1.Id);
     319      DT.ResourceGroup modGroup = HeuristicLab.Services.Authentication.Convert.ToDto(group);
     320
     321
     322      modGroup.Name = "clientName1_modified";
     323
     324      IList<Guid> rgList = new List<Guid>();
     325      rgList.Add(groupID3);
     326      modGroup.ResourceGroup = rgList;
     327      modGroup.Description = "Test-group_modifiet";
     328
     329      cs.UpdateResourceGroup(modGroup);
    271330    }
    272331
     
    276335    [TestMethod]
    277336    public void TestGetResourceGroup() {
    278       ClientService cs = new ClientService();
     337      AuthenticationService cs = new AuthenticationService();
    279338      DT.ResourceGroup rg = cs.GetResourceGroup(groupID1);
    280339      Assert.AreEqual(rg.Id, groupID1);
     
    287346    [TestMethod]
    288347    public void TestGetResourceGroups() {
    289       ClientService cs = new ClientService();
     348      AuthenticationService cs = new AuthenticationService();
    290349      IEnumerable<DT.ResourceGroup> groups = cs.GetResourceGroups();
    291350      Assert.AreEqual(3, groups.Count<DT.ResourceGroup>());
     
    298357
    299358    /// <summary>
    300     /// Delete existing ResourceGroup whisch is no parent group
     359    /// Delete existing ResourceGroup which is no parent group
    301360    /// </summary>
    302361    [TestMethod]
    303362    public void TestDeleteResourceGroup1() {
    304       ClientService cs = new ClientService();
     363      AuthenticationService cs = new AuthenticationService();
    305364
    306365      int cntPrev = GetNumberOfEntries(sqlCountGroups);
    307       Assert.IsTrue(cs.DeleteResourceGroup(rg2));
     366      cs.DeleteResourceGroup(rg2);
    308367      int cntNew = GetNumberOfEntries(sqlCountGroups);
    309368      Assert.AreEqual(cntPrev, (cntNew + 1));
     
    311370
    312371    /// <summary>
    313     /// try to delete existing ResourceGroup whisch is parent group
     372    /// try to delete existing ResourceGroup wich is parent group
    314373    /// </summary>
    315374    [TestMethod]
    316375    public void TestDeleteResourceGroup2() {
    317       ClientService cs = new ClientService();
    318 
     376      AuthenticationService cs = new AuthenticationService();
    319377      int cntPrev = GetNumberOfEntries(sqlCountGroups);
    320       Assert.IsFalse(cs.DeleteResourceGroup(rg1));
     378      cs.DeleteResourceGroup(rg1);
    321379      int cntNew = GetNumberOfEntries(sqlCountGroups);
    322380      Assert.AreEqual(cntPrev, cntNew);
     
    332390    [TestMethod]
    333391    public void TestAddClient1() {
    334       ClientService cs = new ClientService();
     392      AuthenticationService cs = new AuthenticationService();
    335393
    336394      DT.Client cl3 = new DT.Client();
    337395      cl3.Name = "clientName3";
    338       cl3.ResourceGroup = groupID3;
     396
     397      IList<Guid> rgList = new List<Guid>();
     398      rgList.Add(groupID3);
     399      cl3.ResourceGroup = rgList;
     400
    339401      cl3.Description = "Test-PC-3";
    340402      cl3.IPAdress = "192.168.0.30";
     
    347409      int cntPrev = GetNumberOfEntries(sqlCountClients);
    348410      cl3.Id = cs.AddClient(cl3);
    349       Assert.AreNotEqual(Guid.Empty, cl3.Id); 
     411      Assert.AreNotEqual(Guid.Empty, cl3.Id);
    350412      int cntNew = GetNumberOfEntries(sqlCountClients);
    351413      Assert.AreEqual(cntPrev, (cntNew - 1));
     
    360422    [TestMethod]
    361423    public void TestAddClient2() {
    362       ClientService cs = new ClientService();
     424      AuthenticationService cs = new AuthenticationService();
    363425
    364426      DT.Client cl3 = new DT.Client();
    365427      cl3.Name = "clientNamexxxx";
    366       cl3.ResourceGroup = Guid.NewGuid();
     428
     429      IList<Guid> rgList = new List<Guid>();
     430      rgList.Add(Guid.NewGuid());
     431      cl3.ResourceGroup = rgList;
    367432
    368433      int cntPrev = GetNumberOfEntries(sqlCountClients);
     
    370435      Assert.AreEqual(Guid.Empty, cl3.Id);
    371436      int cntNew = GetNumberOfEntries(sqlCountClients);
    372       Assert.AreEqual(cntPrev, cntNew); 
     437      Assert.AreEqual(cntPrev, cntNew);
    373438    }
    374439
     
    378443    [TestMethod]
    379444    public void TestGetClient1() {
    380       ClientService cs = new ClientService();
     445      AuthenticationService cs = new AuthenticationService();
    381446      DT.Client cl = cs.GetClient(clientID1);
    382447      Assert.AreEqual(cl.Id, clientID1);
     
    392457    //[TestMethod]
    393458    //public void TestGetClient2() {
    394     //  ClientService cs = new ClientService();
     459    //  AuthenticationService cs = new AuthenticationService();
    395460    //  DT.Client cl = cs.GetClient(Guid.NewGuid());
    396461    //  Assert.IsNull(cl);
     
    402467    //[TestMethod]
    403468    //public void TestGetClient3() {
    404     //  ClientService cs = new ClientService();
     469    //  AuthenticationService cs = new AuthenticationService();
    405470    //  DT.Client cl = cs.GetClient(Guid.Empty);
    406471    //  Assert.IsNull(cl);
     
    416481    [TestMethod]
    417482    public void TestDeleteClient1() {
    418       ClientService cs = new ClientService();
     483      AuthenticationService cs = new AuthenticationService();
    419484
    420485      int cntPrev = GetNumberOfEntries(sqlCountClients);
    421       Assert.IsTrue(cs.DeleteClient(cl1));
     486      cs.DeleteClient(cl1);
    422487      int cntNew = GetNumberOfEntries(sqlCountClients);
    423488      Assert.AreEqual(cntPrev, (cntNew + 1));
    424489    }
    425490
    426     /// <summary>
    427     /// try to delete not existing client
    428     /// </summary>
    429     [TestMethod]
    430     public void TestDeleteClient2() {
    431       ClientService cs = new ClientService();
    432       DT.Client cl3 = new DT.Client();
    433       cl3.Name = "clientName3";
    434       cl3.ResourceGroup = groupID3;
    435       cl3.Description = "Test-PC-3";
    436       cl3.IPAdress = "192.168.0.30";
    437       cl3.NumberOfProcessors = "2";
    438       cl3.NumberOfThreads = "2";
    439       cl3.OperatingSystem = "Vista";
    440       cl3.MemorySize = "4096";
    441       cl3.ProcessorType = "Intel";
    442 
    443       int cntPrev = GetNumberOfEntries(sqlCountClients);
    444       Assert.IsFalse(cs.DeleteClient(cl3));
    445       int cntNew = GetNumberOfEntries(sqlCountClients);
    446       Assert.AreEqual(cntPrev, cntNew);
    447     }
     491    ///// <summary>
     492    ///// try to delete not existing client
     493    ///// </summary>
     494    //[TestMethod]
     495    //public void TestDeleteClient2() {
     496    //  AuthenticationService cs = new AuthenticationService();
     497    //  DT.Client cl3 = new DT.Client();
     498    //  cl3.Name = "clientName3";
     499
     500    //  IList<Guid> rgList = new List<Guid>();
     501    //  rgList.Add(groupID3);
     502    //  cl3.ResourceGroup = rgList;
     503
     504    //  cl3.Description = "Test-PC-3";
     505    //  cl3.IPAdress = "192.168.0.30";
     506    //  cl3.NumberOfProcessors = "2";
     507    //  cl3.NumberOfThreads = "2";
     508    //  cl3.OperatingSystem = "Vista";
     509    //  cl3.MemorySize = "4096";
     510    //  cl3.ProcessorType = "Intel";
     511
     512    //  int cntPrev = GetNumberOfEntries(sqlCountClients);
     513    //  cs.DeleteClient(cl3);
     514    //  int cntNew = GetNumberOfEntries(sqlCountClients);
     515    //  Assert.AreEqual(cntPrev, cntNew);
     516    //}
    448517
    449518    /// <summary>
     
    452521    [TestMethod]
    453522    public void TestGetClients() {
    454       ClientService cs = new ClientService();
     523      AuthenticationService cs = new AuthenticationService();
    455524      IEnumerable<DT.Client> clients = cs.GetClients();
    456525      Assert.AreEqual(2, clients.Count<DT.Client>());
     
    466535    [TestMethod]
    467536    public void TestUpdateClient1() {
    468       ClientService cs = new ClientService();
    469       DT.Client cl1 = new DT.Client();
    470       cl1.Name = "clientName1_modified";
    471       cl1.ResourceGroup = groupID3;
    472       cl1.Description = "Test-PC-1_modifiet";
    473       cl1.IPAdress = "192.168.0.11";
    474       cl1.NumberOfProcessors = "4";
    475       cl1.NumberOfThreads = "2";
    476       cl1.OperatingSystem = "Vista";
    477       cl1.MemorySize = "2096";
    478       cl1.ProcessorType = "Intel";
    479 
    480       int cntPrev = GetNumberOfEntries(sqlCountClients);
    481       Assert.IsTrue(cs.UpdateClient(cl1));
    482       int cntNew = GetNumberOfEntries(sqlCountClients);
    483       Assert.AreEqual(cntPrev, cntNew);
     537      AuthenticationService cs = new AuthenticationService();
    484538
    485539      DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl1.Id);
    486       Assert.IsTrue(CompareClients(HL.Convert.ToDto(client), cl1));
    487     }
    488 
    489     /// <summary>
    490     /// try to update not existing client
    491     /// </summary>
    492     [TestMethod]
    493     public void TestUpdateClient2() {
    494       ClientService cs = new ClientService();
    495       DT.Client cl3 = new DT.Client();
    496       cl3.Id = Guid.NewGuid();
    497       cl3.Name = "clientName3";
    498       cl3.ResourceGroup = groupID3;
    499       cl3.Description = "Test-PC-3";
    500       cl3.IPAdress = "192.168.0.30";
    501       cl3.NumberOfProcessors = "2";
    502       cl3.NumberOfThreads = "2";
    503       cl3.OperatingSystem = "Vista";
    504       cl3.MemorySize = "4096";
    505       cl3.ProcessorType = "Intel";
    506 
    507       int cntPrev = GetNumberOfEntries(sqlCountClients);
    508       Assert.IsFalse(cs.UpdateClient(cl3));
    509       int cntNew = GetNumberOfEntries(sqlCountClients);
    510       Assert.AreEqual(cntPrev, cntNew);
    511 
    512       DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl3.Id);
    513       Assert.IsNull(client);
    514     }
     540      DT.Client modClient = HeuristicLab.Services.Authentication.Convert.ToDto(client);
     541
     542      //cl1.Id ;
     543      //cl1.ResourceType ;
     544      modClient.Name = "clientName1_modified";
     545
     546      IList<Guid> rgList = new List<Guid>();
     547      rgList.Add(groupID3);
     548      modClient.ResourceGroup = rgList;
     549
     550      modClient.Description = "Test-PC-1_modifiet";
     551      modClient.IPAdress = "192.168.0.11";
     552      modClient.NumberOfProcessors = "4";
     553      modClient.NumberOfThreads = "2";
     554      modClient.OperatingSystem = "Vista";
     555      modClient.MemorySize = "2196";
     556      modClient.ProcessorType = "Intel";
     557
     558      cs.UpdateClient(modClient);
     559
     560      //DA.Client client1 = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl1.Id);
     561      //Assert.IsTrue(CompareClients(HL.Convert.ToDto(client1), modClient));
     562    }
     563
     564    ///// <summary>
     565    ///// try to update not existing client
     566    ///// </summary>
     567    //[TestMethod]
     568    //public void TestUpdateClient2() {
     569    //  AuthenticationService cs = new AuthenticationService();
     570    //  DT.Client cl3 = new DT.Client();
     571    //  cl3.Id = Guid.NewGuid();
     572    //  cl3.Name = "clientName3";
     573
     574    //  IList<Guid> rgList = new List<Guid>();
     575    //  rgList.Add(groupID3);
     576    //  cl3.ResourceGroup = rgList;
     577
     578    //  cl3.Description = "Test-PC-3";
     579    //  cl3.IPAdress = "192.168.0.30";
     580    //  cl3.NumberOfProcessors = "2";
     581    //  cl3.NumberOfThreads = "2";
     582    //  cl3.OperatingSystem = "Vista";
     583    //  cl3.MemorySize = "4096";
     584    //  cl3.ProcessorType = "Intel";
     585
     586    //  int cntPrev = GetNumberOfEntries(sqlCountClients);
     587    //  //Assert.IsFalse(cs.UpdateClient(cl3));
     588    //  int cntNew = GetNumberOfEntries(sqlCountClients);
     589    //  Assert.AreEqual(cntPrev, cntNew);
     590
     591    //  DA.Client client = dc.Resources.OfType<DA.Client>().First(x => x.Id == cl3.Id);
     592    //  Assert.IsNull(client);
     593    //}
    515594
    516595    #endregion
    517    
     596
     597    /// <summary>
     598    /// get Members
     599    /// </summary>
     600    [TestMethod]
     601    public void TestGetMembers() {
     602      AuthenticationService cs = new AuthenticationService();
     603      IEnumerable<DT.Resource> members = cs.GetMembers(rg1.Id);
     604      Assert.AreEqual(2, members.Count());
     605    }
     606
     607    /// <summary>
     608    /// get ResourceGroupsOf
     609    /// </summary>
     610    [TestMethod]
     611    public void TestGetResourceGroupsOf() {
     612      AuthenticationService cs = new AuthenticationService();
     613      IEnumerable<DT.Resource> resGroups = cs.GetResourceGroupsOf(cl1.Id);
     614      Assert.AreEqual(2, resGroups.Count());
     615    }
     616
     617    /// <summary>
     618    /// get Members
     619    /// </summary>
     620    [TestMethod]
     621    public void TestGetRootResources() {
     622      AuthenticationService cs = new AuthenticationService();
     623      IEnumerable<DT.Resource> rootResourceList = cs.GetRootResources();
     624      Assert.AreEqual(2, rootResourceList.Count());
     625    }
     626
    518627    #endregion //Testmethods
    519628  }
Note: See TracChangeset for help on using the changeset viewer.