/// <summary>
        /// Refreshes this instance.
        /// </summary>
        public void Refresh()
        {
            var configService = ServiceLocator.Current.GetInstance <IConfigurationService>();

            ReferenceExists     = !IsInitialMapping;
            CurrentMappingBasis = configService.HospitalRegion;
            if (SelectedStates != null)
            {
                SelectedStates.OfType <SelectListItem>().ToList().ForEach(OnRemoveStateCommand);
            }
            RaisePropertyChanged(() => SelectedStates);
            CurrentMappingBasis.DefaultStates
            .OfType <string>()
            .ToList()
            .ForEach(ab =>
            {
                var toAdd = AvailableStates.OfType <SelectListItem>().FirstOrDefault(kvp => kvp.Value != null && kvp.Value.ToString().EqualsIgnoreCase(ab));
                if (toAdd != null)
                {
                    AddStateToContext(toAdd);
                }
            });
            RaisePropertyChanged(() => AvailableStates);
            SelectedRegionType = CurrentMappingBasis.SelectedRegionType ?? typeof(object);
            RaisePropertyChanged(() => SelectedRegionType);
        }
Exemplo n.º 2
0
        private void Initialize()
        {
            AddStateToContextCommand = new DelegateCommand(OnAddState, CanAddState);
            RemoveStateCommand       = new DelegateCommand <State>(OnRemoveStateCommand, CanRemoveState);

            SelectedStates  = CollectionHelper.EmptyListCollectionView <State>();
            EventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>();
            StateCollection = Context.HospitalRegistryService
                              .GetStates()
                              .Select(state => new KeyValuePair <string, State>(state.Abbreviation, state))
                              .Concat(new[] { new KeyValuePair <string, State>(SELECT_STATE, null) })
                              .OrderBy(item => item.Value != null)
                              .ThenBy(item => item.Key).ToListCollectionView();

            var defaultStates = HospitalRegion.Default.DefaultStates.OfType <string>().ToList();

            defaultStates.ForEach(s =>
            {
                var toRemove = StateCollection.OfType <KeyValuePair <string, State> >().First(kvp => kvp.Key == s);
                StateCollection.Remove(toRemove);
                SelectedStates.AddNewItem(toRemove.Value);
            });
            SelectedStates.CommitNew();
            StateCollection.CommitEdit();
            StateCollection.MoveCurrentToFirst();
            /*Regions for combo box, Object type return "SELECT" on display, and NULL on return using  */
            RegionTypes = (new[] {
                typeof(object),
                typeof(HealthReferralRegion),
                typeof(HospitalServiceArea)
            }).ToListCollectionView();

            SelectedRegionType = HospitalRegion.Default.SelectedRegionType;
        }
        /// <summary>
        /// Saves the mapping.
        /// </summary>
        private void SaveMapping()
        {
            ConfigurationService.HospitalRegion.AddStates(SelectedStates.OfType <SelectListItem>().Select(item => item.Text).ToArray(), true);

            ConfigurationService.HospitalRegion.SelectedRegionType = SelectedRegionType;
            ConfigurationService.Save();

            MonahrqContext.ReportingStatesContext = SelectedStates.OfType <SelectListItem>().Select(item => item.Text).ToList();
            MonahrqContext.SelectedRegionType     = SelectedRegionType;

            if (SelectedRegionType != typeof(CustomRegion))
            {
                var sessionProvider = ServiceLocator.Current.GetInstance <IDomainSessionFactoryProvider>();
                //Task.Factory.StartNew(() =>
                //    {
                try
                {
                    ClearRegions(sessionProvider, SelectedRegionType,
                                 SelectedStates.OfType <SelectListItem>().ToArray());
                }
                catch (Exception exc)
                {
                    Logger.Write(exc);
                }
                //});
            }
        }
 /// <summary>
 /// Adds the state to context.
 /// </summary>
 /// <param name="stateKvp">The state KVP.</param>
 private void AddStateToContext(SelectListItem stateKvp)
 {
     SelectedStates.AddNewItem(stateKvp);
     AvailableStates.Remove(stateKvp);
     AvailableStates.MoveCurrentToFirst();
     SelectedStates.CommitNew();
     ApplyContextCommand.RaiseCanExecuteChanged();
 }
Exemplo n.º 5
0
        public override RouteModifier OnNext()
        {
            //next step is
            Context.ContextStates     = SelectedStates.OfType <State>();
            Context.ContextRegionType = RegionTypes.CurrentItem as Type;
            Context.LoadData();

            DataContextObject.Reset();
            return(base.OnNext());
        }
Exemplo n.º 6
0
        public StateMachineViewModel()
        {
            PendingTransition = new TransitionViewModel();
            Runner            = new StateMachineRunnerViewModel(this);

            Blackboard = new BlackboardViewModel()
            {
                Actions    = new NodifyObservableCollection <BlackboardItemReferenceViewModel>(BlackboardDescriptor.GetAvailableItems <IBlackboardAction>()),
                Conditions = new NodifyObservableCollection <BlackboardItemReferenceViewModel>(BlackboardDescriptor.GetAvailableItems <IBlackboardCondition>())
            };
            // public INodifyObservableCollection<T> WhenAdded(Action<T> added)
            // INodifyObservableCollection<T>, Action<T> 임으로 T는 WhenAdded 의부모 속성을 가지므로 파라미터 하나짜리 익명함수의 경우 해당 파라미터는 부모의 객체 타입이다.
            // Source 의경우는 TransitionViewModel 객체의 StateViewModel 이다.
            // public NodifyObservableCollection<StateViewModel> Transitions { get; } = new NodifyObservableCollection<StateViewModel>();
            // 초기화 구문 같은데...
            Transitions.WhenAdded(c => c.Source.Transitions.Add(c.Target))
            .WhenRemoved(c => c.Source.Transitions.Remove(c.Target))
            .WhenCleared(c => c.ForEach(i =>
            {
                i.Source.Transitions.Clear();
                i.Target.Transitions.Clear();
            }));

            States.WhenAdded(x => x.Graph = this)
            .WhenRemoved(x => DisconnectState(x))
            .WhenCleared(x =>
            {
                Transitions.Clear();
                OnCreateDefaultNodes();
            });

            OnCreateDefaultKeys();

            // 여기서 노드와 arrow 가 생성됨.
            OnCreateDefaultNodes();

            // RequeryCommand ???
            RenameStateCommand         = new RequeryCommand(() => SelectedStates[0].IsRenaming = true, () => SelectedStates.Count == 1 && SelectedStates[0].IsEditable);
            DisconnectStateCommand     = new RequeryCommand <StateViewModel>(x => DisconnectState(x), x => !IsRunning && x.Transitions.Count > 0);
            DisconnectSelectionCommand = new RequeryCommand(() => SelectedStates.ForEach(x => DisconnectState(x)), () => !IsRunning && SelectedStates.Count > 0 && Transitions.Count > 0);
            DeleteSelectionCommand     = new RequeryCommand(() => SelectedStates.ToList().ForEach(x => x.IsEditable.Then(() => States.Remove(x))), () => !IsRunning && (SelectedStates.Count > 1 || (SelectedStates.Count == 1 && SelectedStates[0].IsEditable)));

            AddStateCommand = new RequeryCommand <Point>(p => States.Add(new StateViewModel
            {
                Name            = "New State",
                IsRenaming      = true,
                Location        = p,
                ActionReference = Blackboard.Actions.Count > 0 ? Blackboard.Actions[0] : null
            }), p => !IsRunning);

            CreateTransitionCommand = new DelegateCommand <(object Source, object?Target)>(s => Transitions.Add(new TransitionViewModel
            {
                Source = (StateViewModel)s.Source,
                Target = (StateViewModel)s.Target !
            }), s => !IsRunning && s.Source is StateViewModel source && s.Target is StateViewModel target && target != s.Source && target != States[0] && !source.Transitions.Contains(s.Target));
        /// <summary>
        /// Called when [remove state command].
        /// </summary>
        /// <param name="state">The state.</param>
        private void OnRemoveStateCommand(SelectListItem state)
        {
            try
            {
                SelectedStates.Remove(state);
                AvailableStates = AvailableStates.SourceCollection.OfType <SelectListItem>()
                                  .Concat(new[] { state })
                                  .OrderBy(item => item.Value != null)
                                  .ThenBy(item => item.Text).ToListCollectionView();

                ApplyContextCommand.RaiseCanExecuteChanged();
            }
            catch (Exception ex)
            {
                Events.GetEvent <ErrorNotificationEvent>().Publish(ex);
            }
        }
Exemplo n.º 8
0
 private void OnRemoveStateCommand(State state)
 {
     try
     {
         SelectedStates.Remove(state);
         //                StateCollection.MoveCurrentToFirst();
         StateCollection = StateCollection.SourceCollection.OfType <KeyValuePair <string, State> >()
                           .Concat(new[] { new KeyValuePair <string, State>(state.Name, state) })
                           .OrderBy(item => item.Value != null)
                           .ThenBy(item => item.Key).ToListCollectionView();
         RaisePropertyChanged(() => SelectedStates);
     }
     catch (Exception ex)
     {
         EventAggregator.GetEvent <ErrorNotificationEvent>().Publish(ex);
     }
 }
Exemplo n.º 9
0
        private void OnAddState()
        {
            if (SelectedState.Value == null)
            {
                return;
            }

            var state = SelectedState.Value;

            SelectedStates.AddNewItem(SelectedState.Value);
            StateCollection.Remove(SelectedState);
            StateCollection.MoveCurrentToFirst();
            SelectedStates.CommitNew();

            RaisePropertyChanged(() => SelectedStates);
            RaisePropertyChanged(() => StateCollection);
        }
        /// <summary>
        /// Called when [imports satisfied].
        /// </summary>
        public override void OnImportsSatisfied()
        {
            base.OnImportsSatisfied();

            CurrentMappingBasis = ConfigurationService.HospitalRegion;
            ReferenceExists     = !IsInitialMapping;

            AddStateToContextCommand      = new DelegateCommand(OnAddState, CanAddState);
            RemoveStateFromContextCommand = new DelegateCommand <SelectListItem>(OnRemoveStateCommand, CanRemoveState);
            ApplyContextCommand           = new DelegateCommand(OnApplyContextCommand, CanApplyContextCommand);
            NavigateBackCommand           = new DelegateCommand(OnNavigateBackCommand);
            SelectedStates = CollectionHelper.EmptyListCollectionView <SelectListItem>();
            var crit = PredicateBuilder.True <State>();

            ListExtensions.ForEach(CurrentMappingBasis.DefaultStates.OfType <string>().ToList(),
                                   ab => crit = crit.And(st => st.Abbreviation != ab));

            var availStates = new List <SelectListItem>();

            availStates.Add(SELECT_STATE);

            var allStates = HospitalRegistryService.GetStates(null).ToList();

            availStates.AddRange(allStates.AsQueryable()
                                 .Where(crit)
                                 .Select(state => new SelectListItem {
                Model = state, Text = state.Abbreviation, Value = state.Abbreviation
            })
                                 //.Concat(new[] { SELECT_STATE })
                                 .OrderBy(item => item.Text).ToList());

            AvailableStates = availStates.ToListCollectionView();

            crit = PredicateBuilder.False <State>();

            ListExtensions.ForEach(CurrentMappingBasis.DefaultStates
                                   .OfType <string>(), ab => crit = crit.Or(st => st.Abbreviation == ab));

            var selectedStates = allStates.AsQueryable().Where(crit).Select(st => new SelectListItem {
                Text = st.Abbreviation, Value = st.Abbreviation, Model = st
            }).ToList();

            // Setting the Selected Reporting States for Global use.
            //if (!MonahrqContext.ReportingStatesContext.Any(s => selectedStates.Any(s1 => s.In(s1)) ))
            //    MonahrqContext.ReportingStatesContext.AddRange(selectedStates);
            MonahrqContext.ReportingStatesContext.AddRange(selectedStates.Select(s => s.Text).ToList());

            SelectedStates = selectedStates.ToListCollectionView();
            SelectedStates.CommitNew();
            AvailableStates.CommitEdit();
            AvailableStates.MoveCurrentToFirst();

            SelectedState = SELECT_STATE;

            // Regions for combo box, Object type return "SELECT" on display, and NULL on return using
            RegionTypes = (new[] {
                typeof(object),
                typeof(CustomRegion),
                typeof(HealthReferralRegion),
                typeof(HospitalServiceArea)
            }).ToListCollectionView();

            SelectedRegionType = CurrentMappingBasis.SelectedRegionType;
        }