Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4649


Ignore:
Timestamp:
10/28/10 14:52:56 (14 years ago)
Author:
cneumuel
Message:
  • moved db-context into datalayer
  • businesslayer only defines the transaction-scope
  • removed contextfactory
  • implemented convert-methods
  • made naming in db and domainobjects more consistent
  • changed wcf-service to be http-only (for now)

(#1233)

Location:
branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New
Files:
5 added
6 deleted
23 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Clients.Hive/3.3/HeuristicLab.Clients.Hive-3.3.csproj

    r4629 r4649  
    7676    <Compile Include="Exceptions\JobResultPollingException.cs" />
    7777    <Compile Include="Exceptions\OptimizerNotFoundException.cs" />
    78     <Compile Include="HiveExperiment\HiveExperimentList.cs" />
    79     <Compile Include="HiveExperiment\HiveJobList.cs" />
    80     <Compile Include="Jobs\JobList.cs" />
    8178    <Compile Include="Jobs\OptimizerJob.cs" />
    8279    <Compile Include="HeuristicLabClientsHivePlugin.cs" />
    8380    <Compile Include="HiveExperiment\HiveClient.cs" />
    84     <Compile Include="HiveExperiment\HiveJob.cs" />
    85     <Compile Include="HiveExperiment\HiveExperiment.cs" />
     81    <Compile Include="HiveExperiment\HiveJobClient.cs" />
     82    <Compile Include="HiveExperiment\HiveExperimentClient.cs" />
    8683    <Compile Include="HiveExperiment\JobResultPoller.cs" />
    8784    <Compile Include="Progress\IProgress.cs" />
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Clients.Hive/3.3/HiveExperiment/HiveClient.cs

    r4629 r4649  
    3838    private bool currentlyUpdating;
    3939
    40     private ILog log;
    41     public ILog Log {
    42       get { return log; }
    43     }
    44 
    45     private HiveExperimentList hiveExperiments;
    46     public HiveExperimentList HiveExperiments {
     40    private ItemList<HiveExperimentClient> hiveExperiments;
     41    public ItemList<HiveExperimentClient> HiveExperiments {
    4742      get { return hiveExperiments; }
    4843      set {
     
    7469    private void RegisterHiveExperimentsEvent() {
    7570      if (hiveExperiments != null) {
    76         hiveExperiments.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
     71        hiveExperiments.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<HiveExperimentClient>>(hiveExperiments_ItemsRemoved);
    7772      }
    7873    }
     
    8075    private void DeRegisterHiveExperimentsEvents() {
    8176      if (hiveExperiments != null) {
    82         hiveExperiments.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<HiveExperiment>>(hiveExperiments_ItemsRemoved);
     77        hiveExperiments.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<HiveExperimentClient>>(hiveExperiments_ItemsRemoved);
    8378      }
    8479    }
    8580
    8681    public HiveClient() {
    87       this.log = new Log();
     82     
    8883    }
    8984
    9085    public override IDeepCloneable Clone(Cloner cloner) {
    9186      HiveClient clone = (HiveClient)base.Clone(cloner);
    92       clone.log = (ILog)cloner.Clone(this.log);
    93       clone.hiveExperiments = (HiveExperimentList)cloner.Clone(this.hiveExperiments);
     87      clone.hiveExperiments = (ItemList<HiveExperimentClient>)cloner.Clone(this.hiveExperiments);
    9488      return clone;
    9589    }
     
    10094        IsProgressing = true;
    10195        if (this.HiveExperiments == null) {
    102           this.HiveExperiments = new HiveExperimentList();
     96          this.HiveExperiments = new ItemList<HiveExperimentClient>();
    10397        }
    10498        using (var service = ServiceLocator.Instance.ServicePool.GetService()) {
     
    121115    private void RefreshExperimentList(IEnumerable<DT.HiveExperiment> hiveExperiments) {
    122116      foreach (DT.HiveExperiment hiveExperimentDto in hiveExperiments) {
    123         DT.HiveExperiment hiveExperiment = GetHiveExperiment(hiveExperimentDto.Id);
     117        HiveExperimentClient hiveExperiment = GetHiveExperiment(hiveExperimentDto.Id);
    124118        if (hiveExperiment == null) {
    125119          // not yet there, create new
    126           this.HiveExperiments.Add(new HiveExperiment(hiveExperimentDto));
     120          this.HiveExperiments.Add(new HiveExperimentClient(hiveExperimentDto));
    127121        } else {
    128122          // update
     
    132126    }
    133127
    134     private DT.HiveExperiment GetHiveExperiment(Guid hiveExperimentId) {
    135       return this.HiveExperiments.SingleOrDefault(he => he.Id.Equals(hiveExperimentId));
    136     }
    137 
    138     private void LogMessage(string message) {
    139       // HeuristicLab.Log is not Thread-Safe, so lock on every call
    140       lock (locker) {
    141         log.LogMessage(message);
    142       }
     128    private HiveExperimentClient GetHiveExperiment(Guid hiveExperimentId) {
     129      return this.HiveExperiments.SingleOrDefault(he => he.HiveExperimentId.Equals(hiveExperimentId));
    143130    }
    144131
     
    149136    }
    150137   
    151     void hiveExperiments_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperiment>> e) {
     138    void hiveExperiments_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<HiveExperimentClient>> e) {
    152139      if (!currentlyUpdating) {
    153140        using (Disposable<IHiveService> service = ServiceLocator.Instance.ServicePool.GetService()) {
    154           foreach (IndexedItem<HiveExperiment> item in e.Items) {
     141          foreach (IndexedItem<HiveExperimentClient> item in e.Items) {
    155142            if (item.Value.HiveExperimentId != Guid.Empty) {
    156143              service.Obj.DeleteHiveExperiment(item.Value.HiveExperimentId);
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Clients.Hive/3.3/ServiceClients/GenerateServiceClients.cmd

    r4629 r4649  
    77
    88svcutil.exe ^
    9   http://localhost:9001/HiveService/mex ^
     9  http://localhost:9000/HiveService/mex ^
    1010  /out:HiveServiceClient ^
    1111  /namespace:*,HeuristicLab.Clients.Hive ^
    1212  /targetClientVersion:Version35 ^
    1313  /enableDataBinding ^
    14   /config:..\app.config ^
    15   /reference:..\..\..\HeuristicLab.Services.Hive.Common\3.3\bin\debug\HeuristicLab.Services.Hive.Common-3.3.dll
     14  /config:..\app.config
    1615
    1716echo.
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Clients.Hive/3.3/ServiceClients/ServiceClientFactory.cs

    r4629 r4649  
    105105
    106106    private void RegisterServiceEvents() {
    107       disposableService.OnDisposing += new EventHandler(disposableService_OnDisposing);
     107      disposableService.Disposing += disposableService_Disposing;
    108108      ((ICommunicationObject)disposableService.Obj).Faulted += new EventHandler(WcfServicePool_Faulted);
    109109    }
    110110
    111111    private void DeregisterServiceEvents() {
    112       disposableService.OnDisposing -= new EventHandler(disposableService_OnDisposing);
     112      disposableService.Disposing -= disposableService_Disposing;
    113113      ((ICommunicationObject)disposableService.Obj).Faulted -= new EventHandler(WcfServicePool_Faulted);
    114114    }
     
    122122    }
    123123
    124     private void disposableService_OnDisposing(object sender, EventArgs e) {
     124    private void disposableService_Disposing(object sender, EventArgs<T> e) {
    125125      DisposeService();
    126126    }
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Clients.Hive/3.3/app.config

    r4629 r4649  
    33    <system.serviceModel>
    44        <bindings>
    5             <netTcpBinding>
    6                 <binding name="TcpEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00"
    7                     receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
    8                     transferMode="Streamed" transactionProtocol="OleTransactions"
    9                     hostNameComparisonMode="StrongWildcard" listenBacklog="10"
    10                     maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
    11                     maxReceivedMessageSize="65536">
     5            <wsHttpBinding>
     6                <binding name="HttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
     7                    receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
     8                    transactionFlow="false" hostNameComparisonMode="StrongWildcard"
     9                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
     10                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
     11                    allowCookies="false">
    1212                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
    1313                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    1414                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
    1515                        enabled="false" />
    16                     <security mode="TransportWithMessageCredential">
    17                         <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
    18                         <message clientCredentialType="UserName" algorithmSuite="Default" />
     16                    <security mode="Message">
     17                        <transport clientCredentialType="Windows" proxyCredentialType="None"
     18                            realm="" />
     19                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
     20                            algorithmSuite="Default" />
    1921                    </security>
    2022                </binding>
    21             </netTcpBinding>
     23            </wsHttpBinding>
    2224        </bindings>
    2325        <client>
    24             <endpoint address="net.tcp://localhost:9000/HiveService" binding="netTcpBinding"
    25                 bindingConfiguration="TcpEndpoint" contract="HeuristicLab.Services.Hive.Common.ServiceContracts.IHiveService"
    26                 name="TcpEndpoint">
     26            <endpoint address="http://localhost:9000/HiveService" binding="wsHttpBinding"
     27                bindingConfiguration="HttpBinding" contract="HeuristicLab.Clients.Hive.IHiveService"
     28                name="HttpBinding">
    2729                <identity>
    28                     <dns value="localhost" />
     30                    <userPrincipalName value="S0920454044@hagenberg.fhooe.at" />
    2931                </identity>
    3032            </endpoint>
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/DataTransfer/HiveExperiment.cs

    r4629 r4649  
    3030  public class HiveExperiment : NamedHiveItem {
    3131    [DataMember]
    32     public string ResourceIds { get; set; }
    33     [DataMember]
    3432    public Guid UserId { get; set; }
    3533    [DataMember]
     
    3735
    3836    public override string ToString() {
    39       return base.ToString() + "Name: " + Name + ", Description: " + Description + ", ResourceIds: " + ResourceIds;
     37      return base.ToString() + "Name: " + Name + ", Description: " + Description;
    4038    }
    4139   
    4240    public override IDeepCloneable Clone(Cloner cloner) {
    4341      var clone = (HiveExperiment)base.Clone(cloner);
    44       clone.ResourceIds = this.ResourceIds;
    4542      clone.RootJobId = this.RootJobId;
    4643      clone.UserId = this.UserId;
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/DataTransfer/HiveItem.cs

    r4629 r4649  
    88namespace HeuristicLab.Services.Hive.Common.DataTransfer {
    99  [DataContract]
    10   public abstract class HiveItem : IDeepCloneable {
     10  [Serializable]
     11  public abstract class HiveItem : HiveItemBase {
    1112    [DataMember]
    1213    public Guid Id { get; set; }
    1314
    1415    public virtual IDeepCloneable Clone(Cloner cloner) {
    15       HiveItem clone = (HiveItem)Activator.CreateInstance(this.GetType(), true);
    16       cloner.RegisterClonedObject(this, clone);
     16      HiveItem clone = (HiveItem)base.Clone(cloner);
    1717      clone.Id = this.Id;
    1818      return clone;
    1919    }
    20 
    21     public object Clone() {
    22       return Clone(new Cloner());
    23     }
    2420  }
    2521}
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/DataTransfer/Job.cs

    r4629 r4649  
    2727
    2828namespace HeuristicLab.Services.Hive.Common.DataTransfer {
    29 
    3029  [DataContract]
    3130  [Serializable]
     
    4039    public int MemoryNeeded { get; set; }
    4140    [DataMember]
    42     public List<Guid> PluginsNeededIds { get; set; }
    43     [DataMember]
    44     public List<Guid> AssignedResourceIds { get; set; }
    45     [DataMember]
    46     public Guid ProjectId { get; set; }
     41    public Guid? ProjectId { get; set; }
    4742
    4843    public override string ToString() {
    49       return base.ToString() + "State: " + State + ", [SlaveId : " + SlaveId + " ] , DateCreated: " + DateCreated + ", DateCalculated: " + DateCalculated +
    50         "Priority: " + Priority + ", CoresNeeded: " + CoresNeeded + "AssignedResources: " + AssignedResourceIds;
     44      return base.ToString() + "State: " + JobState + ", [SlaveId : " + SlaveId + " ] , DateCreated: " + DateCreated + ", DateCalculated: " + DateCalculated +
     45        "Priority: " + Priority + ", CoresNeeded: " + CoresNeeded;
    5146    }
    5247
    5348    public Job() {
    54       PluginsNeededIds = new List<Guid>();
    55       AssignedResourceIds = new List<Guid>();
    5649    }
    5750
     
    6255      clone.CoresNeeded = this.CoresNeeded;
    6356      clone.MemoryNeeded = this.MemoryNeeded;
    64       clone.PluginsNeededIds = new List<Guid>(this.PluginsNeededIds);
    65       clone.AssignedResourceIds = new List<Guid>(this.AssignedResourceIds);
    6657      clone.ProjectId = this.ProjectId;
    6758      return clone;
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/DataTransfer/JobData.cs

    r4629 r4649  
    2828  [DataContract]
    2929  [Serializable]
    30   public class JobData : HiveItem {
     30  public class JobData : HiveItemBase {
    3131    [DataMember]
    3232    public Guid JobId { get; set; }
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/DataTransfer/JobState.cs

    r4615 r4649  
    2323namespace HeuristicLab.Services.Hive.Common.DataTransfer {
    2424  public enum JobState {
    25     /// <summary>
    26     /// Job is actively calculated on a Slave
     25        /// <summary>
     26    /// A job is offline as long as he is not yet submitted to the hive
    2727    /// </summary>
    28     Calculating,
     28    Offline,
    2929
    3030    /// <summary>
     
    3333    Waiting,
    3434
     35        /// <summary>
     36    /// The job is paused and waits on the server to be sent back to a Slave when all of its child jobs are Finished.
     37    /// </summary>
     38    WaitingForChildJobs,
     39
     40    /// <summary>
     41    /// Job is actively calculated on a Slave
     42    /// </summary>
     43    Calculating,
     44   
    3545    /// <summary>
    3646    /// Job as finished and is ready to be collected by the Client
     
    4656    /// Job as been aborted due to an error. Results are ready to be collected
    4757    /// </summary>
    48     Failed,
    49 
    50     /// <summary>
    51     /// The job is paused and waits on the server to be sent back to a Slave when all of its child jobs are Finished.
    52     /// </summary>
    53     WaitForChildJobs
     58    Failed
    5459  };
    5560
     
    6772    public static bool IsWaiting(this JobState jobState) {
    6873      return jobState == JobState.Waiting ||
    69         jobState == JobState.WaitForChildJobs;
     74        jobState == JobState.WaitingForChildJobs;
    7075    }
    7176
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/DataTransfer/LightweightJob.cs

    r4629 r4649  
    2929  public class LightweightJob : HiveItem {
    3030    [DataMember]
    31     public Guid SlaveId { get; set; }
     31    public Guid? SlaveId { get; set; }
    3232    [DataMember]
    33     public JobState State { get; set; }
     33    public JobState JobState { get; set; }
    3434    [DataMember]
    35     public TimeSpan ExecutionTime { get; set; }
     35    public TimeSpan? ExecutionTime { get; set; }
    3636    [DataMember]
    3737    public String Exception { get; set; }
     
    4545    public Guid? ParentJobId { get; set; }
    4646
    47     public LightweightJob() { }
     47    public LightweightJob() {
     48      JobState = DataTransfer.JobState.Offline;
     49    }
    4850
    4951    public LightweightJob(Job job) {
    5052      this.SlaveId = job.SlaveId;
    51       this.State = job.State;
     53      this.JobState = job.JobState;
    5254      this.ExecutionTime = job.ExecutionTime;
    5355      this.Exception = job.Exception;
     
    6163      var clone = (LightweightJob)base.Clone(cloner);
    6264      clone.SlaveId = this.SlaveId;
    63       clone.State = this.State;
     65      clone.JobState = this.JobState;
    6466      clone.ExecutionTime = this.ExecutionTime;
    6567      clone.Exception = this.Exception;
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/DataTransfer/Slave.cs

    r4629 r4649  
    3333    public int? FreeCores { get; set; }
    3434    [DataMember]
    35     public int? CpuSpeedPerCore { get; set; }
     35    public int? CpuSpeed { get; set; }
    3636    [DataMember]
    3737    public int? Memory { get; set; }
     
    3939    public int? FreeMemory { get; set; }
    4040    [DataMember]
    41     public SlaveState State { get; set; }
     41    public SlaveState SlaveState { get; set; }
    4242    [DataMember]
    43     public CalendarState CalendarSyncStatus { get; set; }
     43    public CalendarState CalendarSyncState { get; set; }
    4444    [DataMember]
    45     public Guid SlaveConfigId { get; set; }
     45    public Guid? SlaveConfigId { get; set; }
    4646    [DataMember]
    4747    public bool IsAllowedToCalculate { get; set; }
    4848
     49    public Slave() {
     50      SlaveState = DataTransfer.SlaveState.Idle;
     51    }
     52
    4953    public override string ToString() {
    50       return base.ToString() + ", NrOfCores: " + Cores + ", NrOfFreeCores " + FreeCores + ", State: " + State;
     54      return base.ToString() + ", NrOfCores: " + Cores + ", NrOfFreeCores " + FreeCores + ", State: " + SlaveState;
    5155    }
    5256
     
    5559      clone.Cores = this.Cores;
    5660      clone.FreeCores = this.FreeCores;
    57       clone.CpuSpeedPerCore = this.CpuSpeedPerCore;
     61      clone.CpuSpeed = this.CpuSpeed;
    5862      clone.Memory = this.Memory;
    5963      clone.FreeMemory = this.FreeMemory;
    60       clone.State = this.State;
    61       clone.CalendarSyncStatus = this.CalendarSyncStatus;
     64      clone.SlaveState = this.SlaveState;
     65      clone.CalendarSyncState = this.CalendarSyncState;
    6266      clone.SlaveConfigId = this.SlaveConfigId;
    6367      clone.IsAllowedToCalculate = this.IsAllowedToCalculate;
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/DataTransfer/SlaveGroup.cs

    r4629 r4649  
    3030  public class SlaveGroup : Resource {
    3131    [DataMember]
    32     public List<Guid> ResourcesIds { get; set; }
     32    public List<Guid> ChildResourcesIds { get; set; }
     33    [DataMember]
     34    public List<Guid> ParentResourcesIds { get; set; }
    3335
    3436    public SlaveGroup() {
    35       ResourcesIds = new List<Guid>();
     37      ChildResourcesIds = new List<Guid>();
    3638    }
    3739
    3840    public override IDeepCloneable Clone(Cloner cloner) {
    3941      var clone = (SlaveGroup)base.Clone(cloner);
    40       clone.ResourcesIds = new List<Guid>(this.ResourcesIds);
     42      clone.ChildResourcesIds = new List<Guid>(this.ChildResourcesIds);
     43      clone.ParentResourcesIds = new List<Guid>(this.ParentResourcesIds);
    4144      return clone;
    4245    }
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/Disposable.cs

    r4598 r4649  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324
    2425namespace HeuristicLab.Services.Hive.Common {
     
    3435
    3536    public void Dispose() {
    36       if (OnDisposing != null)
    37         OnDisposing(this, new EventArgs());
     37      if (Disposing != null)
     38        Disposing(this, new EventArgs<T>(obj));
    3839    }
    3940
    40     public event EventHandler OnDisposing;
     41    public event EventHandler<EventArgs<T>> Disposing;
    4142  }
    4243}
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/HeuristicLab.Services.Hive.Common-3.3.csproj

    r4629 r4649  
    6767    <Compile Include="DataTransfer\HiveExperiment.cs" />
    6868    <Compile Include="DataTransfer\HiveItem.cs" />
     69    <Compile Include="DataTransfer\HiveItemBase.cs" />
    6970    <Compile Include="DataTransfer\HivePluginData.cs" />
    7071    <Compile Include="DataTransfer\HivePlugin.cs" />
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.Common/3.3/ServiceContracts/IHiveService.cs

    r4629 r4649  
    156156    #region Slave Methods
    157157    [OperationContract]
     158    Guid AddSlave(Slave slave);
     159
     160    [OperationContract]
    158161    Guid AddSlaveGroup(SlaveGroup slaveGroup);
    159162
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/Convert.cs

    r4598 r4649  
    2424using System.Linq;
    2525using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
     26using System;
    2627
    2728namespace HeuristicLab.Services.Hive.DataAccess {
    2829  public static class Convert {
    29 
    30    
    3130    #region Job
    3231    public static DT.Job ToDto(Job source) {
    3332      if (source == null) return null;
    34       return new DT.Job { Id = source.JobId };// todo
     33      return new DT.Job {
     34        Id = source.JobId,
     35        CoresNeeded = source.CoresNeeded,
     36        DateCalculated = source.DateCalculated,
     37        DateCreated = source.DateCreated,
     38        DateFinished = source.DateFinished,
     39        Exception = source.Exception,
     40        ExecutionTime = source.ExecutionTime,
     41        MemoryNeeded = source.MemoryNeeded,
     42        ParentJobId = source.ParentJobId,
     43        Priority = source.Priority,
     44        ProjectId = source.ProjectId,
     45        SlaveId = source.SlaveId,
     46        JobState = source.JobState,
     47        UserId = source.UserId
     48      };
    3549    }
    3650    public static Job ToEntity(DT.Job source) {
    3751      if (source == null) return null;
    38       return new Job { JobId = source.Id };// todo
     52      var entity = new Job(); ToEntity(source, entity);
     53      return entity;
    3954    }
    4055    public static void ToEntity(DT.Job source, Job target) {
    4156      if ((source != null) && (target != null)) {
    42         target.JobId = source.Id;// todo
     57        target.JobId = source.Id;
     58        target.CoresNeeded = source.CoresNeeded;
     59        target.DateCalculated = source.DateCalculated;
     60        target.DateCreated = source.DateCreated;
     61        target.DateFinished = source.DateFinished;
     62        target.Exception = source.Exception;
     63        target.ExecutionTime = source.ExecutionTime;
     64        target.MemoryNeeded = source.MemoryNeeded;
     65        target.ParentJobId = source.ParentJobId;
     66        target.Priority = source.Priority;
     67        target.ProjectId = source.ProjectId;
     68        target.SlaveId = source.SlaveId;
     69        target.JobState = source.JobState;
     70        target.UserId = source.UserId;
    4371      }
    4472    }
     
    4876    public static DT.JobData ToDto(JobData source) {
    4977      if (source == null) return null;
    50       return new DT.JobData { JobId = source.JobId };// todo
     78      return new DT.JobData { JobId = source.JobId, Data = source.Data.ToArray() };
    5179    }
    5280    public static JobData ToEntity(DT.JobData source) {
    5381      if (source == null) return null;
    54       return new JobData { JobId = source.Id };// todo
     82      var entity = new JobData(); ToEntity(source, entity);
     83      return entity;
    5584    }
    5685    public static void ToEntity(DT.JobData source, JobData target) {
    5786      if ((source != null) && (target != null)) {
    58         target.JobId = source.Id;// todo
     87        target.JobId = source.JobId; target.Data = new Binary(source.Data);
    5988      }
    6089    }
    6190    #endregion
    62    
     91
    6392    #region HiveExperiment
    6493    public static DT.HiveExperiment ToDto(HiveExperiment source) {
    6594      if (source == null) return null;
    66       return new DT.HiveExperiment { Id = source.HiveExperimentId };// todo
     95      return new DT.HiveExperiment { Id = source.HiveExperimentId, Description = source.Description, Name = source.Name, RootJobId = source.RootJobId, UserId = source.UserId };
    6796    }
    6897    public static HiveExperiment ToEntity(DT.HiveExperiment source) {
    6998      if (source == null) return null;
    70       return new HiveExperiment { HiveExperimentId = source.Id };// todo
     99      var entity = new HiveExperiment(); ToEntity(source, entity);
     100      return entity;
    71101    }
    72102    public static void ToEntity(DT.HiveExperiment source, HiveExperiment target) {
    73103      if ((source != null) && (target != null)) {
    74         target.HiveExperimentId = source.Id;// todo
     104        target.HiveExperimentId = source.Id; target.Description = source.Description; target.Name = source.Name; target.RootJobId = source.RootJobId; target.UserId = source.UserId;
    75105      }
    76106    }
     
    80110    public static DT.Slave ToDto(Slave source) {
    81111      if (source == null) return null;
    82       return new DT.Slave { Id = source.ResourceId };// todo
     112      return new DT.Slave { Id = source.ResourceId, CalendarSyncState = source.CalendarSyncState, Cores = source.Cores, CpuSpeed = source.CpuSpeed, FreeCores = source.FreeCores, FreeMemory = source.FreeMemory, IsAllowedToCalculate = source.IsAllowedToCalculate, Memory = source.Memory, Name = source.Name, SlaveConfigId = source.SlaveConfigId, SlaveState = source.SlaveState };
    83113    }
    84114    public static Slave ToEntity(DT.Slave source) {
    85115      if (source == null) return null;
    86       return new Slave { ResourceId = source.Id };// todo
     116      var entity = new Slave(); ToEntity(source, entity);
     117      return entity;
    87118    }
    88119    public static void ToEntity(DT.Slave source, Slave target) {
    89120      if ((source != null) && (target != null)) {
    90         target.ResourceId = source.Id;// todo
     121        target.ResourceId = source.Id; target.CalendarSyncState = source.CalendarSyncState; target.Cores = source.Cores; target.CpuSpeed = source.CpuSpeed; target.FreeCores = source.FreeCores; target.FreeMemory = source.FreeMemory; target.IsAllowedToCalculate = source.IsAllowedToCalculate; target.Memory = source.Memory; target.Name = source.Name; target.SlaveConfigId = source.SlaveConfigId; target.SlaveState = source.SlaveState;
    91122      }
    92123    }
     
    96127    public static DT.SlaveGroup ToDto(SlaveGroup source) {
    97128      if (source == null) return null;
    98       return new DT.SlaveGroup { Id = source.ResourceId };// todo
     129      return new DT.SlaveGroup { Id = source.ResourceId, Name = source.Name, ChildResourcesIds = source.SlaveGroup_Resources_Children.Select(x => x.ResourceId).ToList(), ParentResourcesIds = source.SlaveGroup_Resources_Parents.Select(x => x.ResourceId).ToList() };
    99130    }
    100131    public static SlaveGroup ToEntity(DT.SlaveGroup source) {
    101132      if (source == null) return null;
    102       return new SlaveGroup { ResourceId = source.Id };// todo
     133      var entity = new SlaveGroup(); ToEntity(source, entity);
     134      return entity;
    103135    }
    104136    public static void ToEntity(DT.SlaveGroup source, SlaveGroup target) {
    105137      if ((source != null) && (target != null)) {
    106         target.ResourceId = source.Id;// todo
     138        target.ResourceId = source.Id;
     139        target.Name = source.Name;
     140        //target.SlaveGroup_Resources_Children = // TODO: see how working with groups will work, then decide how to handle enumerations in here
     141        //target.SlaveGroup_Resources_Parents =
    107142      }
    108143    }
     
    112147    public static DT.Resource ToDto(Resource source) {
    113148      if (source == null) return null;
    114       return new DT.Resource { Id = source.ResourceId };// todo
     149      return new DT.Resource { Id = source.ResourceId, Name = source.Name };
    115150    }
    116151    public static Resource ToEntity(DT.Resource source) {
    117152      if (source == null) return null;
    118       return new Resource { ResourceId = source.Id };// todo
     153      var entity = new Resource(); ToEntity(source, entity);
     154      return entity;
    119155    }
    120156    public static void ToEntity(DT.Resource source, Resource target) {
    121157      if ((source != null) && (target != null)) {
    122         target.ResourceId = source.Id;// todo
     158        target.ResourceId = source.Id; target.Name = source.Name;
    123159      }
    124160    }
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HeuristicLab.Services.Hive.DataAccess-3.3.csproj

    r4629 r4649  
    6161  </ItemGroup>
    6262  <ItemGroup>
    63     <Compile Include="ContextFactory.cs" />
    6463    <Compile Include="Convert.cs" />
    6564    <Compile Include="HeuristicLabServicesHiveDataAccessPlugin.cs" />
     
    8281    </Compile>
    8382    <Compile Include="Tools\CreateHiveDatabaseApplication.cs" />
     83    <Compile Include="TransactionManager.cs" />
    8484  </ItemGroup>
    8585  <ItemGroup>
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDao.cs

    r4629 r4649  
    88  using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
    99  using HeuristicLab.Services.Hive.Common.DataTransfer;
     10  using HeuristicLab.Services.Hive.DataAccess.Properties;
    1011
    1112  public class HiveDao : IHiveDao {
    12     private IContextFactory<HiveDataContext> contextFactory;
    13     private DataAccess.HiveDataContext db { get { return contextFactory.CurrentContext; } }
    14 
    15     public HiveDao(IContextFactory<HiveDataContext> contextFactory) {
    16       this.contextFactory = contextFactory;
     13    public HiveDataContext CreateContext() {
     14      return new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString);
     15    }
     16
     17    public HiveDao() {
    1718    }
    1819
    1920    #region Job Methods
    2021    public DT.Job GetJob(Guid id) {
    21       return Convert.ToDto(db.Jobs.SingleOrDefault(x => x.JobId == id));
     22      using (var db = CreateContext()) {
     23        return Convert.ToDto(db.Jobs.SingleOrDefault(x => x.JobId == id));
     24      }
    2225    }
    2326
    2427    public IEnumerable<DT.Job> GetJobs(Expression<Func<Job, bool>> predicate) {
    25       return db.Jobs.Where(predicate).Select(x => Convert.ToDto(x));
     28      using (var db = CreateContext()) {
     29        return db.Jobs.Where(predicate).Select(x => Convert.ToDto(x)).ToArray();
     30      }
    2631    }
    2732
    2833    public Guid AddJob(DT.Job dto) {
    29       var entity = Convert.ToEntity(dto);
    30       db.Jobs.InsertOnSubmit(entity);
    31       db.SubmitChanges();
    32       return entity.JobId;
     34      using (var db = CreateContext()) {
     35        var entity = Convert.ToEntity(dto);
     36        db.Jobs.InsertOnSubmit(entity);
     37        db.SubmitChanges();
     38        return entity.JobId;
     39      }
    3340    }
    3441
    3542    public void UpdateJob(DT.Job dto) {
    36       var entity = db.Jobs.FirstOrDefault(x => x.JobId == dto.Id);
    37       if (entity == null) db.Jobs.InsertOnSubmit(Convert.ToEntity(dto));
    38       else Convert.ToEntity(dto, entity);
    39       db.SubmitChanges();
     43      using (var db = CreateContext()) {
     44        var entity = db.Jobs.FirstOrDefault(x => x.JobId == dto.Id);
     45        if (entity == null) db.Jobs.InsertOnSubmit(Convert.ToEntity(dto));
     46        else Convert.ToEntity(dto, entity);
     47        db.SubmitChanges();
     48      }
    4049    }
    4150
    4251    public void DeleteJob(Guid id) {
    43       var entity = db.Jobs.FirstOrDefault(x => x.JobId == id);
    44       if (entity != null) db.Jobs.DeleteOnSubmit(entity);
    45       db.SubmitChanges();
     52      using (var db = CreateContext()) {
     53        var entity = db.Jobs.FirstOrDefault(x => x.JobId == id);
     54        if (entity != null) db.Jobs.DeleteOnSubmit(entity);
     55        db.SubmitChanges();
     56      }
    4657    }
    4758
    4859    public IEnumerable<DT.Job> GetAvailableParentJobs(Guid slaveId) {
    49       // todo: slaveId is unused!
    50       var query = from ar in db.AssignedResources
    51                   where ar.Job.JobState == JobState.WaitForChildJobs &&
    52                     (from child in db.Jobs
    53                      where child.ParentJobId == ar.Job.JobId
    54                      select child.JobState == JobState.Finished).All(x => x) &&
    55                     (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet)
    56                      where child.ParentJobId == ar.Job.JobId
    57                      select child).Count() > 0
    58                   orderby ar.Job.Priority descending
    59                   select Convert.ToDto(ar.Job);
    60       return query;
     60      using (var db = CreateContext()) {
     61        // todo: slaveId is unused!
     62        var query = from ar in db.AssignedResources
     63                    where ar.Job.JobState == JobState.WaitingForChildJobs &&
     64                      (from child in db.Jobs
     65                       where child.ParentJobId == ar.Job.JobId
     66                       select child.JobState == JobState.Finished).All(x => x) &&
     67                      (from child in db.Jobs // avoid returning WaitForChildJobs jobs where no child-jobs exist (yet)
     68                       where child.ParentJobId == ar.Job.JobId
     69                       select child).Count() > 0
     70                    orderby ar.Job.Priority descending
     71                    select Convert.ToDto(ar.Job);
     72        return query;
     73      }
    6174    }
    6275
    6376    public IEnumerable<DT.Job> GetAvailableJobs(DT.Slave slave) {
    64       var query = from j in db.Jobs
    65                   where j.JobState == JobState.Waiting && j.CoresNeeded <= slave.FreeCores && j.MemoryNeeded <= slave.FreeMemory
    66                   orderby j.Priority descending
    67                   select Convert.ToDto(j);
    68       return query.Union(GetAvailableParentJobs(slave.Id)).OrderByDescending(x => x.Priority).ToArray();
     77      using (var db = CreateContext()) {
     78        var query = from j in db.Jobs
     79                    where j.JobState == JobState.Waiting && j.CoresNeeded <= slave.FreeCores && j.MemoryNeeded <= slave.FreeMemory
     80                    orderby j.Priority descending
     81                    select Convert.ToDto(j);
     82        return query.Union(GetAvailableParentJobs(slave.Id)).OrderByDescending(x => x.Priority).ToArray();
     83      }
    6984    }
    7085    #endregion
     
    7388
    7489    public DT.JobData GetJobData(Guid id) {
    75       return Convert.ToDto(db.JobDatas.SingleOrDefault(x => x.JobId == id));
     90      using (var db = CreateContext()) {
     91        return Convert.ToDto(db.JobDatas.SingleOrDefault(x => x.JobId == id));
     92      }
    7693    }
    7794
    7895    public IEnumerable<DT.JobData> GetJobDatas(Expression<Func<JobData, bool>> predicate) {
    79       return db.JobDatas.Where(predicate).Select(x => Convert.ToDto(x));
     96      using (var db = CreateContext()) {
     97        return db.JobDatas.Where(predicate).Select(x => Convert.ToDto(x)).ToArray();
     98      }
    8099    }
    81100
    82101    public Guid AddJobData(DT.JobData dto) {
    83       var entity = Convert.ToEntity(dto);
    84       db.JobDatas.InsertOnSubmit(entity);
    85       db.SubmitChanges();
    86       return entity.JobId;
     102      using (var db = CreateContext()) {
     103        var entity = Convert.ToEntity(dto);
     104        db.JobDatas.InsertOnSubmit(entity);
     105        db.SubmitChanges();
     106        return entity.JobId;
     107      }
    87108    }
    88109
    89110    public void UpdateJobData(DT.JobData dto) {
    90       var entity = db.JobDatas.FirstOrDefault(x => x.JobId == dto.Id);
    91       if (entity == null) db.JobDatas.InsertOnSubmit(Convert.ToEntity(dto));
    92       else Convert.ToEntity(dto, entity);
    93       db.SubmitChanges();
     111      using (var db = CreateContext()) {
     112        var entity = db.JobDatas.FirstOrDefault(x => x.JobId == dto.JobId);
     113        if (entity == null) db.JobDatas.InsertOnSubmit(Convert.ToEntity(dto));
     114        else Convert.ToEntity(dto, entity);
     115        db.SubmitChanges();
     116      }
    94117    }
    95118
    96119    public void DeleteJobData(Guid id) {
    97       var entity = db.JobDatas.FirstOrDefault(x => x.JobId == id); // check if all the byte[] is loaded into memory here. otherwise work around to delete without loading it
    98       if (entity != null) db.JobDatas.DeleteOnSubmit(entity);
    99       db.SubmitChanges();
     120      using (var db = CreateContext()) {
     121        var entity = db.JobDatas.FirstOrDefault(x => x.JobId == id); // check if all the byte[] is loaded into memory here. otherwise work around to delete without loading it
     122        if (entity != null) db.JobDatas.DeleteOnSubmit(entity);
     123        db.SubmitChanges();
     124      }
    100125    }
    101126    #endregion
     
    103128    #region HiveExperiment Methods
    104129    public DT.HiveExperiment GetHiveExperiment(Guid id) {
    105       return Convert.ToDto(db.HiveExperiments.SingleOrDefault(x => x.HiveExperimentId == id));
     130      using (var db = CreateContext()) {
     131        return Convert.ToDto(db.HiveExperiments.SingleOrDefault(x => x.HiveExperimentId == id));
     132      }
    106133    }
    107134
    108135    public IEnumerable<DT.HiveExperiment> GetHiveExperiments(Expression<Func<HiveExperiment, bool>> predicate) {
    109       return db.HiveExperiments.Where(predicate).Select(x => Convert.ToDto(x));
     136      using (var db = CreateContext()) {
     137        return db.HiveExperiments.Where(predicate).Select(x => Convert.ToDto(x)).ToArray();
     138      }
    110139    }
    111140
    112141    public Guid AddHiveExperiment(DT.HiveExperiment dto) {
    113       var entity = Convert.ToEntity(dto);
    114       db.HiveExperiments.InsertOnSubmit(entity);
    115       db.SubmitChanges();
    116       return entity.HiveExperimentId;
     142      using (var db = CreateContext()) {
     143        var entity = Convert.ToEntity(dto);
     144        db.HiveExperiments.InsertOnSubmit(entity);
     145        db.SubmitChanges();
     146        return entity.HiveExperimentId;
     147      }
    117148    }
    118149
    119150    public void UpdateHiveExperiment(DT.HiveExperiment dto) {
    120       var entity = db.HiveExperiments.FirstOrDefault(x => x.HiveExperimentId == dto.Id);
    121       if (entity == null) db.HiveExperiments.InsertOnSubmit(Convert.ToEntity(dto));
    122       else Convert.ToEntity(dto, entity);
    123       db.SubmitChanges();
     151      using (var db = CreateContext()) {
     152        var entity = db.HiveExperiments.FirstOrDefault(x => x.HiveExperimentId == dto.Id);
     153        if (entity == null) db.HiveExperiments.InsertOnSubmit(Convert.ToEntity(dto));
     154        else Convert.ToEntity(dto, entity);
     155        db.SubmitChanges();
     156      }
    124157    }
    125158
    126159    public void DeleteHiveExperiment(Guid id) {
    127       var entity = db.HiveExperiments.FirstOrDefault(x => x.HiveExperimentId == id);
    128       if (entity != null) db.HiveExperiments.DeleteOnSubmit(entity);
    129       db.SubmitChanges();
    130     }
    131     #endregion
    132 
     160      using (var db = CreateContext()) {
     161        var entity = db.HiveExperiments.FirstOrDefault(x => x.HiveExperimentId == id);
     162        if (entity != null) db.HiveExperiments.DeleteOnSubmit(entity);
     163        db.SubmitChanges();
     164      }
     165    }
     166    #endregion
    133167
    134168    #region Slave Methods
    135169    public DT.Slave GetSlave(Guid id) {
    136       return Convert.ToDto(db.Resources.OfType<Slave>().SingleOrDefault(x => x.ResourceId == id));
     170      using (var db = CreateContext()) {
     171        return Convert.ToDto(db.Resources.OfType<Slave>().SingleOrDefault(x => x.ResourceId == id));
     172      }
    137173    }
    138174
    139175    public IEnumerable<DT.Slave> GetSlaves(Expression<Func<Slave, bool>> predicate) {
    140       return db.Resources.OfType<Slave>().Where(predicate).Select(x => Convert.ToDto(x));
     176      using (var db = CreateContext()) {
     177        return db.Resources.OfType<Slave>().Where(predicate).Select(x => Convert.ToDto(x)).ToArray();
     178      }
    141179    }
    142180
    143181    public Guid AddSlave(DT.Slave dto) {
    144       var entity = Convert.ToEntity(dto);
    145       db.Resources.InsertOnSubmit(entity);
    146       db.SubmitChanges();
    147       return entity.ResourceId;
     182      using (var db = CreateContext()) {
     183        var entity = Convert.ToEntity(dto);
     184        db.Resources.InsertOnSubmit(entity);
     185        db.SubmitChanges();
     186        return entity.ResourceId;
     187      }
    148188    }
    149189
    150190    public void UpdateSlave(DT.Slave dto) {
    151       var entity = db.Resources.OfType<Slave>().FirstOrDefault(x => x.ResourceId == dto.Id);
    152       if (entity == null) db.Resources.InsertOnSubmit(Convert.ToEntity(dto));
    153       else Convert.ToEntity(dto, entity);
    154       db.SubmitChanges();
     191      using (var db = CreateContext()) {
     192        var entity = db.Resources.OfType<Slave>().FirstOrDefault(x => x.ResourceId == dto.Id);
     193        if (entity == null) db.Resources.InsertOnSubmit(Convert.ToEntity(dto));
     194        else Convert.ToEntity(dto, entity);
     195        db.SubmitChanges();
     196      }
    155197    }
    156198
    157199    public void DeleteSlave(Guid id) {
    158       var entity = db.Resources.OfType<Slave>().FirstOrDefault(x => x.ResourceId == id);
    159       if (entity != null) db.Resources.DeleteOnSubmit(entity);
    160       db.SubmitChanges();
     200      using (var db = CreateContext()) {
     201        var entity = db.Resources.OfType<Slave>().FirstOrDefault(x => x.ResourceId == id);
     202        if (entity != null) db.Resources.DeleteOnSubmit(entity);
     203        db.SubmitChanges();
     204      }
    161205    }
    162206    #endregion
     
    164208    #region SlaveGroup Methods
    165209    public DT.SlaveGroup GetSlaveGroup(Guid id) {
    166       return Convert.ToDto(db.Resources.OfType<SlaveGroup>().SingleOrDefault(x => x.ResourceId == id));
     210      using (var db = CreateContext()) {
     211        return Convert.ToDto(db.Resources.OfType<SlaveGroup>().SingleOrDefault(x => x.ResourceId == id));
     212      }
    167213    }
    168214
    169215    public IEnumerable<DT.SlaveGroup> GetSlaveGroups(Expression<Func<SlaveGroup, bool>> predicate) {
    170       return db.Resources.OfType<SlaveGroup>().Where(predicate).Select(x => Convert.ToDto(x));
     216      using (var db = CreateContext()) {
     217        return db.Resources.OfType<SlaveGroup>().Where(predicate).Select(x => Convert.ToDto(x)).ToArray();
     218      }
    171219    }
    172220
    173221    public Guid AddSlaveGroup(DT.SlaveGroup dto) {
    174       var entity = Convert.ToEntity(dto);
    175       db.Resources.InsertOnSubmit(entity);
    176       db.SubmitChanges();
    177       return entity.ResourceId;
     222      using (var db = CreateContext()) {
     223        var entity = Convert.ToEntity(dto);
     224        db.Resources.InsertOnSubmit(entity);
     225        db.SubmitChanges();
     226        return entity.ResourceId;
     227      }
    178228    }
    179229
    180230    public void UpdateSlaveGroup(DT.SlaveGroup dto) {
    181       var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == dto.Id);
    182       if (entity == null) db.Resources.InsertOnSubmit(Convert.ToEntity(dto));
    183       else Convert.ToEntity(dto, entity);
    184       db.SubmitChanges();
     231      using (var db = CreateContext()) {
     232        var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == dto.Id);
     233        if (entity == null) db.Resources.InsertOnSubmit(Convert.ToEntity(dto));
     234        else Convert.ToEntity(dto, entity);
     235        db.SubmitChanges();
     236      }
    185237    }
    186238
    187239    public void DeleteSlaveGroup(Guid id) {
    188       var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == id);
    189       if (entity != null) db.Resources.DeleteOnSubmit(entity);
    190       db.SubmitChanges();
     240      using (var db = CreateContext()) {
     241        var entity = db.Resources.OfType<SlaveGroup>().FirstOrDefault(x => x.ResourceId == id);
     242        if (entity != null) db.Resources.DeleteOnSubmit(entity);
     243        db.SubmitChanges();
     244      }
    191245    }
    192246    #endregion
     
    194248    #region Resource Methods
    195249    public DT.Resource GetResource(Guid id) {
    196       return Convert.ToDto(db.Resources.SingleOrDefault(x => x.ResourceId == id));
     250      using (var db = CreateContext()) {
     251        return Convert.ToDto(db.Resources.SingleOrDefault(x => x.ResourceId == id));
     252      }
    197253    }
    198254
    199255    public IEnumerable<DT.Resource> GetResources(Expression<Func<Resource, bool>> predicate) {
    200       return db.Resources.Where(predicate).Select(x => Convert.ToDto(x));
     256      using (var db = CreateContext()) {
     257        return db.Resources.Where(predicate).Select(x => Convert.ToDto(x)).ToArray();
     258      }
    201259    }
    202260
    203261    public Guid AddResource(DT.Resource dto) {
    204       var entity = Convert.ToEntity(dto);
    205       db.Resources.InsertOnSubmit(entity);
    206       db.SubmitChanges();
    207       return entity.ResourceId;
     262      using (var db = CreateContext()) {
     263        var entity = Convert.ToEntity(dto);
     264        db.Resources.InsertOnSubmit(entity);
     265        db.SubmitChanges();
     266        return entity.ResourceId;
     267      }
    208268    }
    209269
    210270    public void UpdateResource(DT.Resource dto) {
    211       var entity = db.Resources.FirstOrDefault(x => x.ResourceId == dto.Id);
    212       if (entity == null) db.Resources.InsertOnSubmit(Convert.ToEntity(dto));
    213       else Convert.ToEntity(dto, entity);
    214       db.SubmitChanges();
     271      using (var db = CreateContext()) {
     272        var entity = db.Resources.FirstOrDefault(x => x.ResourceId == dto.Id);
     273        if (entity == null) db.Resources.InsertOnSubmit(Convert.ToEntity(dto));
     274        else Convert.ToEntity(dto, entity);
     275        db.SubmitChanges();
     276      }
    215277    }
    216278
    217279    public void DeleteResource(Guid id) {
    218       var entity = db.Resources.FirstOrDefault(x => x.ResourceId == id);
    219       if (entity != null) db.Resources.DeleteOnSubmit(entity);
    220       db.SubmitChanges();
     280      using (var db = CreateContext()) {
     281        var entity = db.Resources.FirstOrDefault(x => x.ResourceId == id);
     282        if (entity != null) db.Resources.DeleteOnSubmit(entity);
     283        db.SubmitChanges();
     284      }
    221285    }
    222286    #endregion
     
    224288    #region Authorization Methods
    225289    public bool IsUserAuthorizedForJobs(Guid userId, params Guid[] jobIds) {
    226       var userIds = from job in db.Jobs // this needs to be fast!
    227                     where jobIds.Contains(job.JobId)
    228                     select job.UserId;
    229       return userIds.All(x => x == userId);
    230     }
    231     #endregion
    232 
    233 
     290      using (var db = CreateContext()) {
     291        var userIds = from job in db.Jobs // this needs to be fast!
     292                      where jobIds.Contains(job.JobId)
     293                      select job.UserId;
     294        return userIds.All(x => x == userId);
     295      }
     296    }
     297    #endregion
    234298  }
    235299}
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml

    r4615 r4649  
    7070      <Association Name="Resource_UptimeCalendar" Member="UptimeCalendars" ThisKey="ResourceId" OtherKey="ResourceId" Type="UptimeCalendar" />
    7171      <Type Name="Slave" InheritanceCode="Slave" IsInheritanceDefault="true">
    72         <Column Name="CPUSpeed" Type="System.Int32" DbType="Int" CanBeNull="true" />
     72        <Column Name="CpuSpeed" Storage="_CPUSpeed" Type="System.Int32" DbType="Int" CanBeNull="true" />
    7373        <Column Name="Memory" Type="System.Int32" DbType="Int" CanBeNull="true" />
    7474        <Column Name="Login" Type="System.DateTime" DbType="DateTime" CanBeNull="true" />
    75         <Column Name="Status" Type="System.String" DbType="VarChar(MAX)" CanBeNull="true" />
    76         <Column Name="CalendarSyncStatus" Type="System.String" DbType="VarChar(MAX)" CanBeNull="true" />
     75        <Column Name="SlaveState" Storage="_Status" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.SlaveState" DbType="VarChar(15)" CanBeNull="true" />
     76        <Column Name="CalendarSyncState" Storage="_CalendarSyncStatus" Type="global::HeuristicLab.Services.Hive.Common.DataTransfer.CalendarState" DbType="VarChar(MAX)" CanBeNull="true" />
    7777        <Column Name="UseCalendarFromResourceId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    7878        <Column Name="SlaveConfigId" Type="System.Guid" DbType="UniqueIdentifier" CanBeNull="true" />
    79         <Column Name="NumberOfCores" Type="System.Int32" DbType="Int" CanBeNull="true" />
    80         <Column Name="NumberOfFreeCores" Type="System.Int32" DbType="Int" CanBeNull="true" />
     79        <Column Name="Cores" Storage="_NumberOfCores" Type="System.Int32" DbType="Int" CanBeNull="true" />
     80        <Column Name="FreeCores" Storage="_NumberOfFreeCores" Type="System.Int32" DbType="Int" CanBeNull="true" />
    8181        <Column Name="FreeMemory" Type="System.Int32" DbType="Int" CanBeNull="true" />
    8282        <Column Name="IsAllowedToCalculate" Type="System.Boolean" DbType="Bit" CanBeNull="false" />
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs

    r4615 r4649  
    15691569    private System.Nullable<System.DateTime> _Login;
    15701570   
    1571     private string _Status;
    1572    
    1573     private string _CalendarSyncStatus;
     1571    private global::HeuristicLab.Services.Hive.Common.DataTransfer.SlaveState _Status;
     1572   
     1573    private global::HeuristicLab.Services.Hive.Common.DataTransfer.CalendarState _CalendarSyncStatus;
    15741574   
    15751575    private System.Nullable<System.Guid> _UseCalendarFromResourceId;
     
    15951595    partial void OnValidate(System.Data.Linq.ChangeAction action);
    15961596    partial void OnCreated();
    1597     partial void OnCPUSpeedChanging(System.Nullable<int> value);
    1598     partial void OnCPUSpeedChanged();
     1597    partial void OnCpuSpeedChanging(System.Nullable<int> value);
     1598    partial void OnCpuSpeedChanged();
    15991599    partial void OnMemoryChanging(System.Nullable<int> value);
    16001600    partial void OnMemoryChanged();
    16011601    partial void OnLoginChanging(System.Nullable<System.DateTime> value);
    16021602    partial void OnLoginChanged();
    1603     partial void OnStatusChanging(string value);
    1604     partial void OnStatusChanged();
    1605     partial void OnCalendarSyncStatusChanging(string value);
    1606     partial void OnCalendarSyncStatusChanged();
     1603    partial void OnSlaveStateChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.SlaveState value);
     1604    partial void OnSlaveStateChanged();
     1605    partial void OnCalendarSyncStateChanging(global::HeuristicLab.Services.Hive.Common.DataTransfer.CalendarState value);
     1606    partial void OnCalendarSyncStateChanged();
    16071607    partial void OnUseCalendarFromResourceIdChanging(System.Nullable<System.Guid> value);
    16081608    partial void OnUseCalendarFromResourceIdChanged();
    16091609    partial void OnSlaveConfigIdChanging(System.Nullable<System.Guid> value);
    16101610    partial void OnSlaveConfigIdChanged();
    1611     partial void OnNumberOfCoresChanging(System.Nullable<int> value);
    1612     partial void OnNumberOfCoresChanged();
    1613     partial void OnNumberOfFreeCoresChanging(System.Nullable<int> value);
    1614     partial void OnNumberOfFreeCoresChanged();
     1611    partial void OnCoresChanging(System.Nullable<int> value);
     1612    partial void OnCoresChanged();
     1613    partial void OnFreeCoresChanging(System.Nullable<int> value);
     1614    partial void OnFreeCoresChanged();
    16151615    partial void OnFreeMemoryChanging(System.Nullable<int> value);
    16161616    partial void OnFreeMemoryChanged();
     
    16281628   
    16291629    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CPUSpeed", DbType="Int")]
    1630     public System.Nullable<int> CPUSpeed
     1630    public System.Nullable<int> CpuSpeed
    16311631    {
    16321632      get
     
    16381638        if ((this._CPUSpeed != value))
    16391639        {
    1640           this.OnCPUSpeedChanging(value);
     1640          this.OnCpuSpeedChanging(value);
    16411641          this.SendPropertyChanging();
    16421642          this._CPUSpeed = value;
    1643           this.SendPropertyChanged("CPUSpeed");
    1644           this.OnCPUSpeedChanged();
     1643          this.SendPropertyChanged("CpuSpeed");
     1644          this.OnCpuSpeedChanged();
    16451645        }
    16461646      }
     
    16871687    }
    16881688   
    1689     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Status", DbType="VarChar(MAX)")]
    1690     public string Status
     1689    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Status", DbType="VarChar(15)", CanBeNull=true)]
     1690    public global::HeuristicLab.Services.Hive.Common.DataTransfer.SlaveState SlaveState
    16911691    {
    16921692      get
     
    16981698        if ((this._Status != value))
    16991699        {
    1700           this.OnStatusChanging(value);
     1700          this.OnSlaveStateChanging(value);
    17011701          this.SendPropertyChanging();
    17021702          this._Status = value;
    1703           this.SendPropertyChanged("Status");
    1704           this.OnStatusChanged();
    1705         }
    1706       }
    1707     }
    1708    
    1709     [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CalendarSyncStatus", DbType="VarChar(MAX)")]
    1710     public string CalendarSyncStatus
     1703          this.SendPropertyChanged("SlaveState");
     1704          this.OnSlaveStateChanged();
     1705        }
     1706      }
     1707    }
     1708   
     1709    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CalendarSyncStatus", DbType="VarChar(MAX)", CanBeNull=true)]
     1710    public global::HeuristicLab.Services.Hive.Common.DataTransfer.CalendarState CalendarSyncState
    17111711    {
    17121712      get
     
    17181718        if ((this._CalendarSyncStatus != value))
    17191719        {
    1720           this.OnCalendarSyncStatusChanging(value);
     1720          this.OnCalendarSyncStateChanging(value);
    17211721          this.SendPropertyChanging();
    17221722          this._CalendarSyncStatus = value;
    1723           this.SendPropertyChanged("CalendarSyncStatus");
    1724           this.OnCalendarSyncStatusChanged();
     1723          this.SendPropertyChanged("CalendarSyncState");
     1724          this.OnCalendarSyncStateChanged();
    17251725        }
    17261726      }
     
    17721772   
    17731773    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_NumberOfCores", DbType="Int")]
    1774     public System.Nullable<int> NumberOfCores
     1774    public System.Nullable<int> Cores
    17751775    {
    17761776      get
     
    17821782        if ((this._NumberOfCores != value))
    17831783        {
    1784           this.OnNumberOfCoresChanging(value);
     1784          this.OnCoresChanging(value);
    17851785          this.SendPropertyChanging();
    17861786          this._NumberOfCores = value;
    1787           this.SendPropertyChanged("NumberOfCores");
    1788           this.OnNumberOfCoresChanged();
     1787          this.SendPropertyChanged("Cores");
     1788          this.OnCoresChanged();
    17891789        }
    17901790      }
     
    17921792   
    17931793    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_NumberOfFreeCores", DbType="Int")]
    1794     public System.Nullable<int> NumberOfFreeCores
     1794    public System.Nullable<int> FreeCores
    17951795    {
    17961796      get
     
    18021802        if ((this._NumberOfFreeCores != value))
    18031803        {
    1804           this.OnNumberOfFreeCoresChanging(value);
     1804          this.OnFreeCoresChanging(value);
    18051805          this.SendPropertyChanging();
    18061806          this._NumberOfFreeCores = value;
    1807           this.SendPropertyChanged("NumberOfFreeCores");
    1808           this.OnNumberOfFreeCoresChanged();
     1807          this.SendPropertyChanged("FreeCores");
     1808          this.OnFreeCoresChanged();
    18091809        }
    18101810      }
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/HeuristicLab.Services.Hive.DataAccess/3.3/Tools/CreateHiveDatabaseApplication.cs

    r4629 r4649  
    2727
    2828    public override void Run() {
    29       CreateDataContext<HiveDataContext> contextCreator = new CreateDataContext<HiveDataContext>(ContextFactory<HiveDataContext>.CreateHiveContext);
    30       IContextFactory<HiveDataContext> contextFactory = new ContextFactory<HiveDataContext>(contextCreator);
    31 
    32       using (contextFactory.GetContext(false)) {
    33         if (contextFactory.CurrentContext.DatabaseExists())
    34           contextFactory.CurrentContext.DeleteDatabase();
    35         contextFactory.CurrentContext.CreateDatabase();
     29      var dao = new HiveDao();
     30      using (var db = dao.CreateContext()) {
     31        if (db.DatabaseExists())
     32          db.DeleteDatabase();
     33        db.CreateDatabase();
    3634      }
    3735    }
  • branches/HeuristicLab.Hive/sources/HeuristicLab.Hive.New/MergeConfigs.cmd

    r4629 r4649  
    66copy "%SolutionDir%HeuristicLab 3.3.exe.config" "%TargetDir%"
    77
    8 %SolutionDir%ConfigMerger "%SolutionDir%HeuristicLab.Hive-3.3.dll.config" "HeuristicLab 3.3.exe.config"
    9 
    10 copy "HeuristicLab 3.3.exe.config" "%target%"
     8%SolutionDir%ConfigMerger "%TargetDir%HeuristicLab.Hive-3.3.dll.config" "%TargetDir%HeuristicLab 3.3.exe.config"
     9copy "%TargetDir%HeuristicLab 3.3.exe.config" "asdf.config"
     10copy "%TargetDir%HeuristicLab 3.3.exe.config" "%target%"
Note: See TracChangeset for help on using the changeset viewer.