Skip to content

Commit

Permalink
Merge pull request #52 from mhelvacikoylu/v2
Browse files Browse the repository at this point in the history
2.7.12
  • Loading branch information
mhelvacikoylu authored Feb 28, 2020
2 parents a39d342 + d9c39e3 commit 3f89e97
Show file tree
Hide file tree
Showing 200 changed files with 1,487 additions and 1,033 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# Twino
# What's Twino?

**Twino** is a .NET Core TCP Server provides multiple protocols on same host.<br>
**Twino** is an extensible .NET Core TCP Server provides multiple protocols on same host.<br>
**Twino** is a complete Messaging Queue server library.<br>
**Twino** is a WebSocket server with advanced client management.<br>
**Twino** is a HTTP server with MVC Support.<br>

Twino HTTP Server supports MVC architecture.<br>
Twino WebSockets provides advanced WebSocket server management<br>
Twino MQ provides quick messaging queue server library<br>
Twino IOC can be used on all protocols.
**Twino** is an HTTP server with MVC Architecture.<br>
**Twino** is an IOC Library with service pools and scopes.<br>
**Twino** is a WebSocket Client.<br>

## Why Twino?

Expand Down
2 changes: 1 addition & 1 deletion src/Benchmarks/Http/Benchmark.Json/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static void Main(string[] args)
server.UseHttp(async (request, response) =>
{
if (request.Path.Equals("/json", StringComparison.InvariantCultureIgnoreCase))
response.SetToJson(new {message = "Hello, World!"});
response.SetToJson(new { message = "Hello, World!" });
else
response.StatusCode = HttpStatusCode.NotFound;
Expand Down
1 change: 0 additions & 1 deletion src/Benchmarks/Http/Benchmark.PlainText/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Twino.Protocols.Http;
Expand Down
2 changes: 1 addition & 1 deletion src/Benchmarks/Mvc/Benchmark.Mvc.Json/JsonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class JsonController : TwinoController
[HttpGet]
public async Task<IActionResult> Get()
{
return await JsonAsync(new {message = "Hello, World!"});
return await JsonAsync(new { message = "Hello, World!" });
}
}
}
1 change: 0 additions & 1 deletion src/Benchmarks/Mvc/Benchmark.Mvc.PlainText/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Twino.Mvc;
using Twino.Protocols.Http;
using Twino.Server;

namespace Benchmark.Mvc.PlainText
Expand Down
131 changes: 72 additions & 59 deletions src/Samples/Playground/Program.cs
Original file line number Diff line number Diff line change
@@ -1,77 +1,90 @@
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Twino.MQ.Data;
using Twino.Protocols.TMQ;
using Twino.Ioc;

namespace Playground
{
class Program

interface IService1
{
static async Task Main(string[] args)
{
Database database = new Database(new DatabaseOptions
{
Filename = "/home/mehmet/Desktop/test.tdb",
AutoFlush = true,
AutoShrink = true,
InstantFlush = false,
ShrinkInterval = TimeSpan.FromSeconds(30),
FlushInterval = TimeSpan.FromSeconds(5),
CreateBackupOnShrink = true
});
void Test1();
}

await database.Open();
var messages = await database.List();
Console.WriteLine($"There are {messages.Count} messages in database");
interface IService2
{
void Test2();
}

DefaultUniqueIdGenerator generator = new DefaultUniqueIdGenerator();
while (true)
{
string command = Console.ReadLine();
if (string.IsNullOrEmpty(command))
break;
class Service1 : IService1
{

switch (command.ToLower())
{
case "i":
for (int i = 0; i < 300; i++)
{
TmqMessage message = new TmqMessage(MessageType.Channel, "channel");
message.SetMessageId(generator.Create());
message.SetStringContent("Hello, World!");
public void Test1()
{
Console.WriteLine("echo 1");
}
}

bool saved = await database.Insert(message);
Console.WriteLine(saved ? "Saved" : "Failed");
}
class Service2 : IService2
{
public void Test2()
{ }
}

break;
interface IService3 { }
class Service3 : IService3
{
public Service3(IService1 service1)
{
service1.Test1();
}
}

case "d":
for (int j = 0; j < 100; j++)
{
var list = await database.List();
if (list.Count > 2)
{
Random rnd = new Random();
int i = rnd.Next(1, list.Count - 1);
var first = list.Skip(i).FirstOrDefault();
bool deleted = await database.Delete(first.Key);
Console.WriteLine($"Delete {first.Value} is {deleted}");
}
}
class Service1Proxy : IServiceProxy
{
private IService2 _service2;
public Service1Proxy(IService2 service2)
{
_service2 = service2;
}

break;
public object Proxy(object decorated)
{
return DenemeDispatchProxy<IService1>.Create((IService1)decorated, _service2);
}
}

case "s":
ShrinkInfo shrink = await database.Shrink();
Console.WriteLine($"Database shrink: {shrink.Successful} in {shrink.TotalDuration.TotalMilliseconds} ms");
break;
}
}

await database.Close();
Console.WriteLine("Database closed");
class DenemeDispatchProxy<T> : DispatchProxy
{
private T _decorated;
private IService2 _service2;
public static T Create(T decorated, IService2 service2)
{
object proxy = Create<T, DenemeDispatchProxy<T>>();
DenemeDispatchProxy<T> instance = (DenemeDispatchProxy<T>)proxy;
instance._decorated = decorated;
instance._service2 = service2;
return (T)proxy;
}

protected override object Invoke(MethodInfo targetMethod, object[] args)
{
Console.WriteLine("PROXY");
return targetMethod.Invoke(_decorated, args);
}
}

class Program
{
static async Task Main(string[] args)
{
var container = new ServiceContainer();
container.AddSingleton<IService1, Service1, Service1Proxy>();
container.AddSingleton<IService2, Service2>();
container.AddSingleton<IService3, Service3>();
var instance3 = await container.Get<IService3>(container.CreateScope());
Console.ReadLine();
}
}
}
2 changes: 0 additions & 2 deletions src/Samples/Sample.Connectors/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using Twino.Client;
using Twino.Client.Connectors;
using Twino.Client.WebSocket;
using Twino.Client.WebSocket.Connectors;
using Twino.Core;
Expand Down
6 changes: 2 additions & 4 deletions src/Samples/Sample.Http.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Twino.Server;
using System;
using System;
using System.Net;
using System.Text;
using Twino.Client.WebSocket;
using Twino.Protocols.Http;
using Twino.Server;

namespace Sample.Http.Server
{
Expand Down
36 changes: 18 additions & 18 deletions src/Samples/Sample.MQ.Data/Overload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public class Overload
public async Task OverloadAsync()
{
Database db = new Database(new DatabaseOptions
{
Filename = "/home/mehmet/Desktop/tdb/test.tdb",
AutoShrink = true,
ShrinkInterval = TimeSpan.FromMilliseconds(15000),
AutoFlush = true,
InstantFlush = false,
FlushInterval = TimeSpan.FromMilliseconds(250),
CreateBackupOnShrink = true
});
{
Filename = "/home/mehmet/Desktop/tdb/test.tdb",
AutoShrink = true,
ShrinkInterval = TimeSpan.FromMilliseconds(15000),
AutoFlush = true,
InstantFlush = false,
FlushInterval = TimeSpan.FromMilliseconds(250),
CreateBackupOnShrink = true
});

db.OnShrink += (database, info) =>
{
Expand Down Expand Up @@ -119,15 +119,15 @@ public async Task OverloadAsync()
Console.WriteLine("items : " + items.Count);

db = new Database(new DatabaseOptions
{
Filename = "/home/mehmet/Desktop/tdb/test.tdb",
AutoShrink = false,
ShrinkInterval = TimeSpan.FromMilliseconds(3000),
AutoFlush = true,
InstantFlush = false,
FlushInterval = TimeSpan.FromMilliseconds(250),
CreateBackupOnShrink = true
});
{
Filename = "/home/mehmet/Desktop/tdb/test.tdb",
AutoShrink = false,
ShrinkInterval = TimeSpan.FromMilliseconds(3000),
AutoFlush = true,
InstantFlush = false,
FlushInterval = TimeSpan.FromMilliseconds(250),
CreateBackupOnShrink = true
});

Stopwatch sw2 = new Stopwatch();
sw2.Start();
Expand Down
4 changes: 2 additions & 2 deletions src/Samples/Sample.MQ.Data/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ static async Task Main(string[] args)
while (true)
{
Overload o = new Overload();
await o.OverloadAsync();
await o.OverloadAsync();
}
}

}
}
4 changes: 2 additions & 2 deletions src/Samples/Sample.Mq/Consumer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Sample.Mq.Models;
using System;
using System.Threading;
using Sample.Mq.Models;
using Twino.Client.TMQ;
using Twino.Client.TMQ.Connectors;
using Twino.Core;
Expand Down Expand Up @@ -59,7 +59,7 @@ private void Connected(SocketBase client)
{
Console.WriteLine("consumer connection established");

TmqClient tc = (TmqClient) client;
TmqClient tc = (TmqClient)client;
tc.AutoAcknowledge = true;

tc.Join("AckChannel", false);
Expand Down
6 changes: 3 additions & 3 deletions src/Samples/Sample.Mq/Producer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Sample.Mq.Models;
using System;
using System.Threading;
using Sample.Mq.Models;
using Twino.Client.TMQ;
using Twino.Client.TMQ.Connectors;
using Twino.Core;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void Start()
private void Connected(SocketBase client)
{
Console.WriteLine("producer connection established");
TmqClient tmq = (TmqClient) client;
TmqClient tmq = (TmqClient)client;
if (_firstConnection)
{
_firstConnection = false;
Expand All @@ -80,7 +80,7 @@ private void MessageReceived(ClientSocketBase<TmqMessage> client, TmqMessage mes
TmqMessage response = message.CreateResponse();
response.ContentType = ModelTypes.ProducerResponse;
response.SetJsonContent(model);
TmqClient tmq = (TmqClient) client;
TmqClient tmq = (TmqClient)client;
tmq.Send(response);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Samples/Sample.Mq/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Sample.Mq.Server;
using System;
using System.Threading;
using System.Threading.Tasks;
using Sample.Mq.Server;
using Twino.MQ;
using Twino.MQ.Options;
using Twino.Server;
Expand Down
14 changes: 7 additions & 7 deletions src/Samples/Sample.Mvc/Controller/AuthController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
using Sample.Mvc.Models;
using Sample.Mvc.Models;
using System.Threading.Tasks;
using Twino.Mvc;
using Twino.Mvc.Auth;
using Twino.Mvc.Auth.Jwt;
Expand Down Expand Up @@ -43,11 +43,11 @@ public IActionResult IT()
public async Task<IActionResult> Post([FromBody] LoginModel model)
{
return await JsonAsync(new
{
Ok = true,
Code = 200,
Message = "Success: " + model.Username
});
{
Ok = true,
Code = 200,
Message = "Success: " + model.Username
});
}
}
}
13 changes: 6 additions & 7 deletions src/Samples/Sample.Mvc/Controller/DemoController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -24,10 +23,10 @@ public class DemoController : TwinoController
public IActionResult File()
{
FileStream fs = new FileStream("/home/mehmet/Desktop/twino/kmöğx.pdf", FileMode.Open, FileAccess.Read);
FileResult file = new FileResult(fs,"kmöğx.pdf");
FileResult file = new FileResult(fs, "kmöğx.pdf");
return file;
}

[HttpGet("geta/{?id}")]
public async Task<IActionResult> GetA([FromRoute] int? id)
{
Expand Down Expand Up @@ -76,9 +75,9 @@ public IActionResult Get3([FromRoute] int? id)
public async Task<IActionResult> Get2()
{
return await JsonAsync(new
{
Message = "Hello World 2: "
});
{
Message = "Hello World 2: "
});
}

[HttpGet("optional/{?num}")]
Expand Down
Loading

0 comments on commit 3f89e97

Please sign in to comment.