Exemplo n.º 1
0
        public Core.RootModel DeserializerRoot(RootModel model)
        {
            var items = new List <Core.ItemModel>();

            this.PopulateItems(model.Items, items);

            if (model.SecurityToBeAddedOpt != null)
            {
                var item = this.DeserializeAdditionalItem(model.SecurityToBeAddedOpt);
                if (!items.Where(x => x.Security.Id == item.Security.Id).Any())
                {
                    items.Insert(0, item);
                }
            }


            var targetTotalExpression = this.modelBuilder.CreateTargetTotalExpression(items);
            var cashExpression        = this.modelBuilder.CreateCashExpression(targetTotalExpression);

            var result = new Core.RootModel(
                model.BottomUpPortfolioId,
                this.DeserializeBuPortfolioSecurityTargetChangesetInfo(model.ChangesetModel),
                items,
                targetTotalExpression,
                cashExpression
                );

            return(result);
        }
Exemplo n.º 2
0
        public RootModel SerializeRoot(Core.RootModel model, CalculationTicket ticket)
        {
            var items  = this.SerializeItems(model.Items);
            var result = new RootModel(
                model.PortfolioId,
                this.serializer.SerializeChangeset(model.LatestChangeset),
                items,
                this.serializer.SerializeNullableExpression(model.TargetTotal, ticket),
                this.serializer.SerializeNullableExpression(model.Cash, ticket),
                this.modelChangeDetector.HasChanged(model)
                );

            return(result);
        }
Exemplo n.º 3
0
        public IEnumerable <IValidationIssue> ApplyPstModelIfValid(ManagingPst.RootModel model, String username, CalculationTicket ticket)
        {
            var issues = this.PstManager.Validate(model, ticket);

            if (issues.Any())
            {
                return(issues);
            }
            string userEmail = "";

            using (var connection = this.usersConnectionFactory.CreateConnection())
            {
                var manager = this.dataUsersManagerFactory.CreateDataManager(connection, null);
                userEmail = manager.GetUserEmail(username);
            }

            using (var connection = this.connectionFactory.CreateConnection())
            {
                try
                {
                    CalculationInfo info    = new CalculationInfo();
                    var             manager = this.dataManagerFactory.CreateDataManager(connection, null);
                    var             retVal  = this.PstManager.ApplyIsValid(model, username, userEmail, connection, ticket, this.RepositoryManager.ClaimSecurityRepository(manager), ref info);
                    if (!retVal.Any())
                    {
                        this.Calculate(info.Id, true);
                    }
                    return(retVal);
                }
                catch (EmailNotificationException e)
                {
                    throw new ApplicationException("Notification email cannot be sent. Data haven't been saved yet. You can try again. If the problem persist contact IT department.", e);
                }
                catch (CalculationException e)
                {
                    throw new ApplicationException("You change has been saved but portfolio recalculation went wrong. Contact IT department to restart recalculations.", e);
                }
                catch (OutputTargetingFileException e)
                {
                    throw new ApplicationException("You change has been saved but targeting output file cannot be saved. Contact IT department to restart recalculations.", e);
                }
            }
        }
 protected void Traverse(RootModel root, List <IExpression> result)
 {
     result.Add(root.TargetTotal);
     root.Items.ForEach(item => result.Add(item.Target));
 }
        public Boolean HasChanged(RootModel root)
        {
            var expressions = this.expressionTraverser.Traverse(root);

            return(base.HasChanged(expressions));
        }
Exemplo n.º 6
0
        public IEnumerable <IValidationIssue> Validate(RootModel model, CalculationTicket ticket)
        {
            var issues = this.modelValidator.ValidateRoot(model, ticket);

            return(issues);
        }