Пример #1
0
        /// <summary>
        /// Returns the operations for the specified method.
        /// </summary>
        /// <param name="method">The operation method.</param>
        /// <returns>The read-only list of provided operations for the specified method.</returns>
        /// <exception cref="System.ArgumentNullException">The method is null.</exception>
        public IList <Type> GetOperations(OperationMethod method)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method", "The method is null.");
            }

            List <Type> operation = new List <Type>();

            Type[] types = _assembly.GetTypes();

            // get operations
            foreach (Type operationType in types.Where(type => !type.IsAbstract && type.GetCustomAttributes(typeof(OperationMethodImplementationAttribute), false).Length > 0))
            {
                OperationMethodImplementationAttribute attribute = operationType.GetCustomAttributes(typeof(OperationMethodImplementationAttribute), false)[0] as OperationMethodImplementationAttribute;

                // the operation matches the specified method
                if (attribute.Identifier.Equals(method.Identifier) && attribute.Version.Equals(method.Version))
                {
                    operation.Add(operationType);
                }
            }

            return(operation.AsReadOnly());
        }
Пример #2
0
        /// <summary>
        /// Returns all operations provided by the provider.
        /// </summary>
        /// <returns>The read-only dictionary of provided operations.</returns>
        public IDictionary <OperationMethod, IList <Type> > GetOperations()
        {
            Dictionary <OperationMethod, IList <Type> > operations = new Dictionary <OperationMethod, IList <Type> >();

            Type[] types = _assembly.GetTypes();
            List <OperationMethod> listOfMethods = new List <OperationMethod>();

            // get methods
            foreach (Type collectionType in types.Where(type => type.GetCustomAttributes(typeof(OperationMethodCollectionAttribute), false).Length > 0))
            {
                listOfMethods.AddRange(collectionType.InvokeMember("All", BindingFlags.GetProperty, null, null, null) as IList <OperationMethod>);
            }

            // get operations
            foreach (Type operationType in types.Where(type => !type.IsAbstract && type.GetCustomAttributes(typeof(OperationMethodImplementationAttribute), false).Length > 0))
            {
                OperationMethodImplementationAttribute attribute = operationType.GetCustomAttributes(typeof(OperationMethodImplementationAttribute), false)[0] as OperationMethodImplementationAttribute;
                OperationMethod method = listOfMethods.FirstOrDefault(m => m.Identifier.Equals(attribute.Identifier));

                if (method != null) // add methods and operations to the collection
                {
                    if (!operations.ContainsKey(method))
                    {
                        operations.Add(method, new List <Type>());
                    }

                    operations[method].Add(operationType);
                }
            }

            return(new ReadOnlyDictionary <OperationMethod, IList <Type> >(operations));
        }
Пример #3
0
        public void OperationTypeAttributeConstructorTest()
        {
            OperationMethodImplementationAttribute attribute;

            // test case 1: improper parameters

            Assert.Throws <ArgumentNullException>(() => attribute = new OperationMethodImplementationAttribute(null, null));
            Assert.Throws <ArgumentNullException>(() => attribute = new OperationMethodImplementationAttribute(IdentifiedObject.UserDefinedIdentifier, null));
            Assert.Throws <ArgumentNullException>(() => attribute = new OperationMethodImplementationAttribute(IdentifiedObject.UserDefinedIdentifier, "Test Method", null));
            Assert.Throws <ArgumentException>(() => attribute     = new OperationMethodImplementationAttribute(IdentifiedObject.UserDefinedIdentifier, "Test Method", "1.0.0", typeof(Object)));

            // test case 2: proper parameters without credential

            attribute = new OperationMethodImplementationAttribute(IdentifiedObject.UserDefinedIdentifier, "Test Method");

            Assert.AreEqual(IdentifiedObject.UserDefinedIdentifier, attribute.Identifier);
            Assert.AreEqual("Test Method", attribute.Name);
            Assert.IsNotNull(attribute.GetCredential());
            Assert.IsInstanceOf <OperationCredential>(attribute.GetCredential());

            // test case 3: proper parameters with credential

            attribute = new OperationMethodImplementationAttribute(IdentifiedObject.UserDefinedIdentifier, "Test Method", "1.0.0", typeof(OperationCredential));

            Assert.IsNotNull(attribute.GetCredential());
            Assert.IsInstanceOf <OperationCredential>(attribute.GetCredential());
        }