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; }
public ActionData(IFile file, IActionPropertySet inputSet, OptionList options) { m_file = file; m_actionProps = new ActionPropertySet(inputSet); IActionProperty actionPropertyName = new ActionProperty("FileName", typeof(System.String), PropertyDisplayType.Default, false, false, m_file.FileName, true); IActionProperty actionPropertyDisplay = new ActionProperty("DisplayName", typeof(System.String), PropertyDisplayType.Default, false, false, m_file.DisplayName, true); IActionProperty actionPropertyType = new ActionProperty("FileType", typeof(System.String), PropertyDisplayType.Default, false, false, FileTypeBridge.GetFileType(m_file.FileType), true); m_actionProps.SystemProperties["FileName"] = actionPropertyName; m_actionProps.SystemProperties["DisplayName"] = actionPropertyDisplay; m_actionProps.SystemProperties["FileType"] = actionPropertyType; m_properties["FileName"] = actionPropertyName.Value.ToString(); m_properties["DisplayName"] = actionPropertyDisplay.Value.ToString(); m_properties["FileType"] = actionPropertyType.Value.ToString(); foreach (KeyValuePair<string, IActionProperty> prop in m_actionProps) { if (options.Contains(prop.Key)) prop.Value.Value = options[prop.Key].Checked; } if (m_actionProps.ContainsKey("HandleFootnotesHiddenData") && options.Contains("Footnotes") && options["Footnotes"].Checked) { m_actionProps["HandleFootnotesHiddenData"].Value = true; } FileName = m_file.FileName; }
// 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 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); }
/// <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 ActionPropertySet MergeProperties(ActionPropertySet[] sets) { ActionPropertySet merged = new ActionPropertySet(); merged["ThisWasMerged"] = new ActionProperty("yaya", "sisterhood"); countMerged = sets.Length; return merged; }
public Stream ExecuteMime(IActionData3 data, ActionPropertySet aProperties) { if (aProperties.ContainsKey(AbortOnExecuteActionStringTable.Abort)) throw new AbortActionException("Abort as requested"); return data.Content; }
public string Execute(IActionData3 input, ActionPropertySet aProperties) { if (aProperties.ContainsKey(AbortOnExecuteActionStringTable.Abort)) throw new AbortActionException("Abort as requested"); return input.FileName; }
void m_contentItem_StateChanged(object sender, UIObjectStateChangedArgs args) { StateChangedFired = true; UIContentItem contentItem = args.Object as UIContentItem; if (contentItem == null) { throw new InvalidOperationException("No UIContentItem has been supplied"); } if (contentItem.ClientActionControl == null) { return; } try { ActionPropertySet propertySet = new ActionPropertySet(); foreach (ActionPropertyFacade property in contentItem.ActionPropertySet.Values) { propertySet[property.DefaultDisplayName] = property; } foreach (ActionPropertyFacade property in contentItem.ActionPropertySet.SystemProperties.Values) { propertySet.SystemProperties[property.DefaultDisplayName] = property; } contentItem.ClientActionControl.ActionProperties = propertySet; } // TODO: Decide an appropriate course of action, do we bail? catch { } }
public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties) { if (data == null) return null; return data.Content; }
public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties) { if (EnableAbortOnExecute) { throw new AbortActionException(); } return data.Content; }
protected string CleanFile(string inFile, ActionPropertySet actions) { PDFCleanUserAction action = new PDFCleanUserAction(); ActionDataImpl testData = new ActionDataImpl(Path.Combine(TestRoot, inFile)); testData.Properties.Add(strings.StrmProp_DisplayName, inFile); testData.Properties.Add("CorrectedDisplayName", inFile); return action.Execute(testData, actions); }
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; }
public ActionPropertySet MergeProperties(ActionPropertySet[] sets) { return PropertyMerger.Merge(sets, delegate(ActionProperty dest, ActionProperty src) { if (dest.DataType == typeof(bool) && (bool) src.Value) { dest.Value = true; } return dest; }); }
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; //} }
public ActionPropertySet MergeProperties(ActionPropertySet[] sets) { return new ActionPropertySet(PropertyMerger.Merge(sets, delegate(ActionProperty dest, ActionProperty src) { if (dest.DefaultDisplayName == Properties.LanguageResources.Description) { string mergedValue = dest.Value.ToString().Contains(src.Value.ToString()) ? dest.Value.ToString() : String.Format("{0}{1}{2}", dest.Value, Environment.NewLine, src.Value); return new ActionProperty(dest.DefaultDisplayName, dest.DataType, dest.DisplayType, dest.Visible, dest.Override, mergedValue, dest.ReadOnly) as IActionProperty; } return dest; })); }
public IPolicyResponseAction MergePra() { if (m_propertiesList.Count > 1) { ActionPropertySet[] actionPropertySetArray = m_propertiesList.ToArray(); m_enginePropertiesList = new List<ActionPropertySet>(); ActionPropertySet mergedEngineProperties = MergeEngineProperties(actionPropertySetArray); // there is only ever one set of values for the SystemProperties so pick a // random one to save. SortedList<string, IActionProperty> systemProperties = new SortedList<string, IActionProperty>(); foreach (string s in m_engineSystemProperties) { if (actionPropertySetArray[0].SystemProperties.ContainsKey(s)) systemProperties[s] = actionPropertySetArray[0].SystemProperties[s].Clone(); else systemProperties[s] = new ActionProperty(s, ""); } ActionPropertySet mergedProps = m_pra.Action.MergeProperties(actionPropertySetArray); if (mergedProps == null) { mergedProps = new ActionPropertySet(); } foreach (string key in mergedEngineProperties.Keys) { if (!mergedProps.ContainsKey(key)) mergedProps[key] = new ActionProperty(key, ""); mergedProps[key] = mergedEngineProperties[key]; } m_pra.InternalProperties = mergedProps; // enforce the values of the SystemProperties that were saved prior to merge foreach (string s in m_engineSystemProperties) { m_pra.InternalProperties.SystemProperties[s] = systemProperties[s]; } } return m_pra; }
internal virtual ActionPropertySet BuildActionProperties(string sourceFilePath) { ActionPropertySet result = new ActionPropertySet(); CleanActionPropertySet temp = new CleanActionPropertySet(); var dict = temp.GetFCSContentTypeDict(); foreach (string key in temp.Keys) { result.Add(new ActionProperty(key, temp[key].Value)); } foreach (MetadataType mdt in m_metadataExclusions) { ContentType ct = Utils.ConvertContentType(mdt); string contentType; if (dict.TryGetValue(ct, out contentType)) { result[contentType].Value = false; } } foreach (CommonFieldType cft in m_fieldExclusions) { string fieldType = "ExcludeFieldCodes" + Utils.ConvertFieldType(cft); result[fieldType].Value = true; } result[CleanOption.UseWordOptimizingAddin].Value = true; result[CleanOption.ExcludeCustomProperties].Value = Normalize(CustomPropertyExclusionList); result[CleanOption.ExcludeFieldCodes].Value = Normalize(AdvancedFieldExclusionList); result[CleanOption.DeleteFieldCodes].Value = Normalize(FieldDeletionList); result[CleanOption.ExcludeDocumentVariables].Value = Normalize(DocumentVariableExclusionList); result[CleanOption.HandleFootnotesHiddenData].Value = TreatFootNotesAsMetadata; //result.Add(new ActionProperty("EnableFootnotes", true)); // always set this so that the cleaning is controlled by the excluded metadata types if (!string.IsNullOrEmpty(sourceFilePath)) { var fileType = ValidateFileType(sourceFilePath); result.SystemProperties.Add("FileType", new ActionProperty("FileType", FileTypeBridge.GetFileType(fileType))); } return result; }
#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 void Test_01_CleanPDFMarkups() { string master = Path.Combine(TestRoot, _testInputFileNameTemplate); _testInputFile = TestCopy(master, "Test_01_CleanPDFMarkups.pdf"); ActionPropertySet pdfActionProperties = new ActionPropertySet(); pdfActionProperties.SystemProperties.Add(strings.SysProp_FileType, new ActionProperty(strings.SysProp_FileType, typeof(string), PropertyDisplayType.Default, false, false, ".pdf", true)); pdfActionProperties.Add(PDFCleanOption.Markups, new ActionProperty(PDFCleanOption.Markups, true)); _testOutputFile = CleanFile(_testInputFile, pdfActionProperties); Metadata pdfCheckBefore = StaticShared.DiscoverMetadata(master); Metadata pdfCheckAfter = StaticShared.DiscoverMetadata(_testOutputFile); Assert.AreEqual(0, pdfCheckAfter.Markups, "Marksups not cleaned"); // Check nothing else has changed Assert.AreEqual(pdfCheckBefore.Attachments, pdfCheckAfter.Attachments, "Attachments number changed"); Assert.AreEqual(pdfCheckBefore.Bookmarks, pdfCheckAfter.Bookmarks, "Bookmarks number changed"); Assert.AreEqual(pdfCheckBefore.Properties, pdfCheckAfter.Properties, "Properties different"); }
public ActionPropertySet MergeProperties(ActionPropertySet[] sets) { return PropertyMerger.Merge(sets, delegate(ActionProperty dest, ActionProperty src) { if (dest.DefaultDisplayName == Workshare.Policy.Actions.Properties.LanguageResources.Description) { string mergedValue; if (dest.Value.ToString().Contains(src.Value.ToString())) mergedValue = dest.Value.ToString(); //DE4858 Avoid appending the desc value when it is a duplicate of a previous value. else mergedValue = String.Format("{0}{1}{2}", dest.Value.ToString(), Environment.NewLine, src.Value.ToString()); return new ActionProperty(dest.DefaultDisplayName, dest.DataType, dest.DisplayType, dest.Visible, dest.Override, mergedValue, dest.ReadOnly) as IActionProperty; } return dest; }); }
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(); } } }
public ActionPropertySet MergeProperties(ActionPropertySet[] sets) { ActionPropertySet actionPropertySet = new ActionPropertySet(PropertyMerger.Merge(sets, delegate(ActionProperty dest, ActionProperty src) { if (dest.DataType == typeof(bool)) { dest.Value = (bool) dest.Value || (bool) src.Value; } return dest; })); String password = String.Empty; foreach (ActionPropertySet apc in sets) { if (!String.IsNullOrEmpty(apc[ZipActionStringTable.Password].Value as String)) { if (password.Length == 0) { password = apc[ZipActionStringTable.Password].Value.ToString(); } else if (password != apc[ZipActionStringTable.Password].Value.ToString()) { if (actionPropertySet[ZipActionStringTable.Password].Override) { password = String.Empty; actionPropertySet[ZipActionStringTable.PasswordRequired].Value = true; break; } else { throw new AbortActionException(LanguageResources.PASSWORDS_DIFFERENT); } } } } actionPropertySet[ZipActionStringTable.Password].Value = password; return actionPropertySet; }
public void GuessWhatDeepCopyDoes() { //setup PolicyResponseAction src = new PolicyResponseAction(); src.Assembly = "helloworld"; src.ActionSetId = "action set id"; src.AllowOverride = true; src.ClassName = "classname"; ActionPropertySet srcPropertySet = new ActionPropertySet(); srcPropertySet["Execute"] = new ActionProperty("Execute", "1"); srcPropertySet["Foobar"] = new ActionProperty("Foobar", "2"); foreach(string s in m_engineSystemProperties) { srcPropertySet.SystemProperties[s] = new ActionProperty(s, s); } src.InternalProperties = srcPropertySet; //execute PolicyResponseAction copy = src.DeepCopy(); //verify FieldInfo[] fields = src.GetType().GetFields(); foreach (FieldInfo f in fields) { Assert.AreEqual(f.GetValue(src), f.GetValue(copy), "Field {0} differs", f.Name); } PropertyInfo[] properties = src.GetType().GetProperties(); foreach (PropertyInfo p in properties) { if (p.PropertyType.BaseType != typeof(string).BaseType) continue; if (p.PropertyType.IsGenericType) continue; Assert.AreEqual(p.GetValue(src, null), p.GetValue(copy, null), "Property {0} differs", p.Name); } }
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(); }
public ActionPropertySet MergeProperties(ActionPropertySet[] sets) { return null; }
public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties) { return data.Content; }
public Stream ExecuteMime(IActionData3 data, ActionPropertySet properties) { throw new NotImplementedException(); }
public string Execute(IActionData3 input, ActionPropertySet properties) { throw new Exception("The method or operation is not implemented."); }
private void DoLightSpeedCleanEx(List<ContentType> listContentTypes) { System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); ActionDataImpl testData = new ActionDataImpl(m_sInputFile); testData.Properties.Add("DisplayName", m_sInputFile); testData.Properties.Add("FileName", m_sInputFile); IAction3 cleaner = LoadCleaner(); ActionPropertySet cleanProperties = new ActionPropertySet(cleaner.PropertySet); //ensure no fallback occurs as that would miss the point of lightspeed cleanProperties.SystemProperties.Add("RunAt", new ActionProperty("RunAt", "Server")); m_sFileForBinClean = cleaner.Execute(testData, cleanProperties); watch.Stop(); m_binCleanTime = watch.Elapsed.TotalSeconds; }