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));
            }
        }
Example #2
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));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StorageLinkConnection"/> class. This constructor allows a mock
 /// web service to be passed in.
 /// </summary>
 /// <param name="synchronizer">The synchronizer used for synchronizing the cache update. Usually <see cref="MainWindow"/>.</param>
 /// <param name="service">The web service.</param>
 public StorageLinkConnection(ISynchronizeInvoke synchronizer, IStorageLinkWebService service) :
     this(synchronizer, service.Host, service.Username, service.Password)
 {
     Util.ThrowIfParameterNull(service, "service");
     _service = service;
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StorageLinkConnection"/> class. This constructor allows a mock
 /// web service to be passed in.
 /// </summary>
 /// <param name="synchronizer">The synchronizer used for synchronizing the cache update. Usually <see cref="MainWindow"/>.</param>
 /// <param name="service">The web service.</param>
 public StorageLinkConnection(ISynchronizeInvoke synchronizer, IStorageLinkWebService service) :
     this(synchronizer, service.Host, service.Username, service.Password)
 {
     Util.ThrowIfParameterNull(service, "service");
     _service = service;
 }