-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTechnology.cs
79 lines (76 loc) · 2.77 KB
/
Technology.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
namespace NonPersistentObjectsDemo.Module.BusinessObjects {
[DomainComponent]
public class Technology : NonPersistentBaseObject, IAssignable<Technology> {
public Technology() : base() { }
public Technology(Guid oid) : base(oid) { }
private string _Name;
public string Name {
get { return _Name; }
set { SetPropertyValue<string>(ref _Name, value); }
}
private string _Description;
[FieldSize(FieldSizeAttribute.Unlimited)]
public string Description {
get { return _Description; }
set { SetPropertyValue<string>(ref _Description, value); }
}
public void Assign(Technology source) {
Name = source.Name;
Description = source.Description;
}
}
class NPTechnologyAdapter : NonPersistentObjectAdapter<Technology, Guid> {
private static Dictionary<Guid, Technology> storage;
static NPTechnologyAdapter() {
storage = new Dictionary<Guid, Technology>();
}
public NPTechnologyAdapter(NonPersistentObjectSpace npos) : base(npos) { }
protected override Technology LoadObjectByKey(Guid key) {
Technology result = null;
Technology objData;
if(storage.TryGetValue(key, out objData)) {
result = new Technology(key);
result.Assign(objData);
}
return result;
}
protected override Technology ReloadObject(Technology obj) {
Technology objData = LoadData(obj.Oid);
obj.Assign(objData);
return obj;
}
protected override void CommitChanges(List<Technology> objects) {
foreach(var obj in objects) {
Technology objData;
if(ObjectSpace.IsDeletedObject(obj)) {
storage.Remove(obj.Oid);
}
else if(ObjectSpace.IsNewObject(obj)) {
objData = new Technology(obj.Oid);
objData.Assign(obj);
storage.Add(obj.Oid, objData);
}
else {
objData = LoadData(obj.Oid);
objData.Assign(obj);
}
}
}
private Technology LoadData(Guid key) {
Technology objData;
if(!storage.TryGetValue(key, out objData)) {
throw new InvalidOperationException("Object is not found in the storage.");
}
return objData;
}
}
}