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);
            }
        }
Пример #2
0
        public PolicyResponseAction DeepCopy()
        {
            PolicyResponseAction clone = new PolicyResponseAction();

            clone.m_Action = m_Action;
            clone.m_Precedence = m_Precedence;
            clone.m_AllowOverride = m_AllowOverride;
            clone.m_Type = m_Type;
            clone.m_isExceptionAction = m_isExceptionAction;
            clone.m_Name = m_Name;
            clone.m_Description = m_Description;
            clone.m_ActionSetId = m_ActionSetId;
            clone.m_assembly = m_assembly;
            clone.m_className = m_className;

            clone.m_ActionProperties = new ActionPropertySetClone(m_ActionProperties);

            foreach(KeyValuePair<string, string> customPropertyPair in m_CustomProperties)
            {
                clone.m_CustomProperties.Add(customPropertyPair.Key, customPropertyPair.Value);
            }

            return clone;
        }
Пример #3
0
		private void ExecuteAction(PolicyResponseAction pra, ActionData item)
		{
			string displayName = null;
			if (item.Underworld != null)
			{
				displayName = item.Underworld.DisplayName;
			}
			else
			{
				item.Properties.TryGetValue("FileName", out displayName);
			}
			Logger.LogDebug("Pre-Execute: " + displayName);

			OnBeforeExecuteHandler(pra.Action.Name, item.DisplayName);
			try
			{
				Dictionary<string, string> streamProperties = item.Properties;

				item.FileName = pra.Action.Execute(item, pra.InternalProperties as ActionPropertySet);
				item.DisplayName = streamProperties["DisplayName"];
			}
			catch (Exception e)
			{
				OnAfterExecuteHandler(pra.Action.Name, item.DisplayName);
				if (e is AbortActionException)
				{
					throw;
				}
				string message = "ActionExecution: Exception on " + pra.Type + ". Message: " + e.Message;
				PolicyActionException pae = new PolicyActionException(message, e);
				pae.ContentId = displayName;
				throw pae;
			}
			OnAfterExecuteHandler(pra.Action.Name, item.DisplayName);
			Logger.LogDebug("Post-Execute: " + displayName);
		}
Пример #4
0
        public static IActionPropertySet GetActionPropertySet(PolicyResponseObject upi, IFile file, PolicyResponseAction thisAction)
        {
            Collection<IContentItem> fileCollection = upi.ContentCollection;
            foreach (ContentItem filePolicyInfo in fileCollection)
            {
                IFile currentFile = filePolicyInfo.File;
                if (file.UniqueIdentifier == currentFile.UniqueIdentifier)
                {
                    if (filePolicyInfo.PolicySetCollection == null)
                        continue;

                    foreach (IPolicySetResponse policySet in filePolicyInfo.PolicySetCollection)
                    {
                        PolicySetResponse policySetInfo = policySet as PolicySetResponse;
                        if (policySetInfo.PolicyReportCollection == null)
                            continue;

                        foreach (IPolicyResponse policyInfo in policySetInfo.PolicyReportCollection)
                        {
                            if (policyInfo.ActionCollection == null)
                                continue;

                            foreach (IPolicyResponseAction  ai in policyInfo.ActionCollection)
                            {
                                PolicyResponseAction actionInfo = ai as PolicyResponseAction;
                                if (actionInfo.Action == null)
                                    continue;

                                if (actionInfo.SupersededByAction == null &&
                                    actionInfo.Type == thisAction.Type &&
                                    actionInfo.ExceptionAction == thisAction.ExceptionAction)
                                {
                                    return actionInfo.InternalProperties;
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
Пример #5
0
        /// <summary>
        /// This method retrieves the properties for a given action, provided with a PolicyResponse, and IFile
        /// </summary>
        /// <param name="upi"></param>
        /// <param name="file"></param>
        /// <param name="thisAction"></param>
        /// <returns></returns>
        public static IActionPropertySet GetPropertySetForCorrespondingAction(PolicyResponseObject upi, IFile file, PolicyResponseAction thisAction)
        {
            foreach (IResolvedAction resolvedAction in upi.ResolvedActionCollection)
            {
                if (thisAction.Type == resolvedAction.ResponseAction.Type)
                {
                    Collection<IContentItem> fileCollection = resolvedAction.ContentCollection;
                    foreach (ContentItem filePolicyInfo in fileCollection)
                    {
                        IFile currentFile = filePolicyInfo.File;
                        if (file.UniqueIdentifier == currentFile.UniqueIdentifier)
                        {
                            if (filePolicyInfo.PolicySetCollection == null)
                                continue;

                            foreach (IPolicySetResponse policySet in filePolicyInfo.PolicySetCollection)
                            {
                                PolicySetResponse policySetInfo = policySet as PolicySetResponse;
                                if (policySetInfo.PolicyReportCollection == null)
                                    continue;

                                foreach (IPolicyResponse policyInfo in policySetInfo.PolicyReportCollection)
                                {
                                    if (policyInfo.ActionCollection == null)
                                        continue;

                                    foreach (IPolicyResponseAction ai in policyInfo.ActionCollection)
                                    {
                                        PolicyResponseAction actionInfo = ai as PolicyResponseAction;
                                        if (actionInfo.Action == null)
                                            continue;

                                        if (actionInfo.SupersededByAction == null &&
                                            actionInfo.Type == thisAction.Type &&
                                            actionInfo.ExceptionAction == thisAction.ExceptionAction)
                                        {
                                            foreach (IActionPropertyResponse apr in actionInfo.SystemPropertyCollection)
                                            {
                                                if (actionInfo.Action.PropertySet.SystemProperties.ContainsKey(apr.Name))
                                                {
                                                    actionInfo.Action.PropertySet.SystemProperties[apr.Name].Value = apr.Value;
                                                }
                                                else
                                                {
                                                    ActionProperty prop = new ActionProperty(apr.Name, apr.Value);
                                                    actionInfo.Action.PropertySet.SystemProperties.Add(apr.Name, prop);
                                                }
                                            }
                                            return actionInfo.Action.PropertySet;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
Пример #6
0
		private void LoadPresetActions(string actionName)
		{
			foreach (PresetActionInfo presetActionInfo in m_presetActionsInfo)
			{
				if (presetActionInfo.Name.CompareTo(actionName) == 0)
				{
					ISupportedFilesSet supportedFiles = SupportedFileSet.CreateFileCollection("");

					// If the map does not contain SupportedFileTypes, keep going
					// to maintain backwards compatibility for old policies
					if (presetActionInfo.SupportedFileTypes != null && presetActionInfo.SupportedFileTypes.Length > 0)
					{
						string supportedFiletypes = presetActionInfo.SupportedFileTypes;
						foreach (string s in supportedFiletypes.Split(new char[] { ';' }))
						{
							supportedFiles.AddSupportFor(s);
						}
					}
					if (presetActionInfo.NonSupportedFileTypes != null && presetActionInfo.NonSupportedFileTypes.Length > 0)
					{
						string nonsupportedFiletypes = presetActionInfo.NonSupportedFileTypes;

						foreach (string s in nonsupportedFiletypes.Split(new char[] { ';' }))
						{
							supportedFiles.RemoveSupportFor(s);
						}
					}

					if (!supportedFiles.Supports(FileTypeBridge.GetFileType(m_CurrentFileInfo.File.FileType)))
					{
						//The action is not directly supported.

						if ((Source.PolicyType == PolicyType.ClientEmail || Source.PolicyType == PolicyType.Mta)
							&& supportedFiles.Supports(FileTypeBridge.GetFileType(Workshare.Policy.FileType.Email)))
						{
							//actions that support email should be allowed to trigger from an email's attachments, 
							//even though the action may not explicity support attachment file types. So don't return.
						}
						else
						{
							continue;
						}
					}


					string name = presetActionInfo.Name;
					string objectRef = presetActionInfo.ObjectReference;
					string assemblyName = string.Empty;
					string className = string.Empty;

					OnPolicyProgressEvent(new PolicyProgressEventArgs(m_CurrentFileInfo.File, EventType.action, name));

					CachedAction cachedAction = null;

					try
					{
						cachedAction = LoadActionObject(objectRef, name, out assemblyName, out className);
					}
					catch (Exception ex)
					{
						Logger.LogError("Failed to load action");
						Logger.LogError(ex);
						cachedAction = null;
					}

					if (cachedAction == null)
						return;

					try
					{
						IActionProperty transparent = cachedAction.Properties["transparent"];
						if (((bool) transparent.Value) == true)
							continue;
					}
					catch
					{
					}
					string description = string.Empty;

					PolicyResponseAction actionInfo = new PolicyResponseAction(cachedAction, name, description, m_ExceptionAction);
					actionInfo.ClassName = className;
					actionInfo.Assembly = assemblyName;
					if (m_ObjectMetadata[objectRef] != null)
					{
						List<KeyValuePair<string, string>> metadata = m_ObjectMetadata[objectRef] as List<KeyValuePair<string, string>>;
						foreach (KeyValuePair<string, string> kvp in metadata)
						{
							if (string.Compare(kvp.Key, "allowoveride", true, CultureInfo.InvariantCulture) == 0)
							{
								cachedAction.AllowOverride = kvp.Value == "false";
								actionInfo.AllowOverride = cachedAction.AllowOverride;
							}
						}
					}

					// if m_CurrentActions == null you are probably using an old style rules xml file.
					if (m_CurrentActions == null)
						throw new PolicyEngineException("Current Actions are null. Is your rules file up to date?");

					m_CurrentActions.Add(actionInfo);
				}
			}

			return;
		}
Пример #7
0
		private object AddActionHandler(IBRERuleContext aBrc, Hashtable aMap, object aStep)
		{
			string name = GetName(aMap);

			OnPolicyProgressEvent(new PolicyProgressEventArgs(m_CurrentFileInfo.File, EventType.action, name));

			ISupportedFilesSet supportedFiles = SupportedFileSet.CreateFileCollection("");

			// If the map does not contain SupportedFileTypes, keep going
			// to maintain backwards compatibility for old policies
			if (aMap.Contains("SupportedFileTypes") || aMap.Contains("NonSupportedFileTypes"))
			{
				if (aMap.Contains("SupportedFileTypes"))
				{
					string supportedFiletypes = aMap["SupportedFileTypes"] as string;
					foreach (string s in supportedFiletypes.Split(new char[] { ';' }))
					{
						supportedFiles.AddSupportFor(s);
					}
				}
				if (aMap.Contains("NonSupportedFileTypes"))
				{
					string nonsupportedFiletypes = aMap["NonSupportedFileTypes"] as string;

					foreach (string s in nonsupportedFiletypes.Split(new char[] { ';' }))
					{
						supportedFiles.RemoveSupportFor(s);
					}
				}

				if (!supportedFiles.Supports(FileTypeBridge.GetFileType(m_CurrentFileInfo.File.FileType)))
				{
					//The action is not directly supported.

					if ((Source.PolicyType == PolicyType.ClientEmail || Source.PolicyType == PolicyType.Mta)
						&& supportedFiles.Supports(FileTypeBridge.GetFileType(Workshare.Policy.FileType.Email)))
					{
						//actions that support email should be allowed to trigger from an email's attachments, 
						//even though the action may not explicity support attachment file types. So don't return.
					}
					else
					{
						return null;
					}
				}
			}

			if (aMap.Contains("ObjectRef") == false)
				return null;

			string objectRef = aMap["ObjectRef"] as string;
			string assemblyName = string.Empty;
			string className = string.Empty;

			CachedAction cachedAction = null;

			try
			{
				cachedAction = LoadActionObject(objectRef, name, out assemblyName, out className);
			}
			catch (Exception ex)
			{
				Logger.LogError("Failed to load action");
				Logger.LogError(ex);
				cachedAction = null;
			}

			if (cachedAction == null)
				return null;

			string description = string.Empty;
			if (aMap.Contains("Description"))
				description = aMap["Description"] as string;

			PolicyResponseAction actionInfo = new PolicyResponseAction(cachedAction, name, description, m_ExceptionAction);
			actionInfo.ClassName = className;
			actionInfo.Assembly = assemblyName;
			if (m_ObjectMetadata[objectRef] != null)
			{
				List<KeyValuePair<string, string>> metadata = m_ObjectMetadata[objectRef] as List<KeyValuePair<string, string>>;
				foreach (KeyValuePair<string, string> kvp in metadata)
				{
					if (string.Compare(kvp.Key, "allowoveride", true, CultureInfo.InvariantCulture) == 0)
					{
						cachedAction.AllowOverride = kvp.Value == "false";
						actionInfo.AllowOverride = cachedAction.AllowOverride;
					}
				}
			}

			string exceptionHandlerPropertyName = "ExceptionHandler";
			if (aMap.Contains(exceptionHandlerPropertyName))
				(actionInfo as IPolicyResponseAction).Properties.Add(exceptionHandlerPropertyName, (string) aMap[exceptionHandlerPropertyName]);

			// if m_CurrentActions == null you are probably using an old style rules xml file.
			if (m_CurrentActions == null)
				throw new PolicyEngineException("Current Actions are null. Is your rules file up to date?");

			m_CurrentActions.Add(actionInfo);
			return null;
		}
Пример #8
0
        public void ReadXml(XmlReader reader)
        {
            if (reader.NodeType != XmlNodeType.Element)
                return;

            Name = reader.GetAttribute("Name");
            Description = reader.GetAttribute("Description");
            Triggered = bool.Parse(reader.GetAttribute("Triggered"));
            int iExpectedActionCount = Int32.Parse(reader.GetAttribute("NumActions"), CultureInfo.InvariantCulture);
            bool bIsMT = reader.IsEmptyElement;
            reader.ReadStartElement("PolicyResponse");

            if (m_Actions == null)
                m_Actions = new Collection<IPolicyResponseAction>();
            else
                iExpectedActionCount += m_Actions.Count;

            while (reader.IsStartElement("ActionInfo"))
            {
                PolicyResponseAction anAction = new PolicyResponseAction();
                anAction.ReadXml(reader);
                m_Actions.Add(anAction);
            }
  
            if(!bIsMT)
                reader.ReadEndElement();
            if (m_Actions.Count != iExpectedActionCount)
                throw new PolicyEngineException("Inconsistent XML");
        }
Пример #9
0
		public static IPolicyResponseAction GetIPolicyResponseAction(Workshare.PolicyContent.Action actionIn)
		{
			if (null == actionIn)
				throw new ArgumentException("actionIn");

			PolicyResponseAction pra = new PolicyResponseAction();
			pra.Name = actionIn.Name;
			pra.Assembly = actionIn.Assembly;
			pra.ClassName = actionIn.ClassName;
			pra.Overridden = actionIn.Overriden;
			pra.Processed = actionIn.Processed;
			pra.Type = actionIn.Type;
			pra.IsExceptionAction = IsExceptionAction(actionIn);
			pra.Precedence = actionIn.Precedence;
			pra.Action = CreateInstanceOfAction(actionIn);

			if (actionIn.SupersededByAction != null)
			{
				pra.SupersededByAction = GetIPolicyResponseAction(actionIn.SupersededByAction);
			}

			pra.InternalProperties = new ActionPropertySet();
			if (actionIn.ActionProperties != null)
			{
				foreach (Workshare.PolicyContent.ActionProperty property in actionIn.ActionProperties)
				{
					IActionProperty actionProp = ActionPropertyAdaptor.GetIActionProperty(property);

					pra.InternalProperties[actionProp.DefaultDisplayName] = actionProp;
					pra.Action.PropertySet[actionProp.DefaultDisplayName] = actionProp;
				}

				foreach (Workshare.PolicyContent.ActionProperty property in actionIn.SystemProperties)
				{
					IActionProperty systemProp = ActionPropertyAdaptor.GetIActionProperty(property);
					pra.InternalProperties.SystemProperties[systemProp.DefaultDisplayName] = systemProp;
					pra.Action.PropertySet.SystemProperties[systemProp.DefaultDisplayName] = systemProp;
				}
			}

			//The 'Properties' field is hidden in PolicyResponseAction...use IPolicyResponseAction.
			IPolicyResponseAction iPra = pra;
			if ( actionIn.Properties != null)
			{
				foreach (CustomProperty property in actionIn.Properties)
				{
					iPra.Properties[property.Name] = property.Value;
				}
			}

			return pra;
		}