Nessuna descrizione

Program.cs 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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
  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/PushMessage/SetCensusURL";
  79. string Dataaaurl = web.DownloadString(seturl);//这一句话就能请求到数据了
  80. string url = "http://oa.shuanghui.net/PushMessage/SetPush";
  81. string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
  82. Program program = new Program();
  83. if (DateTime.Now.ToString("HH") == "09")
  84. {
  85. string str1 = File.ReadAllText("D:\\Push\\PushMessage.txt");
  86. if (!string.IsNullOrEmpty(str1))
  87. {
  88. var obj = JsonConvert.DeserializeObject<PushTime>(str1);
  89. if (obj != null)
  90. {
  91. if (DateTime.Now.Day - obj.time .Day >0)
  92. {
  93. program.time.time = DateTime.Now;
  94. program.time.morning = 1;
  95. program.time.Afternoon = 0;
  96. // System.Console.WriteLine("aavaa" + program.time.morning);
  97. Push(program.time);
  98. string urla = "http://oa.shuanghui.net/PushMessage/PushMessagePush";
  99. string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了
  100. }
  101. else
  102. {
  103. if (program.time.morning<=0)
  104. {
  105. program.time.time = DateTime.Now;
  106. program.time.morning = 1;
  107. program.time.Afternoon = obj.Afternoon ;
  108. // System.Console.WriteLine("aacaa" + program.time.morning);
  109. Push(program.time);
  110. string urla = "http://oa.shuanghui.net/PushMessage/PushMessagePush";
  111. string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了
  112. }
  113. }
  114. }
  115. }
  116. }
  117. else if (DateTime.Now.ToString("HH") == "14")
  118. {
  119. string str1 = File.ReadAllText("D:\\Push\\PushMessage.txt");
  120. // System.Console.WriteLine("nnvnn" + str1);
  121. if (!string.IsNullOrEmpty(str1))
  122. {
  123. var obj = JsonConvert.DeserializeObject<PushTime>(str1);
  124. if (obj != null)
  125. {
  126. if (DateTime.Now.Day - obj.time.Day > 0)
  127. {
  128. program.time.time = DateTime.Now;
  129. program.time.morning = obj .morning ;
  130. program.time.Afternoon = 1;
  131. Push(program.time);
  132. //System.Console.WriteLine("nnvnn" + program.time.Afternoon);
  133. string urla = "http://oa.shuanghui.net/PushMessage/PushMessagePush";
  134. string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了
  135. }
  136. else
  137. {
  138. if (program.time.Afternoon <= 0)
  139. {
  140. program.time.time = DateTime.Now;
  141. program.time.morning = obj.morning;
  142. program.time.Afternoon = 1;
  143. Push(program.time);
  144. // System.Console.WriteLine("nncnn" + program.time.Afternoon);
  145. string urla = "http://oa.shuanghui.net/PushMessage/PushMessagePush";
  146. string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. catch
  154. {
  155. }
  156. }
  157. }
  158. }
  159. }