예제 #1
0
        public static void Main(string[] args)
        {
            // ensure path to file is absolute, not relative
            string filename = args[0];
            if (!Path.IsPathRooted(filename))
                filename = Path.Combine(Environment.CurrentDirectory, filename);

            OfficeCleaner c = new OfficeCleaner();

            // set up to redact only fields and comments
            c.ExcludedMetadataTypes.Fill();// Exclude cleaning of all metadata types
            c.ExcludedMetadataTypes.Remove(MetadataType.Comment); // re-enable cleaning of desired types
            c.ExcludedMetadataTypes.Remove(MetadataType.Field);

            // exclude cleaning of certain field types
            c.ExcludedFieldTypes.Add(CommonFieldType.Numbering);
            c.ExcludedFieldTypes.Add(CommonFieldType.Formula);
            c.ExcludedFieldTypes.Add(CommonFieldType.Reference);

            string targetFileName = Path.GetTempFileName();

            c.CleanFileTo(filename, targetFileName);
        }
예제 #2
0
 public void TestSimpleCleanTo()
 {
     string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.docx");
     using (TempFile tf = new TempFile(testDoc))
     {
         using (TempFile dest = new TempFile())
         {
             File.Delete(dest.FilePath);
             string initialHash = tf.MD5Sum;
             IOfficeCleaner c = new OfficeCleaner();
             c.CleanFileTo(tf.FilePath, dest.FilePath);
             Assert.IsTrue(File.Exists(dest.FilePath), "We expected the dest file to be created");
             string newHash = dest.MD5Sum;
             Assert.AreNotEqual(initialHash, newHash, "We expected the Cleanion to change the file contents");
         }
     }
 }
예제 #3
0
 public void TestRelativePath3()
 {
     string outputDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\output.doc");
     IOfficeCleaner c = new OfficeCleaner();
     c.CleanFileTo("test.doc", outputDoc);
 }
예제 #4
0
        public void TestBadOutputFile()
        {
            string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.docx");
            using (TempFile tf = new TempFile(testDoc))
            {
                OfficeCleaner r = new OfficeCleaner();
                try
                {
                    r.CleanFileTo(tf.FilePath, "q:\\blah\\no\\existy\\here.doc");
                    Assert.Fail("We expected not to get here - should have thrown an exception");
                }
                catch (Exception e)
                {
                    //Assert.IsInstanceOf(typeof(IOException), e);
                }
            }

        }
예제 #5
0
        public void TestLockedOutputFile()
        {
            string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.docx");
            using (TempFile tf = new TempFile(testDoc))
            {
                using (TempFile dest = new TempFile())
                {
                    using (Stream s = File.Open(dest.FilePath, FileMode.Open, FileAccess.ReadWrite))
                    {
                        OfficeCleaner r = new OfficeCleaner();
                        try
                        {
                            r.CleanFileTo(tf.FilePath, dest.FilePath);
                            Assert.Fail("We expected not to get here - should have thrown an exception");
                        }
                        catch (Exception e)
                        {
                            //Assert.IsInstanceOf(typeof(IOException), e);
                        }
                    }
                }
            }

        }
예제 #6
0
        public void TestMissingInputFile()
        {
            string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\i_do_not_exist.docx");
            using (TempFile dest = new TempFile())
            {
                File.Delete(dest.FilePath);
                OfficeCleaner r = new OfficeCleaner();
                try
                {
                    r.CleanFileTo(testDoc, dest.FilePath);
                    Assert.Fail("We expected not to get here - should have thrown an exception");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOf(typeof(FileNotFoundException), e);
                }
                Assert.IsFalse(File.Exists(dest.FilePath), "We expected the dest file not to be created");
            }

        }
예제 #7
0
        public void TestCleanToWithPPTApp()
        {
            return;

			Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();

            try
            {
                AppCountMonitor monitor = new AppCountMonitor("powerpnt");
                string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.ppt");
                using (TempFile tf = new TempFile(testDoc))
                {
                    using (TempFile dest = new TempFile())
                    {
                        File.Delete(dest.FilePath);
                        string initialHash = tf.MD5Sum;
                        IOfficeCleaner c = new OfficeCleaner();
                        c.CleanFileTo(tf.FilePath, dest.FilePath, app);
                        Assert.IsTrue(File.Exists(dest.FilePath), "We expected the dest file to be created");
                        string newHash = dest.MD5Sum;
                        Assert.AreNotEqual(initialHash, newHash, "We expected the Cleanion to change the file contents");
                    }
                }
                Assert.IsFalse(monitor.SeenMoreInstances(), "Additional instances of PowerPoint were created during the test run - that means it didn't use the provided instance");
            }
            finally
            {
                object oFalse = false;
                app.Quit();
				Marshal.ReleaseComObject(app);
            }
        }