Program.cs 4.1 KB

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