Skip to content

Commit

Permalink
analizators/U2U1009
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhorukovAnton committed Jan 11, 2022
1 parent c85c2e6 commit 50c0596
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 81 deletions.
14 changes: 9 additions & 5 deletions common/ASC.Core.Common/Billing/CouponManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,23 @@ private async Task<string> CreatePromotionAsync(TenantManager tenantManager)
Log.Error(ex.Message, ex);
throw;
}
}

internal Task<IEnumerable<AvangateProduct>> GetProducts()
{
if (Products != null) return Task.FromResult(Products);
return InternalGetProducts();
}

internal async Task<IEnumerable<AvangateProduct>> GetProducts()
{
if (Products != null) return Products;

private async Task<IEnumerable<AvangateProduct>> InternalGetProducts()
{
await SemaphoreSlim.WaitAsync();

if (Products != null)
{
SemaphoreSlim.Release();
return Products;
}
}

try
{
Expand Down
10 changes: 8 additions & 2 deletions common/ASC.Core.Common/EF/Context/BaseDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,16 @@ public void Dispose()
}
}
}
public async ValueTask DisposeAsync()

public ValueTask DisposeAsync()
{
if (Context == null) return;
if (Context == null) return ValueTask.CompletedTask;

return InternalDisposeAsync();
}

private async ValueTask InternalDisposeAsync()
{
foreach (var c in Context)
{
if (c != null)
Expand Down
8 changes: 6 additions & 2 deletions common/ASC.Data.Backup.Core/Tasks/PortalTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,15 @@ protected void RunMysqlFile(string file, bool db = false)
Logger.DebugFormat("complete mysql file {0}", file);
}

protected async Task RunMysqlFile(Stream stream, string delimiter = ";")
protected Task RunMysqlFile(Stream stream, string delimiter = ";")
{
if (stream == null) return Task.CompletedTask;

if (stream == null) return;
return InternalRunMysqlFile(stream, delimiter);
}

private async Task InternalRunMysqlFile(Stream stream, string delimiter)
{
using var reader = new StreamReader(stream, Encoding.UTF8);
string commandText;

Expand Down
37 changes: 21 additions & 16 deletions common/ASC.Data.Storage/StorageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ public StorageHandler(IServiceProvider serviceProvider, string path, string modu
}

private IServiceProvider ServiceProvider { get; }

public async Task Invoke(HttpContext context)
{

public Task Invoke(HttpContext context)
{
using var scope = ServiceProvider.CreateScope();
var scopeClass = scope.ServiceProvider.GetService<StorageHandlerScope>();
var (tenantManager, securityContext, storageFactory, emailValidationKeyProvider) = scopeClass;

if (_checkAuth && !securityContext.IsAuthenticated)
{
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return;
return Task.CompletedTask;
}

var storage = storageFactory.GetStorage(tenantManager.GetCurrentTenant().TenantId.ToString(CultureInfo.InvariantCulture), _module);
var path = CrossPlatform.PathCombine(_path, GetRouteValue("pathInfo").Replace('/', Path.DirectorySeparatorChar));
var path = CrossPlatform.PathCombine(_path, GetRouteValue("pathInfo", context).Replace('/', Path.DirectorySeparatorChar));
var header = context.Request.Query[Constants.QUERY_HEADER].FirstOrDefault() ?? "";

var auth = context.Request.Query[Constants.QUERY_AUTH].FirstOrDefault() ?? "";
Expand All @@ -92,14 +92,14 @@ public async Task Invoke(HttpContext context)
if (validateResult != EmailValidationKeyProvider.ValidationResult.Ok)
{
context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return;
return Task.CompletedTask;
}
}

if (!storage.IsFile(_domain, path))
{
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
return;
return Task.CompletedTask;
}

var headers = header.Length > 0 ? header.Split('&').Select(HttpUtility.UrlDecode) : new string[] { };
Expand All @@ -113,9 +113,9 @@ public async Task Invoke(HttpContext context)
//context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

context.Response.Redirect(uri.ToString());
return;
}

return Task.CompletedTask;
}

string encoding = null;
if (storage is DiscDataStore && storage.IsFile(_domain, path + ".gz"))
{
Expand Down Expand Up @@ -143,18 +143,23 @@ public async Task Invoke(HttpContext context)
if (encoding != null)
context.Response.Headers["Content-Encoding"] = encoding;

return InternalInvoke(context, storage, path);
}

private async Task InternalInvoke(HttpContext context, IDataStore storage, string path)
{
using (var stream = storage.GetReadStream(_domain, path))
{
await stream.CopyToAsync(context.Response.Body);
}

await context.Response.Body.FlushAsync();
await context.Response.CompleteAsync();

string GetRouteValue(string name)
{
return (context.GetRouteValue(name) ?? "").ToString();
}
await context.Response.CompleteAsync();
}

private string GetRouteValue(string name, HttpContext context)
{
return (context.GetRouteValue(name) ?? "").ToString();
}
}

Expand Down
26 changes: 18 additions & 8 deletions common/services/ASC.ElasticSearch/Engine/FactoryIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,18 @@ public void Index(List<T> data, bool immediately = true, int retry = 0)
throw;
}
}
}
}

public async Task IndexAsync(List<T> data, bool immediately = true, int retry = 0)
public Task IndexAsync(List<T> data, bool immediately = true, int retry = 0)
{
var t = ServiceProvider.GetService<T>();
if (!Support(t) || !data.Any()) return;
if (!Support(t) || !data.Any()) return Task.CompletedTask;

return InternalIndexAsync(data, immediately, retry);
}

private async Task InternalIndexAsync(List<T> data, bool immediately, int retry)
{
try
{
await Indexer.IndexAsync(data, immediately).ConfigureAwait(false);
Expand Down Expand Up @@ -627,20 +632,25 @@ public bool CheckState(bool cacheState = true)
return false;
}
}

public async Task<bool> CheckStateAsync(bool cacheState = true)
{

public Task<bool> CheckStateAsync(bool cacheState = true)
{
const string key = "elasticsearch";

if (cacheState)
{
var cacheValue = cache.Get<string>(key);
if (!string.IsNullOrEmpty(cacheValue))
{
return Convert.ToBoolean(cacheValue);
return Task.FromResult(Convert.ToBoolean(cacheValue));
}
}
}

return InternalCheckStateAsync(cacheState, key);
}

private async Task<bool> InternalCheckStateAsync(bool cacheState, string key)
{
var cacheTime = DateTime.UtcNow.AddMinutes(15);

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ public ContactPhotoHandlerMiddleware(RequestDelegate next)

private readonly RequestDelegate _next;

public async System.Threading.Tasks.Task Invoke(HttpContext context,
public System.Threading.Tasks.Task Invoke(HttpContext context,
SetupInfo setupInfo,
CrmSecurity crmSecurity,
FileSizeComment fileSizeComment,
WebItemSecurity webItemSecurity,
MessageTarget messageTarget,
MessageService messageService,
DaoFactory daoFactory,
ContactPhotoManager contactPhotoManager)
{
ContactPhotoManager contactPhotoManager){

if (!webItemSecurity.IsAvailableForMe(ProductEntryPoint.ID))
throw crmSecurity.CreateSecurityException();
Expand All @@ -82,6 +81,18 @@ public ContactPhotoHandlerMiddleware(RequestDelegate next)
throw crmSecurity.CreateSecurityException();
}

return InternalInvoke(context, setupInfo, fileSizeComment, messageTarget, messageService, contactPhotoManager, contact, contactId);
}

private async System.Threading.Tasks.Task InternalInvoke(HttpContext context,
SetupInfo setupInfo,
FileSizeComment fileSizeComment,
MessageTarget messageTarget,
MessageService messageService,
ContactPhotoManager contactPhotoManager,
Contact contact,
int contactId)
{
var fileUploadResult = new FileUploadResult();

if (context.Request.Form.Files.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class ImportFileHandlerMiddleware
_next = next;
}

public async Task Invoke(HttpContext context,
public Task Invoke(HttpContext context,
WebItemSecurity webItemSecurity,
CrmSecurity crmSecurity,
Global global,
Expand All @@ -59,6 +59,15 @@ public class ImportFileHandlerMiddleware
if (!webItemSecurity.IsAvailableForMe(ProductEntryPoint.ID))
throw crmSecurity.CreateSecurityException();

return InternalInvoke(context, webItemSecurity, crmSecurity, global, importFromCSV);
}

private async Task InternalInvoke(HttpContext context,
WebItemSecurity webItemSecurity,
CrmSecurity crmSecurity,
Global global,
ImportFromCSV importFromCSV)
{
var fileUploadResult = new FileUploadResult();

if (context.Request.Form.Files.Count == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RequestDelegate next
_next = next;
}

public async System.Threading.Tasks.Task Invoke(HttpContext context,
public System.Threading.Tasks.Task Invoke(HttpContext context,
CrmSecurity crmSecurity,
SetupInfo setupInfo,
FileSizeComment fileSizeComment,
Expand All @@ -62,6 +62,16 @@ RequestDelegate next
if (!crmSecurity.IsAdmin)
throw crmSecurity.CreateSecurityException();

return InternalInvoke(context, crmSecurity, setupInfo, fileSizeComment, contactPhotoManager, organisationLogoManager);
}

private async System.Threading.Tasks.Task InternalInvoke(HttpContext context,
CrmSecurity crmSecurity,
SetupInfo setupInfo,
FileSizeComment fileSizeComment,
ContactPhotoManager contactPhotoManager,
OrganisationLogoManager organisationLogoManager)
{
var fileUploadResult = new FileUploadResult();

if (context.Request.Form.Files.Count == 0)
Expand Down
9 changes: 7 additions & 2 deletions products/ASC.Files/Core/Core/Dao/TeamlabDao/FileDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,17 +1507,22 @@ internal protected DbFile InitDocument(DbFile dbFile)
return dbFile;
}

internal protected async Task<DbFile> InitDocumentAsync(DbFile dbFile)
internal protected Task<DbFile> InitDocumentAsync(DbFile dbFile)
{
if (!FactoryIndexer.CanIndexByContent(dbFile))
{
dbFile.Document = new Document
{
Data = Convert.ToBase64String(Encoding.UTF8.GetBytes(""))
};
return dbFile;
return Task.FromResult(dbFile);
}

return InernalInitDocumentAsync(dbFile);
}

private async Task<DbFile> InernalInitDocumentAsync(DbFile dbFile)
{
var file = ServiceProvider.GetService<File<int>>();
file.ID = dbFile.Id;
file.Title = dbFile.Title;
Expand Down

0 comments on commit 50c0596

Please sign in to comment.