Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                ApplicationLicenseManager.AddProcessLicenses(System.Reflection.Assembly.GetExecutingAssembly(), "License.lic");

                // Register structured types
                MessageContext context = new MessageContext();

                // Start the server.
                ServerManager server = new TestServerManager();
                ApplicationInstance.Default.Start(server, null, server);
                Console.WriteLine("Endpoint URL: opc.tcp://localhost:48030");
                // Block until the server exits.
                Console.WriteLine("Press <enter> to exit the program.");
                Console.ReadLine();
                // Stop the server.
                server.Stop();
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
                Console.WriteLine("Press <enter> to exit the program.");
                Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        public async Task StartAsync(CancellationToken token)
        {
            var log = LogConfig.CreateLogger();

            log.Information($"Starting {GetApplicationName()}");

            try
            {
                ApplicationLicenseManager.AddProcessLicenses(System.Reflection.Assembly.GetExecutingAssembly(), GetUALicensePath());
                ApplicationInstance.Default.Start();

                log.Information($"License {ApplicationLicenseManager.GetAvailableLicense()} loaded successfully");
            }
            catch (Exception ex)
            {
                log.Error(ex, "Failed to load license.");
            }

            try
            {
                await StreamToEventHub(token);
            }
            catch (Exception ex)
            {
                log.Fatal(ex, "Fatal error");
            }
            finally
            {
                LogConfig.EndLogging();
            }
        }
Exemplo n.º 3
0
        public bool Start()
        {
            if (Manager.IsRunning)
            {
                return(false);
            }

            ApplicationLicenseManager.AddProcessLicenses(Assembly.GetExecutingAssembly(),
                                                         "License.lic");
            var application = new ApplicationInstance {
                ConfigurationFilePath = "ServerConfig.xml"
            };

            application.LoadConfiguration(false, true);
            ConfigureOpcUaApplicationFromCode(application, Ip, Port);
            application.Start(Manager, o => { }, Manager);
            if (Manager.SessionManager != null)
            {
                Manager.SessionManager.SessionCreated += (session, reason) =>
                {
                    Logger.Info($"Client({session.Id.Identifier}) connected.");
                    if (Manager.ConnectHandler?.Callback == null)
                    {
                        return;
                    }
                    var result = Manager.ConnectHandler.Callback(Manager.ConnectHandler.HandlerContext, session);
                    Manager.GetSessionContext()[session] = result;
                };
                Manager.SessionManager.SessionClosing += (session, reason) =>
                {
                    Logger.Info($"Client({session.Id.Identifier}) disconnected.");
                    if (Manager.DisconnectHandler?.Callback == null)
                    {
                        return;
                    }
                    Manager.DisconnectHandler.Callback(Manager.DisconnectHandler.HandlerContext, session);
                    Manager.GetSessionContext().Remove(session);
                };
            }
            else
            {
                Logger.Warn(
                    "Cannot append events SessionCreated, and SessionClosing to the SessionManager, due to available SessionManager reference isn't null!");
            }

            Logger.Info("UA Convenience Layer is running ...");
            return(true);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                ApplicationLicenseManager.AddProcessLicenses(System.Reflection.Assembly.GetExecutingAssembly(), "License.lic");
                GettingStartedServerManager server = new GettingStartedServerManager();

                ConfigureOpcUaApplicatiopnFromCode();
                ApplicationInstance.Default.Start(server, null, server);

                Console.WriteLine("Press <Enter> to exit the program.");
                Console.ReadLine();

                server.Stop();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            try
            {
                // The license file must be loaded from an embedded resource.
                ApplicationLicenseManager.AddProcessLicenses(System.Reflection.Assembly.GetExecutingAssembly(), "License.lic");

                // Start the server.
                Console.WriteLine("Starting Server.");
                GettingStartedServerManager server = new GettingStartedServerManager();
                //***********************************************************************
                // The following function can be called to configure the server from code
                // This will disable the configuration settings from app.config file
                //ConfigureOpcUaApplicationFromCode();
                //***********************************************************************
                ApplicationInstance.Default.AutoCreateCertificate = true;
                ApplicationInstance.Default.Start(server, null, server);

                // Print endpoints for information.
                PrintEndpoints(server);

                // Block until the server exits.
                Console.WriteLine("Press <enter> to exit the program.");
                Console.ReadLine();

                // Stop the server.
                Console.WriteLine("Stopping Server.");
                server.Stop();
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: {0}", e.Message);
                Console.WriteLine("Press <enter> to exit the program.");
                Console.ReadLine();
            }
        }