Advertisement
artemgf

Wjrk Program

Mar 1st, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.78 KB | None | 0 0
  1. using System;
  2. using System.Windows.Input;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.IO;
  8. using System.Diagnostics;
  9. using System.Resources;
  10. using Keystroke.API;
  11. using Keystroke;
  12. using System.Globalization;
  13. using System.Threading;
  14. using Google;
  15. using Google.GData.Client;
  16. using Google.GData.Extensions;
  17. using Google.GData.Spreadsheets;
  18. using Google.Apis.Auth.OAuth2;
  19. using Google.Apis.Sheets.v4;
  20. using Google.Apis.Sheets.v4.Data;
  21. using Google.Apis.Services;
  22. using Google.Apis.Util.Store;
  23.  
  24. namespace Прогаы
  25. {
  26.  
  27.     class Program
  28.     {
  29.         static string directchecer = "";
  30.         static string directread = "";
  31.         //static string[] Scopes = { SheetsService.Scope.SpreadsheetsReadonly };
  32.         static string ApplicationName = "Соревнование от Романа тест";
  33.         static String namecontest = "2018-02-25";
  34.         static String namelist = "Для заполнения";
  35.  
  36.         private static void OnChanged(Object source, FileSystemEventArgs e)
  37.         {
  38.             try
  39.             {
  40.                 Console.OutputEncoding = Encoding.GetEncoding(1251);
  41.                 String name = "";
  42.                 String num = "";
  43.                 StreamReader sr;
  44.                 string directcode = Path.GetDirectoryName(e.FullPath);
  45.                 List<string> lines = new List<string>();
  46.  
  47.                 using (var ssr = new StreamReader(File.Open(e.FullPath, FileMode.Open)))
  48.                 {
  49.                     string s;
  50.                     if ((s = ssr.ReadLine()) != null)
  51.                     {
  52.                         String[] arr = s.Split(' ');
  53.                         name = arr[0] + " " + arr[1];
  54.                         num = arr[2];
  55.                     }
  56.                     while ((s = ssr.ReadLine()) != null)
  57.                     {
  58.                         lines.Add(s);
  59.                     }
  60.                 }
  61.  
  62.                 using (var output = new StreamWriter(File.Open("in.cpp", FileMode.Create)))
  63.                     foreach (var line in lines)
  64.                         output.WriteLine(line);
  65.                 lines.Clear();
  66.                 File.Delete(e.FullPath);
  67.                 String com = "contest="+namecontest+" " + num + "=in.cpp:VC++";
  68.                 Console.WriteLine(com);
  69.  
  70.                 Process p = new Process();
  71.                 ProcessStartInfo psi = new ProcessStartInfo();
  72.  
  73.                 string errors, messages;
  74.  
  75.                 psi.WorkingDirectory = directchecer;
  76.                 psi.FileName = directchecer+"\\local_contests.exe";
  77.                 psi.Arguments = com;
  78.                 psi.UseShellExecute = false;
  79.                 psi.RedirectStandardError = true;
  80.                 psi.RedirectStandardOutput = true;
  81.  
  82.                 StreamReader errorsReader;
  83.                 StreamReader stdReader;
  84.  
  85.                 p.StartInfo = psi;
  86.  
  87.                 p.Start();
  88.                 errorsReader = p.StandardError;
  89.                 stdReader = p.StandardOutput;
  90.                 errors = errorsReader.ReadToEnd();
  91.                 messages = stdReader.ReadToEnd();
  92.                 try
  93.                 {
  94.                     p.WaitForExit();
  95.                 }
  96.                 catch (Exception ex)
  97.                 {
  98.                     ;
  99.                 }
  100.  
  101.                 using (var fr = new StreamWriter(File.OpenWrite("out.txt")))
  102.                 {
  103.                     fr.WriteLine(messages);
  104.                 }
  105.  
  106.                 File.Delete("in.cpp");
  107.                 String res;
  108.                 using (sr = File.OpenText("out.txt"))
  109.                 {
  110.                     String s = "";
  111.                     while ((s = sr.ReadLine()) != null)
  112.                     {
  113.                         if (s == "Checking...")
  114.                             break;
  115.                         else
  116.                             if (s == "Compilation error:")
  117.                             lines.Add(s);
  118.                     }
  119.                     String h="";
  120.                     while ((s = sr.ReadLine()) != null)
  121.                     {
  122.                         lines.Add(s);
  123.                         h = s;
  124.                     }
  125.                     using (var output = new StreamWriter(File.Open(directchecer+"\\"+e.Name+" result.txt", FileMode.Create)))
  126.                         foreach (var line in lines)
  127.                             output.WriteLine(line);
  128.                     File.Delete("out.txt");
  129.                     if (h.Length != 0)
  130.                     {
  131.                         String[] arr = h.Split(' ');
  132.                         res = arr[arr.Length - 1];
  133.                     }
  134.                 }
  135.             }
  136.             catch (Exception exp)
  137.             {
  138.                 Console.WriteLine(exp.Message);
  139.             }
  140.         }
  141.  
  142.         static void Main(string[] args)
  143.         {
  144.             Console.WriteLine("Write name of contest");
  145.             namecontest = Console.ReadLine();
  146.             Console.WriteLine("Write path to directory with cheker");
  147.             directchecer = Console.ReadLine();
  148.             Console.WriteLine("Write path to directory where program have to check change");
  149.             directread = Console.ReadLine();
  150.             FileSystemWatcher fsw = new FileSystemWatcher(directread);
  151.             fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
  152.               | NotifyFilters.FileName | NotifyFilters.DirectoryName;
  153.             fsw.Created += new FileSystemEventHandler(OnChanged);
  154.             fsw.Changed += new FileSystemEventHandler(OnChanged);
  155.             fsw.EnableRaisingEvents = true;
  156.             ConsoleKeyInfo key;
  157.             do
  158.             {
  159.                 key = Console.ReadKey();
  160.             }
  161.             while (key.Key != ConsoleKey.Escape);
  162.  
  163.         }
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement