artemgf

newProg with Google

Feb 26th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using System.IO;
  8. using System.Diagnostics;
  9. using System.Resources;
  10. using Google;
  11. using Google.GData.Client;
  12. using Google.GData.Extensions;
  13. using Google.GData.Spreadsheets;
  14. using Google.Apis.Auth.OAuth2;
  15. using Google.Apis.Sheets.v4;
  16. using Google.Apis.Sheets.v4.Data;
  17. using Google.Apis.Services;
  18. using Google.Apis.Util.Store;
  19.  
  20. namespace Прогаы
  21. {
  22.    
  23.     class Program
  24.     {
  25.         static string[] Scopes = { SheetsService.Scope.SpreadsheetsReadonly };
  26.         static string ApplicationName = "Соревнование от Романа тест";
  27.         static String namecontest = "2018-02-25";
  28.         static String namelist = "Для заполнения";
  29.         private static void OnChanged(Object source, FileSystemEventArgs e)
  30.         {
  31.             String name = "";
  32.             String num = "";
  33.             StreamReader sr;
  34.             using (sr = File.OpenText(e.Name))
  35.             {
  36.                 String s = "";
  37.                 if ((s = sr.ReadLine()) != null)
  38.                 {
  39.                     String[] arr = s.Split(' ');
  40.                     name = arr[0] + " " + arr[1];
  41.                     num = arr[3];
  42.                 }
  43.                 while ((s = sr.ReadLine()) != null)
  44.                 {
  45.                     File.AppendAllText("in.cpp", s);
  46.                 }
  47.             }
  48.             File.Delete(e.Name);
  49.             String com = "contest=" + namecontest + " " + num + "=in.cpp:VC++ > out.txt";
  50.             Process.Start("local_contests.exe", com).WaitForExit();
  51.             String res;
  52.             File.Delete("in.cpp");
  53.             using (sr = File.OpenText(e.Name))
  54.             {
  55.                 String s = "";
  56.                 while ((s = sr.ReadLine()) != null)
  57.                 {
  58.                     if (s == "Checking...")
  59.                         break;
  60.                 }
  61.                 while ((s = sr.ReadLine()) != null)
  62.                 {
  63.                     File.AppendAllText("result of " + name + ".txt", s);
  64.                 }
  65.                 String[] arr = s.Split(' ');
  66.                 res = arr[arr.Length - 1];
  67.             }
  68.             File.Delete("out.txt");
  69.  
  70.             UserCredential credential;
  71.             using (var stream =
  72.                 new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
  73.             {
  74.                 string credPath = System.Environment.GetFolderPath(
  75.                     System.Environment.SpecialFolder.Personal);
  76.                 credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
  77.  
  78.                 credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
  79.                     GoogleClientSecrets.Load(stream).Secrets,
  80.                     Scopes,
  81.                     "user",
  82.                     CancellationToken.None,
  83.                     new FileDataStore(credPath, true)).Result;
  84.                 Console.WriteLine("Credential file saved to: " + credPath);
  85.             }
  86.             var service = new SheetsService(new BaseClientService.Initializer()
  87.             {
  88.                 HttpClientInitializer = credential,
  89.                 ApplicationName = ApplicationName,
  90.             });
  91.             String spreadsheetId = "tv5GnmrP9WbOEyQNrBjEcAQ9";
  92.             String range = namelist + "!A2:L";
  93.  
  94.             SpreadsheetsResource.ValuesResource.GetRequest request =
  95.                   service.Spreadsheets.Values.Get(spreadsheetId, range);
  96.             ValueRange response = request.Execute();
  97.             IList<IList<Object>> values = response.Values;
  98.             if (values != null && values.Count > 0)
  99.             {
  100.                 var i = 0;
  101.                 var our = -1;
  102.                 foreach (var row in values)
  103.                 {
  104.                     if (row[0] == name)
  105.                         our = i;
  106.                     i++;
  107.                 }
  108.                 if(our!=-1)
  109.                 {
  110.                     values[our][num[num.Length - 1] - '0'] = res;
  111.                 }
  112.             }
  113.             response.Values = values;
  114.             SpreadsheetsResource.ValuesResource.UpdateRequest requesst = service.Spreadsheets.Values.Update(response, spreadsheetId, range);
  115.         }
  116.  
  117.         static void Main(string[] args)
  118.         {
  119.             FileSystemWatcher fsw = new FileSystemWatcher("C:\\");
  120.             fsw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
  121.               | NotifyFilters.FileName | NotifyFilters.DirectoryName;
  122.  
  123.             fsw.Created += new FileSystemEventHandler(OnChanged);
  124.             fsw.EnableRaisingEvents = true;
  125.         }
  126.     }
  127. }
Add Comment
Please, Sign In to add comment