Skip to content

Commit

Permalink
analizators/U2U1209
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhorukovAnton committed Jan 18, 2022
1 parent f1f7a82 commit 6c57925
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 67 deletions.
4 changes: 1 addition & 3 deletions common/ASC.Common/Logging/SelfCleaningTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions common/ASC.Core.Common/Configuration/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -354,9 +351,9 @@ private void Init(IReadOnlyDictionary<string, string> additional)

HandlerType = Type.GetType(additional[HandlerTypeKey]);

if (additional.ContainsKey(CdnKey))
if (additional.TryGetValue(CdnKey, out var value))
{
Cdn = GetCdn(additional[CdnKey]);
Cdn = GetCdn(value);
}
}

Expand Down
3 changes: 1 addition & 2 deletions common/ASC.Core.Common/Data/DbAzService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ public IEnumerable<AzRecord> 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)
{
Expand Down
13 changes: 5 additions & 8 deletions common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
19 changes: 8 additions & 11 deletions common/ASC.Data.Storage/RackspaceCloud/RackspaceCloudStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down
47 changes: 19 additions & 28 deletions common/ASC.Data.Storage/S3/S3Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Feed/Data/FeedAggregateDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public List<FeedResultItem> 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
{
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.MessagingSystem/DbSender/MessagesRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.MessagingSystem/MessageTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ private void AggregateFeeds(object interval)
{
dictionary = new Dictionary<Guid, int>();
}
if (dictionary.ContainsKey(userGuid))
if (dictionary.TryGetValue(userGuid, out var value))
{
++dictionary[userGuid];
++value;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions common/services/ASC.UrlShortener.Svc/UrlShortenerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

Expand Down

0 comments on commit 6c57925

Please sign in to comment.