Ejemplo n.º 1
0
 /// <summary>
 /// Invoked an action.
 /// </summary>
 /// <param name="action">The action to invoke.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="action" /> is <see langword="null" />.
 /// </exception>
 public void InvokeAction(CachedAction action)
 {
     this.InvokeInner(action);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Caches an action.
 /// </summary>
 /// <param name="action">The action to cache.</param>
 /// <param name="timeout">The timeout / update interval.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="action" /> is <see langword="null" />.
 /// </exception>
 public void SaveAction(CachedAction action, TimeSpan timeout)
 {
     this.SaveInner(action, timeout);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Caches an action without a timeout.
 /// </summary>
 /// <param name="action">The action to cache.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="action" /> is <see langword="null" />.
 /// </exception>
 public void SaveAction(CachedAction action)
 {
     this.SaveInner(action, null);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Resets the state of an action.
 /// </summary>
 /// <param name="action">The action to reset.</param>
 /// <returns>Action was resetted or not.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="action" /> is <see langword="null" />.
 /// </exception>
 public bool ResetAction(CachedAction action)
 {
     return(this.ResetInner(action));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Removes an action from the cache.
 /// </summary>
 /// <param name="action">The action to remove.</param>
 /// <returns>Action was removed or not.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="action" /> is <see langword="null" />.
 /// </exception>
 public bool RemoveAction(CachedAction action)
 {
     return(this.RemoveInner(action));
 }
Ejemplo n.º 6
0
		internal CachedAction LoadActionObject(string objectRef, string ActionName, out string assembly, out string actionClass)
		{
			assembly = string.Empty;
			actionClass = string.Empty;

			object actionPropertiesObject = null;
			if (m_CachedActions.ContainsKey(objectRef))
				return m_CachedActions[objectRef];

			string xpath = string.Format(CultureInfo.InvariantCulture, "*[@ref='{0}']", objectRef);
			XmlNode objectNode = m_ActionNode.SelectSingleNode(xpath);

			assembly = objectNode.Attributes.GetNamedItem("assembly").Value;
			string className = objectNode.Attributes.GetNamedItem("class").Value;
			string objectReference = objectNode.Attributes.GetNamedItem("ref").Value;
			string precedence = objectNode.Attributes.GetNamedItem("precedence").Value;

			actionClass = className;

			// Old policies dont have runat in the objects.xml
			string runat = objectNode.Attributes["runat"] == null ? string.Empty : objectNode.Attributes["runat"].Value;

			if (!ShouldLoadAction(runat))
				return null;

			// Construct the actionobject and its associated property set
			object actionObject = null;
			lock (m_lock)
			{
				string path = AssemblyLocation.GetPathForActionAssembly(assembly);

				actionObject = LoadObject(path, className);
				actionPropertiesObject = LoadActionPropertySet(path);
			}

			// Set all the properties to their default values, as provided
			// by the action property set. This means that, even if the xml 
			// for the action does not contain entries for properties that need to
			// be supported in the action they will be there. Also set system
			// properties at this point
			CachedAction cachedAction = new CachedAction(actionObject, actionPropertiesObject);

			if (objectNode.Attributes["type"] != null)
				cachedAction.Type = objectNode.Attributes["type"].Value;

			// Populate the system properties - just do in here for now
			// FileType
			// CurrentUser
			// Date
			// RecipientList
			// RunAt
			IActionProperty actionProperty = new ActionProperty("FileType", FileType.GetType(), PropertyDisplayType.Default, false, false, FileType, true);
			cachedAction.Properties.SystemProperties.Add("FileType", actionProperty);
			actionProperty = new ActionProperty("CurrentUser", CurrentUser.GetType(), PropertyDisplayType.Default, false, false, CurrentUser, true);
			cachedAction.Properties.SystemProperties.Add("CurrentUser", actionProperty);
			actionProperty = new ActionProperty("Date", CurrentDate.GetType(), PropertyDisplayType.Default, false, false, CurrentDate, true);
			cachedAction.Properties.SystemProperties.Add("Date", actionProperty);
			actionProperty = new ActionProperty("RecipientList", RecipientList.GetType(), PropertyDisplayType.Default, false, false, RecipientList, true);
			cachedAction.Properties.SystemProperties.Add("RecipientList", actionProperty);
			actionProperty = new ActionProperty("RunAt", CurrentRunAtMode.GetType(), PropertyDisplayType.Default, false, false, CurrentRunAtMode, true);
			cachedAction.Properties.SystemProperties.Add("RunAt", actionProperty);

			XmlNodeList dataElements = objectNode.ChildNodes;

			cachedAction.Precedence = Workshare.Policy.Actions.CertifiedActions.ActionPrecedence.GetPrecedence(assembly);
			cachedAction.AllowOverride = GetAllowOverride(objectNode);

			foreach (XmlNode dataElement in dataElements)
			{
				string deName = GetNameAttribute(dataElement);
				string deType = dataElement.Attributes.GetNamedItem("type").Value.ToLower(CultureInfo.InvariantCulture);

				bool allowOverride = GetAllowOverride(dataElement);
				bool isVisible = GetIsVisible(dataElement);
				bool isCustomProperty = GetIsCustomProperty(dataElement);

				foreach (XmlNode childNode in dataElement)
				{
					string name = childNode.Name.ToLower(CultureInfo.InvariantCulture);

					switch (name)
					{
					case "dataitem":
						{
							switch (deType)
							{
							case "boolean":
								cachedAction.SetProperty(deName, childNode.InnerText.ToLower(CultureInfo.InvariantCulture) == "true", allowOverride, isVisible, null);
								break;
							case "string":
								cachedAction.SetProperty(deName, childNode.InnerText, allowOverride, isVisible, null);
								break;
							case "long":
								cachedAction.SetProperty(deName, Convert.ToInt32(childNode.InnerText, CultureInfo.InvariantCulture), allowOverride, isVisible, null);
								break;
							case "double":
								cachedAction.SetProperty(deName, Convert.ToDouble(childNode.InnerText, CultureInfo.InvariantCulture), allowOverride, isVisible, null);
								break;
							case "datetime":
							case "date":
								cachedAction.SetProperty(deName, Convert.ToDateTime(childNode.InnerText, CultureInfo.InvariantCulture), allowOverride, isVisible, null);
								break;
							case "empty":
								cachedAction.SetProperty(deName, null, allowOverride, isVisible, null);
								break;
							case "stringarray":
								cachedAction.SetStringArrayProperty(deName, childNode.InnerText, allowOverride, isVisible, null);
								break;
							}

							break; //dataitem
						}
					case "datasource":
						{
							string asmName = childNode.Attributes.GetNamedItem("assembly").Value;
							string clsName = childNode.Attributes.GetNamedItem("class").Value;
							object datasourceObj = LoadObject(asmName, clsName);

							foreach (XmlNode dataMethod in childNode.ChildNodes)
							{
								string methodName = GetNameAttribute(dataMethod);
								MethodInfo methodInfo = datasourceObj.GetType().GetMethod(methodName);
								if (methodInfo != null)
									cachedAction.SetProperty(deName, methodInfo.Invoke(datasourceObj, null), allowOverride, isVisible, null);
								else
								{
									PropertyInfo propInfo = datasourceObj.GetType().GetProperty(methodName);
									if (propInfo != null)
									{
										if (isCustomProperty)
										{
											// If this is a custom property that has been mapped to a system property, then the value needs
											// to be converted into an appropriate string. For all type of system property currently supported
											// this is satisfied by a ToString(), EXCEPT for a string array, which needs to be converted into
											// a single string delimited by semi-colons
											if (propInfo.PropertyType == typeof(string[]))
											{
												cachedAction.SetProperty(deName, Utils.StringArrayToDelimitedString(propInfo.GetValue(datasourceObj, null) as string[], ';'), allowOverride, isVisible, null);
											}
											else
											{
												cachedAction.SetProperty(deName, propInfo.GetValue(datasourceObj, null).ToString(), allowOverride, isVisible, null);
											}
										}
										else
										{
											// It's not a custom property, so populate the property with the object value
											cachedAction.SetProperty(deName, propInfo.GetValue(datasourceObj, null), allowOverride, isVisible, null);
										}
									}
								}
							}
							break;
						}
					default:
						break;
					}
				}
			}
			return cachedAction;
		}