Ejemplo n.º 1
0
        public void BeginConnect()
        {
            if (_synchronizer != null)
            {
                lock (_syncObject)
                {
                    if (ConnectionState != StorageLinkConnectionState.Disconnected)
                    {
                        return;
                    }
                    _connectionState = StorageLinkConnectionState.Connecting;
                }
                OnConnectionStateChanged(new ConnectionStateChangedEventArgs(_connectionState));

                ThreadPool.QueueUserWorkItem(RunCacheLoop);
            }
        }
Ejemplo n.º 2
0
 public ConnectionStateChangedEventArgs(StorageLinkConnectionState state)
 {
     ConnectionState = state;
 }
Ejemplo n.º 3
0
        private void RunCacheLoop(object state)
        {
            try
            {
                if (_service == null)
                {
                    try
                    {
                        _service = new StorageLinkSSLWebService(Username, Password, Host);
                    }
                    catch( UriFormatException e )
                    {
                        savedException = e;
                        ConnectionState = StorageLinkConnectionState.Disconnected;
                        EndConnect();
                    }
                }

                while (!IsConnectionEnding)
                {
                    if (ConnectionState != StorageLinkConnectionState.Connected || RefreshInProgress)
                    {
                        // not connected: try and update entire cache
                        try
                        {
                            Update();
                            Error = string.Empty;
                            ConnectionState = StorageLinkConnectionState.Connected;
                        }
                        catch (SoapException e)
                        {
                            Error = ConvertSoapException(e).Message;
                            ConnectionState = StorageLinkConnectionState.Disconnected;
                        }
                        catch (WebException e)
                        {
                            Error = e.Message;
                            ConnectionState = StorageLinkConnectionState.Disconnected;
                        }
                        RefreshInProgress = false;
                    }

                    if (ConnectionState == StorageLinkConnectionState.Connected)
                    {
                        try
                        {
                            _listener.ProcessEvents();
                        }
                        catch (SoapException e)
                        {
                            Error = ConvertSoapException(e).Message;
                            ConnectionState = StorageLinkConnectionState.Disconnected;
                        }
                        catch (WebException e)
                        {
                            Error = e.Message;
                            ConnectionState = StorageLinkConnectionState.Disconnected;
                        }
                    }

                    Thread.Sleep(ConnectionState == StorageLinkConnectionState.Connected ? 2000 : 5000);
                }
            }
            finally
            {
                if (_service != null)
                {
                    _service.Dispose();
                    _service = null;
                }
                lock (_syncObject)
                {
                    _ending = false;
                    _connectionState = StorageLinkConnectionState.Disconnected;
                }
                OnConnectionStateChanged(new ConnectionStateChangedEventArgs(_connectionState));
            }
        }
Ejemplo n.º 4
0
        public void BeginConnect()
        {
            if (_synchronizer != null)
            {
                lock (_syncObject)
                {
                    if (ConnectionState != StorageLinkConnectionState.Disconnected)
                    {
                        return;
                    }
                    _connectionState = StorageLinkConnectionState.Connecting;
                }
                OnConnectionStateChanged(new ConnectionStateChangedEventArgs(_connectionState));

                ThreadPool.QueueUserWorkItem(RunCacheLoop);
       
            }
        }
Ejemplo n.º 5
0
 public ConnectionStateChangedEventArgs(StorageLinkConnectionState state)
 {
     ConnectionState = state;
 }
Ejemplo n.º 6
0
        private void RunCacheLoop(object state)
        {
            try
            {
                if (_service == null)
                {
                    try
                    {
                        _service = new StorageLinkSSLWebService(Username, Password, Host);
                    }
                    catch (UriFormatException e)
                    {
                        savedException  = e;
                        ConnectionState = StorageLinkConnectionState.Disconnected;
                        EndConnect();
                    }
                }

                while (!IsConnectionEnding)
                {
                    if (ConnectionState != StorageLinkConnectionState.Connected || RefreshInProgress)
                    {
                        // not connected: try and update entire cache
                        try
                        {
                            Update();
                            Error           = string.Empty;
                            ConnectionState = StorageLinkConnectionState.Connected;
                        }
                        catch (SoapException e)
                        {
                            Error           = ConvertSoapException(e).Message;
                            ConnectionState = StorageLinkConnectionState.Disconnected;
                        }
                        catch (WebException e)
                        {
                            Error           = e.Message;
                            ConnectionState = StorageLinkConnectionState.Disconnected;
                        }
                        RefreshInProgress = false;
                    }

                    if (ConnectionState == StorageLinkConnectionState.Connected)
                    {
                        try
                        {
                            _listener.ProcessEvents();
                        }
                        catch (SoapException e)
                        {
                            Error           = ConvertSoapException(e).Message;
                            ConnectionState = StorageLinkConnectionState.Disconnected;
                        }
                        catch (WebException e)
                        {
                            Error           = e.Message;
                            ConnectionState = StorageLinkConnectionState.Disconnected;
                        }
                    }

                    Thread.Sleep(ConnectionState == StorageLinkConnectionState.Connected ? 2000 : 5000);
                }
            }
            finally
            {
                if (_service != null)
                {
                    _service.Dispose();
                    _service = null;
                }
                lock (_syncObject)
                {
                    _ending          = false;
                    _connectionState = StorageLinkConnectionState.Disconnected;
                }
                OnConnectionStateChanged(new ConnectionStateChangedEventArgs(_connectionState));
            }
        }