コード例 #1
0
        /// <summary>
        /// Handler for UnpublishNodes direct method
        /// </summary>
        public async Task <PublishedNodesResponseApiModel> UnpublishNodesAsync(
            PublishNodesEndpointApiModel request)
        {
            await _configServices.UnpublishNodesAsync(request.ToServiceModel()).ConfigureAwait(false);

            return(new PublishedNodesResponseApiModel());
        }
コード例 #2
0
        public async Task DmApiGetConfiguredNodesOnEndpointAsyncUsernamePasswordTest(string publishedNodesFile)
        {
            var endpointUrl        = "opc.tcp://opcplc:50000";
            var authenticationMode = AuthenticationMode.UsernamePassword;
            var username           = "******";
            var password           = "******";

            var endpointRequest = new PublishNodesEndpointApiModel {
                EndpointUrl           = endpointUrl,
                OpcAuthenticationMode = authenticationMode,
                UserName = username,
                Password = password,
            };

            var methodsController = await publishNodeAsync(publishedNodesFile);

            var response = await FluentActions
                           .Invoking(async() => await methodsController
                                     .GetConfiguredNodesOnEndpointAsync(endpointRequest).ConfigureAwait(false))
                           .Should()
                           .NotThrowAsync()
                           .ConfigureAwait(false);

            response.Subject.OpcNodes.Count()
            .Should()
            .Be(2);
            response.Subject.OpcNodes.First().Id
            .Should()
            .Be("ns=2;s=FastUInt3");
            response.Subject.OpcNodes[1].Id
            .Should()
            .Be("ns=2;s=FastUInt4");
        }
コード例 #3
0
        /// <summary>
        /// Create a service model for an api model
        /// </summary>
        public static PublishedNodesEntryModel ToServiceModel(
            this PublishNodesEndpointApiModel model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new PublishedNodesEntryModel {
                EndpointUrl = !string.IsNullOrEmpty(model.EndpointUrl)
                    ? new Uri(model.EndpointUrl)
                    : null,
                UseSecurity = model.UseSecurity,
                OpcAuthenticationMode = (OpcAuthenticationMode)model.OpcAuthenticationMode,
                OpcAuthenticationPassword = model.Password,
                OpcAuthenticationUsername = model.UserName,
                OpcNodes = model.OpcNodes != null
                    ? model.OpcNodes.Select(n => n.ToServiceModel()).ToList()
                    : null,
                DataSetWriterGroup = model.DataSetWriterGroup,
                DataSetWriterId = model.DataSetWriterId,
                Tag = model.Tag,
                DataSetPublishingIntervalTimespan = model.DataSetPublishingIntervalTimespan,
                // only fill the DataSetPublishingInterval if the DataSetPublishingIntervalTimespan
                // was not provided.
                DataSetPublishingInterval = !model.DataSetPublishingIntervalTimespan.HasValue
                    ? model.DataSetPublishingInterval
                    : null,
            });
        }
コード例 #4
0
        public async Task DmApiGetConfiguredNodesOnEndpointAsyncOpcAuthenticationModeTest(string publishedNodesFile)
        {
            var endpointUrl               = "opc.tcp://opcplc:50000";
            var dataSetWriterGroup        = "Leaf1";
            var dataSetWriterId           = "Leaf1_10000_3085991c-b85c-4311-9bfb-a916da952235";
            var dataSetPublishingInterval = 3000;
            var authenticationMode        = AuthenticationMode.Anonymous;

            var endpointRequest = new PublishNodesEndpointApiModel {
                EndpointUrl               = endpointUrl,
                DataSetWriterGroup        = dataSetWriterGroup,
                DataSetWriterId           = dataSetWriterId,
                DataSetPublishingInterval = dataSetPublishingInterval,
                OpcAuthenticationMode     = authenticationMode,
            };

            var methodsController = await publishNodeAsync(publishedNodesFile);

            var response = await FluentActions
                           .Invoking(async() => await methodsController
                                     .GetConfiguredNodesOnEndpointAsync(endpointRequest).ConfigureAwait(false))
                           .Should()
                           .NotThrowAsync()
                           .ConfigureAwait(false);

            response.Subject.OpcNodes.Count()
            .Should()
            .Be(1);
            response.Subject.OpcNodes.First().Id
            .Should()
            .Be("ns=2;s=SlowUInt2");
        }
コード例 #5
0
        public async Task DmApiGetConfiguredNodesOnEndpointAsyncUseSecurityTest(string publishedNodesFile)
        {
            var endpointUrl = "opc.tcp://opcplc:50000";
            var useSecurity = false;

            var endpointRequest = new PublishNodesEndpointApiModel {
                EndpointUrl = endpointUrl,
                UseSecurity = useSecurity,
            };

            var methodsController = await publishNodeAsync(publishedNodesFile);

            var response = await FluentActions
                           .Invoking(async() => await methodsController
                                     .GetConfiguredNodesOnEndpointAsync(endpointRequest).ConfigureAwait(false))
                           .Should()
                           .NotThrowAsync()
                           .ConfigureAwait(false);

            response.Subject.OpcNodes.Count()
            .Should()
            .Be(1);
            response.Subject.OpcNodes.First().Id
            .Should()
            .Be("ns=2;s=SlowUInt3");
        }
コード例 #6
0
        public async Task DmApiGetConfiguredNodesOnEndpointAsyncDataSetWriterGroupTest(string publishedNodesFile)
        {
            var endpointUrl        = "opc.tcp://opcplc:50000";
            var dataSetWriterGroup = "Leaf0";
            var dataSetWriterId    = "Leaf0_10000_3085991c-b85c-4311-9bfb-a916da952234";
            var authenticationMode = AuthenticationMode.UsernamePassword;
            var username           = "******";
            var password           = "******";

            var endpointRequest = new PublishNodesEndpointApiModel {
                EndpointUrl           = endpointUrl,
                DataSetWriterGroup    = dataSetWriterGroup,
                DataSetWriterId       = dataSetWriterId,
                OpcAuthenticationMode = authenticationMode,
                UserName = username,
                Password = password,
            };

            var methodsController = await publishNodeAsync(publishedNodesFile);

            var response = await FluentActions
                           .Invoking(async() => await methodsController
                                     .GetConfiguredNodesOnEndpointAsync(endpointRequest).ConfigureAwait(false))
                           .Should()
                           .NotThrowAsync()
                           .ConfigureAwait(false);

            response.Subject.OpcNodes.Count()
            .Should()
            .Be(1);
            response.Subject.OpcNodes.First().Id
            .Should()
            .Be("ns=2;s=SlowUInt1");
        }
コード例 #7
0
        /// <summary>
        /// Handler for UnpublishAllNodes direct method
        /// </summary>
        public async Task <PublishedNodesResponseApiModel> UnpublishAllNodesAsync(
            PublishNodesEndpointApiModel request)
        {
            if (request.OpcNodes != null && request.OpcNodes.Count > 0)
            {
                throw new MethodCallStatusException((int)HttpStatusCode.BadRequest, "OpcNodes is set.");
            }
            await _configServices.UnpublishAllNodesAsync(request.ToServiceModel()).ConfigureAwait(false);

            return(new PublishedNodesResponseApiModel());
        }
コード例 #8
0
 /// <summary>
 /// Compare PublishNodesEndpointApiModel with PublishedNodeApiModel
 /// </summary>
 public static void AssertEndpointModel(PublishNodesEndpointApiModel expected, PublishNodesEndpointApiModel actual)
 {
     Assert.Equal(expected.DataSetPublishingInterval, actual.DataSetPublishingInterval);
     Assert.Equal(expected.DataSetPublishingIntervalTimespan, actual.DataSetPublishingIntervalTimespan);
     Assert.Equal(expected.DataSetWriterGroup, actual.DataSetWriterGroup);
     Assert.Equal(expected.DataSetWriterId, actual.DataSetWriterId);
     Assert.Equal(expected.EndpointUrl.TrimEnd('/'), actual.EndpointUrl.TrimEnd('/'));
     Assert.Equal(expected.OpcAuthenticationMode, actual.OpcAuthenticationMode);
     Assert.Equal(expected.UserName, actual.UserName);
     Assert.Equal(expected.UseSecurity, actual.UseSecurity);
 }
コード例 #9
0
        public void UseSecuritySerializationTest()
        {
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();

            var model = new PublishNodesEndpointApiModel {
                EndpointUrl = "opc.tcp://localhost:50000",
                OpcNodes    = new List <PublishedNodeApiModel> {
                    new PublishedNodeApiModel {
                        Id = "i=2258"
                    }
                }
            };

            var modeJson = newtonSoftJsonSerializer.SerializeToString(model);

            Assert.Contains("\"useSecurity\":false", modeJson);

            model = new PublishNodesEndpointApiModel {
                EndpointUrl = "opc.tcp://localhost:50000",
                UseSecurity = false,
                OpcNodes    = new List <PublishedNodeApiModel> {
                    new PublishedNodeApiModel {
                        Id = "i=2258"
                    }
                }
            };

            modeJson = newtonSoftJsonSerializer.SerializeToString(model);
            Assert.Contains("\"useSecurity\":false", modeJson);

            model = new PublishNodesEndpointApiModel {
                EndpointUrl = "opc.tcp://localhost:50000",
                UseSecurity = true,
                OpcNodes    = new List <PublishedNodeApiModel> {
                    new PublishedNodeApiModel {
                        Id = "i=2258"
                    }
                }
            };

            modeJson = newtonSoftJsonSerializer.SerializeToString(model);
            Assert.Contains("\"useSecurity\":true", modeJson);
        }
コード例 #10
0
        public void OpcAuthenticationModeSerializationTest()
        {
            var newtonSoftJsonSerializer = new NewtonSoftJsonSerializer();

            var model = new PublishNodesEndpointApiModel {
                EndpointUrl = "opc.tcp://localhost:50000",
                OpcNodes    = new List <PublishedNodeApiModel> {
                    new PublishedNodeApiModel {
                        Id = "i=2258"
                    }
                }
            };

            var modeJson = newtonSoftJsonSerializer.SerializeToString(model);

            Assert.Contains("\"opcAuthenticationMode\":\"anonymous\"", modeJson);

            model = new PublishNodesEndpointApiModel {
                EndpointUrl           = "opc.tcp://localhost:50000",
                OpcAuthenticationMode = AuthenticationMode.Anonymous,
                OpcNodes = new List <PublishedNodeApiModel> {
                    new PublishedNodeApiModel {
                        Id = "i=2258"
                    }
                }
            };

            modeJson = newtonSoftJsonSerializer.SerializeToString(model);
            Assert.Contains("\"opcAuthenticationMode\":\"anonymous\"", modeJson);

            model = new PublishNodesEndpointApiModel {
                EndpointUrl           = "opc.tcp://localhost:50000",
                OpcAuthenticationMode = AuthenticationMode.UsernamePassword,
                OpcNodes = new List <PublishedNodeApiModel> {
                    new PublishedNodeApiModel {
                        Id = "i=2258"
                    }
                }
            };

            modeJson = newtonSoftJsonSerializer.SerializeToString(model);
            Assert.Contains("\"opcAuthenticationMode\":\"usernamePassword\"", modeJson);
        }
コード例 #11
0
            /// <summary>
            /// Compare PublishNodesEndpointApiModel of requst with DiagnosticInfoApiModel returned
            /// from GetDiagnosticInfo direct method call.
            /// </summary>
            public static void AssertEndpointDiagnosticInfoModel(
                PublishNodesEndpointApiModel expected,
                DiagnosticInfoApiModel diagnosticInfo)
            {
                var actual = diagnosticInfo.Endpoint;

                Assert.Equal(expected.DataSetWriterGroup, actual.DataSetWriterGroup);
                Assert.Equal(expected.EndpointUrl.TrimEnd('/'), actual.EndpointUrl.TrimEnd('/'));
                Assert.Equal(expected.OpcAuthenticationMode, actual.OpcAuthenticationMode);
                Assert.Equal(expected.UserName, actual.UserName);
                Assert.Equal(expected.UseSecurity, actual.UseSecurity);

                // Check validity of diagnosticInfo
                Assert.True(diagnosticInfo.IngressValueChanges > 0);
                Assert.True(diagnosticInfo.IngressDataChanges > 0);
                Assert.Equal(0, diagnosticInfo.MonitoredOpcNodesFailedCount);
                Assert.Equal(expected.OpcNodes.Count, diagnosticInfo.MonitoredOpcNodesSucceededCount);
                Assert.True(diagnosticInfo.OpcEndpointConnected);
                Assert.True(diagnosticInfo.OutgressIoTMessageCount > 0);

                // Check that we are not dropping anything.
                Assert.Equal(0U, diagnosticInfo.EncoderNotificationsDropped);
                Assert.Equal(0UL, diagnosticInfo.OutgressInputBufferDropped);
            }
コード例 #12
0
        /// <summary>
        /// Handler for GetConfiguredNodesOnEndpoint direct method
        /// </summary>
        public async Task <GetConfiguredNodesOnEndpointResponseApiModel> GetConfiguredNodesOnEndpointAsync(PublishNodesEndpointApiModel request)
        {
            var response = await _configServices.GetConfiguredNodesOnEndpointAsync(request.ToServiceModel()).ConfigureAwait(false);

            return(new GetConfiguredNodesOnEndpointResponseApiModel()
            {
                OpcNodes = response.ToApiModel(),
            });
        }