Compare commits

..

No commits in common. 'a44cfba5ac4b21806d168f3fefbea9e6917c7eb5' and '287b28f36b68d1f747f8a9d81a871716f5887af5' have entirely different histories.

  1. 63
      .gitattributes
  2. 363
      .gitignore
  3. 10
      General/General.csproj
  4. 30
      General/utils/CollectionsUtils.cs
  5. 158
      General/utils/StringUtils.cs
  6. 191
      General/utils/TimerUtils.cs
  7. 25
      Soul2-Library.sln

63
.gitattributes vendored

@ -1,63 +0,0 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

363
.gitignore vendored

@ -1,363 +0,0 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd

@ -1,10 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Soul2.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>
</Project>

@ -1,30 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Soul2.General.utils
{
public class CollectionsUtils
{
public static bool isNotEmpty(IEnumerable collection)
{
return !isEmpty(collection);
}
public static bool isEmpty(IEnumerable collection)
{
if (collection == null)
{
return true;
}
foreach (var item in collection)
{
return false;
}
return true;
}
}
}

@ -1,158 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Soul2.General.utils
{
/// <summary>
/// 字符串工具类
/// By Soul2
/// </summary>
public static class StringUtils
{
/// <summary>
/// 判断空值(null或"")
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool isEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
public static bool isNotEmpty(this string str)
{
return !string.IsNullOrEmpty(str);
}
/// <summary>
/// 判断空值(null、""或只有空格)
/// </summary>
/// <param name="str">被判断的字符串</param>
/// <returns></returns>
public static bool isNotBlank(this string str) { return !string.IsNullOrWhiteSpace(str); }
public static bool IsBlank(this string str) { return string.IsNullOrWhiteSpace(str); }
/// <summary>
/// 任何一个为空
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static bool isAnyBlank(params string[] strs)
{
foreach (var str in strs)
{
if (string.IsNullOrWhiteSpace(str))
{
return true;
}
}
return false;
}
/// <summary>
/// 任何一个为空
/// 空格属于非空
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static bool isAnyEmpty(params string[] strs)
{
foreach (var str in strs)
{
if (string.IsNullOrEmpty(str))
{
return true;
}
}
return false;
}
/// <summary>
/// 任何一个不为空
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static bool isNoneBlank(params string[] strs)
{
foreach (var str in strs)
{
if (string.IsNullOrWhiteSpace(str))
{
return false;
}
}
return true;
}
/// <summary>
/// 任何一个不为空
/// 空格属于非空
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static bool isNoneEmpty(params string[] strs)
{
foreach (var str in strs)
{
if (string.IsNullOrEmpty(str))
{
return false;
}
}
return true;
}
/// <summary>
/// 如果不以val结尾,则添加到结尾
/// </summary>
/// <param name="original"></param>
/// <param name="str"></param>
public static void appendIfMissing(this string original, string str)
{
if (!original.EndsWith(str))
{
original += str;
}
}
/// <summary>
/// 如果不以val开头,则添加到开头
/// </summary>
/// <param name="original"></param>
/// <param name="str"></param>
public static void prependIfMissing(this string original, string str)
{
if (!original.StartsWith(str))
{
original = str + original;
}
}
/// <summary>
/// 翻转
/// 例:"123"->"321"
/// </summary>
/// <param name="original"></param>
/// <returns></returns>
public static string flip(this string original)
{
char[] chars = original.ToCharArray();
Array.Reverse(chars);
return new string(chars);
}
public static string subStrWith(this string original, int begin, int end)
{
if (begin < 0 || end > original.Length || begin > end)
{
throw new ArgumentException("Invalid input parameters");
}
return original.Substring(begin, end - begin);
}
}
}

@ -1,191 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Timer = System.Timers.Timer;
namespace Soul2.General.utils
{
/// <summary>
/// 扩展System.Timers.Timer
/// By Soul2
/// </summary>
public static class TimerUtils
{
private const int default_loop_times = 512;
/// <summary>
/// 一次性计时器
/// 运行结束后自动销毁
/// </summary>
/// <param name="timer"></param>
/// <param name="time"></param>
/// <param name="callback"></param>
/// <returns></returns>
public static Timer startOnce(this Timer timer, double time, Action<Timer> callback)
{
void onElapsed(object source, ElapsedEventArgs e)
{
callback(timer);
timer.destroy();
}
return run(timer, (int)(time * 1000), false, onElapsed);
}
public static Timer startOnce(this Timer timer, double time, Action callback)
{
return timer.startOnce(time, (t) => callback?.Invoke());
}
/// <summary>
/// 循环计时器
/// 可以指定运行次数
/// 运行结束后自动销毁
/// </summary>
/// <param name="timer">计时器</param>
/// <param name="time">时长</param>
/// <param name="times">次数</param>
/// <param name="callback"></param>
/// <returns></returns>
public static Timer startLoop(this Timer timer, double time, int times, Action<Timer, int> callback)
{
int run_times = 0;
void onElapsed(object source, ElapsedEventArgs e)
{
run_times += 1;
if (run_times <= times)
{
callback(timer, run_times);
}
else
{
timer.destroy();
}
}
return run(timer, (int)(time * 1000), true, onElapsed);
}
public static Timer startLoop(this Timer timer, double time, int times, Action<Timer> callback)
{
return timer.startLoop(time, times, (t, i) => callback?.Invoke(t));
}
public static Timer startLoop(this Timer timer, double time, int times, Action<int> callback)
{
return timer.startLoop(time, times, (t, i) => callback?.Invoke(i));
}
public static Timer startLoop(this Timer timer, double time, int times, Action callback)
{
return timer.startLoop(time, times, (t, i) => callback?.Invoke());
}
/// <summary>
/// 循环计时器
/// 默认运行次数512
/// </summary>
/// <param name="timer">计时器</param>
/// <param name="time">时长</param>
/// <param name="times">次数</param>
/// <param name="callback"></param>
/// <returns></returns>
public static Timer startKeep(this Timer timer, double time, Action<Timer, int> callback, int times = default_loop_times)
{
int run_times = 0;
void onElapsed(object source, ElapsedEventArgs e)
{
run_times += 1;
if (run_times <= times)
{
callback(timer, run_times);
}
else
{
timer.destroy();
}
}
return run(timer, (int)(time * 1000), true, onElapsed);
}
public static Timer startKeep(this Timer timer, double time, Action<int> callback, int times = default_loop_times)
{
return timer.startKeep(time, (t, i) => callback?.Invoke(i));
}
public static Timer startKeep(this Timer timer, double time, Action<Timer> callback, int times = default_loop_times)
{
return timer.startKeep(time, (t, i) => callback?.Invoke(t));
}
public static Timer startKeep(this Timer timer, double time, Action callback, int times = default_loop_times)
{
return timer.startKeep(time, (t, i) => callback?.Invoke());
}
public static void destroy(this Timer timer)
{
if (timer.Enabled)
{
timer.Stop();
}
timer.Dispose();
}
// -----------------------------------------
private static Timer run(Timer timer, int interval, bool loop, ElapsedEventHandler elapsed)
{
timer.Elapsed += elapsed;
timer.Interval = interval;
timer.AutoReset = loop;
timer.Start();
return timer;
}
public static Timer startOnce(double time, Action<Timer> callback)
{
return new Timer().startOnce(time, callback);
}
public static Timer startOnce(double time, Action callback)
{
return new Timer().startOnce(time, callback);
}
// -----------------------------------------
public static Timer startLoop(double time, int times, Action<Timer, int> callback)
{
return new Timer().startLoop(time, times, callback);
}
public static Timer startLoop(double time, int times, Action<Timer> callback)
{
return new Timer().startLoop(time, times, callback);
}
public static Timer startLoop(double time, int times, Action<int> callback)
{
return new Timer().startLoop(time, times, callback);
}
public static Timer startLoop(double time, int times, Action callback)
{
return new Timer().startLoop(time, times, callback);
}
// -----------------------------------------
public static Timer startKeep(double time, Action<Timer, int> callback, int times = default_loop_times)
{
return new Timer().startKeep(time, callback, times);
}
public static Timer startKeep(double time, Action<int> callback, int times = default_loop_times)
{
return new Timer().startKeep(time, callback, times);
}
public static Timer startKeep(double time, Action<Timer> callback, int times = default_loop_times)
{
return new Timer().startKeep(time, callback, times);
}
public static Timer startKeep(double time, Action callback, int times = default_loop_times)
{
return new Timer().startKeep(time, callback, times);
}
}
}

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "General", "General\General.csproj", "{8B24AB73-0D6F-426D-92D3-25CBE6ED718E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8B24AB73-0D6F-426D-92D3-25CBE6ED718E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B24AB73-0D6F-426D-92D3-25CBE6ED718E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B24AB73-0D6F-426D-92D3-25CBE6ED718E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B24AB73-0D6F-426D-92D3-25CBE6ED718E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9A5A4059-DD4A-465F-9AF2-E036B3C730C6}
EndGlobalSection
EndGlobal
Loading…
Cancel
Save