Ejemplo n.º 1
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();
     }
 }
		internal void DoAsposeProcess(CleanData cleanData)
		{
			bool bDoc = true;
			IActionProperty ap;
			CleanPropertiesDisplayTranslator strings = CleanPropertiesDisplayTranslator.Instance;
			if (cleanData.cleanProperties.SystemProperties.TryGetValue(strings.SysProp_FileType, out ap))
			{
				string stype = (string) ap.Value;
				if (stype != ".doc")	// no need for tolower(), as we set this
				{
					bDoc = false;
				}
			}

			bool bHasFootnotes = false;
			if (cleanData.cleanProperties.ContainsKey(CleanOption.Footnotes))
			{
				bHasFootnotes = (bool) cleanData.cleanProperties[CleanOption.Footnotes].Value;
			}

			bool bHasComments = false;
			if (cleanData.cleanProperties.ContainsKey(CleanOption.Comments))
			{
				bHasComments = (bool) cleanData.cleanProperties[CleanOption.Comments].Value;
			}

			// if cleaning included footnotes or comments then Aspose.Words.Load(cleanData.tempFile) and Aspose.Words.Save(cleanData.tempFile)
			// we have NOT done doc discovery so do not know if doc includes those things. so: quicker to discover or just do? [as might end up doing both]
			// it is actually jolly very fast (< 1 sec for 100 page doc)
			if (bDoc && (bHasFootnotes || bHasComments))
			{
				Aspose.Words.License lic = new Aspose.Words.License();
				lic.SetLicense("Aspose.Total.lic");
				Aspose.Words.Document doc = new Aspose.Words.Document(cleanData.tempFile.TempFile);
				doc.Save(cleanData.tempFile.TempFile);
			}
		}
Ejemplo n.º 3
0
		private static void RunCleanThread(CleanData cleanData)
		{
			Thread staThread = new Thread(DoClean);
			staThread.Name = MethodBase.GetCurrentMethod().DeclaringType.Name + "." + MethodBase.GetCurrentMethod().Name;
			staThread.SetApartmentState(ApartmentState.STA);
			staThread.Start(cleanData);
			staThread.Join();
			if (cleanData.Error != null)
			{
                throw cleanData.Error;
			}
		}
		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);
			}
		}