Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.IO;
- using System.Diagnostics;
- using System.Resources;
- 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[] Scopes = { SheetsService.Scope.SpreadsheetsReadonly };
- static string ApplicationName = "Соревнование от Романа тест";
- static String namecontest = "2018-02-25";
- static String namelist = "Для заполнения";
- private static void OnChanged(Object source, FileSystemEventArgs e)
- {
- String name = "";
- String num = "";
- StreamReader sr;
- using (sr = File.OpenText(e.Name))
- {
- String s = "";
- if ((s = sr.ReadLine()) != null)
- {
- String[] arr = s.Split(' ');
- name = arr[0] + " " + arr[1];
- num = arr[3];
- }
- while ((s = sr.ReadLine()) != null)
- {
- File.AppendAllText("in.cpp", s);
- }
- }
- File.Delete(e.Name);
- String com = "contest=" + namecontest + " " + num + "=in.cpp:VC++ > out.txt";
- Process.Start("local_contests.exe", com).WaitForExit();
- String res;
- File.Delete("in.cpp");
- using (sr = File.OpenText(e.Name))
- {
- String s = "";
- while ((s = sr.ReadLine()) != null)
- {
- if (s == "Checking...")
- break;
- }
- while ((s = sr.ReadLine()) != null)
- {
- File.AppendAllText("result of " + name + ".txt", s);
- }
- String[] arr = s.Split(' ');
- res = arr[arr.Length - 1];
- }
- File.Delete("out.txt");
- UserCredential credential;
- using (var stream =
- new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
- {
- string credPath = System.Environment.GetFolderPath(
- System.Environment.SpecialFolder.Personal);
- credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
- credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
- GoogleClientSecrets.Load(stream).Secrets,
- Scopes,
- "user",
- CancellationToken.None,
- new FileDataStore(credPath, true)).Result;
- Console.WriteLine("Credential file saved to: " + credPath);
- }
- var service = new SheetsService(new BaseClientService.Initializer()
- {
- HttpClientInitializer = credential,
- ApplicationName = ApplicationName,
- });
- String spreadsheetId = "tv5GnmrP9WbOEyQNrBjEcAQ9";
- String range = namelist + "!A2:L";
- SpreadsheetsResource.ValuesResource.GetRequest request =
- service.Spreadsheets.Values.Get(spreadsheetId, range);
- ValueRange response = request.Execute();
- IList<IList<Object>> values = response.Values;
- if (values != null && values.Count > 0)
- {
- var i = 0;
- var our = -1;
- foreach (var row in values)
- {
- if (row[0] == name)
- our = i;
- i++;
- }
- if(our!=-1)
- {
- values[our][num[num.Length - 1] - '0'] = res;
- }
- }
- response.Values = values;
- SpreadsheetsResource.ValuesResource.UpdateRequest requesst = service.Spreadsheets.Values.Update(response, spreadsheetId, range);
- }
- static void Main(string[] args)
- {
- FileSystemWatcher fsw = new FileSystemWatcher("C:\\");
- fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
- | NotifyFilters.FileName | NotifyFilters.DirectoryName;
- fsw.Created += new FileSystemEventHandler(OnChanged);
- fsw.EnableRaisingEvents = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment