/// <summary>
        ///     Adds a collection of items to the collection
        /// </summary>
        /// <param name="items"> The items to add to the list </param>
        /// <exception cref="System.ArgumentNullException">Thrown if item argument is null</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if the item passed in or the collection itself instance is in ReadOnly state</exception>
        /// <exception cref="System.ArgumentException">Thrown if the item that is being added already belongs to another ItemCollection</exception>
        /// <exception cref="System.ArgumentException">Thrown if the ItemCollection already contains an item with the same identity</exception>
        /// <returns> Whether the add was successful </returns>
        internal bool AtomicAddRange(List <T> items)
        {
            var originalData = _collectionData;
            var newData      = new CollectionData(originalData, items.Count);

            // Add the new items, this will also perform duplication check
            foreach (var item in items)
            {
                if (item == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("items"));
                }
                Debug.Assert(!String.IsNullOrEmpty(item.Identity), "Identity of the item must never be null or empty");

                AddInternalHelper(item, newData, false);
            }

            var swappedOutData = Interlocked.CompareExchange(ref _collectionData, newData, originalData);

            // Check if the exchange was done, if not, then someone must have changed the data in the meantime, so
            // return false
            if (swappedOutData != originalData)
            {
                return(false);
            }

            return(true);
        }
 internal static void CheckAndAddMembers(IEnumerable <EdmMember> members, EntityType entityType)
 {
     foreach (EdmMember member in members)
     {
         if (member == null)
         {
             throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(members)));
         }
         entityType.AddMember(member);
     }
 }
 internal void AddRange(List <T> items)
 {
     Check.NotNull <List <T> >(items, nameof(items));
     foreach (T obj in items)
     {
         if ((object)obj == null)
         {
             throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(items)));
         }
         this.AddInternal(obj);
     }
 }
        public void AddRange_throws_ArgumentNullException_for_null_collection_item()
        {
            var metadataCollection = new MetadataCollection <MetadataItem>();

            Assert.Equal(
                Strings.ADP_CollectionParameterElementIsNull("items"),
                Assert.Throws <ArgumentException>(
                    () => metadataCollection.AddRange(
                        new List <MetadataItem>
            {
                null
            })).Message);
        }
        public void Constructor_throws_ArgumentException_for_null_collection_item()
        {
            var items = new[]
            {
                new EntityType("E0", "N", DataSpace.CSpace),
                null,
                new EntityType("E2", "N", DataSpace.CSpace)
            };

            Assert.Equal(
                Strings.ADP_CollectionParameterElementIsNull("items"),
                Assert.Throws <ArgumentException>(() => new MetadataCollection <MetadataItem>(items)).Message);
        }
        // <summary>
        // Adds the specified items to the collection.
        // </summary>
        // <param name="items">The items to add to the collection.</param>
        // <exception cref="System.ArgumentException">An item to add is null.</exception>
        // <exception cref="System.ArgumentException">An item with the same identity already exists.</exception>
        // <returns>A boolean that indicates whether the operation was successful.</returns>
        internal void AddRange(IEnumerable <T> items)
        {
            Check.NotNull(items, "items");

            // Add the new items, this will also perform duplication check.
            foreach (var item in items)
            {
                if (item == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("items"));
                }

                AddInternal(item);
            }
        }
        public static MetadataArtifactLoader CreateCompositeFromXmlReaders(
            IEnumerable <XmlReader> xmlReaders)
        {
            List <MetadataArtifactLoader> allCollections = new List <MetadataArtifactLoader>();

            foreach (XmlReader xmlReader in xmlReaders)
            {
                if (xmlReader == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(xmlReaders)));
                }
                allCollections.Add((MetadataArtifactLoader) new MetadataArtifactLoaderXmlReaderWrapper(xmlReader));
            }
            return(MetadataArtifactLoader.Create(allCollections));
        }
Example #8
0
        // <summary>
        // Helper method that wraps a collection of XmlReader objects in MetadataArtifactLoader
        // instances.
        // </summary>
        // <param name="xmlReaders"> The collection of XmlReader objects to wrap </param>
        // <returns> An instance of MetadataArtifactLoader </returns>
        public static MetadataArtifactLoader CreateCompositeFromXmlReaders(IEnumerable <XmlReader> xmlReaders)
        {
            var loaders = new List <MetadataArtifactLoader>();

            foreach (var reader in xmlReaders)
            {
                if (reader == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("xmlReaders"));
                }

                loaders.Add(new MetadataArtifactLoaderXmlReaderWrapper(reader));
            }

            return(Create(loaders));
        }
Example #9
0
        /// <summary>
        ///     Checks for each property to be non-null and then adds it to the member collection
        /// </summary>
        /// <param name="members"> members for this type </param>
        /// <param name="entityType"> the membersCollection to which the members should be added </param>
        internal static void CheckAndAddMembers(
            IEnumerable <EdmMember> members,
            EntityType entityType)
        {
            foreach (var member in members)
            {
                // Check for each property to be non-null
                if (null == member)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("members"));
                }

                // Add the property to the member collection
                entityType.AddMember(member);
            }
        }
 internal MetadataCollection(IEnumerable <T> items)
 {
     this._metadataList = new List <T>();
     if (items == null)
     {
         return;
     }
     foreach (T obj in items)
     {
         if ((object)obj == null)
         {
             throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(items)));
         }
         this.AddInternal(obj);
     }
 }
 internal void CheckAndAddKeyMembers(IEnumerable <string> keyMembers)
 {
     foreach (string keyMember in keyMembers)
     {
         if (keyMember == null)
         {
             throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(keyMembers)));
         }
         EdmMember member;
         if (!this.Members.TryGetValue(keyMember, false, out member))
         {
             throw new ArgumentException(Strings.InvalidKeyMember((object)keyMember));
         }
         this.AddKeyMember(member);
     }
 }
        /// <summary>
        ///     The constructor for constructing the collection with the given items
        /// </summary>
        /// <param name="items"> The items to populate the collection </param>
        internal MetadataCollection(IEnumerable <T> items)
        {
            _collectionData = new CollectionData();
            if (items != null)
            {
                foreach (var item in items)
                {
                    if (item == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("items"));
                    }

                    Debug.Assert(!String.IsNullOrEmpty(item.Identity), "Identity of the item must never be null or empty");
                    AddInternal(item);
                }
            }
        }
 private static IEnumerable <EdmProperty> CheckProperties(
     IEnumerable <EdmProperty> properties)
 {
     if (properties != null)
     {
         int num = 0;
         foreach (EdmProperty property in properties)
         {
             if (property == null)
             {
                 throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(properties)));
             }
             ++num;
         }
     }
     return(properties);
 }
        // <summary>
        // Creates a metadata collection that contains the specified items.
        // The items are copied into an internal list.
        // </summary>
        // <param name="items">An enumerable of items to be stored in the collection.</param>
        internal MetadataCollection(IEnumerable <T> items)
        {
            _metadataList = new List <T>();

            if (items != null)
            {
                foreach (var item in items)
                {
                    if (item == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("items"));
                    }

                    AddInternal(item);
                }
            }
        }
Example #15
0
 /// <summary>
 ///     Checks for each key member to be non-null
 ///     also check for it to be present in the members collection
 ///     and then adds it to the KeyMembers collection.
 ///     Throw if the key member is not already in the members
 ///     collection. Cannot do much other than that as the
 ///     Key members is just an Ienumerable of the names
 ///     of the members.
 /// </summary>
 /// <param name="keyMembers"> the list of keys (member names) to be added for the given type </param>
 internal void CheckAndAddKeyMembers(IEnumerable <String> keyMembers)
 {
     foreach (var keyMember in keyMembers)
     {
         // Check for each keymember to be non-null
         if (null == keyMember)
         {
             throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("keyMembers"));
         }
         // Check for whether the key exists in the members collection
         EdmMember member;
         if (!Members.TryGetValue(keyMember, false, out member))
         {
             throw new ArgumentException(Strings.InvalidKeyMember(keyMember));
             //--- to do, identify the right exception to throw here
         }
         // Add the key member to the key member collection
         AddKeyMember(member);
     }
 }
Example #16
0
        private static IEnumerable <EdmProperty> CheckProperties(IEnumerable <EdmProperty> properties)
        {
            if (null != properties)
            {
                var i = 0;
                foreach (var prop in properties)
                {
                    if (prop == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("properties"));
                    }
                    i++;
                }

                /*
                 * if (i < 1)
                 * {
                 *  throw EntityUtil.ArgumentOutOfRange("properties");
                 * }
                 */
            }
            return(properties);
        }
        internal EdmFunction(
            string name,
            string namespaceName,
            DataSpace dataSpace,
            EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            this._schemaName = payload.Schema;
            IList <FunctionParameter> source = payload.ReturnParameters ?? (IList <FunctionParameter>) new FunctionParameter[0];

            foreach (FunctionParameter functionParameter in (IEnumerable <FunctionParameter>)source)
            {
                if (functionParameter == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)nameof(ReturnParameters)));
                }
                if (functionParameter.Mode != ParameterMode.ReturnValue)
                {
                    throw new ArgumentException(Strings.NonReturnParameterInReturnParameterCollection);
                }
            }
            this._returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(source.Select <FunctionParameter, FunctionParameter>((Func <FunctionParameter, FunctionParameter>)(returnParameter => SafeLink <EdmFunction> .BindChild <FunctionParameter>(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))).ToList <FunctionParameter>());
            if (payload.IsAggregate.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                EdmFunction.SetFunctionAttribute(ref this._functionAttributes, EdmFunction.FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }
            if (payload.ParameterTypeSemantics.HasValue)
            {
                this._parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }
            if (payload.StoreFunctionName != null)
            {
                this._storeFunctionNameAttribute = payload.StoreFunctionName;
            }
            if (payload.EntitySets != null)
            {
                if (payload.EntitySets.Count != source.Count)
                {
                    throw new ArgumentException(Strings.NumberOfEntitySetsDoesNotMatchNumberOfReturnParameters);
                }
                this._entitySets = new ReadOnlyCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                if (this._returnParameters.Count > 1)
                {
                    throw new ArgumentException(Strings.NullEntitySetsForFunctionReturningMultipleResultSets);
                }
                this._entitySets = new ReadOnlyCollection <EntitySet>((IList <EntitySet>) this._returnParameters.Select <FunctionParameter, EntitySet>((Func <FunctionParameter, EntitySet>)(p => (EntitySet)null)).ToList <EntitySet>());
            }
            if (payload.CommandText != null)
            {
                this._commandTextAttribute = payload.CommandText;
            }
            if (payload.Parameters != null)
            {
                foreach (FunctionParameter parameter in (IEnumerable <FunctionParameter>)payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull((object)"parameters"));
                    }
                    if (parameter.Mode == ParameterMode.ReturnValue)
                    {
                        throw new ArgumentException(Strings.ReturnParameterInInputParameterCollection);
                    }
                }
                this._parameters = (ReadOnlyMetadataCollection <FunctionParameter>) new SafeLinkCollection <EdmFunction, FunctionParameter>(this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>((IEnumerable <FunctionParameter>)payload.Parameters));
            }
            else
            {
                this._parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }
Example #18
0
        internal EdmFunction(string name, string namespaceName, DataSpace dataSpace, EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            //---- name of the 'schema'
            //---- this is used by the SQL Gen utility and update pipeline to support generation of the correct function name in the store
            _schemaName = payload.Schema;

            var returnParameters = payload.ReturnParameters ?? new FunctionParameter[0];

            foreach (var returnParameter in returnParameters)
            {
                if (returnParameter == null)
                {
                    throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("ReturnParameters"));
                }

                if (returnParameter.Mode != ParameterMode.ReturnValue)
                {
                    throw new ArgumentException(Strings.NonReturnParameterInReturnParameterCollection);
                }
            }

            _returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(
                returnParameters
                .Select(
                    returnParameter =>
                    SafeLink <EdmFunction> .BindChild(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))
                .ToList());

            if (payload.IsAggregate.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                SetFunctionAttribute(
                    ref _functionAttributes, FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }

            if (payload.ParameterTypeSemantics.HasValue)
            {
                _parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }

            if (payload.StoreFunctionName != null)
            {
                _storeFunctionNameAttribute = payload.StoreFunctionName;
            }

            if (payload.EntitySets != null)
            {
                if (payload.EntitySets.Count != returnParameters.Count)
                {
                    throw new ArgumentException(Strings.NumberOfEntitySetsDoesNotMatchNumberOfReturnParameters);
                }

                _entitySets = new ReadOnlyCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                if (_returnParameters.Count > 1)
                {
                    throw new ArgumentException(Strings.NullEntitySetsForFunctionReturningMultipleResultSets);
                }

                _entitySets = new ReadOnlyCollection <EntitySet>(_returnParameters.Select(p => (EntitySet)null).ToList());
            }

            if (payload.CommandText != null)
            {
                _commandTextAttribute = payload.CommandText;
            }

            if (payload.Parameters != null)
            {
                // validate the parameters
                foreach (var parameter in payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("parameters"));
                    }

                    if (parameter.Mode == ParameterMode.ReturnValue)
                    {
                        throw new ArgumentException(Strings.ReturnParameterInInputParameterCollection);
                    }
                }

                // Populate the parameters
                _parameters = new SafeLinkCollection <EdmFunction, FunctionParameter>(
                    this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>(payload.Parameters));
            }
            else
            {
                _parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }
Example #19
0
        internal EdmFunction(string name, string namespaceName, DataSpace dataSpace, EdmFunctionPayload payload)
            : base(name, namespaceName, dataSpace)
        {
            //---- name of the 'schema'
            //---- this is used by the SQL Gen utility and update pipeline to support generation of the correct function name in the store
            _schemaName = payload.Schema;
            _fullName   = NamespaceName + "." + Name;

            var returnParameters = payload.ReturnParameters;

            Debug.Assert(returnParameters.All((returnParameter) => returnParameter != null), "All return parameters must be non-null");
            Debug.Assert(
                returnParameters.All((returnParameter) => returnParameter.Mode == ParameterMode.ReturnValue),
                "Return parameter in a function must have the ParameterMode equal to ReturnValue.");

            _returnParameters = new ReadOnlyMetadataCollection <FunctionParameter>(
                returnParameters
                .Select(
                    (returnParameter) =>
                    SafeLink <EdmFunction> .BindChild(this, FunctionParameter.DeclaringFunctionLinker, returnParameter))
                .ToList());

            if (payload.IsAggregate.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.Aggregate, payload.IsAggregate.Value);
            }
            if (payload.IsBuiltIn.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.BuiltIn, payload.IsBuiltIn.Value);
            }
            if (payload.IsNiladic.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.NiladicFunction, payload.IsNiladic.Value);
            }
            if (payload.IsComposable.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsComposable, payload.IsComposable.Value);
            }
            if (payload.IsFromProviderManifest.HasValue)
            {
                SetFunctionAttribute(
                    ref _functionAttributes, FunctionAttributes.IsFromProviderManifest, payload.IsFromProviderManifest.Value);
            }
            if (payload.IsCachedStoreFunction.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsCachedStoreFunction, payload.IsCachedStoreFunction.Value);
            }
            if (payload.IsFunctionImport.HasValue)
            {
                SetFunctionAttribute(ref _functionAttributes, FunctionAttributes.IsFunctionImport, payload.IsFunctionImport.Value);
            }

            if (payload.ParameterTypeSemantics.HasValue)
            {
                _parameterTypeSemantics = payload.ParameterTypeSemantics.Value;
            }

            if (payload.StoreFunctionName != null)
            {
                _storeFunctionNameAttribute = payload.StoreFunctionName;
            }

            if (payload.EntitySets != null)
            {
                Debug.Assert(
                    _returnParameters.Count == payload.EntitySets.Length,
                    "The number of entity sets should match the number of return parameters");
                _entitySets = new ReadOnlyMetadataCollection <EntitySet>(payload.EntitySets);
            }
            else
            {
                var list = new List <EntitySet>();
                if (_returnParameters.Count != 0)
                {
                    Debug.Assert(
                        _returnParameters.Count == 1, "If there was more than one result set payload.EntitySets should not have been null");
                    list.Add(null);
                }
                _entitySets = new ReadOnlyMetadataCollection <EntitySet>(list);
            }

            if (payload.CommandText != null)
            {
                _commandTextAttribute = payload.CommandText;
            }

            if (payload.Parameters != null)
            {
                // validate the parameters
                foreach (var parameter in payload.Parameters)
                {
                    if (parameter == null)
                    {
                        throw new ArgumentException(Strings.ADP_CollectionParameterElementIsNull("parameters"));
                    }
                    Debug.Assert(
                        parameter.Mode != ParameterMode.ReturnValue, "No function parameter can have ParameterMode equal to ReturnValue.");
                }

                // Populate the parameters
                _parameters = new SafeLinkCollection <EdmFunction, FunctionParameter>(
                    this, FunctionParameter.DeclaringFunctionLinker, new MetadataCollection <FunctionParameter>(payload.Parameters));
            }
            else
            {
                _parameters = new ReadOnlyMetadataCollection <FunctionParameter>(new MetadataCollection <FunctionParameter>());
            }
        }