////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public virtual void Build(ProjectionState pProjectionState,
                                  IProjectionVisualSettings pSettings)
        {
            vProjectionState = pProjectionState;
            vSettings        = (ProjectionVisualSettingsStandard)pSettings;

            ////

            vSpotObj = new GameObject("Spot");
            vSpotObj.transform.SetParent(gameObject.transform, false);
            vSpotObj.transform.localScale = Vector3.zero;

            MeshFilter spotFilt = vSpotObj.AddComponent <MeshFilter>();

            MeshUtil.BuildCircleMesh(spotFilt.mesh, 0.5f, 32);
            vSpotMesh = spotFilt.mesh;

            MeshRenderer spotRend = vSpotObj.AddComponent <MeshRenderer>();

            spotRend.sharedMaterial =
                Materials.GetLayer(Materials.Layer.AboveText, Materials.DepthHintMax);

            ////

            vLineObj      = GameObject.CreatePrimitive(PrimitiveType.Cube);
            vLineObj.name = "Line";
            vLineObj.transform.SetParent(gameObject.transform, false);
            vLineObj.transform.localScale = Vector3.zero;
            vLineMesh = vLineObj.GetComponent <MeshFilter>().mesh;

            MeshRenderer lineRend = vLineObj.GetComponent <MeshRenderer>();

            lineRend.sharedMaterial =
                Materials.GetLayer(Materials.Layer.AboveText, Materials.DepthHintMax);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public void Build(ProjectionState pProjectionState, IProjectionVisualSettings pSettings)
        {
            vProjectionState = pProjectionState;
            vSettings        = (ProjectionVisualSettingsStandard)pSettings;

            ////

            vSpotObj = new GameObject("Spot");
            vSpotObj.transform.SetParent(gameObject.transform, false);
            vSpotObj.transform.localScale = Vector3.zero;

            MeshFilter spotMeshFilt = vSpotObj.AddComponent <MeshFilter>();

            MeshUtil.BuildCircleMesh(spotMeshFilt.mesh, 0.5f, 32);

            MeshRenderer spotMeshRend = vSpotObj.AddComponent <MeshRenderer>();

            spotMeshRend.sharedMaterial              = new Material(Shader.Find("Unlit/AlphaSelfIllum"));
            spotMeshRend.sharedMaterial.renderQueue += 100;

            ////

            vLineObj      = GameObject.CreatePrimitive(PrimitiveType.Cube);
            vLineObj.name = "Line";
            vLineObj.transform.SetParent(gameObject.transform, false);
            vLineObj.transform.localScale                 = Vector3.zero;
            vLineObj.renderer.sharedMaterial              = new Material(Shader.Find("Unlit/AlphaSelfIllum"));
            vLineObj.renderer.sharedMaterial.renderQueue += 200;
        }
예제 #3
0
 private void Safeguard_Check()
 {
     if (GridProgram.Echo == null)
     {
         throw new ArgumentNullException("Passed Echo reference was null.");
     }
     if (GridProgram.GridTerminalSystem == null)
     {
         throw new ArgumentNullException("Passed GTS reference was null.");
     }
     GridProgram.Echo("Running SafeGuard check..");
     if (Projector == null)
     {
         throw new NullReferenceException("Projector reference was null.");
     }
     if (!Projector.IsProjecting)
     {
         ProjectionState = ProjectionState.Idle;
     }
     else if (Projector.IsProjecting && Projector.RemainingBlocks == 0)
     {
         ProjectionState = ProjectionState.Finished;
     }
     else if (Projector.IsProjecting && Projector.RemainingBlocks != 0)
     {
         ProjectionState = ProjectionState.Projecting;
     }
     ApplyConfig();
     GridProgram.Echo("OK.");
 }
예제 #4
0
        private async Task ExecuteAsync(CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                _logger.LogInformation($"{nameof(StoreProjector<TProjection>)}.{nameof(ExecuteAsync)} was cancelled before execution");
                cancellationToken.ThrowIfCancellationRequested();
            }

            using (var context = _projectionDbContextFactory.Create())
            {
                var state = await context.ProjectionStates.FindAsync(_name);

                if (state == null)
                {
                    state = new ProjectionState
                    {
                        Name        = _name,
                        CreatedDate = DateTimeOffset.UtcNow,
                        Position    = 0
                    };

                    context.ProjectionStates.Add(state);

                    await context.SaveChangesAsync(cancellationToken);
                }

                while (!cancellationToken.IsCancellationRequested)
                {
                    try
                    {
                        await context.Entry(state).ReloadAsync();

                        var page = await _eventStore.GetEventsAsync(state.Position);

                        foreach (var @event in page.Events)
                        {
                            await _projectionManager.HandleAsync(@event.Payload);
                        }

                        if (state.Position == page.Offset)
                        {
                            await Task.Delay(_options.Value.Interval);
                        }
                        else
                        {
                            state.Position         = page.Offset;
                            state.LastModifiedDate = DateTimeOffset.UtcNow;

                            await context.SaveChangesAsync();
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogCritical(ex, $"Process '{typeof(TProjection).Name}' failed at postion '{state.Position}' due to an unexpected error. See exception details for more information.");
                        break;
                    }
                }
            }
        }
예제 #5
0
        public Result GetProjState(
            string relativePath,
            out ProjectionState state)
        {
            unsafe
            {
                byte   stateAttr;
                Attr[] attrs = new[]
                {
                    new Attr
                    {
                        Name  = (byte *)this.stateAttrNamePtr,
                        Value = &stateAttr,
                        Size  = 1
                    }
                };

                int res = _GetProjAttrs(
                    this.handle,
                    relativePath,
                    attrs,
                    (uint)attrs.Length);
                Result result = res.ToResult();

                if (result == Result.Success)
                {
                    if (attrs[0].Size == -1)
                    {
                        state = ProjectionState.Full;
                    }
                    else if (stateAttr == 'n')
                    {
                        state = ProjectionState.Hydrated;
                    }
                    else if (stateAttr == 'y')
                    {
                        state = ProjectionState.Empty;
                    }
                    else
                    {
                        state  = ProjectionState.Invalid;
                        result = Result.Invalid;
                    }
                }
                else if (res == Errno.Constants.EPERM)
                {
                    // EPERM returned when inode is neither file nor directory
                    state  = ProjectionState.Unknown;
                    result = Result.Invalid;
                }
                else
                {
                    state = ProjectionState.Invalid;
                }

                return(result);
            }
        }
예제 #6
0
 static bool InitialStatesAreEqual(ProjectionState newInitialState, ProjectionState oldInitialState, ref ProjectionDefinitionComparisonResult result)
 {
     if (newInitialState != oldInitialState)
     {
         result = ProjectionDefinitionComparisonResult.Unequal("The initial projection state is not the same as the persisted definition");
         return(false);
     }
     return(true);
 }
예제 #7
0
 /// <summary>
 /// Initializes an instance of the <see cref="ProjectManyEvents" /> class.
 /// </summary>
 /// <param name="embedding">The <see cref="EmbeddingId"/> that identifies the embedding.</param>
 /// <param name="projection">The <see cref="IProjection"/> that is used to update the state.</param>
 /// <param name="initialState">The <see cref="ProjectionState"/> that is used to initialize newly created states.</param>
 /// <param name="logger">The <see cref="ILogger" />.</param>
 public ProjectManyEvents(
     EmbeddingId identifier,
     IEmbedding embedding,
     ProjectionState initialState,
     ILogger logger)
 {
     _identifier   = identifier;
     _embedding    = embedding;
     _initialState = initialState;
     _logger       = logger;
 }
예제 #8
0
 /// <summary>
 /// Hide all projection windows
 /// </summary>
 public void HideProjectionWindow()
 {
     foreach (var pw in ProjectionWindows)
     {
         if (CurrentState != ProjectionState.Disabled)
         {
             pw.Hide();
         }
     }
     CurrentState = ProjectionState.Disabled;
 }
예제 #9
0
 /// <inheritdoc/>
 public Try <bool> TryCheckEquality(ProjectionState left, ProjectionState right)
 {
     try
     {
         var leftObject  = JObject.Parse(left.Value);
         var rightObject = JObject.Parse(right.Value);
         return(JToken.DeepEquals(leftObject, rightObject));
     }
     catch (Exception ex)
     {
         return(ex);
     }
 }
예제 #10
0
        private void GameView_DisplayModeChange(DisplayMode mode)
        {
            RenderSupport.DefaultProjectionState = new ProjectionState(ProjectionDescription.Orthogonal(0, 0, mode.Width, mode.Height));

            _rasterContext          = new RasterizerContext(RenderSupport.RasterizerStatesManager.ScissorDisableViewPortEnable);
            _rasterContext.ViewPort = ViewPort.CreateViewPort(0, 0, mode.Width, mode.Height, CoordinateSystem, AspectMode.LetterBox);

            ProjectionState projectionState = new ProjectionState(ProjectionDescription.Orthogonal(CoordinateSystem));

            _touchTranslator.ViewPort = _rasterContext.ViewPort;
            _rootNode.RenderStates.ProjectionState   = projectionState;
            _rootNode.RenderStates.RasterizerContext = _rasterContext;
        }
예제 #11
0
    /// <inheritdoc/>
    public Try <bool> TryCheckForProjectionStateLoop(ProjectionState currentState, IEnumerable <ProjectionState> previousStates)
    {
        var equalityResults = previousStates.AsParallel()
                              .Select(previousState => _comparer.TryCheckEquality(previousState, currentState))
                              // The query execution is deferred so need to call for ToList here
                              // https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/introduction-to-plinq#the-forall-operator
                              .ToList();
        var failure = equalityResults.FirstOrDefault(_ => !_.Success);

        if (failure is not null)
        {
            return(failure.Exception);
        }
        return(equalityResults.Any(_ => _.Result));
    }
예제 #12
0
    /// <inheritdoc/>
    public IEmbeddingProcessor Create(EmbeddingId embeddingId, IEmbedding embedding, ProjectionState initialState, ExecutionContext executionContext)
    {
        var projectManyEvents = CreateProjectManyEvents(embeddingId, embedding, initialState);

        return(new EmbeddingProcessor(
                   embeddingId,
                   _tenant,
                   executionContext,
                   CreateEmbeddingStateUpdater(embeddingId, projectManyEvents),
                   _streamEventWatcher,
                   _eventStore,
                   _embeddingStore,
                   CreateStateTransitionEventsCalculator(embeddingId, embedding, projectManyEvents),
                   _loggerFactory.CreateLogger <EmbeddingProcessor>()));
    }
예제 #13
0
 /// <summary>
 /// Show the projection window and disable blackout
 /// </summary>
 public void ShowProjectionWindow()
 {
     foreach (var pw in ProjectionWindows)
     {
         if (CurrentState == ProjectionState.Disabled)
         {
             pw.SetBlackout(false, false);
             pw.Show();
         }
         else if (CurrentState == ProjectionState.Blackout)
         {
             pw.SetBlackout(false, true);
         }
     }
     CurrentState = ProjectionState.Active;
 }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        internal void Build(ProjectionState pProjectionState, IProjectionVisualSettings pSettings)
        {
            vProjectionState = pProjectionState;
            vSettings        = pSettings;

            ////

            vRendererHold = new GameObject("ProjectionRendererHold");
            vRendererHold.transform.SetParent(gameObject.transform, false);

            vRendererObj = new GameObject("ProjectionRenderer");
            vRendererObj.transform.SetParent(vRendererHold.transform, false);

            vRenderer = (IUiProjectionRenderer)vRendererObj.AddComponent(vSettings.Renderer);
            vRenderer.Build(vProjectionState, vSettings);
        }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectionReplaceResult"/> class.
 /// </summary>
 /// <param name="state">The new <see cref="ProjectionState"/> to persist.</param>
 public ProjectionReplaceResult(ProjectionState state)
 {
     State = state;
 }
예제 #16
0
 /// <summary>
 /// Initializes an instance of the <see cref="FailedToReplaceEmbedding" /> class.
 /// </summary>
 /// <param name="embedding">The embedding identifier.</param>
 /// <param name="key">The projection key</param>
 /// <param name="version">The aggregate root version.</param>
 /// <param name="state">The new projection state.</param>
 public FailedToReplaceEmbedding(EmbeddingId embedding, ProjectionKey key, AggregateRootVersion version, ProjectionState state)
     : base($"Failed to replace embedding with id {embedding.Value}, key {key.Value} and aggregate root version {version.Value} with state {state.Value}")
 {
 }
예제 #17
0
    /// <inheritdoc />
    public async Task <bool> TryReplace(ProjectionDefinition projection, ProjectionKey key, ProjectionState state, CancellationToken token)
    {
        ThrowIfShouldNotPersistFor(projection);

        try
        {
            var document = _converter.Convert(state, projection.Copies.MongoDB.Conversions);
            AddKeyTo(document, key);

            var collection = GetCollectionFor(projection);
            var filter     = GetFilterFor(key);

            var replaceResult = await collection.ReplaceOneAsync(filter, document, new ReplaceOptions { IsUpsert = true }, token).ConfigureAwait(false);

            return(replaceResult.IsAcknowledged);
        }
        catch (MongoWaitQueueFullException)
        {
            return(false);
        }
    }
예제 #18
0
    /// <inheritdoc/>
    public async Task <bool> TryReplace(ProjectionId projection, ScopeId scope, ProjectionKey key, ProjectionState state, CancellationToken token)
    {
        try
        {
            var collection = await _projections.GetStates(scope, projection, token).ConfigureAwait(false);

            var filter           = CreateKeyFilter(key);
            var updateDefinition = Builders <Projection>
                                   .Update
                                   .Set(_ => _.Content, BsonDocument.Parse(state.Value))
                                   .Set(_ => _.ContentRaw, state.Value);

            var updateResult = await collection.UpdateOneAsync(
                filter,
                updateDefinition,
                new UpdateOptions { IsUpsert = true },
                token).ConfigureAwait(false);

            return(updateResult.IsAcknowledged);
        }
        catch (MongoWaitQueueFullException)
        {
            return(false);
        }
    }
예제 #19
0
    public async Task <bool> TryReplace(ProjectionDefinition projection, ProjectionKey key, ProjectionState state, CancellationToken token)
    {
        Log.ReplacingProjectionState(_logger, projection.Projection, projection.Scope, key);
        _metrics.IncrementTotalReplaceAttempts();
        foreach (var store in ApplicableCopyStores(projection))
        {
            if (!await store.TryReplace(projection, key, state, token).ConfigureAwait(false))
            {
                Log.FailedToReplaceProjectionStateInCopyStore(_logger, projection.Projection, projection.Scope, key);
                _metrics.IncrementTotalFailedCopyStoreReplacements();
                return(false);
            }
            _metrics.IncrementTotalCopyStoreReplacements();
        }

        return(await _projectionStore.TryReplace(projection.Projection, projection.Scope, key, state, token));
    }
 /// <inheritdoc/>
 public Task <Try <UncommittedAggregateEvents> > TryConverge(EmbeddingCurrentState current, ProjectionState desired, ExecutionContext executionContext, CancellationToken cancellationToken)
 => DoWork(
     current,
     newCurrent => _stateComparer.TryCheckEquality(newCurrent.State, desired),
     (newCurrent, token) => _embedding.TryCompare(newCurrent, desired, executionContext, token),
     executionContext,
     cancellationToken);
예제 #21
0
 internal static void ErrorReplacingEmbedding(this ILogger logger, EmbeddingId embedding, ProjectionKey key, AggregateRootVersion version, ProjectionState state, Exception exception)
 => _errorReplacingEmbedding(logger, embedding, key, version, state, exception);
예제 #22
0
 internal static void ReplacingEmbedding(this ILogger logger, EmbeddingId embedding, ProjectionKey key, AggregateRootVersion version, ProjectionState state)
 => _replacingEmbedding(logger, embedding, key, version, state, null);