public async Task SaveElementAsync(IEntity entity)
        {
            if (!entity.IsSaveable)
            {
                return;
            }

            // TODO: check for modification state

            var index = GetIndex(entity);

            if (index < 0)
            {
                return;
            }

            _elements[index].State = ElementState.Saving;
            StateHasChanged?.Invoke(this, new System.EventArgs());

            var replacementEntity = await _entityService.UpsertEntityAsync(entity, _parentEntities);

            _elements[index].Entity = replacementEntity;
            _elements[index].State  = ElementState.Existing;

            StateHasChanged?.Invoke(this, new System.EventArgs());
        }
Beispiel #2
0
        /// <summary>
        /// Resets the service to initial state
        /// </summary>
        public void Reset()
        {
            ShouldRender   = true;
            ActiveItem     = default;
            ActiveSpacerId = null;
            Items          = null;

            StateHasChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #3
0
 public void DropActiveItem(Zone zone)
 {
     if (ActiveItem.Zone == zone)
     {
     }
     else
     {
         ActiveItem.Zone = zone;
     }
     ActiveItem = null;
     StateHasChanged?.Invoke();
 }
        public bool SelectElementPreviousOf(ListState list)
        {
            var index = GetIndex(list);

            if (index < 0)
            {
                return(false);
            }

            _elements[index].Focus = true;
            StateHasChanged?.Invoke(this, new System.EventArgs());

            return(true);
        }
Beispiel #5
0
 public MinerClient(HubConnection hubConnection)
 {
     HubConnection = hubConnection;
     foreach (var method in typeof(IMinerClient).GetMethods())
     {
         HubConnection.On(method.Name, method.GetParameters().Select(p => p.ParameterType).ToArray(), parameters =>
         {
             Console.WriteLine($"Calling {method.Name} with {parameters.Length} parameters.");
             var result = (Task)method.Invoke(this, parameters);
             Console.WriteLine($"Called {method.Name} with {parameters.Length} parameters.");
             StateHasChanged?.Invoke();
             return(result);
         });
     }
 }
Beispiel #6
0
        public void ReduceAction(object action)
        {
            IEnumerable <IReducer <TState> > acceptedReducers = reducers.Where(x => x.ShouldAction(action));
            TState newState = State;

            foreach (var reducer in acceptedReducers)
            {
                newState = reducer.Reduce(newState, action);
            }

            if (State != newState)
            {
                State = newState;
                StateHasChanged?.Invoke();
            }
        }
        public void StartGeneticAlgo(string target)
        {
            var selection = new EliteSelection();
            var crossover = new ThreeParentCrossover();
            var mutation  = new ReverseSequenceMutation();
            var fitness   = new MyFitness {
                Target = target
            };
            var chromosome = new Chromosome(target);
            var population = new Population(500, 1000, chromosome);

            _stopwatch = Stopwatch.StartNew();

            _ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation)
            {
                Termination         = new GenerationNumberTermination(300),
                MutationProbability = float.MaxValue
            };
            _timer = new Timer(new TimerCallback(_ =>
            {
                _ga.Termination = new GenerationNumberTermination(_ga.GenerationsNumber + 1);
                if (_ga.GenerationsNumber > 0)
                {
                    _ga.Resume();
                }
                else
                {
                    _ga.Start();
                }

                var teste = string.Empty;
                for (var i = 0; i < _ga.BestChromosome.GetGenes().Length; i++)
                {
                    teste += _ga.BestChromosome.GetGenes()[i].Value;
                    if (teste == target)
                    {
                        Stop();
                        _stopwatch.Stop();
                    }
                }
                StateHasChanged?.Invoke();
            }), null, 0, 1);
        }
        public IConsoleHost WriteLine(string text)
        {
            var targetLine = _CurrentLine ?? NewLine();

            var lines = text.Split('\n').Select(t => t.TrimEnd('\r')).ToArray();

            for (var l = 0; l < lines.Length; l++)
            {
                if (l > 0)
                {
                    targetLine = NewLine();
                }
                targetLine.AddFragments(CreateFragments(lines[l]));
            }

            _CurrentLine = null;
            StateHasChanged?.Invoke(this, EventArgs.Empty);
            return(this);
        }
 private void CollectionHasChanged()
 {
     StateHasChanged?.Invoke(this, EventArgs.Empty);
 }
 private void ItemHasChanged(object sender, PropertyChangedEventArgs e)
 {
     StateHasChanged?.Invoke(this, EventArgs.Empty);
 }
 public void Clear()
 {
     _Lines.Clear();
     StateHasChanged?.Invoke(this, EventArgs.Empty);
 }
Beispiel #12
0
 public void InvokeStateChange()
 {
     StateHasChanged?.Invoke(this, new EventArgs());
 }
 private void OnStateHasChanged() => StateHasChanged?.Invoke(this, EventArgs.Empty);
 protected void UpdateState() => StateHasChanged?.Invoke(null, EventArgs.Empty);