Пример #1
0
        public void CommonContainerTests()
        {
            var styles       = new AssembledStyles();
            var columnWidths = new FixedColumnWidths(new[] { 10 });
            var root1        = new RootBox(styles);
            var root2        = new RootBox(styles);

            VerifyCC(root1, root1, root1, root1, root1);
            VerifyCC(root2, root2, root2, root2, root2);
            var row1 = new RowBox(styles, columnWidths, false);
            var div1 = new DivBox(styles);

            root2.AddBox(row1);
            root1.AddBox(div1);
            VerifyCC(row1, row1, row1, row1, row1);
            VerifyCC(div1, div1, div1, div1, div1);
            VerifyCC(root1, div1, root1, root1, div1);
            VerifyCC(root2, row1, root2, root2, row1);
            var row2 = new RowBox(styles, columnWidths, false);
            var div2 = new DivBox(styles);

            root2.AddBox(row2);
            root1.AddBox(div2);
            VerifyCC(row1, row2, root2, row1, row2);
            VerifyCC(div1, div2, root1, div1, div2);
            var row3 = new RowBox(styles, columnWidths, false);
            var div3 = new DivBox(styles);

            row1.AddBox(row3);
            div1.AddBox(div3);
            VerifyCC(row1, row3, row1, row1, row3);
            VerifyCC(row2, row3, root2, row2, row1);
            VerifyCC(div1, div3, div1, div1, div3);
            VerifyCC(div2, div3, root1, div2, div1);
            var row4 = new RowBox(styles, columnWidths, false);
            var div4 = new DivBox(styles);

            row2.AddBox(row4);
            div2.AddBox(div4);
            VerifyCC(row3, row4, root2, row1, row2);
            VerifyCC(row1, row4, root2, row1, row2);
            VerifyCC(div3, div4, root1, div1, div2);
            VerifyCC(div1, div4, root1, div1, div2);
        }
Пример #2
0
		public void NestedRowsLayout()
		{
			var styles = new AssembledStyles();
			var box1 = new LayoutInfoRecorderBox(styles, Color.Red, 72000, 36000);
			var box2 = new LayoutInfoRecorderBox(styles, Color.Blue, 108000, 18000);
			var box3 = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
			var box4 = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
			var widths = new FixedColumnWidths(new[] {34, 67, 99});
			// pass widths to RowBox constructor
			var row1 = new RowBox(styles, widths, false);
			var row2 = new RowBox(styles, widths, false);
			row1.AddBox(box1);
			row1.AddBox(box2);
			row2.AddBox(box3);
			row2.AddBox(box4);
			RootBox root = new RootBox(styles);
			root.AddBox(row1);
			root.AddBox(row2);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			Assert.That(box1.LastLayoutInfo.MaxWidth, Is.EqualTo(34));
			Assert.That(box1.Height, Is.EqualTo(48));
			Assert.That(box2.Height, Is.EqualTo(24));
			Assert.That(box3.Height, Is.EqualTo(24));
			Assert.That(box4.Height, Is.EqualTo(24));
			Assert.That(root.Height, Is.EqualTo(48 + 24));
			Assert.That(box1.Left, Is.EqualTo(0));
			Assert.That(box2.Left, Is.EqualTo(96));
			Assert.That(box3.Left, Is.EqualTo(0));
			Assert.That(box4.Left, Is.EqualTo(96));
			Assert.That(row1.Top, Is.EqualTo(0));
			Assert.That(box1.Top, Is.EqualTo(0));
			Assert.That(box2.Top, Is.EqualTo(0));
			Assert.That(row2.Top, Is.EqualTo(48));
			Assert.That(box3.Top, Is.EqualTo(0));
			Assert.That(box4.Top, Is.EqualTo(0));
			Assert.That(box1.Width, Is.EqualTo(96));
			Assert.That(box2.Width, Is.EqualTo(144));
			Assert.That(box3.Width, Is.EqualTo(96));
			Assert.That(box4.Width, Is.EqualTo(96));
			Assert.That(root.Width, Is.EqualTo(96 + 144));

			// Now try changing the size of a block.
			MockSite site = new MockSite();
			root.Site = site;
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 120, 128);
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			box2.UpdateSize(144000, 36000);
			Assert.That(box2.Width, Is.EqualTo(96 * 2));
			Assert.That(box2.Height, Is.EqualTo(48));
			Assert.That(row1.Height, Is.EqualTo(48));
			Assert.That(root.Height, Is.EqualTo(72));
			Assert.That(root.Width, Is.EqualTo(96 * 3));
			// Since it got both wider and higher, we should invalidate at least the whole current size.
			var bigInvalidate = root.InvalidateRect;
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); // unchanged this time
			Assert.That(root.Width, Is.EqualTo(96 + 144)); // narrower box2 still determines it
			// Got narrower, at least the whole old invalidate rectangle should be invalidated.
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(72000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); // unchanged this time
			Assert.That(root.Width, Is.EqualTo(144 + 48)); // new smaller value
			// It got thinner. We want an optimized invalidate rectangle that does not
			// include the left boxes. But it must include the space at the right that the root box used to occupy.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (it's in the fixmap so its own Relayout does this);
			// the shrinkage area at the right of row2;
			// and the area computed because row2 moved.
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 48, 144); // old box2
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24); // shrinkage of row1
			// This is from the new left of div2 to its old right (old right was 48 + 48 + 24 + 24)
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

			site.RectsInvalidated.Clear();
			box2.UpdateSize(144000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); //  unchanged this time
			Assert.That(root.Width, Is.EqualTo(144 + 144)); // new larger value
			// It got wider. We want an optimized invalidate rectangle that does not
			// include the left boxes. But it must include the space at the right where the root box grew.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (it returns true from Relayout);
			// the growth area at the right of div2;
			// and the area computed because div2 moved.
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96); // new box2
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24); // new part of div1 occupied by box2
			// This is from the old left of div2 to its new right (48 + 96 + 24 + 24)
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
		}
Пример #3
0
		public void RowClippedPaint()
		{
			var styles = new AssembledStyles();
			var box1 = new FgBlockBox(styles, Color.Red, 36000, 72000);
			var box2 = new FgBlockBox(styles, Color.Blue, 18000, 108000);
			var box3 = new FgBlockBox(styles, Color.Orange, 18000, 72000);
			var box4 = new FgBlockBox(styles, Color.Orange, 18000, 72000);
			var widths = new FixedColumnWidths(new[] { 34, 67, 99, 46 });
			var row1 = new RowBox(styles, widths, false);
			row1.AddBox(box1);
			row1.AddBox(box2);
			row1.AddBox(box3);
			row1.AddBox(box4);
			RootBox root = new RootBox(styles);
			root.AddBox(row1);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			var rect1 = new Rectangle(0, 0, 48, 96);
			var rect2 = new Rectangle(0, 0, 24, 144);
			rect2.Offset(rect1.Right, 0);
			var rect3 = new Rectangle(0, 0, 24, 96);
			rect3.Offset(rect2.Right, 0);
			var rect4 = new Rectangle(0, 0, 24, 96);
			rect4.Offset(rect3.Right, 0);
			var paintRects = new[] { rect1, rect2, rect3, rect4 };
			VerifyPaint(root, new Rectangle(-1000, -1000, 2000, 2000), 0, 0, paintRects);
			// Clipping off the left part, but not the whole, of a box does not prevent drawing it.
			VerifyPaint(root, new Rectangle(10, -1000, -10 + rect4.Right - 10, 2000), 0, 0, paintRects);
			// Even clipping all but one pixel does not prevent drawing.
			VerifyPaint(root, new Rectangle(47, -1000, -47 + rect3.Right + 1, 2000), 0, 0, paintRects);
			// However if we clip a bit more we should draw less
			var middleTwo = new[] { rect2, rect3 };
			VerifyPaint(root, new Rectangle(48, -1000, -48 + rect3.Right - 2, 2000), 0, 0, middleTwo);
			// If the clip covers just a bit of the first box we paint just that.
			var firstOne = new[] { rect1 };
			VerifyPaint(root, new Rectangle(-1000, -1000, 1000 + 10, 2000), 0, 0, firstOne);
			// If the clip covers just a bit of the last box we paint just that.
			var lastOne = new[] { rect4 };
			VerifyPaint(root, new Rectangle(rect4.Right - 2, -1000, 1000, 2000), 0, 0, lastOne);
			// If the clip is entirely above the pile we draw nothing.
			VerifyPaint(root, new Rectangle(-1000, -1000, 990, 2000), 0, 0, null);
			// Likewise if entirely below.
			VerifyPaint(root, new Rectangle(rect4.Right + 10, -1000, 10, 2000), 0, 0, null);
			// Now try with simulated scrolling. Use a normal clip rectangle, but pretend the first two
			// and a bit boxes are scrolled off.
			var offset = rect2.Right + 10;
			var rect3Offset = rect3;
			rect3Offset.Offset(-offset, 0);
			var rect4Offset = rect4;
			rect4Offset.Offset(-offset, 0);
			var lastTwoOffset = new[] { rect3Offset, rect4Offset };
			VerifyPaint(root, new Rectangle(0, -1000, 200, 2000), offset, 0, lastTwoOffset);
		}
Пример #4
0
        public void NestedRowsLayout()
        {
            var styles = new AssembledStyles();
            var box1   = new LayoutInfoRecorderBox(styles, Color.Red, 72000, 36000);
            var box2   = new LayoutInfoRecorderBox(styles, Color.Blue, 108000, 18000);
            var box3   = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
            var box4   = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
            var widths = new FixedColumnWidths(new[] { 34, 67, 99 });
            // pass widths to RowBox constructor
            var row1 = new RowBox(styles, widths, false);
            var row2 = new RowBox(styles, widths, false);

            row1.AddBox(box1);
            row1.AddBox(box2);
            row2.AddBox(box3);
            row2.AddBox(box4);
            RootBox root = new RootBox(styles);

            root.AddBox(row1);
            root.AddBox(row2);
            LayoutInfo layoutArgs = MakeLayoutInfo();

            root.Layout(layoutArgs);
            Assert.That(box1.LastLayoutInfo.MaxWidth, Is.EqualTo(34));
            Assert.That(box1.Height, Is.EqualTo(48));
            Assert.That(box2.Height, Is.EqualTo(24));
            Assert.That(box3.Height, Is.EqualTo(24));
            Assert.That(box4.Height, Is.EqualTo(24));
            Assert.That(root.Height, Is.EqualTo(48 + 24));
            Assert.That(box1.Left, Is.EqualTo(0));
            Assert.That(box2.Left, Is.EqualTo(96));
            Assert.That(box3.Left, Is.EqualTo(0));
            Assert.That(box4.Left, Is.EqualTo(96));
            Assert.That(row1.Top, Is.EqualTo(0));
            Assert.That(box1.Top, Is.EqualTo(0));
            Assert.That(box2.Top, Is.EqualTo(0));
            Assert.That(row2.Top, Is.EqualTo(48));
            Assert.That(box3.Top, Is.EqualTo(0));
            Assert.That(box4.Top, Is.EqualTo(0));
            Assert.That(box1.Width, Is.EqualTo(96));
            Assert.That(box2.Width, Is.EqualTo(144));
            Assert.That(box3.Width, Is.EqualTo(96));
            Assert.That(box4.Width, Is.EqualTo(96));
            Assert.That(root.Width, Is.EqualTo(96 + 144));

            // Now try changing the size of a block.
            MockSite site = new MockSite();

            root.Site = site;
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 120, 128);

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            box2.UpdateSize(144000, 36000);
            Assert.That(box2.Width, Is.EqualTo(96 * 2));
            Assert.That(box2.Height, Is.EqualTo(48));
            Assert.That(row1.Height, Is.EqualTo(48));
            Assert.That(root.Height, Is.EqualTo(72));
            Assert.That(root.Width, Is.EqualTo(96 * 3));
            // Since it got both wider and higher, we should invalidate at least the whole current size.
            var bigInvalidate = root.InvalidateRect;

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             // unchanged this time
            Assert.That(root.Width, Is.EqualTo(96 + 144));             // narrower box2 still determines it
            // Got narrower, at least the whole old invalidate rectangle should be invalidated.
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(72000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             // unchanged this time
            Assert.That(root.Width, Is.EqualTo(144 + 48));             // new smaller value
            // It got thinner. We want an optimized invalidate rectangle that does not
            // include the left boxes. But it must include the space at the right that the root box used to occupy.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (it's in the fixmap so its own Relayout does this);
            // the shrinkage area at the right of row2;
            // and the area computed because row2 moved.
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 48, 144); // old box2
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24); // shrinkage of row1
            // This is from the new left of div2 to its old right (old right was 48 + 48 + 24 + 24)
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

            site.RectsInvalidated.Clear();
            box2.UpdateSize(144000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             //  unchanged this time
            Assert.That(root.Width, Is.EqualTo(144 + 144));            // new larger value
            // It got wider. We want an optimized invalidate rectangle that does not
            // include the left boxes. But it must include the space at the right where the root box grew.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (it returns true from Relayout);
            // the growth area at the right of div2;
            // and the area computed because div2 moved.
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96); // new box2
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24); // new part of div1 occupied by box2
            // This is from the old left of div2 to its new right (48 + 96 + 24 + 24)
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
        }
Пример #5
0
        public void RowClippedPaint()
        {
            var styles = new AssembledStyles();
            var box1   = new FgBlockBox(styles, Color.Red, 36000, 72000);
            var box2   = new FgBlockBox(styles, Color.Blue, 18000, 108000);
            var box3   = new FgBlockBox(styles, Color.Orange, 18000, 72000);
            var box4   = new FgBlockBox(styles, Color.Orange, 18000, 72000);
            var widths = new FixedColumnWidths(new[] { 34, 67, 99, 46 });
            var row1   = new RowBox(styles, widths, false);

            row1.AddBox(box1);
            row1.AddBox(box2);
            row1.AddBox(box3);
            row1.AddBox(box4);
            RootBox root = new RootBox(styles);

            root.AddBox(row1);
            LayoutInfo layoutArgs = MakeLayoutInfo();

            root.Layout(layoutArgs);
            var rect1 = new Rectangle(0, 0, 48, 96);
            var rect2 = new Rectangle(0, 0, 24, 144);

            rect2.Offset(rect1.Right, 0);
            var rect3 = new Rectangle(0, 0, 24, 96);

            rect3.Offset(rect2.Right, 0);
            var rect4 = new Rectangle(0, 0, 24, 96);

            rect4.Offset(rect3.Right, 0);
            var paintRects = new[] { rect1, rect2, rect3, rect4 };

            VerifyPaint(root, new Rectangle(-1000, -1000, 2000, 2000), 0, 0, paintRects);
            // Clipping off the left part, but not the whole, of a box does not prevent drawing it.
            VerifyPaint(root, new Rectangle(10, -1000, -10 + rect4.Right - 10, 2000), 0, 0, paintRects);
            // Even clipping all but one pixel does not prevent drawing.
            VerifyPaint(root, new Rectangle(47, -1000, -47 + rect3.Right + 1, 2000), 0, 0, paintRects);
            // However if we clip a bit more we should draw less
            var middleTwo = new[] { rect2, rect3 };

            VerifyPaint(root, new Rectangle(48, -1000, -48 + rect3.Right - 2, 2000), 0, 0, middleTwo);
            // If the clip covers just a bit of the first box we paint just that.
            var firstOne = new[] { rect1 };

            VerifyPaint(root, new Rectangle(-1000, -1000, 1000 + 10, 2000), 0, 0, firstOne);
            // If the clip covers just a bit of the last box we paint just that.
            var lastOne = new[] { rect4 };

            VerifyPaint(root, new Rectangle(rect4.Right - 2, -1000, 1000, 2000), 0, 0, lastOne);
            // If the clip is entirely above the pile we draw nothing.
            VerifyPaint(root, new Rectangle(-1000, -1000, 990, 2000), 0, 0, null);
            // Likewise if entirely below.
            VerifyPaint(root, new Rectangle(rect4.Right + 10, -1000, 10, 2000), 0, 0, null);
            // Now try with simulated scrolling. Use a normal clip rectangle, but pretend the first two
            // and a bit boxes are scrolled off.
            var offset      = rect2.Right + 10;
            var rect3Offset = rect3;

            rect3Offset.Offset(-offset, 0);
            var rect4Offset = rect4;

            rect4Offset.Offset(-offset, 0);
            var lastTwoOffset = new[] { rect3Offset, rect4Offset };

            VerifyPaint(root, new Rectangle(0, -1000, 200, 2000), offset, 0, lastTwoOffset);
        }
Пример #6
0
        public override async Task SendAsync(IConfigurationRoot root)
        {
            ModbusTcpManager.RebootModbusTcp = false;

            int iFrequency = 0;

            YamlBase.Modules.Where(c => c.Launcher == nameof(Communication.ModbusTcp)).Select(c => new
            {
                c.Frequency
            }).ToList().ForEach(c =>
            {
                iFrequency = c.Frequency;
            });

            List <MachineShell> MachineBoxes = new();

            root.GetSection(nameof(ModbusTcpTitle.MachineBox)).GetChildren().Select(c => new
            {
                machineNo  = c.GetValue <string>(nameof(ModbusTcpRoot.MachineNo)),
                production = c.GetValue <bool>(nameof(ModbusTcpRoot.Production)),
                disabled   = c.GetValue <bool>(nameof(ModbusTcpRoot.Disabled)),
                vesion     = c.GetValue <string>(nameof(ModbusTcpRoot.Version)),
                address    = c.GetValue <string>(nameof(ModbusTcpRoot.Address)),
                port       = c.GetValue <int>(nameof(ModbusTcpRoot.Port)),
                map        = c.GetSection(nameof(ModbusTcpRoot.Map)).GetChildren().Select(c => new
                {
                    disabled     = c.GetValue <bool>(nameof(ElementBox.Disabled)),
                    channel      = c.GetValue <string>(nameof(ElementBox.Channel)),
                    functionCode = c.GetValue <int>(nameof(ElementBox.FunctionCode)),
                    slaveAddress = c.GetValue <byte>(nameof(ElementBox.SlaveAddress)),
                    startAddress = c.GetValue <ushort>(nameof(ElementBox.StartAddress)),
                    Points       = c.GetSection(nameof(ElementBox.NumberOfPoints)).GetChildren().Select(c => new
                    {
                        pointNo    = c.GetValue <int>(nameof(Numberofpoint.PointNo)),
                        attribName = c.GetValue <string>(nameof(Numberofpoint.AttribName))
                    }).ToList()
                }).ToList()
            }).ToList().ForEach(c =>
            {
                if (c.disabled)
                {
                    return;
                }

                List <MessageBox> boxes = new();

                c.map.ForEach(c =>
                {
                    if (c.disabled)
                    {
                        return;
                    }

                    HostChannel Channel = c.channel switch
                    {
                        nameof(HostChannel.Status) => HostChannel.Status,
                        nameof(HostChannel.Parameter) => HostChannel.Parameter,
                        nameof(HostChannel.Production) => HostChannel.Production,
                        _ => HostChannel.Undefined
                    };

                    if (Channel == HostChannel.Undefined)
                    {
                        return;
                    }

                    List <PickPoint> points = new();

                    c.Points.ForEach(c =>
                    {
                        points.Add(new()
                        {
                            PointNo    = c.pointNo,
                            AttribName = c.attribName
                        });
                    });

                    boxes.Add(new()
                    {
                        Channel      = Channel,
                        FunctionCode = c.functionCode,
                        SlaveAddress = c.slaveAddress,
                        StartAddress = c.startAddress,
                        PickPoints   = points
                    });
                });

                MachineBoxes.Add(new()
                {
                    MachineNo    = c.machineNo,
                    Production   = c.production,
                    Vesion       = c.vesion,
                    Address      = c.address,
                    Port         = c.port,
                    MessageBoxes = boxes
                });
            });

            void Working(object obj)
            {
                MachineBoxes.ForEach(async c =>
                {
                    await Task.Run(() =>
                    {
                        int iPort         = c.Port;
                        string sMachineNo = c.MachineNo, sAddress = c.Address;

                        lock (MachineSwitch) if (!MachineSwitch.ContainsKey(sMachineNo))
                            {
                                MachineSwitch.Add(sMachineNo, true);
                            }

                        c.MessageBoxes.ForEach(async c =>
                        {
                            try
                            {
                                if (c.PickPoints.Count == 0)
                                {
                                    return;
                                }

                                using TcpClient client      = new TcpClient(sAddress, iPort);
                                using ModbusIpMaster master = ModbusIpMaster.CreateIp(client);
                                ushort[] result             = await master.ReadHoldingRegistersAsync(c.SlaveAddress, c.StartAddress, Convert.ToUInt16(c.PickPoints.Count));

                                if (result == null || result.Length == 0)
                                {
                                    return;
                                }

                                MachineSwitch[sMachineNo] = true;

                                c.PickPoints.ForEach(c =>
                                {
                                    string sKey = sMachineNo + "#" + c.AttribName;

                                    lock (RowBox)
                                    {
                                        if (!RowBox.ContainsKey(sKey))
                                        {
                                            RowBox.Add(sKey, result[c.PointNo]);
                                        }
                                        else
                                        {
                                            RowBox[sKey] = result[c.PointNo];
                                        }
                                    }
                                });
                            }
                            catch (Exception e)
                            {
                                if (MachineSwitch[sMachineNo] == true)
                                {
                                    //webapi <==

                                    Console.WriteLine($" No.{sMachineNo} => {e.Message}");
                                }

                                MachineSwitch[sMachineNo] = false;
                            }
                        });
                    });
                });
            }

            await Task.Run(() =>
            {
                try
                {
                    Callback += new TimerCallback(Working);
                    Callback += new TimerCallback(RocketLaunch);
                    Timer     = new Timer(Callback, null, Timeout.Infinite, iFrequency);
                    Timer.Change(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(iFrequency));
                }
                catch (Exception e)
                {
                    Console.WriteLine("sMMP => " + e.Message + "\n" + e.StackTrace);
                }
            });

            void RocketLaunch(object obj)
            {
                MachineBoxes.ToList().ForEach(async c =>
                {
                    await Task.Run(() =>
                    {
                        bool bProduction  = c.Production;
                        string sMachineNo = c.MachineNo, sVersion = c.Vesion;

                        List <Parameter> parameters = new();

                        c.MessageBoxes.ForEach(c =>
                        {
                            c.PickPoints.ForEach(c =>
                            {
                                string sKey = sMachineNo + "#" + c.AttribName;

                                if (RowBox.ContainsKey(sKey))
                                {
                                    lock (HistoryBox)
                                    {
                                        if (!HistoryBox.ContainsKey(sKey))
                                        {
                                            HistoryBox.Add(sKey, RowBox[sKey]);
                                        }
                                        else
                                        {
                                            if (RowBox[sKey] != HistoryBox[sKey])
                                            {
                                                parameters.Add(new()
                                                {
                                                    AttribNo    = c.AttribName,
                                                    AttribValue = RowBox[sKey]
                                                });

                                                HistoryBox[sKey] = RowBox[sKey];
                                            }
                                        }
                                    }
                                }
                            });

                            GlobalVariables globally = new();

                            GlobalApproach.PushDataToHost(c.Channel, new()
                            {
                                Version        = sVersion,
                                Production     = bProduction,
                                MachineNo      = sMachineNo,
                                ReportDateTime = globally.NowTime,
                                Row            = parameters
                            });
                        });
                    });
                });
            }
        }
Пример #7
0
		public void CommonContainerTests()
		{
			var styles = new AssembledStyles();
			var columnWidths = new FixedColumnWidths(new[] {10});
			var root1 = new RootBox(styles);
			var root2 = new RootBox(styles);
			VerifyCC(root1, root1, root1, root1, root1);
			VerifyCC(root2, root2, root2, root2, root2);
			var row1 = new RowBox(styles, columnWidths, false);
			var div1 = new DivBox(styles);
			root2.AddBox(row1);
			root1.AddBox(div1);
			VerifyCC(row1, row1, row1, row1, row1);
			VerifyCC(div1, div1, div1, div1, div1);
			VerifyCC(root1, div1, root1, root1, div1);
			VerifyCC(root2, row1, root2, root2, row1);
			var row2 = new RowBox(styles, columnWidths, false);
			var div2 = new DivBox(styles);
			root2.AddBox(row2);
			root1.AddBox(div2);
			VerifyCC(row1, row2, root2, row1, row2);
			VerifyCC(div1, div2, root1, div1, div2);
			var row3 = new RowBox(styles, columnWidths, false);
			var div3 = new DivBox(styles);
			row1.AddBox(row3);
			div1.AddBox(div3);
			VerifyCC(row1, row3, row1, row1, row3);
			VerifyCC(row2, row3, root2, row2, row1);
			VerifyCC(div1, div3, div1, div1, div3);
			VerifyCC(div2, div3, root1, div2, div1);
			var row4 = new RowBox(styles, columnWidths, false);
			var div4 = new DivBox(styles);
			row2.AddBox(row4);
			div2.AddBox(div4);
			VerifyCC(row3, row4, root2, row1, row2);
			VerifyCC(row1, row4, root2, row1, row2);
			VerifyCC(div3, div4, root1, div1, div2);
			VerifyCC(div1, div4, root1, div1, div2);
		}