/// <summary>
 /// Aborts the import.
 /// </summary>
 /// <param name="importHistory">The import history.</param>
 private void AbortImport(IImportHistory importHistory)
 {
     try
     {
         IRepository <IImportHistory> rep        = EntityFactory.GetRepository <IImportHistory>();
         IQueryable         qry                  = (IQueryable)rep;
         IExpressionFactory ep                   = qry.GetExpressionFactory();
         Sage.Platform.Repository.ICriteria crit = qry.CreateCriteria();
         crit.Add(ep.Eq("Id", importHistory.Id));
         IProjections projections = qry.GetProjectionsFactory();
         crit.SetProjection(projections.Property("ProcessState"));
         object state = crit.UniqueResult();
         if (state != null)
         {
             ImportProcessState processState = (ImportProcessState)Enum.Parse(typeof(ImportProcessState), state.ToString());
             if (!processState.Equals(ImportProcessState.Completed) || !processState.Equals(ImportProcessState.Abort))
             {
                 SetProcessState(importHistory.Id.ToString(), Enum.GetName(typeof(ImportProcessState), ImportProcessState.Abort), "Aborted");
             }
         }
     }
     catch (Exception)
     {
         //throw new ApplicationException("Error getting process state");
     }
 }
    /// <summary>
    /// Adds the distinct CampaignTarget group names to list.
    /// </summary>
    private void AddDistinctGroupItemsToList()
    {
        lbxGroups.Items.Clear();
        lbxGroups.Items.Add(String.Empty);

        IRepository <ICampaignTarget> rep = EntityFactory.GetRepository <ICampaignTarget>();
        IQueryable         query          = (IQueryable)rep;
        IExpressionFactory expressions    = query.GetExpressionFactory();
        IProjections       projections    = query.GetProjectionsFactory();
        ICriteria          criteria       = query.CreateCriteria()
                                            .SetProjection(projections.Distinct(projections.Property("GroupName")))
                                            .Add(expressions.And(expressions.Eq("Campaign.Id", EntityContext.EntityID), expressions.IsNotNull("GroupName")));

        IList <object> groups = criteria.List <object>();

        if (groups != null)
        {
            foreach (string group in groups)
            {
                if (!String.IsNullOrEmpty(group))
                {
                    ListItem item = new ListItem {
                        Text = @group
                    };
                    lbxGroups.Items.Add(item);
                }
            }
        }
    }
    /// <summary>
    /// Adds the distinct CampaignStage stage names to list.
    /// </summary>
    private void AddDistinctStageItemsToList()
    {
        lbxStages.Items.Clear();
        lbxStages.Items.Add("");

        IRepository <ICampaignStage> rep = EntityFactory.GetRepository <ICampaignStage>();
        IQueryable         query         = (IQueryable)rep;
        IExpressionFactory expressions   = query.GetExpressionFactory();
        IProjections       projections   = query.GetProjectionsFactory();
        ICriteria          criteria      = query.CreateCriteria()
                                           .SetProjection(projections.Distinct(projections.Property("Description")))
                                           .Add(expressions.And(expressions.Eq("Campaign.Id", EntityContext.EntityID), expressions.IsNotNull("Description")));

        IList <object> stages = criteria.List <object>();

        if (stages != null)
        {
            foreach (string stage in stages)
            {
                if (!String.IsNullOrEmpty(stage))
                {
                    ListItem item = new ListItem {
                        Text = stage
                    };
                    lbxStages.Items.Add(item);
                }
            }
        }
    }
 public PapierSettingPersoonProjector(IActorRef projectionCoordinator, IProjections <RM.PapierSettingPersoon> projections,
                                      Func <QueryContext> queryContextFactory)
     : base(projectionCoordinator)
 {
     _projections         = projections;
     _queryContextFactory = queryContextFactory;
 }
Example #5
0
        private static void MaterializeNavigationProperties <T>(
            IProjections projections,
            dynamic mainEntity,
            dynamic projectedEntity,
            Type projectedEntityAnonymousType) where T : class, IEntity
        {
            // TODO: Cache this!
            Type genericListType      = typeof(List <>);
            var  genericDynamicMapper = typeof(Mapper).GetMethods(BindingFlags.Static | BindingFlags.Public).Where(m => m.Name == "DynamicMap").ToList()[2];

            foreach (var projection in projections.NavigationPropertiesProjections)
            {
                var navigationPropertyOnMainEntity             = typeof(T).GetProperty(projection.ReferingPropertyName);
                var navigationPropertyOnProjectedAnonymousType = projectedEntityAnonymousType.GetProperty(projection.Name);

                var propertValues = (IEnumerable)navigationPropertyOnProjectedAnonymousType.GetValue(projectedEntity);

                Type listOfTypeProjectionType = genericListType.MakeGenericType(new[] { projection.Type });

                var   mapperOfProjectionType = genericDynamicMapper.MakeGenericMethod(projection.Type);
                IList navigationPropertyList = (IList)Activator.CreateInstance(listOfTypeProjectionType);
                foreach (var value in propertValues)
                {
                    var valueOfNavigationPropertyProjection = mapperOfProjectionType.Invoke(null, new object[] { value });

                    navigationPropertyList.Add(valueOfNavigationPropertyProjection);
                }

                navigationPropertyOnMainEntity.SetValue(mainEntity, navigationPropertyList);
            }
        }
    /// <summary>
    /// Gets the contact targets.
    /// </summary>
    /// <returns></returns>
    private IList GetContactTargets()
    {
        IList              contactList;
        IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
        IExpressionFactory expressions = query.GetExpressionFactory();
        IProjections       projections = query.GetProjectionsFactory();
        ICriteria          criteria    = query.CreateCriteria("a1")
                                         .CreateCriteria("Account", "account")
                                         .CreateCriteria("a1.Addresses", "address")
                                         .SetProjection(projections.ProjectionList()
                                                        .Add(projections.Distinct(projections.Property("Id")))
                                                        .Add(projections.Property("FirstName"))
                                                        .Add(projections.Property("LastName"))
                                                        .Add(projections.Property("AccountName"))
                                                        .Add(projections.Property("Email"))
                                                        .Add(projections.Property("address.City"))
                                                        .Add(projections.Property("address.State"))
                                                        .Add(projections.Property("address.PostalCode"))
                                                        .Add(projections.Property("WorkPhone"))

                                                        );

        AddExpressionsCriteria(criteria, expressions);
        contactList = criteria.List();
        // NOTE: The generic exception handler was removed since the exception was rethrown; this exception would be logged twice otherwise.
        // We may want to throw a UserObservableApplicationException in the future.
        return(contactList);
    }
Example #7
0
    /// <summary>
    /// Gets the contact targets.
    /// </summary>
    /// <returns></returns>
    private IList GetContactTargets()
    {
        IList contactList;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("a1")
                                             .CreateCriteria("Account", "account")
                                             .CreateCriteria("a1.Addresses", "address")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Distinct(projections.Property("Id")))
                                                            .Add(projections.Property("FirstName"))
                                                            .Add(projections.Property("LastName"))
                                                            .Add(projections.Property("Account"))
                                                            .Add(projections.Property("Email"))
                                                            .Add(projections.Property("address.City"))
                                                            .Add(projections.Property("address.State"))
                                                            .Add(projections.Property("address.PostalCode"))
                                                            .Add(projections.Property("WorkPhone"))
                                                            );
            AddExpressionsCriteria(criteria, expressions);
            contactList = criteria.List();
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            throw;
        }
        return(contactList);
    }
 public PropertyProjector(
     Expression <Func <T, dynamic> > e,
     IProjections a,
     Type t)
 {
     Expression     = e;
     AllProjections = a;
     ProjectedEntityAnonymousType = t;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectionsService"/> class.
 /// </summary>
 /// <param name="projections">The <see cref="IProjections"/> to use to perform operations on Projections.</param>
 /// <param name="exceptionToFailureConverter">The <see cref="IExceptionToFailureConverter"/> to use to convert exceptions to failures.</param>
 /// <param name="definitionConverter">The <see cref="IConvertProjectionDefinitions"/> to use to convert projection definition fields.</param>
 /// <param name="streamProcessorStatusConverter">The <see cref="IConvertStreamProcessorStatuses"/> to use to convert stream processor states.</param>
 /// <param name="logger">The logger to use for logging.</param>
 public ProjectionsService(
     IProjections projections,
     IExceptionToFailureConverter exceptionToFailureConverter,
     IConvertProjectionDefinitions definitionConverter,
     IConvertStreamProcessorStatuses streamProcessorStatusConverter,
     ILogger logger)
 {
     _projections = projections;
     _exceptionToFailureConverter    = exceptionToFailureConverter;
     _definitionConverter            = definitionConverter;
     _streamProcessorStatusConverter = streamProcessorStatusConverter;
     _logger = logger;
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectionsService"/> class.
 /// </summary>
 /// <param name="reverseCallServices">The initiator to use to start reverse call protocols.</param>
 /// <param name="protocol">The projections protocol to use to parse and create messages.</param>
 /// <param name="executionContextCreator">The execution context creator to use to validate execution contexts on requests.</param>
 /// <param name="projections">The <see cref="IProjections"/> to use to register projections.</param>
 /// <param name="hostApplicationLifetime">The <see cref="IHostApplicationLifetime"/> to use to stop ongoing reverse calls when the application is shutting down.</param>
 /// <param name="logger">The logger to use for logging.</param>
 public ProjectionsService(
     IInitiateReverseCallServices reverseCallServices,
     IProjectionsProtocol protocol,
     ICreateExecutionContexts executionContextCreator,
     IProjections projections,
     IHostApplicationLifetime hostApplicationLifetime,
     ILogger logger)
 {
     _reverseCallServices     = reverseCallServices;
     _protocol                = protocol;
     _executionContextCreator = executionContextCreator;
     _projections             = projections;
     _hostApplicationLifetime = hostApplicationLifetime;
     _logger = logger;
 }
Example #11
0
    /// <summary>
    /// Gets the contact targets via a join through Account.
    /// </summary>
    /// <returns></returns>
    private IList GetAccountTargets()
    {
        IList contactList;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("a1")
                                             .CreateCriteria("Account", "account")
                                             .CreateCriteria("Addresses", "address")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Distinct(projections.Property("Id")))
                                                            .Add(projections.Property("FirstName"))
                                                            .Add(projections.Property("LastName"))
                                                            .Add(projections.Property("Account"))
                                                            .Add(projections.Property("Email"))
                                                            .Add(projections.Property("address.City"))
                                                            .Add(projections.Property("address.State"))
                                                            .Add(projections.Property("address.PostalCode"))
                                                            .Add(projections.Property("WorkPhone"))
                                                            );
            AddExpressionsCriteria(criteria, expressions);
            contactList = criteria.List();
        }
        catch (NHibernate.QueryException nex)
        {
            log.Error(nex.Message);
            string message = GetLocalResourceObject("QueryError").ToString();
            if (nex.Message.Contains("could not resolve property"))
            {
                message += "  " + GetLocalResourceObject("QueryErrorInvalidParameter");
            }

            throw new ValidationException(message);
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            throw;
        }
        return(contactList);
    }
Example #12
0
    /// <inheritdoc />
    protected override void Setup(IServiceProvider services)
    {
        _eventStore  = services.GetRequiredService <IEventStore>();
        _projections = services.GetRequiredService <IProjections>();
        _eventTypes  = Enumerable.Range(0, EventTypes).Select(_ => new ArtifactId(Guid.NewGuid())).ToArray();
        var uncommittedEvents = new List <UncommittedEvent>();

        foreach (var eventType in _eventTypes)
        {
            foreach (var _ in Enumerable.Range(0, Events))
            {
                uncommittedEvents.Add(new UncommittedEvent("some event source", new Artifact(eventType, ArtifactGeneration.First), false, "{\"hello\": 42}"));
            }
        }
        foreach (var tenant in ConfiguredTenants)
        {
            _eventStore.Commit(new UncommittedEvents(uncommittedEvents), Runtime.CreateExecutionContextFor(tenant)).GetAwaiter().GetResult();
        }
    }
    /// <summary>
    /// Gets the contact targets via a join through Account.
    /// </summary>
    /// <returns></returns>
    private IList GetAccountTargets()
    {
        IList contactList;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("a1")
                                             .CreateCriteria("Account", "account")
                                             .CreateCriteria("Addresses", "address")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Distinct(projections.Property("Id")))
                                                            .Add(projections.Property("FirstName"))
                                                            .Add(projections.Property("LastName"))
                                                            .Add(projections.Property("AccountName"))
                                                            .Add(projections.Property("Email"))
                                                            .Add(projections.Property("address.City"))
                                                            .Add(projections.Property("address.State"))
                                                            .Add(projections.Property("address.PostalCode"))
                                                            .Add(projections.Property("WorkPhone"))
                                                            );
            AddExpressionsCriteria(criteria, expressions);
            contactList = criteria.List();
        }
        catch (NHibernate.QueryException nex)
        {
            log.Error("The call to ManageTargets.GetAccountTargets() failed", nex);
            string message = GetLocalResourceObject("QueryError").ToString();
            if (nex.Message.Contains("could not resolve property"))
            {
                message += "  " + GetLocalResourceObject("QueryErrorInvalidParameter");
            }

            throw new ValidationException(message);
        }
        // NOTE: The generic exception handler was removed since the exception was rethrown; this exception would be logged twice otherwise.
        // We may want to throw a UserObservableApplicationException in the future.
        return(contactList);
    }
Example #14
0
    /// <summary>
    /// Gets the Lead targets.
    /// </summary>
    /// <returns></returns>
    private IList GetLeadTargets()
    {
        IList leadList = null;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <ILead>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("lead")
                                             .SetCacheable(true)
                                             .CreateCriteria("CampaignTargets", "target")
                                             .Add(expressions.Eq("Campaign.Id", EntityContext.EntityID))
                                             .CreateCriteria("TargetResponses", "response")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Property("response.LeadSource"))
                                                            .Add(projections.Property("LeadNameLastFirst"))
                                                            .Add(projections.Property("target.TargetType"))
                                                            .Add(projections.Property("response.ResponseDate"))
                                                            .Add(projections.Property("response.ResponseMethod"))
                                                            .Add(projections.Property("response.Stage"))
                                                            .Add(projections.Property("response.Comments"))
                                                            .Add(projections.Property("target.Id"))
                                                            .Add(projections.Property("response.Id"))
                                                            .Add(projections.Property("lead.LastName"))
                                                            );
            criteria = GetExpressions(criteria, expressions);
            if (chkName.Checked)
            {
                criteria.Add(expressions.InsensitiveLike("lead.LastName", txtName.Text, LikeMatchMode.BeginsWith));
            }
            leadList = criteria.List();
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            throw;
        }
        return(leadList);
    }
Example #15
0
 public ProjectionDefinitions(IProjections projections, IConvertProjectionDefinition definitionConverter)
 {
     _projections         = projections;
     _definitionConverter = definitionConverter;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HomeController"/> class.
 /// </summary>
 /// <param name="projections">The projections.</param>
 /// <param name="commandProcessor">The command processor.</param>
 public HomeController(IProjections projections, ICommandProcessor commandProcessor)
 {
     _projections      = projections;
     _commandProcessor = commandProcessor;
 }
Example #17
0
 public UpdatePropertyBuilder()
 {
     AllProjections = new Projections();
 }
Example #18
0
 /// <summary>
 /// Initializes an instance of the <see cref="ProjectionStates" /> class.
 /// </summary>
 /// <param name="projections">The projections repository.</param>
 public ProjectionStates(IProjections projections)
 {
     _projections = projections;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HomeController"/> class.
 /// </summary>
 /// <param name="projections">The projections.</param>
 /// <param name="commandProcessor">The command processor.</param>
 public HomeController(IProjections projections, ICommandProcessor commandProcessor)
 {
     _projections = projections;
     _commandProcessor = commandProcessor;
 }