Пример #1
0
        internal static void BuildAsync()
        {
            if (YamlBase.Modules == null)
            {
                return;
            }

            Task.Run(async() =>
            {
                YamlBase.Modules.ForEach(async c =>
                {
                    switch (c.Launcher)
                    {
                    case nameof(Communication.CsvFile):
                        await Task.Run(() =>
                        {
                            if (c.Enable)
                            {
                                EnableCsvFile = true;
                                GlobalApproach.PipeBuilder(true, Communication.CsvFile);
                            }
                            ;
                        });
                        break;

                    case nameof(Communication.ModbusTcp):
                        await Task.Run(() =>
                        {
                            if (c.Enable)
                            {
                                EnableModbusTcp = true;
                                GlobalApproach.PipeBuilder(true, Communication.ModbusTcp);
                                IConstruction factory = SimpleFactory.BuildService(c.Arguments.Replace(" ", ""));
                                factory.Start();
                            }
                            ;
                        });
                        break;

                    case nameof(Communication.OpcUa):
                        await Task.Run(() =>
                        {
                            if (c.Enable)
                            {
                                EnableOpcUa = true;
                                GlobalApproach.PipeBuilder(true, Communication.OpcUa);
                            }
                            ;
                        });
                        break;
                    }
                });

                while (!EnableEdgeService)
                {
                    ;
                }

                if (EnableCsvFile == false)
                {
                    GlobalApproach.PipeBuilder(false, Communication.CsvFile);
                }
                if (EnableModbusTcp == false)
                {
                    GlobalApproach.PipeBuilder(false, Communication.ModbusTcp);
                }
                if (EnableOpcUa == false)
                {
                    GlobalApproach.PipeBuilder(false, Communication.OpcUa);
                }

                Console.WriteLine("\n Local IP => " + GeneralTools.GetLocalIP());

                string EquallyDivided = new('*', 14);

                Console.WriteLine($"{Welcome(WelcomeTitle)}\n {EquallyDivided} {ServiceTitle} {EquallyDivided}\n");

                await Task.Run(async() =>
                {
                    await Task.Delay(TimeSpan.FromSeconds(5));
                    if (!YamlBase.Propertie.Debug)
                    {
                        ShowWindow(GetConsoleWindow(), 0);
                    }
                });
Пример #2
0
        public override async Task SendAsync(PayloadRoot root, HostChannel channel)
        {
            try
            {
                if (channel == HostChannel.Undefined || root.Row.Count == 0)
                {
                    return;
                }

                FoundationProvider provider  = new();
                GlobalVariables    variables = new();

                XElement xHost = new("host");
                xHost.Add(new XAttribute("prod", provider.FoundationBasic.Eai.Host.Name));
                xHost.Add(new XAttribute("ver", provider.FoundationBasic.Eai.Host.Version));
                xHost.Add(new XAttribute("ip", GeneralTools.GetLocalIP()));
                xHost.Add(new XAttribute("id", provider.FoundationBasic.Eai.Host.Id));
                xHost.Add(new XAttribute("acct", provider.FoundationBasic.Eai.Host.Account));
                xHost.Add(new XAttribute("lang", provider.FoundationBasic.Eai.Host.Language));
                xHost.Add(new XAttribute("timestamp", DateTime.Now.ToString(("yyyyMMddHHmmssfff"))));

                XElement service = new("service");
                service.Add(new XAttribute("prod", provider.FoundationBasic.Eai.Service.Name));
                service.Add(new XAttribute("name", channel switch
                {
                    HostChannel.Status => "change.machine.status.process",
                    HostChannel.Parameter => "parameter.check.process",
                    HostChannel.Production => "production.edc.process",
                    _ => ""
                }));
                service.Add(new XAttribute("srvver", provider.FoundationBasic.Eai.Service.Srvver));
                service.Add(new XAttribute("ip", provider.FoundationBasic.Eai.Service.Ip));
                service.Add(new XAttribute("id", provider.FoundationBasic.Eai.Service.Id));

                XElement xRoot = new XElement("request");
                xRoot.Add(new XAttribute("key", (xHost.ToString() + service.ToString()).ToMD5()));
                xRoot.Add(new XAttribute("type", "sync"));
                xRoot.Add(xHost);
                xRoot.Add(service);

                XElement xPayload = new("payload");

                XElement xParam = new("param");
                xParam.Add(new XAttribute("key", "std_data"));
                xParam.Add(new XAttribute("type", "xml"));
                xPayload.Add(xParam);

                XElement xDataRequest = new("data_request");
                xParam.Add(xDataRequest);

                XElement xDatainfo = new("datainfo");
                xDataRequest.Add(xDatainfo);

                XElement xParameter = new("parameter");
                xParameter.Add(new XAttribute("key", channel switch
                {
                    HostChannel.Status => "change_machine_status",
                    HostChannel.Parameter => "parameter_check",
                    HostChannel.Production => "production_edc",
                    _ => ""
                }));