1
1
懒得勤快 5 жил өмнө
parent
commit
98b8fc5eb2

+ 4 - 4
Masuit.Tools.Core/Files/SevenZipCompressor.cs

@@ -165,9 +165,9 @@ namespace Masuit.Tools.Files
                     return null;
                 }
             }).Where(u => u != null).ToList();
-            foreach (var (key, value) in dic)
+            foreach (var pair in dic)
             {
-                archive.AddEntry(Path.Combine(rootdir, value), key);
+                archive.AddEntry(Path.Combine(rootdir, pair.Value), pair.Key);
             }
 
             if (remoteUrls.Any())
@@ -188,9 +188,9 @@ namespace Masuit.Tools.Files
                         }
                     }).Wait();
                 });
-                foreach (var (key, value) in streams)
+                foreach (var pair in streams)
                 {
-                    archive.AddEntry(key, value);
+                    archive.AddEntry(pair.Key, pair.Value);
                 }
             }
 

+ 11 - 1
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -3,7 +3,7 @@
     <Import Project="..\SDKPulishNuget.targets" />
 
     <PropertyGroup>
-        <TargetFrameworks>netstandard2.1;net5</TargetFrameworks>
+        <TargetFrameworks>netstandard2.0;netstandard2.1;net5</TargetFrameworks>
         <Description>
             包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,html处理,验证码、NoSql等常用封装。
             官网教程:https://masuit.com/55
@@ -360,6 +360,16 @@
         <PackageReference Include="SharpCompress" Version="0.26.0" />
     </ItemGroup>
 
+    <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
+        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.6" />
+        <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
+        <PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
+        <PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
+        <PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
+        <PackageReference Include="System.Diagnostics.PerformanceCounter" Version="4.7.0" />
+        <PackageReference Include="System.Drawing.Common" Version="4.7.0" />
+        <PackageReference Include="System.Management" Version="4.7.0" />
+    </ItemGroup>
     <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1'">
         <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
         <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />

+ 3 - 64
Masuit.Tools.Core/Models/ITree.cs

@@ -1,6 +1,4 @@
 using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations.Schema;
-using System.Linq;
 
 namespace Masuit.Tools.Core.Models
 {
@@ -13,75 +11,16 @@ namespace Masuit.Tools.Core.Models
         /// <summary>
         /// 名字
         /// </summary>
-        public string Name { get; set; }
+        string Name { get; set; }
 
         /// <summary>
         /// 父节点
         /// </summary>
-        public T Parent { get; set; }
+        T Parent { get; set; }
 
         /// <summary>
         /// 子级
         /// </summary>
-        public ICollection<T> Children { get; set; }
-
-        /// <summary>
-        /// 所有子级
-        /// </summary>
-        [NotMapped]
-        public ICollection<T> AllChildren => GetChildren(this);
-
-        /// <summary>
-        /// 所有父级
-        /// </summary>
-        [NotMapped]
-        public ICollection<T> AllParent => GetParents(this);
-
-        /// <summary>
-        /// 是否是根节点
-        /// </summary>
-        [NotMapped]
-        public bool IsRoot => Parent == null;
-
-        /// <summary>
-        /// 是否是叶子节点
-        /// </summary>
-        [NotMapped]
-        public bool IsLeaf => Children.Count == 0;
-
-        /// <summary>
-        /// 深度
-        /// </summary>
-        [NotMapped]
-        public int Level => IsRoot ? 0 : Parent.Level + 1;
-
-        /// <summary>
-        /// 节点路径(UNIX路径格式,以“/”分隔)
-        /// </summary>
-        [NotMapped]
-        public string Path => GetFullPath(this);
-
-        private string GetFullPath(ITree<T> c) => c.Parent != null ? GetFullPath(c.Parent) + "/" + c.Name : c.Name;
-
-        /// <summary>
-        /// 递归取出所有下级
-        /// </summary>
-        /// <param name="t"></param>
-        /// <returns></returns>
-        private List<T> GetChildren(ITree<T> t)
-        {
-            return t.Children.Union(t.Children.Where(c => c.Children.Any()).SelectMany(tree => GetChildren(tree))).ToList();
-        }
-
-        /// <summary>
-        /// 递归取出所有上级
-        /// </summary>
-        /// <param name="t"></param>
-        /// <returns></returns>
-        private List<T> GetParents(ITree<T> t)
-        {
-            var list = new List<T>() { t.Parent };
-            return t.Parent != null ? list.Union(GetParents(t.Parent)).ToList() : list;
-        }
+        ICollection<T> Children { get; set; }
     }
 }

+ 55 - 2
Masuit.Tools.Core/Models/TreeExtensions.cs

@@ -16,7 +16,7 @@ namespace Masuit.Tools.Core.Models
         /// <param name="items"></param>
         /// <param name="func"></param>
         /// <returns></returns>
-        public static IEnumerable<T> Filter<T>(this IEnumerable<T> items, Func<T, bool> func) where T : class, ITree<T>
+        public static IEnumerable<T> Filter<T>(this IEnumerable<T> items, Func<T, bool> func) where T : ITree<T>
         {
             var results = new List<T>();
             foreach (var item in items.Where(i => i != null))
@@ -37,7 +37,7 @@ namespace Masuit.Tools.Core.Models
         /// <param name="item"></param>
         /// <param name="func"></param>
         /// <returns></returns>
-        public static IEnumerable<T> Filter<T>(this T item, Func<T, bool> func) where T : class, ITree<T>
+        public static IEnumerable<T> Filter<T>(this T item, Func<T, bool> func) where T : ITree<T>
         {
             return (new[] { item }).Filter(func);
         }
@@ -58,5 +58,58 @@ namespace Masuit.Tools.Core.Models
             }
             return result;
         }
+
+        /// <summary>
+        /// 所有子级
+        /// </summary>
+        public static ICollection<T> AllChildren<T>(this ITree<T> tree) where T : ITree<T> => GetChildren(tree);
+
+        /// <summary>
+        /// 所有父级
+        /// </summary>
+        public static ICollection<T> AllParent<T>(this ITree<T> tree) where T : ITree<T> => GetParents(tree);
+
+        /// <summary>
+        /// 是否是根节点
+        /// </summary>
+        public static bool IsRoot<T>(this ITree<T> tree) where T : ITree<T> => tree.Parent == null;
+
+        /// <summary>
+        /// 是否是叶子节点
+        /// </summary>
+        public static bool IsLeaf<T>(this ITree<T> tree) where T : ITree<T> => tree.Children.Count == 0;
+
+        /// <summary>
+        /// 深度
+        /// </summary>
+        public static int Level<T>(this ITree<T> tree) where T : ITree<T> => IsRoot(tree) ? 0 : Level(tree.Parent) + 1;
+
+        /// <summary>
+        /// 节点路径(UNIX路径格式,以“/”分隔)
+        /// </summary>
+        public static string Path<T>(this ITree<T> tree) where T : ITree<T> => GetFullPath(tree);
+
+        private static string GetFullPath<T>(ITree<T> c) where T : ITree<T> => c.Parent != null ? GetFullPath(c.Parent) + "/" + c.Name : c.Name;
+
+        /// <summary>
+        /// 递归取出所有下级
+        /// </summary>
+        /// <param name="t"></param>
+        /// <returns></returns>
+        private static List<T> GetChildren<T>(ITree<T> t) where T : ITree<T>
+        {
+            return t.Children.Union(t.Children.Where(c => c.Children.Any()).SelectMany(tree => GetChildren(tree))).ToList();
+        }
+
+        /// <summary>
+        /// 递归取出所有上级
+        /// </summary>
+        /// <param name="t"></param>
+        /// <returns></returns>
+        private static List<T> GetParents<T>(ITree<T> t) where T : ITree<T>
+        {
+            var list = new List<T>() { t.Parent };
+            return t.Parent != null ? list.Union(GetParents(t.Parent)).ToList() : list;
+        }
     }
 }

+ 26 - 3
NetCoreTest/Program.cs

@@ -1,8 +1,10 @@
-using Masuit.Tools.Reflection;
+using Masuit.Tools.Core.Models;
+using Masuit.Tools.Reflection;
 using Masuit.Tools.Security;
 using Microsoft.AspNetCore;
 using Microsoft.AspNetCore.Hosting;
 using System;
+using System.Collections.Generic;
 using System.ComponentModel;
 
 namespace NetCoreTest
@@ -13,8 +15,15 @@ namespace NetCoreTest
         {
             var myClass = new MyClass()
             {
-                MyProperty1 = 1
+                MyProperty1 = 1,
+                Name = "1",
+                Parent = new MyClass()
+                {
+                    Name = "mc"
+                }
             };
+            var path = myClass.Path();
+            Console.WriteLine(path);
 
             myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
             Console.ReadKey();
@@ -36,11 +45,25 @@ namespace NetCoreTest
 
     }
 
-    public class MyClass
+    public class MyClass : ITree<MyClass>
     {
         [Description("test")]
         public string MyProperty { get; set; }
         public int? MyProperty1 { get; set; }
 
+        /// <summary>
+        /// 名字
+        /// </summary>
+        public string Name { get; set; }
+
+        /// <summary>
+        /// 父节点
+        /// </summary>
+        public virtual MyClass Parent { get; set; }
+
+        /// <summary>
+        /// 子级
+        /// </summary>
+        public ICollection<MyClass> Children { get; set; }
     }
 }