Esempio n. 1
0
		/// <summary>
		/// Returns the named action property from the given set
		/// </summary>
		/// <param name="propertySet">The set of properties to search</param>
		/// <param name="propName">The name of the desired property</param>
		/// <returns>The property if it exists; null otherwise</returns>
		private IActionProperty GetActionProperty(IActionPropertySet properties, string propName)
		{
			if (properties != null)
			{
				IActionProperty prop;
				properties.TryGetValue(propName, out prop);
				return prop;
			}
			return null;
		}
		/// <summary>
		/// Helper to try and get a boolean property value
		/// </summary>
		/// <param name="propertySet">The property set to attempt the 'get' on</param>
		/// <param name="propName">The name of the property</param>
		/// <param name="defaultValue">A default value to return if the property does not exist</param>
		/// <returns>The value of the boolean property or the defaultValue</returns>
		private static bool TryGetProperty(IActionPropertySet propertySet, string propName, bool defaultValue)
		{
			IActionProperty prop;
			if (propertySet.TryGetValue(propName, out prop))
			{
				return Convert.ToBoolean(prop.Value, CultureInfo.InvariantCulture);
			}
			return defaultValue;
		}
		/// <summary>
		/// Helper to try and set a boolean property in a property set, if it exists
		/// </summary>
		/// <param name="propertySet">The property set to attempt the 'set' on</param>
		/// <param name="propName">The name of the property</param>
		/// <param name="value">The new value for the property</param>
		/// <returns>True if successful, false otherwise</returns>
		private static bool TrySetProperty(IActionPropertySet propertySet, string propName, bool value)
		{
			IActionProperty prop;
			if (propertySet.TryGetValue(propName, out prop))
			{
				prop.Value = value;
				return true;
			}
			return false;
		}
        /// <summary>
        /// Merges the filetype and all boolean properties from the source to the target property set
        /// </summary>
        /// <param name="source">The properties to merge from</param>
        /// <param name="target">The properties to merge to</param>
        /// <param name="assign">Whether to replace or merge (OR) boolean values in the target set</param>
        private static void MergePropertySets(IActionPropertySet source, IActionPropertySet target, bool assign)
        {
            IActionProperty sourceProp;
			source.SystemProperties.TryGetValue(PropertyNames.FileType, out sourceProp);
            if (sourceProp != null)
            {
                string sourceFileType = sourceProp.Value as string;
                if (!string.IsNullOrEmpty(sourceFileType))
                {
                    IActionProperty targetProp;
                    if (target.SystemProperties.TryGetValue(PropertyNames.FileType, out targetProp))
                    {
                        if (!(targetProp.Value as string).Contains(sourceFileType))
                        {
                            targetProp.Value += ";" + sourceFileType;
                        }
                    }
                    else
                    {
                        target.SystemProperties.Add(PropertyNames.FileType, sourceProp.Clone());
                    }
                }
            }

			foreach (IActionProperty property in source.Values)
			{
				IActionProperty targetProperty;
				if (!target.TryGetValue(property.DefaultDisplayName, out targetProperty))
				{
					target.Add(property.DefaultDisplayName, property.Clone());
					continue;
				}
				if (property.DataType != typeof(bool))
				{
					continue;
				}
				bool sourceValue = (bool) property.Value;
				if (assign)
				{
					targetProperty.Value = sourceValue;
				}
                else if (sourceValue)
				{
					targetProperty.Value = true;
				}
			}
        }