Example #1
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();
            }
        }
        public static RTDocument PPT2RTDwithSVG(string pptFilename)
        {
            //Pri2: Investigate where BasePath is and where we should be putting it in more depth.
            //      Concerned that we're creating directories there that never get cleaned up...
            if (!Directory.Exists(tfc.BasePath))
            {
                Directory.CreateDirectory(tfc.BasePath);
            }
            // Initialize PowerPoint app
            ApplicationClass ppt = new ApplicationClass();

            ppt.Visible = MsoTriState.msoTrue;

            // Open the PPT file
            Presentation presentation = ppt.Presentations.Open(pptFilename, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
            PrintOptions po           = presentation.PrintOptions;

            po.ActivePrinter = @"SVGmaker";
            System.Threading.Thread.Sleep(6000);
            po.OutputType        = PpPrintOutputType.ppPrintOutputSlides;
            po.PrintInBackground = MsoTriState.msoFalse;
            Slides slides = presentation.Slides;

            // Set up the document
            RTDocument rtDoc = new RTDocument();

            rtDoc.Identifier       = Guid.NewGuid();
            rtDoc.Metadata.Title   = GetPresentationProperty(ppt.ActivePresentation, "Title");
            rtDoc.Metadata.Creator = GetPresentationProperty(ppt.ActivePresentation, "Author");

            //Iterate through the pages
            foreach (Slide s in slides)
            {
                // Set the page properties
                Page p = new Page();
                p.Identifier = Guid.NewGuid();
                p.Extension  = GetSlideSVG(presentation, s);
                p.MimeType   = "image/svg"; // TODO: look up the real value for this
                rtDoc.Resources.Pages.Add(p.Identifier, p);

                // Set the TOCNode properties for the page
                TOCNode tn = new TOCNode();
                tn.Title              = GetSlideTitle(s);
                tn.Resource           = p;
                tn.ResourceIdentifier = p.Identifier;
                // TODO: Insert thumbnail? (tn.thumbnail)
                rtDoc.Organization.TableOfContents.Add(tn);
            }

            // Close PPT
            presentation.Close();
            if (ppt.Presentations.Count == 0)
            {
                ppt.Quit();
            }
            ppt = null;

            tfc.Delete();

            return(rtDoc);
        }
Example #3
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();
		}
Example #4
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();
        }
Example #5
0
        public static RTDocument PPT2RTDocument(string pptFilename)
        {
            //Pri2: Investigate where BasePath is and where we should be putting it in more depth.
            //      Concerned that we're creating directories there that never get cleaned up...
            if (!Directory.Exists(tfc.BasePath))
            {
                Directory.CreateDirectory(tfc.BasePath);
            }
            // Initialize PowerPoint app
            ApplicationClass ppt = new ApplicationClass();

            // Open the PPT file
            Presentation presentation = ppt.Presentations.Open(pptFilename, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
            Slides       slides       = presentation.Slides;

            // Set up the document
            RTDocument rtDoc = new RTDocument();

            rtDoc.Identifier       = Guid.NewGuid();
            rtDoc.Metadata.Title   = GetPresentationProperty(presentation, "Title");
            rtDoc.Metadata.Creator = GetPresentationProperty(presentation, "Author");

            // Create shared MemoryStream to minimize mem usage
            MemoryStream ms = new MemoryStream();

            //Iterate through the pages
            int i = 0;

            foreach (Slide s in slides)
            {
                // Set the page properties
                Page p = new Page();
                p.Identifier = Guid.NewGuid();
                p.Image      = GetSlideImage(s, ms);
                if (p.Image is Metafile)
                {
                    p.MimeType = "image/x-wmf";
                }
                if (p.Image is Bitmap)
                {
                    p.MimeType = "image/png";
                }
                rtDoc.Resources.Pages.Add(p.Identifier, p);

                // TODO, slice in RegionBuilder code from Presenter work...

                // Set the TOCNode properties for the page
                TOCNode tn = new TOCNode();
                tn.Title              = GetSlideTitle(s);
                tn.Resource           = p;
                tn.ResourceIdentifier = p.Identifier;
                //Pri2: Shouldn't this be a byte[] containing the PNG stream instead of a System.Drawing.Image?
                tn.Thumbnail = RTDocumentHelper.GetThumbnailFromImage(p.Image);
                rtDoc.Organization.TableOfContents.Add(tn);
                i++;
            }

            // Close PPT
            presentation.Close();
            if (ppt.Presentations.Count == 0)
            {
                ppt.Quit();
            }

            ppt = null;

            tfc.Delete();

            return(rtDoc);
        }