No Description

Program.cs 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. 
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. namespace Push
  12. {
  13. class Program
  14. {
  15. public class PushTime
  16. {
  17. public DateTime time;
  18. public int morning;
  19. public int Afternoon;
  20. }
  21. private PushTime time = new PushTime();
  22. static void Main(string[] args)
  23. {
  24. Console.OutputEncoding = System.Text.Encoding.UTF8;
  25. Environment.SetEnvironmentVariable("needDetails", "true");
  26. Console.OutputEncoding = System.Text.Encoding.UTF8;
  27. Environment.SetEnvironmentVariable("needDetails", "true");
  28. System.Console.WriteLine("Hello Push!");
  29. // System.Console.WriteLine(DateTime.Now.ToString("HH"));
  30. //PushTime time = new PushTime();
  31. //time.time = DateTime.Now;
  32. //time.morning = 0;
  33. //time.Afternoon = 0;
  34. //Push(time);
  35. Thread t = new Thread(new ThreadStart(SetCensusURL));
  36. t.Start();
  37. }
  38. public static void Push(PushTime time)
  39. {
  40. FileStream fs = null;
  41. try
  42. {
  43. if (!Directory.Exists("D:\\Push"))
  44. {
  45. Directory.CreateDirectory("D:\\Push");
  46. }
  47. if ( File.Exists("D:\\Push\\PushMessage.txt"))
  48. {
  49. // System.Console.WriteLine(JsonConvert.SerializeObject(time));
  50. File.WriteAllText("D:\\Push\\PushMessage.txt", JsonConvert.SerializeObject(time), Encoding.UTF8);
  51. }
  52. else
  53. {
  54. // System.Console.WriteLine(JsonConvert.SerializeObject(time));
  55. File.WriteAllText("D:\\Push\\PushMessage.txt", JsonConvert.SerializeObject(time), Encoding.UTF8);
  56. }
  57. }
  58. finally
  59. {
  60. if (fs != null)
  61. {
  62. fs.Close();
  63. }
  64. }
  65. }
  66. //http://oa.shuanghui.net:8046/
  67. private static void SetCensusURL()
  68. {
  69. int n = 0;
  70. while (true)
  71. {
  72. Thread.Sleep(60 * 1000);
  73. n += 1;
  74. WebClient web = new WebClient();
  75. web.Encoding = Encoding.UTF8;
  76. try
  77. {
  78. string seturl = "http://oa.shuanghui.net:8046/PushMessage/SetCensusURL";
  79. string Dataaaurl = web.DownloadString(seturl);//这一句话就能请求到数据了
  80. // System.Console.WriteLine("nnvnn" + Dataaaurl);
  81. string url = "http://oa.shuanghui.net:8046/PushMessage/SetPush";
  82. string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
  83. // System.Console.WriteLine("nnvnn" + Dataaa);
  84. //Program program = new Program();
  85. // if (DateTime.Now.ToString("HH") == "09")
  86. // {
  87. // string str1 = File.ReadAllText("D:\\Push\\PushMessage.txt");
  88. // if (!string.IsNullOrEmpty(str1))
  89. // {
  90. // var obj = JsonConvert.DeserializeObject<PushTime>(str1);
  91. // if (obj != null)
  92. // {
  93. // if (DateTime.Now.Day - obj.time .Day >0)
  94. // {
  95. // program.time.time = DateTime.Now;
  96. // program.time.morning = 1;
  97. // program.time.Afternoon = 0;
  98. // // System.Console.WriteLine("aavaa" + program.time.morning);
  99. // Push(program.time);
  100. // string urla = "http://192.168.8.9:1001//PushMessage/PushMessagePush";
  101. // string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了
  102. // }
  103. // else
  104. // {
  105. // if (program.time.morning<=0)
  106. // {
  107. // program.time.time = DateTime.Now;
  108. // program.time.morning = 1;
  109. // program.time.Afternoon = obj.Afternoon ;
  110. // // System.Console.WriteLine("aacaa" + program.time.morning);
  111. // Push(program.time);
  112. // string urla = "http://192.168.8.9:1001//PushMessage/PushMessagePush";
  113. // string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了
  114. // }
  115. // }
  116. // }
  117. // }
  118. // }
  119. // else if (DateTime.Now.ToString("HH") == "14")
  120. // {
  121. // string str1 = File.ReadAllText("D:\\Push\\PushMessage.txt");
  122. // // System.Console.WriteLine("nnvnn" + str1);
  123. // if (!string.IsNullOrEmpty(str1))
  124. // {
  125. // var obj = JsonConvert.DeserializeObject<PushTime>(str1);
  126. // if (obj != null)
  127. // {
  128. // if (DateTime.Now.Day - obj.time.Day > 0)
  129. // {
  130. // program.time.time = DateTime.Now;
  131. // program.time.morning = obj .morning ;
  132. // program.time.Afternoon = 1;
  133. // Push(program.time);
  134. // //System.Console.WriteLine("nnvnn" + program.time.Afternoon);
  135. // string urla = "http://oa.shuanghui.net:8046//PushMessage/PushMessagePush";
  136. // string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了
  137. // }
  138. // else
  139. // {
  140. // if (program.time.Afternoon <= 0)
  141. // {
  142. // program.time.time = DateTime.Now;
  143. // program.time.morning = obj.morning;
  144. // program.time.Afternoon = 1;
  145. // Push(program.time);
  146. // // System.Console.WriteLine("nncnn" + program.time.Afternoon);
  147. // string urla = "http://oa.shuanghui.net:8046//PushMessage/PushMessagePush";
  148. // string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了
  149. // }
  150. // }
  151. // }
  152. // }
  153. // }
  154. }
  155. catch
  156. {
  157. }
  158. }
  159. }
  160. }
  161. }