Exemple #1
0
        protected override void OnStart()
        {
            // build a loggerFactory.
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(builder => builder.AddDebug());
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var loggerFactory   = serviceProvider.GetService <ILoggerFactory>();

            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.MobileHmi")
                               .SetDirectoryStore(Path.Combine(
                                                      Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                      "pki"))
                               .SetIdentity(this.ShowSignInDialog)
                               .SetLoggerFactory(loggerFactory)
                               .AddMappedEndpoint("opc.tcp://localhost:26543", "opc.tcp://10.0.2.2:26543")
                               .Build();

            this.application.Run();

            // Show the MainPage
            this.MainPage = new NavigationPage(new MainPage());
        }
Exemple #2
0
        /// <inheritdoc/>
        protected override void OnStartup(StartupEventArgs e)
        {
            // Setup a logger.
            this.loggerFactory = new LoggerFactory();
            this.loggerFactory.AddDebug(LogLevel.Trace);

            // Read 'appSettings.json' for endpoint configuration
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appSettings.json", true)
                         .Build();

            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.RobotHmi")
                               .SetDirectoryStore(Path.Combine(
                                                      Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                      "Workstation.RobotHmi",
                                                      "pki"))
                               .SetIdentity(this.ShowSignInDialog)
                               .SetLoggerFactory(this.loggerFactory)
                               .AddMappedEndpoints(config)
                               .Build();

            this.application.Run();

            // Start Prism bootstrapper
            this.bootstrapper = new AppBootstrapper(this.loggerFactory);
            this.bootstrapper.Run();
        }
Exemple #3
0
        /// <inheritdoc/>
        protected override void OnStartup(StartupEventArgs e)
        {
            // Setup a logger.
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(builder => builder.AddDebug());
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var loggerFactory   = serviceProvider.GetService <ILoggerFactory>();

            // Read 'appSettings.json' for endpoint configuration
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appSettings.json", true)
                         .Build();

            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.RobotHmi")
                               .SetDirectoryStore(Path.Combine(
                                                      Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                      "Workstation.RobotHmi",
                                                      "pki"))
                               .SetIdentity(this.ShowSignInDialog)
                               .SetLoggerFactory(loggerFactory)
                               .AddMappedEndpoints(config)
                               .Build();

            this.application.Run();

            base.OnStartup(e);
        }
        public override Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
        {
            // Setup a logger.
            this.loggerFactory = new LoggerFactory();
            this.loggerFactory.AddDebug(LogLevel.Trace);

            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.RobotApp")
                               .SetDirectoryStore(Path.Combine(ApplicationData.Current.LocalFolder.Path, "pki"))
                               .SetIdentity(this.ShowSignInDialog)
                               .SetLoggerFactory(this.loggerFactory)
                               .Build();

            this.application.Run();

            // Register view models with the container using the name of the view.
            this.container.RegisterType <INavigable, MainPageViewModel>(nameof(MainPage), new ContainerControlledLifetimeManager());
            this.container.RegisterType <INavigable, AxisPageViewModel>(nameof(AxisPage), new ContainerControlledLifetimeManager());
            this.container.RegisterType <INavigable, SettingsPageViewModel>(nameof(SettingsPage));

            // Show the MainPage.
            this.NavigationService.Navigate(typeof(MainPage));
            return(Task.CompletedTask);
        }
Exemple #5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // build a loggerFactory.
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(builder => builder.AddDebug());
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var loggerFactory   = serviceProvider.GetService <ILoggerFactory>();

            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.StatusHmi")
                               .SetDirectoryStore(Path.Combine(
                                                      Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                      "Workstation.StatusHmi",
                                                      "pki"))
                               .SetIdentity(this.ShowSignInDialog)
                               .SetLoggerFactory(loggerFactory)
                               .Build();

            this.application.Run();

            // Create and show the main view.
            var view = new MainView();

            view.Show();
            base.OnStartup(e);
        }
Exemple #6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // Setup a logger.
            this.loggerFactory = new LoggerFactory();
            this.loggerFactory.AddDebug(LogLevel.Trace);

            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .UseApplicationUri($"urn:{Dns.GetHostName()}:Workstation.StatusHmi")
                               .UseDirectoryStore(Path.Combine(
                                                      Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                      "Workstation.StatusHmi",
                                                      "pki"))
                               .UseIdentity(this.ShowSignInDialog)
                               .UseLoggerFactory(this.loggerFactory)
                               .Build();

            this.application.Run();

            // Create and show the main view.
            var view = new MainView();

            view.Show();
            base.OnStartup(e);
        }
Exemple #7
0
 public static async Task startUaApp()
 {
     application = new UaApplicationBuilder()
                   .SetApplicationUri(appDescription.ApplicationUri)
                   .SetDirectoryStore(Path.Combine(
                                          Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                          "Workstation.UaClient",
                                          "pki"))
                   .SetIdentity(Program.channel.UserIdentity)
                   .SetLoggerFactory(loggerFactory)
                   .AddMappedEndpoint(discoveryUrl, channel.RemoteEndpoint)
                   .Build();
     application.Run();
     await application.GetChannelAsync(discoveryUrl, new CancellationToken());
 }
Exemple #8
0
        protected override void OnStartup(StartupEventArgs e)
        {
            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.StatusHmi")
                               .SetDirectoryStore($"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Workstation.StatusHmi\\pki")
                               .SetIdentity(this.ShowSignInDialog)
                               .Build();

            this.application.Run();

            // Create and show the main view.
            //var view = new MainWindow();
            //view.Show();
        }
Exemple #9
0
        protected override void OnStart()
        {
            // Setup a logger.
            this.loggerFactory = new LoggerFactory();
            this.loggerFactory.AddDebug(LogLevel.Trace);

            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .UseApplicationUri($"urn:{Dns.GetHostName()}:Workstation.MobileHmi")
                               .UseDirectoryStore(Path.Combine(
                                                      Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                                      "pki"))
                               .UseIdentity(this.ShowSignInDialog)
                               .UseLoggerFactory(this.loggerFactory)
                               .Map("opc.tcp://localhost:26543", "opc.tcp://10.0.2.2:26543")
                               .Build();

            this.application.Run();

            // Show the MainPage
            this.MainPage = new NavigationPage(new MainPage());
        }
Exemple #10
0
        protected override void OnStartup(StartupEventArgs e)
        {
            string thisProcessName = Process.GetCurrentProcess().ProcessName;

            if (Process.GetProcesses().Count(p => p.ProcessName == thisProcessName) > 1)
            {
                MessageBox.Show("Приложение уже запущено");
                return;
            }
            // Build and run an OPC UA application instance.
            this.application = new UaApplicationBuilder()
                               .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.StatusHmi")
                               .SetDirectoryStore($"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Workstation.StatusHmi\\pki")
                               .SetIdentity(this.ShowSignInDialog)
                               .Build();

            this.application.Run();

            // Create and show the main view.
            //var view = new MainWindow();
            //view.Show();
        }
Exemple #11
0
        public App()
        {
            InitializeComponent();
            EnteredBackground += App_EnteredBackground;
            Resuming          += App_Resuming;

            // Setup a logger.
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(builder => builder.AddDebug());
            var serviceProvider = serviceCollection.BuildServiceProvider();
            var loggerFactory   = serviceProvider.GetService <ILoggerFactory>();

            // Build and run an OPC UA application instance.
            this.uaApplication = new UaApplicationBuilder()
                                 .SetApplicationUri($"urn:{System.Net.Dns.GetHostName()}:Workstation.RobotApp")
                                 .SetDirectoryStore(Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "pki"))
                                 .SetIdentity(this.ShowSignInDialog)
                                 .SetLoggerFactory(loggerFactory)
                                 .Build();

            this.uaApplication.Run();
            _activationService = new Lazy <ActivationService>(CreateActivationService);
        }
Exemple #12
0
        private static async Task TestAsync()
        {
            UaApplication application = null;

            loggerFactory = new LoggerFactory();
            loggerFactory.AddDebug(LogLevel.Trace);

            discoveryUrl = "opc.tcp://localhost:4840";

            Console.WriteLine("Step 1 - Describe this app.");
            appDescription = new ApplicationDescription()
            {
                ApplicationName = "MyHomework",
                ApplicationUri  = $"urn:{System.Net.Dns.GetHostName()}:MyHomework",
                ApplicationType = ApplicationType.Client,
            };

            Console.WriteLine("Step 2 - Create a certificate store.");
            var certificateStore = new DirectoryStore(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                             "Workstation.ConsoleApp", "pki"));

            Console.WriteLine("Step 3 - Create a session with your server.");
            channel = new UaTcpSessionChannel(
                appDescription,
                certificateStore,
                ShowSignInDialog,
                discoveryUrl,
                loggerFactory: loggerFactory);
            try
            {
                await channel.OpenAsync();

                Console.WriteLine($"  Opened channel with endpoint '{channel.RemoteEndpoint.EndpointUrl}'.");
                Console.WriteLine($"  SecurityPolicyUri: '{channel.RemoteEndpoint.SecurityPolicyUri}'.");
                Console.WriteLine($"  SecurityMode: '{channel.RemoteEndpoint.SecurityMode}'.");
                Console.WriteLine($"  SecurityLevel: '{channel.RemoteEndpoint.SecurityLevel}'.");
                Console.WriteLine($"  UserIdentityTokens: '{channel.RemoteEndpoint.UserIdentityTokens}'.");
                Console.WriteLine($"  UserIdentity: '{channel.UserIdentity}'.");
                Console.WriteLine($"channel.ServerUris:{channel.RemoteEndpoint}");
                Console.WriteLine($"channel.ServerUris:{channel.ServerUris}");

                Console.WriteLine("Step 4 - Browse the server namespace.");
                Console.WriteLine("+ Root");
                //BrowseRequest browseRequest = new BrowseRequest
                //{
                //    NodesToBrowse = new BrowseDescription[]
                //    {
                //        new BrowseDescription
                //        {
                //            NodeId = NodeId.Parse(ObjectIds.RootFolder), BrowseDirection = BrowseDirection.Forward,
                //            ReferenceTypeId = NodeId.Parse(ReferenceTypeIds.HierarchicalReferences),
                //            NodeClassMask = (uint) NodeClass.Variable | (uint) NodeClass.Object |
                //                            (uint) NodeClass.Method,
                //            IncludeSubtypes = true, ResultMask = (uint) BrowseResultMask.All
                //        }
                //    },
                //};
                //BrowseResponse browseResponse = await channel.BrowseAsync(browseRequest);
                //foreach (var rd1 in browseResponse.Results[0].References ?? new ReferenceDescription[0])
                //{
                //    Console.WriteLine("  + {0}: {1}, {2}", rd1.DisplayName, rd1.BrowseName, rd1.NodeClass);
                //    browseRequest = new BrowseRequest
                //    {
                //        NodesToBrowse = new BrowseDescription[]
                //        {
                //            new BrowseDescription
                //            {
                //                NodeId = ExpandedNodeId.ToNodeId(rd1.NodeId, channel.NamespaceUris),
                //                BrowseDirection = BrowseDirection.Forward,
                //                ReferenceTypeId = NodeId.Parse(ReferenceTypeIds.HierarchicalReferences),
                //                NodeClassMask = (uint) NodeClass.Variable | (uint) NodeClass.Object |
                //                                (uint) NodeClass.Method,
                //                IncludeSubtypes = true, ResultMask = (uint) BrowseResultMask.All
                //            }
                //        },
                //    };
                //    browseResponse = await channel.BrowseAsync(browseRequest);
                //    foreach (var rd2 in browseResponse.Results[0].References ?? new ReferenceDescription[0])
                //    {
                //        Console.WriteLine("    + {0}: {1}, {2}", rd2.DisplayName, rd2.BrowseName, rd2.NodeClass);
                //        browseRequest = new BrowseRequest
                //        {
                //            NodesToBrowse = new BrowseDescription[]
                //            {
                //                new BrowseDescription
                //                {
                //                    NodeId = ExpandedNodeId.ToNodeId(rd2.NodeId, channel.NamespaceUris),
                //                    BrowseDirection = BrowseDirection.Forward,
                //                    ReferenceTypeId = NodeId.Parse(ReferenceTypeIds.HierarchicalReferences),
                //                    NodeClassMask = (uint) NodeClass.Variable | (uint) NodeClass.Object |
                //                                    (uint) NodeClass.Method,
                //                    IncludeSubtypes = true, ResultMask = (uint) BrowseResultMask.All
                //                }
                //            },
                //        };
                //        browseResponse = await channel.BrowseAsync(browseRequest);
                //        foreach (var rd3 in browseResponse.Results[0].References ?? new ReferenceDescription[0])
                //        {
                //            Console.WriteLine("      + {0}: {1}, {2}", rd3.DisplayName, rd3.BrowseName, rd3.NodeClass);
                //        }
                //    }
                //}
                //Console.WriteLine("test");
                //Console.WriteLine("Step 5 - Create a subscription.");
                //var subscriptionRequest = new CreateSubscriptionRequest
                //{
                //    RequestedPublishingInterval = 500,
                //    RequestedMaxKeepAliveCount = 10,
                //    RequestedLifetimeCount = 30,
                //    PublishingEnabled = true
                //};
                //var subscriptionResponse = await channel.CreateSubscriptionAsync(subscriptionRequest);
                //var id = subscriptionResponse.SubscriptionId;

                //Console.WriteLine("Step 6 - Add items to the subscription.");
                //var itemsToCreate = new MonitoredItemCreateRequest[]
                //{
                //    new MonitoredItemCreateRequest
                //    {
                //        ItemToMonitor = new ReadValueId
                //        {
                //            NodeId = NodeId.Parse("ns=6;s=::Program:Cube.Admin.ProdProcessedCount"),
                //            AttributeId = AttributeIds.Value
                //        },
                //        MonitoringMode = MonitoringMode.Reporting,
                //        RequestedParameters = new MonitoringParameters
                //            {ClientHandle = 1, SamplingInterval = -1, QueueSize = 0, DiscardOldest = true}
                //    }
                //};
                //var itemsRequest = new CreateMonitoredItemsRequest
                //{
                //    SubscriptionId = id,
                //    ItemsToCreate = itemsToCreate,
                //};
                //var itemsResponse = await channel.CreateMonitoredItemsAsync(itemsRequest);

                //Console.WriteLine("Step 7 - Subscribe to PublishResponse stream.");
                //var token = channel.Where(pr => pr.SubscriptionId == id).Subscribe(pr =>
                //{
                //    // loop thru all the data change notifications
                //    var dcns = pr.NotificationMessage.NotificationData.OfType<DataChangeNotification>();
                //    foreach (var dcn in dcns)
                //    {
                //        foreach (var min in dcn.MonitoredItems)
                //        {
                //            Console.WriteLine(
                //                $"sub: {pr.SubscriptionId}; handle: {min.ClientHandle}; value: {min.Value}");

                //        }
                //    }
                //});

                //Console.WriteLine("Press any key to delete the subscription...");
                //while (!Console.KeyAvailable)
                //{
                //    await Task.Delay(500);
                //}

                //Console.ReadKey(true);

                //    Console.WriteLine("Step 8 - Delete the subscription.");
                //    var request = new DeleteSubscriptionsRequest
                //    {
                //        SubscriptionIds = new uint[] {id}
                //    };
                //    await channel.DeleteSubscriptionsAsync(request);
                //    //token.Dispose();

                //    Console.WriteLine("Press any key to close the session...");
                //    Console.ReadKey(true);

                //    Console.WriteLine("Step 9 - Close the session.");
                await channel.CloseAsync();
            }
            catch (ServiceResultException ex)
            {
                if ((uint)ex.HResult == StatusCodes.BadSecurityChecksFailed)
                {
                    Console.WriteLine("Error connecting to endpoint. Did the server reject our certificate?");
                }

                await channel.AbortAsync();

                throw;
            }
        }