public void Should_Create_TreeItems_With_Exports_For_Folders()
        {
            var report = new MyReportBase();
            var designContext = TestHelper.CreateDesignerContext();

            var northwind = TestHelper.NorthwindDataSource;
            var fakeDefinition1 = new DesignTimeDataSourceDefinition(northwind.DataSourceName, @"TestFolder", string.Empty);
            var fakeDefinition2 = new DesignTimeDataSourceDefinition(northwind.DataSourceName, @"FakeFolder", string.Empty);
            var fakeDefinition3 = new DesignTimeDataSourceDefinition(northwind.DataSourceName, @"TestFolder\TestChildFolder", string.Empty);

            report.DesignTimeDataSources.Add(northwind);
            report.DesignTimeDataSources.Add(fakeDefinition1);
            report.DesignTimeDataSources.Add(fakeDefinition2);
            report.DesignTimeDataSources.Add(fakeDefinition3);

            DynamicTree<DesignTimeDataSourceTreeItem> tree;
            List<DesignTimeDataSourceTreeItem> flatList;

            var treeItems = DesignTimeHelper.BuildDesignTimeDataSourceTreeItems(locator, report, out tree, out flatList).ToList();

            ////  Show TreeView, debug only
            //var form = new SelectDesignTimeDataSourceForm(designContext, report, (selectedDefinition) => { });
            //form.ShowDialog();

            Assert.AreEqual(8, treeItems.Count);
        }
        public void can_serialize_custom_report_properties()
        {
            var report1 = new DummyReport();

            var abc = new DesignTimeDataSourceDefinition("a", "b", "c");
            report1.RyansSerializeTestObject = abc;

            var report2 = TestHelper.RunThroughSerializer(report1);

            Assert.IsNotNull(report2.RyansSerializeTestObject);
            Assert.AreEqual(report1.RyansSerializeTestObject, report2.RyansSerializeTestObject);
        }
        public void datasources_list_is_serialized()
        {
            var factory = new ReportFactory();

            var abc = new DesignTimeDataSourceDefinition("a", "b", "c");
            var xyz = new DesignTimeDataSourceDefinition("x", "y", "z");

            var report1 = (MyReportBase)factory.GetDefaultReport();

            // Collection
            report1.DesignTimeDataSources.Add(abc);
            report1.DesignTimeDataSources.Add(xyz);

            var report2 = TestHelper.RunThroughSerializer(report1);
            Assert.IsTrue(report2.DesignTimeDataSources.Count == 2);
        }
        public TraversedDatasourceResult GetDataSource(DesignTimeDataSourceDefinition definition)
        {
            var rootDatasource = GetDataSourceWithoutTraversal(definition);

            // Traverse Relation Path
            var targetDataSource = ObjectGraphPathTraverser.TraversePath(rootDatasource, definition.DataSourceRelationPath);

            // Assign Datasource Types to DesignTimeDatasource, not that we've obtained the datasource & traversed the relation path
            definition.RootDataSourceType = null;
            definition.DataSourceType = null;

            if (rootDatasource != null) definition.RootDataSourceType = rootDatasource.GetType();
            if (targetDataSource != null) definition.DataSourceType = targetDataSource.GetType();

            return new TraversedDatasourceResult(definition, rootDatasource, targetDataSource);
        }
        public static bool ChangeDesignTimeDatasource(this MyReportBase report, DesignTimeDataSourceDefinition definition, IDesignerContext designContext)
        {
            object datasource = null;

            if (definition != null)
            {
                // Get Traversed Datasource
                var traversedResult = designContext.DataSourceLocator.GetTraversedObjectFromDataSourceDefinition(definition);
                datasource = traversedResult.TraversedDataSource;

                if (traversedResult.RootDataSource == null)
                    MessageBox.Show("Datasource: {0} could not be found or did not return a datasource.".FormatString(definition.ToString()));
                else
                {
                    // Store Definition on Report

                    // If already in list, Remore & Re-add, so as to move definition to index 0
                    if (report.DesignTimeDataSources.Contains(definition))
                    {
                        var index = report.DesignTimeDataSources.IndexOf(definition);
                        report.DesignTimeDataSources.RemoveAt(index);
                    }

                    // Add item as first in list - So we know it was the last one used
                    report.DesignTimeDataSources.Insert(0, definition);

                    // Verify Traversal worked
                    if (traversedResult.TraversedDataSource == null)
                        MessageBox.Show("Datasource: {0} was found, but the traversed Relation Path did not return a value.".FormatString(definition.ToString()));
                }
            }

            // Set DataSource
            report.SetReportDataSource(datasource);

            // Refresh Design Panel Fields List
            var designPanel = designContext.DesignForm.DesignMdiController.ActiveDesignPanel;
            if (designPanel != null)
                designPanel.Activate();

            return report.DataSource != null;
        }
        private object GetDataSourceWithoutTraversal(DesignTimeDataSourceDefinition definition)
        {
            var matches = (from provider in this.GetReportDatasourceProviders()
                           from datasourceMetadata in provider.GetReportDatasources()
                           where datasourceMetadata.UniqueId == definition.DataSourceUniqueId
                           select new { provider, datasourceMetadata }).ToList();

            if (matches.Count == 0)
                return null;

            if (matches.Count > 1)
                throw new Exception("Multiple Design-Time Datasources were found with UniqueId: {0}".FormatString(definition.DataSourceUniqueId));

            var match = matches.Single();

            // Fetch
            var datasource = match.provider.GetReportDatasource(match.datasourceMetadata.UniqueId);

            return datasource;
        }
        public void datasource_should_serialize_all_properties()
        {
            var datasource1 = new DesignTimeDataSourceDefinition("mydatasource", "mypath", "myrelation")
            {
                RootDataSourceType = typeof(Product),
                DataSourceType = typeof(Order)
            };

            var factory = new ReportFactory();

            var report1 = (MyReportBase)factory.GetDefaultReport();
            report1.DesignTimeDataSources.Add(datasource1);

            var report2 = TestHelper.RunThroughSerializer(report1);
            var datasource2 = report2.DesignTimeDataSources.Single();

            // Assert all properties were serialized
            Assert.AreEqual(datasource1.DataSourceName, datasource2.DataSourceName);
            Assert.AreEqual(datasource1.DataSourceRelationPath, datasource2.DataSourceRelationPath);
            Assert.AreEqual(datasource1.DataSourceType, datasource2.DataSourceType);
            Assert.AreEqual(datasource1.RootDataSourceType, datasource2.RootDataSourceType);
        }
 public Lazy<IReportDatasource, IReportDatasourceMetadata> GetDatasource(DesignTimeDataSourceDefinition definition)
 {
     return GetDatasource(definition.DataSourceAssemblyLocationPath, definition.DataSourceName);
 }
 public TraversedDatasourceResult(DesignTimeDataSourceDefinition definition, object rootDataSource, object traversedDataSource)
 {
     Definition = definition;
     RootDataSource = rootDataSource;
     TraversedDataSource = traversedDataSource;
 }
        public TraversedDatasourceResult GetTraversedObjectFromDataSourceDefinition(DesignTimeDataSourceDefinition definition)
        {
            if (definition == null)
                return new TraversedDatasourceResult(null, null, null);

            // Get Export
            var export = GetDatasource(definition.DataSourceAssemblyLocationPath, definition.DataSourceName);
            var exportInstance = export.Value;

            // Get Datasource
            var rootDataSource = exportInstance.GetDataSource();

            // Traverse Relation Path
            var targetDataSource = ObjectGraphPathTraverser.TraversePath(rootDataSource, definition.DataSourceRelationPath);

            // Assign Datasource Types to DesignTimeDatasource, not that we've obtained the datasource & traversed the relation path
            definition.RootDataSourceType = null;
            definition.DataSourceType = null;

            if (rootDataSource != null) definition.RootDataSourceType = rootDataSource.GetType();
            if (targetDataSource != null) definition.DataSourceType = targetDataSource.GetType();

            return new TraversedDatasourceResult(definition, rootDataSource, targetDataSource);
        }
        public static void PassDesignTimeDataSourceToSubreport(SubreportBase container, MyReportBase subreport, IDesignerContext designContext)
        {
            var parentReport = (MyReportBase)container.RootReport;

            var parentDataSourceItem = parentReport.GetSelectedDesignTimeDatasource();

            if (parentDataSourceItem != null)
            {
                var path = DesignTimeHelper.GetFullDataMemberPath(container.Band);

                var datasourceDefinition = new DesignTimeDataSourceDefinition(parentDataSourceItem.DataSourceName, parentDataSourceItem.DataSourceAssemblyLocationPath, path);

                // Go!
                subreport.ChangeDesignTimeDatasource(datasourceDefinition, designContext);
            }
        }
 public XRLoadDesignTimeDatasourceMessage(MyReportBase report, DesignTimeDataSourceDefinition datasourceDefinition, Action<object> setDatasourceCallback)
 {
     Report = report;
     DatasourceDefinition = datasourceDefinition;
     SetDatasourceCallback = setDatasourceCallback;
 }