aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/Entities/MachineVersion.cs
blob: 7b90623d8fd7f64ee58fc9716ee7345c3ae8c408 (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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reser
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Builders;
using Tango.BL.Serialization;

namespace Tango.BL.Entities
{
    public partial class MachineVersion : MachineVersionBase
    {
        public async Task ApplyPrototypeMachine(Machine machine, ObservablesContext context)
        {
            machine = await new MachineBuilder(context)
                .Set(machine)
                .WithOrganization()
                .WithConfiguration()
                .WithSpools()
                .WithCats()
                .BuildAsync();

            PrototypeMachineData = machine.ToJson(new EntitySerializationStrategy()
                .Include(() => machine.Configuration)
                .Ignore(() => machine.Name)
                .Ignore(() => machine.MachinesEvents)
                .Ignore(() => machine.Configuration.Machines)
                .Ignore(() => machine.Jobs)
                .Ignore(() => machine.SerialNumber)
                .Ignore(() => machine.DefaultRmlGuid)
                .Ignore(() => machine.DefaultColorSpaceGuid)
                .Ignore(() => machine.DefaultSpoolTypeGuid)
                .Ignore(() => machine.LoadedRmlGuid)
                .Ignore(() => machine.DeviceId)
                .Ignore(() => machine.DeviceName)
                .Ignore(() => machine.IsDeviceRegistered)
                .Ignore(() => machine.SiteGuid),
                
                EntitySerializationFlags.IgnoreGuids | EntitySerializationFlags.IgnoreReferenceTypes);
        }

        public async Task<Machine> CreatePrototypeMachine(ObservablesContext context)
        {
            Machine m = new Machine();

            String protoTypeData = (await context.MachineVersions.SingleOrDefaultAsync(x => x.Guid == Guid)).PrototypeMachineData;

            Machine machine = Machine.FromJson(protoTypeData, new EntitySerializationStrategy()
                .Include(() => m.Configuration)
                .Ignore(() => m.Name)
                .Ignore(() => m.MachinesEvents)
                .Ignore(() => m.Configuration.Machines)
                .Ignore(() => m.Jobs)
                .Ignore(() => m.SerialNumber)
                .Ignore(() => m.DefaultRmlGuid)
                .Ignore(() => m.DefaultColorSpaceGuid)
                .Ignore(() => m.DefaultSpoolTypeGuid)
                .Ignore(() => m.LoadedRmlGuid)
                .Ignore(() => m.DeviceId)
                .Ignore(() => m.DeviceName)
                .Ignore(() => m.IsDeviceRegistered)
                .Ignore(() => m.SiteGuid),

                EntitySerializationFlags.IgnoreGuids | EntitySerializationFlags.IgnoreReferenceTypes);


            machine.OrganizationGuid = null;
            machine.ConfigurationGuid = null;
            machine.ConfigurationGuid = machine.Configuration.Guid;


            foreach (var cat in machine.Cats)
            {
                cat.MachineGuid = machine.Guid;
            }

            machine.MachineVersionGuid = Guid;
            machine.ProductionDate = DateTime.UtcNow;

            foreach (var idsPack in machine.Configuration.IdsPacks)
            {
                idsPack.DispenserGuid = null;
                idsPack.ConfigurationGuid = machine.ConfigurationGuid;
            }

            foreach (var spool in machine.Spools)
            {
                spool.MachineGuid = machine.Guid;
            }

            machine.DefaultColorSpaceGuid = null;
            machine.DefaultRmlGuid = null;
            machine.DefaultSpoolTypeGuid = null;

            return machine;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MachineVersion" /> class.
        /// </summary>
        public MachineVersion() : base()
        {

        }
    }
}