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 /// /// Gets or sets the property as a collection of . /// [NotMapped] [JsonIgnore] public List SupportedJobTypes { get { try { return TargetJobTypes.ToEnumValues(','); } catch (Exception ex) { LogManager.Log(ex, "Could not parse machine target job types!"); return new List(); } } set { TargetJobTypes = String.Join(",", value.Select(x => x.ToInt32())); } } /// /// Gets or sets the property as a collection of . /// [NotMapped] [JsonIgnore] public List SupportedColorSpaces { get { try { if (!String.IsNullOrWhiteSpace(TargetColorSpaceCodes)) { return TargetColorSpaceCodes.Split(',').Select(x => (ColorSpaces)int.Parse(x)).ToList(); } else { return new List(); } } catch (Exception ex) { LogManager.Log(ex, "Could not parse machine target color space codes!"); return new List(); } } set { TargetColorSpaceCodes = String.Join(",", value.Select(x => x.ToInt32())); } } /// /// Gets or sets the installed head on this machine. /// [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); } /// /// Initializes a new instance of the class. /// public Machine() : base() { } public async Task> GetSiteSpoolTypes(ObservablesContext db) { ObservableCollection spoolTypes = new ObservableCollection(); 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(); var standardSpool = await db.SpoolTypes.FirstOrDefaultAsync(x => x.Code == (int)BL.Enumerations.SpoolTypes.StandardSpool); if (standardSpool != null) { spoolTypes.Add(standardSpool); } } return spoolTypes; } } }