Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/08/09 12:48:18 (15 years ago)
Author:
gkronber
Message:

Merged change sets from CEDMA branch to trunk:

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Core/DataSet.cs

    r957 r1287  
    3030
    3131namespace HeuristicLab.CEDMA.Core {
    32   public class DataSet {
     32  public class DataSet : IViewable {
    3333    public IStore Store { get; set; }
    34     public long Id { get; set; }
    35     public string Name { get; set; }
     34
     35    private Guid guid;
     36    public Guid Guid {
     37      get { return guid; }
     38    }
     39
     40    private string name;
     41    public string Name {
     42      get { return name; }
     43      set { name = value; }
     44    }
     45
    3646    private Problem problem;
    37 
    3847    public Problem Problem {
    39       get { return problem; }
     48      get {
     49        // lazy loading of problem from DB
     50        if (problem == null) {
     51          //var serializedDataVar = new HeuristicLab.CEDMA.DB.Interfaces.Variable("SerializedData");
     52          //var persistedData = Store.Query(
     53          //  new Statement[] { new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, serializedDataVar)});
     54          var persistedData = Store.Query(
     55            "<" + Ontology.CedmaNameSpace + Guid + "> <" + Ontology.PredicateSerializedData.Uri + "> ?SerializedData .");
     56          if (persistedData.Count() == 1) {
     57            Literal persistedLiteral = (Literal)persistedData.First().Get("SerializedData");
     58            this.problem = (Problem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String((string)persistedLiteral.Value));
     59          } else
     60            this.problem = new Problem(); // no entry in the DB => create a new problem
     61        }
     62        return problem;
     63      }
    4064    }
    4165
    4266    public DataSet()
    4367      : base() {
    44       problem = new Problem();
     68      guid = Guid.NewGuid();
     69      name = "Data set";
    4570    }
    4671
    47     public DataSet(IStore store, long id)
     72    public DataSet(IStore store, Entity dataSetEntity)
    4873      : this() {
    4974      Store = store;
    50       Id = id;
    51     }
    52 
    53     public void Save() {
    54       throw new NotImplementedException();
     75      guid = new Guid(dataSetEntity.Uri.Remove(0, Ontology.CedmaNameSpace.Length));
     76      name = guid.ToString();
    5577    }
    5678
    5779    public void Activate() {
    58       throw new NotImplementedException();
    59     }
    60 
    61     private void UpdateDataSet(long Id, byte[] p) {
    62       throw new NotImplementedException();
     80      Entity myEntity = new Entity(Ontology.CedmaNameSpace + Guid);
     81      Store.Add(new Statement(myEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet));
     82      Store.Add(new Statement(myEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(PersistenceManager.SaveToGZip(problem)))));
     83      Store.Add(new Statement(myEntity, Ontology.PredicateName, new Literal(name)));
    6384    }
    6485
     
    6687      return new DataSetView(this);
    6788    }
     89
     90    internal Results GetResults() {
     91      Results results = new Results(Store);
     92      results.FilterDataSet(new Entity(Ontology.CedmaNameSpace + Guid));
     93      return results;
     94    }
    6895  }
    6996}
Note: See TracChangeset for help on using the changeset viewer.