/// <summary> /// Обновить визуальное представление пасеки. /// </summary> /// <param name="options">Опции обновления view-модели пасеки.</param> private void Refresh(RefreshApiaryVmOptions options) { IApiaryState state = this.GetStateForRefresh(options); this.tempHoneyCount = state.HoneyCount; this.RefreshBeehives(state.BeehiveStates); this.RaiseMainPropertiesChanged(); }
/// <summary> /// Остановка пасеки. /// </summary> private void Stop() { IApiaryState lastState = this.apiary.Stop(); ApiaryXmlState xmlLastState = ApiaryXmlState.CopyFrom(lastState); xmlLastState.SaveInCache(); this.isWorking = false; this.RefreshCanExecuteCommands(); }
/// <summary> /// Создать потокобезопасное изменяемое состояние пасеки. /// </summary> /// <param name="baseState">Любой интерфейс состояния пасеки.</param> public ApiaryStateThreadSafe(IApiaryState baseState) { if (baseState == null) { throw new ArgumentNullException( nameof(baseState), "Необходимо передать состояние пасеки."); } this.beehiveStates = new List <BeehiveStateThreadSafe>( baseState.BeehiveStates.Select(baseBeehiveState => new BeehiveStateThreadSafe(baseBeehiveState))); this.honeyCount = baseState.HoneyCount; }
/// <summary> /// Создать xml-сериализуемое состояние на основе /// переданного состояния любого вида. /// </summary> /// <param name="state">Состояние пасеки.</param> /// <returns>Новое xml-сериализуемое состояние пасеки.</returns> public static ApiaryXmlState CopyFrom(IApiaryState state) { return(new ApiaryXmlState { HoneyCount = state.HoneyCount, BeehiveStates = new List <BeehiveXmlState>( state.BeehiveStates.Select(bhState => new BeehiveXmlState { BeehiveNumber = bhState.BeehiveNumber, HoneyCount = bhState.HoneyCount, BeesTotalCount = bhState.BeesTotalCount, BeesInsideCount = bhState.BeesInsideCount, WorkerBeesCount = bhState.WorkerBeesCount, QueensCount = bhState.QueensCount, GuardsCount = bhState.GuardsCount })) }); }
/// <summary> /// Запустить пасеку. /// </summary> /// <param name="state">Исходное состояние пасеки.</param> public void Start(IApiaryState state) { if (this.isWorking) { throw new InvalidOperationException( "Пасека уже работает."); } this.isWorking = true; this.HoneyCount = state.HoneyCount; lock (lockObject) { this.beehives = new List <MathBeehive>(state.BeehiveStates.Select( bhState => new MathBeehive(bhState))); ThreadPoolTimer.CreatePeriodicTimer( this.TimerElapsed, TimeSpan.FromMilliseconds(this.beehives.First().IntervalMs)); } }
/// <summary> /// "Запустить" пасеку. /// </summary> /// <param name="state">Исходное состояние пасеки.</param> public void Start(IApiaryState state) { if (this.isWorking) { throw new InvalidOperationException( "Ошибка запуска пасеки. Пасека уже работает."); } this.HoneyCount = state.HoneyCount; this.beehives.Clear(); foreach (IBeehiveState beehiveState in state.BeehiveStates) { var newBeehive = new BeeWorkflowBeehive(); this.beehives.Add(newBeehive); newBeehive.Start(beehiveState); } this.isWorking = true; }