/**
         * Adds the given projection.
         *
         * @param projection the projection to add
         * @return this
         */
        public IExitOperationsCollector AddProjection(IProjection projection)
        {
            if (projection.GetType().IsAssignableFrom(distinct.GetType()))
            {
                this.distinct = (Distinct)projection;
                //TODO: Distinct doesn't work yet
                log.Error("Distinct is not ready yet");
                throw new NotSupportedException();
            }
            if (projection.GetType().IsAssignableFrom(rowCountProjection.GetType()))
            {
                rowCountProjection = (RowCountProjection)projection;
            }
            if (projection.GetType().IsAssignableFrom(aggregateProjection.GetType()))
            {
                if (projection.ToString().ToLower().StartsWith("avg"))
                {
                    this.avgProjection = (AggregateProjection)projection;
                }
                else
                {
                    this.aggregateProjection = (AggregateProjection)projection;
                }
            }
            else
            {
                log.Error("Adding an unsupported Projection: " + projection.GetType().Name);
                throw new NotSupportedException();
            }

            return(this);
        }
        /**
         * Adds the given projection.
         *
         * @param projection the projection to add
         * @return this
         */
        public IExitOperationsCollector AddProjection(IProjection projection)
        {
            if (projection.GetType().IsAssignableFrom(distinct.GetType()))
            {
                this.distinct = (Distinct) projection;
                //TODO: Distinct doesn't work yet
                log.Error("Distinct is not ready yet");
                throw new NotSupportedException();
            }
            if (projection.GetType().IsAssignableFrom(rowCountProjection.GetType()))
            {
                rowCountProjection = (RowCountProjection) projection;
            }
            if (projection.GetType().IsAssignableFrom(aggregateProjection.GetType()))
            {
                if (projection.ToString().ToLower().StartsWith("avg"))
                {
                    this.avgProjection = (AggregateProjection)projection;
                }
                else
                {
                    this.aggregateProjection = (AggregateProjection)projection;
                }
            }
            else
            {
                log.Error("Adding an unsupported Projection: " + projection.GetType().Name);
                throw new NotSupportedException();
            }

            return this;
        }
        /// <summary>
        /// Append a projection response to the command event stream
        /// </summary>
        /// <param name="domainName"></param>
        /// <param name="entityTypeName"></param>
        /// <param name="instanceKey"></param>
        /// <param name="projectionTypeName"></param>
        /// <param name="asOfDate"></param>
        /// <param name="correlationIdentifier"></param>
        /// <param name="asOfSequenceNumber"></param>
        /// <param name="projectionResult"></param>
        /// <returns></returns>
        public async Task PostProjectionResponse(string domainName,
                                                 string entityTypeName,
                                                 string instanceKey,
                                                 string projectionTypeName,
                                                 Nullable <DateTime> asOfDate,
                                                 string correlationIdentifier,
                                                 int asOfSequenceNumber,
                                                 IProjection projectionResult)
        {
            EventStream esCmd = new EventStream(new EventStreamAttribute(MakeDomainCommandName(DomainName),
                                                                         CommandName,
                                                                         UniqueIdentifier,
                                                                         notificationDispatcherName: _commandDispatcherName),
                                                context: _commandContext);


            ProjectionValueReturned evRet = new ProjectionValueReturned()
            {
                ProjectionDomainName     = domainName,
                ProjectionEntityTypeName = entityTypeName,
                ProjectionInstanceKey    = instanceKey,
                AsOfDate              = asOfDate,
                AsOfSequenceNumber    = asOfSequenceNumber,
                CorrelationIdentifier = correlationIdentifier,
                ProjectionTypeName    = projectionTypeName,
                DateLogged            = DateTime.UtcNow,
                Value = projectionResult.ToString()
            };

            await esCmd.AppendEvent(evRet);
        }
 public AggregateExitOperation(IProjection projection)
 {
     string projectionAsString = projection.ToString();
     int start = projectionAsString.IndexOf("(");
     string aggregateName = projectionAsString.Substring(0, start);
     start++;
     int stop = projectionAsString.IndexOf(")");
     _fieldName = projectionAsString.Substring(start, stop - start);
     _aggregate = (SupportedAggregations) Enum.Parse(_aggregate.GetType(), aggregateName.ToUpper());
 }
        public AggregateExitOperation(IProjection projection)
        {
            string projectionAsString = projection.ToString();
            int    start         = projectionAsString.IndexOf("(");
            string aggregateName = projectionAsString.Substring(0, start);

            start++;
            int stop = projectionAsString.IndexOf(")");

            _fieldName = projectionAsString.Substring(start, stop - start);
            _aggregate = (SupportedAggregations)Enum.Parse(_aggregate.GetType(), aggregateName.ToUpper());
        }
Beispiel #6
0
            /// <summary>
            /// Retreive the property name from a supplied PropertyProjection
            /// Note:  throws is the supplied IProjection is not a PropertyProjection
            /// </summary>
            public string AsProperty()
            {
                if (_property != null)
                {
                    return(_property);
                }

                if (!(_projection is PropertyProjection))
                {
                    throw new Exception("Cannot determine property for " + _projection.ToString());
                }

                return(((PropertyProjection)_projection).PropertyName);
            }
Beispiel #7
0
 public override string ToString()
 {
     return("distinct " + projection.ToString());
 }
 public override string ToString()
 {
     return((_projection != null ? _projection.ToString() : "ID") + " == " + value);
 }
Beispiel #9
0
 public override string ToString()
 {
     return((projection != null ? projection.ToString() : propertyName) + (ascending ? " asc" : " desc"));
 }
Beispiel #10
0
 public override string ToString()
 {
     return(projection.ToString());
 }
Beispiel #11
0
        public ICriteria SetProjection(IProjection projection)
        {
            if (projection is ProjectionList)
            {
                throw new NotSupportedException("Projection lists are not (yet) supported.");
            }

            var distinct = projection as Distinct;

            if (distinct != null)
            {
                ApplyActionToShards(c => c.SetProjection(projection));
                this.listExitOperationBuilder.Distinct = true;
                return(this);
            }

            if (!projection.IsAggregate)
            {
                ApplyActionToShards(c => c.SetProjection(projection));
                return(this);
            }

            string aggregationName = projection.ToString();

            if (aggregationName.StartsWith("avg", StringComparison.OrdinalIgnoreCase))
            {
                var projectionList = Projections.ProjectionList()
                                     .Add(projection)
                                     .Add(Projections.RowCount());
                ApplyActionToShards(c => c.SetProjection(projectionList));
                this.listExitOperationBuilder.Aggregation =
                    c => AggregationUtil.Average(c, GetDoubleFieldSelector(0), GetInt32FieldSelector(1));
                return(this);
            }

            if (aggregationName.StartsWith("sum", StringComparison.OrdinalIgnoreCase))
            {
                ApplyActionToShards(c => c.SetProjection(projection));
                this.listExitOperationBuilder.Aggregation = ToSumFunc(projection);
                return(this);
            }

            if (aggregationName.StartsWith("count", StringComparison.OrdinalIgnoreCase))
            {
                ApplyActionToShards(c => c.SetProjection(projection));
                this.listExitOperationBuilder.Aggregation = ToSumFunc(projection);
                return(this);
            }

            if (aggregationName.StartsWith("min", StringComparison.OrdinalIgnoreCase))
            {
                ApplyActionToShards(c => c.SetProjection(projection));
                this.listExitOperationBuilder.Aggregation = AggregationUtil.Min;
                return(this);
            }

            if (aggregationName.StartsWith("max", StringComparison.OrdinalIgnoreCase))
            {
                ApplyActionToShards(c => c.SetProjection(projection));
                this.listExitOperationBuilder.Aggregation = AggregationUtil.Max;
                return(this);
            }

            var message = string.Format(
                CultureInfo.InvariantCulture,
                "Aggregate projection '{0}' is currently not supported across shards.",
                aggregationName);

            Log.Error(message);
            throw new NotSupportedException(message);
        }
 public override string ToString()
 {
     return(projection.ToString() + " as " + alias);
 }
Beispiel #13
0
 public override String ToString()
 {
     return("Cellular Automata evolved " + DiscreteTimer.Instance.GetTime() + " times, based on " + grid.ToString());
 }
 public override string ToString()
 {
     return(aggregate + "(" + (projection != null ? projection.ToString() : propertyName) + ')');
 }
        internal static object GetColumnNameAsSqlStringPart(IProjection projection, ICriteriaQuery criteriaQuery, ICriteria criteria)
        {
            var columnNames = GetColumnNamesAsSqlStringParts(projection, criteriaQuery, criteria);

            if (columnNames.Length != 1)
            {
                throw new QueryException("property or projection does not map to a single column: " + (projection.ToString()));
            }

            return(columnNames[0]);
        }