Exemple #1
0
        //======================================================================
        // Constructor

        /// <summary>
        /// Initializes a new instance of a subscription.
        /// </summary>
        internal Subscription(
            Server server,
            OpcXml.Da10.Service proxy,
            SubscriptionState state,
            int filters)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }
            if (proxy == null)
            {
                throw new ArgumentNullException("proxy");
            }

            m_server  = server;
            m_proxy   = proxy;
            m_filters = filters;
            m_state   = (state != null)?(SubscriptionState)state.Clone():new SubscriptionState();

            if (m_state.Name == null || m_state.Name == "")
            {
                lock (typeof(Subscription))
                {
                    m_state.Name = String.Format("Subscription{0,3:000}", ++m_counter);
                }
            }
        }
        //======================================================================
        // Initialization

        /// <summary>
        /// Connects to the server with the specified URL and credentials.
        /// </summary>
        public virtual void Initialize(URL url, ConnectData connectData)
        {
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            lock (this)
            {
                try
                {
                    m_proxy             = new OpcXml.Da10.Service();
                    m_proxy.Credentials = (connectData != null)?connectData.GetCredential(null, null):null;
                    m_proxy.Url         = url.ToString();
                    m_proxy.Proxy       = (connectData != null)?connectData.GetProxy():new WebProxy();

                    m_proxy.UnsafeAuthenticatedConnectionSharing = true;
                }
                catch (Exception e)
                {
                    string msg = e.Message;
                }

                try
                {
                    GetStatus();
                }
                catch (WebException e)
                {
                    if (e.Status == WebExceptionStatus.ConnectFailure)
                    {
                        throw new ConnectFailedException(e);
                    }

                    throw new AccessDeniedException(e);
                }

                m_url = (URL)url.Clone();
            }
        }