/// <summary>
        /// Updates the list of servers displayed in the control.
        /// </summary>
        private void OnUpdateServers(object state)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new WaitCallback(OnUpdateServers), state);
                return;
            }

            ItemsLV.Items.Clear();

            ServerOnNetworkCollection servers = state as ServerOnNetworkCollection;

            if (servers != null)
            {
                foreach (ServerOnNetwork server in servers)
                {
                    AddItem(server);
                }
            }

            if (ItemsLV.Items.Count == 0)
            {
                this.Instructions = Utils.Format("No servers to display.");
            }

            AdjustColumns();
        }
        /// <summary>
        /// Fetches the network servers from the discovery server.
        /// </summary>
        private bool DiscoverServersOnNetwork(Uri discoveryUrl)
        {
            // use a short timeout.
            EndpointConfiguration configuration = EndpointConfiguration.Create(m_configuration);

            configuration.OperationTimeout = m_discoveryTimeout;
            DiscoveryClient client = null;

            try
            {
                client = DiscoveryClient.Create(
                    discoveryUrl,
                    BindingFactory.Create(m_configuration, m_configuration.CreateMessageContext()),
                    EndpointConfiguration.Create(m_configuration));

                uint             startingRecordId       = (uint)0;
                uint             maxRecordsToReturn     = (uint)0;
                StringCollection serverCapabilityFilter = new StringCollection();
                DateTime         lastCounterResetTime   = DateTime.MinValue;

                try
                {
                    startingRecordId   = (uint)m_startingRecordIdUpDown.Value;
                    maxRecordsToReturn = (uint)m_maxRecordsToReturnUpDown.Value;

                    if (!String.IsNullOrEmpty(m_capabilityFilterTextBox.Text))
                    {
                        serverCapabilityFilter = new StringCollection(m_capabilityFilterTextBox.Text.Split(','));
                    }
                }
                catch (Exception e)
                {
                    Utils.Trace("Error retrieving FindServersOnNetwork paramters. Error=({1}){0}", e.Message, e.GetType());
                    return(false);
                }

                ServerOnNetworkCollection servers = client.FindServersOnNetwork(startingRecordId, maxRecordsToReturn, serverCapabilityFilter, out lastCounterResetTime);
                m_discoveryUrl = discoveryUrl.ToString();
                OnUpdateServers(servers);
                return(true);
            }
            catch (Exception e)
            {
                Utils.Trace("DISCOVERY ERROR - Could not fetch servers from url: {0}. Error=({2}){1}", discoveryUrl, e.Message, e.GetType());
                return(false);
            }
            finally
            {
                if (client != null)
                {
                    client.Close();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Invokes the FindServersOnNetwork service.
        /// </summary>
        public virtual ResponseHeader FindServersOnNetwork(
            RequestHeader requestHeader,
            uint startingRecordId,
            uint maxRecordsToReturn,
            StringCollection serverCapabilityFilter,
            out DateTime lastCounterResetTime,
            out ServerOnNetworkCollection servers)
        {
            lastCounterResetTime = DateTime.MinValue;
            servers = null;

            ValidateRequest(requestHeader);

            // Insert implementation.

            return(CreateResponse(requestHeader, StatusCodes.BadServiceUnsupported));
        }
예제 #4
0
        /// <summary>
        /// Invokes the FindServersOnNetwork service.
        /// </summary>
        /// <param name="startingRecordId"></param>
        /// <param name="maxRecordsToReturn"></param>
        /// <param name="serverCapabilityFilter"></param>
        /// <param name="lastCounterResetTime"></param>
        /// <returns></returns>
        public virtual ServerOnNetworkCollection FindServersOnNetwork(
            uint startingRecordId,
            uint maxRecordsToReturn,
            StringCollection serverCapabilityFilter,
            out DateTime lastCounterResetTime)
        {
            ServerOnNetworkCollection servers = null;

            FindServersOnNetwork(
                null,
                startingRecordId,
                maxRecordsToReturn,
                serverCapabilityFilter,
                out lastCounterResetTime,
                out servers);

            return(servers);
        }
예제 #5
0
        /// <summary>
        /// 发现网络中的服务端(主要为其他PC端获取本机的服务列表使用)
        /// </summary>
        /// <param name="requestHeader"></param>
        /// <param name="startingRecordId"></param>
        /// <param name="maxRecordsToReturn"></param>
        /// <param name="serverCapabilityFilter"></param>
        /// <param name="lastCounterResetTime"></param>
        /// <param name="servers"></param>
        /// <returns></returns>
        public override ResponseHeader FindServersOnNetwork(
            RequestHeader requestHeader,
            uint startingRecordId,
            uint maxRecordsToReturn,
            StringCollection serverCapabilityFilter,
            out DateTime lastCounterResetTime,
            out ServerOnNetworkCollection servers)
        {
            lastCounterResetTime = DateTime.MinValue;
            servers = null;

            ValidateRequest(requestHeader);

            try
            {
                lock (_serverTable)
                {
                    uint rId = 0;
                    foreach (var item in _serverTable)
                    {
                        rId++;
                        servers.Add(new ServerOnNetwork()
                        {
                            DiscoveryUrl       = item.DiscoveryUrls.FirstOrDefault(),
                            RecordId           = rId,
                            ServerName         = item.ServerNames.FirstOrDefault()?.Text,
                            ServerCapabilities = { "Realtime Data", "Events & Alarms" },
                        });
                    }
                }

                lastCounterResetTime = DateTime.Now;
                return(CreateResponse(requestHeader, StatusCodes.Good));
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("查找网络中的服务FindServersOnNetwork()时触发异常:" + ex.Message);
                Console.ResetColor();
            }
            return(CreateResponse(requestHeader, StatusCodes.BadUnexpectedError));
        }
        private void OnFindServersOnNetworkComplete(IAsyncResult result)
        {
            FindServersOnNetworkData data = result.AsyncState as FindServersOnNetworkData;

            try
            {
                DateTime lastCounterResetTime;
                ServerOnNetworkCollection servers = null;
                data.DiscoveryClient.EndFindServersOnNetwork(result, out lastCounterResetTime, out servers);

                data.LastCounterResetTime = lastCounterResetTime;
                data.Servers = servers;
                data.OperationCompleted();
            }
            catch (Exception e)
            {
                data.Exception = e;
                data.OperationCompleted();
            }
        }
예제 #7
0
        /// <summary>
        /// Invokes the FindServersOnNetwork service.
        /// </summary>
        public virtual ResponseHeader FindServersOnNetwork(
            RequestHeader                 requestHeader,
            uint                          startingRecordId,
            uint                          maxRecordsToReturn,
            StringCollection              serverCapabilityFilter,
            out DateTime                  lastCounterResetTime,
            out ServerOnNetworkCollection servers)
        {
            lastCounterResetTime = DateTime.MinValue;
            servers = null;

            ValidateRequest(requestHeader);

            // Insert implementation.

            return CreateResponse(requestHeader, StatusCodes.BadServiceUnsupported);
        }
예제 #8
0
 public override ResponseHeader FindServersOnNetwork(RequestHeader requestHeader, uint startingRecordId, uint maxRecordsToReturn, StringCollection serverCapabilityFilter, out DateTime lastCounterResetTime, out ServerOnNetworkCollection servers)
 {
     return(base.FindServersOnNetwork(requestHeader, startingRecordId, maxRecordsToReturn, serverCapabilityFilter, out lastCounterResetTime, out servers));
 }
예제 #9
0
        /// <summary>
        /// Finishes an asynchronous invocation of the FindServersOnNetwork service.
        /// </summary>
        public ResponseHeader EndFindServersOnNetwork(
            IAsyncResult                  result,
            out DateTime                  lastCounterResetTime,
            out ServerOnNetworkCollection servers)
        {
            FindServersOnNetworkResponse response = null;

            try
            {
                if (UseTransportChannel)
                {
                    IServiceResponse genericResponse = TransportChannel.EndSendRequest(result);

                    if (genericResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    ValidateResponse(genericResponse.ResponseHeader);
                    response = (FindServersOnNetworkResponse)genericResponse;
                }
                else
                {
                    FindServersOnNetworkResponseMessage responseMessage = InnerChannel.EndFindServersOnNetwork(result);

                    if (responseMessage == null || responseMessage.FindServersOnNetworkResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    response = responseMessage.FindServersOnNetworkResponse;
                    ValidateResponse(response.ResponseHeader);
                }

                lastCounterResetTime = response.LastCounterResetTime;
                servers              = response.Servers;
            }
            finally
            {
                RequestCompleted(null, response, "FindServersOnNetwork");
            }

            return response.ResponseHeader;
        }
예제 #10
0
        /// <summary>
        /// Invokes the FindServersOnNetwork service.
        /// </summary>
        public virtual ResponseHeader FindServersOnNetwork(
            RequestHeader                 requestHeader,
            uint                          startingRecordId,
            uint                          maxRecordsToReturn,
            StringCollection              serverCapabilityFilter,
            out DateTime                  lastCounterResetTime,
            out ServerOnNetworkCollection servers)
        {
            FindServersOnNetworkRequest request = new FindServersOnNetworkRequest();
            FindServersOnNetworkResponse response = null;

            request.RequestHeader          = requestHeader;
            request.StartingRecordId       = startingRecordId;
            request.MaxRecordsToReturn     = maxRecordsToReturn;
            request.ServerCapabilityFilter = serverCapabilityFilter;

            UpdateRequestHeader(request, requestHeader == null, "FindServersOnNetwork");

            try
            {
                if (UseTransportChannel)
                {
                    IServiceResponse genericResponse = TransportChannel.SendRequest(request);

                    if (genericResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    ValidateResponse(genericResponse.ResponseHeader);
                    response = (FindServersOnNetworkResponse)genericResponse;
                }
                else
                {
                    FindServersOnNetworkResponseMessage responseMessage = InnerChannel.FindServersOnNetwork(new FindServersOnNetworkMessage(request));

                    if (responseMessage == null || responseMessage.FindServersOnNetworkResponse == null)
                    {
                        throw new ServiceResultException(StatusCodes.BadUnknownResponse);
                    }

                    response = responseMessage.FindServersOnNetworkResponse;
                    ValidateResponse(response.ResponseHeader);
                }

                lastCounterResetTime = response.LastCounterResetTime;
                servers              = response.Servers;
            }
            finally
            {
                RequestCompleted(request, response, "FindServersOnNetwork");
            }

            return response.ResponseHeader;
        }