整合了社区主流开源框架(CAP、SkyAPM、WebAPIClient、Chloe等)的微服务项目示例
You can run the following command to install the Sikiro.Tookits in your project。
PM> Install-Package Sikiro.Tookits
var sr = new ServiceResult(); if (sr.Error) return;
* Extensionc# var list = new List().DistinctBy(a => a.Name);
DataTable dt = list.ToDataTable();
int numString = "1".TryInt(1);
* Helperc# Guid guid = GuidHelper.GenerateComb(); ``` and so on
This is mongo repository.Base on MongoDB.Driver.It is easy to use.
You can run the following command to install the Sikiro.Nosql.Mongo in your project。
PM> Install-Package Sikiro.Nosql.Mongo
var mongoRepository = new MongoRepository("mongodb://10.1.20.143:27017");
[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; }
}
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 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 according to the condition
c# mongoRepository.Delete(a => a.Id == u.Id);
Get the first data by filtering condition
var getResult = mongoRepository.Get(a => a.Id == u.Id);
You can also query qualified data list.
c# var listResult = mongoRepository.ToList(a => a.Id == u.Id);
var listResult = mongoRepository.PageList(a => a.Id == u.Id, a => a.Desc(b => b.BirthDateTime), 1, 10);
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);
基于NPOI封装
public void ConfigureServices(IServiceCollection services) { services.AddExcelClient("http://rpc.gshichina.com/api/file"); }
使用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);
}
[HttpGet("import")] public IEnumerable Import() { var baseString = "data:application/vnd.ms-excel;base64,UEsDBBQAAAgIAFdGME8xSZgR7wAAANMCAAALAAAAX3Jl";return _ec.HttpImport<student>(baseString);
}
public void Import() { var file = Request.Form.Files[0]; _ec.HttpImport(file); }
基于DotNetCore.CAP.MySql与DotNetCore.CAP.RabbitMQ封装
public void ConfigureServices(IServiceCollection services) { services.AddChloeDbContext("Server=im.gshichina.com;Port=5002;Database=business_platform;Uid=ge;Pwd=shi2019");services.AddCap(x => { x.UseMySql("Server=im.gshichina.com;Port=5002;Database=business_platform;Uid=ge;Pwd=shi2019"); x.UseRabbitMQ(option => { 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);
}
[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, () => { _businessPlatformContext.Insert(new Test { Id = DateTime.Now.ToString(CultureInfo.InvariantCulture) }); _capBus.Publish("sample.rabbitmq.mysql2", DateTime.Now); }); return Ok(); }
}
[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}"); }
}