Merge branch 'master' of github.com:ONLYOFFICE/CommunityServer-AspNetCore

This commit is contained in:
Alexey Safronov 2019-05-30 10:34:44 +03:00
commit 49609fed77
25 changed files with 238 additions and 133 deletions

View File

@ -1,43 +1,55 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.202
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Studio", "web\ASC.Web.Studio\ASC.Web.Studio.csproj", "{90183112-BCD6-4E16-9CA2-12231930DAB4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Api", "web\ASC.Web.Api\ASC.Web.Api.csproj", "{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Common", "common\ASC.Common\ASC.Common.csproj", "{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Core.Common", "common\ASC.Core.Common\ASC.Core.Common.csproj", "{A51D0454-4AFA-46DE-89D4-B03D37E1816C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{90183112-BCD6-4E16-9CA2-12231930DAB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90183112-BCD6-4E16-9CA2-12231930DAB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90183112-BCD6-4E16-9CA2-12231930DAB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90183112-BCD6-4E16-9CA2-12231930DAB4}.Release|Any CPU.Build.0 = Release|Any CPU
{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Release|Any CPU.Build.0 = Release|Any CPU
{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Release|Any CPU.Build.0 = Release|Any CPU
{A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {62783077-E041-40BA-A406-E7EF12CAFF2D}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.202
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Studio", "web\ASC.Web.Studio\ASC.Web.Studio.csproj", "{90183112-BCD6-4E16-9CA2-12231930DAB4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Api", "web\ASC.Web.Api\ASC.Web.Api.csproj", "{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Common", "common\ASC.Common\ASC.Common.csproj", "{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Core.Common", "common\ASC.Core.Common\ASC.Core.Common.csproj", "{A51D0454-4AFA-46DE-89D4-B03D37E1816C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.People", "products\ASC.People\ASC.People.csproj", "{BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASC.Api.Core", "common\ASC.Api.Core\ASC.Api.Core.csproj", "{62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{90183112-BCD6-4E16-9CA2-12231930DAB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90183112-BCD6-4E16-9CA2-12231930DAB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90183112-BCD6-4E16-9CA2-12231930DAB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90183112-BCD6-4E16-9CA2-12231930DAB4}.Release|Any CPU.Build.0 = Release|Any CPU
{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Release|Any CPU.Build.0 = Release|Any CPU
{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Release|Any CPU.Build.0 = Release|Any CPU
{A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Release|Any CPU.Build.0 = Release|Any CPU
{BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}.Release|Any CPU.Build.0 = Release|Any CPU
{62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {62783077-E041-40BA-A406-E7EF12CAFF2D}
EndGlobalSection
EndGlobal

14
build/build.bat Normal file
View File

@ -0,0 +1,14 @@
PUSHD %~dp0
echo "ASC.Web.Components"
cd ../web/ASC.Web.Components
call npm install
echo "ASC.Web.sln"
cd ../../
call dotnet build ASC.Web.sln
echo "ASC.People"
call dotnet publish products/ASC.People --self-contained -r win10-x64 -o build/deploy
echo "ASC.Web.Api"
call dotnet publish web/ASC.Web.Api --self-contained -r win10-x64 -o build/deploy

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ASC.Common\ASC.Common.csproj" />
<ProjectReference Include="..\ASC.Core.Common\ASC.Core.Common.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,9 @@
using System;
namespace ASC.Api.Core
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public class CustomApiAttribute : Attribute
{
}
}

View File

@ -29,6 +29,7 @@ namespace ASC.Web.Api.Middleware
var currentBody = context.Response.Body;
using var memoryStream = new MemoryStream();
context.Response.Body = memoryStream;
await next(context);

View File

@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:65458/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ASC.Api.Core": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:65459/"
}
}
}

View File

@ -34,6 +34,7 @@
<ItemGroup>
<PackageReference Include="ARSoft.Tools.NetStandard.DXSdata" Version="1.0.0" />
<PackageReference Include="Autofac" Version="4.9.2" />
<PackageReference Include="Autofac.Configuration" Version="4.1.0" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
@ -46,6 +47,7 @@
<PackageReference Include="MySql.Data" Version="8.0.16" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NLog" Version="4.6.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.2" />
<PackageReference Include="NVelocity" Version="1.2.0" />
<PackageReference Include="StackExchange.Redis" Version="2.0.601" />
<PackageReference Include="StackExchange.Redis.Extensions.Core" Version="5.0.2" />

View File

@ -30,9 +30,11 @@ using System.Collections.Generic;
using System.Reflection;
using ASC.Common.DependencyInjection;
using Autofac;
using Autofac.Configuration;
using log4net.Config;
using log4net.Core;
using log4net.Util;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NLog;
namespace ASC.Common.Logging
@ -754,30 +756,48 @@ namespace ASC.Common.Logging
public class LogManager
{
internal static IContainer Builder { get; set; }
internal IContainer Builder { get; set; }
internal static ConcurrentDictionary<string, ILog> Logs;
static LogManager()
{
var container = AutofacConfigLoader.Load("core");
if (container != null)
{
Builder = container.Build();
}
Logs = new ConcurrentDictionary<string, ILog>();
}
public LogManager(IContainer builder)
{
Builder = builder;
}
public static ILog GetLogger(string name)
{
{
var logManager = CommonServiceProvider.GetService<LogManager>();
ILog result;
if (!Logs.TryGetValue(name, out result))
{
result = Logs.AddOrUpdate(name, Builder != null ? Builder.Resolve<ILog>(new TypedParameter(typeof(string), name)) : new NullLog(), (k, v) => v);
result = Logs.AddOrUpdate(name, logManager.Builder != null ? logManager.Builder.Resolve<ILog>(new TypedParameter(typeof(string), name)) : new NullLog(), (k, v) => v);
}
return result;
}
}
public static class LogExtension
{
public static IServiceCollection AddLogManager(this IServiceCollection services, IConfiguration configuration)
{
var module = new ConfigurationModule(configuration);
var builder = new ContainerBuilder();
builder.RegisterModule(module);
var container = builder.Build();
services.AddSingleton(container)
.AddSingleton<LogManager>();
return services;
}
}
}

View File

@ -10,6 +10,10 @@
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>false</Optimize>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview4-19216-03" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.0.0-preview4-19216-03" />
@ -22,6 +26,11 @@
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\ASC.Api.Core\ASC.Api.Core.csproj" />
</ItemGroup>
<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">

View File

@ -0,0 +1,4 @@

using ASC.Api.Core;
[assembly: CustomApi]

View File

@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace ASC.People.Controllers
{
[Route("api/[controller]")]
public class SampleDataController : Controller
{
private static string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
[HttpGet("[action]")]
public IEnumerable<WeatherForecast> WeatherForecasts()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
});
}
public class WeatherForecast
{
public string DateFormatted { get; set; }
public int TemperatureC { get; set; }
public string Summary { get; set; }
public int TemperatureF
{
get
{
return 32 + (int)(TemperatureC / 0.5556);
}
}
}
}
}

View File

@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace ASC.People
{

View File

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

View File

@ -1,8 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -6,18 +6,14 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview4-19216-03" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview3.19153.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0-preview3.19153.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0-preview3.19153.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0-preview5-19264-04" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\ASC.Common\ASC.Common.csproj" />
<ProjectReference Include="..\..\common\ASC.Core.Common\ASC.Core.Common.csproj" />
<ItemGroup>
<ProjectReference Include="..\..\common\ASC.Api.Core\ASC.Api.Core.csproj" />
<ProjectReference Include="..\..\common\ASC.Common\ASC.Common.csproj" />
<ProjectReference Include="..\..\common\ASC.Core.Common\ASC.Core.Common.csproj" />
</ItemGroup>
</Project>

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
namespace ASC.Web.Api
{
public class Program
@ -15,6 +16,9 @@ namespace ASC.Web.Api
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
})
.ConfigureAppConfiguration((hostingContext, config) => {
config.AddJsonFile("autofac.json");
});
}
}

View File

@ -8,20 +8,27 @@ using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ASC.Api.Core;
using ASC.Common.Logging;
using ASC.Web.Api.Handlers;
using ASC.Web.Api.Middleware;
using System.Linq;
using System.Reflection;
using System.IO;
namespace ASC.Web.Api
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers()
@ -32,12 +39,22 @@ namespace ASC.Web.Api
services.AddAuthentication("cookie").AddScheme<AuthenticationSchemeOptions, CookieAuthHandler>("cookie", a=> { });
services.AddMvc(config =>
var builder = services.AddMvc(config =>
{
var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter)));
config.Filters.Add(new AuthorizeFilter(policy));
});
var assemblies = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.dll")
.Select(Assembly.LoadFrom)
.Where(r => r.GetCustomAttribute<CustomApiAttribute>() != null);
foreach (var a in assemblies) {
builder.AddApplicationPart(a);
}
services.AddLogManager(Configuration);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

View File

@ -0,0 +1,12 @@
{
"components": [
{
"type": "ASC.Common.Logging.LogNLog, ASC.Common",
"services": [
{
"type": "ASC.Common.Logging.ILog, ASC.Common"
}
]
}
]
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog>
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="ASC.Common"/>
</extensions>
<variable name="logDirectory" value="..\Logs\"/>
<conversionPattern value=""/>
<targets async="true">
<default-target-parameters type="SelfCleaning" archiveNumbering="DateAndSequence" archiveEvery="Day" enableArchiveFileCompression="true" archiveAboveSize="52428800" keepFileOpen="true" archiveDateFormat="MM-dd" layout="${date:format=yyyy-MM-dd HH\:mm\:ss,fff} ${level:uppercase=true} [${threadid}] ${logger} - ${message} ${exception:format=ToString}"/>
<target name="web" type="SelfCleaning" fileName="${logDirectory}web.log" />
<target name="sql" type="SelfCleaning" fileName="${logDirectory}web.sql.log" layout="${date:universalTime=true:format=yyyy-MM-dd HH\:mm\:ss,fff}|${threadid}|${event-properties:item=duration}|${message}|${event-properties:item=sql}|${event-properties:item=sqlParams}"/>
<target name="files" type="SelfCleaning" fileName="${logDirectory}web.files.log"/>
<target name="api" type="SelfCleaning" fileName="${logDirectory}web.api.log"/>
<target name="notify" type="SelfCleaning" fileName="${logDirectory}web.notify.log" />
<target name="ownFile-web" type="File" fileName="${logDirectory}web.asp.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
</targets>
<rules>
<logger name="ASC.SQL" minlevel="Debug" writeTo="sql" final ="true" />
<logger name="ASC.Files" minlevel="Debug" writeTo="files" final ="true" />
<logger name="ASC.Api" minlevel="Debug" writeTo="api" final ="true" />
<logger name="ASC.Notify.Messages" minlevel="Debug" writeTo="notify" final ="true" />
<logger name="ASC*" minlevel="Debug" writeTo="web" />
<logger name="Microsoft.*" maxlevel="Info" writeTo="web" final="true" />
</rules>
</nlog>