Example #1
0
 public StateMachineController(LifeCycleState lifeCycleState, SchedulerState schedulerState,
                               ConnectivityState connectivityState)
 {
     _lifeCycleState    = lifeCycleState;
     _schedulerState    = schedulerState;
     _connectivityState = connectivityState;
 }
Example #2
0
        /// <summary>
        /// Конструктор. Создает новый агрегат.
        /// </summary>
        /// <param name="buildDate">Дата сборки.</param>
        /// <param name="number">Номер.</param>
        /// <param name="releaseNumber">Номер релиза.</param>
        /// <param name="distributionId">Идентификатор дистрибутива.</param>
        /// <param name="location">Местоположение.</param>
        /// <param name="sourceType">Тип хранилища.</param>
        /// <param name="lifeCycleState"><see cref="LifeCycleState"/>.</param>
        /// <param name="suffixes">Суффиксы.</param>
        public Build(
            DateTime buildDate,
            VersionNumber number,
            VersionNumber releaseNumber,
            Guid distributionId,
            string location,
            BuildSourceType sourceType,
            LifeCycleState lifeCycleState,
            IList <string> suffixes = null)
        {
            location.ThrowIsNullOrWhiteSpace(new CreateBuildException("Invalid location value"));
            ValidateReleaseNumber(releaseNumber, number, location);

            Id = Guid.NewGuid();

            Apply(new BuildCreated(
                      Id,
                      buildDate,
                      distributionId,
                      location,
                      number,
                      releaseNumber,
                      lifeCycleState,
                      sourceType,
                      suffixes ?? new List <string>(),
                      CreateMetadata()));
            UpdateArtifactState(ArtifactState.Created);
        }
Example #3
0
        public async Task Check_BuildCurrentAndNewState_CanChange(string suffix, LifeCycleState currentState, LifeCycleState newState, bool expectedCanChange)
        {
            Build build = CreateBuild(currentState, suffix);

            StateChangeCheckResult result = await buildStateChangeChecker.Check(build, newState);

            Assert.Equal(expectedCanChange, result.CanChange);
        }
Example #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void setInitialState(StateAwareSuspendableLifeCycle lifeCycle, LifeCycleState state) throws Throwable
        internal static void SetInitialState(StateAwareSuspendableLifeCycle lifeCycle, LifeCycleState state)
        {
            foreach (LifeCycleState lifeCycleState in LifeCycleState.values())
            {
                if (lifeCycleState.compareTo(state) <= 0)
                {
                    lifeCycleState.set(lifeCycle);
                }
            }
        }
        public ReturnCode_t DeactivateComponent(LightweightRTObject comp)
        {
            _executor.Dispose();

            _state = LifeCycleState.INACTIVE_STATE;

            _component.OnDeactivated(0);

            return ReturnCode_t.RTC_OK;
        }
Example #6
0
        protected override void InitTestData()
        {
            startState = new LifeCycleState(TestData.Get("StartName"), 20, 20);

            confirmingState = new LifeCycleState(TestData.Get("ConfirmingName"), 300, 20)
            {
                Label       = TestData.Get("ConfirmingLabel"),
                Icon        = "PackageDefinition.svg",
                Permissions = shopWorkersPermissionName
            };

            creatingState = new LifeCycleState(TestData.Get("CreatingName"), 600, 20)
            {
                Permissions = shopWorkersPermissionName
            };

            completedState = new LifeCycleState(TestData.Get("CompletedName"), 900, 20)
            {
                Label       = TestData.Get("CompletedLabel"),
                Permissions = lcmPermissionName
            };

            startConfirmTransition = new LifeCycleTransition(startState, confirmingState)
            {
                Role = Actor.ActorInfo.LoginName
            };

            confirmCreatingTransition = new LifeCycleTransition(confirmingState, creatingState)
            {
                Role = "Innovator Admin"
            };

            creatingCompletedTransition = new LifeCycleTransition(creatingState, completedState)
            {
                Role = Actor.ActorInfo.LoginName
            };

            lifeCycleMap = new LifeCycleMap(TestData.Get("MapName"))
            {
                Description = TestData.Get("MapDescription"),
                States      = new List <LifeCycleState> {
                    startState, confirmingState, creatingState, completedState
                },
                Transitions = new List <LifeCycleTransition> {
                    startConfirmTransition, confirmCreatingTransition, creatingCompletedTransition
                }
            };

            var lifeCycleMapColumnLabel = Actor.AsksFor(LocaleState.LabelOf.GridColumn("Life Cycle Map", "name"));

            searchData = new Dictionary <string, string>
            {
                [lifeCycleMapColumnLabel] = lifeCycleMap.Name
            };
        }
        public ExecutionContextServiceServant()
        {
            _state = LifeCycleState.CREATED_STATE;
            _timeSpan = TimeSpan.FromSeconds(1);
            _isRunning = false;
            _state = LifeCycleState.INACTIVE_STATE;

            ExecutionContextScheduler = new EventLoopScheduler();

            _profile = new ExecutionContextProfile();
        }
Example #8
0
 private void SetFailed(Exception error)
 {
     _state = LifeCycleState.FAILED;
     if (_listeners != null)
     {
         foreach (IListener listener in _listeners)
         {
             listener.LifeCycleFailure(this, error);
         }
     }
 }
Example #9
0
 private void SetStopped()
 {
     _state = LifeCycleState.STOPPED;
     if (_listeners != null)
     {
         foreach (IListener listener in _listeners)
         {
             listener.LifeCycleStopped(this);
         }
     }
 }
Example #10
0
 private void SetStarting()
 {
     _state = LifeCycleState.STARTING;
     if (_listeners != null)
     {
         foreach (IListener listener in _listeners)
         {
             listener.LifeCycleStarting(this);
         }
     }
 }
Example #11
0
 private Build CreateBuild(LifeCycleState state, string suffix = "")
 {
     return(new Build(
                DateTime.Now,
                new VersionNumber("4.3.2.1"),
                new VersionNumber("4.3.2"),
                Guid.NewGuid(),
                "Vipnet_Clinet\\4.3.2\\4.3.2_(4.3.2.1)" + suffix,
                BuildSourceType.Pdc,
                state,
                new List <string>()
                ));
 }
        private void UpdateBuildCore(Build build, UpdateBuild command, LifeCycleState newState)
        {
            if (build.LifeCycleState != newState)
            {
                Logger.LogWarning("New state of build does not match with current. " +
                                  $"Current state: {build.LifeCycleState} -> New state: {newState}. " +
                                  $"Current number: {build.Number} -> New number: {command.Number}. " +
                                  $"Current location: {build.Location} -> New location: {command.Location}.");

                build.UpdateLifeCycleState(newState, command.ChangeDate);
            }

            build.Update(command.Location, command.ReleaseNumber, command.Number, command.Suffixes, command.ChangeDate);
        }
        public void IsSatisfiedBy_LifeCycleStates_ResultExpected(
            LifeCycleState[] specificationLifeCycleStates,
            LifeCycleState buildLifeCycleState,
            bool expectedResult)
        {
            var build = new BuildReadModel {
                LifeCycleState = buildLifeCycleState
            };
            var specification = new WithLifeCycleStateSpecification(specificationLifeCycleStates);

            var result = specification.IsSatisfiedBy(build);

            Assert.Equal(expectedResult, result);
        }
        public ReturnCode_t ActivateComponent(LightweightRTObject comp)
        {
            Observable.Start(() =>
            {
                _state = LifeCycleState.ACTIVE_STATE;
                _component.OnActivated(0);
            }, ExecutionContextScheduler)
            .Subscribe(_ =>
            {
                _executor = Observable
                    .Interval(_timeSpan, ExecutionContextScheduler)
                    .Subscribe(__ => _component.OnExecute(0));
            });

            return ReturnCode_t.RTC_OK;
        }
            /// <inheritdoc />
            public async Task <IEnumerable <BuildReadModel> > Handle(Query request, CancellationToken cancellationToken)
            {
                LifeCycleState state = stateMapper.MapFromSuffixes(request.Suffixes);

                IList <BuildReadModel> builds =
                    await buildRepository
                    .QueryAll(x =>
                              x.DistributionId == request.DistributionId &&
                              x.Number == request.BuildNumber &&
                              x.SourceType == request.SourceType &&
                              x.LifeCycleState == state, cancellationToken);

                HashSet <string> setSuffixes = request.Suffixes.ToHashSet(StringComparer.OrdinalIgnoreCase);

                return(builds.Where(b => setSuffixes.SetEquals(b.Suffixes)));
            }
Example #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Parameterized.Parameters(name = "From {0} and {1} to {2} should end in {3}") public static Iterable<Object[]> data()
        public static IEnumerable <object[]> Data()
        {
            IList <object[]> @params = new List <object[]>();

            foreach (LifeCycleState lifeCycleState in LifeCycleState.values())
            {
                foreach (SuspendedState suspendedState in SuspendedState.values())
                {
                    foreach (SuspendedState toSuspendedState in toSuspendedState())
                    {
                        @params.Add(new object[] { lifeCycleState, suspendedState, toSuspendedState, ExpectedResult(lifeCycleState, suspendedState, toSuspendedState) });
                    }
                }
            }
            return(@params);
        }
        /// <inheritdoc />
        protected override Task UpdateBuild(Build build, UpdateBuild command)
        {
            Logger.LogInformation(
                "Received command UpdateBuild with " +
                $"BuildId: {command.BuildId}, " +
                $"Location: {command.Location}, " +
                $"ReleaseNumber: {command.ReleaseNumber}, " +
                $"Number: {command.Number}, " +
                $"Suffixes: {command.Suffixes?.JoinWith(",")}.");

            LifeCycleState newState = lifeCycleStateMapper.MapFromSuffixes(command.Suffixes.ToArray());

            Logger.LogInformation($"Suffixes were mapped to {newState} for Location: {command.Location}.");

            UpdateBuildCore(build, command, newState);

            Logger.LogInformation($"Build aggregate Id: {command.BuildId} has been updated successfully. NewPath: {command.Location}");

            return(Task.CompletedTask);
        }
Example #18
0
        /// <summary>
        /// Обновляет <see cref="LifeCycleState"/>.
        /// </summary>
        /// <param name="newState">Новое состояние билда.</param>
        /// <param name="changeDate">Дата изменения.</param>
        /// <param name="comment">Комментарий пользовталя.</param>
        /// <param name="actionUserId">Идентификатор пользователь, кто совершал действие.</param>
        public void UpdateLifeCycleState(
            LifeCycleState newState,
            DateTime changeDate,
            string comment      = default,
            string actionUserId = default)
        {
            if (newState == LifeCycleState)
            {
                return;
            }

            var metadata = CreateMetadata(changeDate, actionUserId);

            if (!string.IsNullOrEmpty(comment))
            {
                metadata.Add(MetadataKeys.Comment, comment);
            }

            Apply(new LifeCycleStateChanged(newState, metadata));
            UpdateArtifactState(ArtifactState.Updated);
        }
Example #19
0
 private static LifeCycleState ExpectedResult(SuspendedState state, LifeCycleState toLifeCycle)
 {
     if (state == SuspendedState.Untouched || state == SuspendedState.Enabled)
     {
         return(toLifeCycle);
     }
     else if (state == SuspendedState.Disabled)
     {
         if (toLifeCycle == LifeCycleState.Shutdown)
         {
             return(toLifeCycle);
         }
         else
         {
             return(LifeCycleState.Stop);
         }
     }
     else
     {
         throw new System.InvalidOperationException("Unknown state " + state);
     }
 }
Example #20
0
        /// <inheritdoc />
        protected override async Task HandleCore(CreateBuild command)
        {
            logger.LogInformation($"Received command CreateBuild: {command}");

            LifeCycleState lifeCycleState = lifeCycleStateMapper.MapFromSuffixes(command.Suffixes);

            logger.LogInformation($"Suffixes were mapped to {lifeCycleState}. {command}.");

            Build aggregate = new (
                command.BuildDate,
                command.Number,
                command.ReleaseNumber,
                command.DistributionId,
                command.Location,
                command.SourceType,
                lifeCycleState,
                command.Suffixes);

            await aggregateRepository.Add(aggregate);

            logger.LogInformation($"Build aggregate Id:{aggregate.Id} has been created successfully. {command}");
        }
Example #21
0
 private static LifeCycleState ExpectedResult(LifeCycleState fromState, SuspendedState fromSuspendedState, SuspendedState toSuspendedState)
 {
     if (toSuspendedState == SuspendedState.Disabled)
     {
         return(LifeCycleState.Stop);
     }
     else if (toSuspendedState == SuspendedState.Enabled)
     {
         if (fromSuspendedState == SuspendedState.Disabled)
         {
             if (fromState == LifeCycleState.Init || fromState == LifeCycleState.Shutdown)
             {
                 return(LifeCycleState.Stop);
             }
         }
         return(fromState);
     }
     else
     {
         throw new System.InvalidOperationException("Should not transition to any other state got: " + toSuspendedState);
     }
 }
 private void SetupInit(LifeCycleState buildLifeCycleStateMapperValue)
 {
     buildLifeCycleStateMapperMock
     .Setup(x => x.MapFromSuffixes(It.IsAny <string[]>()))
     .Returns(buildLifeCycleStateMapperValue);
 }
Example #23
0
        public static bool WaitState(this RTObject target, LifeCycleState state, TimeSpan timeout)
        {
            Observable.Interval(TimeSpan.FromMilliseconds(500))
                .Select(_ => target.GetState(0))
                .Where(x => x == state)
                .Timeout(timeout)
                .First();

            // コンポーネント接続失敗
            // タイムアウト

            return true;
        }
 private void SetFailed(Exception error)
 {
     _state = LifeCycleState.FAILED;
     if (_listeners != null)
     {
         foreach (IListener listener in _listeners)
         {
             listener.LifeCycleFailure(this, error);
         }
     }
 }
 private void SetupBuildLifeCycleStateMapper(LifeCycleState returnState)
 {
     buildLifeCycleStateMapperMock
     .Setup(x => x.MapFromSuffixes(It.IsAny <string[]>()))
     .Returns(returnState);
 }
        private void SetStarted()
        {
            _state = LifeCycleState.STARTED;
            if (_listeners != null)
            {

                foreach (IListener listener in _listeners)
                {
                    listener.LifeCycleStarted(this);
                }
            }
        }
        private void SetStopping()
        {
            _state = LifeCycleState.STOPPING;

            if (_listeners != null)
            {
                foreach (IListener listener in _listeners)
                {
                    listener.LifeCycleStopping(this);
                }
            }
        }
Example #28
0
 public void GroupLifeCycleStateChange(string tenantFriendlyName, LifeCycleState lifeCycleState)
 {
     Clients.All.groupLifeCycleStateChange(tenantFriendlyName, lifeCycleState);
 }
Example #29
0
        public void Map_Suffixes_ExpectedState(string[] suffixes, LifeCycleState expectedState)
        {
            LifeCycleState state = mapper.MapFromSuffixes(suffixes);

            Assert.Equal(expectedState, state);
        }
Example #30
0
 public AppLifeCycleMessage(LifeCycleState status)
 {
     Status = status;
 }
        private void CreateByListItem(int index)
        {
            var creatDialog = new CreatePropertyDialog();
            var Vm          = creatDialog.DataContext as CreatePropertyDialogVM;

            switch (index)
            {
            case 0:
            {
                if (creatDialog.ShowDialog() == true)
                {
                    var newLitera = new Litera()
                    {
                        Name = Vm.Name, dbImage = AppService.ConverBitmapImageToByteArray(Vm.PropImage)
                    };
                    newLitera.Save();
                    ObjectPropperties.Add(newLitera);
                    AppService.PropertyVM.Literas.Add(newLitera);
                }
                break;
            }

            case 1:
            {
                if (creatDialog.ShowDialog() == true)
                {
                    var newClass = new ProdactClass()
                    {
                        Name = Vm.Name, dbImage = AppService.ConverBitmapImageToByteArray(Vm.PropImage)
                    };
                    newClass.Save();
                    ObjectPropperties.Add(newClass);
                    AppService.PropertyVM.ProdactClasses.Add(newClass);
                }
                break;
            }

            case 2:
            {
                if (creatDialog.ShowDialog() == true)
                {
                    var newLC = new LifeCycleState()
                    {
                        Name = Vm.Name, dbImage = AppService.ConverBitmapImageToByteArray(Vm.PropImage)
                    };
                    newLC.Save();
                    ObjectPropperties.Add(newLC);
                    AppService.PropertyVM.LifeCycleStates.Add(newLC);
                }
                break;
            }

            case 3:
            {
                if (creatDialog.ShowDialog() == true)
                {
                    var newSection = new ECNsection()
                    {
                        Name = Vm.Name, dbImage = AppService.ConverBitmapImageToByteArray(Vm.PropImage)
                    };
                    newSection.Save();
                    ObjectPropperties.Add(newSection);
                    AppService.PropertyVM.ECNsections.Add(newSection);
                }
                break;
            }
            }
        }
 internal void RaiseStateChanged(LifeCycleState state)
 {
     var args = new StateChangedEventArgs() {State = state};
     _stateSubject.OnNext(args);
 }