blob: 6b0e459eb24dfd6d1db8e2bf125e6820920de06c (
plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Tango.Core;
using Tango.DAL.Remote.DB;
using Tango.Settings;
namespace Tango.DAL.Observables
{
public class ObservablesEntitiesAdapter : ExtendedObject
{
private static ObservablesEntitiesAdapter _instance;
public static ObservablesEntitiesAdapter Instance
{
get
{
if (_instance == null)
{
_instance = new ObservablesEntitiesAdapter();
}
return _instance;
}
}
public RemoteDB Context { get; private set; }
public static implicit operator DbContext(ObservablesEntitiesAdapter instance)
{
return instance.Context;
}
private ObservablesEntitiesAdapter()
{
Context = new RemoteDB(SettingsManager.Default.DataBase.SQLServerAddress, false);
Invalidate();
}
public void SaveChanges()
{
Context.SaveChanges();
Invalidate();
}
public void Invalidate()
{
LoadedObjectsService.Reset();
Organizations = Context.ORGANIZATIONS.Where(x => !x.DELETED).ToList().Select(x => ObservableEntity.CreateObservableFromEntity<Organization>(x)).ToObservableCollection();
OrganizationsViewSource = CreateCollectionView(Organizations);
Machines = Context.MACHINES.Where(x => !x.DELETED).ToList().Select(x => ObservableEntity.CreateObservableFromEntity<Machine>(x)).ToObservableCollection();
foreach (var machine in Machines)
{
machine.MachinesConfigurations = machine.MachinesConfigurations.OrderByDescending(x => x.LastUpdated).ToObservableCollection();
}
MachineVersions = Context.MACHINE_VERSIONS.Where(x => !x.DELETED).ToList().OrderBy(x => x.VERSION).Select(x => ObservableEntity.CreateObservableFromEntity<MachineVersion>(x)).ToObservableCollection();
Addresses = Context.ADDRESSES.Where(x => !x.DELETED).ToList().OrderBy(x => x.ADDRESS_STRING).Select(x => ObservableEntity.CreateObservableFromEntity<Address>(x)).ToObservableCollection();
Contacts = Context.CONTACTS.Where(x => !x.DELETED).ToList().OrderBy(x => x.FULL_NAME).Select(x => ObservableEntity.CreateObservableFromEntity<Contact>(x)).ToObservableCollection();
Users = Context.USERS.Where(x => !x.DELETED).ToList().OrderBy(x => x.CONTACT.FULL_NAME).Select(x => ObservableEntity.CreateObservableFromEntity<User>(x)).ToObservableCollection();
Roles = Context.ROLES.Where(x => !x.DELETED).ToList().OrderBy(x => x.NAME).Select(x => ObservableEntity.CreateObservableFromEntity<Role>(x)).ToObservableCollection();
}
private ObservableCollection<Organization> _organizations;
public ObservableCollection<Organization> Organizations
{
get { return _organizations; }
set { _organizations = value; RaisePropertyChangedAuto(); }
}
private ICollectionView _organizationsViewSource;
public ICollectionView OrganizationsViewSource
{
get { return _organizationsViewSource; }
set { _organizationsViewSource = value; RaisePropertyChangedAuto(); }
}
private ObservableCollection<Machine> _machines;
public ObservableCollection<Machine> Machines
{
get { return _machines; }
set
{
_machines = value; RaisePropertyChangedAuto();
}
}
private ObservableCollection<MachineVersion> _machineVersions;
public ObservableCollection<MachineVersion> MachineVersions
{
get { return _machineVersions; }
set { _machineVersions = value; RaisePropertyChangedAuto(); }
}
private ObservableCollection<Address> _addresses;
public ObservableCollection<Address> Addresses
{
get { return _addresses; }
set { _addresses = value; RaisePropertyChangedAuto(); }
}
private ObservableCollection<Contact> _contacts;
public ObservableCollection<Contact> Contacts
{
get { return _contacts; }
set { _contacts = value; RaisePropertyChangedAuto(); }
}
private ObservableCollection<User> _users;
public ObservableCollection<User> Users
{
get { return _users; }
set { _users = value; RaisePropertyChangedAuto(); }
}
private ObservableCollection<Role> _roles;
public ObservableCollection<Role> Roles
{
get { return _roles; }
set { _roles = value; RaisePropertyChangedAuto(); }
}
private ICollectionView CreateCollectionView<T>(ObservableCollection<T> collection)
{
var view = CollectionViewSource.GetDefaultView(collection);
return view;
}
}
}
|