예제 #1
0
        private QueryDefinitionCollection LoadAllQueryDefinitions()
        {
            var storageProviderDefinitionFinder = new StorageGroupBasedStorageProviderDefinitionFinder(DomainObjectsConfiguration.Current.Storage);

            if (QueryFiles.Count == 0)
            {
                return(new QueryConfigurationLoader(GetDefaultQueryFilePath(), storageProviderDefinitionFinder).GetQueryDefinitions());
            }
            else
            {
                QueryDefinitionCollection result = new QueryDefinitionCollection();

                for (int i = 0; i < QueryFiles.Count; i++)
                {
                    QueryConfigurationLoader  loader           = new QueryConfigurationLoader(QueryFiles[i].RootedFileName, storageProviderDefinitionFinder);
                    QueryDefinitionCollection queryDefinitions = loader.GetQueryDefinitions();
                    try
                    {
                        result.Merge(queryDefinitions);
                    }
                    catch (DuplicateQueryDefinitionException ex)
                    {
                        string message = string.Format("File '{0}' defines a duplicate for query definition '{1}'.", QueryFiles[i].RootedFileName,
                                                       ex.QueryDefinition.ID);
                        throw new ConfigurationException(message);
                    }
                }
                return(result);
            }
        }
        // standard constructor for collections

        /// <summary>
        /// Initializes a new <b>QueryDefinitionCollection</b> as a shallow copy of a given <see cref="QueryDefinitionCollection"/>.
        /// </summary>
        /// <remarks>The new <b>QueryDefinitionCollection</b> has the same items as the given <paramref name="collection"/>.</remarks>
        /// <param name="collection">The <see cref="QueryDefinitionCollection"/> to copy. Must not be <see langword="null"/>.</param>
        /// <param name="makeCollectionReadOnly">Indicates whether the new collection should be read-only.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="collection"/> is <see langword="null"/>.</exception>
        public QueryDefinitionCollection(
            QueryDefinitionCollection collection,
            bool makeCollectionReadOnly)
        {
            ArgumentUtility.CheckNotNull("collection", collection);

            foreach (QueryDefinition queryDefinition in collection)
            {
                Add(queryDefinition);
            }

            this.SetIsReadOnly(makeCollectionReadOnly);
        }
        public void Merge(QueryDefinitionCollection source)
        {
            ArgumentUtility.CheckNotNull("source", source);

            foreach (QueryDefinition query in source)
            {
                if (Contains(query.ID))
                {
                    throw new DuplicateQueryDefinitionException(this[query.ID], query);
                }
                else
                {
                    Add(query);
                }
            }
        }