public static void StartInterpreting(TestFile testFile, MainWindow mw) { mainWindow = mw; Utilities.UsableMethods.unzipTest(testFile); lines = Utilities.UsableMethods.ReadFile(testFile.unzippedTestPath + testFile.fileWithTestName); PrepareTest(); StartTest(); }
internal async void WaitForTestWrapper() { TestFile testFile; if (Utilities.MockedTestFile.isFileMocked) { testFile = new TestFile(clientName); System.IO.Directory.CreateDirectory(testFile.unzippedTestPath); } else { Func<TestFile> indicatorToGetTestFromServer = new Func<TestFile>(() => Connection.ClientConnection.Instance.GetTestFromServer(clientName)); await ClientConnection.Instance.WaitForTest(); testFile = await Task.Run<TestFile>(indicatorToGetTestFromServer); } if (testFile != null) StartTest(testFile); else CancelTest(); }
internal TestFile GetTestFromServer(string clientName) { Int64 catchedBytes = 0; int countOfBytes; var buffer = new byte[1024 * 8]; try { networkStream.Read(buffer, 0, 8); Int64 numberOfBytes = BitConverter.ToInt64(buffer, 0); testFile = new TestFile(clientName); AppDomain.CurrentDomain.ProcessExit += new EventHandler(testFile.Dispose);//(testFile.Dispose); Directory.CreateDirectory(testFile.unzippedTestPath); using (var fileWithTest = File.Create(testFile.zippedTestPath)) { while (catchedBytes < numberOfBytes && (countOfBytes = networkStream.Read(buffer, 0, buffer.Length)) > 0) { fileWithTest.Write(buffer, 0, countOfBytes); catchedBytes += countOfBytes; } networkStream.Flush(); testFile.fileWithTest = fileWithTest; } MessageBoxResult result = MessageBox.Show("Test został pomyślnie ściągnięty z Serwera", "Rozpocznij Test", MessageBoxButton.OKCancel); if (!(result == MessageBoxResult.OK)) { testFile.Dispose(null, null); testFile = null; } } catch (ArgumentNullException) { MessageBox.Show("Bufor wysłany przez serwer jest pusty"); testFile.Dispose(null, null); testFile = null; } catch (ArgumentOutOfRangeException) { MessageBox.Show("Serwer wysłał za duży bufor danych"); testFile.Dispose(null, null); testFile = null; } catch (IOException) { MessageBox.Show("Wybrane gniazdo zostało wcześniej zakmnięte lub wystąpił problem podczas zapisywania pliku z testem na dysku twardym"); testFile.Dispose(null, null); testFile = null; } catch (ObjectDisposedException) { MessageBox.Show("Problem z odczytem danych z sieci"); testFile.Dispose(null, null); testFile = null; } return testFile; }