Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // monitor_fs.cpp
- // compile with: /clr
- #using <system.dll>
- using namespace System;
- using namespace System::IO;
- using namespace System::Diagnostics;
- ref class FSEventHandler
- {
- public:
- void OnChanged(Object^ source, FileSystemEventArgs^ e)
- {
- Console::WriteLine("File: {0} {1}",
- e->FullPath, e->ChangeType);
- String^ name="";
- String^ num="";
- StreamReader^ sr = File::OpenText(e->Name);
- try
- {
- String^ s = "";
- if (s = sr->ReadLine())
- {
- array<String^>^ arr = s->Split(' ');
- arr[0] + " " + arr[1];
- num = arr[3];
- }
- while (s = sr->ReadLine())
- {
- File::AppendAllText("in.cpp", s);
- }
- }
- finally
- {
- if (sr)
- delete (IDisposable^)(sr);
- }
- String^ com = "contest=2018-02-25 " + name + "=in.cpp:VC++ > out.txt";
- Process::Start("local_contests.exe",com);
- StreamReader^ sr = File::OpenText("out.txt");
- String^ res;
- try
- {
- String^ s = "";
- while (s = sr->ReadLine())
- {
- if (s == "Checking...")
- break;
- }
- while (s = sr->ReadLine())
- {
- File::AppendAllText("res.txt", s);
- }
- array<String^>^ arr = s->Split(' ');
- res = arr[arr->Length - 1];
- }
- finally
- {
- if (sr)
- delete (IDisposable^)(sr);
- }
- }
- };
- int main()
- {
- array<String^>^ args = Environment::GetCommandLineArgs();
- if (args->Length < 2)
- {
- Console::WriteLine("Usage: Watcher.exe <directory>");
- return -1;
- }
- FileSystemWatcher^ fsWatcher = gcnew FileSystemWatcher();
- fsWatcher->Path = args[1];
- fsWatcher->NotifyFilter = static_cast<NotifyFilters>
- (NotifyFilters::FileName |
- NotifyFilters::Attributes |
- NotifyFilters::LastAccess |
- NotifyFilters::LastWrite |
- NotifyFilters::Security |
- NotifyFilters::Size);
- FSEventHandler^ handler = gcnew FSEventHandler();
- fsWatcher->Changed += gcnew FileSystemEventHandler(
- handler, &FSEventHandler::OnChanged);
- fsWatcher->Created += gcnew FileSystemEventHandler(
- handler, &FSEventHandler::OnChanged);
- fsWatcher->Deleted += gcnew FileSystemEventHandler(
- handler, &FSEventHandler::OnChanged);
- fsWatcher->EnableRaisingEvents = true;
- //Console::WriteLine("Press Enter to quit the sample.");
- //Console::ReadLine();
- }
- Azure
- https://developers.google.com/sheets/api/quickstart/dotnet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement