- .Net微服务实战之技术选型篇
- .Net微服务实战之技术架构分层篇
- .Net微服务实战之DevOps篇
- .Net微服务实战之负载均衡(上)
- .Net微服务实战之CI/CD
- .Net微服务实战之Kubernetes的搭建与使用
- .Net在Windows上使用Jenkins做CI/CD的那些事
Sikiro.Tookits is base And Frequently-used Tools Library.
You can run the following command to install the Sikiro.Tookits in your project。
PM> Install-Package Sikiro.Tookits
- Base
var pl = new PageList<User>(1, 10, 100, new List<User>());
var sr = new ServiceResult<User>();
if (sr.Error)
return;
- Extension
var list = new List<User>().DistinctBy(a => a.Name);
DataTable dt = list.ToDataTable();
int numString = "1".TryInt(1);
- Helper
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<string> { "guangdong", "guangzhou" },
Sex = 1,
Son = new User
{
Name = "xiaochenpi",
BirthDateTime = DateTime.Now
}
});
Update according to the condition part field
mongoRepository.Update<User>(a => a.Id == u.Id, a => new User { AddressList = new List<string> { "guangdong", "jiangmen", "cuihuwan" } });
You can also update the entity field information based on the primary key
getResult.Name = "superskychen";
mongoRepository.Update(getResult);
Delete according to the condition
mongoRepository.Delete<User>(a => a.Id == u.Id);
Get the first data by filtering condition
var getResult = mongoRepository.Get<User>(a => a.Id == u.Id);
You can also query qualified data list.
var listResult = mongoRepository.ToList<User>(a => a.Id == u.Id);
var listResult = mongoRepository.PageList<User>(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<string> { "guangdong", "guangzhou" },
Sex = 1,
Son = new User
{
Name = "xiaochenpi",
BirthDateTime = DateTime.Now
}
};
var addresult = mongoRepository.Add(u);
var getResult = mongoRepository.Get<User>(a => a.Id == u.Id);
getResult.Name = "superskychen";
mongoRepository.Update(getResult);
mongoRepository.Update<User>(a => a.Id == u.Id, a => new User { AddressList = new List<string> { "guangdong", "jiangmen", "cuihuwan" } });
mongoRepository.Exists<User>(a => a.Id == u.Id);
mongoRepository.Delete<User>(a => a.Id == u.Id);
基于NPOI封装
public void ConfigureServices(IServiceCollection services)
{
services.AddExcelClient("http://rpc.gshichina.com/api/file");
}
使用Get请求方式新开页面导出Excel
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名称");
}
}
[HttpGet]
public async Task<ActionResult<string>> Get()
{
var list = new List<Student>
{
new Student
{
Id = "1",
Name = "123123"
},
new Student
{
Id = "12",
Name = "asdasdqwe"
}
};
return await _ec.HttpExportAsync(list);
}
[HttpGet("import")]
public IEnumerable<Student> 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<object>(file);
}
基于DotNetCore.CAP.MySql与DotNetCore.CAP.RabbitMQ封装
public void ConfigureServices(IServiceCollection services)
{
services.AddChloeDbContext<BusinessPlatformContext>("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($@"{DateTime.Now} Subscriber invoked, Sent time:{time}");
}
}
- UseTransactionEx里必须使用_capBus.Publish
- 默认重发间隔60秒,重试第3次与第四次间隔4分钟,默认次数上限50次
- 配置文档 :http://cap.dotnetcore.xyz/user-guide/zh/cap/configuration/