save_everything
This commit is contained in:
parent
388ebd964b
commit
5d280daf74
@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
|
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
|
||||||
<PackageReference Include="System.Data.SQLite" Version="1.0.115.5" />
|
<PackageReference Include="System.Data.SQLite" Version="1.0.115.5" />
|
||||||
<PackageReference Include="System.Data.SQLite.EF6" Version="1.0.115.5" />
|
<PackageReference Include="System.Data.SQLite.EF6" Version="1.0.115.5" />
|
||||||
<PackageReference Include="System.Data.SQLite.Linq" Version="1.0.115.5" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -4,19 +4,22 @@ using Cuipod;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Net;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Chatter.Logic.Actions
|
namespace Chatter.Logic.Actions
|
||||||
{
|
{
|
||||||
public static class ListActionManager
|
public class ListActionManager
|
||||||
{
|
{
|
||||||
public static Action<Request, Response, ILogger<App>> GetListAction() =>
|
public readonly IMessageService _messageService;
|
||||||
(request, response, logger) => {
|
|
||||||
var service = new MessageService();
|
|
||||||
|
|
||||||
IEnumerable<MessageModel> messages = service.GetMessages();
|
public ListActionManager(IMessageService messageService)
|
||||||
|
{
|
||||||
|
_messageService = messageService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action<Request, Response, ILogger<App>> GetListAction() =>
|
||||||
|
(request, response, logger) => {
|
||||||
|
IEnumerable<MessageModel> messages = _messageService.GetMessages();
|
||||||
|
|
||||||
response.RenderPlainTextLine("# Chatter");
|
response.RenderPlainTextLine("# Chatter");
|
||||||
response.RenderPlainTextLine("");
|
response.RenderPlainTextLine("");
|
||||||
@ -47,7 +50,7 @@ namespace Chatter.Logic.Actions
|
|||||||
//todo: pagination here?
|
//todo: pagination here?
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Action<Request, Response, ILogger<App>> PostAction() =>
|
public Action<Request, Response, ILogger<App>> PostAction() =>
|
||||||
(request, response, logger) => {
|
(request, response, logger) => {
|
||||||
if (string.IsNullOrEmpty(request.Parameters))
|
if (string.IsNullOrEmpty(request.Parameters))
|
||||||
{
|
{
|
||||||
@ -56,17 +59,23 @@ namespace Chatter.Logic.Actions
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
// redirect to show/ route with input parameters
|
// redirect to show/ route with input parameters
|
||||||
var model = new PostModel()
|
var model = new PostModel()
|
||||||
{
|
{
|
||||||
Text = request.Parameters
|
Text = WebUtility.UrlDecode(request.Parameters)
|
||||||
};
|
};
|
||||||
var service = new MessageService();
|
_messageService.AddMessage(model);
|
||||||
service.AddMessage(model);
|
|
||||||
|
|
||||||
response.SetRedirectURL(request.BaseURL + "/list");
|
response.SetRedirectURL(request.BaseURL + "/list");
|
||||||
response.Status = StatusCode.RedirectTemp;
|
response.Status = StatusCode.RedirectTemp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public Action<Request, Response, ILogger<App>> LoginAction() =>
|
||||||
|
(request, response, logger) => {
|
||||||
|
response.RenderPlainTextLine("Cert required");
|
||||||
|
response.Status = StatusCode.ClientCertRequired;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
using Chatter.Logic.Actions;
|
using Chatter.Connector;
|
||||||
|
using Chatter.Logic.Actions;
|
||||||
|
using Chatter.Repository;
|
||||||
|
using Chatter.Service;
|
||||||
using Cuipod;
|
using Cuipod;
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
using System.Security.Cryptography.X509Certificates;
|
||||||
@ -45,6 +49,17 @@ namespace Chatter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ServiceProvider GetServiceProvider()
|
||||||
|
{
|
||||||
|
var serviceCollection = new ServiceCollection();
|
||||||
|
serviceCollection.AddSingleton<IDbConnector, SqLiteConnector>();
|
||||||
|
serviceCollection.AddScoped<IMessageService, MessageService>();
|
||||||
|
serviceCollection.AddScoped<IMessageRepository, MessageRepository>();
|
||||||
|
serviceCollection.AddScoped<ListActionManager>();
|
||||||
|
|
||||||
|
return serviceCollection.BuildServiceProvider();
|
||||||
|
}
|
||||||
|
|
||||||
private static int AppMain(string directoryToServe, X509Certificate2 certificate)
|
private static int AppMain(string directoryToServe, X509Certificate2 certificate)
|
||||||
{
|
{
|
||||||
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
|
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
|
||||||
@ -57,6 +72,8 @@ namespace Chatter
|
|||||||
.SetMinimumLevel(LogLevel.Debug)
|
.SetMinimumLevel(LogLevel.Debug)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
using var serviceProvider = GetServiceProvider();
|
||||||
|
|
||||||
ILogger<App> logger = loggerFactory.CreateLogger<App>();
|
ILogger<App> logger = loggerFactory.CreateLogger<App>();
|
||||||
|
|
||||||
App app = new App(
|
App app = new App(
|
||||||
@ -70,8 +87,9 @@ namespace Chatter
|
|||||||
response.RenderFileContent("index.gmi");
|
response.RenderFileContent("index.gmi");
|
||||||
});
|
});
|
||||||
|
|
||||||
app.OnRequest("/list", ListActionManager.GetListAction());
|
app.OnRequest("/list", serviceProvider.GetService<ListActionManager>().GetListAction());
|
||||||
app.OnRequest("/post", ListActionManager.PostAction());
|
app.OnRequest("/post", serviceProvider.GetService<ListActionManager>().PostAction());
|
||||||
|
app.OnRequest("/login", serviceProvider.GetService<ListActionManager>().LoginAction());
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
|
|||||||
@ -20,24 +20,19 @@ namespace Chatter.Repository
|
|||||||
{
|
{
|
||||||
private readonly IDbConnector _connector;
|
private readonly IDbConnector _connector;
|
||||||
|
|
||||||
public MessageRepository()
|
public MessageRepository(IDbConnector connector)
|
||||||
{
|
{
|
||||||
|
_connector = connector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddMessage(MessageDto msg)
|
public void AddMessage(MessageDto msg)
|
||||||
{
|
{
|
||||||
using (var connector = new SqLiteConnector())
|
_connector.AddMessage(msg);
|
||||||
{
|
|
||||||
connector.AddMessage(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<MessageDto> GetMessages()
|
public IEnumerable<MessageDto> GetMessages()
|
||||||
{
|
{
|
||||||
using (var connector = new SqLiteConnector())
|
return _connector.GetMessages();
|
||||||
{
|
|
||||||
return connector.GetMessages();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,9 +20,9 @@ namespace Chatter.Service
|
|||||||
{
|
{
|
||||||
public readonly IMessageRepository _repository;
|
public readonly IMessageRepository _repository;
|
||||||
|
|
||||||
public MessageService()
|
public MessageService(IMessageRepository repository)
|
||||||
{
|
{
|
||||||
_repository = new MessageRepository();
|
_repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<MessageModel> GetMessages()
|
public IEnumerable<MessageModel> GetMessages()
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
# Chatter gemini app
|
# Chatter gemini app
|
||||||
This is chatter gemini app. An application can be used for chat with several different users. The idea of the project is to have the least amount of data stored permanently.
|
|
||||||
|
|
||||||
## Requirements:
|
This is chatter gemini app. An application can be used for chat with several different users. The idea of the project is to have the least amount of data stored permanently. This project uses sqlite in-memory database to store messages which means every time you reload it you lose all data.
|
||||||
* redis -- messages
|
|
||||||
* nosql database -- permanent userdata
|
|
||||||
|
|
||||||
=> /list Message list
|
=> /list Message list
|
||||||
=> /post Post message
|
=> /post Post message
|
||||||
@ -5,9 +5,7 @@ VisualStudioVersion = 17.0.31919.166
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cuipod", "Cuipod\Cuipod.csproj", "{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cuipod", "Cuipod\Cuipod.csproj", "{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CuipodExample", "CuipodExample\CuipodExample.csproj", "{BD343B0B-29EB-4498-8CD2-D9483B6BDA98}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chatter", "Chatter\Chatter.csproj", "{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}"
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chatter", "Chatter\Chatter.csproj", "{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}"
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -19,10 +17,6 @@ Global
|
|||||||
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Release|Any CPU.Build.0 = Release|Any CPU
|
{2B6AD5A5-F10B-4FC3-BF12-5DD26FAF3796}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{BD343B0B-29EB-4498-8CD2-D9483B6BDA98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{BD343B0B-29EB-4498-8CD2-D9483B6BDA98}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{BD343B0B-29EB-4498-8CD2-D9483B6BDA98}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{BD343B0B-29EB-4498-8CD2-D9483B6BDA98}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{20C8B6F9-63FB-458D-921E-5DFD6EBE4435}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|||||||
@ -100,7 +100,22 @@ namespace Cuipod
|
|||||||
private Response ProcessRequest(SslStream sslStream)
|
private Response ProcessRequest(SslStream sslStream)
|
||||||
{
|
{
|
||||||
sslStream.ReadTimeout = 5000;
|
sslStream.ReadTimeout = 5000;
|
||||||
sslStream.AuthenticateAsServer(_serverCertificate, false, SslProtocols.Tls12 | SslProtocols.Tls13, false);
|
sslStream.AuthenticateAsServer(new SslServerAuthenticationOptions()
|
||||||
|
{
|
||||||
|
ServerCertificate = _serverCertificate,
|
||||||
|
EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13,
|
||||||
|
ClientCertificateRequired = false,
|
||||||
|
CertificateRevocationCheckMode = X509RevocationMode.NoCheck
|
||||||
|
});
|
||||||
|
//sslStream.AuthenticateAsServer(_serverCertificate, false, , false);
|
||||||
|
//var clientCertificate = sslStream.RemoteCertificate;
|
||||||
|
//var clientCertificateHash = Convert.ToBase64String(clientCertificate.GetCertHash());
|
||||||
|
|
||||||
|
//var username = clientCertificate.Issuer;
|
||||||
|
//if (sslStream.IsMutuallyAuthenticated)
|
||||||
|
//{
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
// Read a message from the client.
|
// Read a message from the client.
|
||||||
string rawRequest = ReadRequest(sslStream);
|
string rawRequest = ReadRequest(sslStream);
|
||||||
|
|||||||
Reference in New Issue
Block a user