Pico.Core 1.1.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pico.Core --version 1.1.7
NuGet\Install-Package Pico.Core -Version 1.1.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pico.Core" Version="1.1.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pico.Core --version 1.1.7
#r "nuget: Pico.Core, 1.1.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pico.Core as a Cake Addin
#addin nuget:?package=Pico.Core&version=1.1.7

// Install Pico.Core as a Cake Tool
#tool nuget:?package=Pico.Core&version=1.1.7

公共组件 Pico.Core

版本描述

v1.0.9

实现了字符串的扩展方法
断言较验参数
EF动态Where条件
EF统一分页查询方法
Camunda 外部任务标准监听,回调,获取指定实例的当前任务
统一的Id生成器
封装了解释Accesstoken实现获取用户身份信息
封装了部分的Grap Api的调用
封装了http+Json的请求方法
封装API的标准输出 Result
封装了二唯码生成器
统一了基本查询参数SearchParam,可供扩展
统一了AzureFunction入口方法调用

组件使用说明

Azure Function

//在 Startup.cs中增加启动配置
 PicoApplication.Setup();
//方法标准写法
[FunctionName("token")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
{
    return await req.ExecutingAsync(async () =>
     {
       return await GraphUtil.GetAccessTokenAsync();
     }, log);
}
//或者,兼容未走网关的服务
[FunctionName("token")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
    ILogger log,ClaimsPrincipal claims)
{
    return await req.ExecutingAsync(async () =>
     {
         //业务逻辑
       return await GraphUtil.GetAccessTokenAsync();
     }, log,claims);
 }

.Net Core Api

获取身份信息

IdentityUtil.Email //获取当前用户
IdentityUtil.IsLogin() //判断用户是否登录
IdentityUtil.AccessToken //获取访问的Token

Camunda 流程引擎

//1.在启动类开启Bpm
PicoApplication.Setup(new PicoConfiguration(){
  EnableBpm = true,
});
//2.在配置文件中增加如下配置
"BPM_CONFIG_JSON": {"ApiUrl": "","SecretKey":""}
// 3.实现Camunda监听器
 internal class CamundaService : CamundaListener
    {
        public static ISet<string> Topics = new HashSet<string> {
            C.TERMINATE_REMOVE
        };
        public override Dictionary<string, CamundaVariable> ExecuteTask(ExternalTask task)
        {
            var variables = task.Variables;
            switch (task.TopicName)
            {
                case C.TERMINATE_REMOVE:
                    //定义业务逻辑
                    //回写流程变量
                    variables[xxx] = new CamundaVariable { Value = xxx };
                    break;
                default:
                    break;
            }
            return variables;
        }
    }
//4.在启动类中启动监听
new CamundaService().Start(CamundaService.Topics);

//启动流程
var res =CamundaUtil.StartByKey<T>(new StartProcess<T>(),key)
//任务回调
CamundaUtil.Callback(new CallbackProcess())
//获取指定用户当前实例的待办任务ID
var taskId CamundaUtil.GetTaskId(processId,email)

Redis 缓存工具

//1.在启动类开启Redis
PicoApplication.Setup(new PicoConfiguration(){
  EnableReadis = true,
});
//2.在配置文件中增加如下配置
//3.从缓存中取值
CacheUtil.GetAsync(key).Result
CacheUtil.GetAsync<T>(key).Result
//设置值
CacheUtil.SetAsync(key,val,cacheTime)
//删除
CacheUtil.RemoveAsync(key)
//键值判断
CacheUtil.ExistAsync(key)

Id生成器

IdUtil.LongId() //雪花算法生成唯一long型Id
IdUtil.StringId()//雪花算法生成唯一string型Id

QrCode生成器

QrCodeUtil.GetQRCode("https://helpdesk.poico.com") //为指定的Url生成二维码图像

RestUtil 请求工具

var body = new RestParm{
    Url="https://xx.com/service",
    Body=new object()
};
var res = await body.PostAsync(); //异步方法获取返回结果
var res = body.PostAsync().Result; //同步方法获取返回结果
GetAsync()//Http GET 请求
PutAsync()//Http PUT 请求
DeleteAsync()//Http DELETE 请求
PatchAsync()//Http PATCH 请求

GraphUtil 请求工具

//1.在启动类开启Graph
PicoApplication.Setup(new PicoConfiguration(){
  EnableGraph = true,
});
//2.在配置文件中增加如下配置
"GRAPH_CONFIG_JSON": {"TenantId": "","ClientId": "","SecretKey":""}
// 3.获取accessToken
var token = GraphUtil.GetAccessTokenAsync().Result;
//4.获取o365UserId
var userId =GraphUtil.GetUserId(email);

Result 标准输出

{
    "code": 200,
    "success": true,
    "msg": "操作成功",
    "time": 1511,
    "data":null,
    "status": "Success"
}

Page<T> 标准分页返回

var pageInfo = new Page<Project>(1,10);
var Q =from p in db.Projects select p;
var res = Q.ToPageList(pageInfo, new KeyValuePair<Expression<Func<Project, object>>, E.Sort>(e => e.ProjectId, E.Sort.ASC));
//前端页指定排序
var res = Q.ToPageList(pageInfo, new KeyValuePair<string, E.Sort> ("ProjectId",E.Sort.ASC), new KeyValuePair<string, E.Sort>("ProjectStatus", E.Sort.DESC));
                   

动态查询条件

var args = new SearchParam{Keyword="xx",StartTime="xx",EndTime="xx"};
var Q =from p in db.Projects select p;
Q = Q.Where(args.Keyword.IsNotEmpty(), e => e.ProjectName.Contains(args.Keyword) || e.SicName.Contains(args.Keyword))
      .Where(args.StartTime > TimeUtil.MinValue, e => e.ShowCloseDate >= args.StartTime.Date)
      .Where(args.EndTime > TimeUtil.MinValue, e => e.ShowCloseDate <= args.EndTime.Date);
return Q.ToList();

动态排序

//后端指定排序字段
 var orderByItems = new HashSet<KeyValuePair<Expression<Func<Projects, object>>, E.Sort>>
                {
                    new  KeyValuePair<Expression<Func<Projects, object>>, E.Sort> (e=>e.ProjectId,E.Sort.ASC),
                     new  KeyValuePair<Expression<Func<Projects, object>>, E.Sort>(e=>e.ProjectStatus, E.Sort.DESC)
                };
 var result = Q.OrderBy(orderByItems.ToArray()).ToList();
 //前端指定排序字段
  var orderByItems = new HashSet<KeyValuePair<string, E.Sort>>
                {
                    new KeyValuePair<string, E.Sort> ("ProjectId",E.Sort.ASC),
                     new KeyValuePair<string, E.Sort>("ProjectStatus", E.Sort.DESC)
                };
 var result = Q.OrderBy(orderByItems.ToArray()).ToList();

值判断

var str="xxx";
//非空判断
str.IsNotEmpty()
//空判断
str.IsEmpty()
//忽略大小写相等判断
"xx".EqualsIgnoreCase(str)

var obj= new ojbect();
//非空判断
obj.IsNotEmpty()
//空判断
obj.IsEmpty()

参数较验

//用断言代替if else
Tools.AssertEmpty(email,"Email Is Required") 
Tools.AssertFalse(agr>18,"年龄必须大于18") 
Tools.AssertTrue(o365UserId.IsNotEmpty(),"帐号已被注册") 
Tools.AssertNull(user,"User Not Fund")

Json序列化与反序列化

//返序列化
var json ="";
var obj = json.ToObject<T>();

//序列化
var obj = new object();
var json = obj.ToJson();

字符串与基本类型转换

var str="";
str.ToInt() //string to int
str.ToLong() //string to long
str.ToBool() //string to bool
str.ToDouble() //string to double
str.ToDateTime() //string to datetime
//datetime to string
var dt =TimeUtil.Now;
dt.ToFormatString(dt,"yyyy-MM-dd")

统一获取服务器时间

TimeUtil.Now
TimeUtil.UtcNow
TimeUtil.MinValue

邮件工具

var emailRequest = new EmailParam { To = "xx", Body = "test", Subject = "test", };
await emailRequest.TriggerAsync();
//Teams 审批流
var approveRequest= new ApproveParam {To = "xx",Title = "test",Details = "test", Requestor = "xx", CallbackUrl = "xx",Id = "test"};
approveRequest.TriggerAsync();
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.9 18 5/13/2024
1.5.8 68 5/10/2024
1.5.7 69 5/7/2024
1.5.6 244 4/16/2024
1.5.5 75 4/16/2024
1.5.4 86 4/16/2024
1.5.3 648 2/29/2024
1.5.2 309 2/26/2024
1.5.1 128 1/15/2024
1.5.0 181 12/28/2023
1.4.9 97 12/26/2023
1.4.8 244 12/15/2023
1.4.7 92 12/13/2023
1.4.6 102 12/12/2023
1.4.5 99 12/8/2023
1.4.4 95 12/4/2023
1.4.3 269 11/23/2023
1.4.2 117 11/22/2023
1.4.1 167 10/7/2023
1.4.0 108 9/27/2023
1.3.9 127 9/26/2023
1.3.8 125 9/12/2023
1.3.7 108 9/12/2023
1.3.6 129 8/30/2023
1.3.5 113 8/30/2023
1.3.4 179 6/21/2023
1.3.3 182 6/16/2023
1.3.1 257 5/12/2023
1.3.0 174 5/9/2023
1.2.9 172 4/28/2023
1.2.8 446 4/24/2023
1.2.7 187 4/23/2023
1.2.6 196 4/20/2023
1.2.5 170 4/19/2023
1.2.4 181 4/18/2023
1.2.3 161 4/18/2023
1.2.2 174 4/17/2023
1.2.1 168 4/17/2023
1.2.0 168 4/11/2023
1.1.9 180 4/11/2023
1.1.8 166 4/11/2023
1.1.7 189 4/8/2023
1.1.6 276 3/29/2023
1.1.5 203 3/27/2023
1.1.4 209 3/22/2023
1.1.3 215 3/22/2023
1.1.2 209 3/22/2023
1.1.1 224 3/17/2023
1.1.0 217 3/17/2023
1.0.9 240 3/17/2023
1.0.8 223 3/16/2023
1.0.7 226 3/16/2023
1.0.6 225 3/16/2023
1.0.5 209 3/15/2023
1.0.4 234 3/13/2023
1.0.3 257 3/11/2023
1.0.2 254 3/11/2023
1.0.1 259 3/8/2023
1.0.0 231 3/8/2023