From 6c5792583a019221ee5cdd3faca17bcc17334320 Mon Sep 17 00:00:00 2001 From: SuhorukovAnton Date: Tue, 18 Jan 2022 17:43:46 +0300 Subject: [PATCH] analizators/U2U1209 --- .../ASC.Common/Logging/SelfCleaningTarget.cs | 4 +- .../ASC.Core.Common/Configuration/Consumer.cs | 9 ++-- common/ASC.Core.Common/Data/DbAzService.cs | 3 +- .../GoogleCloud/GoogleCloudStorage.cs | 13 ++--- .../RackspaceCloud/RackspaceCloudStorage.cs | 19 ++++---- common/ASC.Data.Storage/S3/S3Storage.cs | 47 ++++++++----------- .../Data/FeedAggregateDataProvider.cs | 4 +- .../DbSender/MessagesRepository.cs | 4 +- common/ASC.MessagingSystem/MessageTarget.cs | 2 +- .../Service/FeedAggregatorService.cs | 4 +- .../UrlShortenerService.cs | 4 +- 11 files changed, 46 insertions(+), 67 deletions(-) diff --git a/common/ASC.Common/Logging/SelfCleaningTarget.cs b/common/ASC.Common/Logging/SelfCleaningTarget.cs index 613c1dd405a..86a7f5c125b 100644 --- a/common/ASC.Common/Logging/SelfCleaningTarget.cs +++ b/common/ASC.Common/Logging/SelfCleaningTarget.cs @@ -53,10 +53,8 @@ private static int GetCleanPeriod() const string key = "cleanPeriod"; - if (NLog.LogManager.Configuration.Variables.Keys.Contains(key)) + if (LogManager.Configuration.Variables.TryGetValue(key, out var variable)) { - var variable = NLog.LogManager.Configuration.Variables[key]; - if (variable != null && !string.IsNullOrEmpty(variable.Text)) { int.TryParse(variable.Text, out value); diff --git a/common/ASC.Core.Common/Configuration/Consumer.cs b/common/ASC.Core.Common/Configuration/Consumer.cs index 2a88d89c104..59e5aaa4a5e 100644 --- a/common/ASC.Core.Common/Configuration/Consumer.cs +++ b/common/ASC.Core.Common/Configuration/Consumer.cs @@ -245,10 +245,7 @@ private string Get(string name) if (string.IsNullOrEmpty(value)) { - if (AllProps.ContainsKey(name)) - { - value = AllProps[name]; - } + AllProps.TryGetValue(name, out value); } return value; @@ -354,9 +351,9 @@ private void Init(IReadOnlyDictionary additional) HandlerType = Type.GetType(additional[HandlerTypeKey]); - if (additional.ContainsKey(CdnKey)) + if (additional.TryGetValue(CdnKey, out var value)) { - Cdn = GetCdn(additional[CdnKey]); + Cdn = GetCdn(value); } } diff --git a/common/ASC.Core.Common/Data/DbAzService.cs b/common/ASC.Core.Common/Data/DbAzService.cs index 978ba30eab9..b7feb320fd6 100644 --- a/common/ASC.Core.Common/Data/DbAzService.cs +++ b/common/ASC.Core.Common/Data/DbAzService.cs @@ -75,9 +75,8 @@ public IEnumerable GetAces(int tenant, DateTime from) foreach (var a in tenantAces) { var key = string.Concat(a.Tenant.ToString(), a.SubjectId.ToString(), a.ActionId.ToString(), a.ObjectId); - if (commonAces.ContainsKey(key)) + if (commonAces.TryGetValue(key, out var common)) { - var common = commonAces[key]; commonAces.Remove(key); if (common.Reaction == a.Reaction) { diff --git a/common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs b/common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs index bdac9eefd48..a62f12e517b 100644 --- a/common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs +++ b/common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs @@ -120,17 +120,14 @@ public override IDataStore Configure(string tenant, Handler handlerConfig, Modul ? new Uri(props["cnamessl"], UriKind.Absolute) : new Uri("https://storage.googleapis.com/" + _bucket + "/", UriKind.Absolute); - if (props.ContainsKey("lower")) + if (props.TryGetValue("lower", out var value)) { - bool.TryParse(props["lower"], out _lowerCasing); + bool.TryParse(value, out _lowerCasing); } _json = props["json"]; - if (props.ContainsKey("subdir")) - { - _subDir = props["subdir"]; - } + props.TryGetValue("subdir", out _subDir); return this; } @@ -348,9 +345,9 @@ private PredefinedObjectAcl GetDomainACL(string domain) return PredefinedObjectAcl.Private; } - if (_domainsAcl.ContainsKey(domain)) + if (_domainsAcl.TryGetValue(domain, out var value)) { - return _domainsAcl[domain]; + return value; } return _moduleAcl; } diff --git a/common/ASC.Data.Storage/RackspaceCloud/RackspaceCloudStorage.cs b/common/ASC.Data.Storage/RackspaceCloud/RackspaceCloudStorage.cs index a044e89d742..27157bdb5c5 100644 --- a/common/ASC.Data.Storage/RackspaceCloud/RackspaceCloudStorage.cs +++ b/common/ASC.Data.Storage/RackspaceCloud/RackspaceCloudStorage.cs @@ -146,15 +146,12 @@ public override IDataStore Configure(string tenant, Handler handlerConfig, Modul _apiKey = props["apiKey"]; _username = props["username"]; - if (props.ContainsKey("lower")) + if (props.TryGetValue("lower", out var value)) { - bool.TryParse(props["lower"], out _lowerCasing); + bool.TryParse(value, out _lowerCasing); } - if (props.ContainsKey("subdir")) - { - _subDir = props["subdir"]; - } + props.TryGetValue("subdir", out _subDir); _public_container = props["public_container"]; @@ -193,13 +190,13 @@ public override Uri GetInternalUri(string domain, string path, TimeSpan expire, var accounMetaData = client.GetAccountMetaData(_region); string secretKey; - if (accounMetaData.ContainsKey("Temp-Url-Key")) + if (accounMetaData.TryGetValue("Temp-Url-Key", out secretKey)) { - secretKey = accounMetaData["Temp-Url-Key"]; + } else { - secretKey = ASC.Common.Utils.RandomString.Generate(64); + secretKey = Common.Utils.RandomString.Generate(64); accounMetaData.Add("Temp-Url-Key", secretKey); client.UpdateAccountMetadata(accounMetaData, _region); } @@ -380,9 +377,9 @@ private ACL GetDomainACL(string domain) return ACL.Auto; } - if (_domainsAcl.ContainsKey(domain)) + if (_domainsAcl.TryGetValue(domain, out var value)) { - return _domainsAcl[domain]; + return value; } return _moduleAcl; } diff --git a/common/ASC.Data.Storage/S3/S3Storage.cs b/common/ASC.Data.Storage/S3/S3Storage.cs index 44eefb7c86b..af7ce40e5d7 100644 --- a/common/ASC.Data.Storage/S3/S3Storage.cs +++ b/common/ASC.Data.Storage/S3/S3Storage.cs @@ -98,9 +98,9 @@ private S3CannedACL GetDomainACL(string domain) return S3CannedACL.Private; } - if (_domainsAcl.ContainsKey(domain)) + if (_domainsAcl.TryGetValue(domain, out var value)) { - return _domainsAcl[domain]; + return value; } return _moduleAcl; } @@ -1116,40 +1116,37 @@ public override IDataStore Configure(string tenant, Handler handlerConfig, Modul _secretAccessKeyId = props["secretaccesskey"]; _bucket = props["bucket"]; - if (props.ContainsKey("recycleDir")) - { - _recycleDir = props["recycleDir"]; - } + props.TryGetValue("recycleDir", out _recycleDir); - if (props.ContainsKey("region") && !string.IsNullOrEmpty(props["region"])) + if (props.TryGetValue("region", out var region) && !string.IsNullOrEmpty(region)) { - _region = props["region"]; + _region = region; } - if (props.ContainsKey("serviceurl") && !string.IsNullOrEmpty(props["serviceurl"])) + if (props.TryGetValue("serviceurl", out var url) && !string.IsNullOrEmpty(url)) { - _serviceurl = props["serviceurl"]; + _serviceurl = url; } - if (props.ContainsKey("forcepathstyle")) + if (props.TryGetValue("forcepathstyle", out var style)) { - if (bool.TryParse(props["forcepathstyle"], out var fps)) + if (bool.TryParse(style, out var fps)) { _forcepathstyle = fps; } } - if (props.ContainsKey("usehttp")) + if (props.TryGetValue("usehttp", out var use)) { - if (bool.TryParse(props["usehttp"], out var uh)) + if (bool.TryParse(use, out var uh)) { _useHttp = uh; } } - if (props.ContainsKey("sse") && !string.IsNullOrEmpty(props["sse"])) + if (props.TryGetValue("sse", out var sse) && !string.IsNullOrEmpty(sse)) { - _sse = (props["sse"].ToLower()) switch + _sse = sse.ToLower() switch { "none" => ServerSideEncryptionMethod.None, "aes256" => ServerSideEncryptionMethod.AES256, @@ -1166,23 +1163,17 @@ public override IDataStore Configure(string tenant, Handler handlerConfig, Modul ? new Uri(props["cnamessl"], UriKind.Absolute) : new Uri($"https://s3.{_region}.amazonaws.com/{_bucket}/", UriKind.Absolute); - if (props.ContainsKey("lower")) - { - bool.TryParse(props["lower"], out _lowerCasing); - } - if (props.ContainsKey("cloudfront")) + if (props.TryGetValue("lower", out var lower)) { - bool.TryParse(props["cloudfront"], out _revalidateCloudFront); + bool.TryParse(lower, out _lowerCasing); } - if (props.ContainsKey("distribution")) + if (props.TryGetValue("cloudfront", out var front)) { - _distributionId = props["distribution"]; + bool.TryParse(front, out _revalidateCloudFront); } - if (props.ContainsKey("subdir")) - { - _subDir = props["subdir"]; - } + props.TryGetValue("distribution", out _distributionId); + props.TryGetValue("subdir", out _subDir); return this; } diff --git a/common/ASC.Feed/Data/FeedAggregateDataProvider.cs b/common/ASC.Feed/Data/FeedAggregateDataProvider.cs index e718b5df939..9a9d1c41297 100644 --- a/common/ASC.Feed/Data/FeedAggregateDataProvider.cs +++ b/common/ASC.Feed/Data/FeedAggregateDataProvider.cs @@ -179,9 +179,9 @@ public List GetFeeds(FeedApiFilter filter) feedsIteration = GetFeedsInternal(filter); foreach (var feed in feedsIteration) { - if (feeds.ContainsKey(feed.GroupId)) + if (feeds.TryGetValue(feed.GroupId, out var value)) { - feeds[feed.GroupId].Add(feed); + value.Add(feed); } else { diff --git a/common/ASC.MessagingSystem/DbSender/MessagesRepository.cs b/common/ASC.MessagingSystem/DbSender/MessagesRepository.cs index 85a5709df9b..1cc81b31db9 100644 --- a/common/ASC.MessagingSystem/DbSender/MessagesRepository.cs +++ b/common/ASC.MessagingSystem/DbSender/MessagesRepository.cs @@ -133,9 +133,9 @@ private void FlushCache(object state) ClientInfo clientInfo; - if (dict.ContainsKey(message.UAHeader)) + if (dict.TryGetValue(message.UAHeader, out clientInfo)) { - clientInfo = dict[message.UAHeader]; + } else { diff --git a/common/ASC.MessagingSystem/MessageTarget.cs b/common/ASC.MessagingSystem/MessageTarget.cs index 7fe9bee69c2..ab8359fab20 100644 --- a/common/ASC.MessagingSystem/MessageTarget.cs +++ b/common/ASC.MessagingSystem/MessageTarget.cs @@ -99,7 +99,7 @@ public MessageTarget Parse(string value) var items = value.Split(','); - if (items.Count == 0) return null; + if (items.Length == 0) return null; return new MessageTarget(Option) { diff --git a/common/services/ASC.Feed.Aggregator/Service/FeedAggregatorService.cs b/common/services/ASC.Feed.Aggregator/Service/FeedAggregatorService.cs index e39804b5682..738fedcc572 100644 --- a/common/services/ASC.Feed.Aggregator/Service/FeedAggregatorService.cs +++ b/common/services/ASC.Feed.Aggregator/Service/FeedAggregatorService.cs @@ -201,9 +201,9 @@ private void AggregateFeeds(object interval) { dictionary = new Dictionary(); } - if (dictionary.ContainsKey(userGuid)) + if (dictionary.TryGetValue(userGuid, out var value)) { - ++dictionary[userGuid]; + ++value; } else { diff --git a/common/services/ASC.UrlShortener.Svc/UrlShortenerService.cs b/common/services/ASC.UrlShortener.Svc/UrlShortenerService.cs index a343f8dc5bd..a5cad6e13e0 100644 --- a/common/services/ASC.UrlShortener.Svc/UrlShortenerService.cs +++ b/common/services/ASC.UrlShortener.Svc/UrlShortenerService.cs @@ -140,9 +140,9 @@ private ProcessStartInfo GetProcessStartInfo() if (splited.Length < 2) continue; - if (dict.ContainsKey(splited[0])) + if (dict.TryGetValue(splited[0], out var value)) { - startInfo.EnvironmentVariables.Add("sql:" + dict[splited[0]], splited[1]); + startInfo.EnvironmentVariables.Add("sql:" + dict[value], splited[1]); } }