/// <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); }
void PasteImage() { Image image = ImageHelper.GetClipboardImage(); if (image != null) { string tempFileName = Path.GetTempFileName(); File.Delete(tempFileName); tempFileName = Path.ChangeExtension(tempFileName, ".png"); tempFileCollection.AddFile(tempFileName, false); image.Save(tempFileName, System.Drawing.Imaging.ImageFormat.Png); openFile(tempFileName); } }
/// <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 } }
private static Image GetSlideImage(Slide s, MemoryStream ms) { // Export the slide to a temporary file string filename = tfc.BasePath + "\\" + Guid.NewGuid().ToString() + ".emf"; tfc.AddFile(filename, false); s.Export(filename, "EMF", 0, 0); // Create a Metafile from that file and serialize it for transport // Pri2: Shouldn't this just be the EMF stream bytes, more cross platform? Image image = Image.FromFile(filename); // Check for size overage and downconvert to JPG if EMF is too large // Note: By default EMF is the best, but we switch to JPG after a larger size // TODO: The max EMF size should be read from the UI or config file if (ImageSize(image, ms) > 250000) { image.Dispose(); //We can get reasonable reliability and quality by exporting wmf from PPT, then using //.Net to make jpg. Exporting directly to jpg was found to be flaky with some //PPT versions, and to result in worse quality. string wmffilename = tfc.BasePath + "\\" + Guid.NewGuid().ToString() + ".wmf"; string jpgfilename = tfc.BasePath + "\\" + Guid.NewGuid().ToString() + ".jpg"; tfc.AddFile(wmffilename, false); tfc.AddFile(jpgfilename, false); s.Export(wmffilename, "WMF", 0, 0); //Convert to jpg Image img = Image.FromFile(wmffilename); img.Save(jpgfilename, ImageFormat.Jpeg); img.Dispose(); image = Image.FromFile(jpgfilename); } return(image); }
private void backgroundWorkerScan_DoWork(object sender, DoWorkEventArgs e) { using (WiaScannerAdapter adapter = new WiaScannerAdapter()) { try { string tempFileName = Path.GetTempFileName(); File.Delete(tempFileName); tempFileName = Path.ChangeExtension(tempFileName, ".png"); tempFileCollection.AddFile(tempFileName, false); FileInfo imageFile = new FileInfo(tempFileName); if (imageFile.Exists) { imageFile.Delete(); } adapter.ScanImage(ImageFormat.Png, imageFile.FullName); e.Result = tempFileName; } catch (WiaOperationException ex) { throw new Exception(System.Text.RegularExpressions.Regex.Replace(ex.ErrorCode.ToString(), "(?=\\p{Lu}+)", " ").Trim() + "."); } } }
protected override void OnKeyDown(KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.V) { Image image = ImageHelper.GetClipboardImage(); if (image != null) { string tempFileName = Path.GetTempFileName(); File.Delete(tempFileName); tempFileName = Path.ChangeExtension(tempFileName, ".png"); tempFileCollection.AddFile(tempFileName, false); image.Save(tempFileName, ImageFormat.Png); openFile(tempFileName); e.Handled = true; } } base.OnKeyDown(e); }
private static String GetSlideSVG(Presentation pres, Slide s) { // Pxport the slide to a temporary file using SVGmaker string filename = tfc.BasePath + "\\" + Guid.NewGuid().ToString() + ".svg"; tfc.AddFile(filename, false); pres.PrintOut(s.SlideNumber, s.SlideNumber, filename, 1, MsoTriState.msoFalse); // seems to prevent any deadlocking during opening the file due to waiting for the printer System.Threading.Thread.Sleep(250); // Load data from file System.IO.StreamReader sr = new StreamReader(filename); String svg = sr.ReadToEnd(); sr.Close(); return(svg); }
void PasteImage() { BitmapSource image = ImageHelper.GetClipboardImage(); if (image != null) { string tempFileName = Path.GetTempFileName(); File.Delete(tempFileName); tempFileName = Path.ChangeExtension(tempFileName, ".png"); tempFileCollection.AddFile(tempFileName, false); using (var fileStream = new FileStream(tempFileName, FileMode.Create)) { BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(image)); encoder.Save(fileStream); } openFile(tempFileName); } }
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); } }
/// <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 } }
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(); }
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(); }