using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations.Schema; 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())); } } #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; } /// /// Initializes a new instance of the class. /// public Machine() : base() { } } }