public AasxPluginResultBase ActivateAction(string action, params object[] args) { if (action == "server-stop") { this.stop = true; } if (action == "server-start") { this.stop = false; Log.Info("This is a (empty) sample server demonstrating the plugin capabilities, only."); int i = 0; while (true) { if (this.stop) { Log.Info("Stopping ..."); break; } System.Threading.Thread.Sleep(50); if (i % 20 == 0) { Log.Info("Heartbeat {0} ..", i); } i++; } Log.Info("Stopped."); } var res = new AasxPluginResultBase(); return(res); }
public AasxPluginResultBase ActivateAction(string action, params object[] args) { if (action == "get-licenses") { var lic = new AasxPluginResultLicense(); lic.shortLicense = "This application uses the OPC Foundation .NET Standard stack. See: OPC REDISTRIBUTABLES " + "Agreement of Use." + Environment.NewLine + "The OPC UA Example Code of OPC UA Standard is licensed under the MIT license (MIT)."; lic.isStandardLicense = true; lic.longLicense = AasxPluginHelper.LoadLicenseTxtFromAssemblyDir( "LICENSE.txt", Assembly.GetExecutingAssembly()); return(lic); } if (action == "server-stop") { this.stop = true; } if (action == "server-start") { // init this.stop = false; logger.Info("Starting OPC UA AASX Server. Based on the OPC Foundation UA Net Standard stack."); logger.Info("Copyright (c) 2018-2021 Festo AG & Co. KG " + "<https://www.festo.com/net/de_de/Forms/web/contact_international>, author: Michael Hoffmeister."); logger.Info("Portions copyright (c) by OPC Foundation, Inc. and licensed under the Reciprocal " + "Community License (RCL)."); logger.Info("See https://opcfoundation.org/license/rcl.html."); // access AASX if (args == null || args.Length < 1) { logger.Info("No AASX package environment passed to plug-in. Stopping..."); System.Threading.Thread.Sleep(5000); return(null); } var package = args[0] as AdminShellPackageEnv; if (package == null) { logger.Info("No AASX package environment passed to plug-in. Stopping..."); System.Threading.Thread.Sleep(5000); return(null); } logger.Info("AASX package env has filename {0}", package.Filename); // configure UA here a little bit ApplicationInstance.MessageDlg = new ApplicationMessageDlg(logger); // arguments var externalOptions = new List <string>(); if (options?.Args != null) { foreach (var o1 in options.Args) { externalOptions.Add(o1); } } if (args.Length >= 2 && args[1] is string[]) { var pluginArgs = args[1] as string[]; if (pluginArgs != null && pluginArgs.Length > 0) { foreach (var o2 in pluginArgs) { externalOptions.Add(o2); } } } // debug var lstr = $"Taking over {externalOptions.Count} arguments: "; foreach (var ls in externalOptions) { lstr += ls + " "; } logger.Info("{0}", lstr); // parse var internalOptions = new AasOpcUaServer.AasxUaServerOptions(); internalOptions.ParseArgs(externalOptions.ToArray()); // run the server try { this.server = new UaServerWrapper(_autoAccept: true, _stopTimeout: 0, _aasxEnv: package, logger: logger, _serverOptions: internalOptions); this.server.Run(); } catch (Exception ex) { logger.Info("Exception whenn running server: {0}", ex.Message); } // do as long as user wants int i = 0; while (true) { if (this.stop) { logger.Info("Stopping ..."); if (this.server != null) { this.server.Stop(); } break; } // MICHA TODO : Temporary disabled // seems not to work anymore ////if (this.server != null && this.server.IsNotRunningAnymore()) //// break; // new option if (true == this.server?.FinallyStopped) { break; } System.Threading.Thread.Sleep(50); if (i % 200 == 0) { logger.Info("Heartbeat {0} x 50ms ..", i); } i++; } logger.Info("Stopped."); } var res = new AasxPluginResultBase(); return(res); }