Example #1
0
        internal DataRow FindMetaDataCollectionRow(string collectionName)
        {
            bool   versionFailure;
            bool   haveExactMatch;
            bool   haveMultipleInexactMatches;
            string candidateCollectionName;

            DataTable metaDataCollectionsTable = _metaDataCollectionsDataSet.Tables[DbMetaDataCollectionNames.MetaDataCollections];

            if (metaDataCollectionsTable == null)
            {
                throw ADP.InvalidXml();
            }

            DataColumn collectionNameColumn = metaDataCollectionsTable.Columns[DbMetaDataColumnNames.CollectionName];

            if ((null == collectionNameColumn) || (typeof(System.String) != collectionNameColumn.DataType))
            {
                throw ADP.InvalidXmlMissingColumn(DbMetaDataCollectionNames.MetaDataCollections, DbMetaDataColumnNames.CollectionName);
            }

            DataRow requestedCollectionRow = null;
            String  exactCollectionName    = null;

            // find the requested collection
            versionFailure             = false;
            haveExactMatch             = false;
            haveMultipleInexactMatches = false;

            foreach (DataRow row in metaDataCollectionsTable.Rows)
            {
                candidateCollectionName = row[collectionNameColumn, DataRowVersion.Current] as string;
                if (ADP.IsEmpty(candidateCollectionName))
                {
                    throw ADP.InvalidXmlInvalidValue(DbMetaDataCollectionNames.MetaDataCollections, DbMetaDataColumnNames.CollectionName);
                }

                if (ADP.CompareInsensitiveInvariant(candidateCollectionName, collectionName))
                {
                    if (SupportedByCurrentVersion(row) == false)
                    {
                        versionFailure = true;
                    }
                    else
                    {
                        if (collectionName == candidateCollectionName)
                        {
                            if (haveExactMatch == true)
                            {
                                throw ADP.CollectionNameIsNotUnique(collectionName);
                            }
                            requestedCollectionRow = row;
                            exactCollectionName    = candidateCollectionName;
                            haveExactMatch         = true;
                        }
                        else
                        {
                            // have an inexact match - ok only if it is the only one
                            if (exactCollectionName != null)
                            {
                                // can't fail here becasue we may still find an exact match
                                haveMultipleInexactMatches = true;
                            }
                            requestedCollectionRow = row;
                            exactCollectionName    = candidateCollectionName;
                        }
                    }
                }
            }

            if (requestedCollectionRow == null)
            {
                if (versionFailure == false)
                {
                    throw ADP.UndefinedCollection(collectionName);
                }
                else
                {
                    throw ADP.UnsupportedVersion(collectionName);
                }
            }

            if ((haveExactMatch == false) && (haveMultipleInexactMatches == true))
            {
                throw ADP.AmbigousCollectionName(collectionName);
            }

            return(requestedCollectionRow);
        }
        internal DataRow FindMetaDataCollectionRow(string collectionName)
        {
            DataTable table = this._metaDataCollectionsDataSet.Tables[DbMetaDataCollectionNames.MetaDataCollections];

            if (table == null)
            {
                throw ADP.InvalidXml();
            }
            DataColumn column = table.Columns[DbMetaDataColumnNames.CollectionName];

            if ((column == null) || (typeof(string) != column.DataType))
            {
                throw ADP.InvalidXmlMissingColumn(DbMetaDataCollectionNames.MetaDataCollections, DbMetaDataColumnNames.CollectionName);
            }
            DataRow row2  = null;
            string  str2  = null;
            bool    flag3 = false;
            bool    flag  = false;
            bool    flag2 = false;

            foreach (DataRow row in table.Rows)
            {
                string str = row[column, DataRowVersion.Current] as string;
                if (ADP.IsEmpty(str))
                {
                    throw ADP.InvalidXmlInvalidValue(DbMetaDataCollectionNames.MetaDataCollections, DbMetaDataColumnNames.CollectionName);
                }
                if (ADP.CompareInsensitiveInvariant(str, collectionName))
                {
                    if (!this.SupportedByCurrentVersion(row))
                    {
                        flag3 = true;
                    }
                    else if (collectionName == str)
                    {
                        if (flag)
                        {
                            throw ADP.CollectionNameIsNotUnique(collectionName);
                        }
                        row2 = row;
                        str2 = str;
                        flag = true;
                    }
                    else
                    {
                        if (str2 != null)
                        {
                            flag2 = true;
                        }
                        row2 = row;
                        str2 = str;
                    }
                }
            }
            if (row2 == null)
            {
                if (!flag3)
                {
                    throw ADP.UndefinedCollection(collectionName);
                }
                throw ADP.UnsupportedVersion(collectionName);
            }
            if (!flag && flag2)
            {
                throw ADP.AmbigousCollectionName(collectionName);
            }
            return(row2);
        }