using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Push { class Program { public class PushTime { public DateTime time; public int morning; public int Afternoon; } private PushTime time = new PushTime(); static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.UTF8; Environment.SetEnvironmentVariable("needDetails", "true"); // Console.OutputEncoding = System.Text.Encoding.UTF8; // Environment.SetEnvironmentVariable("needDetails", "true"); System.Console.WriteLine("Hello Push!"); // System.Console.WriteLine(DateTime.Now.ToString("HH")); //PushTime time = new PushTime(); //time.time = DateTime.Now; //time.morning = 0; //time.Afternoon = 0; //Push(time); Thread t = new Thread(new ThreadStart(SetCensusURL)); t.Start(); } public static void Push(PushTime time) { FileStream fs = null; try { if (!Directory.Exists("D:\\Push")) { Directory.CreateDirectory("D:\\Push"); } if ( File.Exists("D:\\Push\\PushMessage.txt")) { // System.Console.WriteLine(JsonConvert.SerializeObject(time)); File.WriteAllText("D:\\Push\\PushMessage.txt", JsonConvert.SerializeObject(time), Encoding.UTF8); } else { // System.Console.WriteLine(JsonConvert.SerializeObject(time)); File.WriteAllText("D:\\Push\\PushMessage.txt", JsonConvert.SerializeObject(time), Encoding.UTF8); } } finally { if (fs != null) { fs.Close(); } } } //http://oa.shuanghui.net:8046/ private static void SetCensusURL() { int n = 0; while (true) { Thread.Sleep(60 * 1000); n += 1; WebClient web = new WebClient(); web.Encoding = Encoding.UTF8; try { string seturl = "http://oa.shuanghui.net:8046/PushMessage/SetCensusURL"; string Dataaaurl = web.DownloadString(seturl);//这一句话就能请求到数据了 // System.Console.WriteLine("nnvnn" + Dataaaurl); string url = "http://oa.shuanghui.net:8046/PushMessage/SetPush"; string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了 // System.Console.WriteLine("nnvnn" + Dataaa); //Program program = new Program(); // if (DateTime.Now.ToString("HH") == "09") // { // string str1 = File.ReadAllText("D:\\Push\\PushMessage.txt"); // if (!string.IsNullOrEmpty(str1)) // { // var obj = JsonConvert.DeserializeObject(str1); // if (obj != null) // { // if (DateTime.Now.Day - obj.time .Day >0) // { // program.time.time = DateTime.Now; // program.time.morning = 1; // program.time.Afternoon = 0; // // System.Console.WriteLine("aavaa" + program.time.morning); // Push(program.time); // string urla = "http://192.168.8.9:1001//PushMessage/PushMessagePush"; // string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了 // } // else // { // if (program.time.morning<=0) // { // program.time.time = DateTime.Now; // program.time.morning = 1; // program.time.Afternoon = obj.Afternoon ; // // System.Console.WriteLine("aacaa" + program.time.morning); // Push(program.time); // string urla = "http://192.168.8.9:1001//PushMessage/PushMessagePush"; // string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了 // } // } // } // } // } // else if (DateTime.Now.ToString("HH") == "14") // { // string str1 = File.ReadAllText("D:\\Push\\PushMessage.txt"); // // System.Console.WriteLine("nnvnn" + str1); // if (!string.IsNullOrEmpty(str1)) // { // var obj = JsonConvert.DeserializeObject(str1); // if (obj != null) // { // if (DateTime.Now.Day - obj.time.Day > 0) // { // program.time.time = DateTime.Now; // program.time.morning = obj .morning ; // program.time.Afternoon = 1; // Push(program.time); // //System.Console.WriteLine("nnvnn" + program.time.Afternoon); // string urla = "http://oa.shuanghui.net:8046//PushMessage/PushMessagePush"; // string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了 // } // else // { // if (program.time.Afternoon <= 0) // { // program.time.time = DateTime.Now; // program.time.morning = obj.morning; // program.time.Afternoon = 1; // Push(program.time); // // System.Console.WriteLine("nncnn" + program.time.Afternoon); // string urla = "http://oa.shuanghui.net:8046//PushMessage/PushMessagePush"; // string Dataa = web.DownloadString(urla);//这一句话就能请求到数据了 // } // } // } // } // } } catch { } } } } }