// FixTest_ProtectProcessingFile
		public string Execute(IActionData3 input, ActionPropertySet properties)
		{
			throw new NotImplementedException("Convert file to stream as input, convert stream to file as output and update displayname and file type.");
			////This mock action just copies the contents of what was passed in, then prepends 4 bytes to the stream, so that tests can check contents.
			////Alternatively it will 'abort' and leave the stream untouched.

			//if (EnableAbortOnExecute)
			//{
			//    throw new AbortActionException();
			//}
			//else
			//{
			//    Stream str = new MemoryStream();

			//    //append DEADBEEF to the start of the stream, to signal that we did some sort of work on this stream.
			//    byte[] deadbeef = STREAMSIGNALBYTES;
			//    str.Write(deadbeef, 0, deadbeef.Length);

			//    byte[] buffer = new byte[input.Content.Length];
			//    input.Content.Position = 0;
			//    input.Content.Read(buffer, 0, buffer.Length);
			//    str.Write(buffer, 0, buffer.Length);

			//    return str;
			//}
		}
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet aProperties)
        {
			if (aProperties.ContainsKey(AbortOnExecuteActionStringTable.Abort))
                throw new AbortActionException("Abort as requested");

			return data.Content;
        }
Beispiel #3
0
		static public void Merge(IActionData3 master, IActionData3 spawn, bool deleteWidows)
		{
			if (spawn == null || master == null)
				return;

			if (master.Id != spawn.Id)
				return;

			foreach (IActionData3 c in spawn.Nested)
			{

				if (!master.Nested.Contains(c))
				{
					if (c.Nested.Count == 0)//&& (!deleteWidowedNodes || c.Content != null || c.Content.Length > 0))
						master.Nested.Add(c);
				}
				else
				{
					IActionData3 localFolderCopy = master.Nested[master.Nested.IndexOf(c)] as IActionData3;
					Merge(localFolderCopy, c, false);
				}
			}

			if (deleteWidows)
				RemoveWidows(master);
		}
Beispiel #4
0
		/// <summary>
		/// The Block user action does not alter the input stream
		/// </summary>
		/// <param name="input"></param>
		/// <param name="aProperties"></param>
		/// <returns></returns>
		public string Execute(IActionData3 input, ActionPropertySet aProperties)
		{
			if (input == null)
				return null;

			return input.FileName;
		}
        public override Stream Execute(IActionData3 input, ActionPropertySet properties)
        {
            Dictionary<string, string> streamProperties = input.Properties;
            BinaryCleanActionPropertySet cleanProperties = new BinaryCleanActionPropertySet(properties);

            CleanPropertiesDisplayTranslator strings = CleanPropertiesDisplayTranslator.Instance;
            if (!streamProperties.ContainsKey(strings.StrmProp_DisplayName))
            {
                Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage("UNABLE_TO_GET_FILE_IN_STREAM", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly());
                Logger.LogError(errorMessage.LogString);
				throw new CleanUserActionException(errorMessage.DisplayString);
            }

            if (properties.SystemProperties.ContainsKey(strings.SysProp_FileType))
            {
                if (!m_supportedFiles.Supports(properties.SystemProperties[strings.SysProp_FileType].Value as string))
                {
					Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage("UNABLE_TO_CLEAN_NON_SUPPORTED_FILETYPE", "Workshare.Policy.Actions.Properties.LanguageResources", Assembly.GetExecutingAssembly());
					Logger.LogError(errorMessage.LogString);
                    return null;
                }
            }

            return CallCleanThread(cleanProperties, input.Content, ref streamProperties, strings);
        }
Beispiel #6
0
		public string Execute(IActionData3 input, ActionPropertySet properties)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append(Environment.UserDomainName);
			sb.Append(@"\\");
			sb.Append(Environment.UserName);
			sb.Append(" sent the following content: ");
			sb.Append(input.Properties["FileName"]);
			sb.Append(" on ");
			sb.Append(DateTime.Now.ToUniversalTime().ToString(CultureInfo.InvariantCulture));

			if (!(bool) properties["User Validated"].Value)
			{
				File.AppendAllText(_path + "\\Not_Verified.txt", sb.ToString());
			}
			else
			{
				sb.Append(", with verification details of: ");
				sb.Append(properties["Verfication Detail"].Value.ToString());

				File.AppendAllText(_path + "\\Verified.txt", sb.ToString());
			}

			return input.FileName;
		}
Beispiel #7
0
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties)
		{
			if (data == null)
				return null;

			return data.Content;
		}
		public string Execute(IActionData3 input, ActionPropertySet aProperties)
        {
			if (aProperties.ContainsKey(AbortOnExecuteActionStringTable.Abort))
                throw new AbortActionException("Abort as requested");
            
            return input.FileName;
        }
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties)
		{
			if (EnableAbortOnExecute)
			{
				throw new AbortActionException();
			}
			return data.Content;
		}
		public string Execute(IActionData3 input, ActionPropertySet properties)
		{
			ActionData root = input as ActionData; // shortcut
			foreach (ActionData item in root.GetAllLeafs())
			{
				item.DisplayName = "Modified-" + item.DisplayName;
			}

			root.DisplayName = "Modified-" + root.DisplayName;
			return root.FileName;
		}
Beispiel #11
0
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet aProperties)
		{
			throw new NotImplementedException();

			//try
			//{
			//    using (MimeProxy proxy = new MimeProxy(data.Content))
			//    using (Email2Mime email2Mime = new Email2Mime(proxy))
			//    {
			//        string prefixString = properties[TagMimeActionStringTable.SubjectPrefix].Value as string;

			//        if (!string.IsNullOrEmpty(prefixString))
			//        {
			//            proxy.Subject = prefixString + proxy.Subject;
			//        }

			//        bool removeAllAttachments = (bool)properties[TagMimeActionStringTable.RemoveAllAttachments].Value;
			//        if (removeAllAttachments)
			//        {
			//            proxy.Attachments.Clear();
			//        }

			//        bool insertAttachment = (bool)properties[TagMimeActionStringTable.InsertAttachment].Value;
			//        if (insertAttachment)
			//        {
			//            bool embedAttachment = (bool)properties[TagMimeActionStringTable.EmbeddedAttachment].Value;
			//            string attachmentName = properties[TagMimeActionStringTable.AttachmentName].Value as string;
			//            if (!string.IsNullOrEmpty(attachmentName))
			//            {
			//                EmailAttachment attachment = new EmailAttachment();
			//                attachment.FileName = attachmentName;
			//                attachment.DisplayName = Path.GetFileName(attachmentName);

			//                if (embedAttachment)
			//                {
			//                    InsertIntoHtml(proxy, attachment);
			//                }

			//                proxy.Attachments.Add(attachment);
			//            }
			//        }

			//        return email2Mime.ConvertToMimeStream();
			//    }
			//}
			//catch (Exception e)
			//{
			//    System.Diagnostics.Trace.WriteLine(e.Message);
			//    throw;
			//}           
		}
#pragma warning restore 67
		#endregion

		#region IAction3 Members

		public string Execute(IActionData3 input, ActionPropertySet properties)
		{
			ExecuteArgs args;
			args.ActionPropertySet = properties;
			args.IActionData3 = input;
			args.Exception = null;

			Thread staThread = new Thread(state => ExecuteWorker((ExecuteArgs) state));
			staThread.Name = MethodBase.GetCurrentMethod().DeclaringType.Name + "." + MethodBase.GetCurrentMethod().Name;
			staThread.SetApartmentState(ApartmentState.STA);
			//Using STA seems to allow this action to behave correctly when the code is executed from the Workshare Protect Service.

			staThread.Start(args);
			staThread.Join();

			if (args.Exception != null)
				throw args.Exception;

			return m_file;
		}
		public string Execute(IActionData3 inputData, ActionPropertySet aProperties)
		{
			Stream inputStream = null;
			Stream outputStream = null;
			try
			{
				using (Workshare.Policy.Engine.Interfaces.IFile inputFile = new Workshare.Policy.Engine.File(inputData.FileName, Path.GetFileName(inputData.FileName)))
				{
					inputStream = inputFile.Contents;
					outputStream = ExecuteStream(inputStream, inputData.Properties, aProperties);
					if (null != inputStream)
					{
						inputStream.Close();
					}
				}
				
				using (FileStream file = new FileStream(inputData.FileName, FileMode.Create, FileAccess.Write, FileShare.Read))
				{
					StreamUtils.CopyStreamToStream(outputStream, file);
					if (null != outputStream)
					{
						outputStream.Close();
					}
				}

				return inputData.FileName;
			}
			finally
			{
				if (null != inputStream)
				{
					inputStream.Close();
				}
				
				if (null != outputStream)
				{
					outputStream.Close();
				}
			}
		}
Beispiel #14
0
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet aProperties)
		{
			if (aProperties.SystemProperties.ContainsKey(SystemPropertiesStringTable.SysProp_FileType))
			{
				if (!SupportedFileCollection.Supports(aProperties.SystemProperties[SystemPropertiesStringTable.SysProp_FileType].Value as string))
				{
					Logger.LogError(Properties.Resources.UNABLE_TO_TAG_NON_SUPPORTED_FILETYPE);
					return null;
				}
			}

			if ((bool) aProperties[RPostActionStringTable.SendRegistered].Value == false)
			{
				return data.Content;
			}

			MimeProxy mime = new MimeProxy(data.Content);

			foreach (IEmailRecipient recipient in mime.ToRecipients)
				recipient.EmailAddress = recipient.EmailAddress + ".workshare.rpost.org";

			foreach (IEmailRecipient recipient in mime.CcRecipients)
				recipient.EmailAddress = recipient.EmailAddress + ".workshare.rpost.org";

			foreach (IEmailRecipient recipient in mime.BccRecipients)
				recipient.EmailAddress = recipient.EmailAddress + ".workshare.rpost.org";

			if ((bool) aProperties[RPostActionStringTable.Unmarked].Value == true)
			{
				string subject = mime.Subject;
				mime.Subject = "(C) " + subject;
			}

			Email2Mime email = new Email2Mime(mime);

			return email.ConvertToMimeStream();
		}
Beispiel #15
0
		//public string FileName
		//{
		//    get
		//    {
		//        return filename;
		//    }
		//    set
		//    {
		//        filename = value;
		//    }
		//}

		//public string DisplayName
		//{
		//    get
		//    {
		//        return displayname;
		//    }
		//    set
		//    {
		//        displayname = value;
		//    }
		//}


		#region private parts

		private static IActionData3 RemoveWidows(IActionData3 root)
		{
			List<IActionData3> toRemove = new List<IActionData3>();

			foreach (IActionData3 item in root.Nested)
			{
				if (item.Nested.Count == 0 && (string.IsNullOrEmpty(item.FileName) ||
					(!System.IO.File.Exists(item.FileName) && !System.IO.Directory.Exists(item.FileName))
					))
				{
					toRemove.Add(item);
				}
				else
				{
					if (item.Nested.Count > 0)
						toRemove.Add(RemoveWidows(item));
				}
			}

			foreach (IActionData3 item in toRemove)
			{
				if (item == null)
					continue;
				root.Nested.Remove(item);
			}
			if (root.Nested.Count == 0 && (root.Content == null || root.Content.Length == 0))
				return root;

			return null;
		}
Beispiel #16
0
		static public void PruneEmptyCollections(IActionData3 root, List<Guid> ids)
		{
			if (root == null || ids == null)
				return;
			List<IActionData3> toRemove = new List<IActionData3>();

			foreach (IActionData3 node in root.Nested)
			{
				if (node.Nested.Count > 0)
					PruneEmptyCollections(node, ids);

				if (ids.Contains(node.Id) && node.Nested.Count == 0)
					toRemove.Add(node);

			}
			foreach (IActionData3 node in toRemove)
			{
				root.Nested.Remove(node);
			}
		}
Beispiel #17
0
		/// <summary>
		/// This creates a subtree rooted at root containing all the nodes of
		/// root for which the Predicate returns true. root is modified such that
		/// the nodes (if not containers) are deleted from it.
		/// </summary>
		/// <param name="root">source tree</param>
		/// <param name="venn">node evaluation function</param>
		public ActionData(IActionData3 node, Predicate<ActionData> venn, ReadableContentRequest readContentDelegate)
			: this()
		{
			ActionData root = node as ActionData;
			if (root == null)
				return;
			myIC = root.myIC;
			rawContent = root.rawContent;
			streamProperties = root.streamProperties;
			tag = root.tag;
			RetrieveContent = readContentDelegate;
			filename = root.filename;
			displayname = root.displayname;

			List<ActionData> toRemove = new List<ActionData>();
			uniqueID = root.uniqueID;

			foreach (ActionData c in root.Nested)
			{
				if (!venn(c) && c.nested.Count == 0)
					continue;
				if (c.nested.Count == 0)
					toRemove.Add(c);
				ActionData reassignedChild = new ActionData(c, venn, readContentDelegate);
				Nested.Add(reassignedChild);
				reassignedChild.parent = this;
			}
			foreach (ActionData c in toRemove)
			{
				root.Nested.Remove(c);
			}
		}
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties)
		{
			return data.Content;
		}
Beispiel #19
0
		static public void GetAllCollectionId(IActionData3 root, List<Guid> ids)
		{
			if (root.Nested.Count == 0)
				return;
			ids.Add(root.Id);
			foreach (IActionData3 node in root.Nested)
			{
				if (node.Nested.Count > 0)
				{
					GetAllCollectionId(node, ids);
				}
			}
		}
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties)
		{
			throw new NotImplementedException();
		}
Beispiel #21
0
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties)
		{
			throw new NotImplementedException("Convert IActionData3 to IActionData. No inheritance so don't cast. Require Proxy");
		}
		private void ReadAllContents(IActionData3 root, StringBuilder sink)
		{
			foreach (IActionData3 data in root.Nested)
			{
				ReadAllContents(data, sink);
			}

			if (root.ReadableContent == null || root.Nested.Count > 0)
				return;

			using (StreamReader reader = new StreamReader(root.ReadableContent))
			{
				sink.Append("===============Filename: ");
				sink.Append(root.Properties["FileName"]);
				sink.AppendLine();
				sink.Append(reader.ReadToEnd());
				sink.AppendLine();
			}
		}
		public string Execute(IActionData3 input, ActionPropertySet properties)
		{
			throw new Exception("The method or operation is not implemented.");
		}
Beispiel #24
0
		/// <summary>
		/// Transforms an IActionData3 structure to a IContainer structure. As yet does not support
		/// container semantics for arbitrary IActionData3 implementations, only for ActionData instances.
		/// </summary>
		/// <param name="root">IActionData3 object tree</param>
		/// <returns>IContainer root item</returns>
		IContainer ContentToPackedContainer(IActionData3 root)
		{
			foreach (IActionData3 child in root.Nested)
			{
				ContentToPackedContainer(child);
			}
			if (root.Content == null) // file was deleted
				return null;

			ActionData rootActionData = root as ActionData;
			if (rootActionData == null)
			{
				return null;
			}

			if (root.Nested.Count == 0)
			{
				if (rootActionData.FileType != FileType.Folder && rootActionData.FileType != FileType.Selection)
				{
					bool wasReadOnly = false;
					int contentItemId = -1;
					string contentId = string.Empty;
					string recordkey = string.Empty;
					if (rootActionData.Underworld != null)
					{
						contentItemId = rootActionData.Underworld.ContentItemIndex;
						contentId = rootActionData.Underworld.ContentId;
						wasReadOnly = rootActionData.Underworld.WasReadOnly;

						if (!rootActionData.Underworld.Properties.TryGetValue(Workshare.Mime.Conversions.PropertyNames.RecordKey, out recordkey))
						{
							recordkey = string.Empty;
						}
					}
					string filename;
					if (!rootActionData.Properties.TryGetValue("FileName", out filename))
					{
						filename = Guid.NewGuid().ToString();
					}

					// SJ - Update the filename here in the Action Data!!
					rootActionData.Underworld = new File(rootActionData.FileName, rootActionData.DisplayName);
					rootActionData.Underworld.ContentItemIndex = contentItemId;
					rootActionData.Underworld.ContentId = contentId;
					rootActionData.Underworld.WasReadOnly = wasReadOnly;

					if (recordkey.Length > 0)
					{
						rootActionData.Underworld.Properties[Workshare.Mime.Conversions.PropertyNames.RecordKey] = recordkey;
					}

					if (!string.IsNullOrEmpty(filename))
					{
						rootActionData.Underworld.Properties["FileName"] = filename;
					}
				}
			}
			else
			{
				Collection<IContainer> files = rootActionData.Underworld.Files;
				files.Clear();
				foreach (IActionData3 data in rootActionData.Nested)
				{
					if (data.Content == null)
					{
						continue;	// skip deleted files
					}
					ActionData child = data as ActionData;
					if (child == null)
					{
						string filename;
						if (!data.Properties.TryGetValue("FileName", out filename))
						{
							filename = Guid.NewGuid().ToString();
						}
						files.Add(new File(data.Content, filename));
					}
					else
					{
						files.Add(child.Underworld);
					}
				}
			}

			return rootActionData.Underworld;
		}
Beispiel #25
0
		public Stream ExecuteMime(IActionData3 data, ActionPropertySet aProperties)
		{
			IActionProperty prop = null;
			if (aProperties.SystemProperties.TryGetValue(SystemPropertiesStringTable.SysProp_FileType, out prop))
			{
				if (!SupportedFileCollection.Supports(prop.Value as string))
				{
					Logger.LogError(Properties.Resources.UNABLE_TO_TAG_NON_SUPPORTED_FILETYPE);
					return null;
				}
			}

			string prefix = "PGP: ";
			string prefixProp = aProperties[PGPActionStringTable.SubjectPrefix].Value.ToString();
			if ((!string.IsNullOrEmpty(prefixProp)))
				prefix = prefixProp;

			Workshare.Mime.Conversions.MimeProxy mime = new Workshare.Mime.Conversions.MimeProxy(data.Content);
			string existingSubject = mime.Subject;
			mime.Subject = prefix + existingSubject;

			Workshare.Mime.Conversions.Email2Mime email = new Workshare.Mime.Conversions.Email2Mime(mime);

			return email.ConvertToMimeStream();
		}
Beispiel #26
0
		static public void Merge(IActionData3 master, IActionData3 spawn)
		{
			Merge(master, spawn, false);
		}
Beispiel #27
0
		public string Execute(IActionData3 input, ActionPropertySet aProperties)
		{
			return ConvertToPdf(input, aProperties);
		}
Beispiel #28
0
		private String ConvertToPdf(IActionData3 inputData, IActionPropertySet properties)
		{
			try
			{
				var systemProperties = properties.SystemProperties;
				IActionProperty filetypeProperty;
				if (systemProperties.TryGetValue(SystemPropertiesStringTable.SysProp_FileType, out filetypeProperty))
				{
					if (!m_supportedFileCollection.Supports(filetypeProperty.Value as string))
					{
						return null;
					}
				}

				if ((bool) properties[PdfActionStringTable.PasswordRequired].Value)
				{
					string password = properties[PdfActionStringTable.Password].Value.ToString();
					if (string.IsNullOrEmpty(password))
					{
						throw new ArgumentException(LanguageResources.ERROR_PASSWORD_REQUIRED);
					}
					if ((bool) properties[PdfActionStringTable.EnforceStrongPassword].Value && !StrongPassword.IsStrongPassword(password))
					{
						throw new ArgumentException(LanguageResources.ERROR_STRONG_PASSWORD_REQUIRED);
					}
				}

				m_fileType = filetypeProperty.Value as string;
				m_streamProperties = inputData.Properties;
				m_actionPropertySet = properties;
				m_inputFile = inputData.FileName;

				ThreadState thstate = new ThreadState();
				Thread thread = new Thread(new ParameterizedThreadStart(InternalExecute));
				thread.Name = MethodBase.GetCurrentMethod().DeclaringType.Name + "." + MethodBase.GetCurrentMethod().Name;
				thread.SetApartmentState(ApartmentState.STA);
				thread.Start(thstate);
				thread.Join();
				if (thstate.ThreadStateResult)
				{
					return m_outputFile;
				}
				if (thstate.ExceptionCaught != null)
				{
					throw thstate.ExceptionCaught;
				}
				return null;
			}
			catch (Exception e)
			{
				Logger.LogError(e);
				throw;
			}
		}
Beispiel #29
0
		public string Execute(IActionData3 input, ActionPropertySet aProperties)
		{
			throw new NotImplementedException();
		}
Beispiel #30
0
		public string Execute(IActionData3 input, ActionPropertySet aProperties)
		{
			return input.FileName;
		}