Skip to content

Commit

Permalink
analizators/U2U1209
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhorukovAnton committed Jan 19, 2022
1 parent 769fc55 commit 1403afb
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 65 deletions.
8 changes: 4 additions & 4 deletions common/ASC.Api.Core/Middleware/ProductSecurityFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,16 @@ private static Guid FindProduct(ControllerActionDescriptor method)
if (!string.IsNullOrEmpty(url))
{
var module = url.Split('/')[0];
if (products.ContainsKey(module))
if (products.TryGetValue(module, out var communityProduct))
{
return products[module];
return communityProduct;
}
}
}

if (products.ContainsKey(name))
if (products.TryGetValue(name, out var product))
{
return products[name];
return product;
}
return default;
}
Expand Down
8 changes: 3 additions & 5 deletions common/ASC.Core.Common/Billing/BillingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,13 @@ public IEnumerable<PaymentInfo> GetPayments(string portalId)
var result = Request("GetProductsPrices", null, parameters.ToArray());
var prices = JsonSerializer.Deserialize<Dictionary<int, Dictionary<string, Dictionary<string, decimal>>>>(result);

if (prices.ContainsKey(AvangatePaymentSystemId))
if (prices.TryGetValue(AvangatePaymentSystemId, out var pricesPaymentSystem))
{
var pricesPaymentSystem = prices[AvangatePaymentSystemId];

return productIds.Select(productId =>
{
if (pricesPaymentSystem.ContainsKey(productId))
if (pricesPaymentSystem.TryGetValue(productId, out var prices))
{
return new { ProductId = productId, Prices = pricesPaymentSystem[productId] };
return new { ProductId = productId, Prices = prices };
}
return new { ProductId = productId, Prices = new Dictionary<string, decimal>() };
})
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Core.Common/Caching/AzRecordStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void Remove(AzRecord r)
if (r == null) return;

var id = r.ObjectId ?? string.Empty;
if (byObjectId.ContainsKey(id))
if (byObjectId.TryGetValue(id, out var list))
{
byObjectId[id].RemoveAll(a => a.SubjectId == r.SubjectId && a.ActionId == r.ActionId && a.Reaction == r.Reaction);
list.RemoveAll(a => a.SubjectId == r.SubjectId && a.ActionId == r.ActionId && a.Reaction == r.Reaction);
}
}

Expand Down
6 changes: 2 additions & 4 deletions common/ASC.Core.Common/Notify/Senders/SmtpSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ public virtual void Init(IDictionary<string, string> properties)
Host = properties["host"];
Port = properties.ContainsKey("port") ? int.Parse(properties["port"]) : 25;
Ssl = properties.ContainsKey("enableSsl") && bool.Parse(properties["enableSsl"]);
if (properties.ContainsKey("userName"))
if (properties.TryGetValue("userName", out var property))
{
Credentials = new NetworkCredential(
properties["userName"],
properties["password"]);
Credentials = new NetworkCredential(property, properties["password"]);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Data.Backup.Core/Core/DbBackupProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public IEnumerable<XElement> GetElements(int tenant, string[] configs, IDataWrit
xml.Add(node);

var connectionKey = connectionString.ProviderName + connectionString.ConnectionString;
if (connectionKeys.ContainsKey(connectionKey))
if (connectionKeys.TryGetValue(connectionKey, out var value))
{
node.Add(new XAttribute("ref", connectionKeys[connectionKey]));
node.Add(new XAttribute("ref", value));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Data.Backup.Core/Core/DbHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ private string GetWhere(string tableName, int tenant)
{
if (tenant == -1) return string.Empty;

if (whereExceptions.ContainsKey(tableName.ToLower()))
if (whereExceptions.TryGetValue(tableName.ToLower(), out var exc))
{
return string.Format(whereExceptions[tableName.ToLower()], tenant);
return string.Format(exc, tenant);
}
var tenantColumn = GetColumnsFrom(tableName).FirstOrDefault(c => c.StartsWith("tenant", StringComparison.OrdinalIgnoreCase));
return tenantColumn != null ?
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Data.Storage/DiscStorage/DiscDataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,9 @@ private void CopyAll(DirectoryInfo source, DirectoryInfo target, string newdomai
private MappedPath GetPath(string domain)
{
if (domain != null)
if (_mappedPaths.ContainsKey(domain))
if (_mappedPaths.TryGetValue(domain, out var value))
{
return _mappedPaths[domain];
return value;
}
return _mappedPaths[string.Empty].AppendDomain(domain);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary<string,

var realmUrlString = string.Empty;

if (@params.ContainsKey("realmUrl"))
realmUrlString = @params["realmUrl"];
@params.TryGetValue("realmUrl", out realmUrlString);

if (!string.IsNullOrEmpty(realmUrlString))
request = Openid.CreateRequest(id, new Realm(realmUrlString));
Expand Down Expand Up @@ -123,8 +122,7 @@ public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary<string,
var fetchprofile = response.GetExtension<FetchResponse>();

var realmUrlString = string.Empty;
if (@params.ContainsKey("realmUrl"))
realmUrlString = @params["realmUrl"];
@params.TryGetValue("realmUrl", out realmUrlString);

var profile = ProfileFromOpenId(spprofile, fetchprofile, response.ClaimedIdentifier.ToString(), realmUrlString);
return profile;
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.VoipService/Dao/VoIPCallFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class VoipCallFilter
get
{
if (string.IsNullOrWhiteSpace(Type)) return null;
if (TypeStatuses.ContainsKey(Type)) return TypeStatuses[Type];
if (TypeStatuses.TryGetValue(Type, out var status)) return status;

return null;
}
Expand Down
3 changes: 1 addition & 2 deletions common/services/ASC.TelegramService/TelegramHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ public void CreateOrUpdateClientForTenant(int tenantId, string token, int tokenL
var telegramHelper = scope.ServiceProvider.GetService<TelegramHelper>();
var newClient = telegramHelper.InitClient(token, proxy);

if (Clients.ContainsKey(tenantId))
if (Clients.TryGetValue(tenantId, out var client))
{
var client = Clients[tenantId];
client.TokenLifeSpan = tokenLifespan;

if (token != client.Token || proxy != client.Proxy)
Expand Down
16 changes: 8 additions & 8 deletions products/ASC.Files/Core/Core/Security/FileSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,9 @@ private List<FileEntry> GetSharesForMe<T>(IEnumerable<FileShareRecord> records,

files.ForEach(x =>
{
if (fileIds.ContainsKey(x.ID))
if (fileIds.TryGetValue(x.ID, out var access))
{
x.Access = fileIds[x.ID];
x.Access = access;
x.FolderIdDisplay = GlobalFolder.GetFolderShare<T>(daoFactory);
}
});
Expand All @@ -775,9 +775,9 @@ private List<FileEntry> GetSharesForMe<T>(IEnumerable<FileShareRecord> records,
}
folders.ForEach(x =>
{
if (folderIds.ContainsKey(x.ID))
if (folderIds.TryGetValue(x.ID, out var access))
{
x.Access = folderIds[x.ID];
x.Access = access;
x.FolderIdDisplay = GlobalFolder.GetFolderShare<T>(daoFactory);
}
});
Expand Down Expand Up @@ -874,9 +874,9 @@ private List<FileEntry<T>> GetPrivacyForMe<T>(IEnumerable<FileShareRecord> recor

files.ForEach(x =>
{
if (fileIds.ContainsKey(x.ID))
if (fileIds.TryGetValue(x.ID, out var access))
{
x.Access = fileIds[x.ID];
x.Access = access;
x.FolderIdDisplay = GlobalFolder.GetFolderPrivacy<T>(daoFactory);
}
});
Expand All @@ -894,9 +894,9 @@ private List<FileEntry<T>> GetPrivacyForMe<T>(IEnumerable<FileShareRecord> recor
}
folders.ForEach(x =>
{
if (folderIds.ContainsKey(x.ID))
if (folderIds.TryGetValue(x.ID, out var access))
{
x.Access = folderIds[x.ID];
x.Access = access;
x.FolderIdDisplay = GlobalFolder.GetFolderPrivacy<T>(daoFactory);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public virtual bool IsMatch(string id)
private T1 GetDao<T1>(string id) where T1 : ThirdPartyProviderDao<T>
{
var providerKey = $"{id}{typeof(T1)}";
if (Providers.ContainsKey(providerKey)) return (T1)Providers[providerKey];
if (Providers.TryGetValue(providerKey, out var provider)) return (T1)provider;

var res = ServiceProvider.GetService<T1>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ private ItemNameValueCollection<T> ExecPathFromFile(IServiceScope scope, File<T>

var title = file.Title;

if (files.ContainsKey(file.ID))
if (files.TryGetValue(file.ID, out var convertToExt))
{
var convertToExt = files[file.ID];

if (!string.IsNullOrEmpty(convertToExt))
{
title = FileUtility.ReplaceFileExtension(title, convertToExt);
Expand Down Expand Up @@ -317,9 +315,8 @@ internal void CompressToZip(Stream stream, IServiceScope scope)
continue;
}

if (files.ContainsKey(file.ID))
if (files.TryGetValue(file.ID, out convertToExt))
{
convertToExt = files[file.ID];
if (!string.IsNullOrEmpty(convertToExt))
{
newtitle = FileUtility.ReplaceFileExtension(path, convertToExt);
Expand Down
10 changes: 3 additions & 7 deletions products/ASC.Files/Core/Utils/FileConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,8 @@ private void CheckConvertFilesStatus(object _)
logger.Error(string.Format("Error convert {0} with url {1}", file.ID, fileUri), exception);
lock (locker)
{
if (conversionQueue.Keys.Contains(file))
if (conversionQueue.TryGetValue(file, out var operationResult))
{
var operationResult = conversionQueue[file];
if (operationResult.Delete)
{
conversionQueue.Remove(file);
Expand All @@ -297,10 +296,8 @@ private void CheckConvertFilesStatus(object _)
{
lock (locker)
{
if (conversionQueue.Keys.Contains(file))
if (conversionQueue.TryGetValue(file, out var operationResult))
{
var operationResult = conversionQueue[file];

if (DateTime.Now - operationResult.StartDateTime > TimeSpan.FromMinutes(10))
{
operationResult.StopDateTime = DateTime.UtcNow;
Expand Down Expand Up @@ -338,9 +335,8 @@ private void CheckConvertFilesStatus(object _)
{
lock (locker)
{
if (conversionQueue.Keys.Contains(file))
if (conversionQueue.TryGetValue(file, out var operationResult))
{
var operationResult = conversionQueue[file];
if (operationResult.Delete)
{
conversionQueue.Remove(file);
Expand Down
20 changes: 10 additions & 10 deletions products/ASC.Files/Core/Utils/FileMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ internal void ExecMarkFileAsNew<T>(AsyncTaskData<T> obj)

userIDs.ForEach(userID =>
{
if (userEntriesData.ContainsKey(userID))
userEntriesData[userID].AddRange(entries);
if (userEntriesData.TryGetValue(userID, out var value))
value.AddRange(entries);
else
userEntriesData.Add(userID, entries);
Expand Down Expand Up @@ -217,8 +217,8 @@ internal void ExecMarkFileAsNew<T>(AsyncTaskData<T> obj)

if (rootFolder == null) continue;

if (userEntriesData.ContainsKey(userID))
userEntriesData[userID].Add(rootFolder);
if (userEntriesData.TryGetValue(userID, out var value))
value.Add(rootFolder);
else
userEntriesData.Add(userID, new List<FileEntry> { rootFolder });

Expand All @@ -234,8 +234,8 @@ internal void ExecMarkFileAsNew<T>(AsyncTaskData<T> obj)
var commonFolder = folderDao.GetFolder(GlobalFolder.GetFolderCommon<T>(this, DaoFactory));
userIDs.ForEach(userID =>
{
if (userEntriesData.ContainsKey(userID))
userEntriesData[userID].Add(commonFolder);
if (userEntriesData.TryGetValue(userID, out var value))
value.Add(commonFolder);
else
userEntriesData.Add(userID, new List<FileEntry> { commonFolder });
Expand All @@ -253,8 +253,8 @@ internal void ExecMarkFileAsNew<T>(AsyncTaskData<T> obj)
var rootFolder = folderDao.GetFolder(privacyFolderId);
if (rootFolder == null) continue;

if (userEntriesData.ContainsKey(userID))
userEntriesData[userID].Add(rootFolder);
if (userEntriesData.TryGetValue(userID, out var value))
value.Add(rootFolder);
else
userEntriesData.Add(userID, new List<FileEntry> { rootFolder });

Expand All @@ -264,8 +264,8 @@ internal void ExecMarkFileAsNew<T>(AsyncTaskData<T> obj)

userIDs.ForEach(userID =>
{
if (userEntriesData.ContainsKey(userID))
userEntriesData[userID].Add(obj.FileEntry);
if (userEntriesData.TryGetValue(userID, out var value))
value.Add(obj.FileEntry);
else
userEntriesData.Add(userID, new List<FileEntry> { obj.FileEntry });
});
Expand Down
4 changes: 2 additions & 2 deletions products/ASC.Files/Core/Utils/FileTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public bool ProlongEditing<T>(T fileId, Guid tabId, Guid userId, bool editingAlo
var tracker = GetTracker(fileId);
if (tracker != null && IsEditing(fileId))
{
if (tracker.EditingBy.Keys.Contains(tabId))
if (tracker.EditingBy.TryGetValue(tabId, out var trackInfo))
{
tracker.EditingBy[tabId].TrackTime = DateTime.UtcNow;
trackInfo.TrackTime = DateTime.UtcNow;
checkRight = (DateTime.UtcNow - tracker.EditingBy[tabId].CheckRightTime > CheckRightTimeout);
}
else
Expand Down
4 changes: 2 additions & 2 deletions web/ASC.Web.Core/Users/Import/TextFileUserImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ private int GetFieldsMapping(string firstLine, IEnumerable<PropertyInfo> infos,
foreach (var info in infos)
{
var propertyField = field.Trim();
if (NameMapping != null && NameMapping.ContainsKey(propertyField))
if (NameMapping != null)
{
propertyField = NameMapping[propertyField];
NameMapping.TryGetValue(propertyField, out propertyField);
}
if (!string.IsNullOrEmpty(propertyField) && !ExcludeList.Contains(propertyField) && propertyField.Equals(info.Name, StringComparison.OrdinalIgnoreCase))
{
Expand Down
4 changes: 2 additions & 2 deletions web/ASC.Web.Core/WebItemSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ public bool IsAvailableForUser(Guid itemId, Guid @for)
{
lock (dic)
{
if (dic.ContainsKey(id + @for))
if (dic.TryGetValue(id + @for, out var value))
{
return dic[id + @for];
return value;
}
}
}
Expand Down

0 comments on commit 1403afb

Please sign in to comment.