Inheritance: ViewModelBase
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     this._viewModel = e.Parameter as CommandViewModel;
     this.DataContext = _viewModel;
     ResizeContentWidth();
 }
        public MainViewModel()
        {
            CommandList = new ObservableCollection <CommandViewModel>();

            AddCommandCommand = new RelayCommand(() =>
            {
                var list   = CommandList.Where(q => q.Name.StartsWith("Command")).ToList();
                int maxNum = 0;
                foreach (var cmd in list)
                {
                    var numStr = cmd.Name.Replace("Command", "");
                    int result;
                    bool isConvert = int.TryParse(numStr, out result);
                    if (isConvert)
                    {
                        if (maxNum < result)
                        {
                            maxNum = result;
                        }
                    }
                }
                maxNum++;
                var command  = new CommandViewModel();
                command.Name = "Command" + maxNum;
                command.AddSuccessStateCommand.Execute(null);
                this.CommandList.Add(command);
            });

            DeleteCommandCommand = new RelayCommand <CommandViewModel>(command =>
            {
                CommandList.Remove(command);
            });

            UpdateCortanaCommand = new RelayCommand(() =>
            {
                if (CommandList.GroupBy(q => q.Name).Where(w => w.Count() > 1).Count() > 0)
                {
                    Messenger.Default.Send <string>("Commandの名前が重複しています", "error");
                    return;
                }

                CortanaXmlGenerator generator = new CortanaXmlGenerator(CommandPrefix, Example);
                foreach (var command in CommandList)
                {
                    foreach (var state in command.StateList)
                    {
                        if (state is SuccessStateViewModel)
                        {
                            generator.AddCommandService(command.Name + "_" + state.Name, state.Example,
                                                        state.ListenFor.Replace("\r", "").Split('\n'),
                                                        state.FeedBack,
                                                        voiceCommandServiceName);
                        }
                        else if (state is ScriptStateViewModel)
                        {
                            generator.AddCommandService(command.Name + "_" + state.Name, state.Example,
                                                        state.ListenFor.Replace("\r", "").Split('\n'),
                                                        state.FeedBack,
                                                        voiceCommandServiceName);
                        }
                        else if (state is ProtocolStateViewModel)
                        {
                            generator.AddCommandNavigate(command.Name + "_" + state.Name, state.Example,
                                                         state.ListenFor.Replace("\r", "").Split('\n'),
                                                         state.FeedBack,
                                                         voiceCommandServiceName);
                        }
                    }
                    if (command.StateList.GroupBy(q => q.Name).Where(w => w.Count() > 1).Count() > 0)
                    {
                        Messenger.Default.Send <string>(command.Name + "コマンドのstateの名前が重複しています", "error");
                        return;
                    }
                }
                Messenger.Default.Send <bool>(true, "updating");
                var xml    = generator.GenerateXml();
                CurrentXml = xml;
                //Debug.Write(xml);
                OnRegisterVoiceCommand(xml);
                Messenger.Default.Send <bool>(false, "updating");
            });

            OnRegisterVoiceCommand += e =>
            {
            };

            ChangePassCodeCommand = new RelayCommand(() =>
            {
                this.PassCode = Guid.NewGuid().ToString();
            });

            UpdatePreviewCommand = new RelayCommand(() =>
            {
                PreviewCollection.Clear();
                foreach (var command in CommandList)
                {
                    if (command.StateList.Count > 0)
                    {
                        var preview = new CommandPreview(
                            "コマンド「" + command.Name + "」を使用するにはこの発話をしてください",
                            CommandPrefix + " " + command.StateList.First().FirstListenFor);
                        PreviewCollection.Add(preview);
                    }
                }
            });

            InitializeCommand = new RelayCommand(() =>
            {
                AddCommandCommand.Execute(null);
            });



            CommandPrefix = "コルタナ";
            Example       = "こんにちはコルタナ";
            ChangePassCodeCommand.Execute(null);

            ListWidth = 340;

            PreviewCollection = new ObservableCollection <CommandPreview>();
        }
Esempio n. 3
0
        public MainViewModel()
        {
            CommandList = new ObservableCollection<CommandViewModel>();

            AddCommandCommand = new RelayCommand(()=>
            {
                var list = CommandList.Where(q => q.Name.StartsWith("Command")).ToList();
                int maxNum = 0;
                foreach (var cmd in list)
                {
                    var numStr = cmd.Name.Replace("Command", "");
                    int result;
                    bool isConvert = int.TryParse(numStr,out result);
                    if (isConvert)
                    {
                        if(maxNum < result)
                        {
                            maxNum = result;
                        }
                    }
                }
                maxNum++;
                var command = new CommandViewModel();
                command.Name = "Command"+maxNum;
                command.AddSuccessStateCommand.Execute(null);
                this.CommandList.Add(command);
            });

            DeleteCommandCommand = new RelayCommand<CommandViewModel>(command =>
            {
               CommandList.Remove(command);
            });

            UpdateCortanaCommand = new RelayCommand(()=>
            {

                if (CommandList.GroupBy(q => q.Name).Where(w => w.Count() > 1).Count() > 0)
                {
                    Messenger.Default.Send<string>("Commandの名前が重複しています","error");
                    return;
                }

                CortanaXmlGenerator generator = new CortanaXmlGenerator(CommandPrefix,Example);
                foreach(var command in CommandList)
                {
                    foreach(var state in command.StateList)
                    {
                        if(state is SuccessStateViewModel)
                        {
                            generator.AddCommandService(command.Name+"_"+state.Name,state.Example,
                                state.ListenFor.Replace("\r","").Split('\n'),
                                state.FeedBack,
                                voiceCommandServiceName);
                        }else if(state is ScriptStateViewModel)
                        {
                            generator.AddCommandService(command.Name + "_" + state.Name, state.Example,
                                state.ListenFor.Replace("\r", "").Split('\n'),
                                state.FeedBack,
                                voiceCommandServiceName);
                        }else if(state is ProtocolStateViewModel)
                        {
                            generator.AddCommandNavigate(command.Name + "_" + state.Name, state.Example,
                                state.ListenFor.Replace("\r", "").Split('\n'),
                                state.FeedBack,
                                voiceCommandServiceName);
                        }
                    }
                    if (command.StateList.GroupBy(q => q.Name).Where(w => w.Count() > 1).Count() > 0)
                    {
                        Messenger.Default.Send<string>(command.Name+"コマンドのstateの名前が重複しています", "error");
                        return;
                    }
                }
                Messenger.Default.Send<bool>(true, "updating");
                var xml = generator.GenerateXml();
                CurrentXml = xml;
                //Debug.Write(xml);
                OnRegisterVoiceCommand(xml);
                Messenger.Default.Send<bool>(false, "updating");
            });

            OnRegisterVoiceCommand += e =>
            {

            };

            ChangePassCodeCommand = new RelayCommand(() =>
            {
                this.PassCode = Guid.NewGuid().ToString();
            });

            UpdatePreviewCommand = new RelayCommand(() =>
            {

                PreviewCollection.Clear();
                foreach(var command in CommandList)
                {
                    if (command.StateList.Count > 0)
                    {
                        var preview = new CommandPreview(
                            "コマンド「"+command.Name+"」を使用するにはこの発話をしてください",
                            CommandPrefix+" "+command.StateList.First().FirstListenFor);
                        PreviewCollection.Add(preview);
                    }
                }
            });

            InitializeCommand = new RelayCommand(()=>
            {
                AddCommandCommand.Execute(null);
            });

            CommandPrefix = "コルタナ";
            Example = "こんにちはコルタナ";
            ChangePassCodeCommand.Execute(null);

            ListWidth = 340;

            PreviewCollection = new ObservableCollection<CommandPreview>();
        }