diff --git a/src/NzbDrone.Common/Cache/Cached.cs b/src/NzbDrone.Common/Cache/Cached.cs index a530baa55..42463f682 100644 --- a/src/NzbDrone.Common/Cache/Cached.cs +++ b/src/NzbDrone.Common/Cache/Cached.cs @@ -47,8 +47,7 @@ namespace NzbDrone.Common.Cache public T Find(string key) { - CacheItem cacheItem; - if (!_store.TryGetValue(key, out cacheItem)) + if (!_store.TryGetValue(key, out var cacheItem)) { return default(T); } @@ -76,8 +75,7 @@ namespace NzbDrone.Common.Cache public void Remove(string key) { - CacheItem value; - _store.TryRemove(key, out value); + _store.TryRemove(key, out _); } public int Count => _store.Count; @@ -88,9 +86,7 @@ namespace NzbDrone.Common.Cache lifeTime = lifeTime ?? _defaultLifeTime; - CacheItem cacheItem; - - if (_store.TryGetValue(key, out cacheItem) && !cacheItem.IsExpired()) + if (_store.TryGetValue(key, out var cacheItem) && !cacheItem.IsExpired()) { if (_rollingExpiry && lifeTime.HasValue) { diff --git a/src/NzbDrone.Common/Cache/CachedDictionary.cs b/src/NzbDrone.Common/Cache/CachedDictionary.cs index 6332f5054..922b45835 100644 --- a/src/NzbDrone.Common/Cache/CachedDictionary.cs +++ b/src/NzbDrone.Common/Cache/CachedDictionary.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -86,9 +86,7 @@ namespace NzbDrone.Common.Cache { RefreshIfExpired(); - TValue result; - - if (!_items.TryGetValue(key, out result)) + if (!_items.TryGetValue(key, out var result)) { throw new KeyNotFoundException(string.Format("Item {0} not found in cache.", key)); } @@ -100,9 +98,7 @@ namespace NzbDrone.Common.Cache { RefreshIfExpired(); - TValue result; - - _items.TryGetValue(key, out result); + _items.TryGetValue(key, out var result); return result; } @@ -128,8 +124,7 @@ namespace NzbDrone.Common.Cache public void Remove(string key) { - TValue item; - _items.TryRemove(key, out item); + _items.TryRemove(key, out _); } } } diff --git a/src/NzbDrone.Common/Extensions/TryParseExtensions.cs b/src/NzbDrone.Common/Extensions/TryParseExtensions.cs index 1ed79c319..3b9f3db49 100644 --- a/src/NzbDrone.Common/Extensions/TryParseExtensions.cs +++ b/src/NzbDrone.Common/Extensions/TryParseExtensions.cs @@ -6,9 +6,7 @@ namespace NzbDrone.Common.Extensions { public static int? ParseInt32(this string source) { - int result; - - if (int.TryParse(source, out result)) + if (int.TryParse(source, out var result)) { return result; } @@ -18,9 +16,7 @@ namespace NzbDrone.Common.Extensions public static long? ParseInt64(this string source) { - long result; - - if (long.TryParse(source, out result)) + if (long.TryParse(source, out var result)) { return result; } @@ -30,9 +26,7 @@ namespace NzbDrone.Common.Extensions public static double? ParseDouble(this string source) { - double result; - - if (double.TryParse(source.Replace(',', '.'), NumberStyles.Number, CultureInfo.InvariantCulture, out result)) + if (double.TryParse(source.Replace(',', '.'), NumberStyles.Number, CultureInfo.InvariantCulture, out var result)) { return result; } diff --git a/src/NzbDrone.Core/Applications/ApplicationFactory.cs b/src/NzbDrone.Core/Applications/ApplicationFactory.cs index 1b8dc1e2e..31386ad50 100644 --- a/src/NzbDrone.Core/Applications/ApplicationFactory.cs +++ b/src/NzbDrone.Core/Applications/ApplicationFactory.cs @@ -48,8 +48,7 @@ namespace NzbDrone.Core.Applications foreach (var application in applications) { - ApplicationStatus blockedApplicationStatus; - if (blockedApplications.TryGetValue(application.Definition.Id, out blockedApplicationStatus)) + if (blockedApplications.TryGetValue(application.Definition.Id, out var blockedApplicationStatus)) { _logger.Debug("Temporarily ignoring application {0} till {1} due to recent failures.", application.Definition.Name, blockedApplicationStatus.DisabledTill.Value.ToLocalTime()); continue; diff --git a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs index ddd4a98bc..127a5325b 100644 --- a/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/src/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -121,8 +121,7 @@ namespace NzbDrone.Core.Configuration continue; } - object currentValue; - allWithDefaults.TryGetValue(configValue.Key, out currentValue); + allWithDefaults.TryGetValue(configValue.Key, out var currentValue); if (currentValue == null) { continue; diff --git a/src/NzbDrone.Core/Configuration/ConfigService.cs b/src/NzbDrone.Core/Configuration/ConfigService.cs index 8fb717ce6..77e43f378 100644 --- a/src/NzbDrone.Core/Configuration/ConfigService.cs +++ b/src/NzbDrone.Core/Configuration/ConfigService.cs @@ -53,8 +53,7 @@ namespace NzbDrone.Core.Configuration foreach (var configValue in configValues) { - object currentValue; - allWithDefaults.TryGetValue(configValue.Key, out currentValue); + allWithDefaults.TryGetValue(configValue.Key, out var currentValue); if (currentValue == null || configValue.Value == null) { continue; @@ -211,9 +210,7 @@ namespace NzbDrone.Core.Configuration EnsureCache(); - string dbValue; - - if (_cache.TryGetValue(key, out dbValue) && dbValue != null && !string.IsNullOrEmpty(dbValue)) + if (_cache.TryGetValue(key, out var dbValue) && dbValue != null && !string.IsNullOrEmpty(dbValue)) { return dbValue; } diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs index 42b5bb1f2..ebe52b722 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/TorrentDownloadStation.cs @@ -130,9 +130,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected long GetRemainingSize(DownloadStationTask torrent) { var downloadedString = torrent.Additional.Transfer["size_downloaded"]; - long downloadedSize; - if (downloadedString.IsNullOrWhiteSpace() || !long.TryParse(downloadedString, out downloadedSize)) + if (downloadedString.IsNullOrWhiteSpace() || !long.TryParse(downloadedString, out var downloadedSize)) { _logger.Debug("Torrent {0} has invalid size_downloaded: {1}", torrent.Title, downloadedString); downloadedSize = 0; @@ -144,9 +143,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected TimeSpan? GetRemainingTime(DownloadStationTask torrent) { var speedString = torrent.Additional.Transfer["speed_download"]; - long downloadSpeed; - if (speedString.IsNullOrWhiteSpace() || !long.TryParse(speedString, out downloadSpeed)) + if (speedString.IsNullOrWhiteSpace() || !long.TryParse(speedString, out var downloadSpeed)) { _logger.Debug("Torrent {0} has invalid speed_download: {1}", torrent.Title, speedString); downloadSpeed = 0; diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs index 2cf42704b..1759cf600 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/UsenetDownloadStation.cs @@ -211,9 +211,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected long GetRemainingSize(DownloadStationTask task) { var downloadedString = task.Additional.Transfer["size_downloaded"]; - long downloadedSize; - if (downloadedString.IsNullOrWhiteSpace() || !long.TryParse(downloadedString, out downloadedSize)) + if (downloadedString.IsNullOrWhiteSpace() || !long.TryParse(downloadedString, out var downloadedSize)) { _logger.Debug("Task {0} has invalid size_downloaded: {1}", task.Title, downloadedString); downloadedSize = 0; @@ -225,9 +224,8 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation protected long GetDownloadSpeed(DownloadStationTask task) { var speedString = task.Additional.Transfer["speed_download"]; - long downloadSpeed; - if (speedString.IsNullOrWhiteSpace() || !long.TryParse(speedString, out downloadSpeed)) + if (speedString.IsNullOrWhiteSpace() || !long.TryParse(speedString, out var downloadSpeed)) { _logger.Debug("Task {0} has invalid speed_download: {1}", task.Title, speedString); downloadSpeed = 0; diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexLoginResultTypeConverter.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexLoginResultTypeConverter.cs index e74b8f973..7f0f27de7 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexLoginResultTypeConverter.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexLoginResultTypeConverter.cs @@ -15,8 +15,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex.JsonConverters { var result = reader.Value.ToString().Replace("_", string.Empty); - NzbVortexLoginResultType output; - Enum.TryParse(result, true, out output); + Enum.TryParse(result, true, out NzbVortexLoginResultType output); return output; } diff --git a/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexResultTypeConverter.cs b/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexResultTypeConverter.cs index bd63788bc..aa515abdb 100644 --- a/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexResultTypeConverter.cs +++ b/src/NzbDrone.Core/Download/Clients/NzbVortex/JsonConverters/NzbVortexResultTypeConverter.cs @@ -15,8 +15,7 @@ namespace NzbDrone.Core.Download.Clients.NzbVortex.JsonConverters { var result = reader.Value.ToString().Replace("_", string.Empty); - NzbVortexResultType output; - Enum.TryParse(result, true, out output); + Enum.TryParse(result, true, out NzbVortexResultType output); return output; } diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs index 0aa160cda..958b9efde 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/Nzbget.cs @@ -169,8 +169,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget var config = _proxy.GetConfig(Settings); var keepHistory = config.GetValueOrDefault("KeepHistory", "7"); - int value; - if (!int.TryParse(keepHistory, NumberStyles.None, CultureInfo.InvariantCulture, out value) || value == 0) + if (!int.TryParse(keepHistory, NumberStyles.None, CultureInfo.InvariantCulture, out var value) || value == 0) { return new NzbDroneValidationFailure(string.Empty, "NzbGet setting KeepHistory should be greater than 0") { diff --git a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs index 76cff3220..1d0b6d644 100644 --- a/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Nzbget/NzbgetProxy.cs @@ -177,11 +177,10 @@ namespace NzbDrone.Core.Download.Clients.Nzbget var queue = GetQueue(settings); var history = GetHistory(settings); - int nzbId; NzbgetQueueItem queueItem; NzbgetHistoryItem historyItem; - if (id.Length < 10 && int.TryParse(id, out nzbId)) + if (id.Length < 10 && int.TryParse(id, out var nzbId)) { // Download wasn't grabbed by Prowlarr, so the id is the NzbId reported by nzbget. queueItem = queue.SingleOrDefault(h => h.NzbId == nzbId); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs index 246b5b558..f29317251 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs @@ -15,8 +15,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd.JsonConverters { var queuePriority = reader.Value.ToString(); - SabnzbdPriority output; - Enum.TryParse(queuePriority, out output); + Enum.TryParse(queuePriority, out SabnzbdPriority output); return output; } diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs index de610ae9f..41fd428df 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs @@ -52,9 +52,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd request.AddFormUpload("name", filename, nzbData, "application/x-nzb"); - SabnzbdAddResponse response; - - if (!Json.TryDeserialize(ProcessRequest(request, settings), out response)) + if (!Json.TryDeserialize(ProcessRequest(request, settings), out var response)) { response = new SabnzbdAddResponse(); response.Status = true; @@ -71,9 +69,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd request.AddQueryParam("cat", category); request.AddQueryParam("priority", priority); - SabnzbdAddResponse response; - - if (!Json.TryDeserialize(ProcessRequest(request, settings), out response)) + if (!Json.TryDeserialize(ProcessRequest(request, settings), out var response)) { response = new SabnzbdAddResponse(); response.Status = true; @@ -96,9 +92,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd { var request = BuildRequest("version", settings); - SabnzbdVersionResponse response; - - if (!Json.TryDeserialize(ProcessRequest(request, settings), out response)) + if (!Json.TryDeserialize(ProcessRequest(request, settings), out var response)) { response = new SabnzbdVersionResponse(); } @@ -157,9 +151,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd var request = BuildRequest("retry", settings); request.AddQueryParam("value", id); - SabnzbdRetryResponse response; - - if (!Json.TryDeserialize(ProcessRequest(request, settings), out response)) + if (!Json.TryDeserialize(ProcessRequest(request, settings), out var response)) { response = new SabnzbdRetryResponse(); response.Status = true; @@ -230,9 +222,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd private void CheckForError(HttpResponse response) { - SabnzbdJsonError result; - - if (!Json.TryDeserialize(response.Content, out result)) + if (!Json.TryDeserialize(response.Content, out var result)) { //Handle plain text responses from SAB result = new SabnzbdJsonError(); diff --git a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs index bd1f4c37b..66e4dedf1 100644 --- a/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs +++ b/src/NzbDrone.Core/Download/Clients/Vuze/Vuze.cs @@ -46,8 +46,7 @@ namespace NzbDrone.Core.Download.Clients.Vuze _logger.Debug("Vuze protocol version information: {0}", versionString); - int version; - if (!int.TryParse(versionString, out version) || version < MINIMUM_SUPPORTED_PROTOCOL_VERSION) + if (!int.TryParse(versionString, out var version) || version < MINIMUM_SUPPORTED_PROTOCOL_VERSION) { { return new ValidationFailure(string.Empty, "Protocol version not supported, use Vuze 5.0.0.0 or higher with Vuze Web Remote plugin."); diff --git a/src/NzbDrone.Core/Download/DownloadClientFactory.cs b/src/NzbDrone.Core/Download/DownloadClientFactory.cs index f5cd9f005..d692d36ee 100644 --- a/src/NzbDrone.Core/Download/DownloadClientFactory.cs +++ b/src/NzbDrone.Core/Download/DownloadClientFactory.cs @@ -61,8 +61,7 @@ namespace NzbDrone.Core.Download foreach (var client in clients) { - DownloadClientStatus downloadClientStatus; - if (blockedIndexers.TryGetValue(client.Definition.Id, out downloadClientStatus)) + if (blockedIndexers.TryGetValue(client.Definition.Id, out var downloadClientStatus)) { _logger.Debug("Temporarily ignoring download client {0} till {1} due to recent failures.", client.Definition.Name, downloadClientStatus.DisabledTill.Value.ToLocalTime()); continue; diff --git a/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs b/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs index 11ae42719..78e60e314 100644 --- a/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs +++ b/src/NzbDrone.Core/HealthCheck/HealthCheckService.cs @@ -160,8 +160,7 @@ namespace NzbDrone.Core.HealthCheck _isRunningHealthChecksAfterGracePeriod = false; } - IEventDrivenHealthCheck[] checks; - if (!_eventDrivenHealthChecks.TryGetValue(message.GetType(), out checks)) + if (!_eventDrivenHealthChecks.TryGetValue(message.GetType(), out var checks)) { return; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNet.cs b/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNet.cs index 88449dbfa..596810d7f 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNet.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNet.cs @@ -36,10 +36,9 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet var releaseInfo = _indexerStatusService.GetLastRssSyncReleaseInfo(Definition.Id); if (releaseInfo != null) { - int torrentID; - if (int.TryParse(releaseInfo.Guid.Replace("BTN-", string.Empty), out torrentID)) + if (int.TryParse(releaseInfo.Guid.Replace("BTN-", string.Empty), out var torrentId)) { - requestGenerator.LastRecentTorrentID = torrentID; + requestGenerator.LastRecentTorrentID = torrentId; } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesRssParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesRssParser.cs index f17d0e260..8e0292f3c 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesRssParser.cs @@ -150,10 +150,8 @@ namespace NzbDrone.Core.Indexers.Headphones protected override long GetSize(XElement item) { - long size; - var sizeString = TryGetNewznabAttribute(item, "size"); - if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out size)) + if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out var size)) { return size; } @@ -189,9 +187,8 @@ namespace NzbDrone.Core.Indexers.Headphones protected virtual int GetImdbId(XElement item) { var imdbIdString = TryGetNewznabAttribute(item, "imdb"); - int imdbId; - if (!imdbIdString.IsNullOrWhiteSpace() && int.TryParse(imdbIdString, out imdbId)) + if (!imdbIdString.IsNullOrWhiteSpace() && int.TryParse(imdbIdString, out var imdbId)) { return imdbId; } @@ -202,9 +199,8 @@ namespace NzbDrone.Core.Indexers.Headphones protected virtual int GetGrabs(XElement item) { var grabsString = TryGetNewznabAttribute(item, "grabs"); - int grabs; - if (!grabsString.IsNullOrWhiteSpace() && int.TryParse(grabsString, out grabs)) + if (!grabsString.IsNullOrWhiteSpace() && int.TryParse(grabsString, out var grabs)) { return grabs; } @@ -215,9 +211,8 @@ namespace NzbDrone.Core.Indexers.Headphones protected virtual int GetFiles(XElement item) { var filesString = TryGetNewznabAttribute(item, "files"); - int files; - if (!filesString.IsNullOrWhiteSpace() && int.TryParse(filesString, out files)) + if (!filesString.IsNullOrWhiteSpace() && int.TryParse(filesString, out var files)) { return files; } @@ -228,9 +223,8 @@ namespace NzbDrone.Core.Indexers.Headphones protected virtual int GetImdbYear(XElement item) { var imdbYearString = TryGetNewznabAttribute(item, "imdbyear"); - int imdbYear; - if (!imdbYearString.IsNullOrWhiteSpace() && int.TryParse(imdbYearString, out imdbYear)) + if (!imdbYearString.IsNullOrWhiteSpace() && int.TryParse(imdbYearString, out var imdbYear)) { return imdbYear; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs index 063c6c951..87bea73ed 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabRssParser.cs @@ -178,10 +178,8 @@ namespace NzbDrone.Core.Indexers.Newznab protected override long GetSize(XElement item) { - long size; - var sizeString = TryGetNewznabAttribute(item, "size"); - if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out size)) + if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out var size)) { return size; } @@ -241,9 +239,8 @@ namespace NzbDrone.Core.Indexers.Newznab foreach (var attr in attributes) { var idString = TryGetNewznabAttribute(item, attr); - int idInt; - if (!idString.IsNullOrWhiteSpace() && int.TryParse(idString, out idInt)) + if (!idString.IsNullOrWhiteSpace() && int.TryParse(idString, out var idInt)) { return idInt; } @@ -260,9 +257,8 @@ namespace NzbDrone.Core.Indexers.Newznab protected virtual int GetImdbYear(XElement item) { var imdbYearString = TryGetNewznabAttribute(item, "imdbyear"); - int imdbYear; - if (!imdbYearString.IsNullOrWhiteSpace() && int.TryParse(imdbYearString, out imdbYear)) + if (!imdbYearString.IsNullOrWhiteSpace() && int.TryParse(imdbYearString, out var imdbYear)) { return imdbYear; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabRssParser.cs b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabRssParser.cs index d0823f980..9bd544aad 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabRssParser.cs @@ -149,10 +149,8 @@ namespace NzbDrone.Core.Indexers.Torznab protected override long GetSize(XElement item) { - long size; - var sizeString = TryGetTorznabAttribute(item, "size"); - if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out size)) + if (!sizeString.IsNullOrWhiteSpace() && long.TryParse(sizeString, out var size)) { return size; } @@ -298,9 +296,7 @@ namespace NzbDrone.Core.Indexers.Torznab { var attr = TryGetTorznabAttribute(item, key, defaultValue.ToString()); - float result = 0; - - if (float.TryParse(attr, out result)) + if (float.TryParse(attr, out var result)) { return result; } @@ -330,9 +326,8 @@ namespace NzbDrone.Core.Indexers.Torznab foreach (var attr in attributes) { var idString = TryGetTorznabAttribute(item, attr); - int idInt; - if (!idString.IsNullOrWhiteSpace() && int.TryParse(idString, out idInt)) + if (!idString.IsNullOrWhiteSpace() && int.TryParse(idString, out var idInt)) { return idInt; } diff --git a/src/NzbDrone.Core/Indexers/IndexerFactory.cs b/src/NzbDrone.Core/Indexers/IndexerFactory.cs index 93eab492c..9bb810805 100644 --- a/src/NzbDrone.Core/Indexers/IndexerFactory.cs +++ b/src/NzbDrone.Core/Indexers/IndexerFactory.cs @@ -245,8 +245,7 @@ namespace NzbDrone.Core.Indexers foreach (var indexer in indexers) { - IndexerStatus blockedIndexerStatus; - if (blockedIndexers.TryGetValue(indexer.Definition.Id, out blockedIndexerStatus)) + if (blockedIndexers.TryGetValue(indexer.Definition.Id, out var blockedIndexerStatus)) { _logger.Debug("Temporarily ignoring indexer {0} till {1} due to recent failures.", indexer.Definition.Name, blockedIndexerStatus.DisabledTill.Value.ToLocalTime()); continue; diff --git a/src/NzbDrone.Core/Indexers/XElementExtensions.cs b/src/NzbDrone.Core/Indexers/XElementExtensions.cs index 1c4ca6634..f2fb9ef84 100644 --- a/src/NzbDrone.Core/Indexers/XElementExtensions.cs +++ b/src/NzbDrone.Core/Indexers/XElementExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -37,8 +37,7 @@ namespace NzbDrone.Core.Indexers { try { - DateTime result; - if (!DateTime.TryParse(dateString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out result)) + if (!DateTime.TryParse(dateString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal, out var result)) { dateString = RemoveTimeZoneRegex.Replace(dateString, ""); result = DateTime.Parse(dateString, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AssumeUniversal); diff --git a/src/NzbDrone.Core/Messaging/Events/EventAggregator.cs b/src/NzbDrone.Core/Messaging/Events/EventAggregator.cs index 78bc5f15c..39d9dea25 100644 --- a/src/NzbDrone.Core/Messaging/Events/EventAggregator.cs +++ b/src/NzbDrone.Core/Messaging/Events/EventAggregator.cs @@ -75,8 +75,7 @@ namespace NzbDrone.Core.Messaging.Events EventSubscribers subscribers; lock (_eventSubscribers) { - object target; - if (!_eventSubscribers.TryGetValue(eventName, out target)) + if (!_eventSubscribers.TryGetValue(eventName, out var target)) { _eventSubscribers[eventName] = target = new EventSubscribers(_serviceFactory); } diff --git a/src/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs b/src/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs index da36b9970..fbe78dacf 100644 --- a/src/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs +++ b/src/NzbDrone.Core/Notifications/PushBullet/PushBulletProxy.cs @@ -152,14 +152,13 @@ namespace NzbDrone.Core.Notifications.PushBullet private HttpRequestBuilder BuildDeviceRequest(string deviceId) { var requestBuilder = new HttpRequestBuilder(PUSH_URL).Post(); - long integerId; if (deviceId.IsNullOrWhiteSpace()) { return requestBuilder; } - if (long.TryParse(deviceId, out integerId)) + if (long.TryParse(deviceId, out var integerId)) { requestBuilder.AddFormParameter("device_id", integerId); } diff --git a/src/NzbDrone.Core/Parser/DateTimeRoutines.cs b/src/NzbDrone.Core/Parser/DateTimeRoutines.cs index d0aea643a..c5280b6e6 100644 --- a/src/NzbDrone.Core/Parser/DateTimeRoutines.cs +++ b/src/NzbDrone.Core/Parser/DateTimeRoutines.cs @@ -111,9 +111,8 @@ namespace NzbDrone.Core.Parser { parsed_date_time = null; - ParsedDateTime parsed_date; ParsedDateTime parsed_time; - if (!TryParseDate(str, default_format, out parsed_date)) + if (!TryParseDate(str, default_format, out var parsed_date)) { if (!TryParseTime(str, default_format, out parsed_time, null)) { @@ -314,8 +313,7 @@ namespace NzbDrone.Core.Parser m = Regex.Match(str, @"(?<=^|[^\d])(?'year'\d{2}|\d{4})\s*(?'separator'[\-])\s*(?'month'\d{1,2})\s*\'separator'+\s*(?'day'\d{1,2})(?=$|[^\d])", RegexOptions.Compiled | RegexOptions.IgnoreCase); if (m.Success) { - DateTime date; - if (!ConvertToDate(int.Parse(m.Groups["year"].Value), int.Parse(m.Groups["month"].Value), int.Parse(m.Groups["day"].Value), out date)) + if (!ConvertToDate(int.Parse(m.Groups["year"].Value), int.Parse(m.Groups["month"].Value), int.Parse(m.Groups["day"].Value), out var date)) { return false; } @@ -417,8 +415,7 @@ namespace NzbDrone.Core.Parser year = DefaultDate.Year; } - DateTime date; - if (!ConvertToDate(year, month, int.Parse(m.Groups["day"].Value), out date)) + if (!ConvertToDate(year, month, int.Parse(m.Groups["day"].Value), out var date)) { return false; } diff --git a/src/NzbDrone.Core/Parser/RomanNumerals/RomanNumeral.cs b/src/NzbDrone.Core/Parser/RomanNumerals/RomanNumeral.cs index 7837700ec..ff3f03596 100644 --- a/src/NzbDrone.Core/Parser/RomanNumerals/RomanNumeral.cs +++ b/src/NzbDrone.Core/Parser/RomanNumerals/RomanNumeral.cs @@ -52,9 +52,7 @@ namespace NzbDrone.Core.Parser.RomanNumerals /// The roman numeral. public RomanNumeral(string romanNumeral) { - int value; - - if (TryParse(romanNumeral, out value)) + if (TryParse(romanNumeral, out var value)) { _value = value; } @@ -312,10 +310,9 @@ namespace NzbDrone.Core.Parser.RomanNumerals } else if (obj is string) { - int value; var numeral = obj as string; - if (TryParse(numeral, out value)) + if (TryParse(numeral, out var value)) { return _value.CompareTo(value); } diff --git a/src/NzbDrone.Core/Parser/RomanNumerals/RomanNumeralParser.cs b/src/NzbDrone.Core/Parser/RomanNumerals/RomanNumeralParser.cs index e8d6368d7..a898fc174 100644 --- a/src/NzbDrone.Core/Parser/RomanNumerals/RomanNumeralParser.cs +++ b/src/NzbDrone.Core/Parser/RomanNumerals/RomanNumeralParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; @@ -28,8 +28,7 @@ namespace NzbDrone.Core.Parser.RomanNumerals _simpleArabicNumeralMappings = new Dictionary(); foreach (int arabicNumeral in Enumerable.Range(1, DICTIONARY_PREPOPULATION_SIZE + 1)) { - string romanNumeralAsString, arabicNumeralAsString; - GenerateRomanNumerals(arabicNumeral, out romanNumeralAsString, out arabicNumeralAsString); + GenerateRomanNumerals(arabicNumeral, out var romanNumeralAsString, out var arabicNumeralAsString); ArabicRomanNumeral arm = new ArabicRomanNumeral(arabicNumeral, arabicNumeralAsString, romanNumeralAsString); _arabicRomanNumeralsMapping.Add(arm); @@ -51,9 +50,7 @@ namespace NzbDrone.Core.Parser.RomanNumerals HashSet additionalArabicRomanNumerals = new HashSet(); foreach (int arabicNumeral in Enumerable.Range(offset, length)) { - string romanNumeral; - string arabicNumeralAsString; - GenerateRomanNumerals(arabicNumeral, out romanNumeral, out arabicNumeralAsString); + GenerateRomanNumerals(arabicNumeral, out var romanNumeral, out var arabicNumeralAsString); ArabicRomanNumeral arm = new ArabicRomanNumeral(arabicNumeral, arabicNumeralAsString, romanNumeral); additionalArabicRomanNumerals.Add(arm); } @@ -129,9 +126,7 @@ namespace NzbDrone.Core.Parser.RomanNumerals Dictionary moreNumerals = new Dictionary(); foreach (int arabicNumeral in Enumerable.Range(offset, length)) { - string romanNumeral; - string arabicNumeralAsString; - GenerateRomanNumerals(arabicNumeral, out romanNumeral, out arabicNumeralAsString); + GenerateRomanNumerals(arabicNumeral, out var romanNumeral, out _); SimpleArabicNumeral san = new SimpleArabicNumeral(arabicNumeral); SimpleRomanNumeral srn = new SimpleRomanNumeral(romanNumeral); moreNumerals.Add(san, srn); diff --git a/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs b/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs index cb804ecf4..25a02fd43 100644 --- a/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs +++ b/src/NzbDrone.Mono.Test/DiskProviderTests/DiskProviderFixture.cs @@ -57,8 +57,7 @@ namespace NzbDrone.Mono.Test.DiskProviderTests protected void SetWritePermissionsInternal(string path, bool writable, bool setgid) { // Remove Write permissions, we're still owner so we can clean it up, but we'll have to do that explicitly. - Stat stat; - Syscall.stat(path, out stat); + Syscall.stat(path, out var stat); FilePermissions mode = stat.st_mode; if (writable) diff --git a/src/NzbDrone.Mono/Disk/DiskProvider.cs b/src/NzbDrone.Mono/Disk/DiskProvider.cs index 26b1db082..0cbdf9cfa 100644 --- a/src/NzbDrone.Mono/Disk/DiskProvider.cs +++ b/src/NzbDrone.Mono/Disk/DiskProvider.cs @@ -474,9 +474,7 @@ namespace NzbDrone.Mono.Disk return UNCHANGED_ID; } - uint userId; - - if (uint.TryParse(user, out userId)) + if (uint.TryParse(user, out var userId)) { return userId; } @@ -498,9 +496,7 @@ namespace NzbDrone.Mono.Disk return UNCHANGED_ID; } - uint groupId; - - if (uint.TryParse(group, out groupId)) + if (uint.TryParse(group, out var groupId)) { return groupId; } diff --git a/src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs b/src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs index a837b59a6..103bdf430 100644 --- a/src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs +++ b/src/NzbDrone.Mono/Disk/SymbolicLinkResolver.cs @@ -83,9 +83,7 @@ namespace NzbDrone.Mono.Disk private bool TryFollowFirstSymbolicLink(ref string path) { - string[] dirs; - int lastIndex; - GetPathComponents(path, out dirs, out lastIndex); + GetPathComponents(path, out var dirs, out var lastIndex); if (lastIndex == 0) { diff --git a/src/NzbDrone.Test.Common/LoggingTest.cs b/src/NzbDrone.Test.Common/LoggingTest.cs index 396581f55..0085937ff 100644 --- a/src/NzbDrone.Test.Common/LoggingTest.cs +++ b/src/NzbDrone.Test.Common/LoggingTest.cs @@ -23,8 +23,7 @@ namespace NzbDrone.Test.Common { LogManager.Configuration = new LoggingConfiguration(); - var logOutput = TestLogOutput.Console; - Enum.TryParse(Environment.GetEnvironmentVariable("PROWLARR_TESTS_LOG_OUTPUT"), out logOutput); + Enum.TryParse(Environment.GetEnvironmentVariable("PROWLARR_TESTS_LOG_OUTPUT"), out var logOutput); RegisterSentryLogger(); diff --git a/src/NzbDrone.Update/UpdateApp.cs b/src/NzbDrone.Update/UpdateApp.cs index abbfd0f6d..ce4e92656 100644 --- a/src/NzbDrone.Update/UpdateApp.cs +++ b/src/NzbDrone.Update/UpdateApp.cs @@ -99,8 +99,7 @@ namespace NzbDrone.Update private int ParseProcessId(string arg) { - int id; - if (!int.TryParse(arg, out id) || id <= 0) + if (!int.TryParse(arg, out var id) || id <= 0) { throw new ArgumentOutOfRangeException("arg", "Invalid process ID"); } diff --git a/src/NzbDrone.Windows/Disk/DiskProvider.cs b/src/NzbDrone.Windows/Disk/DiskProvider.cs index f65dae3d0..ebdf026e1 100644 --- a/src/NzbDrone.Windows/Disk/DiskProvider.cs +++ b/src/NzbDrone.Windows/Disk/DiskProvider.cs @@ -92,8 +92,7 @@ namespace NzbDrone.Windows.Disk PropagationFlags.InheritOnly, controlType); - bool modified; - directorySecurity.ModifyAccessRule(AccessControlModification.Add, accessRule, out modified); + directorySecurity.ModifyAccessRule(AccessControlModification.Add, accessRule, out var modified); if (modified) { @@ -142,11 +141,7 @@ namespace NzbDrone.Windows.Disk folderName += '\\'; } - ulong free = 0; - ulong dummy1 = 0; - ulong dummy2 = 0; - - if (GetDiskFreeSpaceEx(folderName, out free, out dummy1, out dummy2)) + if (GetDiskFreeSpaceEx(folderName, out var free, out var dummy1, out var dummy2)) { return (long)free; } @@ -163,11 +158,7 @@ namespace NzbDrone.Windows.Disk folderName += '\\'; } - ulong total = 0; - ulong dummy1 = 0; - ulong dummy2 = 0; - - if (GetDiskFreeSpaceEx(folderName, out dummy1, out total, out dummy2)) + if (GetDiskFreeSpaceEx(folderName, out var dummy1, out var total, out var dummy2)) { return (long)total; } diff --git a/src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs b/src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs index 37c8b2afb..698a7ffc8 100644 --- a/src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs +++ b/src/Prowlarr.Http/ClientSchema/SchemaBuilder.cs @@ -67,8 +67,7 @@ namespace Prowlarr.Http.ClientSchema { lock (_mappings) { - FieldMapping[] result; - if (!_mappings.TryGetValue(type, out result)) + if (!_mappings.TryGetValue(type, out var result)) { result = GetFieldMapping(type, "", v => v);