Program.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 OfficeOpenXml;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.ComponentModel;
  15. using System.IO;
  16. using System.Linq;
  17. using Masuit.Tools.Systems;
  18. using LicenseContext = OfficeOpenXml.LicenseContext;
  19. namespace NetCoreTest
  20. {
  21. public class Program
  22. {
  23. public static void Main(string[] args)
  24. {
  25. ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
  26. var pkg = new ExcelPackage();
  27. pkg.Workbook.Worksheets.Add("Sheet1");
  28. var sheet = pkg.Workbook.Worksheets["Sheet1"];
  29. sheet.FillWorksheet(Enumerable.Range(1, 2).Select(i => new
  30. {
  31. 序号 = i,
  32. 图片 = new Dictionary<string, Stream>()
  33. {
  34. ["https://ldqk.org/1383"] = File.OpenRead(@"D:\images\emotion\16.jpg"),
  35. ["https://ldqk.org/1384"] = File.OpenRead(@"D:\images\emotion\16.jpg"),
  36. ["https://ldqk.org/1385"] = File.OpenRead(@"D:\images\emotion\16.jpg"),
  37. }
  38. }).ToDataTable("aa"), null, 4, 3);
  39. sheet.Cells["A1:F1"].Merge = true;
  40. sheet.Cells["A1"].Value = "title";
  41. pkg.SaveAs("Y:\\1.xlsx");
  42. Console.WriteLine("ok");
  43. Console.ReadKey();
  44. Enumerable.Range(1, 2).Select(i => new
  45. {
  46. 序号 = i,
  47. 图片 = new Dictionary<string, FileStream>()
  48. {
  49. ["https://ldqk.org/1383"] = File.OpenRead(@"D:\images\emotion\16.jpg")
  50. }
  51. }).ToDataTable("aa").ToExcel().SaveFile(@"Y:\2.xlsx");
  52. var myClass = new MyClass()
  53. {
  54. MyProperty1 = 1,
  55. Id = "mcc",
  56. Pid = "mc",
  57. Parent = new MyClass()
  58. {
  59. Id = "mc",
  60. Pid = "ccc",
  61. Parent = new MyClass()
  62. {
  63. Id = "ccc"
  64. }
  65. }
  66. };
  67. var allParent = myClass.AllParent().Append(myClass);
  68. var tree = allParent.ToTreeGeneral(c => c.Id, c => c.Pid);
  69. Console.WriteLine(tree.ToJsonString(new JsonSerializerSettings()
  70. {
  71. ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
  72. Formatting = Formatting.Indented
  73. }));
  74. var path = myClass.Path(c => c.Id);
  75. Console.WriteLine(path);
  76. myClass.SetProperty(nameof(MyClass.MyProperty1), 1);
  77. Console.ReadKey();
  78. var rsaKey = RsaCrypt.GenerateRsaKeys(RsaKeyType.PKCS8, 2048);
  79. Console.WriteLine(rsaKey.PrivateKey);
  80. Console.WriteLine(rsaKey.PublicKey);
  81. var enc = "123456".RSAEncrypt();
  82. Console.WriteLine(enc);
  83. Console.Beep();
  84. var dec = enc.RSADecrypt();
  85. Console.WriteLine(dec);
  86. Console.ReadKey();
  87. //CreateWebHostBuilder(args).Build().Run();
  88. }
  89. public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
  90. WebHost.CreateDefaultBuilder(args)
  91. .UseStartup<Startup>();
  92. }
  93. public class ClassCmd
  94. {
  95. public string MyProperty { get; set; }
  96. public int Num { get; set; }
  97. }
  98. public class ClassDto
  99. {
  100. [DeserializeOnlyJsonProperty]
  101. public string MyProperty { get; set; }
  102. public int Num { get; set; }
  103. }
  104. public class MyClass : ITree<MyClass>
  105. {
  106. [Description("test")]
  107. public string Pid { get; set; }
  108. public int? MyProperty1 { get; set; }
  109. /// <summary>
  110. /// 名字
  111. /// </summary>
  112. public string Id { get; set; }
  113. /// <summary>
  114. /// 父节点
  115. /// </summary>
  116. [JsonIgnore]
  117. public virtual MyClass Parent { get; set; }
  118. /// <summary>
  119. /// 子级
  120. /// </summary>
  121. [JsonIgnore]
  122. public ICollection<MyClass> Children { get; set; } = new List<MyClass>();
  123. /// <summary>
  124. /// 名字
  125. /// </summary>
  126. [DeserializeOnlyJsonProperty]
  127. public string Name { get; set; }
  128. }
  129. }