Program.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using DocumentFormat.OpenXml.Drawing;
  2. using HTEXLib;
  3. using HTEXLib.Builders;
  4. using HTEXLib.Controller;
  5. using HTEXLib.Helpers.ShapeHelpers;
  6. using HTEXLib.Models;
  7. using HTEXLib.Models.Inner;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Net;
  14. using System.Net.NetworkInformation;
  15. using System.Net.Sockets;
  16. using System.Security.Cryptography;
  17. using System.Text;
  18. using System.Text.Json;
  19. using System.Text.RegularExpressions;
  20. using System.Web;
  21. using System.Xml;
  22. using System.Xml.Linq;
  23. namespace HTEXTest
  24. {
  25. public class Node {
  26. public string val { get; set; }
  27. public List<Node> children { get; set; }
  28. public Node(string text, List<Node> node ) {
  29. this.val = text;
  30. this.children = node;
  31. }
  32. }
  33. class Program
  34. {
  35. /// <summary>
  36. /// 获取本地机器网卡的所有IP地址
  37. /// </summary>
  38. /// <returns></returns>
  39. public static List<string> getIPAddress()
  40. {
  41. return NetworkInterface.GetAllNetworkInterfaces()
  42. .SelectMany(i => i.GetIPProperties().UnicastAddresses)
  43. .Select(a => a.Address)
  44. //AddressFamily.InterNetwork 过滤掉IPV6 //过滤127.0.0.1 !IPAddress.IsLoopback(a)
  45. .Where(a => a.AddressFamily == AddressFamily.InterNetwork)
  46. .Select(a => a.ToString()).ToList();
  47. }
  48. public static List<IPAddress> getIPAddressE()
  49. {
  50. return NetworkInterface.GetAllNetworkInterfaces()
  51. .SelectMany(i => i.GetIPProperties().UnicastAddresses)
  52. .Select(a => a.Address)
  53. //AddressFamily.InterNetwork 过滤掉IPV6 //过滤127.0.0.1 !IPAddress.IsLoopback(a)
  54. //.Where(a => a.AddressFamily == AddressFamily.InterNetwork)
  55. .ToList();
  56. }
  57. public static IList<string> PreorderTraversal(Node root)
  58. {
  59. //返回的list
  60. var forReturn = new List<string>();
  61. if (root == null) return forReturn;
  62. //定义一个栈
  63. var stackTemp = new Stack<Node>();
  64. //在栈的顶部插入根节点
  65. stackTemp.Push(root);
  66. while (stackTemp.Any())
  67. {
  68. //移除栈顶部的对象
  69. var curNode = stackTemp.Pop();
  70. //将该对象add至返回的list中
  71. forReturn.Add(curNode.val);
  72. if (curNode.children != null)
  73. {
  74. for (var i = curNode.children.Count - 1; i >= 0; i--)
  75. stackTemp.Push(curNode.children[i]);
  76. }
  77. }
  78. return forReturn;
  79. }
  80. public static void changeArgb(long color) {
  81. //int color = 0x1A0078ff;
  82. long alpha = (color & 0xff000000) >> 24;
  83. long red = (color & 0x00ff0000) >> 16;
  84. long green = (color & 0x0000ff00) >> 8;
  85. long blue = (color & 0x000000ff);
  86. }
  87. public static string sKey= "qJzGEh6hESZDVJeCnFPGuxzaiFYTLQM3";
  88. public static string DESDeCode(string pToDecrypt)
  89. {
  90. // HttpContext.Current.Response.Write(pToDecrypt + "<br>" + sKey);
  91. // HttpContext.Current.Response.End();
  92. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  93. byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
  94. for (int x = 0; x < pToDecrypt.Length / 2; x++)
  95. {
  96. int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
  97. inputByteArray[x] = (byte)i;
  98. }
  99. des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
  100. des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
  101. MemoryStream ms = new MemoryStream();
  102. CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
  103. cs.Write(inputByteArray, 0, inputByteArray.Length);
  104. cs.FlushFinalBlock();
  105. StringBuilder ret = new StringBuilder();
  106. return HttpUtility.UrlDecode(System.Text.Encoding.UTF8.GetString(ms.ToArray()));
  107. }
  108. public static string DESEnCode(string pToEncrypt)
  109. {
  110. pToEncrypt = HttpUtility.UrlEncode(pToEncrypt);
  111. DESCryptoServiceProvider des = new DESCryptoServiceProvider();
  112. byte[] inputByteArray = Encoding.GetEncoding("UTF-8").GetBytes(pToEncrypt);
  113. //建立加密对象的密钥和偏移量
  114. //原文使用ASCIIEncoding.ASCII方法的GetBytes方法
  115. //使得输入密码必须输入英文文本
  116. des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
  117. des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
  118. MemoryStream ms = new MemoryStream();
  119. CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
  120. cs.Write(inputByteArray, 0, inputByteArray.Length);
  121. cs.FlushFinalBlock();
  122. StringBuilder ret = new StringBuilder();
  123. foreach (byte b in ms.ToArray())
  124. {
  125. ret.AppendFormat("{0:X2}", b);
  126. }
  127. ret.ToString();
  128. return ret.ToString();
  129. }
  130. static void Main(string[] args)
  131. {
  132. var str = "123456789";
  133. var aa = DESEnCode(str);
  134. Console.WriteLine(aa);
  135. Console.WriteLine(DESDeCode(aa));
  136. List<double> ds = new List<double>();
  137. ds.Add(0);
  138. ds.Add(51.222);
  139. ds.Add(60);
  140. ds.Add(70);
  141. ds.Add(80);
  142. Console.WriteLine(2.ToString().PadRight(4, '0') + 1.ToString().PadLeft(3, '0'));
  143. Console.WriteLine(25.ToString().PadRight(4, '0') + 10.ToString().PadLeft(3, '0'));
  144. Console.WriteLine(225.ToString().PadRight(4, '0') + 110.ToString().PadLeft(3, '0'));
  145. Console.WriteLine(125.ToString().PadRight(4, '0') + 0.ToString().PadLeft(3, '0'));
  146. XmlDocument doc = new XmlDocument();
  147. //doc.Load("F:\\PPT解析Demo\\presetShapeDefinitions.xml");
  148. //// XmlReader OMML2MML = XmlReader.Create());
  149. //// XmlReader OMML2MML = XmlReader.Create(new StreamReader("F:\\PPT解析Demo\\presetShapeDefinitions.xml"));
  150. //XmlReader OMML2MML = XmlReader.Create(new StringReader(Globals.presetShapeDefinitons));
  151. //Console.WriteLine(BulletAutonumberHelper.LongToText(10));
  152. //Console.WriteLine(BulletAutonumberHelper.LongToText(11));
  153. //Console.WriteLine(BulletAutonumberHelper.LongToText(20));
  154. //Console.WriteLine(BulletAutonumberHelper.LongToText(21));
  155. //Console.WriteLine(BulletAutonumberHelper.LongToText(99));
  156. //Console.WriteLine(BulletAutonumberHelper.LongToText(100));
  157. //Console.WriteLine(BulletAutonumberHelper.LongToText(101));
  158. //Console.WriteLine(BulletAutonumberHelper.LongToText(999));
  159. //Console.WriteLine(BulletAutonumberHelper.LongToText(1000));
  160. //Console.WriteLine(BulletAutonumberHelper.LongToText(1001));
  161. //Console.WriteLine(BulletAutonumberHelper.LongToText(1101));
  162. //Console.WriteLine(BulletAutonumberHelper.LongToText(10101));
  163. //Console.WriteLine(BulletAutonumberHelper.LongToText(10000));
  164. Console.WriteLine(BulletAutonumberHelper.IntToCircle(15, true));
  165. Console.WriteLine( BulletAutonumberHelper.IntToRoman(12, true));
  166. Console.WriteLine(BulletAutonumberHelper.IntToRoman(27, true));
  167. Console.WriteLine(BulletAutonumberHelper.IntToChar(25,false));
  168. Console.WriteLine(BulletAutonumberHelper.IntToChar(26, false));
  169. Console.WriteLine(BulletAutonumberHelper.IntToChar(27, false));
  170. Console.WriteLine(BulletAutonumberHelper.IntToChar(2019, false));
  171. //FF3333
  172. Color color = ColorTranslator.FromHtml("#" + "FF0000CC");
  173. string cls= ColorTranslator.ToHtml(color);
  174. string time = string.Format("{0:yyyyMMdd-HH:mm:ss.fff}", DateTimeOffset.Now);
  175. TimeSpan ts = DateTimeOffset.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  176. var tim= Convert.ToInt64(ts.TotalMilliseconds).ToString();
  177. string appid = "4E28C6F06EDA495491FA7943C143E534";
  178. string appkey = "3B83808EE00E42DFBBEB7502331CF1D8";
  179. string key = appid + appkey + tim;
  180. var sha = ShaHashHelper.GetSHA1(key).ToUpper() ;
  181. List<IPAddress> a = getIPAddressE();
  182. foreach (var ae in a) {
  183. Console.WriteLine(ae);
  184. }
  185. string jsonStr = "{name:计算数据大表名称,num:15,sheet:[{sheetName:不同时期,nums:[23,52,86],special:[准业务,磨合期,老业主,稳定期]},{sheetName:50分制}]}";
  186. string jsonStro = jsonStr.Replace(",", ",");
  187. //string path = "F:\\donghua.pptx";
  188. //var htexBuilder = new HtexBuilder();
  189. //var pptSlides = htexBuilder.GetPPTSlides(path);
  190. //double width = htexBuilder.getSlideWidth();
  191. //double height = htexBuilder.getSlideHeight();
  192. //int slideCounter = 1;
  193. //Htex htex= htexBuilder.Htex;
  194. //htex.page = pptSlides.Count;
  195. //htex.size = new HtexSize { width = width, height = height };
  196. //List<Slide> slides = new List<Slide>();
  197. //foreach (PPTSlide pptSlide in pptSlides)
  198. //{
  199. // var htexController = new HtexController( pptSlide, slideCounter, pptSlides.Count)
  200. // {
  201. // SlideWidth = width,
  202. // SlideHeight = height
  203. // };
  204. // Slide slide= htexController.GenerateHtex();
  205. // slides.Add(slide);
  206. // slideCounter++;
  207. //}
  208. //htexBuilder.presentationDocument.Close();
  209. //GC.Collect();
  210. }
  211. }
  212. }