Exemplo n.º 1
0
        private static int GetColumnId(string uniqueName, ConstantsBase constants, IColumnProvider columnProvider)
        {
            if (!string.IsNullOrEmpty(uniqueName))
            {
                var columns = columnProvider.Find(constants.DataSourceId, uniqueName, cacheOnly: false);

                if (!columns.Any())
                {
                    throw new Exception(
                              string.Format(
                                  "Error initializing Constants for DataSource Id:{0} ({1}): No column found with UniqueName '{2}'",
                                  constants.DataSourceId, constants.Platform, uniqueName));
                }

                if (columns.Count() > 1)
                {
                    throw new Exception(
                              string.Format(
                                  "Error initializing Constants for DataSource Id:{0} ({1}): More than 1 column found with UniqueName '{2}'",
                                  constants.DataSourceId, constants.Platform, uniqueName));
                }

                return(columns.Single().Id);
            }
            return(-1);
        }
Exemplo n.º 2
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            // This method is being called on a new thread; since we're calling the column provider from this new thread, the
            // column writer doesn't need to write their own threading code and can focus solely on the column's function.

            // This method is only called if the _columnsToProcess list has items in it, so we can safely grab the first one, then
            // remove it from the list so it won't be processed again.
            IColumnProvider columnProvider = _columnsToProcess[0];

            _columnsToProcess.Remove(columnProvider);


            // The WhenRunWorkerCompleted method expects Result to be a ColumnValue object, so we'll pass either the result
            // returned from the column provider, or a value containing error information if the column provider throws
            // an exception. Note that we don't update the ListView right now because we're on a thread other than
            // the UI thread. The UI can only be manipulated on its own thread.
            try
            {
                e.Result = columnProvider.Execute(IpAddress);
            }
            catch (Exception e1)
            {
                e.Result = new ColumnValue(columnProvider.ColumnIndex, "Exception: " + e1.Message);
            }
        }
Exemplo n.º 3
0
 protected DataSourceBase(IDataSourceComponents dataSourceComponents)
 {
     _dataSourceComponents   = dataSourceComponents;
     columnProvider          = dataSourceComponents.ColumnProvider;
     QueryHelpers            = dataSourceComponents.QueryHelpers;
     _calculatedColumnHelper = dataSourceComponents.CalculatedColumnHelper;
     requestMapper           = dataSourceComponents.SearchRequestMapper;
     _constants       = dataSourceComponents.Constants;
     _tableMappings   = dataSourceComponents.TableMappings;
     _columnValidator = dataSourceComponents.ColumnMappingValidator;
 }
Exemplo n.º 4
0
 private void PopulateColumnsInConstants(ConstantsBase constants, IColumnProvider columnProvider)
 {
     try
     {
         constants.CurrencyColumnId   = GetColumnId(constants.CurrencyColumnUniqueName, constants, columnProvider);
         constants.DateStatColumnId   = GetColumnId(constants.DateStatColumnUniqueName, constants, columnProvider);
         constants.HourStatColumnId   = GetColumnId(constants.HourStatColumnUniqueName, constants, columnProvider);
         constants.TextSearchColumnId = GetColumnId(constants.TextSearchColumnUniqueName, constants, columnProvider);
     }
     catch (Exception ex)
     {
         // todo : store the exception for later
     }
 }
Exemplo n.º 5
0
 public SchemaProvider(
     ISqlObjectProvider sqlObjectProvider, 
     ISqlExpressionDependencyProvider sqlExpressionDependencyProvider, 
     IForeignKeyProvider foreignKeyProvider, 
     ISqlModuleProvider sqlModuleProvider, 
     ITableDefinitionProvider tableDefinitionProvider, IColumnProvider columnProvider)
 {
     SqlObjectProvider = sqlObjectProvider;
     SqlExpressionDependencyProvider = sqlExpressionDependencyProvider;
     ForeignKeyProvider = foreignKeyProvider;
     SqlModuleProvider = sqlModuleProvider;
     TableDefinitionProvider = tableDefinitionProvider;
     ColumnProvider = columnProvider;
 }
Exemplo n.º 6
0
        public MainForm()
        {
            InitializeComponent();

            // Set up event handlers to update end address label when start address text boxes are changed.
            startAddress1TextBox.TextChanged += UpdateEndAddressLabel;
            startAddress2TextBox.TextChanged += UpdateEndAddressLabel;
            startAddress3TextBox.TextChanged += UpdateEndAddressLabel;

            // Find user's IP address and populate start textboxes with first three octets.
            foreach (IPAddress address in Dns.GetHostAddresses(Dns.GetHostName()))
            {
                if (address.AddressFamily == AddressFamily.InterNetwork)
                {
                    byte[] bytes = address.GetAddressBytes();

                    startAddress1TextBox.Text = bytes[0].ToString();
                    startAddress2TextBox.Text = bytes[1].ToString();
                    startAddress3TextBox.Text = bytes[2].ToString();
                    break;
                }
            }

            IColumnProvider columnProvider = (IColumnProvider) new ComputerNameColumn();

            ColumnProviders.Add(columnProvider);

            ColumnHeader columnHeader = listView.Columns.Add(columnProvider.HeaderText, columnProvider.DefaultWidth, columnProvider.Alignment);

            columnProvider.Initialize(columnHeader.Index);
            columnHeader.TextAlign = HorizontalAlignment.Center;

            IColumnProvider columnProvider2 = (IColumnProvider) new OperatingSystemColumn();

            ColumnProviders.Add(columnProvider2);

            ColumnHeader columnHeader2 = listView.Columns.Add(columnProvider2.HeaderText, columnProvider2.DefaultWidth, columnProvider2.Alignment);

            columnProvider2.Initialize(columnHeader2.Index);
            columnHeader2.TextAlign = HorizontalAlignment.Center;
            //	LoadAddIns();
        }
Exemplo n.º 7
0
        private void LoadAddIns()
        {
            string iColumnProviderName          = typeof(IColumnProvider).FullName;
            string iContextMenuItemProviderName = typeof(IContextMenuItemProvider).FullName;

            DirectoryInfo addInDirInfo = new DirectoryInfo(Path.Combine(Application.StartupPath, "AddIns"));

            if (addInDirInfo.Exists)
            {
                // Get all of the assemblies in the AddIns directory
                foreach (FileInfo fileInfo in addInDirInfo.GetFiles("*.dll"))
                {
                    // Load the assembly and iterate through all of the types in it.
                    Assembly assembly = Assembly.LoadFrom(fileInfo.FullName);

                    foreach (Type type in assembly.GetTypes())
                    {
                        // If the type implements IColumnProvider, create an instance of it and add the column it represents to the list view.
                        if (type.GetInterface(iColumnProviderName) != null)
                        {
                            IColumnProvider columnProvider = (IColumnProvider)Activator.CreateInstance(type);
                            Program.ColumnProviders.Add(columnProvider);

                            ColumnHeader columnHeader = listView.Columns.Add(columnProvider.HeaderText, columnProvider.DefaultWidth, columnProvider.Alignment);
                            columnProvider.Initialize(columnHeader.Index);
                        }

                        // If the type implements IContextMenuItemProvider, create an instance of it and add it to the context menu.
                        if (type.GetInterface(iContextMenuItemProviderName) != null)
                        {
                            IContextMenuItemProvider menuItemProvider = (IContextMenuItemProvider)Activator.CreateInstance(type);
                            Program.ContextMenuItemProviders.Add(menuItemProvider);

                            MenuItemProviderMenuItem contextMenuItem = new MenuItemProviderMenuItem(menuItemProvider);
                            contextMenuItem.Click += contextMenuItem_Click;
                            contextMenu.Items.Add(contextMenuItem);
                        }
                    }
                }
            }
        }
        public DefaultCalculatedColumnHelper(IColumnProvider columnProvider, TableMappingsBase tableMappings, ConstantsBase constants, DefaultQueryHelpers queryHelpers)
            : base(columnProvider, constants.DataSourceId)
        {
            _tableMappings = tableMappings;
            _constants     = constants;
            QueryHelpers   = queryHelpers;

            var statsTable = _tableMappings.GetAllTables().FirstOrDefault(x => x is StatsTableMapping);

            if (statsTable != null)
            {
                _statsTableName = statsTable.KnownTableName;
            }

            var transposeTable = tableMappings.GetAllTables().FirstOrDefault(x => x is TransposeStatsTableMapping);

            if (transposeTable != null)
            {
                _transposeStatsTableName = transposeTable.KnownTableName;
            }
        }
Exemplo n.º 9
0
        public static dynamic GetAutoQuery <TEntity>(string queryString, Type entityType, IQueryable <TEntity> query, AutoQueryableProfile profile) where TEntity : class
        {
            // If query string empty select default entity properties.
            if (string.IsNullOrEmpty(queryString))
            {
                IColumnProvider            columnProvider = ProviderFactory.GetColumnProvider();
                IEnumerable <SelectColumn> selectColumns  = EntityColumnHelper.GetSelectableColumns(profile, entityType);
                if (profile.UseBaseType)
                {
                    return(query.Select(SelectHelper.GetSelector <TEntity, TEntity>(selectColumns, profile)));
                }
                return(query.Select(SelectHelper.GetSelector <TEntity, object>(selectColumns, profile)));
            }

            // Get criteria & clauses from choosen provider (AQ, OData, ...)
            string[]          queryStringParts = queryString.GetParts();
            ICriteriaProvider criteriaProvider = ProviderFactory.GetCriteriaProvider(profile?.ProviderType);
            IList <Criteria>  criterias        = profile.IsClauseAllowed(ClauseType.Filter) ? criteriaProvider.GetCriterias(entityType, queryStringParts, profile).ToList() : null;
            IClauseProvider   clauseProvider   = ProviderFactory.GetClauseProvider(profile?.ProviderType);
            Clauses           clauses          = clauseProvider.GetClauses(queryStringParts, profile);

            var countAllRows = false;
            IEnumerable <WrapperPartType> wrapperParts = null;

            if (clauses.WrapWith != null)
            {
                IWrapperProvider wrapperProvider = ProviderFactory.GetWrapperProvider();
                wrapperParts = wrapperProvider.GetWrapperParts(clauses.WrapWith.Value.Split(','), profile).ToList();
                countAllRows = wrapperParts.Contains(WrapperPartType.TotalCount);
            }

            QueryResult queryResult = QueryBuilder.Build(query, entityType, clauses, criterias, profile, countAllRows);

            if (clauses.WrapWith == null || !wrapperParts.Any())
            {
                return(queryResult.Result);
            }

            return(DefaultWrapperProvider.GetWrappedResult(wrapperParts, queryResult, clauses, queryString));
        }
Exemplo n.º 10
0
        //private static ColumnBO _Instance;

        private ColumnBO(string dbServer, string dbName) : base(dbServer, dbName, "Column")
        {
            _Provider = (IColumnProvider)this.CreateProvider();
        }
Exemplo n.º 11
0
 public FilteredColumnProvider(IColumnProvider provider)
 {
     _provider = provider;
 }
Exemplo n.º 12
0
 public TestCalculatedColumnHelper(IColumnProvider columnProvider, int dataSourceId) : base(columnProvider, dataSourceId)
 {
 }
Exemplo n.º 13
0
        protected DataSourceComponentsBase(IColumnProvider columnProvider)
        {
            // injected
            ColumnProvider = columnProvider;

            // implemented
            RegisterComponents();

            // populate constants
            if (Constants == null)
            {
                throw new Exception("Constants is not registered");
            }
            PopulateColumnsInConstants(Constants, ColumnProvider);

            // set defaults for missing properties
            SearchRequestMapper    = SearchRequestMapper ?? new DefaultSearchRequestMapper(this);
            QueryHelpers           = QueryHelpers ?? new DefaultQueryHelpers(ColumnProvider, Constants, TableMappings);
            CalculatedColumnHelper = CalculatedColumnHelper ?? new DefaultCalculatedColumnHelper(ColumnProvider, TableMappings, Constants, QueryHelpers);

            TransposeStatsQueryBuilder       = TransposeStatsQueryBuilder ?? new DefaultTransposeStatsCteQueryBuilder(this);
            DateStatsQueryBuilder            = DateStatsQueryBuilder ?? new DefaultDateStatsCteQueryBuilder(this);
            StatsQueryBuilder                = StatsQueryBuilder ?? new DefaultStatsQueryBuilder(this);
            DataQueryBuilder                 = DataQueryBuilder ?? new DefaultDataQueryBuilder(this);
            OneToManyCteQueryBuliderFactory  = OneToManyCteQueryBuliderFactory ?? new DefaultOneToManyCteQueryBuilderFactory(this);
            MissingSummarizeDataQueryBuilder = MissingSummarizeDataQueryBuilder ?? new DefaultMissingSummariseDataQueryBuilder(this);
            SearchQueryBuilder               = SearchQueryBuilder ?? new DefaultSearchQueryBuilder(this);
            ColumnMappingValidator           = ColumnMappingValidator ?? new DefaultColumnMappingValidator();

            if (TableMappings == null)
            {
                throw new Exception("TableMappings is not registered");
            }
            if (QueryHelpers == null)
            {
                throw new Exception("QueryHelpers is not registered");
            }
            if (CalculatedColumnHelper == null)
            {
                throw new Exception("CalculatedColumnHelper is not registered");
            }
            if (SearchRequestMapper == null)
            {
                throw new Exception("SearchRequestMapper is not registered");
            }

            if (SearchQueryBuilder == null)
            {
                throw new Exception("SearchQueryBuilder is not registered");
            }
            if (DateStatsQueryBuilder == null)
            {
                throw new Exception("DateStatsQueryBuilder is not registered");
            }
            if (TransposeStatsQueryBuilder == null)
            {
                throw new Exception("TransposeStatsQueryBuilder is not registered");
            }
            if (QueryBuilderBase == null)
            {
                throw new Exception("QueryBuilderBase is not registered");
            }
            if (StatsQueryBuilder == null)
            {
                throw new Exception("StatsQueryBuilder is not registered");
            }
            if (DataQueryBuilder == null)
            {
                throw new Exception("DataQueryBuilder is not registered");
            }
            if (OneToManyCteQueryBuliderFactory == null)
            {
                throw new Exception("OneToManyCteQueryBuliderFactory is not registered");
            }
            if (MissingSummarizeDataQueryBuilder == null)
            {
                throw new Exception("MissingSummarizeDataQueryBuilder is not registered");
            }

            ColumnProvider.Initialize();
        }
Exemplo n.º 14
0
 public SearchRequestFilterMapper(IColumnProvider columnProvider, ConstantsBase constants)
 {
     _constants     = constants;
     ColumnProvider = columnProvider;
 }
Exemplo n.º 15
0
 public DefaultQueryHelpers(IColumnProvider columnProvider, ConstantsBase constants, TableMappingsBase tableMappings)
 {
     _columnProvider = columnProvider;
     _constants      = constants;
     _tableMappings  = tableMappings;
 }
Exemplo n.º 16
0
        public static QueryResult Build <T>(IQueryable <T> query, Type entityType, Clauses clauses, IList <Criteria> criterias, AutoQueryableProfile profile, bool countAllRows) where T : class
        {
            IColumnProvider            columnProvider = ProviderFactory.GetColumnProvider(profile?.ProviderType);
            IEnumerable <SelectColumn> selectColumns  = columnProvider.GetSelectableColumns(clauses, profile, entityType);

            IEnumerable <Column> orderColumns     = OrderByHelper.GetOrderByColumns(profile, clauses.OrderBy, entityType);
            IEnumerable <Column> orderDescColumns = OrderByHelper.GetOrderByColumns(profile, clauses.OrderByDesc, entityType);

            if (criterias != null && criterias.Any())
            {
                query = query.Where(criterias);
            }
            var totalCount = 0;

            if (countAllRows)
            {
                totalCount = query.Count();
            }
            if (orderColumns != null)
            {
                query = query.OrderBy(orderColumns);
            }
            else if (orderDescColumns != null)
            {
                query = query.OrderByDesc(orderDescColumns);
            }

            IQueryable <object> queryProjection;

            if (clauses.Select == null && profile?.UnselectableProperties == null && profile?.SelectableProperties == null)
            {
                queryProjection = query;
            }
            else
            {
                if (profile.UseBaseType)
                {
                    queryProjection = query.Select(SelectHelper.GetSelector <T, T>(selectColumns, profile));
                }
                else
                {
                    queryProjection = query.Select(SelectHelper.GetSelector <T, object>(selectColumns, profile));
                }
            }

            if (clauses.Skip != null)
            {
                int.TryParse(clauses.Skip.Value, out int skip);
                if (profile?.MaxToSkip != null && skip > profile.MaxToSkip)
                {
                    skip = profile.MaxToSkip.Value;
                }
                queryProjection = queryProjection.Skip(skip);
            }
            if (clauses.Top != null)
            {
                int.TryParse(clauses.Top.Value, out int take);
                if (profile?.MaxToTake != null && take > profile?.MaxToTake)
                {
                    take = profile.MaxToTake.Value;
                }
                queryProjection = queryProjection.Take(take);
            }
            else if (clauses.First != null)
            {
                return(new QueryResult {
                    Result = queryProjection.FirstOrDefault(), TotalCount = totalCount
                });
            }
            else if (clauses.Last != null)
            {
                return(new QueryResult {
                    Result = queryProjection.LastOrDefault(), TotalCount = totalCount
                });
            }
            else if (profile?.MaxToTake != null)
            {
                queryProjection = queryProjection.Take(profile.MaxToTake.Value);
            }
            return(new QueryResult {
                Result = queryProjection, TotalCount = totalCount
            });
        }
Exemplo n.º 17
0
 public CalculatedColumnHelperBase(IColumnProvider columnProvider, int dataSourceId)
 {
     ColumnProvider = columnProvider;
     DataSourceId   = dataSourceId;
 }
Exemplo n.º 18
0
 public Scenario1DataSourceComponents(IColumnProvider columnProvider) : base(columnProvider)
 {
 }