blob: 01e17cfdeae910206f9172e3fdb84e5f4d681765 (
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Enumerations;
using Tango.BL.Serialization;
namespace Tango.BL.Entities
{
public partial class Machine : MachineBase
{
#region Properties
/// <summary>
/// Gets or sets the <see cref="TargetJobTypes"/> property as a collection of <see cref="JobTypes"/>.
/// </summary>
[NotMapped]
[JsonIgnore]
public List<JobTypes> SupportedJobTypes
{
get
{
try
{
return TargetJobTypes.ToEnumValues<JobTypes>(',');
}
catch (Exception ex)
{
LogManager.Log(ex, "Could not parse machine target job types!");
return new List<JobTypes>();
}
}
set
{
TargetJobTypes = String.Join(",", value.Select(x => x.ToInt32()));
}
}
/// <summary>
/// Gets or sets the <see cref="TargetColorSpaceCodes"/> property as a collection of <see cref="ColorSpaces"/>.
/// </summary>
[NotMapped]
[JsonIgnore]
public List<ColorSpaces> SupportedColorSpaces
{
get
{
try
{
if (!String.IsNullOrWhiteSpace(TargetColorSpaceCodes))
{
return TargetColorSpaceCodes.Split(',').Select(x => (ColorSpaces)int.Parse(x)).ToList();
}
else
{
return new List<ColorSpaces>();
}
}
catch (Exception ex)
{
LogManager.Log(ex, "Could not parse machine target color space codes!");
return new List<ColorSpaces>();
}
}
set
{
TargetColorSpaceCodes = String.Join(",", value.Select(x => x.ToInt32()));
}
}
/// <summary>
/// Gets or sets the installed head on this machine.
/// </summary>
[NotMapped]
[JsonIgnore]
public HeadTypes MachineHeadType
{
get
{
return (HeadTypes)HeadType;
}
set
{
HeadType = value.ToInt32();
}
}
[NotMapped]
[JsonIgnore]
public MachineTypes Type
{
get
{
return (MachineTypes)MachineType;
}
set
{
MachineType = value.ToInt32();
}
}
#endregion
protected override void RaisePropertyChanged(string propName)
{
base.RaisePropertyChanged(propName);
if (propName == nameof(TargetJobTypes))
{
RaisePropertyChanged(nameof(SupportedJobTypes));
}
else if (propName == nameof(TargetColorSpaceCodes))
{
RaisePropertyChanged(nameof(SupportedColorSpaces));
}
}
public override void Save(ObservablesContext context)
{
foreach (var job in Jobs)
{
job.JobIndex = Jobs.IndexOf(job);
foreach (var segment in job.Segments)
{
//segment.SegmentIndex = job.Segments.IndexOf(segment);
foreach (var stop in segment.BrushStops)
{
foreach (var prop in typeof(BrushStop).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType == typeof(double)))
{
double value = (double)prop.GetValue(stop);
if (double.IsInfinity(value))
{
prop.SetValue(stop, 0d);
}
}
}
}
}
base.Save(context);
}
public override Machine Clone()
{
var cloned = base.Clone();
cloned.Cats = Cats.Select(x => x.Clone(cloned)).ToSynchronizedObservableCollection();
cloned.Configuration = Configuration.Clone();
cloned.ConfigurationGuid = cloned.Configuration.Guid;
cloned.Spools = Spools.Select(x => x.Clone(cloned)).ToSynchronizedObservableCollection();
return cloned;
}
protected override void OnVersionTagChanged(string versiontag)
{
if (versiontag == String.Empty)
{
_versiontag = null;
}
base.OnVersionTagChanged(versiontag);
}
/// <summary>
/// Initializes a new instance of the <see cref="Machine" /> class.
/// </summary>
public Machine() : base()
{
}
public async Task<ObservableCollection<SpoolType>> GetSiteSpoolTypes(ObservablesContext db)
{
ObservableCollection<SpoolType> spoolTypes = new ObservableCollection<SpoolType>();
spoolTypes = (await db.SitesSpoolTypes.Where(x => x.SiteGuid == SiteGuid).Include(x => x.SpoolType).Select(x => x.SpoolType).ToListAsync()).OrderBy(x => x.LastUpdated).ToObservableCollection();
if (spoolTypes.Count == 0)
{
spoolTypes = new ObservableCollection<SpoolType>();
var standardSpool = await db.SpoolTypes.FirstOrDefaultAsync(x => x.Code == (int)BL.Enumerations.SpoolTypes.StandardSpool);
if (standardSpool != null)
{
spoolTypes.Add(standardSpool);
}
}
return spoolTypes;
}
}
}
|