Skip to content

Commit

Permalink
迭代发布器
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuDanK committed Jan 14, 2022
1 parent de0b86b commit a40656b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,5 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/pack
61 changes: 50 additions & 11 deletions SageTools.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,61 @@
using System;
using System.IO;
using SageTools.Extension;
using System.Linq;
using System.Xml;

namespace SageTools.Console
{
internal class Program
{
static void Main(string[] args)
{

System.Console.WriteLine(DateTime.Now.AddDays(-1).EndOfDay());

var time1 = new DateTime(DateTime.Now.Year, 1, 1);
System.Console.WriteLine(time1.EndOfDay());
System.Console.WriteLine(DateTime.Now.IsAfternoon());
System.Console.WriteLine(DateTime.Now.IsMorning());
System.Console.WriteLine(DateTime.Now.IsNow());
System.Console.ReadKey();
var help = args.Any(x => x.Contains("-h"));
if (help)
{
System.Console.WriteLine($"-source= 文件相对路径 {Environment.NewLine}-step= 版本号步长值(整数){Environment.NewLine}-version= 直接指定版本,忽略-step");
Environment.Exit(0);
}
System.Console.WriteLine("处理xml文件");
var source = args.Where(x => x.Contains("-source=")).Select(x => x.Replace("-source=", "")).FirstOrDefault();
var step = args.Where(x => x.Contains("-step=")).Select(x => x.Replace("-step=", "")).FirstOrDefault();
var version = args.Where(x => x.Contains("-version=")).Select(x => x.Replace("-version=", "")).FirstOrDefault();
if (source.IsNullOrEmpty())
{
System.Console.WriteLine("执行错误:必须指定 -source");
Environment.Exit(-1);
}
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, source);
if (!File.Exists(path))
{
System.Console.WriteLine($"执行错误:【{path}】文件不存在");
Environment.Exit(-1);
}
var xmlDoc = new XmlDocument(); //新建XML文件
xmlDoc.Load(path); //加载XML文件
var versionNode = xmlDoc.DocumentElement?.SelectSingleNode("PropertyGroup")?.SelectSingleNode("Version");
if (versionNode == null)
{
System.Console.WriteLine("执行错误:项目没有配置版本号");
Environment.Exit(-1);
}
if (version.IsNullOrEmpty())
{
version = versionNode.InnerText;
var lastNum = version.Substring(version.LastIndexOf(".", StringComparison.Ordinal) + 1);
var newNum = lastNum.ToInt32() + step;
var newVersion = version.Substring(0, version.LastIndexOf(".", StringComparison.Ordinal) + 1) + newNum;
versionNode.InnerText = newVersion;
System.Console.WriteLine($"当前版本{version},末尾版本号{lastNum},新版本号{newVersion}");
}
else
{
System.Console.WriteLine($"直接指定新版本号为 {version}");
versionNode.InnerText = version;
}
xmlDoc.Save(path);
System.Console.WriteLine("处理完毕!");
System.Console.ReadKey();
}
}

}
}
28 changes: 26 additions & 2 deletions SageTools/Extension/Collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,43 @@ public static IList<T> ToPagedList<T>(this ICollection<T> allItems, int pageInde
/// <param name="pageSize">每页大小</param>
public static void PagingToOperate<T>(this ICollection<T> list, Action<ICollection<T>> action, int pageSize = 1000)
{
if (list.IsNullOrEmpty())
if (list.IsNullOrEmpty() || list.Count <= pageSize)
{
action(list);
}
else
{
var pageCount = Math.Ceiling(list.Count * 1d / pageSize);
var pageCount = list.Count.ToPageCount(pageSize);
for (var pageIndex = 0; pageIndex < pageCount; pageIndex++)
{
var items = list.Skip(pageIndex * pageSize).Take(pageSize).ToList();
action(items);
}
}
}

/// <summary>
/// 分页执行操作,返回当前页码
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list">源数据集合</param>
/// <param name="action">要进行的操作</param>
/// <param name="pageSize">每页大小</param>
public static void PagingToOperate<T>(this ICollection<T> list, Action<ICollection<T>,int> action, int pageSize = 1000)
{
if (list.IsNullOrEmpty() || list.Count <= pageSize)
{
action(list,1);
}
else
{
var pageCount = list.Count.ToPageCount(pageSize);
for (var pageIndex = 0; pageIndex < pageCount; pageIndex++)
{
var items = list.Skip(pageIndex * pageSize).Take(pageSize).ToList();
action(items, pageIndex + 1);
}
}
}
}
}
2 changes: 1 addition & 1 deletion SageTools/Extension/DateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private static string ToRelativeTimeSimple(TimeSpan ts, string sign)
/// </summary>
/// <param name="this"></param>
/// <returns></returns>
public static long GetTimeStamp(this DateTime @this)
public static long ToTimeStamp(this DateTime @this)
{
return (long)(@this - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
}
Expand Down
1 change: 1 addition & 0 deletions SageTools/Extension/Number.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public static bool ToBool(this int num)
public static int ToPageCount(this int totalCount,int pageSize)
{
if(totalCount==0 || pageSize==0)return 0;
if (totalCount <= pageSize) return 1;
if (pageSize == 1) return totalCount;
return (int)Math.Ceiling(1D * totalCount / pageSize);
}
Expand Down
2 changes: 1 addition & 1 deletion SageTools/SageTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Company>LiuDanK</Company>
<Description>常用工具类、拓展方法等封装,目前还在实现中</Description>
<Copyright>Copyright © LiuDanK 2021</Copyright>
<VersionPrefix>1.0.0</VersionPrefix>
<Version>1.0.0</Version>
</PropertyGroup>

</Project>

0 comments on commit a40656b

Please sign in to comment.