Ejemplo n.º 1
0
        public Option <T> Next()
        {
            var r = random_.NextDouble();

            if (sortedWeightsList_ == null)
            {
                int idx = (int)(r * list_.Length);
                return(Option.Any(list_[idx]));
            }
            else
            {
                var weight = (decimal)r * weightsSum_;
                var sum    = 0m;
                for (int i = 0; i < sortedWeightsList_.Length; i++)
                {
                    var item = sortedWeightsList_[i];
                    sum += item.Item1;

                    if (sum >= weight)
                    {
                        return(Option.Any(list_[item.Item2]));
                    }
                }

                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 2
0
        private static Root GetRoot(string asOfDate, string tag)
        {
            var randomSeed = (asOfDate + tag + "report2").ToInt32();

            var rootCredit =
                new RootCredit()
                .Generate(
                    root =>
                    root
                    .Property(_ => _.Name).WithStaticValue("serviceTree")
                    .Property(_ => _.Counterparty).WithGeneratedValue(_ => new RandomListValueGenerator <string>(randomSeed, DataLists.Country))
                    .Property(_ => _.Level)
                    .WithNewArray(
                        InstanceFactory.Create <LevelSector>(),
                        level1 =>
                        level1
                        .Property(_ => _.Name).WithGeneratedValue(_ => new ListValueGenerator <string>(DataLists.Markets))
                        .Property(_ => _.Leg_Name).WithGeneratedValue(
                            context =>
            {
                var regexGenerator = new RegexValueGenerator(randomSeed, @"\w{3}\d*");
                return(new LambdaValueGenerator <string>(() => Option.Any(context.CurrentInstance.Name + regexGenerator.Next().Value)));
            })
                        .Property(_ => _.MV_Pct).WithGeneratedValue(_ => (double)_, _ => new PercentageValueGenerator(randomSeed, DataLists.Markets.Length))
                        )
                    );

            return(rootCredit);
        }
Ejemplo n.º 3
0
        private static void ProcessTree(Option<IAbstractSyntaxTree> ast, IGenerator generator)
        {
            if (!ast.Any())
                return;

            generator.Process(ast.Single());
        }
Ejemplo n.º 4
0
        public void OptionAny()
        {
            // Option with value
            var optionInt = Option <int> .Some(12);

            Assert.IsTrue(optionInt.Any());
            Assert.IsTrue(optionInt.Any(intValue => intValue == 12));
            Assert.IsFalse(optionInt.Any(intValue => intValue == 13));

            // Empty option
            Option <int> emptyOptionInt = Option.None;

            Assert.IsFalse(emptyOptionInt.Any());
            Assert.IsFalse(emptyOptionInt.Any(intValue => intValue == 12));

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws <ArgumentNullException>(() => optionInt.Any(null));
        }
Ejemplo n.º 5
0
        public Option <decimal> Next()
        {
            generatedCount_++;
            if (generatedCount_ > count_)
            {
                return(Option.None <decimal>());
            }

            return(Option.Any(prcBuf_[generatedCount_ - 1]));
        }
        private void ProcessPendingWithdrawals()
        {
            Option <MoneyTransaction> option = Option <MoneyTransaction> .CreateEmpty();

            do
            {
                option = this.TrySelectPendingTransaction();
                ProcessPendingWithdrawal(option);
            }while (option.Any());
        }
Ejemplo n.º 7
0
        public void Option_Any_With_None_Must_Return_False()
        {
            // Arrange
            Option <string> option = Option.None;

            // Act
            var result = option.Any();

            // Assert
            _ = result.Must().BeFalse();
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> OnGetAsync()
        {
            Option <string> HtmlDataOption = await _blogConfig.GetWhoIAmHtml();

            if (!HtmlDataOption.Any())
            {
                return(RedirectToPage("/NotFound"));
            }
            HtmlData = HtmlDataOption.Single();
            return(Page());
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> OnPostAsync([FromServices] BlogEntryComponentFactory blogEntryComponentFactory)
        {
            if (blogEntryComponentFactory == null)
            {
                throw new ArgumentNullException(nameof(blogEntryComponentFactory));
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Option <BlogEntryTextModel> blogEntryOption = await _queryComponent.BlogAsync(Id);

            if (!blogEntryOption.Any())
            {
                return(RedirectToPage("/NotFound"));
            }

            BlogEntryTextModel Blog = blogEntryOption.Single();

            Option <BlogEntryComponent> componentResult = await blogEntryComponentFactory.LoadComponentAsynd(Blog.BlogEntryId);

            if (!componentResult.Any())
            {
                return(RedirectToPage("/NotFound"));
            }

            BlogEntryComponent component = componentResult.Single();

            WorkflowResult result = await component.Update(
                BlogEntryUpdateRequest.UriKey,
                BlogEntryUpdateRequest.Title,
                BlogEntryUpdateRequest.MinutesToRead,
                BlogEntryUpdateRequest.TextIntro,
                BlogEntryUpdateRequest.TextEntry,
                BlogEntryUpdateRequest.KeyWordId
                );

            if (!result.Success)
            {
                for (int i = 0; i < result.Errors.Length; i++)
                {
                    ModelState.AddModelError("", result.Errors[i]);
                }
            }
            else
            {
                Id = BlogEntryUpdateRequest.UriKey;
            }

            return(await BindPageModelAndRedirect(true, !result.Success));
        }
Ejemplo n.º 10
0
        public Option <double> Next()
        {
            generatedCount_++;
            if (generatedCount_ > count_)
            {
                return(Option.None <double>());
            }

            var y = func_(generatedCount_ - 1, count_);

            return(Option.Any(y));
        }
Ejemplo n.º 11
0
        private void ProcessPendingWithdrawal(Option <MoneyTransaction> option)
        {
            if (!option.Any())
            {
                return;
            }

            MoneyTransaction transaction = option.Single();

            base.RegisterTransaction(transaction);
            this.pendingTransactions.Remove(transaction);
        }
Ejemplo n.º 12
0
        public Option <T> Next()
        {
            generatedCount_++;
            if (generatedCount_ > count_)
            {
                return(Option.None <T>());
            }

            var value = list_[index_];

            index_++;
            NormalizeIndex();
            return(Option.Any(value));
        }
Ejemplo n.º 13
0
        public IDailyList BuildFor(DateTime date)
        {
            Option <IDailyList> list = this.listRepository.TryGet(date);

            if (list.Any())
            {
                return(list.Single());
            }

            IDailyList newList = this.fallbackBuilder.BuildFor(date);

            this.listRepository.Add(newList);

            return(newList);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> OnPostAddPhoneCallAsync([FromServices] CustomerComponentUowFactory customerComponentUowFactory)
        {
            if (customerComponentUowFactory == null)
            {
                throw new ArgumentNullException(nameof(customerComponentUowFactory));
            }

            ModelState.Clear();
            if (!TryValidateModel(AddPhoneCall))
            {
                ModelState.TryAddModelError("", "Parametros incorrectos");
                return(Page());
            }

            Option <ICustomerComponentUow> customerComponentOption = await customerComponentUowFactory.ExistingCustomerUowAsync(Id);

            if (!customerComponentOption.Any())
            {
                ModelState.TryAddModelError("", "El registro ya no se encuentra en BD");
                return(Page());
            }

            using (ICustomerComponentUow customerComponent = customerComponentOption.Single())
            {
                try
                {
                    WorkflowResult result = await customerComponent.AddPhoneCallAsync(AddPhoneCall.Description, UserId());

                    if (!result.Success)
                    {
                        customerComponent.RollbackChanges();

                        for (int i = 0; i < result.Errors.Length; i++)
                        {
                            ModelState.TryAddModelError("", result.Errors[i]);
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    customerComponent.RollbackChanges();
                    ModelState.AddModelError("", ex.Message);
                }
            }
            Customer = await _customersQueryComponent.CustomerAsync(Id);

            return(Page());
        }
Ejemplo n.º 15
0
        private async Task <ActionResult> BindPageModelAndRedirect(bool isPost = false, bool isError = false)
        {
            Option <BlogEntryTextModel> blogEntryOption = await _queryComponent.BlogAsync(Id);

            if (!blogEntryOption.Any())
            {
                return(RedirectToPage("/NotFound"));
            }

            BlogEntryTextModel Blog = blogEntryOption.Single();

            BlogEntryUpdateRequest = Blog.MapToAddUpdateBlogEntryRequest();

            if (isPost && !isError)
            {
                return(RedirectToPage("/Blog/Index"));
            }
            return(Page());
        }
Ejemplo n.º 16
0
        public async Task <ActionResult> OnGetAsync(int pageIndex = 1, int pageLimit = 10)
        {
            if (pageIndex <= 0 || pageLimit <= 0)
            {
                return(RedirectToPage("/NotFound"));
            }
            BlogModel.Limit     = pageLimit;
            BlogModel.PageIndex = pageIndex;
            BlogModel.Offset    = (BlogModel.PageIndex - 1) * BlogModel.Limit;
            Option <GenericPage <BlogEntryModel> > blogsOption = await _queryComponent.BlogsAsync(BlogModel.Offset, BlogModel.Limit);

            if (!blogsOption.Any())
            {
                return(RedirectToPage("/NotFound"));
            }
            BlogModel.Blogs = blogsOption.Single();
            BindPageLimitSelectItems();
            return(Page());
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> OnGetAsync(string id)
        {
            Id = id;

            if (string.IsNullOrWhiteSpace(id))
            {
                return(RedirectToPage("/NotFound"));
            }

            Option <BlogEntryTextModel> blogEntryOption = await _queryComponent.BlogAsync(id);

            if (!blogEntryOption.Any())
            {
                return(RedirectToPage("/NotFound"));
            }

            Blog = blogEntryOption.Single();

            return(Page());
        }
Ejemplo n.º 18
0
        public override async Task <WorkflowResult> Create(string uriKey, string title, int minutesToRead, string textIntro, string textEntry, int keywordId)
        {
            if (await _blogEntryStorage.ExistsBlogUriKey(_blogEntryComponent.BlogEntryId, uriKey))
            {
                return(_uriKeyDuplicateError);
            }

            Option <int> result = await _blogEntryStorage.Create(uriKey, title, minutesToRead, textIntro, textEntry, keywordId);

            if (!result.Any())
            {
                return(_storageError);
            }

            int id = result.Single();

            _blogEntryComponent.UpdateId(id);
            _blogEntryComponent.BlogEntryState = new ExistingBlogEntryState(_blogEntryStorage, _blogEntryComponent);

            return(_successResult);
        }
Ejemplo n.º 19
0
        public async Task <ActionResult> OnPostDeletePriceDetailAsync(
            [FromServices] IProductComponentFactory productComponentFactory,
            int priceDetailId)
        {
            try
            {
                ModelState.Clear();
                if (priceDetailId <= 0)
                {
                    ModelState.TryAddModelError("", "Acción Invalida");
                    return(Page());
                }
                Option <IProductComponent> productResult = await productComponentFactory.CurrentAsync(Id);

                if (!productResult.Any())
                {
                    ModelState.TryAddModelError("", "Error, registro no existe en bd");
                }

                IProductComponent product = productResult.Single();

                WorkflowResult result = await product.DeletePriceDetailAsync(priceDetailId);

                if (!result.Success)
                {
                    for (int i = 0; i < result.Errors.Length; i++)
                    {
                        ModelState.TryAddModelError("", result.Errors[i]);
                    }
                }

                return(Page());
            }
            finally
            {
                AditionalService = new AddAditionalServiceRequest();
                Product          = await _productQueryComponent.ProductAsync(Id);
            }
        }
Ejemplo n.º 20
0
        public async Task <ActionResult> OnPostAditionalServiceAsync([FromServices] IProductComponentFactory productComponentFactory)
        {
            try
            {
                ModelState.Clear();
                if (!TryValidateModel(AditionalService))
                {
                    return(Page());
                }
                Option <IProductComponent> productResult = await productComponentFactory.CurrentAsync(Id);

                if (!productResult.Any())
                {
                    ModelState.TryAddModelError("", "Error, registro no existe en bd");
                }

                IProductComponent product = productResult.Single();

                WorkflowResult result = await product.AddAditionalServiceAsync(AditionalService.Description, AditionalService.UnitPrice);

                if (!result.Success)
                {
                    for (int i = 0; i < result.Errors.Length; i++)
                    {
                        ModelState.TryAddModelError("", result.Errors[i]);
                    }
                }

                return(Page());
            }
            finally
            {
                AditionalService = new AddAditionalServiceRequest();
                Product          = await _productQueryComponent.ProductAsync(Id);
            }
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> OnPostAsync(
            [FromServices] CustomerComponentUowFactory customerComponentUowFactory,
            [FromServices] CustomersQueryComponent customersQueryComponent)
        {
            if (customerComponentUowFactory == null)
            {
                throw new System.ArgumentNullException(nameof(customerComponentUowFactory));
            }

            if (customersQueryComponent == null)
            {
                throw new ArgumentNullException(nameof(customersQueryComponent));
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Option <ICustomerComponentUow> customerComponentOption = await customerComponentUowFactory.ExistingCustomerUowAsync(Id);

            if (!customerComponentOption.Any())
            {
                return(RedirectToPage("/NotFound"));
            }

            using (ICustomerComponentUow customerComponent = customerComponentOption.Single())
            {
                try
                {
                    WorkflowResult result = await customerComponent.SaveInfoAsync(Customer.Name,
                                                                                  Customer.FamilyName1,
                                                                                  Customer.FamilyName2,
                                                                                  Customer.Telephone,
                                                                                  Customer.Cellphone,
                                                                                  Customer.Email,
                                                                                  Customer.BirthDate,
                                                                                  Customer.PhoneCallsEnabled,
                                                                                  Customer.MailEnabled,
                                                                                  UserId());

                    if (!result.Success)
                    {
                        customerComponent.RollbackChanges();

                        for (int i = 0; i < result.Errors.Length; i++)
                        {
                            ModelState.TryAddModelError("", result.Errors[i]);
                        }

                        return(Page());
                    }

                    return(RedirectToPage("./Details", new { id = customerComponent.CustomerId }));
                }
                catch (System.Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    customerComponent.RollbackChanges();
                }
            }

            return(Page());
        }
Ejemplo n.º 22
0
 public Option <string> Next()
 {
     return(Option.Any(SyntaxVisitor.Visit(random_, root_)));
 }