コード例 #1
0
        public async Task StartSpinWheelAsync(int?totalItemsCount, CancellationToken ct)
        {
            try
            {
                await SemSlim.WaitAsync(ct).ContinueWith(async t =>
                {
                    _logger.Debug("SemSlim in.");

                    try
                    {
                        await _spinWheel.SpinAsync(totalItemsCount, ct);
                    }
                    catch (Exception ex)
                    {
                        _logger.ErrorException("Cannot start SpinWheel:", ex, ex.Message);
                    }
                    finally
                    {
                        _logger.Debug("SemSlim out.");
                        SemSlim.Release();
                    }
                }, ct);
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("Waiting for the semaphore has been canceled.");
            }
            catch (Exception ex)
            {
                _logger.ErrorException("SpinWheel is not available:", ex, ex.Message);
            }
        }
コード例 #2
0
        public async Task <List <IPlexMovieMetadata> > GetMovieMetadataAsync(string libraryName)
        {
            try
            {
                var libraryId = await _repository.GetLibraryIdAsync(_client, libraryName);

                if (libraryId == null)
                {
                    _logger.Error($"Library '{libraryName}' not found!");
                    return(null);
                }

                return(await _repository.GetMovieLibraryMetadataAsync(_client, libraryId));
            }
            catch (ResponseFailureException ex)
            {
                _logger.ErrorException($"{ex.Message}\nRequest: {ex.RequestMethod}: {ex.RequestUri}", ex, ex.InnerException?.Message);
                return(null);
            }
            catch (UnexpectedHttpStatusCodeException ex)
            {
                var msg = $"Received '{ex.StatusCode}' ({(int)ex.StatusCode}) status code after {ex.ResponseDuration} ms from {ex.RequestMethod}: {ex.ResponseUri}";
                _logger.ErrorException($"{msg}\n{ex.Message}", ex);
                return(null);
            }
        }
コード例 #3
0
        private async Task <bool> LoginClientAsync(IClient client)
        {
            try
            {
                _logger.Info($"Logging into '{client.ServerType}'.");
                await client.LoginAsync();

                return(true);
            }
            catch (Exception ex)
            {
                //var innerExceptions = new Func<Exception, IEnumerable<string>>(x =>
                //{
                //    var inmList = new List<string>();
                //    while (x.InnerException != null)
                //    {
                //        inmList.Add(x.Message);
                //        x = x.InnerException;
                //    }
                //    return inmList;
                //});

                //var asd = innerExceptions(ex);
                //_logger.ErrorException("lalala exception {0} {1} {2}", ex, "aaa", "bbb", "ccc");
                _logger.ErrorException($"{client.ServerType} login failed:", ex, ex.InnerException?.Message, ex.InnerException?.Message);
                //throw;
                return(false);
            }
        }
コード例 #4
0
ファイル: SpinWheel.cs プロジェクト: SludgeVohaul/P2EApp
        public async Task SpinAsync(int?totalItemsCount, CancellationToken cancellationToken)
        {
            var spinPosition = 0;

            await Task.Run(async() =>
            {
                try
                {
                    Console.CursorVisible = false;
                    _logger.Debug("Spinwheel is spinning...");
                    var watch = System.Diagnostics.Stopwatch.StartNew();
                    while (cancellationToken.IsCancellationRequested == false)
                    {
                        var spinWheelString = totalItemsCount.HasValue
                            ? $"({GetProcessedItemsCount()} / {totalItemsCount.Value}) {_spinPositions[spinPosition]}"
                            : $"{_spinPositions[spinPosition]}";

                        lock (ConsoleLockObject)
                        {
                            Console.Out.Write(spinWheelString);
                            Console.SetCursorPosition(Console.CursorLeft - spinWheelString.Length, Console.CursorTop);
                        }

                        spinPosition = spinPosition == 3 ? 0 : spinPosition + 1;
                        try
                        {
                            await Task.Delay(100, cancellationToken);
                        }
                        catch (OperationCanceledException)
                        {
                            _logger.Debug("SpinWheel execution has been canceled.");
                        }
                    }
                    watch.Stop();
                    _logger.Debug($"SpinWheel spin time: {watch.ElapsedMilliseconds} ms.");
                }
                catch (Exception ex)
                {
                    // Catch exceptions here.
                    // See https://blogs.msdn.microsoft.com/ptorr/2014/12/10/async-exceptions-in-c/
                    _logger.ErrorException("Spinwheel is broken:", ex, ex.Message);
                }
                finally
                {
                    Console.CursorVisible = true;
                }
            }, cancellationToken);
        }