Что такое Sharpsvr
Sharpsvr — это корпоративный RPC-фреймворк для .NET Core, последняя версия которого разработана на основе .NET Core 2.0 и поддерживает все платформы, соответствующие стандартам .NET Core. Традиционные корпоративные сервисы могут быть преобразованы в распределённые сервисы простым изменением кода после ссылки на библиотеку Sharpsvr. Sharpsvr представляет собой легковесный и высокопроизводительный фреймворк, способный поддерживать до тысячи одновременных клиентских подключений и предоставлять стабильные услуги.
В планах Sharpsvr последовательно поддерживать функции удалённого вызова, обнаружения сервисов, управления версиями сервисов, обновления и понижения версий сервисов, маршрутизации сервисов и автоматического контроля узлов.
Простой пример:
using System.Collections.Generic;
using sharpsvr.attributes;
namespace commontest.src.test
{
[RemoteService]
public interface ICalc
{
[RemoteMethod]
void SayHello(string name="yangyang");
[RemoteMethod]
int TestA(short b);
[RemoteMethod]
int TestA(int c, long d);
[RemoteMethod]
double Add(int a, long b, float c=1.0f, double d = 2.0);
[RemoteMethod]
List<User> GetUserList(User user = null);
[RemoteMethod]
User GetUser(User a=null, User b=null);
}
}
using System.Collections.Generic;
namespace commontest.src.test
{
public class Calc : ICalc
{
public double Add(int a, long b, float c = 1, double d = 2)
{
return a + b + c + d;
}
public User GetUser(User a = null, User b = null)
{
System.Console.WriteLine($"a={a}, b={b}");
throw new System.NotImplementedException();
}
public List<User> GetUserList(User user = null)
{
var result = new List<User>();
result.Add(user);
result.Add(new User{Id=1, Age=2, Sex=true, Message = "hello,hahah", Child=user});
return result;
}
public void SayHello(string name = "yangyang")
{
System.Console.WriteLine("hello:" + name);
}
public int TestA(short b)
{
return b++;
}
public int TestA(int c, long d)
{
return (int)(c * d);
}
}
}
using System;
using System.Threading.Tasks;
using commontest.src.test;
using sharpsvr.net;
namespace svrtest
{
class Program
{
static void Main(string[] args)
{
var svr = new sharpsvr.net.SharpServer();
ICalc cal = new Calc();
Action<IServer> action = async (IServer server)=>{
svr.WithService(cal);
svr.StartUp();
await Task.Run(()=> server.MainLoop());
};
action(svr);
Console.ReadKey();
svr.ShutDown();
}
}
}
using System;
using System.Threading.Tasks;
using commontest.src.test;
namespace clienttest
{
class Program
{
static void RunAsync()
{
Action<Int32> action = async (Int32 number) =>
{
await Task.Run(() =>
{
try
{
Console.WriteLine("thread start number:" + number + ", current thread:" + System.Threading.Thread.CurrentThread.GetHashCode());
ICalc proxy = sharpsvr.proxy.ProxyGenerator.Of<ICalc>(new sharpsvr.proxy.SharpInterceptor());
while (true)
{
try
{
Console.WriteLine("hello:" + proxy.TestA(1, 2L));
var userList = proxy.GetUserList(new User { Id = 123 });
foreach (var user in userList) Console.WriteLine("hello:" + user);
Console.WriteLine("proxy.GetUser:" + proxy.GetUser(new User { Id = 1 }, new User { Age = 2 }));
}
catch (Exception ex)
{
Console.WriteLine("error exception:" + ex);
}
}
}
finally
{
Console.WriteLine("exception not catched!");
}
});
... ```
};
for (int i = 0; i < 100; ++i)
{
action(i);
}
static void RunSync()
{
try
{
ICalc proxy = sharpsvr.proxy.ProxyGenerator.Of<ICalc>(new sharpsvr.proxy.SharpInterceptor());
while (true)
{
try
{
Console.WriteLine("hello:" + proxy.TestA(1, 2L));
var userList = proxy.GetUserList(new User { Id = 123 });
foreach (var user in userList) Console.WriteLine("hello:" + user);
Console.WriteLine("proxy.GetUser:" + proxy.GetUser(new User { Id = 1 }, new User { Age = 2 }));
}
catch (Exception ex)
{
Console.WriteLine("error exception:" + ex);
}
}
}
finally
{
Console.WriteLine("exception not catched!");
}
}
static void Main(string[] args)
{
RunAsync();
Console.ReadKey();
//while(true) System.Threading.Thread.Sleep(100000);
Environment.Exit(0);
}
v 0.1.0
Ниже представлены функции, поддерживаемые sharpsvr 0.1.0:
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )