Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Input;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Diagnostics;
- using System.Resources;
- using Keystroke.API;
- using Keystroke;
- using System.Globalization;
- using System.Threading;
- using Google;
- using Google.GData.Client;
- using Google.GData.Extensions;
- using Google.GData.Spreadsheets;
- using Google.Apis.Auth.OAuth2;
- using Google.Apis.Sheets.v4;
- using Google.Apis.Sheets.v4.Data;
- using Google.Apis.Services;
- using Google.Apis.Util.Store;
- namespace Прогаы
- {
- class Program
- {
- static string directchecer = "";
- static string directread = "";
- //static string[] Scopes = { SheetsService.Scope.SpreadsheetsReadonly };
- static string ApplicationName = "Соревнование от Романа тест";
- static String namecontest = "2018-02-25";
- static String namelist = "Для заполнения";
- private static void OnChanged(Object source, FileSystemEventArgs e)
- {
- try
- {
- Console.OutputEncoding = Encoding.GetEncoding(1251);
- String name = "";
- String num = "";
- StreamReader sr;
- string directcode = Path.GetDirectoryName(e.FullPath);
- List<string> lines = new List<string>();
- using (var ssr = new StreamReader(File.Open(e.FullPath, FileMode.Open)))
- {
- string s;
- if ((s = ssr.ReadLine()) != null)
- {
- String[] arr = s.Split(' ');
- name = arr[0] + " " + arr[1];
- num = arr[2];
- }
- while ((s = ssr.ReadLine()) != null)
- {
- lines.Add(s);
- }
- }
- using (var output = new StreamWriter(File.Open("in.cpp", FileMode.Create)))
- foreach (var line in lines)
- output.WriteLine(line);
- lines.Clear();
- File.Delete(e.FullPath);
- String com = "contest="+namecontest+" " + num + "=in.cpp:VC++";
- Console.WriteLine(com);
- Process p = new Process();
- ProcessStartInfo psi = new ProcessStartInfo();
- string errors, messages;
- psi.WorkingDirectory = directchecer;
- psi.FileName = directchecer+"\\local_contests.exe";
- psi.Arguments = com;
- psi.UseShellExecute = false;
- psi.RedirectStandardError = true;
- psi.RedirectStandardOutput = true;
- StreamReader errorsReader;
- StreamReader stdReader;
- p.StartInfo = psi;
- p.Start();
- errorsReader = p.StandardError;
- stdReader = p.StandardOutput;
- errors = errorsReader.ReadToEnd();
- messages = stdReader.ReadToEnd();
- try
- {
- p.WaitForExit();
- }
- catch (Exception ex)
- {
- ;
- }
- using (var fr = new StreamWriter(File.OpenWrite("out.txt")))
- {
- fr.WriteLine(messages);
- }
- File.Delete("in.cpp");
- String res;
- using (sr = File.OpenText("out.txt"))
- {
- String s = "";
- while ((s = sr.ReadLine()) != null)
- {
- if (s == "Checking...")
- break;
- else
- if (s == "Compilation error:")
- lines.Add(s);
- }
- String h="";
- while ((s = sr.ReadLine()) != null)
- {
- lines.Add(s);
- h = s;
- }
- using (var output = new StreamWriter(File.Open(directchecer+"\\"+e.Name+" result.txt", FileMode.Create)))
- foreach (var line in lines)
- output.WriteLine(line);
- File.Delete("out.txt");
- if (h.Length != 0)
- {
- String[] arr = h.Split(' ');
- res = arr[arr.Length - 1];
- }
- }
- }
- catch (Exception exp)
- {
- Console.WriteLine(exp.Message);
- }
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Write name of contest");
- namecontest = Console.ReadLine();
- Console.WriteLine("Write path to directory with cheker");
- directchecer = Console.ReadLine();
- Console.WriteLine("Write path to directory where program have to check change");
- directread = Console.ReadLine();
- FileSystemWatcher fsw = new FileSystemWatcher(directread);
- fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
- | NotifyFilters.FileName | NotifyFilters.DirectoryName;
- fsw.Created += new FileSystemEventHandler(OnChanged);
- fsw.Changed += new FileSystemEventHandler(OnChanged);
- fsw.EnableRaisingEvents = true;
- ConsoleKeyInfo key;
- do
- {
- key = Console.ReadKey();
- }
- while (key.Key != ConsoleKey.Escape);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement