public override void RemoveMetadata(TempFileForActions tempFile, CleanActionPropertySet cleanProperties)
        {
            try
            {
                m_elementsToClean = GetListOfEnabledElementsToClean(cleanProperties);
                List<Exclusion> listExclusion = GetListOfExcludedElements(cleanProperties);
                using (BinaryData bData = new BinaryData(tempFile.GetMemoryStream()))
                {
                    using (PptxDocumentReader reader = new PptxDocumentReader(bData))
                    {
                        using (Stream str = GetOutputStream())
                        {
                            reader.CleanTo(str, m_elementsToClean, listExclusion);
                            File.Copy(InterimTempFileName, tempFile.TempFile, true);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Logger.LogError("PowerpointX cleaning failed");
                Logger.LogError(ex);
				throw;
            }
            finally
            {
                CleanUp();
            }
        }
Ejemplo n.º 2
0
        private void ExecuteUsingOfficeOpenXml(TempFileForActions tempFile, CleanActionPropertySet elementsToClean)
        {
            try
            {
                m_elementsToClean = GetElementsNotRemovedByDomClean(GetListOfEnabledElementsToClean(elementsToClean));
                using (BinaryData bData = new BinaryData(tempFile.GetMemoryStream()))
                {
                    using (XlsxDocumentReader reader = new XlsxDocumentReader(bData))
                    {
                        using (Stream str = GetOutputStream())
                        {
                            reader.CleanTo(str, m_elementsToClean);
                            File.Copy(InterimTempFileName, tempFile.TempFile, true);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
				Logger.LogError(ex);
				throw;
            }
            finally
            {
                CleanUp();
            }
        }
Ejemplo n.º 3
0
 private Stream CallCleanThread(BinaryCleanActionPropertySet cleanProperties, Stream input, ref Dictionary<string, string> streamProperties, CleanPropertiesDisplayTranslator strings)
 {
     string filename = streamProperties[strings.StrmProp_DisplayName];
     using (TempFileForActions tempFile = new TempFileForActions(System.IO.Path.GetFileName(filename), input))
     {
         CleanData cleanData = new CleanData(cleanProperties, tempFile);
         Thread staThread = new Thread(new ParameterizedThreadStart(DoClean));
         staThread.SetApartmentState(ApartmentState.STA);
         staThread.Start(cleanData);
         staThread.Join();
         if (cleanData.ex != null)
             throw cleanData.ex;
         input.Dispose(); // Clean it out of memory
         return tempFile.GetMemoryStream();
     }
 }
        public override bool VerifyFile(TempFileForActions tempFile)
        {
            try
            {
                using (BinaryData bData = new BinaryData(tempFile.GetMemoryStream()))
                {
                    PptxDocumentReader reader = new PptxDocumentReader(bData);
                    reader.Read();
                }
                return true;
            }
            catch (System.Exception ex)
            {
                Logger.LogError("PowerpointX Verification failed");
				Logger.LogError(ex);
            }
            return false;
        }
		private Stream CallCleanThread(CleanActionPropertySet cleanProperties, Stream input, ref Dictionary<string, string> streamProperties, CleanPropertiesDisplayTranslator strings, bool callingFallbackThread, bool convertFile)
		{
			string originalDisplayName = streamProperties[strings.StrmProp_DisplayName];
			string originalFileName = streamProperties[strings.StrmProp_FileName];

			convertFile = (InstalledProduct.IsProtectEnterpriseClientInstalled() || InstalledProduct.IsProfessionalInstalled()) && FcsFile.IsRtfFile(input);
			if (convertFile)
			{
				input = ConvertToDoc(input, streamProperties, strings);
			}

			string displayName = streamProperties[strings.StrmProp_DisplayName];

			using (TempFileForActions tempFile = new TempFileForActions(Path.GetFileName(displayName), input))
			{
				CleanData cleanData = new CleanData(cleanProperties, tempFile);
				Thread staThread;
				if (callingFallbackThread)
				{
					staThread = new Thread(DoFallbackClean);
					staThread.Name = MethodBase.GetCurrentMethod().DeclaringType.Name + ".DoFallbackClean";
				}
				else
				{
					staThread = new Thread(DoClean);
					staThread.Name = MethodBase.GetCurrentMethod().DeclaringType.Name + ".DoClean";
				}
				staThread.SetApartmentState(ApartmentState.STA);
				staThread.Start(cleanData);
				staThread.Join();
				if (cleanData.ex != null)
				{
					//IActionProperty iap = null;

					if (callingFallbackThread || RunningInServerCtxt(cleanProperties))
					{
						m_fallbackTried = false;
						input.Dispose();
						throw cleanData.ex;
					}
					cleanData.ex = null;
					return CallCleanThread(cleanProperties, input, ref streamProperties, strings, true, convertFile);
				}

				input.Dispose();

				if (!convertFile)
				{
					return tempFile.GetMemoryStream();
				}
				return ConvertFromDoc(tempFile, originalFileName, originalDisplayName, streamProperties, strings);
			}
		}