예제 #1
0
 private void OnCommandComplete(GetEndpointsResponse response, object cookie)
 {
     if (!string.IsNullOrEmpty(response.BILogging))
     {
         Service.Get <StaRTSLogger>().DebugFormat("Updating BI endpoint to {0}", new object[]
         {
             response.BILogging
         });
         Service.Get <BILoggingController>().SetBIUrl(response.BILogging, response.NoProxyBILogging, response.Event2BiLogging, response.Event2NoProxyBiLogging);
     }
     base.Complete();
 }
예제 #2
0
        public async Task <GetEndpointsResponse> GetEndpointsAsync(GetEndpointsRequest getEndpointsRequest)
        {
            UpdateRequestHeader(getEndpointsRequest, true, "GetEndpoints");
            GetEndpointsResponse getEndpointsResponse = null;

            try
            {
                if (UseTransportChannel)
                {
                    var serviceResponse = await Task <IServiceResponse> .Factory.FromAsync(TransportChannel.BeginSendRequest, TransportChannel.EndSendRequest, getEndpointsRequest, null).ConfigureAwait(false);

                    if (serviceResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }
                    ValidateResponse(serviceResponse.ResponseHeader);
                    getEndpointsResponse = (GetEndpointsResponse)serviceResponse;
                }
                else
                {
                    var getEndpointsResponseMessage = await Task <GetEndpointsResponseMessage> .Factory.FromAsync(InnerChannel.BeginGetEndpoints, InnerChannel.EndGetEndpoints, new GetEndpointsMessage(getEndpointsRequest), null).ConfigureAwait(false);

                    if (getEndpointsResponseMessage == null || getEndpointsResponseMessage.GetEndpointsResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }
                    getEndpointsResponse = getEndpointsResponseMessage.GetEndpointsResponse;
                    ValidateResponse(getEndpointsResponse.ResponseHeader);
                }
            }
            finally
            {
                RequestCompleted(getEndpointsRequest, getEndpointsResponse, "GetEndpoints");
            }
            return(getEndpointsResponse);
        }
예제 #3
0
        /// <summary>
        /// Invokes the GetEndpoints service.
        /// </summary>
        public IServiceResponse GetEndpoints(IServiceRequest incoming)
        {
            GetEndpointsResponse response = null;

            GetEndpointsRequest request = (GetEndpointsRequest)incoming;

            EndpointDescriptionCollection endpoints = null;

            response = new GetEndpointsResponse();

            response.ResponseHeader = ServerInstance.GetEndpoints(
               request.RequestHeader,
               request.EndpointUrl,
               request.LocaleIds,
               request.ProfileUris,
               out endpoints);

            response.Endpoints = endpoints;

            return response;
        }
예제 #4
0
        private async Task <bool> TryConnect()
        {
            if (connection != null)
            {
                return(true);
            }

            if (string.IsNullOrEmpty(config.Address))
            {
                return(false);
            }

            try {
                var getEndpointsRequest = new GetEndpointsRequest {
                    EndpointUrl = config.Address,
                    ProfileUris = new[] { TransportProfileUris.UaTcpTransport }
                };

                GetEndpointsResponse endpoints = await UaTcpDiscoveryService.GetEndpointsAsync(getEndpointsRequest);

                EndpointDescription[] noSecurityEndpoints = endpoints.Endpoints.Where(e => e.SecurityPolicyUri == SecurityPolicyUris.None).ToArray();

                var(endpoint, userIdentity) = FirstEndpointWithLogin(noSecurityEndpoints);

                if (endpoint == null || userIdentity == null)
                {
                    throw new Exception("No matching endpoint");
                }

                var channel = new UaTcpSessionChannel(
                    this.appDescription,
                    null,
                    userIdentity,
                    endpoint,
                    loggerFactory);

                await channel.OpenAsync();

                this.connection = channel;

                PrintLine($"Opened session with endpoint '{channel.RemoteEndpoint.EndpointUrl}'.");
                PrintLine($"SecurityPolicy: '{channel.RemoteEndpoint.SecurityPolicyUri}'.");
                PrintLine($"SecurityMode: '{channel.RemoteEndpoint.SecurityMode}'.");
                PrintLine($"UserIdentityToken: '{channel.UserIdentity}'.");

                ItemInfo[] nodesNeedingResolve = mapId2Info.Values.Where(n => n.Node == null).ToArray();
                if (nodesNeedingResolve.Length > 0)
                {
                    PrintLine($"Resolving node ids for {nodesNeedingResolve.Length} items...");

                    TranslateBrowsePathsToNodeIdsRequest req = new TranslateBrowsePathsToNodeIdsRequest()
                    {
                        BrowsePaths = nodesNeedingResolve.Select(n => new BrowsePath()
                        {
                            StartingNode = n.StartingNode,
                            RelativePath = n.RelativePath
                        }).ToArray()
                    };
                    TranslateBrowsePathsToNodeIdsResponse resp = await connection.TranslateBrowsePathsToNodeIdsAsync(req);

                    if (resp.Results.Length != nodesNeedingResolve.Length)
                    {
                        LogWarn("Mismatch", "TranslateBrowsePathsToNodeIds failed");
                    }
                    else
                    {
                        for (int i = 0; i < resp.Results.Length; ++i)
                        {
                            BrowsePathResult x = resp.Results[i];
                            if (StatusCode.IsGood(x.StatusCode) && x.Targets.Length > 0)
                            {
                                NodeId id = x.Targets[0].TargetId.NodeId;
                                nodesNeedingResolve[i].Node = id;
                                PrintLine($"Resolved item '{nodesNeedingResolve[i].Name}' => {id}");
                            }
                            else
                            {
                                PrintLine($"Could not resolve item '{nodesNeedingResolve[i].Name}'!");
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception exp) {
                Exception baseExp = exp.GetBaseException() ?? exp;
                LogWarn("OpenChannel", "Open channel error: " + baseExp.Message, dataItem: null, details: baseExp.StackTrace);
                await CloseChannel();

                return(false);
            }
        }
예제 #5
0
        /// <summary>
        /// Initializes the message with a service fault.
        /// </summary>
        public GetEndpointsResponseMessage(ServiceFault ServiceFault)
        {
            this.GetEndpointsResponse = new GetEndpointsResponse();

            if (ServiceFault != null)
            {
                this.GetEndpointsResponse.ResponseHeader = ServiceFault.ResponseHeader;
            }
        }
예제 #6
0
 /// <summary>
 /// Initializes the message with the body.
 /// </summary>
 public GetEndpointsResponseMessage(GetEndpointsResponse GetEndpointsResponse)
 {
     this.GetEndpointsResponse = GetEndpointsResponse;
 }
예제 #7
0
        /// <summary cref="IServiceMessage.CreateResponse" />
        public object CreateResponse(IServiceResponse response)
        {
            GetEndpointsResponse body = response as GetEndpointsResponse;

            if (body == null)
            {
                body = new GetEndpointsResponse();
                body.ResponseHeader = ((ServiceFault)response).ResponseHeader;
            }

            return new GetEndpointsResponseMessage(body);
        }