Free cookie consent management tool by TermsFeed Policy Generator

Changeset 899


Ignore:
Timestamp:
12/04/08 15:53:04 (16 years ago)
Author:
svonolfe
Message:

Added user adapter to the service locator (#372)

Location:
trunk/sources
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ClientAdapter.cs

    r845 r899  
    3636   
    3737    #region IClientAdapter Members
    38     private ClientInfo Convert(dsHiveServer.ClientRow row) {
    39       if(row != null) {
    40         ClientInfo client = new ClientInfo();
    41        
     38    private ClientInfo Convert(dsHiveServer.ClientRow row,
     39      ClientInfo client) {
     40      if(row != null && client != null) {     
    4241        /*Parent - resource*/
    43         Resource resource =
    44           resAdapter.GetResourceById(row.ResourceId);
    45         client.ResourceId = resource.ResourceId;
    46         client.Name = resource.Name;
     42        client.ResourceId = row.ResourceId;
     43        resAdapter.FillResource(client);
    4744
    4845        /*ClientInfo*/
    4946        client.ClientId = row.GUID;
    50         client.CpuSpeedPerCore = row.CPUSpeed;
    51         client.Memory = row.Memory;
    52         client.Login = row.Login;
    53         if (row.Status != null)
     47       
     48        if (!row.IsCPUSpeedNull())
     49          client.CpuSpeedPerCore = row.CPUSpeed;
     50        else
     51          client.CpuSpeedPerCore = 0;
     52
     53        if (!row.IsMemoryNull())
     54          client.Memory = row.Memory;
     55        else
     56          client.Memory = 0;
     57
     58        if (!row.IsLoginNull())
     59          client.Login = row.Login;
     60        else
     61          client.Login = DateTime.MinValue;
     62
     63        if (!row.IsStatusNull())
    5464          client.State = (State)Enum.Parse(typeof(State), row.Status, true);
    55         client.NrOfCores = row.NumberOfCores;
     65        else
     66          client.State = State.idle;
     67
     68        if (!row.IsNumberOfCoresNull())
     69          client.NrOfCores = row.NumberOfCores;
     70        else
     71          client.NrOfCores = 0;
    5672
    5773        //todo: config adapter (client.config)
     
    107123
    108124    public ClientInfo GetClientById(Guid clientId) {
     125      ClientInfo client = new ClientInfo();
     126     
    109127      dsHiveServer.ClientDataTable data =
    110128          adapter.GetDataById(clientId);
     
    112130        dsHiveServer.ClientRow row =
    113131          data[0];
    114         return Convert(row);
     132        Convert(row, client);
     133
     134        return client;
    115135      } else {
    116136        return null;
     
    126146
    127147      foreach (dsHiveServer.ClientRow row in data) {
    128         allClients.Add(Convert(row));
     148        ClientInfo client = new ClientInfo();
     149        Convert(row, client);
     150        allClients.Add(client);
    129151      }
    130152
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/PermissionOwnerAdapter.cs

    r845 r899  
    5555    }
    5656
     57    internal bool FillPermissionOwner(PermissionOwner permOwner) {
     58      if (permOwner != null) {
     59          return true;
     60      }
     61
     62      return false;
     63    }
     64
    5765    public PermissionOwner GetPermissionOwnerById(long resourceId) {
    5866      throw new NotImplementedException();
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/ResourceAdapter.cs

    r845 r899  
    3333      new dsHiveServerTableAdapters.ResourceTableAdapter();
    3434
    35     private Resource Convert(dsHiveServer.ResourceRow row) {
    36       if (row != null) {
    37         Resource resource = new Resource();
    38 
     35    private Resource Convert(dsHiveServer.ResourceRow row,
     36      Resource resource) {
     37      if (row != null && resource != null) {
    3938        resource.ResourceId = row.ResourceId;
    40         resource.Name = row.Name;
     39        if (!row.IsNameNull())
     40          resource.Name = row.Name;
     41        else
     42          resource.Name = String.Empty;
    4143
    4244        return resource;
    43       } else
     45      } else 
    4446        return null;
    4547    }
     
    4951      if (resource != null && row != null) {
    5052        row.Name = resource.Name;
    51       }
    5253
    53       return row;
     54        return row;
     55      } else
     56        return null;
    5457    }
    5558
     
    7578    }
    7679
     80    internal bool FillResource(Resource resource) {
     81      if (resource != null) {
     82        dsHiveServer.ResourceDataTable data =
     83          adapter.GetDataById(resource.ResourceId);
     84        if (data.Count == 1) {
     85          dsHiveServer.ResourceRow row =
     86            data[0];
     87          Convert(row, resource);
     88
     89          return true;
     90        }
     91      }
     92
     93      return false;
     94    }
     95
    7796    public Resource GetResourceById(long resourceId) {
    78       dsHiveServer.ResourceDataTable data =
    79           adapter.GetDataById(resourceId);
    80       if (data.Count == 1) {
    81         dsHiveServer.ResourceRow row =
    82           data[0];
    83         return Convert(row);
    84       } else {
     97      Resource resource = new Resource();
     98      resource.ResourceId = resourceId;
     99
     100      if(FillResource(resource))
     101        return resource;
     102      else
    85103        return null;
    86       }
    87104    }
    88105
     
    95112
    96113      foreach (dsHiveServer.ResourceRow row in data) {
    97         allResources.Add(Convert(row));
     114        Resource resource = new Resource();
     115        Convert(row, resource);
     116        allResources.Add(resource);
    98117      }
    99118
  • trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/UserAdapter.cs

    r845 r899  
    3636      new PermissionOwnerAdapter();
    3737
    38     private User Convert(dsHiveServer.HiveUserRow row) {
    39       if (row != null) {
    40         User user = new User();
    41 
    42         /*Parent - resource*/
    43         PermissionOwner permOwner =
    44           permOwnerAdapter.GetPermissionOwnerById(row.PermissionOwnerId);
    45         user.PermissionOwnerId = permOwner.PermissionOwnerId;
    46         user.Name = permOwner.Name;
     38    private User Convert(dsHiveServer.HiveUserRow row,
     39      User user) {
     40      if (row != null && user != null) {
     41        /*Parent - PermissionOwner*/
     42        user.PermissionOwnerId = row.PermissionOwnerId;
     43        permOwnerAdapter.FillPermissionOwner(user);
    4744
    4845        /*User*/
    49         user.Password = row.Password;
     46        if (!row.IsPasswordNull())
     47          user.Password = row.Password;
     48        else
     49          user.Password = String.Empty;
    5050
    5151        return user;
     
    5959        row.PermissionOwnerId = user.PermissionOwnerId;
    6060        row.Password = user.Password;
    61       }
    6261
    63       return row;
     62        return row;
     63      } else
     64        return null;     
    6465    }
    6566
     
    7071    }
    7172
    72     public ClientInfo GetUserById(long userId) {
     73    public User GetUserById(long userId) {
     74      throw new NotImplementedException();
     75    }
     76
     77    public User GetUserByName(String name) {
    7378      throw new NotImplementedException();
    7479    }
  • trunk/sources/HeuristicLab.Hive.Server.Core/InternalInterfaces/DataAccess/IUserAdapter.cs

    r845 r899  
    4242    /// <param name="userId"></param>
    4343    /// <returns></returns>
    44     ClientInfo GetUserById(long userId);
     44    User GetUserById(long userId);
     45
     46    /// <summary>
     47    /// Get the user with the specified name
     48    /// </summary>
     49    /// <param name="userId"></param>
     50    /// <returns></returns>
     51    User GetUserByName(string name);
    4552
    4653    /// <summary>
  • trunk/sources/HeuristicLab.Hive.Server.Core/ServiceLocator.cs

    r826 r899  
    3131
    3232  private static IClientAdapter clientAdapter = null;
     33
     34  private static IUserAdapter userAdapter = null;
    3335 
    3436  /// <summary>
     
    4345    return clientAdapter;
    4446  }
     47
     48  /// <summary>
     49  /// Gets the user database adapter
     50  /// </summary>
     51  /// <returns></returns>
     52  internal static IUserAdapter GetUserAdapter() {
     53    if (userAdapter == null) {
     54      userAdapter = discoveryService.GetInstances<IUserAdapter>()[0];
     55    }
     56
     57    return userAdapter;
     58  }
    4559}
  • trunk/sources/HeuristicLab.Hive.Server/MainForm.Designer.cs

    r800 r899  
    4040          this.label1.Location = new System.Drawing.Point(18, 18);
    4141          this.label1.Name = "label1";
    42           this.label1.Size = new System.Drawing.Size(113, 13);
     42          this.label1.Size = new System.Drawing.Size(115, 13);
    4343          this.label1.TabIndex = 0;
    44           this.label1.Text = "Hive server running @";
     44          this.label1.Text = "Hive Server running @";
    4545          //
    4646          // lblAddress1
Note: See TracChangeset for help on using the changeset viewer.