Program.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Masuit.Tools;
  2. using Masuit.Tools.Database;
  3. using Masuit.Tools.Excel;
  4. using Masuit.Tools.Files;
  5. using Masuit.Tools.Models;
  6. using Masuit.Tools.Reflection;
  7. using Masuit.Tools.Security;
  8. using Microsoft.AspNetCore;
  9. using Microsoft.AspNetCore.Hosting;
  10. using Newtonsoft.Json;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Linq;
  15. namespace NetCoreTest
  16. {
  17. public class Program
  18. {
  19. public static void Main(string[] args)
  20. {
  21. var myClass = new MyClass()
  22. {
  23. MyProperty1 = 1,
  24. Id = "mcc",
  25. Pid = "mc",
  26. Parent = new MyClass()
  27. {
  28. Id = "mc",
  29. Pid = "ccc",
  30. Parent = new MyClass()
  31. {
  32. Id = "ccc"
  33. }
  34. }
  35. };
  36. var allParent = myClass.AllParent().Append(myClass);
  37. var tree = allParent.ToTreeGeneral(c => c.Id, c => c.Pid);
  38. tree.Flatten(t => t.Children).Select(t => t.Value).ToDataTable().ToExcel().SaveFile(@"Y:\1.xlsx");
  39. Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings()
  40. {
  41. ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
  42. Formatting = Formatting.Indented
  43. }));
  44. var path = myClass.Path(c => c.Id);
  45. Console.WriteLine(path);
  46. myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
  47. Console.ReadKey();
  48. var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);
  49. Console.WriteLine(rsaKey.PrivateKey);
  50. Console.WriteLine(rsaKey.PublicKey);
  51. var enc = "123456".RSAEncrypt();
  52. Console.WriteLine(enc);
  53. Console.Beep();
  54. var dec = enc.RSADecrypt();
  55. Console.WriteLine(dec);
  56. Console.ReadKey();
  57. //CreateWebHostBuilder(args).Build().Run();
  58. }
  59. public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
  60. WebHost.CreateDefaultBuilder(args)
  61. .UseStartup<Startup>();
  62. }
  63. public class MyClass : ITree<MyClass>
  64. {
  65. [Description("test")]
  66. public string Pid { get; set; }
  67. public int? MyProperty1 { get; set; }
  68. /// <summary>
  69. /// 名字
  70. /// </summary>
  71. public string Id { get; set; }
  72. /// <summary>
  73. /// 父节点
  74. /// </summary>
  75. [JsonIgnore]
  76. public virtual MyClass Parent { get; set; }
  77. /// <summary>
  78. /// 子级
  79. /// </summary>
  80. [JsonIgnore]
  81. public ICollection<MyClass> Children { get; set; } = new List<MyClass>();
  82. /// <summary>
  83. /// 名字
  84. /// </summary>
  85. public string Name { get; set; }
  86. }
  87. }