Esempio n. 1
0
        public void DataExtractCreationTest()
        {
            DataTable table = new DataTable();

            table.Columns.Add("IntColumn", typeof(int));
            table.Columns.Add("StringColumn", typeof(string));
            table.Rows.Add(1, "Row 1");
            table.Rows.Add(2, "Row 2");
            table.Rows.Add(3, "Row 3");
            var reader = table.CreateDataReader();

            using (DashboardObjectDataSource ods = new DashboardObjectDataSource())
            {
                ods.DataSource = new DataReaderList(reader);
                using (DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource())
                {
                    extractDataSource.ExtractSourceOptions.DataSource = ods;
                    extractDataSource.FileName = Path.GetTempFileName();
                    extractDataSource.UpdateExtractFile();
                    IDashboardDataSourceInternal dsi = extractDataSource;
                    var storage = dsi.GetStorage(null);
                    Assert.Equal(3, storage.RowCount);
                }
            }
        }
        public static void ConfigureDataSource(DashboardConfigurator configurator, DataSourceInMemoryStorage storage)
        {
            // Registers an Extract data source.
            DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource("Extract Data Source");

            extractDataSource.Name           = "Extract Data Source";
            extractDataSource.ConnectionName = "dataExtract";
            storage.RegisterDataSource("extractDataSource ", extractDataSource.SaveToXml());

            configurator.ConfigureDataConnection += Configurator_ConfigureDataConnection;
        }
Esempio n. 3
0
        public Form1()
        {
            InitializeComponent();
            ExtractDriverStorage.DefaultDriver = new ExtractEncryptionDriver();

            DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource();

            extractDataSource.ExtractSourceOptions.DataSource = CreateExcelDataSource();
            extractDataSource.FileName = DateTime.Now.ToString(extractFileNamePattern);
            extractDataSource.UpdateExtractFile();

            dashboardViewer1.Dashboard = CreateDashboard(extractDataSource);
        }
Esempio n. 4
0
        private static Dashboard CreateDashboard(DashboardExtractDataSource extractDataSource)
        {
            Dashboard dashboard = new Dashboard();

            dashboard.DataSources.Add(extractDataSource);
            PivotDashboardItem pivot = new PivotDashboardItem();

            pivot.DataSource = extractDataSource;
            pivot.Values.AddRange(new Measure("Extended Price"), new Measure("Quantity"));
            pivot.Columns.Add(new Dimension("OrderDate", DateTimeGroupInterval.Year));
            pivot.Rows.Add(new Dimension("ProductName"));
            dashboard.Items.Add(pivot);
            return(dashboard);
        }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DashboardFileStorage newDashboardStorage = new DashboardFileStorage(HostingEnvironment.MapPath(@"~/App_Data/Dashboards"));

            ASPxDashboard1.SetDashboardStorage(newDashboardStorage);

            ASPxDashboard1.SetConnectionStringsProvider(new ConfigFileConnectionStringsProvider());
            DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();

            DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource("Extract Data Source");

            extractDataSource.ConnectionName = "edsSales";
            dataSourceStorage.RegisterDataSource("extractDataSource", extractDataSource.SaveToXml());
            ASPxDashboard1.SetDataSourceStorage(dataSourceStorage);
        }
Esempio n. 6
0
        public static string UpdateExtractDataSource()
        {
            DashboardExtractDataSource ds = CreateExtractDataSource();
            StringBuilder sb   = new StringBuilder("We updated your extract data source. ");
            var           task = DashboardExtractDataSource.UpdateFile(ds,
                                                                       (fileName, result) => {
                sb.AppendLine($"{DateTime.Now.ToString("T")} - Data Updated - {result} - {Path.GetFileName(fileName)}. ");
            },
                                                                       (fileName, result) => {
                sb.AppendLine($"{DateTime.Now.ToString("T")} - File Updated - {result} - {Path.GetFileName(fileName)}. ");
            });

            // Wait until the data is refreshed in the Extract Data Source.
            task.Wait();
            return(sb.ToString());
        }
Esempio n. 7
0
        private static DashboardExtractDataSource CreateExtractDataSource()
        {
            DashboardSqlDataSource nwindDataSource = new DashboardSqlDataSource("Northwind Invoices", "nwindConnection");
            SelectQuery            invoicesQuery   = SelectQueryFluentBuilder
                                                     .AddTable("Invoices")
                                                     .SelectColumns("City", "Country", "Salesperson", "OrderDate", "Shippers.CompanyName", "ProductName", "UnitPrice", "Quantity", "Discount", "ExtendedPrice", "Freight")
                                                     .Build("Invoices");

            nwindDataSource.Queries.Add(invoicesQuery);
            nwindDataSource.ConnectionOptions.CommandTimeout = 600;

            DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource("Invoices Extract Data Source");

            extractDataSource.ExtractSourceOptions.DataSource = nwindDataSource;
            extractDataSource.ExtractSourceOptions.DataMember = "Invoices";
            return(extractDataSource);
        }
Esempio n. 8
0
    public CustomDataSourceStorage()
    {
        DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource(sqlDataSourceId, "sqlCategories");
        SelectQuery            query         = SelectQueryFluentBuilder
                                               .AddTable("Categories")
                                               .SelectAllColumnsFromTable()
                                               .Build("Categories");

        query.Parameters.Add(new QueryParameter("CategoryNameStartsWith", typeof(DevExpress.DataAccess.Expression), new DevExpress.DataAccess.Expression("[Parameters.CategoryPattern]")));
        sqlDataSource.Queries.Add(query);

        DashboardJsonDataSource jsonDataSource = new DashboardJsonDataSource(jsonDataSourceId)
        {
            RootElement    = "Customers",
            ConnectionName = "jsonCustomers"
        };

        DashboardObjectDataSource objDataSource = new DashboardObjectDataSource(odsDataSourceId)
        {
            DataId = "odsSales"
        };

        DashboardOlapDataSource olapDataSource = new DashboardOlapDataSource(olapDataSourceId, "olapAdventureWorks");

        DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource(extractDataSourceId)
        {
            ConnectionName = "extractSalesPerson"
        };

        DashboardExcelDataSource excelDataSource = new DashboardExcelDataSource(excelDataSourceId)
        {
            ConnectionName = "excelSales",
            SourceOptions  = new ExcelSourceOptions(new ExcelWorksheetSettings("Sheet1"))
        };

        DashboardEFDataSource efDataSource = new DashboardEFDataSource(efDataSourceId, new EFConnectionParameters(typeof(NorthwindDbContext)));

        documents[sqlDataSourceId]     = new XDocument(sqlDataSource.SaveToXml());
        documents[jsonDataSourceId]    = new XDocument(jsonDataSource.SaveToXml());
        documents[odsDataSourceId]     = new XDocument(objDataSource.SaveToXml());
        documents[olapDataSourceId]    = new XDocument(olapDataSource.SaveToXml());
        documents[extractDataSourceId] = new XDocument(extractDataSource.SaveToXml());
        documents[excelDataSourceId]   = new XDocument(excelDataSource.SaveToXml());
        documents[efDataSourceId]      = new XDocument(efDataSource.SaveToXml());
    }
        private void UpdateDataExtract(IDashboardDataExtract extract)
        {
            if (extract == null)
            {
                throw new ArgumentNullException(nameof(extract));
            }
            if (string.IsNullOrWhiteSpace(extract.Script))
            {
                return;
            }

            using (DashboardObjectDataSource ods = new DashboardObjectDataSource())
            {
                ScriptDataSource dataSource = CreateScriptDataSource(extract, Application);
                object           data       = dataSource.GetDataForDataExtract();
                if (data is byte[] buffer)
                {
                    SetDataExtractContent(extract, buffer);
                    return;
                }
                ods.DataSource = data;
                string fileName = Path.GetTempFileName();
                try
                {
                    using (DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource())
                    {
                        extractDataSource.ExtractSourceOptions.DataSource = ods;
                        extractDataSource.FileName = fileName;
                        extractDataSource.UpdateExtractFile();
                        SetDataExtractContent(extract, File.ReadAllBytes(fileName));
                        if (data is ICollection collection)
                        {
                            extract.RowCount = collection.Count;
                        }
                    }
                }
                finally
                {
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }
            }
        }
Esempio n. 10
0
 protected static Dashboard CreateCopy(Dashboard dashboard)
 {
     using (Stream stream = new MemoryStream())
     {
         dashboard.SaveToXml(stream);
         stream.Seek(0L, SeekOrigin.Begin);
         Dashboard copy = new Dashboard();
         copy.LoadFromXml(stream);
         for (int i = 0; i < dashboard.DataSources.Count; i++)
         {
             IDashboardDataSource dataSource = dashboard.DataSources[i];
             if (dataSource is DashboardObjectDataSource)
             {
                 copy.DataSources[i].Data = dataSource.Data;
             }
             DashboardExtractDataSource extractDataSource = dataSource as DashboardExtractDataSource;
             if (extractDataSource is DashboardExtractDataSource)
             {
                 ((DashboardExtractDataSource)copy.DataSources[i]).FileName = extractDataSource.FileName;
             }
         }
         return(copy);
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            DashboardFileStorage dashboardFileStorage = new DashboardFileStorage("~/App_Data/Dashboards");

            ASPxDashboardExtract.SetDashboardStorage(dashboardFileStorage);

            // Uncomment the next line to allow users to create new data sources based on predefined connection strings.
            //ASPxDashboardExtract.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider());

            // Create a data source storage.
            DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();

            // Register an Extract data source.
            DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource("Extract Data Source");

            extractDataSource.ConnectionName = "extractDataConnection";
            dataSourceStorage.RegisterDataSource("extractDataSource ", extractDataSource.SaveToXml());

            // Set the configured data source storage.
            ASPxDashboardExtract.SetDataSourceStorage(dataSourceStorage);

            ASPxDashboardExtract.ConfigureDataConnection += ASPxDashboardExtract_ConfigureDataConnection;
            ASPxDashboardExtract.InitialDashboardId       = "dashboardExtract";
        }
        public Form1()
        {
            InitializeComponent();

            Dashboard dashboard = new Dashboard();
            DashboardExtractDataSource dataSource = new DashboardExtractDataSource();

            dataSource.FileName = @"..\..\Data\SalesDataExtract.dat";
            dashboard.DataSources.Add(dataSource);

            TreemapDashboardItem treeMap = new TreemapDashboardItem();

            treeMap.DataSource = dataSource;
            treeMap.Values.Add(new Measure("Sales"));
            treeMap.Arguments.Add(new Dimension {
                DataMember       = "Product Category",
                GroupChildValues = true
            });
            treeMap.Arguments.Add(new Dimension("Product Sub-Category"));
            treeMap.LayoutAlgorithm = DashboardTreemapLayoutAlgorithm.Striped;

            dashboard.Items.Add(treeMap);
            dashboardViewer1.Dashboard = dashboard;
        }
        static IDashboardDataSource CreateDataSourceCopy(IDashboardDataSource dataSourceToCopy)
        {
            DashboardEFDataSource efDataSource = dataSourceToCopy as DashboardEFDataSource;

            if (efDataSource != null)
            {
                XElement element = efDataSource.SaveToXml();
                DashboardEFDataSource newDataSource = new DashboardEFDataSource();
                newDataSource.LoadFromXml(element);
                newDataSource.Fill();
                return(newDataSource);
            }

            DashboardExcelDataSource excelDataSource = dataSourceToCopy as DashboardExcelDataSource;

            if (excelDataSource != null)
            {
                XElement element = excelDataSource.SaveToXml();
                DashboardExcelDataSource newDataSource = new DashboardExcelDataSource();
                newDataSource.LoadFromXml(element);
                newDataSource.Fill();
                return(newDataSource);
            }

            DashboardExtractDataSource extractDataSource = dataSourceToCopy as DashboardExtractDataSource;

            if (extractDataSource != null)
            {
                XElement element = extractDataSource.SaveToXml();
                DashboardExtractDataSource newDataSource = new DashboardExtractDataSource();
                newDataSource.LoadFromXml(element);
                return(newDataSource);
            }

            DashboardObjectDataSource objectDataSource = dataSourceToCopy as DashboardObjectDataSource;

            if (objectDataSource != null)
            {
                XElement element = objectDataSource.SaveToXml();
                DashboardObjectDataSource newDataSource = new DashboardObjectDataSource();
                newDataSource.LoadFromXml(element);
                newDataSource.Fill();
                return(newDataSource);
            }

            DashboardOlapDataSource olapDataSource = dataSourceToCopy as DashboardOlapDataSource;

            if (olapDataSource != null)
            {
                XElement element = olapDataSource.SaveToXml();
                DashboardOlapDataSource newDataSource = new DashboardOlapDataSource();
                newDataSource.LoadFromXml(element);
                newDataSource.Fill();
                return(newDataSource);
            }

            DashboardSqlDataSource sqlDataSource = dataSourceToCopy as DashboardSqlDataSource;

            if (sqlDataSource != null)
            {
                XElement element = sqlDataSource.SaveToXml();
                DashboardSqlDataSource newDataSource = new DashboardSqlDataSource();
                newDataSource.LoadFromXml(element);
                newDataSource.Fill();
                return(newDataSource);
            }
            return(null);
        }