Пример #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 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));
        }
Пример #3
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)
        }
Пример #4
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;
        }
 /// <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);
 }