-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from mhelvacikoylu/v2
2.7.12
- Loading branch information
Showing
200 changed files
with
1,487 additions
and
1,033 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.