/// <summary>
        /// Reads the local opc servers.
        /// </summary>
        /// <param name="servers">The servers.</param>
        /// <param name="error">The error.</param>
        /// <param name="exception">The exception.</param>
        /// <returns><c>true</c> if the operation succeeds, <c>false</c> otherwise</returns>
        public bool ReadLocalOpcServers(out OpcServerItems servers, out uint error, out Exception exception)
        {
            servers   = new OpcServerItems();
            error     = ResultCodes.Success;
            exception = null;
            var result = true;

            try
            {
                var opc        = OpcMonitor.CreateOpcClient();
                var opcServers = opc.BrowseServers(string.Empty);

                // The IP address is not used anymore...
                servers.AddRange(opcServers.Select(server => new OpcServerItem(false)
                {
                    Name = server.Description, ClassId = server.ServerClass, IpAddress = "127.0.0.1"
                }));

                opc.Dispose();
            }
            catch (Exception ex)
            {
                Logger.FatalException(this, "Error browsing local OPC servers.", exception);
                servers.Clear();
                error     = ResultCodes.CannotBrowseOpcServers;
                exception = ex;
                DiagnosticsCollection.Instance.AddMessage("Error browsing local OPC servers.");
                DiagnosticsCollection.Instance.AddMessage(exception);
                result = false;
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether the FIS communication is required.
        /// </summary>
        /// <returns><c>true</c> if the FIS communication is required; otherwise, <c>false</c>.</returns>
        /// <remarks>
        /// This method checks all the conditions for which the FIS communication is required or not.
        /// </remarks>
        private bool IsFisCommunicationRequired()
        {
            // The communication with the FIS server is required if some conditions meet.
            // All the conditions are checked here in cascade.

            // Check FIS activation flag.
            if (!this.DataManager.Configuration.FisSettings.Enabled)
            {
                return(false);
            }

            // Check the gateway validity.
            if (!OpcMonitor.IsGatewayValid(this.DataManager.Configuration.Gateway))
            {
                return(false);
            }

            // Check whether a first registration has already been done.
            string user     = null;
            string password = null;

            if (this.FisFirstRegistrationRequired(ref user, ref password))
            {
                return(false);
            }

            // The communication with the FIS Server is active!
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Starts the view monitor.
        /// </summary>
        /// <param name="callbackEndpointAddress">The callback endpoint address.</param>
        /// <param name="measurements">The measurements.</param>
        /// <param name="error">The error.</param>
        /// <param name="exception">The exception.</param>
        /// <returns><c>true</c> if the operation succeeds, <c>false</c> otherwise</returns>
        private bool StartViewMonitor(string callbackEndpointAddress, ConfiguredMeasurements measurements, out uint error, out Exception exception)
        {
            if (this.ViewMonitorScheduler.IsRunning)
            {
                error     = ResultCodes.MonitorAlreadyRunning;
                exception = null;
                return(false);
            }

            if (measurements == null)
            {
                error     = ResultCodes.MissingArgument;
                exception = null;
                return(false);
            }

            // Checks gateway validity.
            if (!OpcMonitor.IsGatewayValid(this.DataManager.Configuration.Gateway))
            {
                error     = ResultCodes.InvalidGateway;
                exception = null;
                return(false);
            }

            // Start monitor.
            this.ViewMonitorScheduler.Start(this.DataManager.Configuration, measurements, ViewMonitorRefreshRate);
            this.ViewMonitorTimeoutHandler.SetCurrentTime();
            this.MonitorCallbackAddress = callbackEndpointAddress;
            error     = ResultCodes.Success;
            exception = null;
            return(true);
        }
 /// <summary>
 /// Stops the monitor.
 /// </summary>
 public void Stop()
 {
     // Check it again, because this method is called also when the service stops,
     // independently on the WCF client actions.
     if (this.IsRunning)
     {
         Logger.Debug(this, "Monitor scheduler stopped.");
         this.OpcMonitor.StopMonitor();
         this.OpcMonitor = null;
     }
 }
        /// <summary>
        /// Reads the opc address space.
        /// </summary>
        /// <param name="serverName">Name of the server.</param>
        /// <param name="opcItem">The opc item.</param>
        /// <param name="error">The error.</param>
        /// <param name="exception">The exception.</param>
        /// <returns><c>true</c> if the operation succeeds, <c>false</c> otherwise</returns>
        public bool ReadOpcAddressSpace(string serverName, out OpcItem opcItem, out uint error, out Exception exception)
        {
            // The root of our tree. This is only to have a unique root in the tree.
            // OPC servers do not always have a unique root.
            opcItem = new OpcItem(true)
            {
                Name = "OPC Address Space"
            };
            error     = ResultCodes.Success;
            exception = null;
            var result = true;

            if (string.IsNullOrEmpty(serverName) || string.IsNullOrWhiteSpace(serverName))
            {
                error = ResultCodes.MissingArgument;
                return(false);
            }

            try
            {
                var opc = OpcMonitor.CreateOpcClient();
                var serverDescriptor = new ServerDescriptor(serverName);
                this.BrowseRecursive(opc, serverDescriptor, null, opcItem);

                opc.Dispose();
            }
            catch (Exception ex)
            {
                Logger.FatalException(this, "Error browsing OPC servers.", exception);
                error     = ResultCodes.BrowseAddressSpaceError;
                exception = ex;
                DiagnosticsCollection.Instance.AddMessage(string.Format("Error browsing OPC server: {0}", serverName));
                DiagnosticsCollection.Instance.AddMessage(exception);
                result = false;
            }

            return(result);
        }