Пример #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);
                }
            }
        }
Пример #2
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);
        }
        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);
                    }
                }
            }
        }