Sikiro

by SkyChenSky

SkyChenSky / Sikiro

整合了社区主流开源项目的微服务框架(CAP、SkyAPM、WebAPIClient、Chloe等)

262 Stars 67 Forks Last release: Not found MIT License 22 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Blog

Getting Started

Nuget

You can run the following command to install the Sikiro.Tookits in your project。

PM> Install-Package Sikiro.Tookits

What does it have?

  • Base ```c# var pl = new PageList(1, 10, 100, new List());

var sr = new ServiceResult(); if (sr.Error) return;

* Extension
c# var list = new List().DistinctBy(a => a.Name);

DataTable dt = list.ToDataTable();

int numString = "1".TryInt(1);

* Helper
c# Guid guid = GuidHelper.GenerateComb(); ``` and so on

Sikiro.Nosql.Mongo

This is mongo repository.Base on MongoDB.Driver.It is easy to use.

Getting Started

Nuget

You can run the following command to install the Sikiro.Nosql.Mongo in your project。

PM> Install-Package Sikiro.Nosql.Mongo

Connection

var mongoRepository = new MongoRepository("mongodb://10.1.20.143:27017");

Defining User Entity

[Mongo("Chengongtest", "User")]
public class User : MongoEntity
{
    public string Name { get; set; }

[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
public DateTime BirthDateTime { get; set; }

public User Son { get; set; }

public int Sex { get; set; }

public List<string> AddressList { get; set; }

}

Add

var addresult = mongoRepository.Add(new User
{
    Name = "skychen",
    BirthDateTime = new DateTime(1991, 2, 2),
    AddressList = new List { "guangdong", "guangzhou" },
    Sex = 1,
    Son = new User
    {
        Name = "xiaochenpi",
        BirthDateTime = DateTime.Now
    }
});

UPDATE

Update according to the condition part field

c#
mongoRepository.Update(a => a.Id == u.Id, a => new User { AddressList = new List { "guangdong", "jiangmen", "cuihuwan" } });

You can also update the entity field information based on the primary key

c#
getResult.Name = "superskychen";
mongoRepository.Update(getResult);

DELETE

Delete according to the condition

c#
mongoRepository.Delete(a => a.Id == u.Id);

QUERY

GET

Get the first data by filtering condition

var getResult = mongoRepository.Get(a => a.Id == u.Id);

TOLIST

You can also query qualified data list.

c#
var listResult = mongoRepository.ToList(a => a.Id == u.Id);

PAGELIST

var listResult = mongoRepository.PageList(a => a.Id == u.Id, a => a.Desc(b => b.BirthDateTime), 1, 10);

Finally a complete Demo

var url = "mongodb://10.1.20.143:27017";
var mongoRepository = new MongoRepository(url);

var u = new User { Name = "skychen", BirthDateTime = new DateTime(1991, 2, 2), AddressList = new List { "guangdong", "guangzhou" }, Sex = 1, Son = new User { Name = "xiaochenpi", BirthDateTime = DateTime.Now } };

var addresult = mongoRepository.Add(u);

var getResult = mongoRepository.Get(a => a.Id == u.Id); getResult.Name = "superskychen";

mongoRepository.Update(getResult);

mongoRepository.Update(a => a.Id == u.Id, a => new User { AddressList = new List { "guangdong", "jiangmen", "cuihuwan" } });

mongoRepository.Exists(a => a.Id == u.Id);

mongoRepository.Delete(a => a.Id == u.Id);

ExcelClient

基于NPOI封装

Getting Started

注册

 public void ConfigureServices(IServiceCollection services)
{
    services.AddExcelClient("http://rpc.gshichina.com/api/file");
}

MVC导出

使用Get请求方式新开页面导出Excel ```c# public class DefaultController : Controller { private readonly ExcelClient _ec;

    public DefaultController(ExcelClient ec)
    {
        _ec = ec;
    }

public void Index()
{
    var list = new List<student>
    {
        new Student
        {
            Id = "1",
            Name = "123123"
        },
        new Student
        {
            Id = "12",
            Name = "asdasdqwe"
        }
    };
    _ec.HttpExport(list, "excel名称");
}

}

WebApi导出

```c# [HttpGet] public async Task> Get() { var list = new List { new Student { Id = "1", Name = "123123" }, new Student { Id = "12", Name = "asdasdqwe" } };

return await _ec.HttpExportAsync(list);

}

Base64导入

[HttpGet("import")]
public IEnumerable Import()
{
    var baseString = "data:application/vnd.ms-excel;base64,UEsDBBQAAAgIAFdGME8xSZgR7wAAANMCAAALAAAAX3Jl";

return _ec.HttpImport<student>(baseString);

}

form导入

public void Import()
{
    var file = Request.Form.Files[0];
    _ec.HttpImport(file);
}

DotNetCore.CAP.MySql-分布式事务(最终一致性)

基于DotNetCore.CAP.MySql与DotNetCore.CAP.RabbitMQ封装

Getting Started

注册

public void ConfigureServices(IServiceCollection services)
{
    services.AddChloeDbContext("Server=im.gshichina.com;Port=5002;Database=business_platform;Uid=ge;Pwd=shi2019");

services.AddCap(x =&gt;
{
    x.UseMySql("Server=im.gshichina.com;Port=5002;Database=business_platform;Uid=ge;Pwd=shi2019");
    x.UseRabbitMQ(option =&gt;
    {
        option.HostName = "rabbitmq.gshichina.com";
        option.Port = 5112;
        option.UserName = "guest";
        option.Password = "guest";
    });
    x.UseDashboard();
    x.FailedRetryCount = 5;
    x.FailedRetryInterval = 30;
});

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

}

事务A端

[Route("api/[controller]")]
public class ValuesController : Controller
{
    private readonly ICapPublisher _capBus;
    private readonly BusinessPlatformContext _businessPlatformContext;

public ValuesController(ICapPublisher capPublisher, BusinessPlatformContext businessPlatformContext)
{
    _capBus = capPublisher;
    _businessPlatformContext = businessPlatformContext;
}

[Route("~/adonet/transaction")]
public IActionResult AdonetWithTransaction()
{
    _businessPlatformContext.UseTransactionEx(_capBus, () =&gt;
    {
        _businessPlatformContext.Insert(new Test
        {
            Id = DateTime.Now.ToString(CultureInfo.InvariantCulture)
        });

        _capBus.Publish("sample.rabbitmq.mysql2", DateTime.Now);
    });

    return Ok();
}

}

事务B端

[Route("api/[controller]")]
public class ValuesController : Controller
{
    private readonly ICapPublisher _capBus;
    private readonly BusinessPlatformContext _businessPlatformContext;

public ValuesController(ICapPublisher capPublisher, BusinessPlatformContext businessPlatformContext)
{
    _capBus = capPublisher;
    _businessPlatformContext = businessPlatformContext;
}

[NonAction]
[CapSubscribe("#.rabbitmq.mysql2")]
public void Subscriber(DateTime time)
{
    Console.WriteLine([email protected]"{DateTime.Now} Subscriber invoked, Sent time:{time}");
}

}

注意点

  1. UseTransactionEx里必须使用_capBus.Publish
  2. 默认重发间隔60秒,重试第3次与第四次间隔4分钟,默认次数上限50次
  3. 配置文档 :http://cap.dotnetcore.xyz/user-guide/zh/cap/configuration/

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.