private DataTable GetTableSchema(IEnumerable <XElement> query, bool armedWithLambdaExpression)
        {
            DataTable dataTable = new DataTable();

            foreach (XElement xelement in query)
            {
                DataColumn dataColumn = new DataColumn((string)xelement.Attribute("Name"));
                if (this.HasValue(xelement.Attribute("Type")))
                {
                    dataColumn.DataType = ObjectSchemaLoader.GetTypeByString((string)xelement.Attribute("Type"));
                }
                ICustomTextConverter customTextConverter = new TextConverter();
                if (this.HasValue(xelement.Attribute("TextConverter")))
                {
                    customTextConverter = (ICustomTextConverter)ObjectPickerProfileLoader.CreateObject(xelement.Attribute("TextConverter").Value);
                }
                else if (dataColumn.DataType.Equals(typeof(LocalizedString)))
                {
                    customTextConverter = this.stringIDToLocalizedStringConverter;
                }
                dataColumn.ExtendedProperties["TextConverter"] = customTextConverter;
                if (this.HasValue(xelement.Attribute("DefaultValue")))
                {
                    dataColumn.DefaultValue = customTextConverter.Parse(dataColumn.DataType, (string)xelement.Attribute("DefaultValue"), null);
                }
                if (this.HasValue(xelement.Attribute("AutoIncrement")))
                {
                    dataColumn.AutoIncrement = bool.Parse((string)xelement.Attribute("AutoIncrement"));
                }
                if (this.HasValue(xelement.Attribute("ExpectedType")))
                {
                    dataColumn.ExtendedProperties["ExpectedType"] = ObjectSchemaLoader.GetTypeByString((string)xelement.Attribute("ExpectedType"));
                }
                if (armedWithLambdaExpression && this.HasValue(xelement.Attribute("LambdaExpression")))
                {
                    dataColumn.ExtendedProperties["LambdaExpression"] = (string)xelement.Attribute("LambdaExpression");
                }
                dataTable.Columns.Add(dataColumn);
            }
            return(dataTable);
        }
Пример #2
0
 public CaptionedResultPane(ObjectPickerProfileLoader profileLoader, string profileName) : this(profileLoader.GetProfile(profileName))
 {
 }
 public DataListViewResultPane(ObjectPickerProfileLoader profileLoader, string profileName) : this(profileLoader.GetProfile(profileName))
 {
 }
        public ResultsLoaderProfile GetProfile(string profileName)
        {
            Stream        manifestResource = WinformsHelper.GetManifestResource(this.dataDrivenCategory);
            XmlTextReader reader           = SafeXmlFactory.CreateSafeXmlTextReader(manifestResource);
            XElement      po = XElement.Load(reader);
            DataTable     inputTable;
            var <>        f__AnonymousType = (from dataSource in po.Elements("ResultsLoader")
                                              where (string)dataSource.Attribute("Name") == profileName
                                              select new
            {
                Configuration = this.CreateUIPresentationProfile(po, dataSource.Element("Configuration")),
                DataTable = (from dataTable in dataSource.Elements("DataColumns")
                             select new
                {
                    DataColumns = dataTable.Elements("Column").Union(dataTable.Elements("RefColumns").SelectMany((XElement r) => (from c in po.Element("RefColumnsSection").Elements("RefColumns")
                                                                                                                                  where c.Attribute("Name").Value == r.Attribute("Name").Value
                                                                                                                                  select c).Elements("Column"))),
                    PrimaryKey = (this.HasValue(dataTable.Attribute("PrimaryKey")) ? dataTable.Attribute("PrimaryKey").Value.Split(new char[]
                    {
                        ','
                    }) : new string[0]),
                    NameProperty = (this.HasValue(dataTable.Attribute("NameProperty")) ? dataTable.Attribute("NameProperty").Value : "Name"),
                    DataColumnsCalculator = (IDataColumnsCalculator)(this.HasValue(dataTable.Attribute("DataColumnsCalculator")) ? ObjectPickerProfileLoader.CreateObject(dataTable.Attribute("DataColumnsCalculator").Value) : null),
                    WholeObjectProperty = (this.HasValue(dataTable.Attribute("WholeObjectProperty")) ? dataTable.Attribute("WholeObjectProperty").Value : string.Empty),
                    DistinguishIdentity = (this.HasValue(dataTable.Attribute("DistinguishIdentity")) ? dataTable.Attribute("DistinguishIdentity").Value : string.Empty)
                }).First(),
                InputTable = (this.HasValue(dataSource.Element("InputColumns")) ? (from inputTable in dataSource.Elements("InputColumns")
                                                                                   select new
                {
                    DataColumns = inputTable.Elements("Column").Union(inputTable.Elements("RefColumns").SelectMany((XElement r) => (from c in po.Element("RefColumnsSection").Elements("RefColumns")
                                                                                                                                    where c.Attribute("Name").Value == r.Attribute("Name").Value
                                                                                                                                    select c).Elements("Column"))),
                    PartialOrderComparer = (IPartialOrderComparer)(this.HasValue(inputTable.Attribute("PartialOrderComparer")) ? ObjectPickerProfileLoader.CreateObject(inputTable.Attribute("PartialOrderComparer").Value) : null)
                }).First() : null),
                DataReader = (from dataReader in dataSource.Elements("DataTableFillers")
                              select new
                {
                    DataTableFillers = dataReader.Elements(),
                    BatchSize = (this.HasValue(dataReader.Attribute("BatchSize")) ? dataReader.Attribute("BatchSize").Value : ResultsLoaderProfile.DefaultBatchSize.ToString()),
                    FillType = (this.HasValue(dataReader.Attribute("FillType")) ? ((FillType)Enum.Parse(typeof(FillType), dataReader.Attribute("FillType").Value)) : 0),
                    LoadableFromProfilePredicate = (ILoadableFromProfile)(this.HasValue(dataReader.Attribute("LoadableFromProfilePredicate")) ? ObjectPickerProfileLoader.CreateObject(dataReader.Attribute("LoadableFromProfilePredicate").Value) : null),
                    PostRefreshAction = (PostRefreshActionBase)(this.HasValue(dataReader.Attribute("PostRefreshAction")) ? ObjectPickerProfileLoader.CreateObject(dataReader.Attribute("PostRefreshAction").Value) : null)
                }).First()
            }).First();
            DataTable resultTable = this.GetTableSchema(< > f__AnonymousType.DataTable.DataColumns, true);

            resultTable.PrimaryKey = (from c in < > f__AnonymousType.DataTable.PrimaryKey
                                      select resultTable.Columns[c]).ToArray <DataColumn>();
            resultTable.TableName = profileName;
            inputTable            = ((< > f__AnonymousType.InputTable != null) ? this.GetTableSchema(< > f__AnonymousType.InputTable.DataColumns, false) : new DataTable());
            ResultsLoaderProfile resultsLoaderProfile = new ResultsLoaderProfile(< > f__AnonymousType.Configuration, inputTable, resultTable)
            {
                Name = profileName,
                InputTablePartialOrderComparer = ((< > f__AnonymousType.InputTable == null) ? null : < > f__AnonymousType.InputTable.PartialOrderComparer),
                WholeObjectProperty            = < > f__AnonymousType.DataTable.WholeObjectProperty,
                NameProperty                 = < > f__AnonymousType.DataTable.NameProperty,
                DataColumnsCalculator        = < > f__AnonymousType.DataTable.DataColumnsCalculator,
                LoadableFromProfilePredicate = < > f__AnonymousType.DataReader.LoadableFromProfilePredicate,
                PostRefreshAction            = < > f__AnonymousType.DataReader.PostRefreshAction,
                BatchSize           = ((string.Compare(< > f__AnonymousType.DataReader.BatchSize, "MaxValue", true) == 0) ? int.MaxValue : int.Parse(< > f__AnonymousType.DataReader.BatchSize)),
                DistinguishIdentity = < > f__AnonymousType.DataTable.DistinguishIdentity,
                FillType            = < > f__AnonymousType.DataReader.FillType
            };

            this.AddFillerCollection(resultsLoaderProfile, <> f__AnonymousType.DataReader.DataTableFillers);
            return(resultsLoaderProfile);
        }