public void SetUp()
        {
            disposables = new CompositeDisposable
            {
                VirtualClock.Start()
            };

            clockName = Any.CamelCaseName();
            targetId = Any.Word();
            target = new CommandTarget(targetId);
            store = new InMemoryStore<CommandTarget>(
                _ => _.Id,
                id => new CommandTarget(id))
            {
                target
            };

            CommandSchedulerDbContext.NameOrConnectionString =
                @"Data Source=(localdb)\MSSQLLocalDB; Integrated Security=True; MultipleActiveResultSets=False; Initial Catalog=ItsCqrsTestsCommandScheduler";

            configuration = new Configuration()
                .UseInMemoryCommandScheduling()
                .UseDependency<IStore<CommandTarget>>(_ => store)
                .UseDependency<GetClockName>(c => _ => clockName)
                .TraceScheduledCommands();

            scheduler = configuration.CommandScheduler<CommandTarget>();

            Command<CommandTarget>.AuthorizeDefault = (commandTarget, command) => true;

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
        public void SetUp()
        {
            disposables = new CompositeDisposable
            {
                VirtualClock.Start()
            };

            clockName = Any.CamelCaseName();
            targetId = Any.Word();
            target = new CommandTarget(targetId);
            store = new InMemoryStore<CommandTarget>(
                _ => _.Id,
                id => new CommandTarget(id))
            {
                target
            };

            configuration = new Configuration()
                .UseInMemoryCommandScheduling()
                .UseDependency<IStore<CommandTarget>>(_ => store)
                .UseDependency<GetClockName>(c => _ => clockName)
                .TraceScheduledCommands();

            scheduler = configuration.CommandScheduler<CommandTarget>();

            Command<CommandTarget>.AuthorizeDefault = (commandTarget, command) => true;

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);
        }
Пример #3
0
 public static async Task Schedule <T>(
     this ICommandScheduler <T> scheduler,
     T command,
     DateTimeOffset?dueTime  = null,
     string idempotencyToken = null) =>
 await scheduler.Schedule(
     new CommandDelivery <T>(
         command,
         dueTime,
         idempotencyToken : idempotencyToken));
Пример #4
0
        public EditorConnectionServer(int serverPort, int broadcastPort)
        {
            var service = new NetworkUtilities();

            _scheduler            = new CommandScheduler();
            _server               = new TcpConnectionServer(service.GetLocalIPAddress(), serverPort);
            _server.DataReceived += PublishReceivedData;
            _broadcastPort        = broadcastPort;
            SetupBroadcastCommand();
        }
Пример #5
0
        public static ICommandScheduler <T> Trace <T>(
            this ICommandScheduler <T> scheduler) =>
        scheduler.UseMiddleware(async(delivery, next) =>
        {
            using (var operation = Log.Schedule(delivery))
            {
                await next(delivery);

                Log.Completion(operation, delivery);
            }
        });
        internal static ICommandScheduler <TAggregate> Wrap <TAggregate>(
            this ICommandScheduler <TAggregate> scheduler,
            ScheduledCommandInterceptor <TAggregate> schedule = null,
            ScheduledCommandInterceptor <TAggregate> deliver  = null)
        {
            schedule = schedule ?? (async(c, next) => await next(c));
            deliver  = deliver ?? (async(c, next) => await next(c));

            return(Create <TAggregate>(
                       async command => await schedule(command, async c => await scheduler.Schedule(c)),
                       async command => await deliver(command, async c => await scheduler.Deliver(c))));
        }
Пример #7
0
        public static IDisposable ScheduleCommandsWith <TAggregate>(
            this IEventBus bus,
            ICommandScheduler <TAggregate> scheduler)
            where TAggregate : class, IEventSourced
        {
            var consequenter = Consequenter.Create <IScheduledCommand <TAggregate> >(
                e =>
            {
                scheduler.Schedule(e).Wait();
            });

            return(bus.Subscribe(consequenter));
        }
        protected override void Configure(Configuration configuration)
        {
            disposables = new CompositeDisposable();
            clockName = Any.CamelCaseName();

            configuration.UseSqlStorageForScheduledCommands()
                         .UseInMemoryCommandTargetStore()
                         .TraceScheduledCommands()
                         .UseDependency<GetClockName>(_ => command => clockName);

            scheduler = configuration.CommandScheduler<CommandTarget>();

            store = configuration.Store<CommandTarget>();
        }
        protected override void Configure(Configuration configuration)
        {
            disposables = new CompositeDisposable();
            clockName   = Any.CamelCaseName();

            configuration.UseSqlStorageForScheduledCommands()
            .UseInMemoryCommandTargetStore()
            .TraceScheduledCommands()
            .UseDependency <GetClockName>(_ => command => clockName);

            scheduler = configuration.CommandScheduler <CommandTarget>();

            store = configuration.Store <CommandTarget>();
        }
Пример #10
0
 public GameCommandHandler(
     ICommandScheduler <MarcoPoloPlayerWhoIsIt> itScheduler,
     ICommandScheduler <MarcoPoloPlayerWhoIsNotIt> playerScheduler)
 {
     if (playerScheduler == null)
     {
         throw new ArgumentNullException("itScheduler");
     }
     if (itScheduler == null)
     {
         throw new ArgumentNullException("playerScheduler");
     }
     this.playerScheduler = playerScheduler;
     this.itScheduler     = itScheduler;
 }
Пример #11
0
 /// <summary>
 /// Schedules a constructor command on the specified scheduler.
 /// </summary>
 public static async Task <IScheduledCommand <TTarget> > Schedule <TTarget>(
     this ICommandScheduler <TTarget> scheduler,
     ConstructorCommand <TTarget> command,
     DateTimeOffset?dueTime          = null,
     IPrecondition deliveryDependsOn = null,
     IClock clock = null)
     where TTarget : class
 {
     return(await scheduler.Schedule(
                command : command,
                targetId : command.AggregateId.ToString(),
                dueTime : dueTime,
                deliveryDependsOn : deliveryDependsOn,
                clock : clock));
 }
Пример #12
0
        internal static async Task DeserializeAndDeliverScheduledCommand <TAggregate>(
            ScheduledCommand scheduled,
            ICommandScheduler <TAggregate> scheduler)
        {
            try
            {
                var command = scheduled.ToScheduledCommand <TAggregate>();
                await scheduler.Deliver(command);

                scheduled.Result = command.Result;
            }
            catch (Exception exception)
            {
                scheduled.Result = new CommandFailed(scheduled, exception);
            }
        }
Пример #13
0
 internal static void DeliverIfPreconditionIsSatisfiedWithin <TAggregate>(
     this ICommandScheduler <TAggregate> scheduler,
     TimeSpan timespan,
     IScheduledCommand <TAggregate> scheduledCommand,
     IEventBus eventBus) where TAggregate : IEventSourced
 {
     eventBus.Events <IEvent>()
     .Where(
         e => e.AggregateId == scheduledCommand.DeliveryPrecondition.AggregateId &&
         e.ETag == scheduledCommand.DeliveryPrecondition.ETag)
     .Take(1)
     .Timeout(timespan)
     .Subscribe(
         e => { Task.Run(() => scheduler.Deliver(scheduledCommand)).Wait(); },
         onError: ex => { eventBus.PublishErrorAsync(new EventHandlingError(ex, scheduler)); });
 }
Пример #14
0
        public static async Task DeserializeAndDeliverScheduledCommand <TAggregate>(
            ScheduledCommand scheduled,
            ICommandScheduler <TAggregate> scheduler)
            where TAggregate : IEventSourced
        {
            var command = scheduled.ToScheduledCommand <TAggregate>();

            //here we are setting the command.SequenceNumber to the scheduled.SequenceNumber because when
            //multiple commands are scheduled simultaniously against the same aggregate we were decrementing the
            //scheduled.SequenceNumber correctly, however we were not updating the command.SequenceNumber.
            //this is to prevent any side effects that may have been caused by that bug
            command.SequenceNumber = scheduled.SequenceNumber;

            await scheduler.Deliver(command);

            scheduled.Result = command.Result;
        }
Пример #15
0
        public static Task Schedule <TCommand, TAggregate>(
            this ICommandScheduler <TAggregate> scheduler,
            Guid aggregateId,
            TCommand command,
            DateTimeOffset?dueTime   = null,
            IEvent deliveryDependsOn = null)
            where TCommand : ICommand <TAggregate>
            where TAggregate : IEventSourced
        {
            if (aggregateId == Guid.Empty)
            {
                throw new ArgumentException("Parameter aggregateId cannot be an empty Guid.");
            }

            ScheduledCommandPrecondition precondition = null;

            if (deliveryDependsOn != null)
            {
                if (deliveryDependsOn.AggregateId == Guid.Empty)
                {
                    throw new ArgumentException("An AggregateId must be set on the event on which the scheduled command depends.");
                }

                if (string.IsNullOrWhiteSpace(deliveryDependsOn.ETag))
                {
                    deliveryDependsOn.IfTypeIs <Event>()
                    .ThenDo(e => e.ETag = Guid.NewGuid().ToString("N"))
                    .ElseDo(() => { throw new ArgumentException("An ETag must be set on the event on which the scheduled command depends."); });
                }

                precondition = new ScheduledCommandPrecondition
                {
                    AggregateId = deliveryDependsOn.AggregateId,
                    ETag        = deliveryDependsOn.ETag
                };
            }

            return(scheduler.Schedule(new CommandScheduled <TAggregate>
            {
                Command = command,
                DueTime = dueTime,
                AggregateId = aggregateId,
                SequenceNumber = -DateTimeOffset.UtcNow.Ticks,
                DeliveryPrecondition = precondition
            }));
        }
        /// <summary>
        /// Schedules a command on the specified scheduler.
        /// </summary>
        public static async Task <IScheduledCommand <TTarget> > Schedule <TCommand, TTarget>(
            this ICommandScheduler <TTarget> scheduler,
            string targetId,
            TCommand command,
            DateTimeOffset?dueTime          = null,
            IPrecondition deliveryDependsOn = null)
            where TCommand : ICommand <TTarget>
        {
            var scheduledCommand = new ScheduledCommand <TTarget>(
                command,
                targetId,
                dueTime,
                deliveryDependsOn);

            await scheduler.Schedule(scheduledCommand);

            return(scheduledCommand);
        }
        /// <summary>
        /// Schedules a command on the specified scheduler.
        /// </summary>
        public static async Task <IScheduledCommand <TAggregate> > Schedule <TCommand, TAggregate>(
            this ICommandScheduler <TAggregate> scheduler,
            Guid aggregateId,
            TCommand command,
            DateTimeOffset?dueTime   = null,
            IEvent deliveryDependsOn = null)
            where TCommand : ICommand <TAggregate>
        {
            var scheduledCommand = new ScheduledCommand <TAggregate>(
                command,
                aggregateId,
                dueTime,
                deliveryDependsOn.ToPrecondition());

            await scheduler.Schedule(scheduledCommand);

            return(scheduledCommand);
        }
Пример #18
0
        public Shell(
            IKernel kernel,
            ICommandScheduler <JupyterRequestContext> scheduler,
            ConnectionInformation connectionInformation)
        {
            if (connectionInformation == null)
            {
                throw new ArgumentNullException(nameof(connectionInformation));
            }

            _kernel    = kernel ?? throw new ArgumentNullException(nameof(kernel));
            _scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));

            _shellAddress   = $"{connectionInformation.Transport}://{connectionInformation.IP}:{connectionInformation.ShellPort}";
            _ioPubAddress   = $"{connectionInformation.Transport}://{connectionInformation.IP}:{connectionInformation.IOPubPort}";
            _stdInAddress   = $"{connectionInformation.Transport}://{connectionInformation.IP}:{connectionInformation.StdinPort}";
            _controlAddress = $"{connectionInformation.Transport}://{connectionInformation.IP}:{connectionInformation.ControlPort}";

            var signatureAlgorithm = connectionInformation.SignatureScheme.Replace("-", string.Empty).ToUpperInvariant();

            _signatureValidator = new SignatureValidator(connectionInformation.Key, signatureAlgorithm);
            _shell       = new RouterSocket();
            _ioPubSocket = new PublisherSocket();
            _stdIn       = new RouterSocket();
            _control     = new RouterSocket();

            _shellChannel = new ReplyChannel(new MessageSender(_shell, _signatureValidator));
            _ioPubChannel = new PubSubChannel(new MessageSender(_ioPubSocket, _signatureValidator));
            _stdInChannel = new StdInChannel(new MessageSender(_stdIn, _signatureValidator), new MessageReceiver(_stdIn));

            _disposables = new CompositeDisposable
            {
                _shell,
                _ioPubSocket,
                _stdIn,
                _control
            };
        }
Пример #19
0
        // TODO: (CommandSchedulerExtensions) combine with CommandScheduler class
        public static async Task <IScheduledCommand <TAggregate> > Schedule <TCommand, TAggregate>(
            this ICommandScheduler <TAggregate> scheduler,
            Guid aggregateId,
            TCommand command,
            DateTimeOffset?dueTime   = null,
            IEvent deliveryDependsOn = null)
            where TCommand : ICommand <TAggregate>
            where TAggregate : IEventSourced
        {
            if (aggregateId == Guid.Empty)
            {
                throw new ArgumentException("Parameter aggregateId cannot be an empty Guid.");
            }

            var scheduledCommand = CommandScheduler.CreateScheduledCommand <TCommand, TAggregate>(
                aggregateId,
                command,
                dueTime,
                deliveryDependsOn);

            await scheduler.Schedule(scheduledCommand);

            return(scheduledCommand);
        }
Пример #20
0
 public void RunBeforeEveryTest()
 {
     _scheduler   = new CommandScheduler();
     _testCommand = Substitute.For <ICommand>();
 }
Пример #21
0
 public static ICommandScheduler <T> UseMiddleware <T>(
     this ICommandScheduler <T> scheduler,
     CommandSchedulingMiddleware <T> middleware) =>
 Create <T>(async delivery => await middleware(
                delivery,
                async d => await scheduler.Schedule(d)));
 public CommandsController(ICommandService commandService, ICommandScheduler scheduler)
 {
     _commandService = commandService;
     _scheduler      = scheduler;
 }
Пример #23
0
 public ExecuteState(ICommandScheduler scheduler, CommandExecuter executer)
 {
     this.scheduler = scheduler;
     this.executer = executer;
 }
Пример #24
0
 public NewUserRegisteredEnqueueEmailConfirmationHandler(ICommandScheduler commandScheduler)
 {
     _commandScheduler = commandScheduler;
 }
 // Token: 0x0600197B RID: 6523
 public HUDMapController(HUDMapControllerAsset settings, SimMapDependencies mapDependencies, UserCamera camera, ICommandScheduler simScheduler, bool showBoundariesGame, bool showBoundariesSensors)
 {
     this.mHUDEnabled                   = true;
     this.mFOWSimEnabled                = true;
     this.mFOWRenderEnabled             = true;
     this.mBoundsEnabled                = true;
     this.mDefaultFOWVolumeBuffer       = new CommandBuffer();
     this.mFoWCubeMeshTransform         = Matrix4x4.identity;
     this.mSimScheduler                 = simScheduler;
     this.mMainCamera                   = camera.ActiveCamera;
     this.mFogBuffers                   = new Dictionary <HUDMapController.RenderModeType, CommandBuffer>(2, HUDMapController.sRenderModeTypeComparer);
     this.mBoundsEnabledForLevelGame    = showBoundariesGame;
     this.mBoundsEnabledForLevelSensors = showBoundariesSensors;
     this.mSettings = settings;
     if (this.mSettings != null)
     {
         if (mapDependencies != null)
         {
             Vector3 min = VectorHelper.SimVector2ToUnityVector3(mapDependencies.MinPathfindingBounds, -5000f);
             Vector3 max = VectorHelper.SimVector2ToUnityVector3(mapDependencies.MaxPathfindingBounds, 5000f);
             // MOD: fix sensors on non square maps
             float s = Math.Max(max.x - min.x, max.z - min.z);
             max.x = min.x + s;
             max.z = min.z + s;
             // MOD
             this.mMapBounds = default(Bounds);
             this.mMapBounds.SetMinMax(min, max);
             this.mFOWCamera = HUDMapController.InstantiateFOWCamera(settings.FOWCameraPrefab, this.mMapBounds, ShipbreakersMain.GetDynamicRoot(ShipbreakersMain.DynamicRootIndex.Misc));
             if (this.mMainCamera != null && this.mFOWCamera != null)
             {
                 if (this.mFOWCamera.targetTexture != null)
                 {
                     Log.Error(Log.Channel.Graphics, "RenderTexture asset incorrectly set as target for FoW camera, discarding!", new object[0]);
                     this.mFOWCamera.targetTexture.Release();
                 }
                 this.mFOWTexture              = HUDMapController.CreateFOWRenderTexture(this.mMapBounds);
                 this.mBlurMaterial            = new Material(settings.FOWBlurShader);
                 this.mFOWCamera.targetTexture = this.mFOWTexture;
                 this.mFOWCamera.AddCommandBuffer(CameraEvent.AfterForwardOpaque, HUDMapController.CreateFOWBlurCmdBuffer(this.mBlurMaterial, this.mFOWTexture));
                 this.mFOWMaterial = new Material(settings.FOWMaterial);
                 this.mFOWMaterial.SetTexture("_MainTex", this.mFOWTexture);
                 Vector3    size       = Vector3.one * 5000f + this.mMapBounds.size;
                 GameObject gameObject = HUDMapController.InstantiateFOWVolume(new Bounds(this.mMapBounds.center, size));
                 this.mFoWCubeMesh          = gameObject.GetComponent <MeshFilter>().mesh;
                 this.mFoWCubeMeshTransform = gameObject.transform.localToWorldMatrix;
                 HUDMapController.RebuildFOWVolumeCmdBuffer(this.mDefaultFOWVolumeBuffer, this.mFoWCubeMesh, this.mFoWCubeMeshTransform, this.mFOWMaterial, "FOW Combine (Default)");
                 this.mFogBuffers.Add(HUDMapController.RenderModeType.Default, this.mDefaultFOWVolumeBuffer);
                 UnityEngine.Object.Destroy(gameObject);
                 this.CreateMapBoundsBuffers(settings);
                 this.SetMode(HUDMapController.RenderModeType.Default);
                 this.mAnimFade = new FloatAnimFadeInOut(null, 1f, 1f, 0f);
                 this.mAnimFade.FadeOutCallback = new Action(this.OnAnimFadeOut);
                 this.mAnimFade.Value           = 1f;
                 ShipbreakersMain.PresentationEventSystem.AddHandler <SensorsManagerEvent>(new BBI.Core.Events.EventHandler <SensorsManagerEvent>(this.OnSensorsManagerEvent));
                 ShipbreakersMain.PresentationEventSystem.AddHandler <HUDMapToggleEvent>(new BBI.Core.Events.EventHandler <HUDMapToggleEvent>(this.OnHUDMapToggleEvent));
                 ShipbreakersMain.PresentationEventSystem.AddHandler <HUDMapSettingsEvent>(new BBI.Core.Events.EventHandler <HUDMapSettingsEvent>(this.OnHUDMapSettingsEvent));
                 ShipbreakersMain.PresentationEventSystem.AddHandler <QualitySettingsChangedEvent>(new BBI.Core.Events.EventHandler <QualitySettingsChangedEvent>(this.OnQualitySettingsChanged));
                 ShipbreakersMain.PresentationEventSystem.AddHandler <TacticalOverlayToggleEvent>(new BBI.Core.Events.EventHandler <TacticalOverlayToggleEvent>(this.OnTacticalOverlayToggleEvent));
                 ShipbreakersMain.SimToPresentationEventSystem.AddHandler <MatchGameOverEvent>(new BBI.Core.Events.EventHandler <MatchGameOverEvent>(this.OnMatchGameOverEvent));
                 ShipbreakersMain.SimToPresentationEventSystem.AddHandler <ReplayCompleteEvent>(new BBI.Core.Events.EventHandler <ReplayCompleteEvent>(this.OnReplayCompleteEvent));
             }
             else
             {
                 Log.Error(Log.Channel.Graphics, "Cannot find child Camera for provided UserCamera", new object[]
                 {
                     camera
                 });
             }
             DecalSystem.sFOWCamera = this.mFOWCamera;
             return;
         }
         Log.Error(Log.Channel.Graphics, "[FogOfWar] - Cannot initialize Presentaiton side FoW for level! Make sure it contains a SetRenderSettings and has particle occlusion baked!", new object[0]);
     }
 }
Пример #26
0
 public CommandHandler(ICommandScheduler commandScheduler, IEventStore eventStore)
 {
     _eventStore       = eventStore;
     _commandScheduler = commandScheduler;
 }