示例#1
0
        //======================================================================
        // GetStatus

        /// <summary>
        /// Returns the current server status.
        /// </summary>
        /// <returns>The current server status.</returns>
        public ServerStatus GetStatus()
        {
            lock (this)
            {
                Opc.Da.ServerStatus status = m_cache.GetStatus();
                status.StatusInfo     = m_cache.GetString(status.StatusInfo, m_culture.Name);
                status.LastUpdateTime = DateTimeProvider.GetCurrentTime();
                status.CurrentTime    = DateTimeProvider.GetCurrentTime();

                return(status);
            }
        }
        private Connection CreateConnection(string serverUrl)
        {
            ServiceManager.LogMessage("Connecting to {0}...", serverUrl);
            URL url = new URL(serverUrl);

            Opc.Da.Server server = null;
            try
            {
                server = new Opc.Da.Server(new OpcCom.Factory(), url);
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                try
                {
                    server.Connect();
                    Opc.Da.ServerStatus serverStatus = server.GetStatus();
                    if (serverStatus.ServerState != Opc.Da.serverState.running)
                    {
                        throw new Exception(String.Format("Bad server state ({0})", serverStatus.ServerState));
                    }
                    Connection connection = new Connection(serverUrl, server);
                    server = null;
                    stopwatch.Stop();
                    ServiceManager.LogMessage("Successful created new connection {0}: {1} ({2} ms)",
                                              connection.GetUID(), serverUrl, stopwatch.ElapsedMilliseconds);
                    Counter counter = counters[serverUrl];
                    Interlocked.Increment(ref counter.numConnections);
                    return(connection);
                }
                catch (Exception ex)
                {
                    stopwatch.Stop();
                    ServiceManager.LogMessage("Failed create new connection to {0}: {1} ({2} ms)",
                                              serverUrl, ex.Message, stopwatch.ElapsedMilliseconds);
                    throw new FaultException(ex.Message, new FaultCode("E_FAIL"));
                }
            }
            finally
            {
                if (server != null)
                {
                    if (server.IsConnected)
                    {
                        server.Disconnect();
                    }
                    server.Dispose();
                }
            }
        }
示例#3
0
        //======================================================================
        // GetStatus

        /// <summary>
        /// Returns the current server status.
        /// </summary>
        /// <returns>The current server status.</returns>
        public ServerStatus GetStatus()
        {
            if (m_server == null)
            {
                throw new NotConnectedException();
            }

            ServerStatus status = ((IServer)m_server).GetStatus();

            if (status.StatusInfo == null)
            {
                status.StatusInfo = GetString("serverState." + status.ServerState.ToString());
            }

            return(status);
        }
示例#4
0
        /// <summary>
        /// Copies the current status into object passed in.
        /// </summary>
        Opc.Da.ServerStatus ICacheServer.GetStatus()
        {
            lock (this)
            {
                if (m_disposed)
                {
                    throw new ObjectDisposedException("Opc.Da.Cache");
                }

                Opc.Da.ServerStatus status = new Opc.Da.ServerStatus();

                status.VendorInfo     = m_status.VendorInfo;
                status.ProductVersion = m_status.ProductVersion;
                status.ServerState    = m_status.ServerState;
                status.StatusInfo     = m_status.StatusInfo;
                status.StartTime      = m_status.StartTime;
                status.LastUpdateTime = m_status.LastUpdateTime;
                status.CurrentTime    = DateTimeProvider.GetCurrentTime();

                return(status);
            }
        }
示例#5
0
        /// <summary>
        /// Initializes the cache when the first server is created.
        /// </summary>
        public virtual void Initialize()
        {
            lock (this)
            {
                if (m_disposed) throw new ObjectDisposedException("Opc.Da.Cache");

                // create the resource manager.
                m_resourceManager  = new ResourceManager("OpcDa.Resources.Strings", Assembly.GetExecutingAssembly());

                // initialize status.
                m_status = new ServerStatus();

                m_status.VendorInfo     = ((AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyDescriptionAttribute))).Description;
                m_status.ProductVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                m_status.ServerState    = serverState.running;
                m_status.StatusInfo     = serverState.running.ToString();
                m_status.StartTime      = DateTime.Now;
                m_status.LastUpdateTime = DateTime.MinValue;
                m_status.CurrentTime    = DateTime.Now;

                // start the cache thread.
                ThreadPool.QueueUserWorkItem(new WaitCallback(OnUpdate));
            }
        }
 public void Ping()
 {
     localId          = server.GetLocale();
     supportedLocales = server.GetSupportedLocales();
     status           = server.GetStatus();
 }