예제 #1
0
        public static void run_code(string c)
        {
            //создаю временный файл
            string tempDirectory = @"C:\Users\Morfa\AppData\Local\Temp";

            System.CodeDom.Compiler.TempFileCollection coll = new System.CodeDom.Compiler.TempFileCollection(tempDirectory, true);
            string fileTMP = coll.AddExtension("py", true);

            File.WriteAllText(Path.Combine(tempDirectory, fileTMP), c);

            using (System.Diagnostics.Process myProcess = new System.Diagnostics.Process())
            {
                //передаем в консоль название файла
                myProcess.StartInfo.Arguments = @"/k python3 " + fileTMP;
                myProcess.StartInfo.FileName  = "cmd.exe";
                //запускаем консоль
                myProcess.Start();
                //ожидаем закрытия консоли
                myProcess.WaitForExit();

                //удаляем временные файлы
                System.IO.File.Delete(fileTMP);
                fileTMP = fileTMP.Replace("py", "tmp");
                System.IO.File.Delete(fileTMP);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets a temporary folder specifically for HCMIS
        /// </summary>
        /// <returns></returns>
        private static string GetTempFolder()
        {
            System.CodeDom.Compiler.TempFileCollection tempFileLocation =
                new System.CodeDom.Compiler.TempFileCollection();
            string tempFolder = tempFileLocation.BasePath;

            tempFolder  = tempFolder.Substring(0, tempFolder.LastIndexOf("\\"));
            tempFolder += "\\HCMS";
            return(tempFolder);
        }
예제 #3
0
        /// <summary>
        /// Gets a new file name for exporting with the specified extension.
        /// </summary>
        /// <param name="extension">The extension of the specified file</param>
        /// <returns>Returns a file name that can be used for exporting</returns>
        public static string GetNewFileName(string extension)
        {
            System.CodeDom.Compiler.TempFileCollection tempFileLocation =
                new System.CodeDom.Compiler.TempFileCollection();
            string tempFolder = GetTempFolder();

            if (!System.IO.Directory.Exists(tempFolder))
            {
                System.IO.Directory.CreateDirectory(tempFolder);
            }
            return(tempFileLocation.AddExtension(extension));
        }
예제 #4
0
        /// <summary>
        /// Make sure that we delete files that we made when we are done.
        /// </summary>
        /// <param name="tempFiles"></param>
        private void LDPigTempFiles(System.CodeDom.Compiler.TempFileCollection tempFiles)
        {
            // make sure no resedue from last time
            string pigTxtFile = TestUtils.GetIcuDir() + "data\\locales\\pig.txt";

            TestUtils.DeleteFile(pigTxtFile);
            tempFiles.AddFile(pigTxtFile, false);
            string pigResFile = TestUtils.GetIcuDataDir() + "pig.res";

            TestUtils.DeleteFile(pigResFile);
            tempFiles.AddFile(pigResFile, false);
        }
예제 #5
0
        /// <summary>
        /// Creates temporary and backup files.
        /// </summary>
        /// <param name="saveFiles">The files that need to be backed up.</param>
        /// <param name="backupFiles">The backup that will overwrite the saved files when we are done.</param>
        /// <param name="tempFiles">The "TempFileCollection" that will be used
        ///		to delete the backup files when we are done</param>
        public static void MakeTempFiles(ArrayList saveFiles, out ArrayList backupFiles,
                                         out System.CodeDom.Compiler.TempFileCollection tempFiles)
        {
            tempFiles   = new System.CodeDom.Compiler.TempFileCollection();
            backupFiles = new ArrayList();

            foreach (string str in saveFiles)
            {
                string tmpName = System.IO.Path.GetTempFileName();
                File.Copy(str, tmpName, true);
                backupFiles.Add(tmpName);                               // create a 1 to 1 relationship from src to tmp file
                tempFiles.AddFile(tmpName, false);                      // remove files when container goes out of scope
            }
        }
예제 #6
0
        /// <summary>
        /// Cleans up all the shared stuff.
        /// 1. Icu.Cleanup()
        /// 2. Restores all the files to their original values
        /// </summary>
        /// <param name="saveFiles">The files to overwrite with their backups</param>
        /// <param name="backupFiles">The files to copy from</param>
        /// <param name="tempFiles">The files to delete, may be null, in which case they will not be deleted.</param>
        public static void CleanUpAndRestore(ArrayList saveFiles, ArrayList backupFiles,
                                             System.CodeDom.Compiler.TempFileCollection tempFiles)
        {
            Icu.Cleanup();                      // clean up the ICU files / data

            // Now restore all the original files (pre-test files)
            for (int i = 0; i < saveFiles.Count; i++)
            {
                File.Copy((string)(backupFiles[i]), (string)(saveFiles[i]), true);
            }
            if (tempFiles != null)
            {
                // removes all the temporary files
                tempFiles.Delete();
            }
        }
예제 #7
0
        public async Task <ActionResult> Export([Bind(Prefix = "ID")] int FlightID = 0)
        {
            if (!exLogic.User.hasAccess("FLIGHT.MAP"))
            {
                return(HttpNotFound("You do not have acces to this section"));
            }

            using (var tempFiles = new System.CodeDom.Compiler.TempFileCollection()) {
                string ExportFileName = tempFiles.AddExtension("csv");
                // do something with the file here
                using (System.IO.StreamWriter stream = new System.IO.StreamWriter(ExportFileName)) {
                    var query = from d in ctx.FlightMapDatas
                                where d.FlightID == FlightID
                                orderby d.ReadTime
                                select new {
                        ReadTime  = (DateTime)d.ReadTime,
                        Lat       = d.Latitude,
                        Lng       = d.Longitude,
                        Altitude  = d.Altitude,
                        Speed     = d.Speed,
                        Satellite = d.Satellites,
                        Pitch     = d.Pitch,
                        Roll      = d.Roll,
                        Heading   = d.Heading,
                        Voltage   = d.voltage,
                        Distance  = d.Distance
                    };
                    if (query.Any())
                    {
                        await stream.WriteLineAsync("DateTime,Lat,Lng,Altitude,Speed,Satellite,Pitch,Roll,Heading,Voltage,Distance");

                        foreach (var row in query.ToList())
                        {
                            await stream.WriteLineAsync($"{row.ReadTime.ToString("yyyy-MM-dd HH:mm:ss")},{row.Lat},{row.Lng},{row.Altitude},{row.Speed},{row.Satellite},{row.Pitch},{row.Roll},{row.Heading},{row.Voltage},{row.Distance}");
                        }
                    } //if(query.Any())
                }     //using (System.IO.StreamWriter stream)

                return(File(System.IO.File.OpenRead(ExportFileName), "text/csv", $"Flight-{FlightID}.csv"));
            }//using (var tempFiles)
        }
예제 #8
0
        public void TestSerializeTempFileCollection()
        {
            if (!Directory.Exists("C:/testdir"))
            {
                Directory.CreateDirectory("C:/testdir");
            }
            String testFile = "C:/testdir/test.txt";

            if (!File.Exists(testFile))
            {
                File.Create(testFile);
            }

            String          outputPath = "../../output/tempfilecollection.stm";
            BinaryFormatter formatter  = new BinaryFormatter();

            using (FileStream fs = File.OpenWrite(outputPath))
            {
                System.CodeDom.Compiler.TempFileCollection tempFileCollection =
                    new System.CodeDom.Compiler.TempFileCollection(@"C:\testdir", false);
                tempFileCollection.AddFile(@"C:\testdir\test.txt", false);
                formatter.Serialize(fs, tempFileCollection);
            }
        }
예제 #9
0
        /// <summary>
        /// Creates a temporary qt project template file. It creates the filters 
        /// in the order specified by the array.
        /// </summary>
        /// <param name="filters">The filters to add to the project file</param>
        /// <returns></returns>
        public static string CreateProjectTemplateFile(FakeFilter[] filters, bool useKeyword, string platformName)
        {
            // just to be safe
            ReleaseProjectTemplateFile();

            StreamWriter sw;
            tmpFiles = new System.CodeDom.Compiler.TempFileCollection();
            tmpFiles.KeepFiles = false;

            string tmpFile = tmpFiles.AddExtension("vcproj");

            try
            {
                if (SR.LanguageName == "ja")
                    sw = new StreamWriter(tmpFile, false, System.Text.Encoding.GetEncoding(932));
                else
                    sw = new StreamWriter(tmpFile, false);
            }
            catch (System.Exception e)
            {
                Messages.DisplayErrorMessage(e, SR.GetString("HelperFunctions_TryCreatingNewProject"));
                return null;
            }

            if (SR.LanguageName == "ja")
                sw.WriteLine("<?xml version=\"1.0\" encoding = \"shift_jis\"?>");
            else
                sw.WriteLine("<?xml version=\"1.0\" encoding = \"Windows-1252\"?>");
            sw.WriteLine("<VisualStudioProject");
            sw.WriteLine("    ProjectType=\"Visual C++\"");
            #if VS2005
            sw.WriteLine("    Version=\"8.00\"");
            #elif VS2008
            sw.WriteLine("    Version=\"9.00\"");
            #else
            sw.WriteLine("    Version=\"7.10\"");
            #endif
            sw.WriteLine("    ProjectGUID=\"{B12702AD-ABFB-343A-A199-8E24837244A3}\"");
            if (useKeyword)
                sw.WriteLine("    Keyword=\"" + Resources.qtProjectKeyword + "\">");
            else
                sw.WriteLine(">");

            sw.WriteLine("    <Platforms>");
            sw.WriteLine("        <Platform");
            sw.WriteLine("            Name=\"" + platformName + "\"/>");
            sw.WriteLine("    </Platforms>");
            sw.WriteLine("    <Configurations>");
            sw.WriteLine("        <Configuration");
            sw.WriteLine("            Name=\"Release|" + platformName + "\">");
            sw.WriteLine("        </Configuration>");
            sw.WriteLine("        <Configuration");
            sw.WriteLine("            Name=\"Debug|" + platformName + "\">");
            sw.WriteLine("        </Configuration>");
            sw.WriteLine("    </Configurations>");
            sw.WriteLine("    <Files>");

            for (int i=0; i<filters.Length; i++)
            {
                sw.WriteLine("        <Filter");
                sw.WriteLine("            Name=\"" + filters[i].Name + "\"");
                sw.WriteLine("            Filter=\"" + filters[i].Filter + "\"");
                if (!filters[i].ParseFiles)
                    sw.WriteLine("            ParseFiles=\"FALSE\"");
                if (!filters[i].SCCFiles)
                    sw.WriteLine("            SourceControlFiles=\"FALSE\"");
                sw.WriteLine("            UniqueIdentifier=\"" + filters[i].UniqueIdentifier + "\">");
                sw.WriteLine("        </Filter>");
            }

            sw.WriteLine("    </Files>");
            sw.WriteLine("</VisualStudioProject>");

            sw.Close();

            return tmpFile;
        }
예제 #10
0
		/// <summary>
		/// Creates temporary and backup files.
		/// </summary>
		/// <param name="saveFiles">The files that need to be backed up.</param>
		/// <param name="backupFiles">The backup that will overwrite the saved files when we are done.</param>
		/// <param name="tempFiles">The "TempFileCollection" that will be used
		///		to delete the backup files when we are done</param>
		public static void MakeTempFiles(ArrayList saveFiles, out ArrayList backupFiles,
			out System.CodeDom.Compiler.TempFileCollection tempFiles)
		{
			tempFiles = new System.CodeDom.Compiler.TempFileCollection();
			backupFiles = new ArrayList();

			foreach (string str in saveFiles)
			{
				string tmpName = System.IO.Path.GetTempFileName();
				File.Copy(str, tmpName, true);
				backupFiles.Add(tmpName);			// create a 1 to 1 relationship from src to tmp file
				tempFiles.AddFile(tmpName, false);	// remove files when container goes out of scope
			}
		}
예제 #11
0
        public void TestInstallLanguage_fast_speedtest()
        {
            // First backup the 'important' icu files
            ArrayList saveFiles = new ArrayList();

            InstallLanguageTests.IcuTests.LDInstallSaveFiles(saveFiles);

            // Make a list of files that should be the same between the two runs
            saveFiles.Add(TestUtils.GetIcuDir() + "data\\locales\\res_index.txt");
            saveFiles.Add(TestUtils.GetIcuDir() + "data\\locales\\root.txt");

            // make sure no resedue from last time
            string xxTxtFile = TestUtils.GetIcuDir() + "data\\locales\\xxx1_Wwww_YY2_ZZZ3.txt";

            TestUtils.DeleteFile(xxTxtFile);

            System.CodeDom.Compiler.TempFileCollection tempFiles;
            ArrayList backupFiles;

            // Files that need to be deleted between the running of the program so that they don't exist.
            System.CodeDom.Compiler.TempFileCollection specialDeleteTempFiles =
                new System.CodeDom.Compiler.TempFileCollection();
            specialDeleteTempFiles.AddFile(TestUtils.GetIcuDir()
                                           + "data\\locales\\xxx1_Wwww_YY2_ZZZ3.txt", false);
            specialDeleteTempFiles.AddFile(TestUtils.GetIcuDataDir() + "xxx1_Wwww_YY2_ZZZ3.res", false);

            TestUtils.MakeTempFiles(saveFiles, out backupFiles, out tempFiles);

            // Add files that need to be removed when we are done.
            tempFiles.AddFile(xxTxtFile, false);
            tempFiles.AddFile(TestUtils.GetIcuDataDir() + "xxx1_Wwww_YY2_ZZZ3.res", false);

            Process myProcess = new Process();
            string  rootPath  = TestUtils.GetFWRootDir();
            string  xxxFile   = InstallLanguageTests.IcuTests.MoveLDF("xxx1_Wwww_YY2_ZZZ3.xml");

            tempFiles.AddFile(xxxFile, false);                  // remove file when done with test

            string slow1;
            string slow2;

            int    currentRun = 0;
            int    maxRuns    = 20;
            Random random     = new Random(System.DateTime.Now.Millisecond);

            for (currentRun = 0; currentRun < maxRuns; currentRun++)
            {
                // Randomly switch which one runs first.
                if (random.NextDouble() > .5)
                {
                    slow1 = " -slow";
                    slow2 = "";
                }
                else
                {
                    slow2 = " -slow";
                    slow1 = "";
                }

                try
                {
                    TestUtils.RunProgram("InstallLanguage.exe", "-i " + xxxFile + " -q " + slow1, 0);
                    // Retore all the originals
                    // Don't delete the temporary files yet, we will need them later.
                    TestUtils.CleanUpAndRestore(saveFiles, backupFiles, null);
                    specialDeleteTempFiles.Delete();

                    TestUtils.RunProgram("InstallLanguage.exe", "-i " + xxxFile + " -q " + slow2, 0);
                }
                finally
                {
                    // Restore all the originals
                    // Don't delete the temporary files yet, we will need them later.
                    TestUtils.CleanUpAndRestore(saveFiles, backupFiles, null);
                }
            }

            TestUtils.CleanUpAndRestore(saveFiles, backupFiles, tempFiles);
            // Now make sure the Language was uninstalled / icu restored properly
            InstallLanguageTests.IcuTests.Checkxxx1_Wwww_YY2_ZZZ3Restored();
        }
예제 #12
0
		public void TestInstallLanguage_fast_speedtest()
		{
			// First backup the 'important' icu files
			ArrayList saveFiles = new ArrayList();
			InstallLanguageTests.IcuTests.LDInstallSaveFiles(saveFiles);

			// Make a list of files that should be the same between the two runs
			saveFiles.Add(TestUtils.GetIcuDir() + "data\\locales\\res_index.txt");
			saveFiles.Add(TestUtils.GetIcuDir() + "data\\locales\\root.txt");

			// make sure no resedue from last time
			string xxTxtFile = TestUtils.GetIcuDir() + "data\\locales\\xxx1_Wwww_YY2_ZZZ3.txt";
			TestUtils.DeleteFile(xxTxtFile);

			System.CodeDom.Compiler.TempFileCollection tempFiles;
			ArrayList backupFiles;

			// Files that need to be deleted between the running of the program so that they don't exist.
			System.CodeDom.Compiler.TempFileCollection specialDeleteTempFiles =
				new System.CodeDom.Compiler.TempFileCollection();
			specialDeleteTempFiles.AddFile(TestUtils.GetIcuDir()
				+ "data\\locales\\xxx1_Wwww_YY2_ZZZ3.txt", false);
			specialDeleteTempFiles.AddFile(TestUtils.GetIcuDataDir() + "xxx1_Wwww_YY2_ZZZ3.res", false);

			TestUtils.MakeTempFiles(saveFiles,out backupFiles, out tempFiles);

			// Add files that need to be removed when we are done.
			tempFiles.AddFile(xxTxtFile, false);
			tempFiles.AddFile(TestUtils.GetIcuDataDir() + "xxx1_Wwww_YY2_ZZZ3.res", false);

			Process myProcess = new Process();
			string rootPath = TestUtils.GetFWRootDir();
			string xxxFile = InstallLanguageTests.IcuTests.MoveLDF("xxx1_Wwww_YY2_ZZZ3.xml");
			tempFiles.AddFile(xxxFile, false);	// remove file when done with test

			string slow1;
			string slow2;

			int currentRun = 0;
			int maxRuns = 20;
			Random random = new Random(System.DateTime.Now.Millisecond);
			for( currentRun = 0; currentRun < maxRuns; currentRun ++)
			{
				// Randomly switch which one runs first.
				if(random.NextDouble() > .5)
				{
					slow1 = " -slow";
					slow2 = "";
				}
				else
				{
					slow2 = " -slow";
					slow1 = "";
				}

				try
				{
					TestUtils.RunProgram("InstallLanguage.exe","-i " + xxxFile + " -q " + slow1,0);
					// Retore all the originals
					// Don't delete the temporary files yet, we will need them later.
					TestUtils.CleanUpAndRestore(saveFiles,backupFiles,null);
					specialDeleteTempFiles.Delete();

					TestUtils.RunProgram("InstallLanguage.exe","-i " + xxxFile + " -q " + slow2,0);
				}
				finally
				{
					// Restore all the originals
					// Don't delete the temporary files yet, we will need them later.
					TestUtils.CleanUpAndRestore(saveFiles, backupFiles, null);
				}
			}

			TestUtils.CleanUpAndRestore(saveFiles, backupFiles, tempFiles);
			// Now make sure the Language was uninstalled / icu restored properly
			InstallLanguageTests.IcuTests.Checkxxx1_Wwww_YY2_ZZZ3Restored();
		}
 /// <summary>
 /// Gets a new file name for exporting with the specified extension.
 /// </summary>
 /// <param name="extension">The extension of the specified file</param>
 /// <returns>Returns a file name that can be used for exporting</returns>
 public static string GetNewFileName(string extension)
 {
     System.CodeDom.Compiler.TempFileCollection tempFileLocation =
         new System.CodeDom.Compiler.TempFileCollection();
     string tempFolder = GetTempFolder();
     if (!System.IO.Directory.Exists(tempFolder))
     {
         System.IO.Directory.CreateDirectory(tempFolder);
     }
     return tempFileLocation.AddExtension(extension);
 }
 /// <summary>
 /// Gets a temporary folder specifically for HCMIS
 /// </summary>
 /// <returns></returns>
 private static string GetTempFolder()
 {
     System.CodeDom.Compiler.TempFileCollection tempFileLocation =
         new System.CodeDom.Compiler.TempFileCollection();
     string tempFolder = tempFileLocation.BasePath;
     tempFolder = tempFolder.Substring(0, tempFolder.LastIndexOf("\\"));
     tempFolder += "\\HCMS";
     return tempFolder;
 }