public void TestDiscoverSimpleParaTCs2()
        {
            string fileName = TESTFILE_DIR + "TestDiscoverParaStyles2.doc";
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttTC = docText.GetUniqueTextType(ContentType.TrackChange);
            Assert.IsNotNull(ttTC, "we unexpectedly found no track changes");

            Assert.AreEqual(5, ttTC.Count, "Expected to get 5 separate track change items");

            Assert.AreEqual("Style", ttTC.Nodes[0].GetInfo("Type")[0].value);
            Assert.AreEqual("Workshare", ttTC.Nodes[0].GetInfo("Author")[0].value);
            Assert.AreEqual("Paragraph 1\r", ttTC.Nodes[0].GetInfo("Content")[0].value);

            Assert.AreEqual("Paragraph Property", ttTC.Nodes[1].GetInfo("Type")[0].value);
            Assert.AreEqual("Workshare", ttTC.Nodes[1].GetInfo("Author")[0].value);
            Assert.AreEqual("Paragraph 2\r", ttTC.Nodes[1].GetInfo("Content")[0].value);

            Assert.AreEqual("ListNumber", ttTC.Nodes[2].GetInfo("Type")[0].value);
            Assert.AreEqual("Workshare", ttTC.Nodes[2].GetInfo("Author")[0].value);
            Assert.AreEqual("Paragraph 3\r", ttTC.Nodes[2].GetInfo("Content")[0].value);

            Assert.AreEqual("Paragraph Property", ttTC.Nodes[3].GetInfo("Type")[0].value);
            Assert.AreEqual("Workshare", ttTC.Nodes[3].GetInfo("Author")[0].value);
            Assert.AreEqual("Paragraph 4\r", ttTC.Nodes[3].GetInfo("Content")[0].value);

            Assert.AreEqual("ListNumber", ttTC.Nodes[4].GetInfo("Type")[0].value);
            Assert.AreEqual("Workshare", ttTC.Nodes[4].GetInfo("Author")[0].value);
            Assert.AreEqual("Paragraph 5\r", ttTC.Nodes[4].GetInfo("Content")[0].value);
        }
Example #2
0
        protected void TestCleanTextTypeFromDocument(string fileName, ContentType contentType, string[] textThatShouldntBeCleaned)
        {
            fileName = TESTFILE_DIR + fileName;
            string outFileName = fileName + "_cleaned.doc";
            File.Copy(fileName, outFileName, true);
            using (Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(outFileName, true))
            {
                docReader.Clean(BuildContentTypeList(contentType));
            }

            using (WordDocumentReader docReader2 = new WordDocumentReader(outFileName, false))
            {
                DocumentText dt = docReader2.Read();

                IAbstractTextType tt = dt.GetUniqueTextType(contentType);
                IAbstractTextType ttHid = dt.GetUniqueTextType(ContentType.HiddenText);
                if (tt == null && ttHid == null)
                {
                    CheckHaventCleanedTooMuch(dt.GetUniqueTextType(ContentType.Paragraph), textThatShouldntBeCleaned);

                    return;
                }

                if (tt != null)
                    Assert.AreEqual(0, tt.Nodes.Count, "Expected all the items of type " + contentType.ToString() + " to have been cleaned");

                if (ttHid != null)
                    Assert.AreEqual(0, ttHid.Nodes.Count, "Expected no significant hidden text to show up");


            }
        }
        private void TestCleanTCsFromDocument(string fileName, bool checkHiddenText)
        {
            string outFileName = fileName + "_cleaned.doc";
            File.Copy(fileName, outFileName, true);
            using (Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(outFileName, true))
            {
                docReader.Clean(BuildContentTypeList(ContentType.TrackChange));
            }

            using (WordDocumentReader docReader2 = new WordDocumentReader(outFileName, false))
            {
                DocumentText dt = docReader2.Read();

                IAbstractTextType tt = dt.GetUniqueTextType(ContentType.TrackChange);
                IAbstractTextType ttHid = dt.GetUniqueTextType(ContentType.HiddenText);
                if (tt == null && ttHid == null)
                    return;

                if (tt != null)
                    Assert.AreEqual(0, tt.Nodes.Count, "Expected all the track changes to have been cleaned");

                if (checkHiddenText)
                {
                    if (ttHid != null)
                        Assert.AreEqual(0, ttHid.Nodes.Count, "Expected no significant hidden text to show up");
                }


            }
        }
        public override void Execute(WorkItem workItem)
        {
            try
            {
                m_workItem = workItem;
                DocumentText dtCheck;
                switch (workItem.Extension)
                {
                    case "doc":
                        WordDocumentReader wrdRdr = new WordDocumentReader(workItem.BaseFileName);
                        try
                        {
                            dtCheck = wrdRdr.Read();
                        }
                        catch (Exception)
                        {
                            return; // failed to discover source document
                        }
                        CompareDiscoveryForDoc(workItem.BaseFileName, workItem.DiscoveredText, dtCheck);
                        break;

                    case "ppt":
                        PptDocumentReader pptRdr = new PptDocumentReader(workItem.BaseFileName);
                        try
                        {
                            dtCheck = pptRdr.Read();
                        }
                        catch (Exception)
                        {
                            return; // failed to discover source document
                        }
                        CompareDiscoveryForPpt(workItem.BaseFileName, workItem.DiscoveredText, dtCheck);
                        break;

                    case "xls":
                        ExcelDocumentReader xlsRdr = new ExcelDocumentReader(workItem.BaseFileName);
                        try
                        {
                            dtCheck = xlsRdr.Read();
                        }
                        catch (Exception)
                        {
                            return; // failed to discover source document
                        }
                        CompareDiscoveryForXls(workItem.BaseFileName, workItem.DiscoveredText, dtCheck);
                        break;

                    default:
                        throw new Exception("File extension not expected : " + workItem.Extension);
                }
            }
            catch (Exception e)
            {
                workItem.FailureMode = FailureMode.DiscoveryMismatch;
                throw e;
            }
        }
Example #5
0
        protected static IAbstractTextType GetDiscoveredTextType(string fileName, ContentType contentType)
        {
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(TESTFILE_DIR + fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttresult = docText.GetUniqueTextType(contentType);
            Assert.IsNotNull(ttresult, "we unexpectedly found no text of content type " + contentType.ToString());

            return ttresult;
        }
        public void TestDiscoverSmallTextWithParaCharInteractionAndMultiPara_tc1()
        {
            string fileName = TESTFILE_DIR + "MultiParaSmallText_tracked_1.doc";

            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttST = docText.GetUniqueTextType(ContentType.SmallText);
            Assert.IsNotNull(ttST, "we unexpectedly found no small text");

            Assert.AreEqual(1, ttST.Count, "Expected to get 1 separate small text items");
            Assert.AreEqual("but this large", ttST.Nodes[0].GetInfo("Content")[0].value);

        }
        private void CleanFile(string fileName, List<ContentType> listContentTypes, List<Exclusion> listExclusion)
        {
            try
            {
                using (WordDocumentReader wrdReader = new WordDocumentReader(fileName, true))
                {
                    wrdReader.Clean(listContentTypes, listExclusion);
                }
            }
            catch (System.Exception ex)
            {
                Logger.LogError("Word Binary cleaning failed");
				Logger.LogError(ex);
                throw;
            }
        }
        public void TestDiscoverSmallTextWithParaCharInteractionAndMultiPara()
        {
            string fileName = TESTFILE_DIR + "MultiParaSmallText.doc";

            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttST = docText.GetUniqueTextType(ContentType.SmallText);
            Assert.IsNotNull(ttST, "we unexpectedly found no hidden text");

            Assert.AreEqual(4, ttST.Count, "Expected to get 4 separate small text items");
            Assert.AreEqual("This is in small ", ttST.Nodes[0].GetInfo("Content")[0].value);
            Assert.AreEqual(" and more small\r", ttST.Nodes[1].GetInfo("Content")[0].value);
            Assert.AreEqual("An entirely small para\r", ttST.Nodes[2].GetInfo("Content")[0].value);
            Assert.AreEqual("And another\r", ttST.Nodes[3].GetInfo("Content")[0].value);

        }
        public override bool VerifyFile(TempFileForActions tempFile)
        {
            try
            {
                using (WordDocumentReader reader = new WordDocumentReader(tempFile.TempFile, true))
                {
                    reader.Read();
                    return true;
                }
            }
            catch (System.Exception ex)
            {
                Logger.LogError("Word Verification failed");
				Logger.LogError(ex);
            }
            return false;
        }
        public void TestDiscoverHiddenTextWithHierarchichalStyles()
        {
            string fileName = TESTFILE_DIR + "HierarchicalHiddenStyles.doc";
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttHT = docText.GetUniqueTextType(ContentType.HiddenText);
            Assert.IsNotNull(ttHT, "we unexpectedly found no hidden text");

            Assert.AreEqual(5, ttHT.Count, "Expected to get 5 separate hidden text items");

            Assert.AreEqual("Hidden style\r", ttHT.Nodes[0].GetInfo("Content")[0].value);
            Assert.AreEqual("Double opposite style\r", ttHT.Nodes[1].GetInfo("Content")[0].value);
            Assert.AreEqual("HiddenChar style\r", ttHT.Nodes[2].GetInfo("Content")[0].value);
            Assert.AreEqual("2Oppos ", ttHT.Nodes[3].GetInfo("Content")[0].value);
            Assert.AreEqual(" hidden", ttHT.Nodes[4].GetInfo("Content")[0].value);

        }
Example #11
0
        public void TestQuickDiscovery()
        {
            string fileName = TESTFILE_DIR + "Simple.doc";
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttHidden = docText.GetUniqueTextType(ContentType.HiddenText);

            foreach (IAbstractTextNode tn in ttHidden)
            {
                foreach (NodeInfo ni in tn.GetInfo("Content"))
                {
                    if (ni.value == "Some hidden text\r")
                        return;
                }
            }

            Assert.Fail("Did not find expected hidden text");
        }
        public void TestDiscoverTableChanges()
        {
            string fileName = TESTFILE_DIR + "TestTableTCs.doc";
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttTC = docText.GetUniqueTextType(ContentType.TrackChange);
            Assert.IsNotNull(ttTC, "we unexpectedly found no track changes");

            Assert.AreEqual(7, ttTC.Count, "Expected to get 7 separate track change items");

            Assert.AreEqual("Table Properties", ttTC.Nodes[1].GetInfo("Type")[0].value);
            Assert.AreEqual("Table Properties", ttTC.Nodes[6].GetInfo("Type")[0].value);

        }
Example #13
0
        public DocumentText DiscoverDocument(string sFilename)
        {
            switch (m_ft)
            {
                case Workshare.Policy.FileType.WordDocument:
                    using (WordDocumentReader Word2003Reader1 = new WordDocumentReader(sFilename, false))
                    {
                        return Word2003Reader1.Read();
                    }

                case Workshare.Policy.FileType.ExcelSheet:
                    using (ExcelDocumentReader Excel2003Reader1 = new ExcelDocumentReader(sFilename, false))
                    {
                        return Excel2003Reader1.Read();
                    }

                case Workshare.Policy.FileType.PowerPoint:
                    using (Workshare.FCS.Lite.PptDocumentReader Ppt2003Reader1 = new PptDocumentReader(sFilename, false))
                    {
                        return Ppt2003Reader1.Read();
                    }

                default:
                    break;
            }
            return null;
        }
        public void TestDiscoverCharFormattingTCs()
        {
            string fileName = TESTFILE_DIR + "DiscoverCharTCs.doc";
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttTC = docText.GetUniqueTextType(ContentType.TrackChange);
            Assert.IsNotNull(ttTC, "we unexpectedly found no track changes");

            Assert.AreEqual(9, ttTC.Count, "Expected to get 9 separate track change items");

            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual("Property", ttTC.Nodes[i].GetInfo("Type")[0].value);
            }
        }
Example #15
0
        public void DoBinaryClean(List<ContentType> listContentTypes)
        {
            switch (m_ft)
            {
                case Workshare.Policy.FileType.WordDocument:
                    using (WordDocumentReader Word2003Reader1 = new WordDocumentReader(m_filenameIn, true))
                    {
                        Word2003Reader1.Clean(listContentTypes);
                    }
                    break;

                case Workshare.Policy.FileType.ExcelSheet:
                    using (ExcelDocumentReader Excel2003Reader1 = new ExcelDocumentReader(m_filenameIn, true))
                    {
                        Excel2003Reader1.Clean(listContentTypes);
                    }
                    break;

                case Workshare.Policy.FileType.PowerPoint:
                    using (Workshare.FCS.Lite.PptDocumentReader Ppt2003Reader1 = new PptDocumentReader(m_filenameIn, true))
                    {
                        Ppt2003Reader1.Clean(listContentTypes);
                    }
                    break;

                default:
                    break;
            }
        }
        public void TestDiscoverListnumChanges()
        {
            string fileName = TESTFILE_DIR + "ChangesToListNums.doc";
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttTC = docText.GetUniqueTextType(ContentType.TrackChange);
            Assert.IsNotNull(ttTC, "we unexpectedly found no track changes");

            Assert.AreEqual(2, ttTC.Count, "Expected to get 2 separate track change items");


            Assert.AreEqual("Insertion", ttTC.Nodes[0].GetInfo("Type")[0].value);
            Assert.AreEqual("Workshare", ttTC.Nodes[0].GetInfo("Author")[0].value);
            Assert.AreEqual("two and a half\r", ttTC.Nodes[0].GetInfo("Content")[0].value);

            Assert.AreEqual("ListNumber", ttTC.Nodes[1].GetInfo("Type")[0].value);
            Assert.AreEqual("Workshare", ttTC.Nodes[1].GetInfo("Author")[0].value);
            Assert.AreEqual("two and a half\r", ttTC.Nodes[1].GetInfo("Content")[0].value);

        }
Example #17
0
        /// <summary>
        /// </summary>
        /// <returns>A FCS.Lite.DocumentText object</returns>
        public FCS.Lite.Base.DocumentText AdvancedRead()
        {
            if (m_docText == null)
            {
                FCS.Lite.Base.DocumentReader docReader;

                switch (m_fileData.FileType)
                {
                    case FileType.WordDocument:
                        docReader = new WordDocumentReader(m_fileData.BinaryFileData);
                        break;
                    case FileType.PowerPoint:
                        docReader = new PptDocumentReader(m_fileData.BinaryFileData);
                        break;
                    case FileType.ExcelSheet:
                        docReader = new ExcelDocumentReader(m_fileData.BinaryFileData);
                        break;
                    case FileType.WordDocumentX:
                    case FileType.WordDocumentMacroX:
                    case FileType.WordDocumentTemplateX:
                    case FileType.WordDocumentMacroTemplateX:
                        docReader = new DocxDocumentReader(m_fileData.BinaryFileData);
                        break;
                    case FileType.PowerPointX:
                    case FileType.PowerPointMacroX:
                    case FileType.PowerPointTemplateX:
                    case FileType.PowerPointMacroTemplateX:
					case FileType.PowerPointShowX:
					case FileType.PowerPointMacroShowX:
                        docReader = new PptxDocumentReader(m_fileData.BinaryFileData);
                        break;
                    case FileType.ExcelSheetX:
                    case FileType.ExcelSheetMacroX:
                    case FileType.ExcelSheetTemplateX:
					case FileType.ExcelSheetMacroTemplateX:
						docReader = new XlsxDocumentReader(m_fileData.BinaryFileData);
						break;
					case FileType.PDFDocument:
						docReader = new PdfDocumentReader(m_fileData.BinaryFileData);
						break;
					default:
                        return m_docText;
                }

                using (docReader)
                {
                    m_docText = docReader.Read();
                }
            }
            return m_docText;
        }
		DocumentText DiscoverDocument(string sFilename)
		{
			switch (m_ft)
			{
				case Workshare.Policy.FileType.WordDocument:
					using (WordDocumentReader Word2003Reader1 = new WordDocumentReader(sFilename, false))
					{
						return Word2003Reader1.Read();
					}

				case Workshare.Policy.FileType.ExcelSheet:
					using (ExcelDocumentReader Excel2003Reader1 = new ExcelDocumentReader(sFilename, false))
					{
						return Excel2003Reader1.Read();
					}

				case Workshare.Policy.FileType.PowerPoint:
					using (Workshare.FCS.Lite.PptDocumentReader Ppt2003Reader1 = new PptDocumentReader(sFilename, false))
					{
						return Ppt2003Reader1.Read();
					}

				case Workshare.Policy.FileType.WordDocumentX:
				case Workshare.Policy.FileType.WordDocumentMacroX:
				case Workshare.Policy.FileType.WordDocumentTemplateX:
				case Workshare.Policy.FileType.WordDocumentMacroTemplateX:
					using (DocxDocumentReader Word2007Reader1 = new DocxDocumentReader(sFilename))
					{
						return Word2007Reader1.Read();
					}

				case Workshare.Policy.FileType.ExcelSheetX:
				case Workshare.Policy.FileType.ExcelSheetMacroX:
				case Workshare.Policy.FileType.ExcelSheetTemplateX:
				case Workshare.Policy.FileType.ExcelSheetMacroTemplateX:
					using (XlsxDocumentReader Excel2007Reader1 = new XlsxDocumentReader(sFilename))
					{
						return Excel2007Reader1.Read();
					}

				case Workshare.Policy.FileType.PowerPointX:
				case Workshare.Policy.FileType.PowerPointMacroX:
				case Workshare.Policy.FileType.PowerPointTemplateX:
				case Workshare.Policy.FileType.PowerPointMacroTemplateX:
				case Workshare.Policy.FileType.PowerPointShowX:
				case Workshare.Policy.FileType.PowerPointMacroShowX:
					using (PptxDocumentReader Ppt2007Reader1 = new PptxDocumentReader(sFilename))
					{
						return Ppt2007Reader1.Read();
					}
				default:
					break;
			}
			return null;
		}
        public void TestDontDiscoverListNumTCsWhereTheyDontExist()
        {
            string fileName = TESTFILE_DIR + "AppSpec.doc";
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttTC = docText.GetUniqueTextType(ContentType.TrackChange);
            if (ttTC == null)
                return; // all well

            Assert.AreEqual(0, ttTC.Count, "Expected to get no track change items");

        }
		/// <summary>
		/// Original incarnation of lightspeed clean method. Left for comparison. There is at least one document that gets corrupted by the
		/// lightspeed clean user action as opposed to the method below. see Rally DE8912 in Professional & Deltaview project.
		/// </summary>
		/// <param name="listContentTypes"></param>
		private void DoLightSpeedClean(List<ContentType> listContentTypes)
		{
			System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
			watch.Start();
			switch (m_ft)
			{
				case Workshare.Policy.FileType.WordDocument:
					using (WordDocumentReader Word2003Reader1 = new WordDocumentReader(m_sFileForBinClean, true))
					{
						Word2003Reader1.Clean(listContentTypes);
					}
					break;

				case Workshare.Policy.FileType.ExcelSheet:
					using (ExcelDocumentReader Excel2003Reader1 = new ExcelDocumentReader(m_sFileForBinClean, true))
					{
						Excel2003Reader1.Clean(listContentTypes);
					}
					break;

				case Workshare.Policy.FileType.PowerPoint:
					using (Workshare.FCS.Lite.PptDocumentReader Ppt2003Reader1 = new PptDocumentReader(m_sFileForBinClean, true))
					{
						Ppt2003Reader1.Clean(listContentTypes);
					}
					break;


				case Workshare.Policy.FileType.WordDocumentX:
				case Workshare.Policy.FileType.WordDocumentMacroX:
				case Workshare.Policy.FileType.WordDocumentTemplateX:
				case Workshare.Policy.FileType.WordDocumentMacroTemplateX:
					{
						string outFileName = System.IO.Path.GetTempFileName();
						using (DocxDocumentReader Word2007Reader1 = new DocxDocumentReader(m_sFileForBinClean))
						{
							using (Stream outStr = File.Open(outFileName, FileMode.Create))
							{

								Word2007Reader1.CleanTo(outStr, listContentTypes);
							}
						}
						File.Copy(outFileName, m_sFileForBinClean, true);
						File.Delete(outFileName);
						break;
					}

				case Workshare.Policy.FileType.ExcelSheetX:
				case Workshare.Policy.FileType.ExcelSheetMacroX:
				case Workshare.Policy.FileType.ExcelSheetTemplateX:
				case Workshare.Policy.FileType.ExcelSheetMacroTemplateX:
					{
						string outFileName = System.IO.Path.GetTempFileName();
						using (XlsxDocumentReader Excel2007Reader1 = new XlsxDocumentReader(m_sFileForBinClean))
						{
							using (Stream outStr = File.Open(outFileName, FileMode.Create))
							{

								Excel2007Reader1.CleanTo(outStr, listContentTypes);
							}
						}
						File.Copy(outFileName, m_sFileForBinClean, true);
						File.Delete(outFileName);
						break;
					}

				case Workshare.Policy.FileType.PowerPointX:
				case Workshare.Policy.FileType.PowerPointMacroX:
				case Workshare.Policy.FileType.PowerPointTemplateX:
				case Workshare.Policy.FileType.PowerPointMacroTemplateX:
				case Workshare.Policy.FileType.PowerPointShowX:
				case Workshare.Policy.FileType.PowerPointMacroShowX:
					{
						string outFileName = System.IO.Path.GetTempFileName();
						using (PptxDocumentReader Ppt2007Reader1 = new PptxDocumentReader(m_sFileForBinClean))
						{
							using (Stream outStr = File.Open(outFileName, FileMode.Create))
							{

								Ppt2007Reader1.CleanTo(outStr, listContentTypes);
							}
						}
						File.Copy(outFileName, m_sFileForBinClean, true);
						File.Delete(outFileName);
						break;
					}

				default:
					break;
			}
			watch.Stop();
			m_binCleanTime = watch.Elapsed.TotalSeconds;
		}
        public void TestDiscover2TableChangesInSameTable()
        {
            string fileName = TESTFILE_DIR + "2TableTCsInOneTable.doc";
            Workshare.FCS.Lite.WordDocumentReader docReader = new WordDocumentReader(fileName);
            DocumentText docText = docReader.Read();

            IAbstractTextType ttTC = docText.GetUniqueTextType(ContentType.TrackChange);
            Assert.IsNotNull(ttTC, "we unexpectedly found no track changes");

            Assert.AreEqual(2, ttTC.Count, "Expected to get 2 separate track change items");

            foreach (IAbstractTextNode node in ttTC.Nodes)
            {
                Assert.AreEqual("Table Properties", node.GetInfo("Type")[0].value);
            }
        }