コード例 #1
0
        private void RenewConnection()
        {
            if (disposed)
            {
                return;
            }

            if (Interlocked.CompareExchange(ref isReconnecting, Reconnecting, Idle) == Reconnecting)
            {
                //we already started the reconnection process
                return;
            }

            DisposeConnection();

            Time.Delay(TimeSpan.FromSeconds(15))
            .ContinueWith(_ => EstablishConnection())
            .Unwrap()
            .ObserveException()
            .ContinueWith(task =>
            {
                Interlocked.Exchange(ref isReconnecting, Idle);

                if (task.IsFaulted == false)
                {
                    return;
                }

                foreach (var value in Counters.ValuesSnapshot)
                {
                    value.Error(task.Exception);
                }
                Counters.Clear();
            });
        }
コード例 #2
0
        public static string GetActiveWindowFile()
        {
            var id = GetForegroundWindow().ToInt64();

            if (_files.TryGetValue(id, out var file))
            {
                return(file);
            }

            _files.Clear();
            foreach (var p in Process.GetProcesses())
            {
                using (p)
                    try
                    {
                        _files[p.MainWindowHandle.ToInt64()] = p.MainModule?.FileName ?? string.Empty;
                    }
                    catch (Exception)
                    {
                        _files[p.MainWindowHandle.ToInt64()] = string.Empty;
                    }
            }

            if (_files.TryGetValue(id, out file))
            {
                return(file);
            }
            return(string.Empty);
        }
コード例 #3
0
        public void Dispose()
        {
            foreach (var confirmation in _confirmations)
            {
                confirmation.Value.TrySetCanceled();
            }

            _cts.Cancel();

            _client?.Dispose();

            _counters.Clear();

            try
            {
                _task.Wait();
            }
            catch
            {
                // we're disposing the document store
                // nothing we can do here
            }

            ConnectionStatusChanged?.Invoke(this, EventArgs.Empty);
            ConnectionStatusChanged -= OnConnectionStatusChanged;

            _onDispose?.Invoke();
        }
コード例 #4
0
ファイル: AbstractLandlord.cs プロジェクト: xinix00/ravendb
        public void Dispose()
        {
            Locks.TryAdd(DisposingLock);

            var exceptionAggregator = new ExceptionAggregator(Logger, "Failure to dispose landlord");

            exceptionAggregator.Execute(() =>
            {
                foreach (var databaseTransportState in ResourseTransportStates)
                {
                    databaseTransportState.Value.Dispose();
                }
            });

            // shut down all databases in parallel, avoid having to wait for each one
            Parallel.ForEach(ResourcesStoresCache.Values, dbTask =>
            {
                if (dbTask.IsCompleted == false)
                {
                    dbTask.ContinueWith(task =>
                    {
                        if (task.Status != TaskStatus.RanToCompletion)
                        {
                            return;
                        }

                        try
                        {
                            task.Result.Dispose();
                        }
                        catch (Exception e)
                        {
                            Logger.WarnException("Failure in deferred disposal of a database", e);
                        }
                    });
                }
                else if (dbTask.Status == TaskStatus.RanToCompletion)
                {
                    exceptionAggregator.Execute(dbTask.Result.Dispose);
                }
                // there is no else, the db is probably faulted
            });
            ResourcesStoresCache.Clear();

            try
            {
                ResourceSemaphore.Dispose();
            }
            catch (Exception e)
            {
                Logger.WarnException("Failed to dispose resource semaphore", e);
            }
        }
コード例 #5
0
        public void Dispose()
        {
            _client?.Dispose();

            _cts.Cancel();

            _counters.Clear();

            _task.Wait();

            ConnectionStatusChanged?.Invoke(this, EventArgs.Empty);
            ConnectionStatusChanged -= OnConnectionStatusChanged;

            _onDispose?.Invoke();
        }
コード例 #6
0
ファイル: DatabaseChanges.cs プロジェクト: zuhuizou/DotNetDAL
        public void Dispose()
        {
            foreach (var confirmation in _confirmations)
            {
                confirmation.Value.TrySetCanceled();
            }

            _client?.Dispose();

            _cts.Cancel();

            _counters.Clear();

            _task.Wait();

            ConnectionStatusChanged?.Invoke(this, EventArgs.Empty);
            ConnectionStatusChanged -= OnConnectionStatusChanged;

            _onDispose?.Invoke();
        }
コード例 #7
0
        private void RenewConnection()
        {
            Time.Delay(TimeSpan.FromSeconds(15))
            .ContinueWith(_ => EstablishConnection())
            .Unwrap()
            .ObserveException()
            .ContinueWith(task =>
            {
                if (task.IsFaulted == false)
                {
                    return;
                }

                foreach (var keyValuePair in counters)
                {
                    keyValuePair.Value.Error(task.Exception);
                }
                counters.Clear();
            });
        }
コード例 #8
0
        public void OnError(Exception error)
        {
            if (reconnectAttemptsRemaining <= 0)
            {
                return;
            }

            try
            {
                EstablishConnection().ObserveException().Wait();
            }
            catch (Exception exception)
            {
                foreach (var subject in subjects)
                {
                    subject.Value.OnError(exception);
                }
                subjects.Clear();
            }
        }
コード例 #9
0
ファイル: RemoteDatabaseChanges.cs プロジェクト: SHSE/ravendb
        public void OnError(Exception error)
        {
            logger.ErrorException("Got error from server connection", error);

            EstablishConnection()
            .ObserveException()
            .ContinueWith(task =>
            {
                if (task.IsFaulted == false)
                {
                    return;
                }

                foreach (var keyValuePair in counters)
                {
                    keyValuePair.Value.Error(task.Exception);
                }
                counters.Clear();
            });
        }
コード例 #10
0
        public static string GetActiveWindowName()
        {
            var id = GetForegroundWindow().ToInt64();

            if (_names.TryGetValue(id, out var name))
            {
                return(name);
            }

            _names.Clear();
            foreach (var p in Process.GetProcesses())
            {
                using (p)
                    _names[p.MainWindowHandle.ToInt64()] = p.MainWindowTitle;
            }

            if (_names.TryGetValue(id, out name))
            {
                return(name);
            }
            return(string.Empty);
        }
コード例 #11
0
        public void Dispose()
        {
            disposerLock.EnterWriteLock();
            try
            {
                TenantDatabaseModified.Occured -= TenantDatabaseRemoved;
                var exceptionAggregator = new ExceptionAggregator(logger, "Could not properly dispose of HttpServer");
                exceptionAggregator.Execute(() =>
                {
                    if (serverTimer != null)
                    {
                        serverTimer.Dispose();
                    }
                });
                exceptionAggregator.Execute(() =>
                {
                    if (listener != null && listener.IsListening)
                    {
                        listener.Stop();
                    }
                });
                disposed = true;

                exceptionAggregator.Execute(() =>
                {
                    using (ResourcesStoresCache.WithAllLocks())
                    {
                        // shut down all databases in parallel, avoid having to wait for each one
                        Parallel.ForEach(ResourcesStoresCache.Values, dbTask =>
                        {
                            if (dbTask.IsCompleted == false)
                            {
                                dbTask.ContinueWith(task =>
                                {
                                    if (task.Status != TaskStatus.RanToCompletion)
                                    {
                                        return;
                                    }

                                    try
                                    {
                                        task.Result.Dispose();
                                    }
                                    catch (Exception e)
                                    {
                                        logger.WarnException("Failure in deferred disosal of a database", e);
                                    }
                                });
                            }
                            else if (dbTask.Status == TaskStatus.RanToCompletion)
                            {
                                exceptionAggregator.Execute(dbTask.Result.Dispose);
                            }
                            // there is no else, the db is probably faulted
                        });
                        ResourcesStoresCache.Clear();
                    }
                });

                exceptionAggregator.Execute(currentConfiguration.Dispose);
                exceptionAggregator.Execute(currentDatabase.Dispose);
                exceptionAggregator.Execute(currentTenantId.Dispose);
                exceptionAggregator.Execute(bufferPool.Dispose);
                exceptionAggregator.ThrowIfNeeded();
            }
            finally
            {
                disposerLock.ExitWriteLock();
            }
        }