Example #1
0
		/// <summary>
		/// Creates an instance of <see cref="ChildType"/> from <paramref name="descriptor"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="descriptor">The <see cref="ChildTypeDescriptor"/>.</param>
		/// <param name="behavior">The <see cref="CmsBehavior"/>.</param>
		public static void Create(IMansionContext context, ChildTypeDescriptor descriptor, CmsBehavior behavior)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (descriptor == null)
				throw new ArgumentNullException("descriptor");
			if (behavior == null)
				throw new ArgumentNullException("behavior");

			// get the type
			var type = descriptor.Properties.Get<ITypeDefinition>(context, "type", null);
			var baseType = descriptor.Properties.Get<ITypeDefinition>(context, "baseType", null);
			if (type == null && baseType == null)
				throw new InvalidOperationException(string.Format("Invalid child type descriptor on type '{0}'. Specify either an type or a baseType.", descriptor.TypeDefinition.Name));
			if (type != null && baseType != null)
				throw new InvalidOperationException(string.Format("Invalid child type descriptor on type '{0}'. Ambigious type detected. Specify either an type or a baseType.", descriptor.TypeDefinition.Name));

			if (type != null)
				CreateChildType(context, descriptor, behavior, type);
			else
			{
				CreateChildType(context, descriptor, behavior, baseType);
				foreach (var inheritingType in baseType.GetInheritingTypes(context))
					CreateChildType(context, descriptor, behavior, inheritingType);
			}
		}
		/// <summary>
		/// Creates an instance of <see cref="CmsBehavior"/> from the <paramref name="descriptor"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="descriptor">The <see cref="CmsBehaviorDescriptor"/> from which to extract the behavoir.</param>
		/// <returns>Returns the <see cref="CmsBehavior"/> instance.</returns>
		public static CmsBehavior Create(IMansionContext context, CmsBehaviorDescriptor descriptor)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (descriptor == null)
				throw new ArgumentNullException("descriptor");

			// set the properties
			var behavior = new CmsBehavior
			               {
			               	Label = descriptor.Properties.Get(context, "label", descriptor.TypeDefinition.Name),
			               	PathToIcon = descriptor.Properties.Get(context, "icon", string.Empty),
			               	IsAbstract = descriptor.Properties.Get(context, "abstract", false),
			               	CanChangeOrder = descriptor.Properties.Get(context, "reorderable", true),
			               	CanMove = descriptor.Properties.Get(context, "movable", true),
			               	CanCopy = descriptor.Properties.Get(context, "copyable", true),
			               	CanDelete = descriptor.Properties.Get(context, "deletable", true)
			               };

			//  add all the child type
			foreach (var childTypeDescriptor in descriptor.GetDescriptors<ChildTypeDescriptor>())
				childTypeDescriptor.SetChildTypes(context, behavior);

			// return the instantiated behavior
			return behavior;
		}
		/// <summary>
		/// Sets the <see cref="ChildType"/>s on the <paramref name="behavior"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="behavior">The <see cref="CmsBehavior"/>.</param>
		public void SetChildTypes(IMansionContext context, CmsBehavior behavior)
		{
			// validate argument
			if (context == null)
				throw new ArgumentNullException("context");
			if (behavior == null)
				throw new ArgumentNullException("behavior");

			// return the child type
			ChildType.Create(context, this, behavior);
		}
Example #4
0
		/// <summary>
		/// Creates the child type.
		/// </summary>
		/// <param name="context"></param>
		/// <param name="descriptor"></param>
		/// <param name="behavior"></param>
		/// <param name="type"></param>
		private static void CreateChildType(IMansionContext context, ChildTypeDescriptor descriptor, CmsBehavior behavior, ITypeDefinition type)
		{
			// create the child type
			var childType = new ChildType(type);

			// check if there is an is allowed expression
			var isAllowedExpressionString = descriptor.Properties.Get(context, "allowedExpression", string.Empty);
			if (!string.IsNullOrEmpty(isAllowedExpressionString))
			{
				// get the expresion script service
				var expressionScriptService = context.Nucleus.ResolveSingle<IExpressionScriptService>();

				// compile the script
				childType.IsAllowedExpression = expressionScriptService.Parse(context, new LiteralResource(isAllowedExpressionString));
			}

			behavior.Add(childType);
		}