Example #1
0
        /// <summary>
        /// Called to connect to a server.
        /// </summary>
        public void OnConnect()
        {
            if (server_ == null)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            try
            {
                OpcUserIdentity credentials = null;

                do
                {
                    try
                    {
                        server_.ForceDa20Usage = forceDa20Usage_;
                        server_.Connect(new OpcConnectData(credentials, mProxy_));
                        break;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }

                    credentials = new NetworkCredentialsDlg().ShowDialog(credentials);
                }while (credentials != null);

                // select all filters by default.
                server_.SetResultFilters((int)TsCDaResultFilter.All);

                // initialize controls.
                statusCtrl_.Start(server_);
                updatesCtrl_.Initialize(server_);
                subscriptionCtrl_.Initialize(server_);
                selectServerCtrl_.OnConnect(server_);

                // register for shutdown events.
                server_.ServerShutdownEvent += Server_ServerShutdown;

                // save settings.
                SaveSettings();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                TsCCpxComplexTypeCache.Server = server_ = null;
            }

            Cursor = Cursors.Default;
        }
Example #2
0
        /// <summary>
        /// Called to connect to a server.
        /// </summary>
        public void OnConnect()
        {
            Cursor = Cursors.WaitCursor;

            try
            {
                OpcUserIdentity credentials = null;

                do
                {
                    try
                    {
                        m_server.ForceDa20Usage = _forceDa20Usage;
                        m_server.Connect(new OpcConnectData(credentials, m_proxy));
                        break;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }

                    credentials = new NetworkCredentialsDlg().ShowDialog(credentials);
                }while (credentials != null);

                // select all filters by default.
                m_server.SetResultFilters((int)TsCDaResultFilter.All);

                // initialize controls.
                StatusCTRL.Start(m_server);
                UpdatesCTRL.Initialize(m_server);
                SubscriptionCTRL.Initialize(m_server);
                SelectServerCTRL.OnConnect(m_server);

                // register for shutdown events.
                m_server.ServerShutdownEvent += new OpcServerShutdownEventHandler(Server_ServerShutdown);

                // save settings.
                SaveSettings();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                TsCCpxComplexTypeCache.Server = m_server = null;
            }

            Cursor = Cursors.Default;
        }
Example #3
0
        /// <summary>
        /// Called to connect to a target.
        /// </summary>
        public void OnConnectTarget(OpcServer server)
        {
            if (m_target != null)
            {
                m_target.Disconnect();
                m_target.Dispose();
                m_target = null;
            }

            // use the specified server object directly.
            m_target = (TsCDaServer)server;

            Cursor = Cursors.WaitCursor;

            try
            {
                OpcUserIdentity credentials = null;

                do
                {
                    try
                    {
                        m_target.Connect(new OpcConnectData(credentials, m_proxy));
                        break;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }

                    credentials = new NetworkCredentialsDlg().ShowDialog(credentials);
                }while (credentials != null);

                // select all filters by default.
                m_target.SetResultFilters((int)TsCDaResultFilter.All);

                // initialize controls.
                SelectTargetCTRL.OnConnect(m_target);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                m_target = null;
            }

            Cursor = Cursors.Default;
        }
        /// <summary>
        /// Called to connect to a server.
        /// </summary>
        public void OnConnect()
        {
            if (server_ == null)
            {
                return;
            }
            Cursor = Cursors.WaitCursor;

            try
            {
                OpcUserIdentity credentials = null;

                do
                {
                    try
                    {
                        server_.Connect(new OpcConnectData(credentials, proxy_));
                        break;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }

                    credentials = new NetworkCredentialsDlg().ShowDialog(credentials);
                }while (credentials != null);

                // initialize controls.
                statusCtrl_.Start(server_);
                selectServerCtrl_.OnConnect(server_);
                trendsCtrl_.Initialize(server_);

                // register for shutdown events.
                server_.ServerShutdownEvent += new OpcServerShutdownEventHandler(Server_ServerShutdown);

                // save settings.
                SaveSettings();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                server_ = null;
            }

            Cursor = Cursors.Default;
        }
        internal bool CanWrite(OpcVariableNode node, OpcUserIdentity sessionIdentity)
        {
            var entries = this.AccessControl.Entries;

            foreach (var entry in entries)
            {
                if (entry.Principal.Identity is SystemIdentity serverIdentity)
                {
                    if (serverIdentity.DisplayName == sessionIdentity.DisplayName)
                    {
                        return(entry.IsAllowed(OpcRequestType.Write) &&
                               serverIdentity.IsAllowed(node.Id.ValueAsString));
                    }
                }
            }

            return(false);
        }
        public CDSHelper()
        {
            try
            {
                if (File.Exists(_CDSConfigurationFilename))
                {
                    dynamic Entries = JObject.Parse(File.ReadAllText(_CDSConfigurationFilename));
                    string  apiURL  = Entries.APIURL;
                    if (!apiURL.StartsWith("http"))
                    {
                        throw new Exception("invalid URL");
                    }
                    if (!apiURL.EndsWith("/"))
                    {
                        apiURL = apiURL + "/";
                    }

                    _APIURL           = apiURL;
                    _IoTDeviceID      = Entries.IoTDeviceID;
                    _IoTDevicePW      = Entries.IoTDevicePW;
                    _CompanyId        = Entries.CompanyId;
                    _EquipmentId      = Entries.EquipmentId;
                    _MessageCatalogId = Entries.MessageCatalogId;

                    if (Entries.OPCUAServer != null)
                    {
                        foreach (var uaServer in Entries.OPCUAServer)
                        {
                            OpcUserIdentity.AddIdentity((string)uaServer.EndpointURL, (string)uaServer.userIdentity.id, (string)uaServer.userIdentity.password);
                        }
                    }
                }
                else
                {
                    throw new Exception("Can't load File:CDSConfiguration.json");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
            ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); });
        }
Example #7
0
        /// <summary>
        /// Called to connect to a server.
        /// </summary>
        public void OnConnect()
        {
            Cursor = Cursors.WaitCursor;

            try
            {
                OpcUserIdentity credentials = null;

                do
                {
                    try
                    {
                        m_server.Connect(new OpcConnectData(credentials, m_proxy));
                        break;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }

                    credentials = new NetworkCredentialsDlg().ShowDialog(credentials);
                }while (credentials != null);

                // initialize controls.
                StatusCTRL.Start(m_server);
                SelectServerCTRL.OnConnect(m_server);
                TrendsCTRL.Initialize(m_server);

                // register for shutdown events.
                m_server.ServerShutdownEvent += new OpcServerShutdownEventHandler(Server_ServerShutdown);

                // save settings.
                SaveSettings();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                m_server = null;
            }

            Cursor = Cursors.Default;
        }
        /// <summary>
        /// Displays the network credentials in a model dialog.
        /// </summary>
        public OpcUserIdentity ShowDialog(OpcUserIdentity userIdentity)
        {
            if (userIdentity != null)
            {
                UserNameTB.Text = userIdentity.Username;
                PasswordTB.Text = userIdentity.Password;
                DomainTB.Text   = userIdentity.Domain;
            }

            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            if (DomainTB.Text == null || DomainTB.Text == "")
            {
                return(new OpcUserIdentity(UserNameTB.Text, PasswordTB.Text));
            }

            return(new OpcUserIdentity(UserNameTB.Text, PasswordTB.Text));
        }
Example #9
0
        /// <summary>
        /// Connects to the specified COM server.
        /// </summary>
        public static object Connect(OpcUrl url, OpcConnectData connectData)
        {
            // parse path to find prog id and clsid.
            string progID = url.Path;
            string clsid  = null;

            int index = url.Path.IndexOf('/');

            if (index >= 0)
            {
                progID = url.Path.Substring(0, index);
                clsid  = url.Path.Substring(index + 1);
            }

            // look up prog id if clsid not specified in the url.
            Guid guid;

            if (clsid == null)
            {
                // use OpcEnum to lookup the prog id.
                guid = new ServerEnumerator().CLSIDFromProgID(progID, url.HostName, connectData);

                // check if prog id is actually a clsid string.
                if (guid == Guid.Empty)
                {
                    try
                    {
                        guid = new Guid(progID);
                    }
                    catch
                    {
                        throw new OpcResultException(new OpcResult((int)OpcResult.CO_E_CLASSSTRING.Code, OpcResult.FuncCallType.SysFuncCall, null), String.Format("Could not connect to server {0}", progID));
                    }
                }
            }

            // convert clsid string to a guid.
            else
            {
                try
                {
                    guid = new Guid(clsid);
                }
                catch
                {
                    throw new OpcResultException(new OpcResult((int)OpcResult.CO_E_CLASSSTRING.Code, OpcResult.FuncCallType.SysFuncCall, null), String.Format("Could not connect to server {0}", progID));
                }
            }

            // get the credentials.
            OpcUserIdentity credentials = (connectData != null) ? connectData.UserIdentity : null;

            // instantiate the server using CoCreateInstanceEx.
            if (connectData == null || connectData.LicenseKey == null)
            {
                try
                {
                    return(Utilities.Interop.CreateInstance(guid, url.HostName, credentials));
                }
                catch (Exception e)
                {
                    throw new OpcResultException(OpcResult.CO_E_CLASSSTRING, e.Message, e);
                }
            }

            // instantiate the server using IClassFactory2.
            else
            {
                try
                {
                    return(null);
                    //return Technosoftware.DaAeHdaClient.Utilities.Interop.CreateInstanceWithLicenseKey(guid, url.HostName, credentials, connectData.LicenseKey);
                }
                catch (Exception e)
                {
                    throw new OpcResultException(OpcResult.CO_E_CLASSSTRING, e.Message, e);
                }
            }
        }