public override IFieldTemplate CreateFieldTemplate(MetaColumn column, DataBoundControlMode mode, string uiHint)
        {
            if (column.IsReadOnly)// code to fix caching issue
                    mode = DataBoundControlMode.ReadOnly;

               return base.CreateFieldTemplate(column, mode, uiHint);
        }
Example #2
0
        public virtual string BuildVirtualPath(string templateName, DataBoundControlMode mode)
        {
            if (String.IsNullOrEmpty(templateName))
            {
                throw new ArgumentNullException("uiHint");
            }

            string str = null;

            switch (mode)
            {
            case DataBoundControlMode.ReadOnly:
                str = string.Empty;
                break;

            case DataBoundControlMode.Edit:
                str = "_Edit";
                break;

            case DataBoundControlMode.Insert:
                str = "_Insert";
                break;
            }

            return(String.Format(CultureInfo.InvariantCulture, TemplateFolderVirtualPath + "{0}{1}.ascx", new object[] { templateName, str }));
        }
Example #3
0
        // Methods
        public FieldGenerator( MetaTable table, Control dataBoundControl, DataBoundControlMode mode )
        {
            this._table = table;
            this._dataBoundControl = dataBoundControl;
            this._mode = mode;

            List<MetaColumn> columns = new List<MetaColumn>( _table.Columns );

            //упорядочить колонки в порядке следования в мета-классе.
            var metadataTypeAttribute = (MetadataTypeAttribute)Attribute.GetCustomAttribute( _table.EntityType, typeof( MetadataTypeAttribute ), false );
            if( metadataTypeAttribute != null )
            {
                int index = 0;
                foreach( var memberInfo in metadataTypeAttribute.MetadataClassType.GetMembers().Where( m => m.MemberType == MemberTypes.Field || m.MemberType == MemberTypes.Property ) )
                {
                    int pos = columns.FindIndex( c => c.Name == memberInfo.Name );
                    if( pos >= 0 )
                    {
                        MetaColumn column = columns[ pos ];
                        columns.RemoveAt( pos );
                        columns.Insert( index++, column );
                    }
                }
            }
            _columns = columns;
        }
Example #4
0
        protected string Template(string expression, string templateName,
                                  string htmlElementName, DataBoundControlMode mode)
        {
            Type   containerType = null;
            Type   modelType     = null;
            object modelValue    = null;
            string propertyName  = null;

            ViewDataInfo vdi = Context.ViewData.GetViewDataInfo(expression);

            if (vdi != null)
            {
                containerType = vdi.Container.GetType();

                if (vdi.Descriptor != null)
                {
                    propertyName = vdi.Descriptor.Name;
                    modelType    = vdi.Descriptor.PropertyType;
                }

                modelValue = vdi.Value;
                if (modelValue != null)
                {
                    modelType = modelValue.GetType();
                }
            }

            return(Render(mode, templateName, htmlElementName ?? expression,
                          containerType, modelType ?? typeof(string), propertyName, modelValue));
        }
        private string GetEntityTemplateVirtualPathWithCaching(MetaTable table, DataBoundControlMode mode, string uiHint) {
            long cacheKey = Misc.CombineHashCodes(table, mode, uiHint);

            return _factory.GetTemplatePath(cacheKey, delegate() {
                return GetEntityTemplateVirtualPath(table, mode, uiHint);
            });
        }
Example #6
0
        string GetVirtualPathForMode(string uiHint, MetaTable table, DataBoundControlMode mode)
        {
            if (!String.IsNullOrEmpty(uiHint))
            {
                string str = GetVirtualPathIfExists(uiHint, table, mode);
                if (str != null)
                {
                    return(str);
                }
            }

            // REVIEW: MetaTable doesn't have a DataTypeAttribute; should it?

            //if (column.DataTypeAttribute != null) {
            //    string dataTypeName = column.DataTypeAttribute.GetDataTypeName();
            //    result = GetVirtualPathIfExists(dataTypeName, column, mode);
            //    if (result != null) {
            //        return result;
            //    }
            //}

            return(GetVirtualPathIfExists(table.EntityType.FullName, table, mode) ??
                   GetVirtualPathIfExists(table.EntityType.Name, table, mode) ??
                   GetVirtualPathIfExists("Default", table, mode));
        }
        private bool IsScaffoldColumn(IMetaColumn column, DataBoundControlMode mode, ContainerType containerType)
        {
            if (!column.Scaffold)
            {
                return(false);
            }

            // 1:Many children columns don't make sense for new rows, so ignore them in Insert mode
            if (mode == DataBoundControlMode.Insert)
            {
                var childrenColumn = column as IMetaChildrenColumn;
                if (childrenColumn != null && !childrenColumn.IsManyToMany)
                {
                    return(false);
                }
            }

            var fkColumn = column as IMetaForeignKeyColumn;

            if (fkColumn != null)
            {
                // Ignore the FK column if the user doesn't have access to the parent table
                if (!fkColumn.ParentTable.CanRead(Context.User))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #8
0
        private string GetEntityTemplateVirtualPathWithCaching(MetaTable table, DataBoundControlMode mode, string uiHint)
        {
            long cacheKey = Misc.CombineHashCodes(table, mode, uiHint);

            return(_factory.GetTemplatePath(cacheKey, delegate() {
                return GetEntityTemplateVirtualPath(table, mode, uiHint);
            }));
        }
Example #9
0
        internal string Render(DataBoundControlMode mode, string templateName,
                               string expression, Type parentModelType, Type modelType,
                               string propertyName, object value)
        {
            ModelMetadata metadata = GetMetadata(parentModelType, modelType, propertyName);

            return(Render(mode, metadata, templateName, expression, value));
        }
Example #10
0
 internal static Dictionary <string, Func <HtmlHelper, string> > GetDefaultActions(
     DataBoundControlMode mode
     )
 {
     return(mode == DataBoundControlMode.ReadOnly
       ? _defaultDisplayActions
       : _defaultEditorActions);
 }
        /// <summary>
        /// Returns an enumeration of columns that are to be displayed in a scaffolded context. By default all columns with the Scaffold
        /// property set to true are included, with the exception of:
        /// <ul>
        /// <li>Long-string columns (IsLongString property set to true) when the inListControl flag is true</li>
        /// <li>Children columns when mode is equal to Insert</li>
        /// </ul>
        /// </summary>
        /// <param name="mode">The mode, such as ReadOnly, Edit, or Insert.</param>
        /// <param name="inListControl">A flag indicating if the table is being displayed as an individual entity or as part of list-grid.</param>
        /// <returns></returns>
        public virtual IEnumerable <MetaColumn> GetScaffoldColumns(DataBoundControlMode mode, ContainerType containerType)
        {
            IDictionary <string, int> columnGroupOrder = GetColumnGroupingOrder();

            return(Columns.Where(c => IsScaffoldColumn(c, mode, containerType))
                   .OrderBy(c => GetColumnOrder(c, columnGroupOrder))
                   .ThenBy(c => GetColumnOrder(c)));
        }
        private bool IncludeField(MetaColumn column, DataBoundControlMode mode) {

            // Exclude bool columns in Insert mode (just to test custom filtering)
            if (mode == DataBoundControlMode.Insert && column.ColumnType == typeof(bool))
                return false;

            return true;
        }
        public override string BuildEntityTemplateVirtualPath(string templateName, DataBoundControlMode mode)
        {
            string path = base.BuildEntityTemplateVirtualPath(templateName, mode);

            if (File.Exists(HttpContext.Current.Server.MapPath(path)))
                return path;

            return path.Replace("_" + mode.ToString(), "");
        }
Example #14
0
        public virtual IEnumerable <MetaColumn> GetScaffoldColumns(DataBoundControlMode mode, ContainerType containerType)
        {
            IDictionary <string, int> columnGroupOrder = this.GetColumnGroupingOrder();

            return(from c in this.Columns
                   where this.IsScaffoldColumn(c, mode, containerType)
                   orderby GetColumnOrder(c, columnGroupOrder), GetColumnOrder(c)
                   select c);
        }
 protected string GetNewDataSourceName(Type controlType, DataBoundControlMode mode)
 {
     DataControlFieldsEditor designerForm = this.DesignerForm as DataControlFieldsEditor;
     if (designerForm != null)
     {
         return designerForm.GetNewDataSourceName(controlType, mode);
     }
     return string.Empty;
 }
        // Internal for unit test purpose
        internal string GetFieldTemplateVirtualPathWithCaching(MetaColumn column, DataBoundControlMode mode, string uiHint)
        {
            // Compute a cache key based on all the input paramaters
            long cacheKey = Misc.CombineHashCodes(uiHint, column, mode);

            Func <string> templatePathFactoryFunction = () => GetFieldTemplateVirtualPath(column, mode, uiHint);

            return(_templateFactory.GetTemplatePath(cacheKey, templatePathFactoryFunction));
        }
        protected string GetNewDataSourceName(Type controlType, DataBoundControlMode mode)
        {
            DataControlFieldsEditor designerForm = this.DesignerForm as DataControlFieldsEditor;

            if (designerForm != null)
            {
                return(designerForm.GetNewDataSourceName(controlType, mode));
            }
            return(string.Empty);
        }
Example #18
0
 // Unit testing version
 internal static string Template(HtmlHelper html, string expression, string templateName, string htmlFieldName,
                                 DataBoundControlMode mode, object additionalViewData, TemplateHelperDelegate templateHelper)
 {
     return(templateHelper(html,
                           ModelMetadata.FromStringExpression(expression, html.ViewData),
                           htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
                           templateName,
                           mode,
                           additionalViewData));
 }
Example #19
0
        private bool IncludeField(MetaColumn column, DataBoundControlMode mode)
        {
            // Exclude bool columns in Insert mode (just to test custom filtering)
            if (mode == DataBoundControlMode.Insert && column.ColumnType == typeof(bool))
            {
                return(false);
            }

            return(true);
        }
Example #20
0
        public virtual string BuildEntityTemplateVirtualPath(string templateName, DataBoundControlMode mode)
        {
            if (templateName == null)
            {
                throw new ArgumentNullException("templateName");
            }

            string modeString = mode == DataBoundControlMode.ReadOnly ? String.Empty : "_" + mode.ToString();

            return(String.Format(CultureInfo.InvariantCulture, this.TemplateFolderVirtualPath + "{0}{1}.ascx", templateName, modeString));
        }
Example #21
0
        string GetVirtualPathIfExists(string templateName, MetaTable table, DataBoundControlMode mode)
        {
            string virtualPath = BuildVirtualPath(templateName, mode);

            if (VirtualPathProvider.FileExists(virtualPath))
            {
                return(virtualPath);
            }

            return(null);
        }
Example #22
0
        Type GetFallbackType(Type columnType, MetaColumn column, DataBoundControlMode mode)
        {
            Type ret;

            if (typeFallbacks.TryGetValue(columnType, out ret))
            {
                return(ret);
            }

            return(null);
        }
Example #23
0
        public static string DynamicField(this HtmlHelper html, string uiHint, DataBoundControlMode mode, Expression <Func <object> > expression)
        {
            object entity;
            string fieldName;

            if (!ExpressionUtility.TryGetEntityAndFieldNameFromExpression(expression.Body, out entity, out fieldName))
            {
                throw new ArgumentException("DynamicField expression of unknown type: " + expression.Body.GetType().FullName + "\r\n" + expression.Body.ToString());
            }

            return(DynamicField(html, entity, fieldName, uiHint, mode));
        }
        public virtual EntityTemplateUserControl CreateEntityTemplate(MetaTable table, DataBoundControlMode mode, string uiHint) {
            if (table == null) {
                throw new ArgumentNullException("table");
            }

            string entityTemplatePath = GetEntityTemplateVirtualPathWithCaching(table, mode, uiHint);
            if (entityTemplatePath == null) {
                return null;
            }

            return _templateInstantiator(entityTemplatePath);
        }
        protected virtual DynamicField CreateField(MetaColumn column, ContainerType containerType, DataBoundControlMode mode) {            
            string headerText = (containerType == ContainerType.List ? column.ShortDisplayName : column.DisplayName);

            var field = new DynamicField() {
                DataField = column.Name,
                HeaderText = headerText
            };
            // Turn wrapping off by default so that error messages don't show up on the next line.
            field.ItemStyle.Wrap = false;

            return field;
        }
Example #26
0
 private string GetVirtualPathForMode(string candidateName, DataBoundControlMode mode)
 {
     if (String.IsNullOrEmpty(candidateName))
     {
         return(null);
     }
     else
     {
         string templatePath = BuildEntityTemplateVirtualPath(candidateName, mode);
         return(_factory.FileExists(templatePath) ? templatePath : null);
     }
 }
        /// <summary>
        /// See IFieldTemplateFactory for details.
        /// </summary>
        /// <returns></returns>
        public virtual IFieldTemplate CreateFieldTemplate(MetaColumn column, DataBoundControlMode mode, string uiHint)
        {
            string fieldTemplatePath = GetFieldTemplateVirtualPathWithCaching(column, mode, uiHint);

            if (fieldTemplatePath == null)
            {
                return(null);
            }

            return((IFieldTemplate)BuildManager.CreateInstanceFromVirtualPath(
                       fieldTemplatePath, typeof(IFieldTemplate)));
        }
Example #28
0
        public virtual IFieldTemplate CreateFieldTemplate(MetaColumn column, DataBoundControlMode mode, string uiHint)
        {
            // NO checks are made on parameters in .NET, but well "handle" the NREX
            // throws in the other methods
            string virtualPath = GetFieldTemplateVirtualPath(column, mode, uiHint);

            if (String.IsNullOrEmpty(virtualPath))
            {
                return(null);
            }

            return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(IFieldTemplate)) as IFieldTemplate);
        }
Example #29
0
        public virtual IEntityTemplate CreateEntityTemplate(MetaTable table, ref DataBoundControlMode mode, string uiHint)
        {
            mode = PreprocessMode(table, mode);

            string virtualPath = this.GetEntityTemplateVirtualPath(table, mode, uiHint);

            if (virtualPath == null)
            {
                return(null);
            }

            return((IEntityTemplate)BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(IEntityTemplate)));
        }
Example #30
0
        public virtual string GetEntityTemplateVirtualPath(MetaTable table, DataBoundControlMode mode, string uiHint)
        {
            for (DataBoundControlMode attemptedMode = mode; attemptedMode >= DataBoundControlMode.ReadOnly; attemptedMode -= 1)
            {
                string str = this.GetVirtualPathForMode(uiHint, table, attemptedMode);
                if (str != null)
                {
                    return(str);
                }
            }

            return(null);
        }
        /// <summary>
        /// Gets a chance to change the mode.  e.g. an Edit mode request can be turned into ReadOnly mode
        /// if the column is a primary key
        /// </summary>
        public virtual DataBoundControlMode PreprocessMode(MetaColumn column, DataBoundControlMode mode)
        {
            if (column == null)
            {
                throw new ArgumentNullException("column");
            }

            // Primary keys can't be edited, so put them in readonly mode.  Note that this
            // does not apply to Insert mode, which is fine
            if (column.IsPrimaryKey && mode == DataBoundControlMode.Edit)
            {
                mode = DataBoundControlMode.ReadOnly;
            }

            // Generated columns should never be editable/insertable
            if (column.IsGenerated)
            {
                mode = DataBoundControlMode.ReadOnly;
            }

            // ReadOnly columns cannot be edited nor inserted, and are always in Display mode
            if (column.IsReadOnly)
            {
                if (mode == DataBoundControlMode.Insert && column.AllowInitialValue)
                {
                    // but don't change the mode if we're in insert and an initial value is allowed
                }
                else
                {
                    mode = DataBoundControlMode.ReadOnly;
                }
            }

            // If initial value is not allowed set mode to ReadOnly
            if (mode == DataBoundControlMode.Insert && !column.AllowInitialValue)
            {
                mode = DataBoundControlMode.ReadOnly;
            }

            if (column is MetaForeignKeyColumn)
            {
                // If the foreign key is part of the primary key (e.g. Order and Product in Order_Details table),
                // change the mode to ReadOnly so that they can't be edited.
                if (mode == DataBoundControlMode.Edit && ((MetaForeignKeyColumn)column).IsPrimaryKeyInThisTable)
                {
                    mode = DataBoundControlMode.ReadOnly;
                }
            }

            return(mode);
        }
Example #32
0
        string ColumnTypeToSpecialName(Type columnType, MetaColumn column, DataBoundControlMode mode)
        {
            if (columnType == typeof(int))
            {
                return(GetExistingTemplateVirtualPath("Integer", column, mode));
            }

            if (columnType == typeof(string))
            {
                return(GetExistingTemplateVirtualPath("Text", column, mode));
            }

            return(null);
        }
        private string GetVirtualPathForMode(string templateName, MetaColumn column, DataBoundControlMode mode)
        {
            // If we got a template name, try it
            if (!String.IsNullOrEmpty(templateName))
            {
                string virtualPath = GetVirtualPathIfExists(templateName, column, mode);
                if (virtualPath != null)
                {
                    return(virtualPath);
                }
            }

            // Otherwise, use the column's type
            return(GetVirtualPathForTypeWithFallback(column.ColumnType, column, mode));
        }
Example #34
0
 public override IEnumerable<MetaColumn> GetScaffoldColumns(DataBoundControlMode mode, ContainerType containerType)
 {
     if (_getVisibleColumns == null)
      {
           var visibleColumn = base.GetScaffoldColumns(mode, containerType);
           var secureColumns = from column in visibleColumn
                               where column.ColumnIsVisible()
                               select column;
           return secureColumns;
      }
      else
      {
           return _getVisibleColumns(base.GetScaffoldColumns(mode, containerType));
      }
 }
        public ICollection GenerateFields(Control control)
        {
            DataBoundControlMode mode          = GetMode(control);
            ContainerType        containerType = GetControlContainerType(control);

            // Auto-generate fields from metadata.
            List <DynamicField> fields = new List <DynamicField>();

            foreach (MetaColumn column in _metaTable.GetScaffoldColumns(mode, containerType))
            {
                fields.Add(CreateField(column, containerType, mode));
            }

            return(fields);
        }
Example #36
0
        public ICollection GenerateFields(Control control)
        {
            DataBoundControlMode mode = GetMode(control);

            // Get all of table's columns, take only the ones that should be automatically included in a fields collection,
            // sort the result by the ColumnOrderAttribute, and for each column create a DynamicField
            var fields = from column in _table.GetScaffoldColumns(mode, _containerType)
                         where IncludeField(column)
                         select new DynamicField()
            {
                DataField  = column.Name,
                HeaderText = column.DisplayName
            };

            return(fields.ToList());
        }
Example #37
0
 internal static string TemplateHelper(
     HtmlHelper html,
     ModelMetadata metadata,
     string htmlFieldName,
     string templateName,
     DataBoundControlMode mode,
     object additionalViewData
     )
 {
     return(TemplateHelper(
                html,
                metadata,
                htmlFieldName,
                templateName,
                mode,
                additionalViewData,
                ExecuteTemplate
                ));
 }
        public override IFieldTemplate CreateFieldTemplate(MetaColumn column, DataBoundControlMode mode, string uiHint) {
            // Call Preprocess mode so that we do set the right mode base on the the column's attributes
            mode = PreprocessMode(column, mode);
            bool readOnly = (mode == DataBoundControlMode.ReadOnly);
            // If the folder doesn't exist use the fallback
            if (!DirectoryExists) {
                return CreateFieldTemplate(readOnly, column);
            }

            // Always see check if the base found anything first then fall back to the simple field template
            IFieldTemplate fieldTemplate = base.CreateFieldTemplate(column, mode, uiHint);

            // If there was no field template found and the user specified a uiHint then use the default behavior
            if (!String.IsNullOrEmpty(uiHint)) {
                return fieldTemplate;
            }
            
            return fieldTemplate ?? CreateFieldTemplate(readOnly, column);
        }
Example #39
0
 // Unit testing version
 internal static string TemplateFor <TContainer, TValue>(
     this HtmlHelper <TContainer> html,
     Expression <Func <TContainer, TValue> > expression,
     string templateName,
     string htmlFieldName,
     DataBoundControlMode mode,
     object additionalViewData,
     TemplateHelperDelegate templateHelper
     )
 {
     return(templateHelper(
                html,
                ModelMetadata.FromLambdaExpression(expression, html.ViewData),
                htmlFieldName ?? ExpressionHelper.GetExpressionText(expression),
                templateName,
                mode,
                additionalViewData
                ));
 }
        private string GetVirtualPathFallback(MetaTable table, DataBoundControlMode mode, string uiHint, DataBoundControlMode minModeToFallBack) {
            if (mode < minModeToFallBack) {
                return null;
            }

            // the strategy is to go over each candidate name and try to find an existing template for
            // each mode between 'mode' and 'minModeToFallBack'
            // note that GetVirtualPathForMode will return null for empty names (e.g. when the uiHint is not specified)
            string[] fallbackNames = new string[] { uiHint, table.Name, s_defaultTemplateName };
            foreach (var name in fallbackNames) {
                for (var currentMode = mode; currentMode >= minModeToFallBack; currentMode--) {
                    string virtualPath = GetVirtualPathForMode(name, currentMode);
                    if (virtualPath != null) {
                        return virtualPath;
                    }
                }
            }
            return null;
        }
Example #41
0
        string GetExistingTemplateVirtualPath(string baseName, MetaColumn column, DataBoundControlMode mode)
        {
            string templatePath = BuildVirtualPath(baseName, column, mode);

            if (String.IsNullOrEmpty(templatePath))
            {
                return(null);
            }

            // TODO: cache positive hits (and watch for removal events on those)
            string physicalPath = HostingEnvironment.MapPath(templatePath);

            if (File.Exists(physicalPath))
            {
                return(templatePath);
            }

            return(null);
        }
        public virtual string GetEntityTemplateVirtualPath(MetaTable table, DataBoundControlMode mode, string uiHint) {
            if (table == null) {
                throw new ArgumentNullException("table");
            }

            // Fallback order is as follows (where CustomProducts is the uiHint)
            //    CustomProducts_Insert
            //    CustomProducts_Edit
            //    Products_Insert
            //    Products_Edit
            //    Default_Insert
            //    Default_Edit
            //    CustomProducts_ReadOnly
            //    Products_ReadOnly
            //    Default_ReadOnly
            //
            // If nothing matches null is returned

            return GetVirtualPathFallback(table, mode, uiHint, DataBoundControlMode.Edit) ??
                GetVirtualPathFallback(table, DataBoundControlMode.ReadOnly, uiHint, DataBoundControlMode.ReadOnly);
        }
Example #43
0
        public virtual string BuildVirtualPath(string templateName, DataBoundControlMode mode)
        {
            if (String.IsNullOrEmpty(templateName)) {
                throw new ArgumentNullException("uiHint");
            }

            string str = null;

            switch (mode) {
                case DataBoundControlMode.ReadOnly:
                    str = string.Empty;
                    break;

                case DataBoundControlMode.Edit:
                    str = "_Edit";
                    break;

                case DataBoundControlMode.Insert:
                    str = "_Insert";
                    break;
            }

            return String.Format(CultureInfo.InvariantCulture, TemplateFolderVirtualPath + "{0}{1}.ascx", new object[] { templateName, str });
        }
        /// <summary>
        /// See IFieldTemplateFactory for details.
        /// </summary>
        /// <returns></returns>
        public virtual IFieldTemplate CreateFieldTemplate(MetaColumn column, DataBoundControlMode mode, string uiHint) {
            string fieldTemplatePath = GetFieldTemplateVirtualPathWithCaching(column, mode, uiHint);

            if (fieldTemplatePath == null)
                return null;

            return (IFieldTemplate)BuildManager.CreateInstanceFromVirtualPath(
                fieldTemplatePath, typeof(IFieldTemplate));
        }
Example #45
0
		public virtual string GetFieldTemplateVirtualPath (MetaColumn column, DataBoundControlMode mode, string uiHint)
		{
			// NO checks are made on parameters in .NET, but well "handle" the NREX
			// throws in the other methods
			DataBoundControlMode newMode = PreprocessMode (column, mode);

			// The algorithm is as follows:
			//
			//  1. If column has a DataTypeAttribute on it, get the data type
			//     - if it's Custom data type, uiHint is used unconditionally
			//     - if it's not a custom type, ignore uiHint and choose template based
			//       on type
			//
			//  2. If #1 is false and uiHint is not empty, use uiHint if the template
			//     exists
			//
			//  3. If #2 is false, look up type according to the following algorithm:
			//
			//     1. lookup column type's full name
			//     2. if #1 fails, look up short type name
			//     3. if #2 fails, map type to special type name (Int -> Integer, String
			//        -> Text etc)
			//     4. if #3 fails, try to find a fallback type
			//     5. if #4 fails, check if it's a foreign key or child column
			//     6. if #5 fails, return null
			//
			//     From: http://msdn.microsoft.com/en-us/library/cc488523.aspx (augmented)
			//

			DataTypeAttribute attr = column.DataTypeAttribute;
			bool uiHintPresent = !String.IsNullOrEmpty (uiHint);
			string templatePath = null;
			int step = uiHintPresent ? 0 : 1;
			Type columnType = column.ColumnType;

			if (!uiHintPresent && attr == null) {
				if (column is MetaChildrenColumn)
					templatePath = GetExistingTemplateVirtualPath ("Children", column, newMode);
				else if (column is MetaForeignKeyColumn)
					templatePath = GetExistingTemplateVirtualPath ("ForeignKey", column, newMode);
			}
			
			while (step < 6 && templatePath == null) {
				switch (step) {
					case 0:
						templatePath = GetExistingTemplateVirtualPath (uiHint, column, newMode);
						break;

					case 1:
						if (attr != null)
							templatePath = GetTemplateForDataType (attr.DataType, attr.GetDataTypeName (), uiHint, column, newMode);
						break;
							
					case 2:
						templatePath = GetExistingTemplateVirtualPath (columnType.FullName, column, newMode);
						break;

					case 3:
						templatePath = GetExistingTemplateVirtualPath (columnType.Name, column, newMode);
						break;

					case 4:
						templatePath = ColumnTypeToSpecialName (columnType, column, newMode);
						break;

					case 5:
						columnType = GetFallbackType (columnType, column, newMode);
						if (columnType == null)
							step = 5;
						else
							step = uiHintPresent ? 0 : 1;
						break;
				}

				step++;
			}

			return templatePath;
		}
Example #46
0
		Type GetFallbackType (Type columnType, MetaColumn column, DataBoundControlMode mode)
		{
			Type ret;
			if (typeFallbacks.TryGetValue (columnType, out ret))
				return ret;
			
			return null;
		}
Example #47
0
		public virtual DataBoundControlMode PreprocessMode (MetaColumn column, DataBoundControlMode mode)
		{
			// In good tradition of .NET's DynamicData, let's not check the
			// parameters...
			if (column == null)
				throw new NullReferenceException ();

			if (column.IsGenerated)
				return DataBoundControlMode.ReadOnly;
			
			if (column.IsPrimaryKey) {
				if (mode == DataBoundControlMode.Edit)
					return DataBoundControlMode.ReadOnly;
			}
			
			return mode;	
		}
Example #48
0
 public string Render(HtmlHelper html, ModelMetadata metadata, string htmlFieldName, string templateName, DataBoundControlMode readOnly, object additionalViewData, AjaxOptions ajaxOptions)
 {
     return IfaTemplateHelpers.TemplateHelper(html, metadata, htmlFieldName, templateName, readOnly,
                                              additionalViewData, ajaxOptions, GetIfaTheme(html));
 }
        private string GetVirtualPathForTypeWithFallback(Type fieldType, MetaColumn column, DataBoundControlMode mode) {

            string templateName;
            string virtualPath;

            // If we have a data type attribute
            if (column.DataTypeAttribute != null) {
                templateName = column.DataTypeAttribute.GetDataTypeName();

                // Try to get the path from it
                virtualPath = GetVirtualPathIfExists(templateName, column, mode);
                if (virtualPath != null)
                    return virtualPath;
            }

            // Try the actual fully qualified type name (i.e. with the namespace)
            virtualPath = GetVirtualPathIfExists(fieldType.FullName, column, mode);
            if (virtualPath != null)
                return virtualPath;

            // Try the simple type name
            virtualPath = GetVirtualPathIfExists(fieldType.Name, column, mode);
            if (virtualPath != null)
                return virtualPath;

            // If our type name table has an entry for it, try it
            if (_typesToTemplateNames.TryGetValue(fieldType, out templateName)) {
                virtualPath = GetVirtualPathIfExists(templateName, column, mode);
                if (virtualPath != null)
                    return virtualPath;
            }

            // Check if there is a fallback type
            Type fallbackType = GetFallBackType(fieldType);

            // If not, we've run out of options
            if (fallbackType == null)
                return null;

            // If so, try it
            return GetVirtualPathForTypeWithFallback(fallbackType, column, mode);
        }
 public override string GetEntityTemplateVirtualPath(MetaTable table, DataBoundControlMode mode, string uiHint)
 {
     return base.GetEntityTemplateVirtualPath(table, mode, uiHint);
 }
 public override EntityTemplateUserControl CreateEntityTemplate(MetaTable table, DataBoundControlMode mode, string uiHint)
 {
     return base.CreateEntityTemplate(table, mode, uiHint);
 }
Example #52
0
		string GetTemplateForDataType (DataType dataType, string customDataType, string uiHint, MetaColumn column, DataBoundControlMode mode)
		{
			switch (dataType) {
				case DataType.Custom:
					return GetExistingTemplateVirtualPath (customDataType, column, mode);

				case DataType.DateTime:
					return GetExistingTemplateVirtualPath ("DateTime", column, mode);

				case DataType.MultilineText:
					return GetExistingTemplateVirtualPath ("MultilineText", column, mode);
					
				default:
					return GetExistingTemplateVirtualPath ("Text", column, mode);
			}
		}
        /// <summary>
        /// Build the virtual path to the field template user control based on the template name and mode.
        /// By default, it returns names that look like TemplateName_ModeName.ascx, in the folder specified
        /// by TemplateFolderVirtualPath.
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="column"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public virtual string BuildVirtualPath(string templateName, MetaColumn column, DataBoundControlMode mode) {
            if (String.IsNullOrEmpty(templateName)) {
                throw new ArgumentNullException("templateName");
            }

            string modePathModifier = null;
            switch (mode) {
                case DataBoundControlMode.ReadOnly:
                    modePathModifier = String.Empty;
                    break;
                case DataBoundControlMode.Edit:
                    modePathModifier = FieldTemplateFactory.EditModePathModifier;
                    break;
                case DataBoundControlMode.Insert:
                    modePathModifier = FieldTemplateFactory.InsertModePathModifier;
                    break;
                default:
                    Debug.Assert(false);
                    break;
            }

            return String.Format(CultureInfo.InvariantCulture,
                TemplateFolderVirtualPath + "{0}{1}.ascx", templateName, modePathModifier);
        }
Example #54
0
		string GetExistingTemplateVirtualPath (string baseName, MetaColumn column, DataBoundControlMode mode)
		{
			string templatePath = BuildVirtualPath (baseName, column, mode);
			if (String.IsNullOrEmpty (templatePath))
				return null;

			// TODO: cache positive hits (and watch for removal events on those)
			string physicalPath = HostingEnvironment.MapPath (templatePath);
			if (File.Exists (physicalPath))
				return templatePath;

			return null;
		}
        private string GetVirtualPathIfExists(string templateName, MetaColumn column, DataBoundControlMode mode) {
            // Build the path
            string virtualPath = BuildVirtualPath(templateName, column, mode);

            // Check if it exists
            if (_templateFactory.FileExists(virtualPath))
                return virtualPath;

            // If not, return null
            return null;
        }
Example #56
0
		string ColumnTypeToSpecialName (Type columnType, MetaColumn column, DataBoundControlMode mode)
		{
			if (columnType == typeof (int))
				return GetExistingTemplateVirtualPath ("Integer", column, mode);

			if (columnType == typeof (string))
				return GetExistingTemplateVirtualPath ("Text", column, mode);
			
			return null;
		}
 internal string GetNewDataSourceName(System.Type controlType, DataBoundControlMode mode)
 {
     if (mode == DataBoundControlMode.Edit)
     {
         return this.GetNewDataSourceName(controlType, 1);
     }
     if (mode == DataBoundControlMode.Insert)
     {
         return this.GetNewDataSourceName(controlType, 2);
     }
     return this.GetNewDataSourceName(controlType, 0);
 }
Example #58
0
		public virtual string BuildVirtualPath (string templateName, MetaColumn column, DataBoundControlMode mode)
		{
			// Tests show the 'column' parameter is not used here
			
			if (String.IsNullOrEmpty (templateName))
				throw new ArgumentNullException ("templateName");

			string basePath = TemplateFolderVirtualPath;
			string suffix;

			switch (mode) {
				default:
				case DataBoundControlMode.ReadOnly:
					suffix = String.Empty;
					break;

				case DataBoundControlMode.Edit:
					suffix = "_Edit";
					break;

				case DataBoundControlMode.Insert:
					suffix = "_Insert";
					break;
			}
			
			return basePath + templateName + suffix + ".ascx";
		}
Example #59
0
		public virtual IFieldTemplate CreateFieldTemplate (MetaColumn column, DataBoundControlMode mode, string uiHint)
		{
			// NO checks are made on parameters in .NET, but well "handle" the NREX
			// throws in the other methods
			string virtualPath = GetFieldTemplateVirtualPath (column, mode, uiHint);
			if (String.IsNullOrEmpty (virtualPath))
				return null;
			
			return BuildManager.CreateInstanceFromVirtualPath (virtualPath, typeof (IFieldTemplate)) as IFieldTemplate;
		}
        private string GetVirtualPathForMode(string templateName, MetaColumn column, DataBoundControlMode mode) {

            // If we got a template name, try it
            if (!String.IsNullOrEmpty(templateName)) {
                string virtualPath = GetVirtualPathIfExists(templateName, column, mode);
                if (virtualPath != null)
                    return virtualPath;
            }

            // Otherwise, use the column's type
            return GetVirtualPathForTypeWithFallback(column.ColumnType, column, mode);
        }