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();
     }
 }
Ejemplo n.º 2
0
		private void AddProperty(string key, CleanPropertiesDisplayTranslator displayer, Type dataType, PropertyDisplayType displayType, bool visible, bool allowOverride, object value, bool readOnly)
		{
			string name = (displayer == null ? key : displayer.GetDisplayType(key));
			ActionProperty property = new ActionProperty(name, dataType, displayType, visible, allowOverride, value, readOnly);
			Add(key, property);
		}
Ejemplo n.º 3
0
		private void AddInvisibleProperty(string key, CleanPropertiesDisplayTranslator displayer, bool value, bool readOnly)
		{
			AddProperty(key, displayer, typeof(bool), PropertyDisplayType.Checkbox, false, false, value, readOnly);
		}
Ejemplo n.º 4
0
		private void AddProperty(string key, CleanPropertiesDisplayTranslator displayer, string value, bool readOnly)
		{
			AddProperty(key, displayer, typeof(string), PropertyDisplayType.TextBox, true, true, value, readOnly);
		}
		/// <summary>
		/// Converts a stream from a .doc file back to its original format
		/// </summary>
		private static Stream ConvertFromDoc(TempFileForActions tempFile, string originalFileName, string originalDisplayName, IDictionary<string, string> streamProperties, CleanPropertiesDisplayTranslator strings)
		{
			string dstPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + Path.GetExtension(originalFileName));
			Stream convertedStream;
			try
			{
				using (FileStream fs = new FileStream(tempFile.TempFile, FileMode.Open, FileAccess.Read))
				{
					DocConverterCache.ConvertToRtf(fs, tempFile.TempFile, dstPath);
				}
				convertedStream = new MemoryStream(File.ReadAllBytes(dstPath));

				streamProperties[strings.StrmProp_FileName] = originalFileName;
				streamProperties[strings.StrmProp_DisplayName] = originalDisplayName;
			}
			finally
			{
				File.Delete(dstPath);
			}
			return convertedStream;
		}
		/// <summary>
		/// Converts a stream into a .doc file
		/// </summary>
		private static Stream ConvertToDoc(Stream input, IDictionary<string, string> streamProperties, CleanPropertiesDisplayTranslator strings)
		{
			string displayName = streamProperties[strings.StrmProp_DisplayName];
			string fileName = streamProperties[strings.StrmProp_FileName];
			string dstPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".doc");
			try
			{
				fileName = Path.ChangeExtension(fileName, ".doc");
				displayName = Path.ChangeExtension(displayName, ".doc");

				streamProperties[strings.StrmProp_FileName] = fileName;
				streamProperties[strings.StrmProp_DisplayName] = displayName;

				DocConverterCache.ConvertToDoc(input, displayName, dstPath);
				input.Dispose();
				return new MemoryStream(File.ReadAllBytes(dstPath));
			}
			finally
			{
				File.Delete(dstPath);
			}
		}
		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);
			}
		}