Skip to content

Commit

Permalink
Merge pull request #503 from ONLYOFFICE/feature/analizators
Browse files Browse the repository at this point in the history
Feature/analizators
  • Loading branch information
pavelbannov authored Feb 7, 2022
2 parents e16d758 + b2079cc commit 08c6040
Show file tree
Hide file tree
Showing 498 changed files with 4,762 additions and 4,741 deletions.
6 changes: 3 additions & 3 deletions common/ASC.Api.Core/Auth/ConfirmAuthHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
return SecurityContext.IsAuthenticated
? Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name)))
: Task.FromResult(AuthenticateResult.Fail(new AuthenticationException(HttpStatusCode.Unauthorized.ToString())));
: Task.FromResult(AuthenticateResult.Fail(new AuthenticationException(nameof(HttpStatusCode.Unauthorized))));
}

EmailValidationKeyProvider.ValidationResult checkKeyResult;
Expand Down Expand Up @@ -105,14 +105,14 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
var result = checkKeyResult switch
{
EmailValidationKeyProvider.ValidationResult.Ok => AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name)),
_ => AuthenticateResult.Fail(new AuthenticationException(HttpStatusCode.Unauthorized.ToString()))
_ => AuthenticateResult.Fail(new AuthenticationException(nameof(HttpStatusCode.Unauthorized)))
};

return Task.FromResult(result);
}
}

public class ConfirmAuthHandlerExtension
public static class ConfirmAuthHandlerExtension
{
public static void Register(DIHelper services)
{
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Api.Core/Auth/CookieAuthHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
return Task.FromResult(
result ?
AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name)) :
AuthenticateResult.Fail(new AuthenticationException(HttpStatusCode.Unauthorized.ToString()))
AuthenticateResult.Fail(new AuthenticationException(nameof(HttpStatusCode.Unauthorized)))
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Api.Core/Core/ApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class ApiContext : ICloneable
{
private static int MaxCount = 1000;
public IHttpContextAccessor HttpContextAccessor { get; set; }
public Tenant tenant;
public Tenant Tenant { get { return tenant ??= TenantManager.GetCurrentTenant(HttpContextAccessor?.HttpContext); } }
private Tenant _tenant;
public Tenant Tenant { get { return _tenant ??= TenantManager.GetCurrentTenant(HttpContextAccessor?.HttpContext); } }

public ApiContext(IHttpContextAccessor httpContextAccessor, SecurityContext securityContext, TenantManager tenantManager)
{
Expand Down
8 changes: 4 additions & 4 deletions common/ASC.Api.Core/Core/ApiDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
namespace ASC.Api.Core
{
[TypeConverter(typeof(ApiDateTimeTypeConverter))]
public class ApiDateTime : IComparable<ApiDateTime>, IComparable
public sealed class ApiDateTime : IComparable<ApiDateTime>, IComparable
{
internal static readonly string[] Formats = new[]
{
Expand Down Expand Up @@ -88,7 +88,7 @@ public static ApiDateTime Parse(string data, TenantManager tenantManager, TimeZo

public static ApiDateTime Parse(string data, TimeZoneInfo tz, TenantManager tenantManager, TimeZoneConverter timeZoneConverter)
{
if (string.IsNullOrEmpty(data)) throw new ArgumentNullException("data");
if (string.IsNullOrEmpty(data)) throw new ArgumentNullException(nameof(data));

if (data.Length < 7) throw new ArgumentException("invalid date time format");

Expand All @@ -97,7 +97,7 @@ public static ApiDateTime Parse(string data, TimeZoneInfo tz, TenantManager tena
{
//Parse time
var tzOffset = TimeSpan.Zero;
if (offsetPart.Contains(":") && TimeSpan.TryParse(offsetPart.TrimStart('+'), out tzOffset))
if (offsetPart.Contains(':') && TimeSpan.TryParse(offsetPart.TrimStart('+'), out tzOffset))
{
return new ApiDateTime(dateTime, tzOffset);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ public override bool Equals(object obj)
{
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof(ApiDateTime)) return false;
if (!(obj is ApiDateTime)) return false;
return Equals((ApiDateTime)obj);
}

Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Api.Core/Core/BaseStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
Expand Down Expand Up @@ -68,6 +67,7 @@ public virtual void ConfigureServices(IServiceCollection services)
services.AddCustomHealthCheck(Configuration);
services.AddHttpContextAccessor();
services.AddMemoryCache();
services.AddHttpClient();

if (AddAndUseSession)
services.AddSession();
Expand Down Expand Up @@ -131,7 +131,7 @@ public virtual void ConfigureServices(IServiceCollection services)
DIHelper.RegisterProducts(Configuration, HostEnvironment.ContentRootPath);
}

var builder = services.AddMvcCore(config =>
services.AddMvcCore(config =>
{
config.Conventions.Add(new ControllerNameAttributeConvention());

Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Api.Core/Core/CustomHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public static IServiceCollection AddCustomHealthCheck(this IServiceCollection se

var connectionString = configurationExtension.GetConnectionStrings("default");

if (String.Compare(connectionString.ProviderName, "MySql.Data.MySqlClient") == 0)
if (string.Equals(connectionString.ProviderName, "MySql.Data.MySqlClient"))
{
hcBuilder.AddMySql(connectionString.ConnectionString,
name: "mysqldb",
tags: new string[] { "mysqldb" }
);
}

if (String.Compare(connectionString.ProviderName, "Npgsql") == 0)
if (string.Equals(connectionString.ProviderName, "Npgsql"))
{
hcBuilder.AddNpgSql(connectionString.ConnectionString,
name: "postgredb",
Expand Down
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
2 changes: 1 addition & 1 deletion common/ASC.Api.Core/Middleware/TenantStatusFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void OnResourceExecuting(ResourceExecutingContext context)
if (tenant == null)
{
context.Result = new StatusCodeResult((int)HttpStatusCode.NotFound);
log.WarnFormat("Tenant {0} not found", tenant.TenantId);
log.WarnFormat("Current tenant not found");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Api.Core/Model/EmployeeWraperFull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public EmployeeWraperFull GetFull(UserInfo userInfo)
{
var listAdminModules = userInfo.GetListAdminModules(WebItemSecurity);

if (listAdminModules.Any())
if (listAdminModules.Count > 0)
result.ListAdminModules = listAdminModules;
}

Expand All @@ -283,7 +283,7 @@ private void FillConacts(EmployeeWraperFull employeeWraperFull, UserInfo userInf
}
}

if (contacts.Any())
if (contacts.Count > 0)
{
employeeWraperFull.Contacts = contacts;
}
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Api.Core/Routing/FormatRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class CustomHttpMethodAttribute : HttpMethodAttribute
public bool Check { get; set; }
public bool DisableFormat { get; set; }

public CustomHttpMethodAttribute(string method, string template = null, bool check = true, int order = 1)
protected CustomHttpMethodAttribute(string method, string template = null, bool check = true, int order = 1)
: base(new List<string>() { method }, $"[controller]{(template != null ? $"/{template}" : "")}")
{
Check = check;
Expand Down
6 changes: 2 additions & 4 deletions common/ASC.Common/Caching/AscCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
using System.Runtime.Caching;
using System.Text.RegularExpressions;

using Google.Protobuf;

using Microsoft.Extensions.Caching.Memory;

namespace ASC.Common.Caching
Expand All @@ -55,7 +53,7 @@ public void ClearCache()

public static void OnClearCache()
{
var keys = MemoryCache.Default.Select(r => r.Key).ToList();
var keys = MemoryCache.Default.Select(r => r.Key);

foreach (var k in keys)
{
Expand Down Expand Up @@ -114,7 +112,7 @@ public void Remove(string key)
public void Remove(Regex pattern)
{
var copy = MemoryCacheKeys.ToDictionary(p => p.Key, p => p.Value);
var keys = copy.Select(p => p.Key).Where(k => pattern.IsMatch(k)).ToArray();
var keys = copy.Select(p => p.Key).Where(k => pattern.IsMatch(k));

foreach (var key in keys)
{
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Common/Collections/CachedDictionaryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public bool HasItem(string key)

protected string BuildKey(string key, string rootkey)
{
return string.Format("{0}-{1}-{2}", baseKey, rootkey, key);
return $"{baseKey}-{rootkey}-{key}";
}

protected abstract object GetObjectFromCache(string fullKey);
Expand All @@ -106,7 +106,7 @@ public T Get(Func<T> @default)

protected virtual bool FitsCondition(object cached)
{
return cached != null && cached is T;
return cached is T;
}

public virtual T Get(string rootkey, string key, Func<T> defaults)
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Common/Collections/HttpRequestDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace ASC.Collections
{
public sealed class HttpRequestDictionary<T> : CachedDictionaryBase<T>
{
private class CachedItem
private sealed class CachedItem
{
internal T Value { get; set; }

Expand Down
10 changes: 5 additions & 5 deletions common/ASC.Common/DIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public abstract class DIAttribute : Attribute
public Type Service { get; }
public Type Additional { get; set; }

public DIAttribute() { }
protected DIAttribute() { }

public DIAttribute(Type service)
protected DIAttribute(Type service)
{
Service = service;
}

public DIAttribute(Type service, Type implementation)
protected DIAttribute(Type service, Type implementation)
{
Implementation = implementation;
Service = service;
Expand Down Expand Up @@ -233,7 +233,7 @@ public bool TryAdd(Type service, Type implementation = null)
}
else
{
Type c = null;
Type c;
var a1 = a.GetGenericTypeDefinition();
var b = a.GetGenericArguments().FirstOrDefault();

Expand Down Expand Up @@ -297,7 +297,7 @@ public bool TryAdd(Type service, Type implementation = null)
}
else
{
Type c = null;
Type c;
var a1 = a.GetGenericTypeDefinition();
var b = a.GetGenericArguments().FirstOrDefault();

Expand Down
36 changes: 20 additions & 16 deletions common/ASC.Common/Data/StreamExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@
using System;
using System.IO;

public static class StreamExtension

namespace ASC.Common.Data
{
public const int BufferSize = 2048; //NOTE: set to 2048 to fit in minimum tcp window

public static void StreamCopyTo(this Stream srcStream, Stream dstStream, int length)
public static class StreamExtension
{
if (srcStream == null) throw new ArgumentNullException("srcStream");
if (dstStream == null) throw new ArgumentNullException("dstStream");

var buffer = new byte[BufferSize];
int totalRead = 0;
int readed;
while ((readed = srcStream.Read(buffer, 0, length - totalRead > BufferSize ? BufferSize : length - totalRead)) > 0 && totalRead < length)
public const int BufferSize = 2048; //NOTE: set to 2048 to fit in minimum tcp window

public static void StreamCopyTo(this Stream srcStream, Stream dstStream, int length)
{
dstStream.Write(buffer, 0, readed);
totalRead += readed;
}
}
}
if (srcStream == null) throw new ArgumentNullException(nameof(srcStream));
if (dstStream == null) throw new ArgumentNullException(nameof(dstStream));

var buffer = new byte[BufferSize];
int totalRead = 0;
int readed;
while ((readed = srcStream.Read(buffer, 0, length - totalRead > BufferSize ? BufferSize : length - totalRead)) > 0 && totalRead < length)
{
dstStream.Write(buffer, 0, readed);
totalRead += readed;
}
}
}
}
2 changes: 1 addition & 1 deletion common/ASC.Common/Data/TempStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TempStream(TempPath tempPath)

public Stream GetBuffered(Stream srcStream)
{
if (srcStream == null) throw new ArgumentNullException("srcStream");
if (srcStream == null) throw new ArgumentNullException(nameof(srcStream));
if (!srcStream.CanSeek || srcStream.CanTimeout)
{
//Buffer it
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Common/DependencyInjection/AutofacExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static List<string> FindAndLoad(IConfiguration configuration, string curr

void LoadAssembly(string type)
{
var dll = type.Substring(type.IndexOf(",") + 1).Trim();
var dll = type.Substring(type.IndexOf(',') + 1).Trim();
var path = GetFullPath(dll);

if (!string.IsNullOrEmpty(path))
Expand Down
6 changes: 3 additions & 3 deletions common/ASC.Common/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -875,19 +875,19 @@ public override T Get(string name)
}
}

public class LoggerExtension<T> where T : class, ILog, new()
public static class LoggerExtension<T> where T : class, ILog, new()
{
public static void RegisterLog(DIHelper services)
{
services.TryAdd(typeof(IOptionsMonitor<ILog>), typeof(LogManager<T>));
}
}

public class LogNLogExtension : LoggerExtension<LogNLog>
public static class LogNLogExtension
{
public static void Register(DIHelper services)
{
RegisterLog(services);
LoggerExtension<LogNLog>.RegisterLog(services);
}
}
}
6 changes: 2 additions & 4 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 Expand Up @@ -111,7 +109,7 @@ private void Clean()
{
Exception = err,
Level = LogLevel.Error,
Message = string.Format("file: {0}, dir: {1}, mess: {2}", filePath, dirPath, err.Message),
Message = $"file: {filePath}, dir: {dirPath}, mess: {err.Message}",
LoggerName = "SelfCleaningTarget"
});
}
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Common/Logging/SpecialFolderPathConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected override void Convert(TextWriter writer, object state)
var args = Environment.CommandLine.Split(' ');
for (var i = 0; i < args.Length - 1; i++)
{
if (args[i].Equals(Option.Substring(CMD_LINE.Length), StringComparison.InvariantCultureIgnoreCase))
if (args[i].Contains(Option, StringComparison.InvariantCultureIgnoreCase))
{
result = args[i + 1];
}
Expand Down
3 changes: 1 addition & 2 deletions common/ASC.Common/Mapping/MappingProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ private void ApplyMappingsFromAssembly(Assembly assembly)

var types = assembly.GetExportedTypes()
.Where(t => t.GetInterfaces().Any(i =>
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>)))
.ToList();
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>)));

foreach (var type in types)
{
Expand Down
Loading

0 comments on commit 08c6040

Please sign in to comment.