public IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition, IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > exports)
        {
            if (!exports.Any())
            {
                exports = this.catalog.GetExports(definition);
            }

            if (exports.Any())
            {
                return(exports);
            }

            var returnedExports      = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();
            var importDefinitionType = ContractServices.GetImportDefinitionType(definition);

            if (!importDefinitionType.IsAbstract && !importDefinitionType.IsInterface)
            {
                var typeCatalog = new TypeCatalog(importDefinitionType);
                this.catalog.Catalogs.Add(typeCatalog);
                var currentExports = this.catalog.GetExports(definition);
                returnedExports.AddRange(currentExports);
            }

            return(returnedExports);
        }
 public void Calling_IsReflectionImportDefinition_with_null_importDefinition_throws_an_exception()
 {
     Assert.That(delegate
     {
         ContractServices.IsReflectionImportDefinition(null);
     }, Throws.TypeOf <ArgumentNullException>());
 }
Beispiel #3
0
        /// <summary>
        /// Method which can filter exports for given <see cref="ImportDefinition"/> or produce new exports.
        /// </summary>
        /// <param name="definition"><see cref="ImportDefinition"/> instance.</param>
        /// <param name="exports">A collection of <see cref="ExportDefinition"/>
        /// instances along with their <see cref="ComposablePartDefinition"/> instances which match given <see cref="ImportDefinition"/>.</param>
        /// <returns>A collection of <see cref="ExportDefinition"/>
        /// instances along with their <see cref="ComposablePartDefinition"/> instances which match given <see cref="ImportDefinition"/>.</returns>
        public IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > GetExports(ImportDefinition definition, IEnumerable <Tuple <ComposablePartDefinition, ExportDefinition> > exports)
        {
            if (exports.Any())
            {
                return(exports);
            }

            if (!ContractServices.IsReflectionImportDefinition(definition))
            {
                return(Enumerable.Empty <Tuple <ComposablePartDefinition, ExportDefinition> >());
            }

            var returnedExports      = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();
            var importDefinitionType = ContractServices.GetImportDefinitionType(definition);

            if (TypeHelper.IsGenericCollection(importDefinitionType))
            {
                importDefinitionType = TypeHelper.GetGenericCollectionParameter(importDefinitionType);
            }

            if (this.manufacturedParts.Contains(importDefinitionType))
            {
                returnedExports.AddRange(this.aggregateCatalog.GetExports(definition));
            }
            else if (TypeHelper.ShouldCreateClosedGenericPart(importDefinitionType))
            {
                CreateGenericParts(importDefinitionType);
                returnedExports.AddRange(this.aggregateCatalog.GetExports(definition));
            }

            return(returnedExports);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter contract data: ");

            Console.Write("Number: ");
            int number = int.Parse(Console.ReadLine());

            Console.Write("Date: ");
            DateTime date = DateTime.ParseExact(Console.ReadLine(), "dd/MM/yyyy", CultureInfo.InvariantCulture);

            Console.Write("Contract value: ");
            double totalValue = double.Parse(Console.ReadLine());

            Console.Write("Enter the number of installments: ");
            int numberInstallments = int.Parse(Console.ReadLine());

            Contract contract = new Contract(number, date, totalValue);

            ContractServices contractServices = new ContractServices();

            contractServices.ProcessContract(contract, numberInstallments, new Paypal());


            foreach (var item in contract.Installments)
            {
                Console.WriteLine(item);
            }



            Console.ReadKey();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter contract data");
            Console.Write("Number: ");
            int contractNumber = int.Parse(Console.ReadLine());

            Console.Write("Date (dd/MM/yyyy): ");
            DateTime contractDate = DateTime.ParseExact(Console.ReadLine(), "dd/MM/yyyy", CultureInfo.InvariantCulture);

            Console.Write("Contract value: ");
            double contractValue = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            Console.Write("Enter number of installments: ");
            int months = int.Parse(Console.ReadLine());

            Contract dados = new Contract(contractNumber, contractDate, contractValue);

            ContractServices contractServices = new ContractServices(new ValueJuros());

            contractServices.ProcessContract(dados, months);

            Console.WriteLine("Installments:");
            foreach (Installment installment in dados.Installments)
            {
                Console.WriteLine(installment);
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter contract data");
            Console.Write("Number: ");
            int number = int.Parse(Console.ReadLine());

            DateTime date = DateTime.Now;

            Console.Write("Contract value: ");
            double value = double.Parse(Console.ReadLine());

            Console.Write("Enter number of installments: ");
            int installmentsNumber = int.Parse(Console.ReadLine());

            Contract contract = new Contract(number, date, value, new List <Installment>());

            ContractServices contractService = new ContractServices(new PayPalService());

            contractService.ProcessContracts(contract, installmentsNumber);

            Console.WriteLine("Installments:");
            foreach (Installment installment in contract.Installments)
            {
                Console.WriteLine(installment.ToString());
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter contract data: ");
            Console.Write("Number: ");
            int contractNumber = int.Parse(Console.ReadLine());

            Console.Write("Date dd/mm/yyyy: ");
            DateTime contractDate = DateTime.ParseExact(Console.ReadLine(), "dd/MM/yyyy", CultureInfo.InvariantCulture);

            Console.Write("Contract value: ");
            double contractValue = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            Console.Write("Enter number of installments: ");
            int months = int.Parse(Console.ReadLine());

            Contrato myContract = new Contrato(contractNumber, contractDate, contractValue);

            ContractServices contractService = new ContractServices(new PaypalService());

            contractService.ProcessContract(myContract, months);

            Console.WriteLine("Installments: ");
            foreach (Installment installment in myContract.Installments)
            {
                Console.WriteLine(installment);
            }
        }
Beispiel #8
0
 public string UpdateContract(Contract contract)
 {
     if (ContractServices.UpdateContract_String(contract).ToLower() == "Successful".ToLower())
     {
         return("Succesfully Updated!");
     }
     else
     {
         return(ContractServices.UpdateContract_String(contract));;
     }
 }
Beispiel #9
0
 public string DeleteContract(int id)
 {
     if (ContractServices.DeleteContractByID_String(id).ToLower() == "Successful".ToLower())
     {
         return("Successfully Deleted!");
     }
     else
     {
         return(ContractServices.DeleteContractByID_String(id));
     }
 }
        public void GetContractsTest()
        {
            var target = new ContractServices();
            QueryCriteriaDTO queryCriteriaDTO = new QueryCriteriaDTO();

            queryCriteriaDTO.ContractNumber = "5822438";

            var result = target.GetContracts(queryCriteriaDTO);

            Assert.IsNotNull(result);
        }
Beispiel #11
0
        private static void RegisterQueries(IIocContainer container)
        {
            ContractServices.LoadDependentAssemblies(typeof(ApiCompositionMarkType).Assembly);

            var queryContracts = ContractServices.GetAllServices(".Contracts", "Query");

            container.RegisterAllServicesFactoryTransient((r, type) =>
            {
                var optPack = (IOptimizationPackage)r.Resolver(typeof(IOptimizationPackage));
                return(ProxyFactory.CreateQueryProxy(type, optPack));
            }, queryContracts);
        }
Beispiel #12
0
        internal static T CastExportedValue <T>(ICompositionElement element, object?exportedValue)
        {
            bool succeeded = ContractServices.TryCast(typeof(T), exportedValue, out object?typedExportedValue);

            if (!succeeded)
            {
                throw new CompositionContractMismatchException(SR.Format(
                                                                   SR.ContractMismatch_ExportedValueCannotBeCastToT,
                                                                   element.DisplayName,
                                                                   typeof(T)));
            }

            return((T)typedExportedValue !);
        }
Beispiel #13
0
        private object?Cast(Type type, Export export)
        {
            object?value = export.Value;

            if (!ContractServices.TryCast(type, value, out object?result))
            {
                throw new ComposablePartException(
                          SR.Format(
                              SR.ReflectionModel_ImportNotAssignableFromExport,
                              export.ToElement().DisplayName,
                              type.FullName),
                          Definition.ToElement());
            }

            return(result);
        }
Beispiel #14
0
        /// <summary>
        /// Gets type identity for the provided <see cref="IImportConvention"/>.
        /// </summary>
        /// <param name="importConvention">The <see cref="IImportConvention"/> that the type identity should be retreived for.</param>
        /// <param name="member">The <see cref="MemberInfo"/> that is being imported.</param>
        /// <returns>A <see cref="string"/> containing the type identity for the imported.</returns>
        /// <exception cref="ArgumentNullException">The value of the <paramref name="member"/> or <paramref name="importConvention"/> parameter was <see langword="null"/>.</exception>
        public virtual string GetImportTypeIdentity(IImportConvention importConvention, MemberInfo member)
        {
            if (importConvention == null)
            {
                throw new ArgumentNullException("importConvention", "The import convention cannot be null.");
            }

            if (member == null)
            {
                throw new ArgumentNullException("member", "The member cannot be null.");
            }

            return(ContractServices.GetImportTypeIdentity(
                       (importConvention.ContractType == null) ? null : importConvention.ContractType.Invoke(member),
                       member));
        }
Beispiel #15
0
        internal static T CastExportedValue <T>(ICompositionElement element, object exportedValue)
        {
            object typedExportedValue = null;

            bool succeeded = ContractServices.TryCast(typeof(T), exportedValue, out typedExportedValue);

            if (!succeeded)
            {
                throw new CompositionContractMismatchException(string.Format(CultureInfo.CurrentCulture,
                                                                             SR.ContractMismatch_ExportedValueCannotBeCastToT,
                                                                             element.DisplayName,
                                                                             typeof(T)));
            }

            return((T)typedExportedValue);
        }
Beispiel #16
0
        /// <summary>
        /// Gets contract name for the provided <see cref="IExportConvention"/>.
        /// </summary>
        /// <param name="exportConvention">The <see cref="IExportConvention"/> that the contract name should be retreived for.</param>
        /// <param name="member">The <see cref="MemberInfo"/> that is being exported.</param>
        /// <returns>A <see cref="string"/> containing the contract name for the export.</returns>
        /// <exception cref="ArgumentNullException">The value of the <paramref name="member"/> or <paramref name="exportConvention"/> parameter was <see langword="null"/>.</exception>
        public virtual string GetExportContractName(IExportConvention exportConvention, MemberInfo member)
        {
            if (exportConvention == null)
            {
                throw new ArgumentNullException("exportConvention", "The export convention cannot be null.");
            }

            if (member == null)
            {
                throw new ArgumentNullException("member", "The member cannot be null.");
            }

            return(ContractServices.GetExportContractName(
                       (exportConvention.ContractName == null) ? null : exportConvention.ContractName.Invoke(member),
                       (exportConvention.ContractType == null) ? null : exportConvention.ContractType.Invoke(member),
                       member));
        }
Beispiel #17
0
        private static void RegisterCommands(IIocContainer container)
        {
            ContractServices.LoadDependentAssemblies(typeof(ApiCoordinationTypeMark).Assembly);

            var commandContracts = ContractServices.GetAllServices(".Contracts", "Command");

            container.RegisterPerGraph(
                new[] { typeof(IProxyContainer) },
                typeof(ProxyContainer));

            container.RegisterAllServicesFactoryTransient((r, type) =>
            {
                var optPack        = r.Resolver(typeof(IOptimizationPackage)) as IOptimizationPackage;
                var proxyContainer = r.Resolver(typeof(IProxyContainer)) as IProxyContainer;
                return(CommandServiceFactory.CreateCommandService(type, proxyContainer, optPack));
            }, commandContracts);
        }
        internal static T GetExportedValueFromLazy <T>(Export export)
        {
            object exportedValue      = export.Value;
            object typedExportedValue = null;

            bool succeeded = ContractServices.TryCast(typeof(T), exportedValue, out typedExportedValue);

            if (!succeeded)
            {
                throw new CompositionContractMismatchException(string.Format(CultureInfo.CurrentCulture,
                                                                             Strings.ContractMismatch_ExportedValueCannotBeCastToT,
                                                                             export.ToElement().DisplayName,
                                                                             typeof(T)));
            }

            return((T)typedExportedValue);
        }
Beispiel #19
0
        private object Cast(Type type, Export export)
        {
            // TODO: Need to catch CompositionException to provide
            // additional information about what member we're setting
            // and the current dependency graph.
            object value = export.Value;

            object result;

            if (!ContractServices.TryCast(type, value, out result))
            {
                throw new ComposablePartException(
                          String.Format(CultureInfo.CurrentCulture,
                                        Strings.ReflectionModel_ImportNotAssignableFromExport,
                                        export.ToElement().DisplayName,
                                        type.FullName),
                          this.Definition.ToElement());
            }

            return(result);
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter contract data ");
            Console.Write("Number: ");
            int number = int.Parse(Console.ReadLine());

            Console.Write("Date (dd/MM/yyyy): ");
            DateTime date = DateTime.Parse(Console.ReadLine());

            Console.Write("Contract value: ");
            double   value    = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
            Contract contract = new Contract(number, date, value);

            Console.Write("Enter number of installments: ");
            int installments = int.Parse(Console.ReadLine());
            IOnlinePaymentService service          = new PaypalServices();
            ContractServices      contractServices = new ContractServices(service);

            contractServices.ProcessContract(contract, installments);
            foreach (var installment in contract.Installments)
            {
                Console.WriteLine($"{installment.DueDate.ToString("dd/MM/yyyy")} - {installment.Amount.ToString("F2")}");
            }
        }
 public void When_retrieving_import_definition_typoe_for_field_import_import_3_DummyImport3_is_returned()
 {
     ImportDefinition = DummyPartImports.Single(d => d.ContractName == AttributedModelServices.GetContractName(typeof(IDummyImport3)));
     Assert.AreEqual(typeof(IDummyImport3), ContractServices.GetImportDefinitionType(ImportDefinition));
 }
Beispiel #22
0
 public Contract GetContractByID(int id)
 {
     return(ContractServices.GetContractByID_Contract(id));
 }
Beispiel #23
0
 public List <Contract> GetContracts()
 {
     return(ContractServices.GetContracts_ListContract());
 }