示例#1
0
 private void StartWork()
 {
     while (!isStop)
     {
         while (MaxTask - tasks.Count > 0 && !isStop)
         {
             Dictionary <string, string> WCFBack = null;
             try
             {
                 using (TaskRequestServ.TaskPoolClient tp = new TaskRequestServ.TaskPoolClient())
                 {
                     WCFBack = tp.GetTask(HostName, tasks.Count);
                     tp.Close();
                 }
                 if (WCFBack != null)
                 {
                     if (WCFBack["Usage"] == "Work")
                     {
                         Int32   id              = Int32.Parse(WCFBack["Id"]);
                         String  compilerpath    = WCFBack["CompilerPath"];
                         String  compilerargs    = WCFBack["CompilerArgs"];
                         String  codeformat      = WCFBack["CodeFormat"];
                         String  executionformat = WCFBack["ExecutionFormat"];
                         Boolean isscript        = Boolean.Parse(WCFBack["IsScript"]);
                         Int32   compilelimit    = Int32.Parse(WCFBack["CompileLimit"]);
                         String  code            = WCFBack["Code"];
                         tasks.Add(id);
                         Task.Run(() => Judge(id, compilerpath, compilerargs, code, codeformat, executionformat, isscript, compilelimit));
                     }
                     else
                     {
                         MaxTask   = Int32.Parse(WCFBack["MaxTask"]);
                         WorkDir   = WCFBack["WorkDir"];
                         Heartbeat = Int32.Parse(WCFBack["Heartbeat"]);
                         System.Threading.Thread.Sleep(Heartbeat);
                     }
                 }
             }
             catch (Exception)
             {
                 ;
             }
         }
         System.Threading.Thread.Sleep(1000);
     }
 }
示例#2
0
 protected override void OnStart(string[] args)
 {
     using (TaskRequestServ.TaskPoolClient tp = new TaskRequestServ.TaskPoolClient())
     {
         HostName = GetType().Assembly.Location.Split('\\').LastOrDefault().Substring(1).Replace(".exe", "");
         var WCFBack = tp.IamOnline(HostName, Dns.GetHostEntry(Dns.GetHostName()).AddressList.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).FirstOrDefault().ToString(), getRAM(), Environment.ProcessorCount, Environment.OSVersion.ToString(), "c");
         if (WCFBack["Err"] != "")
         {
             throw new Exception("Instance already exist.");
         }
         MaxTask   = Int32.Parse(WCFBack["MaxTask"]);
         WorkDir   = WCFBack["WorkDir"];
         Heartbeat = Int32.Parse(WCFBack["Heartbeat"]);
         tp.Close();
     }
     tr = new System.Threading.Thread(new System.Threading.ThreadStart(() => StartWork()));
     tr.Start();
 }
示例#3
0
 private void updateTaskCompilingResult(int id, String status, Double time, String Reply)
 {
     while (true)
     {
         try
         {
             using (TaskRequestServ.TaskPoolClient tp = new TaskRequestServ.TaskPoolClient())
             {
                 tp.updateTaskCompilingResult(id, status, time, Reply, tasks.Count);
                 tp.Close();
             }
         }
         catch (Exception ex)
         {
             System.Threading.Thread.Sleep(3000);
             continue;
         }
         return;
     }
 }