Esempio n. 1
0
            private ProjectionResult safeProjection(Grid grid, Move move)
            {
                //grid projection logic used to determine safe positions

                Grid             projectedGrid = grid.Copy();
                Team             team          = move.Team;
                ProjectionResult result        = new ProjectionResult();

                projectedGrid.SetMove(move);
                result.WinningPositions.AddRange(immediatePositions(projectedGrid, team));

                //negative outcomes of the move
                result.LosingPositions.AddRange(immediatePositions(projectedGrid, team.Opponent()));
                result.LosingPositions.AddRange(crossPositions(projectedGrid, team.Opponent()));
                if (result.LosingPositions.Count == 0)
                {
                    //check setup moves if no immediate / cross moves are present
                    result.LosingPositions.AddRange(setupPositions(projectedGrid, team.Opponent()));
                }

                //if there is more than one winning position, or the losing positions already contains the winning position,
                //further checking to determine the safeness of the position is not needed
                if (result.WinningPositions.Count == 1 && !result.LosingPositions.Contains(result.WinningPositions.Single()))
                {
                    //opponents response to block your immediate move
                    projectedGrid.SetMove(new Move(team.Opponent(), result.WinningPositions.Single()));

                    //determine if there is at least one safe path that can be formed if the opponent blocks your immediate move
                    if (!projectedGrid.IsFilled && (immediatePositions(projectedGrid, team.Opponent()).Count > 1 ||
                                                    safePositions(projectedGrid, team).Count == 0))
                    {
                        //position is not safe
                        result.LosingPositions.Add(result.WinningPositions.Single());
                    }
                }

                return(result);
            }
Esempio n. 2
0
            private ProjectionResult setupProjection(Grid grid, Move move)
            {
                //grid projection logic used to determine setup positions

                Grid               projectedGrid = grid.Copy();
                Team               team          = move.Team;
                ProjectionResult   result        = new ProjectionResult();
                GridSquarePosition immediate;

                projectedGrid.SetMove(move);
                //only one position will be returned (since cross moves precede setup moves)
                immediate = immediatePositions(projectedGrid, team).Single();
                //opponents response to block your immediate move
                projectedGrid.SetMove(new Move(team.Opponent(), immediate));
                //gets the resultant cross moves from the potential setups
                result.WinningPositions = crossPositions(projectedGrid, team);
                //gets any immediate moves that may have been caused by your opponent's blocking move
                //note that it does not matter if the opponent's blocking move was a cross / setup move
                //since you will be at least one move ahead of them in either case
                result.LosingPositions = immediatePositions(projectedGrid, team.Opponent());

                return(result);
            }
Esempio n. 3
0
        public override bool Execute()
        {
            RazorProject project = this.CreateRazorProject();
            RazorParser  parser  = new RazorParser();

            this.PrintProjectData(project);

            List <string> tempFiles = new List <string>();

            string tempDir = this.CreateTempDirectory();

            Stopwatch watch = Stopwatch.StartNew();

            foreach (RazorPage razorPage in parser.Parse(project))
            {
                string tempFile = this.GetTempFile(tempDir, razorPage);

                using (StreamWriter writer = this.GetStreamWriter(tempFile))
                {
                    RazorGenerator   generator = new RazorGenerator(this.GetGeneratorOptions());
                    ProjectionResult result    = generator.Generate(razorPage.Data);

                    writer.Write(result.Content);
                }

                this.PrintPageData(razorPage, tempFile);

                tempFiles.Add(tempFile);
            }

            this.Compile = tempFiles.ToArray();

            this.PrintResultData(tempFiles.Count, watch.ElapsedMilliseconds);

            return(true);
        }
Esempio n. 4
0
        private ISet <IAssociationOption> BuildOptions(IEnumerable <AttributeHolder> queryResponse,
                                                       ApplicationAssociationDefinition association, ProjectionResult projectionResult)
        {
            ISet <IAssociationOption> options = new SortedSet <IAssociationOption>();

            foreach (var attributeHolder1 in queryResponse)
            {
                var attributeHolder = (DataMap)attributeHolder1;
                var value           = attributeHolder.GetAttribute(projectionResult.ValueKey);

                var labelNumber = association.LabelFields.Count;
                var label       = labelNumber == 1
                                    ? (string)attributeHolder.GetAttribute(association.LabelFields[0])
                                    : BuildComplexLabel(attributeHolder, association);

                if (association.ExtraProjectionFields.Count > 0)
                {
                    options.Add(new MultiValueAssociationOption((string)value, label, attributeHolder));
                }
                else
                {
                    options.Add(new AssociationOption((string)value, label));
                }
            }
            return(options);
        }
Esempio n. 5
0
        protected Projector(
            ILogger <TProject> logger,
            IStoreEvents events,
            TProject process,
            int batchSize,
            TimeSpan timeout)
        {
            _logger = logger;
            _events = events;
            _timer  = new Timer(time => {
                _batch.TriggerBatch();
            });
            _queue   = new BufferBlock <Envelope>();
            _trigger = new TransformBlock <Envelope, Envelope>(
                envelope => {
                _timer.Change(timeout, Timeout.InfiniteTimeSpan);
                return(envelope);
            }
                );
            _batch   = new BatchBlock <Envelope>(batchSize);
            _process = new TransformBlock <Envelope[], ProjectionResult[]>(async envelopes => {
                var time = DateTime.Now;
                try {
                    var results = new ProjectionResult[envelopes.Length];

                    for (var i = 0; i < envelopes.Length; i++)
                    {
                        results[i] = new ProjectionResult {
                            Envelope   = envelopes[i],
                            Projection = await process.Project(envelopes[i]),
                        };
                    }

                    return(results);
                } finally {
                    _logger.LogDebug($"Processed {envelopes.Length} events in {(DateTime.Now - time).TotalMilliseconds}ms");
                }
            });
            _commit = new ActionBlock <ProjectionResult[]>(async envelopes => {
                _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);

                var time = DateTime.Now;
                try {
                    await Commit(envelopes);
                } finally {
                    _logger.LogInformation($"Committed {envelopes.Length} projections in {(DateTime.Now - time).TotalMilliseconds}ms");
                }
            });

            _queue.LinkTo(_trigger, new DataflowLinkOptions {
                PropagateCompletion = true
            });
            _trigger.LinkTo(_batch, new DataflowLinkOptions {
                PropagateCompletion = true
            });
            _batch.LinkTo(_process, new DataflowLinkOptions {
                PropagateCompletion = true
            });
            _process.LinkTo(_commit, new DataflowLinkOptions {
                PropagateCompletion = true
            });
        }
 public Result(ProjectionResult result)
 {
     Page      = result.Page;
     Languages = result.Languages.ToDictionary(x => x.Key, x => ConvertLanguages(x.Value));
 }
Esempio n. 7
0
        public async Task <IActionResult> CreateCustomView(CreateCustomViewModel.ViewType chartViewType, string chartTitle, string apiEndpoint,
                                                           SummaryMethodDescriptor summaryMethodDescriptor, ProjectionResult projectionResult,
                                                           string groupedBarChartDatasetPropertyKey, string groupedBarChartCategoryPropertyKey,
                                                           List <string> groupedBarChartValuePropertyKeys, string barChartCategoryPropertyKey, string barChartValuePropertyKey,
                                                           bool timeRelative, int?relativeTimeStartValue, RelativeTimeGranularity?relativeTimeStartGranularity,
                                                           string absoluteTimeStartDate, string absoluteTimeEndDate, List <string> floatCriteriaJsonPropertyNames,
                                                           List <FloatCriterion.Relation> floatCriteriaRelations, List <float> floatCriteriaComparedValues)
        {
            // Attempt to parse date times from datepicker elements if the time is set to an absolute scale
            DateTime?absoluteTimeStartDateTime = null, absoluteTimeEndDateTime = null;

            if (!timeRelative)
            {
                if (DateTime.TryParseExact(absoluteTimeStartDate, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var candidate))
                {
                    absoluteTimeStartDateTime = candidate;
                }

                if (DateTime.TryParseExact(absoluteTimeEndDate, "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out candidate))
                {
                    absoluteTimeEndDateTime = candidate;
                }
            }

            switch (chartViewType)
            {
            case CreateCustomViewModel.ViewType.Bar:
                await InsertCustomBarChartAsync(chartTitle, apiEndpoint, summaryMethodDescriptor, projectionResult, barChartCategoryPropertyKey,
                                                barChartValuePropertyKey, timeRelative, relativeTimeStartValue, relativeTimeStartGranularity,
                                                absoluteTimeStartDateTime, absoluteTimeEndDateTime, floatCriteriaJsonPropertyNames,
                                                floatCriteriaRelations, floatCriteriaComparedValues);

                break;

            case CreateCustomViewModel.ViewType.GroupedBar:
                await InsertCustomGroupedBarChartAsync(chartTitle, apiEndpoint, summaryMethodDescriptor, projectionResult, groupedBarChartDatasetPropertyKey,
                                                       groupedBarChartCategoryPropertyKey, groupedBarChartValuePropertyKeys, timeRelative, relativeTimeStartValue,
                                                       relativeTimeStartGranularity, absoluteTimeStartDateTime, absoluteTimeEndDateTime, floatCriteriaJsonPropertyNames,
                                                       floatCriteriaRelations, floatCriteriaComparedValues);

                break;
            }

            return(RedirectToAction("Index"));
        }