Program.cs 3.4 KB

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