Advertisement
artemgf

Прога

Feb 25th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. // monitor_fs.cpp  
  2. // compile with: /clr  
  3. #using <system.dll>  
  4.  
  5. using namespace System;
  6. using namespace System::IO;
  7. using namespace System::Diagnostics;
  8.  
  9. ref class FSEventHandler
  10. {
  11. public:
  12.     void OnChanged(Object^ source, FileSystemEventArgs^ e)
  13.     {
  14.         Console::WriteLine("File: {0} {1}",
  15.             e->FullPath, e->ChangeType);
  16.         String^ name="";
  17.         String^ num="";
  18.         StreamReader^ sr = File::OpenText(e->Name);
  19.         try
  20.         {
  21.             String^ s = "";
  22.             if (s = sr->ReadLine())
  23.             {
  24.                 array<String^>^ arr = s->Split(' ');
  25.                  arr[0] + " " + arr[1];
  26.                 num = arr[3];
  27.             }
  28.             while (s = sr->ReadLine())
  29.             {
  30.                 File::AppendAllText("in.cpp", s);
  31.             }
  32.         }
  33.         finally
  34.         {
  35.             if (sr)
  36.                 delete (IDisposable^)(sr);
  37.         }
  38.         String^ com = "contest=2018-02-25 " + name + "=in.cpp:VC++ > out.txt";
  39.         Process::Start("local_contests.exe",com);
  40.         StreamReader^ sr = File::OpenText("out.txt");
  41.         String^ res;
  42.         try
  43.         {
  44.             String^ s = "";
  45.             while (s = sr->ReadLine())
  46.             {
  47.                 if (s == "Checking...")
  48.                     break;
  49.             }
  50.             while (s = sr->ReadLine())
  51.             {
  52.                 File::AppendAllText("res.txt", s);
  53.             }
  54.             array<String^>^ arr = s->Split(' ');
  55.             res = arr[arr->Length - 1];
  56.         }
  57.         finally
  58.         {
  59.             if (sr)
  60.                 delete (IDisposable^)(sr);
  61.         }
  62.  
  63.     }
  64. };
  65.  
  66. int main()
  67. {
  68.     array<String^>^ args = Environment::GetCommandLineArgs();
  69.  
  70.     if (args->Length < 2)
  71.     {
  72.         Console::WriteLine("Usage: Watcher.exe <directory>");
  73.         return -1;
  74.     }
  75.  
  76.     FileSystemWatcher^ fsWatcher = gcnew FileSystemWatcher();
  77.     fsWatcher->Path = args[1];
  78.     fsWatcher->NotifyFilter = static_cast<NotifyFilters>
  79.         (NotifyFilters::FileName |
  80.             NotifyFilters::Attributes |
  81.             NotifyFilters::LastAccess |
  82.             NotifyFilters::LastWrite |
  83.             NotifyFilters::Security |
  84.             NotifyFilters::Size);
  85.  
  86.     FSEventHandler^ handler = gcnew FSEventHandler();
  87.     fsWatcher->Changed += gcnew FileSystemEventHandler(
  88.         handler, &FSEventHandler::OnChanged);
  89.     fsWatcher->Created += gcnew FileSystemEventHandler(
  90.         handler, &FSEventHandler::OnChanged);
  91.     fsWatcher->Deleted += gcnew FileSystemEventHandler(
  92.         handler, &FSEventHandler::OnChanged);
  93.  
  94.     fsWatcher->EnableRaisingEvents = true;
  95.  
  96.     //Console::WriteLine("Press Enter to quit the sample.");
  97.     //Console::ReadLine();
  98. }
  99.  
  100. Azure
  101. https://developers.google.com/sheets/api/quickstart/dotnet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement