Ejemplo n.º 1
0
 internal DefaultAutoFieldGenerator(IMetaTable table)
 {
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     _metaTable = table;
 }
Ejemplo n.º 2
0
 // Fill a ListItemCollection with all the entries from a table
 public static void FillListItemCollection(IMetaTable table, ListItemCollection listItemCollection)
 {
     foreach (var o in table.GetQuery())
     {
         string text  = table.GetDisplayString(o);
         string value = table.GetPrimaryKeyString(o);
         listItemCollection.Add(new ListItem(text, value.TrimEnd()));
     }
 }
Ejemplo n.º 3
0
        bool IMetaModel.TryGetTable(Type entityType, out IMetaTable table)
        {
            MetaTable table2;

            table = null;
            if (this.TryGetTable(entityType, out table2))
            {
                table = table2;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
        bool IMetaModel.TryGetTable(string uniqueTableName, out IMetaTable table)
        {
            MetaTable table2;

            table = null;
            if (this.TryGetTable(uniqueTableName, out table2))
            {
                table = table2;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        bool IMetaModel.TryGetTable(Type entityType, out IMetaTable table)
        {
            MetaTable metaTable;

            table = null;
            if (TryGetTable(entityType, out metaTable))
            {
                table = metaTable;
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        bool IMetaModel.TryGetTable(string uniqueTableName, out IMetaTable table)
        {
            MetaTable metaTable;

            table = null;
            if (TryGetTable(uniqueTableName, out metaTable))
            {
                table = metaTable;
                return(true);
            }
            return(false);
        }
        private async Task RemoveBaseTreeHasLicence(IEntity entity, ISession session, IUnitOfWork unitOfWork, CancellationToken ct)
        {
            // Object is new or deleted --> return direct
            if (!entity.IsLoaded || entity.IsDeleted())
            {
                return;
            }

            // #27178 do not check if the licence management is deactivated
            if (!entity.Columns.Contains("IsLicenceNode"))
            {
                return;
            }

            var bOld = await entity.GetValueAsync <bool>("IsLicenceNode[O]", ct).ConfigureAwait(false);

            var bNew = await entity.GetValueAsync <bool>("IsLicenceNode", ct).ConfigureAwait(false);

            // Flag is removed
            if (bOld && !bNew)
            {
                // Build MN-TableName and FK-ColumName
                string strMNTable = entity.Tablename + "HasLicence";

                IMetaTable mTable = await session.MetaData().GetTableAsync(entity.Tablename, ct).ConfigureAwait(false);

                var mRels = await mTable.GetChildRelationsAsync(ct).ConfigureAwait(false);

                IMetaTableRelation mnRelation = mRels.FirstOrDefault((r) => r.ChildTableName == strMNTable);

                Query qOhL = Query.From(strMNTable)
                             .Where(c => c.Column(mnRelation.ChildColumnName) == entity.GetValue(mnRelation.ParentColumnName))
                             .GetQuery();

                // Get the MN-RelationObject
                IEntityCollection colMN = await session.Source().GetCollectionAsync(qOhL, EntityCollectionLoadType.Bulk, ct).ConfigureAwait(false);

                // Process each Object in ObjectHasLicence Table
                foreach (IEntity eMN in colMN)
                {
                    // Delete and Save
                    eMN.MarkForDeletion();

                    await unitOfWork.PutAsync(eMN, cancellationToken : ct).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 8
0
        public static IQueryable BuildSortQueryable(IQueryable query, IMetaTable table)
        {
            IMetaColumn sortColumn = table.SortColumn;

            if (sortColumn.IsCustomProperty)
            {
                // An extra property can't be optimized on server
                //
                var data = query.OfType <object>().AsEnumerable();
                Func <object, object> lambda = row => DataBinder.GetPropertyValue(row, sortColumn.Name);
                if (table.SortDescending)
                {
                    query = data.OrderByDescending <object, object>(lambda).AsQueryable();
                }
                else
                {
                    query = data.OrderBy <object, object>(lambda).AsQueryable();
                }
            }
            else
            {
                // Build custom expression to optimize sorting on server
                //
                var parameter = Expression.Parameter(query.ElementType, "row");
                LambdaExpression      lambda           = null;
                IMetaForeignKeyColumn foreignKeyColumn = sortColumn as IMetaForeignKeyColumn;
                if (foreignKeyColumn != null)
                {
                    // e.g. product => product.Category.CategoryName
                    var foreignKeySortColumn = foreignKeyColumn.ParentTable.SortColumn;
                    lambda = Expression.Lambda(Expression.Property(Expression.Property(parameter, sortColumn.Name), foreignKeySortColumn.Name), parameter);
                }
                else
                {
                    // e.g. product => product.ProductName
                    lambda = Expression.Lambda(Expression.Property(parameter, sortColumn.Name), parameter);
                }
                string ordering   = table.SortDescending ? "OrderByDescending" : "OrderBy";
                var    expression = Expression.Call(typeof(Queryable), ordering, new Type[] { query.ElementType, lambda.Body.Type }, query.Expression, lambda);
                query = query.Provider.CreateQuery(expression);
            }
            return(query);
        }
Ejemplo n.º 9
0
        internal void ResolveColumn()
        {
            if (IMetaColumn == null)
            {
                if (String.IsNullOrEmpty(DataField))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.DynamicControl_ControlMustHaveDateFieldAttribute, GetType().Name, ID));
                }

                IMetaColumn = IMetaTable.GetColumn(DataField);


                // Try to get them various settings from the model, unless they were explicitely
                // specified on the control
                if (String.IsNullOrEmpty(UIHint))
                {
                    UIHint = IMetaColumn.UIHint;
                }
                if (String.IsNullOrEmpty(DataFormatString))
                {
                    DataFormatString = IMetaColumn.DataFormatString;
                }
                if (String.IsNullOrEmpty(NullDisplayText))
                {
                    NullDisplayText = IMetaColumn.NullDisplayText;
                }
                if (!_customConvertEmptyStringToNullSet)
                {
                    ConvertEmptyStringToNull = IMetaColumn.ConvertEmptyStringToNull;
                }
                if (!_customApplyFormatInEditModeSet)
                {
                    ApplyFormatInEditMode = IMetaColumn.ApplyFormatInEditMode;
                }
                if (ViewState["HtmlEncode"] == null)
                {
                    HtmlEncode = IMetaColumn.HtmlEncode;
                }
            }
        }
Ejemplo n.º 10
0
        private async Task _FillOsInsttype(ISession session, IEntity entity, IUnitOfWork uoWork, CancellationToken ct)
        {
            // nur bei insert
            if (entity.IsLoaded)
            {
                return;
            }

            // zieltabelle deaktiviert
            IMetaTable mt = await session.MetaData().GetTableAsync("InstallationType", ct).ConfigureAwait(false);

            if (mt.IsDeactivated)
            {
                return;
            }

            string uidOs = entity.GetValue("UID_OS").String;

            Query qInstallationType = Query.From("InstallationType")
                                      .Select("UID_InstallationType");

            IEntityCollection colInstallationType = await
                                                    session.Source().GetCollectionAsync(qInstallationType, EntityCollectionLoadType.Slim, ct).ConfigureAwait(false);

            foreach (IEntity colElem in colInstallationType)
            {
                // create a new object
                IEntity eOsInstType = await session.Source().CreateNewAsync("OsInstType",
                                                                            EntityCreationType.DelayedLogic, ct)
                                      .ConfigureAwait(false);

                await eOsInstType.PutValueAsync("UID_OS", uidOs, ct).ConfigureAwait(false);

                await eOsInstType.PutValueAsync("UID_InstallationType", colElem.GetValue("UID_InstallationType"), ct).ConfigureAwait(false);

                // and save
                await uoWork.PutAsync(eOsInstType, ct).ConfigureAwait(false);
            }
        }
Ejemplo n.º 11
0
 internal DynamicControl(IMetaTable table)
 {
     _iMetaTable = table;
 }
Ejemplo n.º 12
0
        internal void RegisterControlInternal(IDataBoundControlInterface dataBoundControl, IDynamicDataSource dataSource, IMetaTable table, bool setSelectionFromUrl, bool isPostBack)
        {
            // Set the auto field generator (for controls that support it - GridView and DetailsView)
            IFieldControl fieldControl = dataBoundControl as IFieldControl;

            if (fieldControl != null)
            {
                fieldControl.FieldsGenerator = new DefaultAutoFieldGenerator(table);
            }
            var linqDataSource   = dataSource as LinqDataSource;
            var entityDataSource = dataSource as EntityDataSource;

            // If the context type is not set, we need to set it
            if (dataSource.ContextType == null)
            {
                dataSource.ContextType = table.DataContextType;

                // If it's a LinqDataSurce, register for ContextCreating so the context gets created using the correct ctor
                // Ideally, this would work with other datasource, but we just don't have the right abstraction
                if (linqDataSource != null)
                {
                    linqDataSource.ContextCreating += delegate(object sender, LinqDataSourceContextEventArgs e) {
                        e.ObjectInstance = table.CreateContext();
                    };
                }

                if (entityDataSource != null)
                {
                    entityDataSource.ContextCreating += delegate(object sender, EntityDataSourceContextCreatingEventArgs e) {
                        e.Context = (ObjectContext)table.CreateContext();
                    };
                }
            }

            // If the datasource doesn't have an EntitySetName (aka TableName), set it from the meta table
            if (String.IsNullOrEmpty(dataSource.EntitySetName))
            {
                dataSource.EntitySetName = table.DataContextPropertyName;
            }

            // If there is no Where clause, turn on auto generate
            if (String.IsNullOrEmpty(dataSource.Where))
            {
                dataSource.AutoGenerateWhereClause = true;
            }

            // If it's a LinqDataSource and the flag is set, pre load the foreign keys
            if (AutoLoadForeignKeys && linqDataSource != null)
            {
                linqDataSource.LoadWithForeignKeys(table.EntityType);
            }

            if (!isPostBack)
            {
                if (table.HasPrimaryKey)
                {
                    dataBoundControl.DataKeyNames = table.PrimaryKeyNames;

                    // Set the virtual selection from the URL if needed
                    var dataKeySelector = dataBoundControl as IPersistedSelector;
                    if (dataKeySelector != null && setSelectionFromUrl)
                    {
                        DataKey dataKey = table.GetDataKeyFromRoute();
                        if (dataKey != null)
                        {
                            dataKeySelector.DataKey = dataKey;
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
 internal DynamicControl(IMetaTable table) {
     _iMetaTable = table;
 }
Ejemplo n.º 14
0
 internal static void EnablePersistedSelection(BaseDataBoundControl baseDataBoundControl, IMetaTable table) {
     Debug.Assert(baseDataBoundControl != null, "NULL!");
     // Make the persisted selection sync up with the selected index if possible
     if (!table.IsReadOnly) {
         DynamicDataExtensions.EnablePersistedSelectionInternal(baseDataBoundControl);
     }
 }
Ejemplo n.º 15
0
 internal static void EnablePersistedSelection(BaseDataBoundControl baseDataBoundControl, IMetaTable table)
 {
     Debug.Assert(baseDataBoundControl != null, "NULL!");
     // Make the persisted selection sync up with the selected index if possible
     if (!table.IsReadOnly)
     {
         DynamicDataExtensions.EnablePersistedSelectionInternal(baseDataBoundControl);
     }
 }
Ejemplo n.º 16
0
        internal void RegisterControlInternal(IDataBoundControlInterface dataBoundControl, IDynamicDataSource dataSource, IMetaTable table, bool setSelectionFromUrl, bool isPostBack) {
            // Set the auto field generator (for controls that support it - GridView and DetailsView)
            IFieldControl fieldControl = dataBoundControl as IFieldControl;
            if (fieldControl != null) {
                fieldControl.FieldsGenerator = new DefaultAutoFieldGenerator(table);
            }
            var linqDataSource = dataSource as LinqDataSource;
            var entityDataSource = dataSource as EntityDataSource;
            // If the context type is not set, we need to set it
            if (dataSource.ContextType == null) {
                dataSource.ContextType = table.DataContextType;

                // If it's a LinqDataSurce, register for ContextCreating so the context gets created using the correct ctor
                // Ideally, this would work with other datasource, but we just don't have the right abstraction
                if (linqDataSource != null) {
                    linqDataSource.ContextCreating += delegate(object sender, LinqDataSourceContextEventArgs e) {
                        e.ObjectInstance = table.CreateContext();
                    };
                }

                if (entityDataSource != null) {
                    entityDataSource.ContextCreating += delegate(object sender, EntityDataSourceContextCreatingEventArgs e) {
                        e.Context = (ObjectContext)table.CreateContext();
                    };
                }
            }

            // If the datasource doesn't have an EntitySetName (aka TableName), set it from the meta table
            if (String.IsNullOrEmpty(dataSource.EntitySetName)) {
                dataSource.EntitySetName = table.DataContextPropertyName;
            }

            // If there is no Where clause, turn on auto generate
            if (String.IsNullOrEmpty(dataSource.Where)) {
                dataSource.AutoGenerateWhereClause = true;
            }

            // If it's a LinqDataSource and the flag is set, pre load the foreign keys
            if (AutoLoadForeignKeys && linqDataSource != null) {
                linqDataSource.LoadWithForeignKeys(table.EntityType);
            }

            if (!isPostBack) {
                if (table.HasPrimaryKey) {
                    dataBoundControl.DataKeyNames = table.PrimaryKeyNames;

                    // Set the virtual selection from the URL if needed
                    var dataKeySelector = dataBoundControl as IPersistedSelector;
                    if (dataKeySelector != null && setSelectionFromUrl) {
                        DataKey dataKey = table.GetDataKeyFromRoute();
                        if (dataKey != null) {
                            dataKeySelector.DataKey = dataKey;
                        }
                    }
                }
            }
        }
 internal DefaultAutoFieldGenerator(IMetaTable table) {
     if (table == null) {
         throw new ArgumentNullException("table");
     }
     _metaTable = table;
 }