예제 #1
0
 public object GetData(DashboardObjectDataSource dataSource, ObjectDataSourceFillParameters fillParameters)
 {
     if (fillParameters.CtorParameters != null && fillParameters.CtorParameters.Count > 0)
     {
         ScriptDataSource scriptDataSource = new ScriptDataSource((string)fillParameters.CtorParameters.Single().Value)
         {
             Application = DataProvider.ContextApplication
         };
         return(scriptDataSource.GetData(fillParameters.Parameters.ToDictionary(p => p.Name, p => p.Value)));
     }
     else
     {
         return(DefaultFillService.GetData(dataSource, fillParameters));
     }
 }
        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);
                    }
                }
            }
        }