public PolicyResponseActionMerger(IPolicyResponseAction action)
 {
     PolicyResponseAction input = action as PolicyResponseAction;
     m_pra = input.DeepCopy();
     m_propertiesList = new List<ActionPropertySet>();
     if (m_pra.InternalProperties != null) AddActionPropertySet(m_pra.InternalProperties);
 }
Esempio n. 2
0
        public static Collection<IContentItem> GetContentItems(PolicyResponseObject upi, IPolicyResponseAction responseAction)
        {
            Dictionary<Guid, IContentItem> contentItems = new Dictionary<Guid, IContentItem>();

            Collection<IContentItem> contentCollection = upi.ContentCollection;
            foreach (ContentItem contentItem in contentCollection)
            {
                IFile currentFile = contentItem.File;

                if (contentItem.PolicySetCollection == null)
                    continue;

                foreach (IPolicySetResponse policySet in contentItem.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.Type == ((PolicyResponseAction)responseAction).Type)
                            {
                                if (!contentItems.ContainsKey(currentFile.UniqueIdentifier))
                                    contentItems.Add(currentFile.UniqueIdentifier, contentItem);
                            }
                        }
                    }
                }
            }

            Collection<IContentItem> contents = new Collection<IContentItem>();
            foreach (KeyValuePair<Guid, IContentItem> kvp in contentItems)
            {
                contents.Add(kvp.Value);
            }

            return contents;
        }
Esempio n. 3
0
		static private void UpdateActionEntity(IPolicyResponseAction ai, bool overridden)
		{
			PolicyResponseAction actionInfo = ai as PolicyResponseAction;

			actionInfo.Processed = true;
			actionInfo.Overridden = overridden;

			foreach (KeyValuePair<string, Workshare.Policy.Action.IActionProperty> property in actionInfo.InternalProperties)
			{
				if (property.Value == null || property.Value.ToString().Length == 0)
					continue;

				if (property.Value.GetType().IsArray)
				{
					string details = string.Empty;
					foreach (object item in property.Value.Value as object[])
					{
						if (details.Length > 0)
							details += "; ";

						details += item.ToString();
					}

					if (details.Length == 0)
						continue;

					property.Value.Value = details;
				}
			}
		}
Esempio n. 4
0
		static private bool ActionAlreadyAdded(IPolicyResponseAction responseAction, List<IPolicyResponseAction> actions)
		{
			foreach (IPolicyResponseAction action in actions)
			{
				if (action.Name == responseAction.Name)
					return true;
			}

			return false;
		}
Esempio n. 5
0
		static private IPolicyResponseAction ExtractExceptionAction(List<IPolicyResponseAction> actions, IPolicyResponseAction requestedAction)
		{
			const string exceptionHandlerPropertyName = "ExceptionHandler";

			foreach (IPolicyResponseAction action in actions)
			{
				string requestedProperty;
				if (!requestedAction.Properties.TryGetValue(exceptionHandlerPropertyName, out requestedProperty))
					continue;

				string currentActionProperty;
				if (!action.Properties.TryGetValue(exceptionHandlerPropertyName, out currentActionProperty))
					continue;

				if (currentActionProperty == requestedProperty)
					return action;
			}

			// Default: If we get here, return the first exception handler if there are any
			if (0 != actions.Count)
			{
				const string exceptionHandler = "ExceptionAction";
				foreach (IPolicyResponseAction action in actions)
				{
					string currentActionProperty;
					if (action.Properties.TryGetValue(exceptionHandler, out currentActionProperty) &&
						(currentActionProperty.ToLowerInvariant() == "true"))
						return action;
				}
			}

			return null;
		}
Esempio n. 6
0
		internal static void UpdateActionEntity(IPolicyResponseAction ai, bool overridden)
		{
			try
			{
				PolicyResponseAction actionInfo = ai as PolicyResponseAction;
				if (actionInfo != null)
				{
					actionInfo.Processed = true;
					actionInfo.Overridden = overridden;

					foreach (KeyValuePair<string, IActionProperty> property in actionInfo.InternalProperties)
					{
						if (property.Value == null || property.Value.ToString().Length == 0)
						{
							continue;
						}

						if (property.Value.GetType().IsArray)
						{
							string details = string.Empty;
							object[] objects = property.Value.Value as object[];
							if (objects != null)
							{
								foreach (object item in objects)
								{
									if (details.Length > 0)
									{
										details += "; ";
									}

									details += item.ToString();
								}
							}

							if (details.Length == 0)
							{
								continue;
							}

							property.Value.Value = details;
						}
					}
				}
			}
			catch (Exception e)
			{
				Logger.LogError(e);
			}
		}
		private void AddActionInfo(IPolicyResponseAction actionInfo)
		{
			PolicyResponse pi = GetLatestPolicyInfoSet()[GetLatestPolicyInfoSet().Count - 1] as PolicyResponse;
			if (pi.ActionCollection == null)
				pi.ActionCollection = new Collection<IPolicyResponseAction>();
			pi.ActionCollection.Add(actionInfo);
		}
Esempio n. 8
0
        internal static ActionEntity ConvertActionEntity(IPolicyResponseAction actionInfo)
        {
            if (actionInfo.Properties.ContainsKey("ExceptionAction") && actionInfo.Properties["ExceptionAction"] == "True" && !actionInfo.Processed)
                return null;

            ActionEntity ae = new ActionEntity();
            ae.ActionName = actionInfo.Name;
            ae.ActionOverriden = actionInfo.Overridden;
            ae.ActionProcessed = actionInfo.Processed;
            ae.ActionType = actionInfo.Type;

            List<ActionPropertyEntity> aList = new List<ActionPropertyEntity>();
            if (actionInfo.ActionPropertyCollection != null && actionInfo.ActionPropertyCollection.Count > 0)
            {
                foreach (IActionPropertyResponse apr in actionInfo.ActionPropertyCollection)
                {
                    if (!string.IsNullOrEmpty(apr.Value))
                    {
                        ActionPropertyEntity ape = new ActionPropertyEntity();
                        ape.Name = apr.Name;
                        ape.PropertyValue = apr.Value;
                        aList.Add(ape);
                    }
                }
            }
            ae.ActionProperties = aList.ToArray();
            return ae;
        }
Esempio n. 9
0
		internal static Workshare.PolicyContent.Action GetAction(IPolicyResponseAction pra)
		{
			if (null == pra)
				throw new ArgumentException("pra");

			Workshare.PolicyContent.Action action = new Workshare.PolicyContent.Action();
			action.ExecutedSequence = 0;
			action.Name = pra.Name;
			action.Overriden = pra.Overridden;
			action.Processed = pra.Processed;
			action.Type = pra.Type;

			action.ActionProperties = new Workshare.PolicyContent.ActionProperty[0];
			Collection<IActionPropertyResponse> actionProps = pra.ActionPropertyCollection;
			if (actionProps != null && actionProps.Count > 0)
			{
				List<Workshare.PolicyContent.ActionProperty> props = new List<Workshare.PolicyContent.ActionProperty>();

				foreach ( IActionPropertyResponse apr in actionProps)
				{
					props.Add(ActionPropertyAdaptor.GetActionProperty(apr));
				}

				action.ActionProperties = props.ToArray();
			}

			action.SystemProperties = new Workshare.PolicyContent.ActionProperty[0];
			Collection<IActionPropertyResponse> sysProps = pra.SystemPropertyCollection;
			if ( sysProps != null && sysProps.Count > 0)
			{
				List<Workshare.PolicyContent.ActionProperty> props = new List<Workshare.PolicyContent.ActionProperty>();
				foreach (IActionPropertyResponse prop in sysProps)
				{
					props.Add(ActionPropertyAdaptor.GetActionProperty(prop));
				}
				action.SystemProperties = props.ToArray();
			}

			action.Properties = new CustomProperty[0];
			if (pra.Properties != null && pra.Properties.Count > 0)
			{
				List<CustomProperty> custProps = new List<CustomProperty>();

				foreach (string key in pra.Properties.Keys)
				{
					custProps.Add(new CustomProperty(key, pra.Properties[key]));
				}

				action.Properties = custProps.ToArray();
			}

			PolicyResponseAction policyResponseAction = pra as PolicyResponseAction;
			if ( policyResponseAction != null)
			{
				action.Assembly = policyResponseAction.Assembly;
				action.ClassName = policyResponseAction.ClassName;
				action.Precedence = policyResponseAction.Precedence;

				if (policyResponseAction.SupersededByAction != null)
				{
					action.SupersededByAction = GetAction(policyResponseAction.SupersededByAction);
				}
			}

			return action;
		}