Exemplo n.º 1
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);


            var doc = XDocument.Parse(e.Message);
            var com = doc.Descendants("command");

            if (com.Count() > 1)//fusion
            {
                dynamic json = JsonConvert.DeserializeObject(com.ElementAt(0).Value);
                var     recognized_command = json["recognized"];

                foreach (var commands in com)
                {
                    json = JsonConvert.DeserializeObject(commands.Value);

                    if (json["source"] != null)
                    {
                        json["recognized"] = recognized_command;
                        break;
                    }
                }

                dManager.handleIMcommand((string)json.ToString());
            }
            else
            {
                dManager.handleIMcommand(com.FirstOrDefault().Value);
            }
        }
Exemplo n.º 2
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            Console.WriteLine(com);
            Console.WriteLine(json);
            Console.WriteLine(json.text_to_speak.ToString());
            switch ((string)json.action.ToString())
            {
            case "speak":
                Speak((string)json.text_to_speak.ToString(), 5);
                break;

            case "presentation":
                gr = new Grammar(Environment.CurrentDirectory + "\\grammarPresentation.grxml", "rootRule");
                sre.UnloadAllGrammars();
                sre.LoadGrammar(gr);
                break;

            case "stop_presentation":
                gr = new Grammar(Environment.CurrentDirectory + "\\grammarEdition.grxml", "rootRule");
                sre.UnloadAllGrammars();
                sre.LoadGrammar(gr);
                break;
            }
        }
Exemplo n.º 3
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            if (!acceptingVoiceInput)
            {
                return;
            }

            XNamespace emma_ns = "http://www.w3.org/2003/04/emma";

            Console.WriteLine(e.Message);
            var doc = XDocument.Parse(e.Message);

            string raw_confidence;

            if (doc.Descendants(emma_ns + "interpretation").Count() == 1)
            {
                raw_confidence = (string)doc.Descendants(emma_ns + "interpretation").FirstOrDefault().Attribute(emma_ns + "confidence").Value;
            }
            else
            {
                raw_confidence = (string)doc.Descendants(emma_ns + "interpretation").ElementAt(1).Attribute(emma_ns + "confidence").Value;
            }

            Console.WriteLine("confidence: " + raw_confidence);
            float confidence = 0F;

            float.TryParse(raw_confidence.Replace(".", ","), out confidence);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            onMessage(json, confidence);
        }
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            // Print json recognized
            Console.WriteLine("json: " + json);

            // Get first command
            String _s = (string)json.recognized[0].ToString();

            switch (_s)
            {
            case "O1":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), null);
                break;

            case "O2":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), null);
                break;

            case "O3":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), null);
                break;

            case "M1":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), null);
                break;

            case "M2":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), null);
                break;

            case "M3":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), null);
                break;

            case "SEARCH":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), (string)json.recognized[1].ToString());
                Console.WriteLine("SEARCH command received!");
                break;

            case "CLOSE":
                //Close the browser
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), null);
                break;

            case "FLIGHT":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), (string)json.recognized[1].ToString());
                Console.WriteLine("FLIGHT command received!");
                break;

            case "HOTEL":
                ProcessingCommandFunctions.AcceptCommand((string)json.recognized[0].ToString(), (string)json.recognized[1].ToString());
                Console.WriteLine("HOTEL command received!");
                break;
            }
        }
Exemplo n.º 5
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            getExpression(json);
            _calc.resetValues();
        }
Exemplo n.º 6
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc        = XDocument.Parse(e.Message);
            var     com        = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json       = JsonConvert.DeserializeObject(com);
            Double  confidence = Convert.ToDouble((string)json.recognized[0].ToString());

            Console.WriteLine((string)json.recognized[0].ToString());
            Console.WriteLine((string)json.recognized[1].ToString());
            String comando = (string)json.recognized[1].ToString();

            /*String goal = (string)json.recognized[2].ToString();
            *  String final = (string)json.recognized[3].ToString();
            *  String type = (string)json.recognized[4].ToString();*/



            /* if (t.getSpeech() == true)
             * {
             *   return;
             * }*/
            if (confidence >= 0.7)
            {
                switch (comando)
                {
                case "inicio":
                    Console.WriteLine("entrou carago");
                    webBrowser1.GoHome();
                    //webBrowser1.Navigate("youtube.com");
                    break;

                case "met":
                    t.Speak("Aqui pode ver o estado do tempo.Fico a aguardar o próximo comando");
                    webBrowser1.Navigate("https://www.ipma.pt/pt/otempo/obs.tempo.presente/");
                    break;

                case "music":
                    t.Speak("As melhores músicas só para si. Fico a aguardar o próximo comando");
                    webBrowser1.Navigate("https://www.youtube.com/watch?v=f4Mc-NYPHaQ&index=2&list=RDEMbHaAxpOZhcVmmF6I3y0siA");
                    break;
                    break;
                }
            }

            /*else
             * {
             *  t.Speak(" Desculpe, hoje estou um pouco lenta! Poderia repetir de novo por favor?");
             *
             * }*/
        }
Exemplo n.º 7
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Dispatcher.CurrentDispatcher.Invoke(() =>
            {
                //

                //Console.WriteLine(e.Message);
                var doc      = XDocument.Parse(e.Message);
                var com      = doc.Descendants("command").FirstOrDefault().Value;
                dynamic json = JsonConvert.DeserializeObject(com);
                Console.WriteLine((string)json.ToString());
                json = convertToDict(json);
                Console.WriteLine((string)json.ToString());
                if (json.action != null)
                {
                    switch ((string)json.action.ToString())
                    {
                    case "SEARCH":
                        this.json = json;
                        command.searchLocation(googledriver, coord, json);
                        break;

                    case "DIRECTIONS":
                        command.getDirections(googledriver, coord, json, transport);
                        break;

                    case "MORE":
                        command.zoomIn(googledriver, json);
                        break;

                    case "LESS":
                        command.zoomOut(googledriver, json);
                        break;

                    case "CHANGE":

                        if (json.transport != null)
                        {
                            transport = (string)json.transport.ToString();
                            Console.WriteLine("transport: " + transport);
                        }

                        break;
                    }
                }
            });
        }
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            // first command
            String firstCommand = (string)json.recognized[0].ToString();

            Console.WriteLine(firstCommand);
            String secondCommand;

            // example of json.recognized: ["OPEN_EMAIL", "DENIS", "GOING"]

            switch (firstCommand)
            {
            case "status":
                secondCommand = (string)json.recognized[1].ToString();
                UpdateStatus(secondCommand);
                Console.WriteLine(secondCommand);
                break;

            case "action":
                secondCommand = (string)json.recognized[1].ToString();
                UpdateAction(secondCommand);
                ExecuteAction(secondCommand);
                Console.WriteLine(secondCommand);
                break;

            case "volume":
                secondCommand = (string)json.recognized[1].ToString();
                UpdateAction("Volume " + secondCommand);
                UpdateVolume(secondCommand);
                Console.WriteLine(secondCommand);
                break;

            case "combo":
                secondCommand = (string)json.recognized[1].ToString();
                UpdateCombo(secondCommand);
                Console.WriteLine(secondCommand);
                break;
            }
        }
Exemplo n.º 9
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            //if (!acceptingVoiceInput) return;

            //XNamespace emma_ns = "http://www.w3.org/2003/04/emma";
            //Console.WriteLine(e.Message);
            var doc = XDocument.Parse(e.Message);

            //string raw_confidence = (string)doc.Descendants(emma_ns+"interpretation").FirstOrDefault().Attribute(emma_ns+"confidence").Value;
            //Console.WriteLine("confidence: " + raw_confidence);
            float confidence = 0F;
            //float.TryParse(raw_confidence.Replace(".", ","), out confidence);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            //Console.WriteLine(json.Hands_air.ToString());
            //Console.WriteLine("Hello");
            onMessage(json, confidence);
        }
Exemplo n.º 10
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var doc = XDocument.Parse(e.Message);

            dynamic json = PreProcessing(doc);

            Console.WriteLine(json);
            var action       = json.recognized["action"] == null ? null : json.recognized.action.ToString() as String;
            var confirmation = json.recognized["confirmation"] == null ? null : json.recognized.confirmation.ToString() as String;
            var confidence   = json.recognized.confidence.ToString() as String;

            Console.WriteLine(action);
            if (confidence.Equals("low confidence") && confirmation == null)
            {
                _tts.Speak(_speechTemplates.GetLowConfidence());
            }
            else if (confidence.Equals("explicit confirmation") && confirmation == null)
            {
                if (!action.Equals("USER_STATUS") && !action.Equals("SAY_COMMANDS") && !action.Equals("SAY_TODO"))
                {
                    lastJsonMessage = json;
                }
                executeCommand(json, action, confidence);
            }
            else if (confidence.Equals("implicit confirmation") && confirmation == null)
            {
                executeCommand(json, action, confidence);
            }
            else if (confirmation != null && lastJsonMessage != null)
            {
                if (confirmation.Equals("yes"))
                {
                    executeCommand(lastJsonMessage, lastJsonMessage.recognized.action.ToString() as String, "implicit confirmation");
                    lastJsonMessage = null;
                }
                else
                {
                    _tts.Speak(_speechTemplates.GetNoConfirmation());
                    lastJsonMessage = null;
                }
            }
        }
Exemplo n.º 11
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            Console.WriteLine("Hello");
            Console.WriteLine(json);

            //Shape _s = null;
            //switch ((string)json.recognized[0].ToString())
            //{
            //    case "SQUARE": _s = rectangle;
            //        break;
            //    case "CIRCLE": _s = circle;
            //        break;
            //    case "TRIANGLE": _s = triangle;
            //        break;
            //}

            //App.Current.Dispatcher.Invoke(() =>
            //{
            //    switch ((string)json.recognized[1].ToString())
            //    {
            //        case "GREEN":
            //            _s.Fill = Brushes.Green;
            //            break;
            //        case "BLUE":
            //            _s.Fill = Brushes.Blue;
            //            break;
            //        case "RED":
            //            _s.Fill = Brushes.Red;
            //            break;

            //        case "YELLOW":
            //            _s.Fill = Brushes.Yellow;
            //            break;
            //    }
            //});
        }
Exemplo n.º 12
0
        public void MmiC_Message(object sender, MmiEventArgs e)
        {
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            switch ((string)json.recognized[0].ToString())
            {
            case "MUTE":
                Invoke((MethodInvoker) delegate
                {
                    if (chkbxSndDisable.Checked == true)
                    {
                        tts.Speak("O som já está desactivado.");
                    }
                    else
                    {
                        chkbxSndDisable.Checked   = true;
                        this._player.DisableAudio = true;
                        tts.Speak("Som desactivado!");
                    }
                    ask_attack = false;
                });
                break;

            case "UNMUTE":
                Invoke((MethodInvoker) delegate
                {
                    if (chkbxSndDisable.Checked == false)
                    {
                        tts.Speak("O som já está activado.");
                    }
                    else
                    {
                        chkbxSndDisable.Checked   = false;
                        this._player.DisableAudio = false;
                        tts.Speak("Som activado!");
                    }
                    ask_attack = false;
                });
                break;

            case "ATACAR":
                Invoke((MethodInvoker) delegate
                {
                    if (_player.CurrentLocation.HasAMonster)
                    {
                        if (JsonArray_Length(json) == 1)
                        {
                            btnUseWeapon_Click(null, null);
                            ask_attack = false;
                        }
                        else
                        {
                            if (_player.CurrentMonster.Name.ToLower() != (string)json.recognized[1].ToString().ToLower())
                            {
                                String monster = (string)json.recognized[1].ToString();
                                if (getObj_ID(monster) != _player.CurrentMonster.ID && getObj_ID(monster) != 0)
                                {
                                    tts.Speak("O monstro não é" + World.MonsterByID(getObj_ID(monster)).Name + ", é" + _player.CurrentMonster.Name + ", tens a certeza que queres atacar?");
                                    ask_attack = true;
                                }
                                else if (getObj_ID(monster) == 0)
                                {
                                    tts.Speak("O monstro não é esse" + ", é" + _player.CurrentMonster.Name + ", tens a certeza que queres atacar?");
                                    ask_attack = true;
                                }
                                else
                                {
                                    btnUseWeapon_Click(null, null);
                                    ask_attack = false;
                                }
                            }
                            else
                            {
                                btnUseWeapon_Click(null, null);
                                ask_attack = false;
                            }
                        }
                    }
                    else
                    {
                        tts.Speak("Não existem monstros aqui.");
                    }
                });
                break;

            case "ABRIR":
                Invoke((MethodInvoker) delegate
                {
                    if ((string)json.recognized[1].ToString().ToLower() == "mapa")
                    {
                        if (!IsFormOpen("WorldMap") && !IsFormOpen("TradingScreen"))
                        {
                            btnMap_Click(null, null);
                        }
                        else if (IsFormOpen("WorldMap"))
                        {
                            tts.Speak("O mapa já está aberto.");
                        }
                        else if (IsFormOpen("TradingScreen"))
                        {
                            tts.Speak("Não podes fazer isso. Neste momento tens o vendedor aberto.");
                        }
                    }
                    else if (_player.CurrentLocation.HasAVendor && (string)json.recognized[1].ToString().ToLower() == "vendedor")
                    {
                        if (!IsFormOpen("WorldMap") && !IsFormOpen("TradingScreen"))
                        {
                            btnTrade_Click(null, null);
                            if (JsonArray_Length(json) > 2 && (string)json.recognized[2].ToString().ToLower() == "comprar")
                            {
                                int itemID = getObj_ID((string)json.recognized[3].ToString());
                                tradingScreen.VoiceBuy(itemID, tts);
                            }
                            else if (JsonArray_Length(json) > 2 && (string)json.recognized[2].ToString().ToLower() == "vender")
                            {
                                int itemID = getObj_ID((string)json.recognized[3].ToString());
                                tradingScreen.VoiceSell(itemID, tts);
                            }
                        }
                        else if (IsFormOpen("TradingScreen"))
                        {
                            if (JsonArray_Length(json) == 2)
                            {
                                tts.Speak("O vendedor já está aberto.");
                            }
                            else if (JsonArray_Length(json) > 2 && (string)json.recognized[2].ToString().ToLower() == "comprar")
                            {
                                int itemID = getObj_ID((string)json.recognized[3].ToString());
                                tradingScreen.VoiceBuy(itemID, tts, "O vendedor já está aberto, mas vou comprar na mesma.");
                            }
                            else
                            {
                                int itemID = getObj_ID((string)json.recognized[3].ToString());
                                tradingScreen.VoiceSell(itemID, tts, "O vendedor já está aberto, mas vou vender na mesma.");
                            }
                        }
                        else if (IsFormOpen("WorldMap"))
                        {
                            tts.Speak("Não podes fazer isso. Neste momento tens o mapa aberto.");
                        }
                    }
                    else if (!_player.CurrentLocation.HasAVendor && (string)json.recognized[1].ToString().ToLower() == "vendedor")
                    {
                        tts.Speak("Não podes fazer isso agora. Não há vendedores neste local.");
                    }
                    else
                    {
                        tts.Speak("Não podes fazer isso agora.");
                    }
                });

                ask_attack = false;
                break;

            case "MOVER":
                Invoke((MethodInvoker) delegate
                {
                    if (JsonArray_Length(json) == 2)
                    {
                        if ((string)json.recognized[1].ToString().ToLower() == "cima")
                        {
                            btnNorth_Click(null, null);
                        }
                        else if ((string)json.recognized[1].ToString().ToLower() == "baixo")
                        {
                            btnSouth_Click(null, null);
                        }
                        else if ((string)json.recognized[1].ToString().ToLower() == "direita")
                        {
                            btnEast_Click(null, null);
                        }
                        else if ((string)json.recognized[1].ToString().ToLower() == "esquerda")
                        {
                            btnWest_Click(null, null);
                        }
                    }
                });
                ask_attack = false;
                break;

            case "FECHAR":
                if (JsonArray_Length(json) == 2)
                {
                    if ((string)json.recognized[1].ToString().ToLower() == "mapa" && IsFormOpen("WorldMap"))
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            mapScreen.Close();
                        });
                    }
                    else if (IsFormOpen("TradingScreen") && (string)json.recognized[1].ToString().ToLower() == "vendedor")
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            tradingScreen.Close();
                        });
                    }
                    else
                    {
                        if (IsFormOpen("WorldMap"))
                        {
                            tts.Speak("Não tens o vendedor aberto, mas sim o mapa.");
                        }
                        else if (IsFormOpen("TradingScreen"))
                        {
                            tts.Speak("Naão tens o mapa aberto, mas sim o vendedor.");
                        }
                        else
                        {
                            tts.Speak("Não tens nada aberto para fechar.");
                        }
                    }
                }
                ask_attack = false;
                break;

            case "COMPRAR":
                if (JsonArray_Length(json) == 2)
                {
                    if (IsFormOpen("TradingScreen"))
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            int itemID = getObj_ID((string)json.recognized[1].ToString());
                            tradingScreen.VoiceBuy(itemID, tts);
                        });
                    }
                    else
                    {
                        if (!_player.CurrentLocation.HasAVendor)
                        {
                            tts.Speak("Não tens um vendedor neste local.");
                        }
                        else
                        {
                            tts.Speak("Primeiro tens que abrir o vendedor.");
                        }
                    }
                }
                ask_attack = false;
                break;

            case "VENDER":
                if (JsonArray_Length(json) == 2)
                {
                    if (IsFormOpen("TradingScreen"))
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            int itemID = getObj_ID((string)json.recognized[1].ToString());
                            tradingScreen.VoiceSell(itemID, tts);
                        });
                    }
                    else
                    {
                        if (!_player.CurrentLocation.HasAVendor)
                        {
                            tts.Speak("Não tens um vendedor neste local.");
                        }
                        else
                        {
                            tts.Speak("Primeiro tens que abrir o vendedor.");
                        }
                    }
                }
                ask_attack = false;
                break;

            case "EQUIPAR":
                if (JsonArray_Length(json) == 2)
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        int itemID  = getObj_ID((string)json.recognized[1].ToString());
                        Item weapon = World.ItemByID(Convert.ToInt32(itemID));
                        if (_player.Weapons.Contains(weapon) && _player.CurrentLocation.HasAMonster)
                        {
                            cboWeapons.SelectedIndex = cboWeapons.FindStringExact(weapon.Name);
                            tts.Speak("Equipáste a arma: " + weapon.Name);
                        }
                        else if (!_player.CurrentLocation.HasAMonster)
                        {
                            tts.Speak("Só podes fazer isso em combate!");
                        }
                        else
                        {
                            tts.Speak("Não tens essa arma.");
                        }
                    });
                }
                ask_attack = false;
                break;

            case "BEBER_POCAO":
                this.Invoke((MethodInvoker) delegate
                {
                    int itemID  = getObj_ID((string)json.recognized[0].ToString());
                    Item potion = World.ItemByID(Convert.ToInt32(itemID));
                    cboPotions.SelectedIndex = cboPotions.FindStringExact(potion.Name);
                    if (_player.Potions.Any() && _player.CurrentLocation.HasAMonster)
                    {
                        btnUsePotion_Click(null, null);
                    }
                    else if (!_player.CurrentLocation.HasAMonster)
                    {
                        tts.Speak("Só podes fazer isso em combate.");
                    }
                    else
                    {
                        tts.Speak("Não tens mais poções.");
                    }
                });
                ask_attack = false;
                break;

            case "INFO":
                this.Invoke((MethodInvoker) delegate
                {
                    if ((string)json.recognized[1].ToString() == "M_RATOS" || (string)json.recognized[1].ToString() == "M_COBRAS")
                    {
                        String description = World.QuestByID(getObj_ID((string)json.recognized[1].ToString())).Description;
                        tts.Speak("A descrição da missão é a seguinte: " + description);
                    }
                    else if ((string)json.recognized[1].ToString() == "NEXT_LVL")
                    {
                        int exp_to_next_level = _player.Level * 100 - _player.ExperiencePoints;
                        tts.Speak("Faltam-te " + exp_to_next_level + " pontos de experiência para o próximo nível.");
                    }
                    else if ((string)json.recognized[1].ToString() == "LOCAL")
                    {
                        string local_name        = _player.CurrentLocation.Name;
                        string local_description = _player.CurrentLocation.Description;
                        tts.Speak("Estás em " + local_name + ". " + local_description);
                    }
                    else if ((string)json.recognized[1].ToString() == "LVL")
                    {
                        tts.Speak("Estás no nível " + _player.Level);
                    }
                    else if ((string)json.recognized[1].ToString() == "ESTADO")
                    {
                        tts.Speak("Estás com " + _player.CurrentHitPoints + " pontos de vida." + "Tens " + _player.Gold + "moedas de ouro." + "E a tua localização é: " + _player.CurrentLocation.Name);
                    }
                    else
                    {
                        tts.Speak("Tens " + _player.CurrentHitPoints + " pontos de vida.");
                    }
                });
                ask_attack = false;
                break;

            case "SIM":
                this.Invoke((MethodInvoker) delegate
                {
                    if (ask_attack == true)
                    {
                        btnUseWeapon_Click(null, null);
                        ask_attack = false;
                    }
                    else
                    {
                        tts.Speak("Desculpa mas não percebi.");
                    }
                });
                break;

            case "NAO":
                this.Invoke((MethodInvoker) delegate
                {
                    if (ask_attack == true)
                    {
                        tts.Speak("Certamente.");
                        ask_attack = false;
                    }
                    else
                    {
                        tts.Speak("Desculpa mas não percebi.");
                    }
                });
                break;
            }
        }
Exemplo n.º 13
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            Console.WriteLine(json);

            switch ((string)json.recognized[0].ToString())
            {
            case "CREATE_EVENT":
                string[] starthour = ((string)json.recognized[3].ToString()).Split(':');

                String endhour_s = ((string)json.recognized[4].ToString());
                if (endhour_s == "NO_HOUR")
                {
                    endhour_s = (Int32.Parse(starthour[0]) + 1) + ":" + (Int32.Parse(starthour[1]));
                }
                createEvent(service, (string)json.recognized[1].ToString(), "Aveiro", stringToEventDateTime((string)json.recognized[2].ToString(), (string)json.recognized[3].ToString()), stringToEventDateTime((string)json.recognized[2].ToString(), endhour_s), " ");
                break;

            case "LIST_EVENTS":
                string   date1      = ((string)json.recognized[1].ToString());
                DateTime start1     = stringToDateTime(date1, 0, 0);
                DateTime end1       = stringToDateTime(date1, 23, 59);
                Events   events     = getNextEvents(100);
                String   phrases    = "";
                bool     existEvent = true;
                if (events.Items != null && events.Items.Count > 0)
                {
                    Console.WriteLine("Upcoming events:");
                    foreach (var eventItem in events.Items)
                    {
                        string when = eventItem.Start.DateTime.ToString();
                        if (String.IsNullOrEmpty(when))
                        {
                            when = eventItem.Start.Date;
                        }
                        if ((DateTime.Compare((DateTime)(eventItem.Start.DateTime), start1) > 0) && (DateTime.Compare((DateTime)(eventItem.Start.DateTime), end1) < 0))
                        {
                            Console.WriteLine("{0} ({1})", eventItem.Summary, when);
                            existEvent = false;
                            phrases   += ("Evento " + eventItem.Summary + " às " + when.Split(' ')[1]) + ". \n";
                        }
                    }
                    t.Speak(phrases);
                }
                if (existEvent)
                {
                    Console.WriteLine("No upcoming events found.");
                    t.Speak("Não tem eventos marcados nesse dia.");
                }

                break;

            case "NEXT_EVENT":
                Events ev        = getNextEvents(1);
                bool   nextEvent = true;
                if (ev.Items != null && ev.Items.Count > 0)
                {
                    Console.WriteLine("Next event:");
                    foreach (var eventItem in ev.Items)
                    {
                        string when = eventItem.Start.DateTime.ToString();
                        if (String.IsNullOrEmpty(when))
                        {
                            when = eventItem.Start.Date;
                        }
                        Console.WriteLine("{0} ({1})", eventItem.Summary, when);
                        nextEvent = false;
                        t.Speak("Evento " + eventItem.Summary + " dia " + when.Split(' ')[0] + "às " + when.Split(' ')[1]);
                    }
                }
                if (nextEvent)
                {
                    t.Speak("Não tem eventos no futuro.");
                }
                break;

            case "CANCEL_EVENT":
                string   date2      = (string)json.recognized[2].ToString();
                string[] starthour2 = ((string)json.recognized[3].ToString()).Split(':');
                DateTime start2     = stringToDateTime(date2, Int32.Parse(starthour2[0]), Int32.Parse(starthour2[1]));
                String   eventID    = getEventId((string)json.recognized[1].ToString(), start2);

                Console.WriteLine(eventID);
                //String cancelDate = start2.ToString().Split(' ')[0]; // data dd/mm/yyyy
                //String cancelDate = date2.Split(' ')[0] + "/" + date2.Split(' ')[1];  // data dd/mm
                String cancelDate = start2.ToShortDateString();
                Console.WriteLine(cancelDate);
                if (eventID != "NO_EVENT")
                {
                    cancelEvent(eventID);
                    t.Speak("Evento " + json.recognized[1].ToString() + " no dia " + cancelDate + " cancelado.");
                }
                else
                {
                    t.Speak("Não tem nenhum evento " + json.recognized[1].ToString() + " nesse hórario.");
                }

                break;

            case "AVAIL_DAY":
                Events   avail_events = getNextEvents(100);
                string   date3        = (string)json.recognized[1].ToString();
                DateTime start3       = stringToDateTime(date3, 0, 0);
                DateTime end3         = stringToDateTime(date3, 23, 59);
                bool     avail        = true;
                if (avail_events.Items != null && avail_events.Items.Count > 0)
                {
                    foreach (var eventItem in avail_events.Items)
                    {
                        string when = eventItem.Start.DateTime.ToString();
                        if (String.IsNullOrEmpty(when))
                        {
                            when = eventItem.Start.Date;
                        }
                        if ((DateTime.Compare((DateTime)(eventItem.Start.DateTime), start3) > 0) && (DateTime.Compare((DateTime)(eventItem.Start.DateTime), end3) < 0))
                        {
                            avail = false;
                            break;
                        }
                    }
                }
                if (avail)
                {
                    t.Speak(" Sim, não tem nenhum evento marcado neste dia. ");
                }
                else
                {
                    t.Speak(" Tem eventos marcados neste dia. ");
                }
                break;

            case "POSTPONE_EVENT":
                string   date4      = ((string)json.recognized[2].ToString());
                string[] starthour4 = ((string)json.recognized[3].ToString()).Split(':');
                string   new_date4  = (string)json.recognized[4].ToString();
                DateTime start4     = stringToDateTime(date4, Int32.Parse(starthour4[0]), Int32.Parse(starthour4[1]));

                String eventID4 = getEventId((string)json.recognized[1].ToString(), start4);
                if (eventID4 != "NO_EVENT")
                {
                    postponeEvent(eventID4, new_date4);
                    t.Speak("Evento " + (string)json.recognized[1].ToString() + " adiado.");
                }
                else
                {
                    t.Speak("Não existe " + (string)json.recognized[1].ToString() + " neste dia.");
                }
                break;

            case "CANCEL_EVENTS_DAY":
                string   date5   = (string)json.recognized[1].ToString();
                DateTime start5  = stringToDateTime(date5, 0, 0);
                DateTime end5    = stringToDateTime(date5, 23, 59);
                Events   events5 = getNextEvents(100);
                int      count   = 0;
                if (events5.Items != null && events5.Items.Count > 0)
                {
                    foreach (var eventItem in events5.Items)
                    {
                        string when = eventItem.Start.DateTime.ToString();
                        if (String.IsNullOrEmpty(when))
                        {
                            when = eventItem.Start.Date;
                        }
                        if ((DateTime.Compare((DateTime)(eventItem.Start.DateTime), start5) > 0) && (DateTime.Compare((DateTime)(eventItem.Start.DateTime), end5) < 0))
                        {
                            cancelEvent(eventItem.Id);
                            count++;
                        }
                    }
                }
                if (count == 1)
                {
                    t.Speak("Foi cancelado um evento");
                }
                else if (count > 1)
                {
                    t.Speak("Foram cancelados " + count + " eventos");
                }
                else
                {
                    t.Speak("Não tem eventos nesse dia");
                }

                break;
            }
        }
Exemplo n.º 14
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            if (!_t.getSpeaking())
            {
                var     doc  = XDocument.Parse(e.Message);
                var     com  = doc.Descendants("command").FirstOrDefault().Value;
                dynamic json = JsonConvert.DeserializeObject(com);
                fillValuesWithMessage(json);

                string numberOne = "", numberTwo = "", operation = "";
                _calc.resetValues();

                if (_beggining == true && confidence < 0.40)
                {
                    _t.Speak(chooseRandomSpeech("help"));
                    _beggining = false;
                }
                else if (_confirmation == true)
                {
                    if (confirmation.Equals("sim"))
                    {
                        _t.Speak("O resultado da operação é " + _calc.makeCalculation(_lastNum1 + _lastOp + _lastNum2).ToString());
                        _confirmation = false;
                    }
                    else if (confirmation.Equals("nao"))
                    {
                        _t.Speak(chooseRandomSpeech("repetition"));
                        _confirmation = false;
                    }
                }
                else
                {
                    if (_beggining == true)
                    {
                        _beggining = false;
                    }
                    if (confidence > 0.7 && goodbye.Equals("goodbye"))
                    {
                        _t.Speak(chooseRandomSpeech("goodbye"));
                    }
                    if (confidence > 0.7 && ajuda.Equals("ajuda"))
                    {
                        _t.Speak(chooseRandomSpeech("help"));
                    }
                    else if (confidence >= 0.90)
                    {
                        numberOne = getNumberTranslated(1);
                        numberTwo = getNumberTranslated(2);
                        if (!oprt.Equals(""))
                        {
                            operation = oprt + ",";
                        }
                        _t.Speak("O resultado da operação é " + _calc.makeCalculation(numberOne + operation + numberTwo).ToString());
                    }
                    else if (confidence >= 0.80 && confidence < 0.90)
                    {
                        numberOne = getNumberTranslated(1);
                        numberTwo = getNumberTranslated(2);
                        if (!oprt.Equals(""))
                        {
                            operation = oprt + ",";
                        }
                        if (numberTwo.Equals("") || numberOne.Equals(""))
                        {
                            if (oprt.Equals("raiz"))
                            {
                                _t.Speak("O resultado de raiz de " + numberTwo.ToString() + "é de " + _calc.makeCalculation(numberOne + operation + numberTwo).ToString());
                            }
                            else if (oprt.Equals("^,2"))
                            {
                                _t.Speak("O resultado de " + numberOne.ToString() + "ao quadrado é de: " + _calc.makeCalculation(numberOne + operation + numberTwo).ToString());
                            }
                            else
                            {
                                _t.Speak("O resultado de " + numberOne.ToString() + "ao cubo é de: " + _calc.makeCalculation(numberOne + operation + numberTwo).ToString());
                            }
                        }
                        else
                        {
                            _t.Speak("O resultado de " + numberOne.ToString() + " " + getOperador(oprt) + " " + numberTwo.ToString() + " é " + _calc.makeCalculation(numberOne + operation + numberTwo).ToString());
                        }
                    }
                    else if (confidence >= 0.45 && confidence < 0.8)
                    {
                        numberOne = getNumberTranslated(1);
                        numberTwo = getNumberTranslated(2);
                        if (!oprt.Equals(""))
                        {
                            operation = oprt + ",";
                        }
                        if (numberTwo.Equals("") || numberOne.Equals(""))
                        {
                            if (oprt.Equals("raiz"))
                            {
                                _t.Speak("Deseja saber o resultado de raiz de " + numberTwo.ToString() + "certo?");
                            }
                            else if (oprt.Equals("^,2"))
                            {
                                _t.Speak("Deseja saber o resultado  de " + numberOne.ToString() + "ao quadrado certo?");
                            }
                            else
                            {
                                _t.Speak("Deseja saber o resultado de " + numberOne.ToString() + "ao cubo certo?");
                            }
                        }
                        else
                        {
                            _t.Speak("Deseja saber o resultado de " + numberOne.ToString() + " " + getOperador(oprt) + " " + numberTwo.ToString() + " certo?");
                        }
                        _lastNum1     = numberOne;
                        _lastNum2     = numberTwo;
                        _lastOp       = operation;
                        _confirmation = true;
                    }
                    else if (confidence < 0.45)
                    {
                        _t.Speak(chooseRandomSpeech("repetition"));
                    }
                }
            }
        }
Exemplo n.º 15
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            // VER A MENSAGEM JSON PARA PERCEBER ESTRUTURA
            // IMPORTANT TO KEEP THE FORMAT {"recognized":["blabla","blablabla"]}

            /*
             * switch (json.recognized[0].ToString())
             * {
             *  case "menuprincipal":
             *      worker.goToHomeFolder();
             *      break;
             *  case "pesquisar":
             *      //worker.search(json.Musica.ToString());
             *      worker.search(json.recognized[1].ToString());
             *      break;
             *
             *  case "navegar":
             *      //switch (json.EscolherNavegaçao.ToString())
             *      switch (json.recognized[1].ToString())
             *      {
             *          case "relevantes":
             *              worker.browseFeatured();
             *              break;
             *          case "podcast":
             *              worker.browsePodcasts();
             *              break;
             *          case "cartas":
             *              worker.browseCharts();
             *              break;
             *          case "genero":
             *              worker.browseGenreMoods();
             *              break;
             *          case "novo":
             *              worker.browseNewReleases();
             *              break;
             *          case "descoberta":
             *              worker.browseDiscover();
             *              break;
             *          case "biblioteca":
             *              worker.goToLibrary();
             *              break;
             *      }
             *      break;
             *
             *  case "adicionar":
             *      switch (json.recognized[1].ToString())
             *      {
             *          case "biblioteca": //add songs to library
             *              worker.addSongToLibrary();
             *              break;
             *          case "fila":    //add songs to wait line -> Not Implemented yet!
             *              break;
             *          case "playlist": //add songs to my playlist -> Not Implement yet!
             *              break;
             *      }
             *      break;
             *
             *  case "reproduzir":
             *      worker.playSong();
             *      break;
             *
             *  case "parar":
             *      worker.pauseSong();
             *      break;
             *
             *  case "retroceder":
             *      worker.goBackSong();
             *      break;
             *
             *  case "musicaanterior":
             *      worker.previousSong();
             *      break;
             *
             *  case "avançar":
             *      worker.nextSong();
             *      break;
             *
             *  case "repetir":
             *      switch (json.recognized[1].ToString())
             *      {
             *          case "repetir":
             *              worker.repeatSong();
             *              break;
             *          case "naorepetir":
             *              worker.unrepeatSong();
             *              //worker.unrepeatSongOnce();
             *              break;
             *          case "repetirumavez":
             *              worker.repeatSongOnce();
             *              break;
             *          case "naorepetirumavez":
             *              worker.unrepeatSongOnce();
             *              break;
             *      }
             *      break;
             *
             *  case "baralhar":
             *      switch (json.recognized[1].ToString())
             *      {
             *          case "baralhar":
             *              worker.shuffleSong();
             *              break;
             *          case "desbaralhar":
             *              worker.unShuffleSong();
             *              break;
             *
             *      }
             *      break;
             *
             *  case "mostrar":
             *      //switch (json.EscolherTema.ToString())
             *      switch (json.recognized[1].ToString())
             *      {
             *          case "playlists":
             *              worker.showPlaylists();
             *              break;
             *
             *          case "feitasparamim":
             *              worker.showMadeForYou();
             *              break;
             *
             *          case "músicas":
             *              worker.showSongs();
             *              break;
             *
             *          case "albuns":
             *              worker.showAlbuns();
             *              break;
             *
             *          case "artistas":
             *              worker.showArtists();
             *              break;
             *
             *          case "podcasts":
             *              worker.showPodcasts();
             *              break;
             *
             *          case "fila":
             *              worker.showSongInQueue();
             *              break;
             *      }
             *      break;
             *
             *  case "criar":
             *      //switch (json.EscolherObjecto.ToString())
             *      switch (json.recognized[1].ToString())
             *      {
             *          case "playlists":
             *              //worker.createPlayList(json.EscolherPlaylist.ToString());
             *              worker.createPlayList();
             *              break;
             *      }
             *      break;
             *
             *  case "tocar":
             *      switch (json.recognized[1].ToString())
             *      {
             *          case "tocarAnzol":
             *              worker.playAnzol();
             *              break;
             *          case "tocarSeteMares":
             *              worker.playSeteMares();
             *              break;
             *          case "tocarEngate":
             *              worker.playEngate();
             *              break;
             *          case "tocarCavalos":
             *              worker.playCavalos();
             *              break;
             *          case "tocarCirco":
             *              worker.playCirco();
             *              break;
             *          case "tocarPaixao":
             *              worker.playPaixao();
             *              break;
             *      }
             *      break;
             *
             *  case "volume":
             *      switch (json.recognized[1].ToString())
             *      {
             *          case "volumeup":
             *              worker.VolumeUp();
             *              break;
             *          case "volumedown":
             *              worker.VolumeDown();
             *              break;
             *          case "mutevolume":
             *              worker.MuteVolume();
             *              break;
             *          case "resetvolume":
             *              worker.ResetVolume();
             *              break;
             *          case "minvolume":
             *              worker.MinVolume();
             *              break;
             *          case "maxvolume":
             *              worker.MaxVolume();
             *              break;
             *          case "volume30":
             *              worker.PutVolumeTo30();
             *              break;
             *          case "volume50":
             *              worker.PutVolumeTo50();
             *              break;
             *          case "volume80":
             *              worker.PutVolumeTo80();
             *              break;
             *      }
             *      break;
             *
             *  case "fecharSpotify":
             *      worker.quitSpotify();
             *      break;
             * }
             */
            switch (json.recognized[0].ToString())
            {
            case "right-hand":
                switch (json.recognized[1].gesto.ToString())
                {
                case "menuprincipal":
                    worker.goToHomeFolder();
                    break;

                case "reproduzir":
                    worker.playSong();
                    break;

                case "parar":
                    worker.pauseSong();
                    break;

                case "avançar":
                    worker.nextSong();
                    break;

                case "volumeup":
                    worker.VolumeUp();
                    break;

                case "volumedown":
                    worker.VolumeDown();
                    break;

                case "repetir":
                    worker.repeatSong();
                    break;

                case "retroceder":
                    worker.goBackSong();
                    break;

                case "baralhar":
                    worker.shuffleSong();
                    break;
                }
                break;

            case "left-hand":
                switch (json.recognized[1].gesto.ToString())
                {
                case "musicaanterior":
                    worker.previousSong();
                    break;
                }
                break;

            case "close-ears":
                switch (json.recognized[1].gesto.ToString())
                {
                case "mute":
                    worker.MuteVolume();
                    break;
                }
                break;

            case "cross-arms":
                switch (json.recognized[1].gesto.ToString())
                {
                case "fecharSpotify":
                    worker.quitSpotify();
                    break;
                }
                break;
            }
        }
Exemplo n.º 16
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            var doc = XDocument.Parse(e.Message);

            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            int sizeJson = com.Split(',').Length;

            var gesto = (string)json.recognized[1].ToString();



            switch (gesto) //confimation
            {
            case "scrollDownRapido":
                velocidade = 5;
                direcao    = "baixo";
                break;

            case "scrollDownDevagar":
                velocidade = 1;
                direcao    = "baixo";
                break;

            case "scrollUpRapido":
                velocidade = 5;
                direcao    = "cima";
                break;

            case "scrollUpDevagar":
                velocidade = 1;
                direcao    = "cima";
                break;

            case "esvaziarC":
                if (orderStart == true)
                {
                    if (produtos > 0)
                    {
                        verCarrinho();
                        t.Speak("Tem a certeza que deseja apagar o carrinho de compras?");
                        esvaziar = true;
                        try
                        {
                            esvaziarCarrinho();
                        }
                        catch { }
                    }
                    else
                    {
                        t.Speak("O carrinho está vazio");
                    }
                }
                break;

            case "RecuarR":
                driver.Navigate().Back();
                break;

            case "AvancarL":
                driver.Navigate().Forward();
                break;

            case "StopS":
                direcao = "parado";
                break;

            case "ScrollDR":
                direcao = "baixo";
                break;

            case "ScrollU":
                direcao = "cima";
                break;

            case "verC":
                if (produtos > 0)
                {
                    try
                    {
                        verCarrinho();
                    }
                    catch { }
                    t.Speak("Aqui tem o seu carrinho!");
                }
                else
                {
                    t.Speak("O carrinho está vazio");
                }
                break;

            case "homePC":
                homepage();
                break;

            default:
                break;
            }

            confirmationValue = (string)json.recognized[7].ToString();
            if (esvaziar == true)
            {
                switch (confirmationValue) //confimation
                {
                case "":
                    break;

                case "sim":
                    esvaziarCarrinho();
                    break;

                case "nao":
                    t.Speak("O carrinho de compras não foi apagado!");
                    esvaziar = false;
                    break;

                default:
                    t.Speak("Não percebi");
                    break;
                }
            }

            if (sizeJson > 3)
            {
                if ((string)json.recognized[0].ToString() == "KEY")
                {
                    orderStart = true;
                    t.Speak("Olá! O que gostaria de fazer?");
                }
                else if ((string)json.recognized[0].ToString() == "EXIT")
                {
                    t.Speak("Tem a certeza que deseja sair?");
                    leaving = true;
                }

                confirmationValue = (string)json.recognized[7].ToString();
                if (leaving == true)
                {
                    switch (confirmationValue) //confimation
                    {
                    case "":
                        break;

                    case "sim":
                        sairAplicacao();
                        break;

                    case "nao":
                        leaving = false;
                        t.Speak("Ok!");
                        break;

                    default:
                        t.Speak("Não percebi");
                        break;
                    }
                }

                if (orderStart)
                {
                    switch ((string)json.recognized[1].ToString())
                    {
                    case "scroll":
                        scrollSmooth();
                        break;

                    case "search":
                        if ((string)json.recognized[2].ToString() == "")
                        {
                            t.Speak("O que deseja procurar?");
                        }
                        break;

                    case "return":
                        homepage();
                        break;

                    case "addtocart":
                        adicionarCarrinho();
                        t.Speak("Adicionado ao carrinho com sucesso!");
                        break;

                    case "changedate":
                        changeDate();

                        t.Speak("Ok, a data de entrega foi alterada!");
                        break;

                    case "viewcart":
                        if (produtos > 0)
                        {
                            verCarrinho();
                            t.Speak("Aqui tem o seu carrinho!");
                        }
                        else
                        {
                            t.Speak("O carrinho está vazio");
                        }
                        break;

                    case "closecart":
                        fecharCarrinho();
                        t.Speak("O carrinho foi fechado com sucesso!");
                        break;

                    case "emptycart":
                        if (produtos > 0)
                        {
                            verCarrinho();
                            t.Speak("Tem a certeza que deseja apagar o carrinho de compras?");
                            esvaziar = true;
                        }
                        else
                        {
                            t.Speak("O carrinho está vazio");
                        }
                        break;

                    default:
                        break;
                    }

                    confirmationValue = (string)json.recognized[7].ToString();
                    if (esvaziar == true)
                    {
                        switch (confirmationValue) //confimation
                        {
                        case "":
                            break;

                        case "sim":
                            esvaziarCarrinho();
                            break;

                        case "nao":
                            t.Speak("O carrinho de compras não foi apagado!");
                            esvaziar = false;
                            break;

                        default:
                            t.Speak("Não percebi");
                            break;
                        }
                    }

                    string place;
                    switch ((string)json.recognized[2].ToString()) //restaurants
                    {
                    case "MCDONALDS":
                        //search mcdonalds
                        driver.FindElementByXPath("//div[contains(text(), 'Procurar')]/parent::button").Click();
                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//input[@placeholder='O que deseja?']")));
                        var searchBox = driver.FindElementByXPath("//input[@placeholder='O que deseja?']");
                        for (int i = 0; i < 20; i++)
                        {
                            searchBox.SendKeys(Keys.Backspace);
                        }
                        searchBox.SendKeys("mcdonalds ");

                        switch ((string)json.recognized[3].ToString()) //place
                        {
                        case "UNIVERSIDADE":
                            place = "(Aveiro Universidade)";
                            searchBox.SendKeys("universidade");
                            searchBox.SendKeys(Keys.Enter);

                            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//div/*[contains(text(), '" + place + "')]")));
                            driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();

                            if (pedidoGrupo == false)
                            {
                                wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//a[contains(text(), 'Entendido')]")));
                                driver.FindElementByXPath("//a[contains(text(), 'Entendido')]").Click();
                                pedidoGrupo = true;
                            }
                            break;

                        case "FORUM":
                            place = "(Aveiro Fórum)";
                            searchBox.SendKeys("fórum");
                            searchBox.SendKeys(Keys.Enter);

                            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//div/*[contains(text(), '" + place + "')]")));
                            driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();

                            if (pedidoGrupo == false)
                            {
                                wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//a[contains(text(), 'Entendido')]")));
                                driver.FindElementByXPath("//a[contains(text(), 'Entendido')]").Click();
                                pedidoGrupo = true;
                            }
                            break;

                        case "GLICINIAS":
                            place = "(Aveiro Glicinias)";
                            searchBox.SendKeys("glicinias");
                            searchBox.SendKeys(Keys.Enter);

                            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//div/*[contains(text(), '" + place + "')]")));
                            driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();

                            if (pedidoGrupo == false)
                            {
                                wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//a[contains(text(), 'Entendido')]")));
                                driver.FindElementByXPath("//a[contains(text(), 'Entendido')]").Click();
                                pedidoGrupo = true;
                            }
                            break;

                        case "":
                            searchBox.SendKeys(Keys.Enter);
                            break;
                        }

                        if ((string)json.recognized[3].ToString() == "")
                        {
                            t.Speak("De qual restaurante?");
                        }
                        else
                        {
                            t.Speak("Que produto quer adquirir?");
                        }

                        break;

                    case "MONTADITOS":
                        driver.FindElementByXPath("//div[contains(text(), 'Procurar')]/parent::button").Click();
                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//input[@placeholder='O que deseja?']")));
                        searchBox = driver.FindElementByXPath("//input[@placeholder='O que deseja?']");
                        for (int i = 0; i < 20; i++)
                        {
                            searchBox.SendKeys(Keys.Backspace);
                        }
                        searchBox.SendKeys("100 montaditos ");

                        searchBox.SendKeys(Keys.Enter);

                        place = "100 Montaditos";

                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//div/*[contains(text(), '" + place + "')]")));
                        driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();

                        if (pedidoGrupo == false)
                        {
                            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//a[contains(text(), 'Entendido')]")));
                            driver.FindElementByXPath("//a[contains(text(), 'Entendido')]").Click();
                            pedidoGrupo = true;
                        }
                        break;

                    case "PIZZAHUT":
                        driver.FindElementByXPath("//div[contains(text(), 'Procurar')]/parent::button").Click();
                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//input[@placeholder='O que deseja?']")));
                        searchBox = driver.FindElementByXPath("//input[@placeholder='O que deseja?']");
                        for (int i = 0; i < 20; i++)
                        {
                            searchBox.SendKeys(Keys.Backspace);
                        }
                        searchBox.SendKeys("pizza hut ");

                        searchBox.SendKeys(Keys.Enter);

                        place = "Pizza Hut";

                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//div/*[contains(text(), '" + place + "')]")));
                        driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();

                        if (pedidoGrupo == false)
                        {
                            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//a[contains(text(), 'Entendido')]")));
                            driver.FindElementByXPath("//a[contains(text(), 'Entendido')]").Click();
                            pedidoGrupo = true;
                        }
                        break;
                    }


                    switch ((string)json.recognized[4].ToString()) //options
                    {
                    case "":
                        break;

                    case ".":
                        //search mcdonalds
                        //pergunta ao user o que quer?
                        break;

                    case "-":

                        break;

                    case "-.":

                        break;
                    }

                    switch ((string)json.recognized[5].ToString()) //food on mcdonalds
                    {
                    case "":
                        break;

                    default:

                        var food = (string)json.recognized[5].ToString();
                        foodRestaurant(food);
                        break;
                    }

                    string itemName = "";
                    switch ((string)json.recognized[6].ToString()) //food options on mcdonalds
                    {
                    case "":
                        break;

                    default:
                        itemName = (string)json.recognized[6].ToString();

                        foodOptions(itemName);
                        break;
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var doc = XDocument.Parse(e.Message);

            Console.WriteLine(doc);

            //foreach(XElement element in doc.Descendants("emma:emma"))

            //var x = doc.Descendants("emma:interpretation").First(rec => rec.Attribute("ID"); //.Attributes("emma:confidence").Single().Value;
            //Console.WriteLine("confidenceee::: " + x);
            //Descendant.Element("mmi:mmi").Attribute("emma:confidence").Value;


            //Console.WriteLine(doc.Root);

            //XNamespace xmlns = "http://www.w3.org/2008/04/mmi-arch";

            //string date = doc.Root.Element(xmlns + "emma:interpretation").Attribute("emma:confidence").Value;


            //var node = doc.XPathSelectElement("/mmi:mmi/mmi:startRequest/mmi:contentURL/mmi:data/emma:emma/emma:interpretation").Attribute("emma:confidence");

            //Console.WriteLine(node);

            //var price = doc.Element("emma:confidence");
            //XNamespace s = "http://www.w3.org/2003/04/emma";
            //XElement body = doc.Descendants(s + "confidence").FirstOrDefault();
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);


            double confidence = double.Parse(json.recognized[0].ToString());

            WebDriverWait wait;

            //Console.WriteLine(json.recognized[2].ToString());


            if ((string)json.recognized[1].ToString() == "KEY" && confidence > 0.75)
            {
                orderStart = true;
                t.Speak("Olá! O que gostaria de fazer?");
            }
            else if ((string)json.recognized[1].ToString() == "EXIT")
            {
                t.Speak("Tem a certeza que deseja sair?");
                leaving = true;
            }

            if (leaving == true && confidence > 0.75)
            {
                var confirmation = (string)json.recognized[8].ToString();
                switch (confirmation) //confimation
                {
                case "":
                    break;

                case "sim":
                    t.Speak("Ok, até breve!");
                    driver.Close();
                    System.Environment.Exit(1);
                    break;

                case "nao":
                    leaving = false;
                    break;

                default:
                    t.Speak("Não percebi");
                    break;
                }
            }

            if (orderStart && confidence > 0.65)
            {
                Console.WriteLine(confidence);
                string action;
                switch ((string)json.recognized[2].ToString())
                {
                case "scroll":
                    scrollSmooth();
                    break;

                case "search":
                    t.Speak("O que deseja procurar?");
                    break;

                case "return":
                    var str = "https://www.ubereats.com/pt-PT/feed/?d=" + DateTime.Now.ToString("yyyy-M-dd") + "&et=870&pl=JTdCJTIyYWRkcmVzcyUyMiUzQSUyMkRFVEklMjAtJTIwRGVwYXJ0YW1lbnRvJTIwZGUlMjBFbGVjdHIlQzMlQjNuaWNhJTJDJTIwVGVsZWNvbXVuaWNhJUMzJUE3JUMzJUI1ZXMlMjBlJTIwSW5mb3JtJUMzJUExdGljYSUyMiUyQyUyMnJlZmVyZW5jZSUyMiUzQSUyMkNoSUpzVjdhcjZxaUl3MFJidHRlelhxZVI3YyUyMiUyQyUyMnJlZmVyZW5jZVR5cGUlMjIlM0ElMjJnb29nbGVfcGxhY2VzJTIyJTJDJTIybGF0aXR1ZGUlMjIlM0E0MC42MzMxNzMxMDAwMDAwMSUyQyUyMmxvbmdpdHVkZSUyMiUzQS04LjY1OTQ5MzMlN0Q%3D&ps=1&st=840";

                    driver.Navigate().GoToUrl(str);
                    break;

                case "addtocart":
                    //var numero = driver.FindElementsByXPath("//div[@class='b5 b6 b7 b8 b9 c3 fw bp']"); // Recebe numero de items. driver.FindElement retorna objecto System...

                    /*var numero = driver.FindElementsByXPath("//descendant::div[@class='al an bo']"); // Recebe numero de items. driver.FindElement retorna objecto System...
                     * action = "Adiciona " + numero + " ao pedido";
                     * driver.FindElementByXPath("//parent::*[contains(text(), '" + action + "')]").Click();*/

                    action = "Adiciona";
                    driver.FindElementByXPath("//parent::*[contains(text(), '" + action + "') and contains(text(), 'ao pedido')]").Click();

                    t.Speak("Adicionado ao carrinho com sucesso!");


                    break;

                /*case "removefromcart":
                 *  action = "remove";
                 *  driver.FindElementByXPath("//parent::*[contains(text(), '" + action + "') and contains(text(), 'ao pedido')]").Click();
                 *  break;*/

                /** XPATH returna null por algum motivo **/

                /*case "reduceitem":
                 *  driver.FindElementByXPath("//div[@class='al an bo']/button[1]").Click();
                 *  break;
                 * case "increaseitem":
                 *  //var test = driver.FindElementByXPath("//div[@class='al an bo']//descendant::button[position()=2]");
                 *  //test.Click();
                 *
                 *  var test = driver.FindElements(By.CssSelector("button[class='b5 b6 b7 b8 b9 ba az eh fs ft fc al aj fb bf cd an bo ce fu fv']"));
                 *  test[1].Click();
                 *  break;
                 */

                case "changedate":
                    action = "Entregar agora";
                    //driver.FindElementByXPath("//parent::*[contains(text(), '" + action + "')]").Click();
                    driver.FindElement(By.CssSelector("button[class='ao aq bi bj bk ah b2'")).Click();
                    action = "Agendar para mais tarde";
                    driver.FindElementByXPath("//parent::*[contains(text(), '" + action + "')]").Click();

                    // Adicionar switch para opções
                    wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                    action = "Definir hora de entrega";
                    wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//button[contains(text(), '" + action + "')]")));
                    driver.FindElementByXPath("//button[contains(text(), '" + action + "')]").Click();
                    driver.Navigate().Refresh();

                    t.Speak("Ok, a data de entrega foi alterada!");
                    break;

                case "viewcart":
                    //driver.Navigate().Refresh();
                    cartClicked = !cartClicked;
                    if (!cartClicked)
                    {
                        driver.FindElementByXPath("//button[@aria-label='checkout']").Click();
                    }
                    t.Speak("Aqui tem o seu carrinho!");
                    break;

                case "closecart":
                    driver.FindElementByCssSelector("button[class='af eh ei ej ek el em ao aq dt b2']").Click();
                    break;

                default:
                    break;
                }

                switch ((string)json.recognized[3].ToString()) //restaurants
                {
                case "MCDONALDS":
                    //search mcdonalds
                    driver.FindElementByXPath("//parent::*[contains(text(), 'Procurar')]").Click();
                    //searchBox.Click();
                    //var searchBox = driver.FindElement(By.CssSelector("input[class='bn ct']"));
                    var searchBox = driver.FindElementByXPath("//input[@placeholder='O que deseja?']");
                    for (int i = 0; i < 20; i++)
                    {
                        searchBox.SendKeys(Keys.Backspace);
                    }
                    searchBox.SendKeys("mcdonalds ");

                    string place;

                    switch ((string)json.recognized[4].ToString())     //place
                    {
                    case "UNIVERSIDADE":
                        place = "(Aveiro Universidade)";
                        searchBox.SendKeys("universidade");
                        searchBox.SendKeys(Keys.Enter);

                        //t.Speak("Carregue no botão");

                        wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("div[class='bz c4 bx c0 c3']")));
                        //var txtElement = driver.FindElementsByXPath("[contains(text(), 'Universidade')]");
                        //var item = driver.FindElement(By.CssSelector("div[class='bz c4 bx c0 c3']"));
                        //item.Click();
                        driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();
                        break;

                    case "FORUM":
                        place = "(Aveiro Fórum)";
                        searchBox.SendKeys("fórum");
                        searchBox.SendKeys(Keys.Enter);

                        wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("div[class='bz c4 bx c0 c3']")));
                        driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();
                        break;

                    case "GLICINIAS":
                        place = "(Aveiro Glicinias)";
                        searchBox.SendKeys("glicinias");
                        searchBox.SendKeys(Keys.Enter);

                        wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("div[class='bz c4 bx c0 c3']")));
                        driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();
                        break;

                    case "":
                        searchBox.SendKeys(Keys.Enter);
                        //tts escolha a opção desejada
                        break;
                    }

                    if ((string)json.recognized[4].ToString() == "")
                    {
                        t.Speak("De qual?");
                    }
                    else
                    {
                        t.Speak("Que produto quer adquirir?");
                    }

                    break;

                case "MONTADITOS":
                    driver.FindElementByXPath("//parent::*[contains(text(), 'Procurar')]").Click();
                    searchBox = driver.FindElementByXPath("//input[@placeholder='O que deseja?']");
                    for (int i = 0; i < 20; i++)
                    {
                        searchBox.SendKeys(Keys.Backspace);
                    }
                    searchBox.SendKeys("100 montaditos ");

                    searchBox.SendKeys(Keys.Enter);

                    place = "100 Montaditos";

                    wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                    wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("div[class='bz c4 bx c0 c3']")));
                    driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();
                    break;

                case "PIZZAHUT":
                    driver.FindElementByXPath("//parent::*[contains(text(), 'Procurar')]").Click();
                    searchBox = driver.FindElementByXPath("//input[@placeholder='O que deseja?']");
                    for (int i = 0; i < 20; i++)
                    {
                        searchBox.SendKeys(Keys.Backspace);
                    }
                    searchBox.SendKeys("pizza hut ");

                    /*switch ((string)json.recognized[4].ToString()) //place
                     * {
                     *  case "UNIVERSIDADE":
                     *      searchBox.SendKeys("universidade");
                     *      break;
                     *  case "FORUM":
                     *      searchBox.SendKeys("fórum");
                     *      break;
                     *  case "GLICINIAS":
                     *      searchBox.SendKeys("glicinias");
                     *      break;
                     * }*/
                    searchBox.SendKeys(Keys.Enter);


                    place = "Pizza Hut";

                    wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                    wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector("div[class='bz c4 bx c0 c3']")));
                    driver.FindElementByXPath("//div/*[contains(text(), '" + place + "')]").Click();
                    break;
                }

                //pergunta ao user o que quer?



                switch ((string)json.recognized[5].ToString()) //options
                {
                case "":
                    break;

                case ".":
                    //search mcdonalds
                    //pergunta ao user o que quer?
                    break;

                case "-":

                    break;

                case "-.":

                    break;
                }

                switch ((string)json.recognized[6].ToString()) //food on mcdonalds
                {
                case "":
                    break;

                default:

                    var food = (string)json.recognized[6].ToString();
                    wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                    wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//*[contains(text(), '" + food + "')]")));

                    driver.FindElementByXPath("//*[contains(text(), '" + food + "')]").Click();
                    t.Speak("Deseja alterar o seu pedido?");
                    break;
                }


                IWebElement element;

                string itemName = "";
                switch ((string)json.recognized[7].ToString()) //food on mcdonalds
                {
                case "":
                    break;

                default:
                    itemName = (string)json.recognized[7].ToString();

                    wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                    wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.XPath("//*[contains(text(), '" + itemName + "')]")));

                    element = driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]");
                    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
                    System.Threading.Thread.Sleep(500);

                    driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]").Click();
                    break;

                    /*case "Bacon":
                     *  itemName = "SEM Bacon";
                     *
                     *  element = driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]");
                     *  ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
                     *  System.Threading.Thread.Sleep(500);
                     *
                     *  driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]").Click();
                     *  break;
                     * case "Alface":
                     *  itemName = "SEM Alface";
                     *
                     *  element = driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]");
                     *  ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
                     *  System.Threading.Thread.Sleep(500);
                     *
                     *  driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]").Click();
                     *  //var item = driver.FindElement(By.CssSelector("div[class='ao bn e0 af bg']"));
                     *  //item.Click();
                     *  break;
                     * case "Queijo":
                     *  itemName = "SEM Queijo";
                     *
                     *  element = driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]");
                     *  ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
                     *  System.Threading.Thread.Sleep(500);
                     *
                     *  driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]").Click();
                     *  break;
                     * case "Cebola":
                     *  itemName = "SEM Cebola";
                     *
                     *  element = driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]");
                     *  ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
                     *  System.Threading.Thread.Sleep(500);
                     *
                     *  driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]").Click();
                     *  break;
                     * case "Ketchup":
                     *  itemName = "SEM Ketchup";
                     *
                     *  element = driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]");
                     *  ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
                     *  System.Threading.Thread.Sleep(500);
                     *
                     *  driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]").Click();
                     *  break;
                     * case "Molho Grão de Mostarda":
                     *  itemName = "Molho Grão de Mostarda";
                     *
                     *  element = driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]");
                     *  ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
                     *  System.Threading.Thread.Sleep(500);
                     *
                     *  driver.FindElementByXPath("//*[contains(text(), '" + itemName + "')]").Click();
                     *  break;
                     * default:
                     *
                     *  //var txtElement = driver.FindElementsByXPath("[contains(text(), '" + (string)json.recognized[5].ToString() + "')]");
                     *  //txtElement.();
                     *  break;*/
                }
            }

            /*else if(confidence< 0.75 && confidence> 0.6)
             * {
             *  t.Speak("Pode");
             * }*/
            else if (confidence < 0.65)
            {
                t.Speak(commandsNotUnderstand[rnd.Next(0, 5)]);
            }
        }
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            InputSimulator inputsim = new InputSimulator();

            double confidence = Double.Parse((string)json.recognized[0].ToString());

            String command = (string)json.recognized[1].ToString();

            /*
             * String command2 = (string)json.recognized[2].ToString();
             *
             * String details = (string)json.recognized[3].ToString();
             *
             * String weapon = (string)json.recognized[4].ToString();
             */

            if (t.getSpeech() == true)
            {
                return;
            }

            if (confidence < 0.3)
            {
                t.Speak("Desculpe, pode repetir?");
            }

            else
            {
                switch (command)
                {
                case "CROUCH":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyDown(VirtualKeyCode.LCONTROL);
                    Thread.Sleep(1000);

                    break;
                }

                case "DAB":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_Y);
                    Thread.Sleep(100);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_D);
                    Thread.Sleep(50);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_A);
                    Thread.Sleep(50);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_B);
                    Thread.Sleep(50);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(50);
                    break;
                }

                case "HEY":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_X);
                    Thread.Sleep(25);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_3);
                    break;
                }

                case "HOLD":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_Z);
                    Thread.Sleep(25);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_4);
                    break;
                }

                case "RELOAD":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_R);
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
        }
Exemplo n.º 19
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var        doc        = XDocument.Parse(e.Message);
            var        com        = doc.Descendants("command").FirstOrDefault().Value;
            dynamic    json       = JsonConvert.DeserializeObject(com);
            double     confidence = Double.Parse((string)json.recognized[0].ToString());
            String     command    = (string)json.recognized[1].ToString();
            String     album      = (string)json.recognized[2].ToString();
            String     song       = (string)json.recognized[3].ToString();
            String     by         = (string)json.recognized[4].ToString();
            String     artist     = (string)json.recognized[5].ToString();
            String     genre      = (string)json.recognized[6].ToString();
            String     from       = (string)json.recognized[7].ToString();
            String     year       = (string)json.recognized[8].ToString();
            SearchItem item;
            float      volume;

            if (t.getSpeech() == true)
            {
                return;
            }

            if (confidence < 0.3)
            {
                t.Speak("Sentence not valid. Please try again");
            }

            // Using just a normal command
            else
            {
                switch (command)
                {
                case "HELP":
                    t.Speak("You can play or stop music, skip and go back, mute and unmute and play artists, genres and songs.");
                    break;

                case "QUIT":
                    t.Speak("Bye Bye");
                    Environment.Exit(0);
                    break;

                case "PLAY":
                    spotify.Play();
                    break;

                case "PAUSE":
                    spotify.Pause();
                    break;

                case "SKIP":
                    spotify.Skip();
                    break;

                case "BACK":
                    spotify.Previous();
                    spotify.Previous();
                    break;

                case "VDOWN":
                    volume = spotify.GetSpotifyVolume();
                    if (volume - 25 >= 0)
                    {
                        spotify.SetSpotifyVolume(volume - 25);
                    }
                    else
                    {
                        spotify.SetSpotifyVolume(0);
                    }
                    break;

                case "VUP":
                    volume = spotify.GetSpotifyVolume();
                    if (volume + 25 <= 100)
                    {
                        spotify.SetSpotifyVolume(volume + 25);
                    }
                    else
                    {
                        spotify.SetSpotifyVolume(100);
                    }
                    break;

                case "MUTE":
                    if (!spotify.IsSpotifyMuted())
                    {
                        spotify.Mute();
                    }
                    break;

                case "UNMUTE":
                    if (spotify.IsSpotifyMuted())
                    {
                        spotify.UnMute();
                    }
                    break;

                case "ADD":
                    String playlist1         = webSpotify.GetUserPlaylists(userId: "4lzrg4ac5nyj1f5bosl1pse1i").Items[0].Id;
                    Paging <PlaylistTrack> p = webSpotify.GetPlaylistTracks("4lzrg4ac5nyj1f5bosl1pse1i", playlist1);
                    for (var i = 0; i < p.Items.Count; i++)
                    {
                        if (p.Items[i].Track.Name.Equals(spotify.GetStatus().Track.TrackResource.Name))
                        {
                            t.Speak("This music is already in your playlist");
                            return;
                        }
                    }

                    ErrorResponse x = webSpotify.AddPlaylistTrack("4lzrg4ac5nyj1f5bosl1pse1i", playlist1, spotify.GetStatus().Track.TrackResource.Uri);
                    if (!x.HasError())
                    {
                        t.Speak("This music was added to your playlist");
                    }
                    break;

                case "LISTEN":
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        if (by == "BY")
                        {
                            // I wanna listen {album} by {artist}
                            if (album != "EMP" && song == "EMP")
                            {
                                String query = album + "+" + artist;
                                item         = webSpotify.SearchItems(query, SearchType.Album);
                                if (item.Albums.Items.Count > 0)
                                {
                                    spotify.PlayURL(item.Albums.Items[0].Uri);
                                }
                                else
                                {
                                    t.Speak("There is no album from that artist");
                                }
                            }
                            // I wanna listen {song} by {artist}
                            else if (song != "EMP" && album == "EMP")
                            {
                                String query = song + "+" + artist;
                                item         = webSpotify.SearchItems(query, SearchType.Track);
                                if (item.Tracks.Items.Count > 0)
                                {
                                    spotify.PlayURL(item.Tracks.Items[0].Uri);
                                }
                                else
                                {
                                    t.Speak("There is no song with that name from that artist");
                                }
                            }
                            else
                            {
                                t.Speak("There is no album or song with that name from that artist");
                            }
                        }
                        else
                        {
                            // I wanna listen {artist} or {something} or {something I like}
                            if (artist != "EMP" && from == "EMP")
                            {
                                switch (artist)
                                {
                                case "LIKE":
                                    Paging <SimplePlaylist> playlists = webSpotify.GetUserPlaylists(userId: "4lzrg4ac5nyj1f5bosl1pse1i");
                                    int size = playlists.Items.Count;
                                    if (size == 0)
                                    {
                                        t.Speak("You don't have playlists.");
                                    }
                                    else
                                    {
                                        Random random           = new Random();
                                        int index               = random.Next(0, size);
                                        SimplePlaylist playlist = playlists.Items[index];
                                        if (playlist.Tracks.Total == 0 && size == 1)
                                        {
                                            t.Speak("Your playlist is empty.");
                                        }
                                        else
                                        {
                                            while (playlist.Tracks.Total == 0)
                                            {
                                                random   = new Random();
                                                index    = random.Next(0, size);
                                                playlist = playlists.Items[index];
                                            }
                                            spotify.PlayURL(playlists.Items[index].Uri);
                                        }
                                    }
                                    break;

                                case "SOMETHING":
                                    spotify.Play();
                                    break;

                                default:
                                    item = webSpotify.SearchItems(artist, SearchType.Artist);
                                    spotify.PlayURL(item.Artists.Items[0].Uri);
                                    break;
                                }
                            }
                            // I wanna listen {artist} from {year}
                            else if (artist != "EMP" && from != "EMP" && year != "EMP")
                            {
                                item = webSpotify.SearchItems(artist, SearchType.Artist | SearchType.Album);
                                if (item.Albums.Items.Count > 0)
                                {
                                    foreach (SimpleAlbum simple_album in item.Albums.Items)
                                    {
                                        String[] album_date = simple_album.ReleaseDate.Split('-');
                                        if (album_date[0] == year)
                                        {
                                            spotify.PlayURL(simple_album.Uri);
                                            return;
                                        }
                                    }
                                    t.Speak("There is no album from that artist on that year");
                                }
                                else
                                {
                                    t.Speak("There is no album from that artist on that year");
                                }
                            }
                            // I wanna listen {song}
                            else if (artist == "EMP" && genre == "EMP" && song != "EMP" && from == "EMP" && year == "EMP")
                            {
                                item = webSpotify.SearchItems(song, SearchType.Track);
                                if (item.Tracks.Items.Count > 0)
                                {
                                    spotify.PlayURL(item.Tracks.Items[0].Uri);
                                }
                                else
                                {
                                    t.Speak("There is no song with that name");
                                }
                            }
                            // I wanna listen {album}
                            else if (album != "EMP" && artist == "EMP" && genre == "EMP" && song == "EMP" && from == "EMP" && year == "EMP")
                            {
                                item = webSpotify.SearchItems(album, SearchType.Album);
                                if (item.Albums.Items.Count > 0)
                                {
                                    spotify.PlayURL(item.Albums.Items[0].Uri);
                                }
                                else
                                {
                                    t.Speak("There is no album with that name");
                                }
                            }
                            // I wanna listen {genre}
                            else if (artist == "EMP" && genre != "EMP" && song == "EMP" && album == "EMP" && from == "EMP" && year == "EMP")
                            {
                                item             = webSpotify.SearchItems(genre, SearchType.Album | SearchType.Track | SearchType.Playlist);
                                int results_size = item.Playlists.Items.Count;
                                if (results_size > 0)
                                {
                                    // Choose playlist randomly
                                    Random random = new Random();
                                    int index     = random.Next(0, results_size);
                                    spotify.PlayURL(item.Playlists.Items[index].Uri);
                                }
                                else
                                {
                                    t.Speak("There are no playlists with that genre");
                                }
                            }
                            else
                            {
                                t.Speak("I am very sorry but this command is not supported");
                            }
                        }
                    });
                    break;

                default:
                    t.Speak("I am very sorry but this command is not supported");
                    break;
                }
            }
        }
Exemplo n.º 20
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var doc = XDocument.Parse(e.Message);
            var com = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            //We always receive 3 arguments -> commandID - commandName - confidence
            string commandID = json["recognized"][0];
            var commandName = json["recognized"][1];
            var confidence = json["recognized"][2];

            
            switch (commandID)
            {
                case "0": //Close tab
                    tabs = driver.WindowHandles.ToList();
                    if (tabs.Count() > 1)
                    {
                        driver.Close();
                        driver.SwitchTo().Window(driver.WindowHandles.First());
                    }
                    break;

                case "1": //Historic
                    sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    sim.Keyboard.KeyPress(VirtualKeyCode.VK_H);
                    sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    driver.SwitchTo().Window(driver.WindowHandles.Last());
                    break;
                    
                case "2": //Maximize
                    driver.Manage().Window.Maximize();
                    break;

                case "3": //Minimize
                    driver.Manage().Window.Minimize();
                    break;

                case "4": //Open Tab
                    sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    sim.Keyboard.KeyPress(VirtualKeyCode.VK_T);
                    sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    driver.SwitchTo().Window(driver.WindowHandles.Last());
                    break;
                    
                case "5": //Scroll down
                    sim.Keyboard.KeyPress(VirtualKeyCode.NEXT);
                    break;

                case "6": //Scroll up
                    sim.Keyboard.KeyPress(VirtualKeyCode.PRIOR);
                    break;
                    
                case "7": //Zoom in
                    sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    sim.Keyboard.KeyPress(VirtualKeyCode.OEM_PLUS);
                    sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    
                    break;
                case "8": //Zoom out
                    sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    sim.Keyboard.KeyPress(VirtualKeyCode.OEM_MINUS);
                    sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    
                    break;
                case "9": //Próxima tab
                    sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    sim.Keyboard.KeyPress(VirtualKeyCode.TAB);
                    sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    //Console.WriteLine(tabs.ToString());
                    tabs = driver.WindowHandles.ToList();
                    int index2 = tabs.IndexOf(driver.CurrentWindowHandle);
                    if (index2 == tabs.Count() - 1)
                    {
                        driver.SwitchTo().Window(driver.WindowHandles.First());
                    }
                    else
                    {
                        driver.SwitchTo().Window(tabs[index2 + 1]);
                    }
                    break;

                case "10": //tab anterior
                    sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    sim.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
                    sim.Keyboard.KeyPress(VirtualKeyCode.TAB);
                    sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    sim.Keyboard.KeyUp(VirtualKeyCode.SHIFT);
                    tabs = driver.WindowHandles.ToList();
                    int index1 = tabs.IndexOf(driver.CurrentWindowHandle);
                    if (index1 == 0)
                    {
                        driver.SwitchTo().Window(driver.WindowHandles.Last());
                    }
                    else
                    {
                        driver.SwitchTo().Window(tabs[index1 - 1]);
                    }
                    break;

                case "11": //adicionar favoritos
                    sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                    sim.Keyboard.KeyPress(VirtualKeyCode.VK_D);
                    sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                    System.Threading.Thread.Sleep(100);
                    sim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
                    break;

            }

            /*
             
                -- visit favs
                case "favourites":
                sim.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
                sim.Keyboard.KeyDown(VirtualKeyCode.SHIFT);
                sim.Keyboard.KeyPress(VirtualKeyCode.VK_O);
                sim.Keyboard.KeyUp(VirtualKeyCode.CONTROL);
                sim.Keyboard.KeyUp(VirtualKeyCode.SHIFT);
                break;

             
             */


        }
        private async void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            //double confidence = Double.Parse((string)json.recognized[0].ToString());
            String command = (string)json.recognized[0].ToString();
            String movie   = (string)json.recognized[1].ToString();
            String number  = (string)json.recognized[2].ToString();
            String time    = (string)json.recognized[3].ToString();

            var info = await mpcHomeCinema.GetInfo();

            Console.WriteLine($"{info.FileName} is playing");
            Console.WriteLine($"{info.State} is its state");
            switch (command)
            {
            case "HELP":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    t.Speak("Hello. You can play or pause movie, change volume, mute or unmute, skip movie or play last one, skip or rewind given time stamp, or open new movie.");
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "PLAY":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.PlayAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "PAUSE":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.PauseAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "NEXT":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.NextAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "BACK":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.PrevAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "MOVEFWD":
                info = await mpcHomeCinema.GetInfo();

                if (movie == "EMP" && number != "EMP" && time != "EMP")
                {
                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        if (time == "HOUR")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours + int.Parse(number), info.Position.Minutes, info.Position.Seconds));
                        }
                        else if (time == "MINUTE")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours, info.Position.Minutes + int.Parse(number), info.Position.Seconds));
                        }
                        else if (time == "SECOND")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours, info.Position.Minutes, info.Position.Seconds + int.Parse(number)));
                        }
                    });
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "MOVEBWD":
                info = await mpcHomeCinema.GetInfo();

                if (movie == "EMP" && number != "EMP" && time != "EMP")
                {
                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        if (time == "HOUR")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours - int.Parse(number), info.Position.Minutes, info.Position.Seconds));
                        }
                        else if (time == "MINUTE")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours, info.Position.Minutes - int.Parse(number), info.Position.Seconds));
                        }
                        else if (time == "SECOND")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(info.Position.Hours, info.Position.Minutes, info.Position.Seconds - int.Parse(number)));
                        }
                    });
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "SETTIME":
                if (movie == "EMP" && number != "EMP" && time != "EMP")
                {
                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        if (time == "HOUR")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(int.Parse(number), 0, 0));
                        }
                        else if (time == "MINUTE")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(0, int.Parse(number), 0));
                        }
                        else if (time == "SECOND")
                        {
                            await mpcHomeCinema.SetPosition(new TimeSpan(0, 0, int.Parse(number)));
                        }
                    });
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "MUTE":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.MuteAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "UNMUTE":
                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    await mpcHomeCinema.UnMuteAsync();
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "SETVOL":
                if (number == "EMP" && time != "EMP" && movie != "EMP")
                {
                    t.Speak("This command is forbidden");
                }
                else
                {
                    info = await mpcHomeCinema.GetInfo();

                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        await mpcHomeCinema.SetVolumeLevel(int.Parse(number));
                    });
                }
                break;

            case "VUP":
                info = await mpcHomeCinema.GetInfo();

                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    if (info.VolumeLevel <= 80)
                    {
                        await mpcHomeCinema.SetVolumeLevel(info.VolumeLevel + 20);
                    }
                    else
                    {
                        t.Speak("You can only increase volume by 20 points with this command. If you want to do it with custom number of points, please use set volume command,");
                    }
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "VDOWN":
                info = await mpcHomeCinema.GetInfo();

                if (movie == "EMP" && number == "EMP" && time == "EMP")
                {
                    if (info.VolumeLevel >= 20)
                    {
                        await mpcHomeCinema.SetVolumeLevel(info.VolumeLevel - 20);
                    }
                    else
                    {
                        t.Speak("You can only decrease volume by 20 points with this command. If you want to do it with custom number of points, please use set volume command,");
                    }
                }
                else
                {
                    t.Speak("This command is forbidden");
                }
                break;

            case "OPENFILE":
                if (movie == "EMP" || number != "EMP" || time != "EMP")
                {
                    t.Speak("This command is forbidden");
                }
                else
                {
                    await App.Current.Dispatcher.Invoke(async() =>
                    {
                        switch (movie)
                        {
                        case "ANIMALS":
                            await mpcHomeCinema.OpenFileAsync("C:\\Users\\Public\\Videos\\SampleVideos\\Animals.wmv");
                            break;

                        case "ODYSSEY":
                            await mpcHomeCinema.OpenFileAsync("C:\\Users\\Public\\Videos\\SampleVideos\\2001_ A SPACE ODYSSEY - Trailer.mp4");
                            break;

                        case "BLUEPLANET":
                            await mpcHomeCinema.OpenFileAsync("C:\\Users\\Public\\Videos\\SampleVideos\\Blue Planet II  The Prequel.wmv");
                            break;

                        case "PLANETEARTH":
                            await mpcHomeCinema.OpenFileAsync("C:\\Users\\Public\\Videos\\SampleVideos\\Planet Earth II Official Extended Trailer  BBC Earth.wmv");
                            break;
                        }
                    });
                }
                break;
            }
        }
Exemplo n.º 22
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            Console.WriteLine(json);
            Console.WriteLine((string)json.recognized[0].ToString());
            Console.WriteLine((string)json.keys[0].ToString());

            Tts t = new Tts();

            //TODO: See where should have the method cleanAllConfirmations()
            //https://docs.microsoft.com/en-us/office/vba/api/powerpoint.slide
            switch ((string)json.keys[0].ToString())
            {
            //TODO: pôr tudo o que está para baixo aqui dentro
            case "openPowerPoint":
                oPowerPoint   = new PowerPoint.Application();
                oPresentation = oPowerPoint.Presentations.Add();
                break;

            case "slide":
                switch ((string)json.recognized[0].ToString())
                {
                case "NEXT_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Next();
                    break;

                case "PREVIOUS_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Previous();
                    break;

                case "NEXT":
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1].Select();
                    break;

                case "PREVIOUS":
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex - 1].Select();
                    break;

                case "JUMP_TO":
                    oPresentation.Slides[Int32.Parse(json.recognized[1].ToString())].Select();
                    break;

                case "JUMP_TO_SLIDE_PRESENTATION":
                    oPresentation.SlideShowWindow.View.GotoSlide(Int32.Parse(json.recognized[1].ToString()));
                    break;

                case "NEW_SLIDE":
                    if (oPresentation.Slides.Count == 0)
                    {
                        oPresentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitle).Select();
                    }
                    else
                    {
                        oPresentation.Slides.Add(oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1, PowerPoint.PpSlideLayout.ppLayoutTitle).Select();;
                    }
                    break;


                case "REMOVE_SLIDE":
                    if (oPresentation.Slides.Count > 0)
                    {
                        oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].Delete();
                        t.Speak("Slide removido!");
                    }
                    else
                    {
                        t.Speak("Não existe nenhum slide.");
                    }
                    break;
                }
                break;

            case "read":
                switch ((string)json.recognized[0].ToString())
                {
                case "TITLE":
                    var title = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].Shapes.Title.TextFrame.TextRange.Text;
                    t.Speak(title);
                    break;

                case "TEXT":
                    var text = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].Shapes[2].TextFrame.TextRange.Text;
                    t.Speak(text);
                    break;

                case "NOTE":
                    var notas = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].NotesPage.Shapes[2].TextFrame.TextRange.Text;
                    t.Speak(notas);
                    break;

                case "TITLE_PRESENTATION":
                    var title_pres = oPresentation.SlideShowWindow.View.Slide.Shapes.Title.TextFrame.TextRange.Text;
                    t.Speak(title_pres);
                    break;

                case "TEXT_PRESENTATION":
                    var text_pres = oPresentation.SlideShowWindow.View.Slide.Shapes[2].TextFrame.TextRange.Text;
                    t.Speak(text_pres);
                    break;

                case "NOTE_PRESENTATION":
                    var note_pres = oPresentation.SlideShowWindow.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text;
                    t.Speak(note_pres);
                    break;
                }
                break;



            case "theme":
                switch ((string)json.recognized[0].ToString())
                {
                case "1":

                    string dir = @"C:\Program Files (x86)\Microsoft Office\";
                    if (Directory.Exists(dir))
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Facet.thmx");
                    }
                    else
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Facet.thmx");
                    }


                    break;

                case "2":

                    string dir1 = @"C:\Program Files (x86)\Microsoft Office\";
                    if (Directory.Exists(dir1))
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Gallery.thmx");
                    }
                    else
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Gallery.thmx");
                    }
                    break;

                case "3":
                    string dir2 = @"C:\Program Files (x86)\Microsoft Office\";
                    if (Directory.Exists(dir2))
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Ion.thmx");
                    }
                    else
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Ion.thmx");
                    }
                    break;
                }
                break;

            case "save":
                oPresentation.Save();
                break;

            case "color":
                Slide     activeSlide = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];;
                TextRange textRange   = activeSlide.Shapes.Title.TextFrame.TextRange;;
                if (json.recognized.Count > 1)
                {
                    switch ((string)json.recognized[0].ToString())
                    {
                    /*case "TITLE":
                     *  activeSlide = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];
                     *  textRange = activeSlide.Shapes.Title.TextFrame.TextRange;
                     *  break;*/
                    case "TEXT":
                        activeSlide = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];
                        textRange   = activeSlide.Shapes[2].TextFrame.TextRange;
                        break;
                    }
                }
                switch ((string)json.recognized[1].ToString())
                {
                case "YELLOW":
                    textRange.Font.Color.RGB = 379903;
                    t.Speak("Mudado para Amarelo");
                    break;

                case "RED":
                    textRange.Font.Color.RGB = 255;
                    t.Speak("Mudado para Vermelho");
                    break;

                case "BLUE":
                    textRange.Font.Color.RGB = 16711680;
                    t.Speak("Mudado para Azul");
                    break;

                case "GREEN":
                    textRange.Font.Color.RGB = 2540123;
                    t.Speak("Mudado para Verde");
                    break;

                case "BLACK":
                    textRange.Font.Color.RGB = 0;
                    t.Speak("Mudado para Preto");
                    break;
                }
                break;

            case "example":
                String presentationTitle = "Proposta de Trabalho 2";

                //Save the file
                //oPresentation.SaveAs(presentationTitle, PowerPoint.PpSaveAsFileType.ppSaveAsPresentation);

                //Add a new slide with Title Layout
                oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutTitle);
                tShape = oSlide.Shapes.Title;
                tShape.TextFrame.TextRange.Text = presentationTitle;
                tShape = oSlide.Shapes[2];
                tShape.TextFrame.TextRange.Text = "Carlos Ribeiro\nGisela Pinto";

                oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
                tShape = oSlide.Shapes.Title;
                tShape.TextFrame.TextRange.Text = "Tema";
                tShape = oSlide.Shapes[2];
                tShape.TextFrame.TextRange.Text = "Interação por voz do Powerpoint";

                //Add Image
                //tShape = oSlide.Shapes.AddPicture("imagePowerPoint.png", Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0);

                oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
                tShape = oSlide.Shapes.Title;
                tShape.TextFrame.TextRange.Text = "Features para utilizar durante uma apresentação";
                tShape = oSlide.Shapes[2];
                tShape.TextFrame.TextRange.Text = "Avançar slide.\n" +
                                                  "Recuar slide.\n" +
                                                  "Saltar slides, por exemplo mudar do slide 2 para o 5.\n" +
                                                  "Ler texto de um slide.\n" +
                                                  "Ler notas de um slide fazendo assim a apresentação completa.\n" +
                                                  "Terminar a apresentação.\n" +
                                                  "Controlar um video que esteja integrado no slide(Iniciar/ parar).";

                oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Eu, Salvador, estou a ler notas do slide 3, beijinhos e abraços";

                //oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);

                //tShape = oSlide.Shapes.AddMediaObject2(@"C:\Users\Gisela Pinto\Documents\IM\Trabalho1\im_2019_2020\Basis4Assignment2\ppt.mp4", MsoTriState.msoTrue, MsoTriState.msoTrue, 8, 8, 530, 530);

                oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
                tShape = oSlide.Shapes.Title;
                tShape.TextFrame.TextRange.Text = "Features para construção de uma apresentação";
                tShape = oSlide.Shapes[2];
                tShape.TextFrame.TextRange.Text = "Iniciar a criação da apresentação com um dos temas sugeridos.\n" +
                                                  "Acrescentar um novo slide em branco/ duplicado.\n" +
                                                  "Remover determinado slide.\n" +
                                                  "Escrever o que o utilizador ditar.\n" +
                                                  "Guardar alterações.\n" +
                                                  "Mudar cor do texto(algumas cores mais usadas).";
                oPresentation.Slides[oSlide.SlideIndex].Select();
                break;

            case "presentation":
                switch ((string)json.recognized[0].ToString())
                {
                case "START":
                    oPresentation.SlideShowSettings.Run();
                    break;

                case "STOP_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Exit();
                    break;
                }
                break;

            case "close":
                oPowerPoint.Quit();
                System.Diagnostics.Process[] pros = System.Diagnostics.Process.GetProcesses();
                for (int i = 0; i < pros.Count(); i++)
                {
                    if (pros[i].ProcessName.ToLower().Contains("powerpnt"))
                    {
                        pros[i].Kill();
                    }
                }
                break;
            }

            /*
             *
             *
             * //Edition
             *
             *
             *          case "COLOR_TITLE":
             *              var activeSlide = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];
             *              rangeTitle = activeSlide.Shapes.Title.TextFrame.TextRange;
             *              if (json.recognized.Count > 1) {
             *                  switch ((string)json.recognized[1].ToString()) {
             *                      case "YELLOW":
             *                          rangeTitle.Font.Color.RGB = 379903;
             *                          t.Speak("Mudado para Amarelo");
             *                          break;
             *                      case "RED":
             *                          rangeTitle.Font.Color.RGB = 255;
             *                          t.Speak("Mudado para Vermelho");
             *                          break;
             *                      case "BLUE":
             *                          rangeTitle.Font.Color.RGB = 16711680;
             *                          t.Speak("Mudado para Azul");
             *                          break;
             *                      case "GREEN":
             *                          rangeTitle.Font.Color.RGB = 2540123;
             *                          t.Speak("Mudado para Verde");
             *                          break;
             *                      case "BLACK":
             *                          rangeTitle.Font.Color.RGB = 0;
             *                          t.Speak("Mudado para Preto");
             *                          break;
             *                  }
             *              }else {
             *                  t.Speak("Deseja mudar para que cor?");
             *                  selectColorTitle = true;
             *              }
             *              break;
             *
             *          case "COLOR_TEXT":
             *              t.Speak("Deseja mudar para que cor?");
             *              var activeSlide2 = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];
             *              rangeShape = activeSlide2.Shapes[2].TextFrame.TextRange;
             *              if (json.recognized.Count > 1) {
             *                  switch ((string)json.recognized[1].ToString()) {
             *                      case "YELLOW":
             *                          rangeTitle.Font.Color.RGB = 379903;
             *                          t.Speak("Mudado para Amarelo");
             *                          break;
             *                      case "RED":
             *                          rangeTitle.Font.Color.RGB = 255;
             *                          t.Speak("Mudado para Vermelho");
             *                          break;
             *                      case "BLUE":
             *                          rangeTitle.Font.Color.RGB = 16711680;
             *                          t.Speak("Mudado para Azul");
             *                          break;
             *                      case "GREEN":
             *                          rangeTitle.Font.Color.RGB = 2540123;
             *                          t.Speak("Mudado para Verde");
             *                          break;
             *                      case "BLACK":
             *                          rangeTitle.Font.Color.RGB = 0;
             *                          t.Speak("Mudado para Preto");
             *                          break;
             *                  }
             *              } else {
             *                  t.Speak("Deseja mudar para que cor?");
             *                  selectColorText = true;
             *              }
             *              break;
             *
             *          case "YELLOW":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 379903;
             *                  t.Speak("Mudado para Amarelo");
             *              } else if (selectColorText == true) {
             *                  selectColorText = false;
             *                  rangeShape.Font.Color.RGB = 379903;
             *                  t.Speak("Mudado para Amarelo");
             *              } else {
             *                  t.Speak("Devo ter percebido mal.");
             *
             *              }
             *              break;
             *
             *          case "RED":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 255;
             *                  t.Speak("Mudado para Vermelho");
             *              } else if (selectColorText == true) {
             *                  selectColorText = false;
             *                  rangeShape.Font.Color.RGB = 255;
             *                  t.Speak("Mudado para Vermelho");
             *              } else {
             *                  t.Speak("Devo ter percebido mal.");
             *              }
             *              break;
             *
             *          case "BLUE":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 16711680;
             *                  t.Speak("Mudado para Azul");
             *              } else if (selectColorText == true) {
             *                  selectColorText = false;
             *                  rangeShape.Font.Color.RGB = 16711680;
             *                  t.Speak("Mudado para Azul");
             *              } else {
             *
             *                  t.Speak("Devo ter percebido mal.");
             *
             *              }
             *              break;
             *
             *          case "GREEN":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 2540123;
             *                  t.Speak("Mudado para Verde");
             *              } else if (selectColorText == true) {
             *                  selectColorText = false;
             *                  rangeShape.Font.Color.RGB = 2540123;
             *                  t.Speak("Mudado para Verde");
             *              } else {
             *                  t.Speak("Devo ter percebido mal.");
             *              }
             *              break;
             *
             *          case "BLACK":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 0;
             *                  t.Speak("Mudado para Preto");
             *              } else if (selectColorText == true) {
             *                  selectColorTitle = false;
             *                  rangeShape.Font.Color.RGB = 0;
             *                  t.Speak("Mudado para Preto");
             *              } else {
             *                  t.Speak("Devo ter percebido mal.");
             *              }
             *              break;
             *
             */
        }
Exemplo n.º 23
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            var     doc  = XDocument.Parse(e.Message);
            dynamic json = null;

            try
            {
                var com = doc.Descendants("command").FirstOrDefault().Value;
                json = JsonConvert.DeserializeObject(com);
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine(ex.ToString());
            }

            string command = null;

            if (json != null)
            {
                command = json.recognized[1].ToString();
                Console.WriteLine(command);
                Console.WriteLine("Received Command: " + command + "\n");
            }
            else
            {
                Console.WriteLine("Invalid command input!\n");
            }

            int           volume           = 50;
            List <String> tmp_playlist_IDs = this.web_worker.GetMyPlayListsUris();
            Dictionary <String, String> tmp_playlist_Dict = this.web_worker.GetMyPlayListDictionary();

            switch (command)
            {
            case "REPRODUZIR_MUSICA":
                if (!this.local_worker.IsPlayingSong())
                {
                    this.local_worker.PlayTrack();
                }
                else
                {
                    tts.Speak("A música já esta a ser reproduzida!");
                }
                break;

            case "PARAR_MUSICA":
                if (this.local_worker.IsPlayingSong())
                {
                    this.local_worker.PauseTrack();
                }
                else
                {
                    tts.Speak("Não é possível parar a música!");
                }
                break;

            case "AVANÇAR_MUSICA":
                this.local_worker.NextTrack();
                //tts.Speak("Avançando esta música!");
                break;

            case "RETROCEDER_MUSICA":
                this.local_worker.PreviousTrack();
                //tts.Speak("Voltando à música anterior!");
                break;

            case "AUMENTAR_VOLUME":
                volume  = (int)this.local_worker.GetVolume();
                volume += 10;
                if (volume <= 100)
                {
                    Console.WriteLine("Volume Actual: " + volume + "\n");
                    this.local_worker.SetVolume(volume);
                }
                else
                {
                    Console.WriteLine("Volume Actual: " + volume + "\n");
                    tts.Speak("O volume já se encontra no máximo!");
                }
                break;

            case "BAIXAR_VOLUME":
                volume  = (int)this.local_worker.GetVolume();
                volume -= 10;
                if (volume >= 0)
                {
                    Console.WriteLine("Volume Actual: " + volume + "\n");
                    this.local_worker.SetVolume(volume);
                }
                else
                {
                    Console.WriteLine("Volume Actual: " + volume + "\n");
                    tts.Speak("O volume já se encontra no mínimo!");
                }
                break;

            case "RETIRAR_VOLUME":
                if (!this.local_worker.MutedSpotify())
                {
                    this.local_worker.MuteVolume();
                }
                else
                {
                    tts.Speak("O volume já se encontra sem som!");
                }
                break;

            case "REPOR_VOLUME":
                if (this.local_worker.MutedSpotify())
                {
                    this.local_worker.UnMuteVolume();
                }
                else
                {
                    tts.Speak("O volume já foi reposto!");
                }
                break;

            case "METER_VOLUME":
                dynamic json_msg = null;
                try
                {
                    var command_msg = doc.Descendants("command").LastOrDefault().Value;
                    json_msg = JsonConvert.DeserializeObject(command_msg);
                }
                catch (NullReferenceException ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                volume = json_msg.volume;
                Console.WriteLine("Volume: " + volume);
                this.local_worker.SetVolume(volume);
                break;

            case "MUSICA_NOME":
                Console.WriteLine("O nome da música é : " + this.local_worker.GetSongTrack());
                tts.Speak("O nome da música é " + this.local_worker.GetSongTrack());
                break;

            case "MUSICA_ARTISTA":
                Console.WriteLine("O artista da música é : " + this.local_worker.GetSongArtist());
                tts.Speak("O artista da música é " + this.local_worker.GetSongArtist());
                break;

            case "MUSICA_ACTUAL":
                Console.WriteLine("A música actual é : " + this.local_worker.GetPlayingSong());
                tts.Speak("A música actual é " + this.local_worker.GetPlayingSong());
                break;

            case "REPETIR_MUSICA":
                if (!this.local_worker.RepeatStatus())
                {
                    this.local_worker.RepeatTrack();
                    tts.Speak("Repetir música activado!");
                }
                else
                {
                    this.local_worker.UnRepeatTrack();
                    tts.Speak("Repetir música desactivado!");
                }
                break;

            case "REPRODUZIR_PLAYLISTS":
                if (tmp_playlist_IDs.Count != 0)
                {
                    this.local_worker.PlayMyPlayListByID(tmp_playlist_IDs.ElementAt(0));
                }
                else
                {
                    tts.Speak("Não existem playlists para reproduzir!");
                }
                break;

            case "AVANÇAR_PLAYLIST":
                if (tmp_playlist_IDs.Count != 0)
                {
                    this.local_worker.PlayMyPlayListByID(tmp_playlist_IDs.ElementAt(this.web_worker.GetTargetPlayList("NextTrack")));
                }
                else
                {
                    tts.Speak("Não existem playlists para avançar!");
                }
                break;

            case "RETROCEDER_PLAYLIST":
                if (tmp_playlist_IDs.Count != 0)
                {
                    this.local_worker.PlayMyPlayListByID(tmp_playlist_IDs.ElementAt(this.web_worker.GetTargetPlayList("PreviousTrack")));
                }
                else
                {
                    tts.Speak("Não existem playlists para retroceder!");
                }
                break;

            case "MUSICAS_SEMELHANTES":
                string artist_ID = this.web_worker.GetRelatedArtistByID(this.local_worker.getCurrentPlayArtistID());
                if (artist_ID == null)
                {
                    artist_ID = this.web_worker.GetRelatedArtistByID(this.local_worker.getPlayingContentID("Artist"));
                }
                Console.WriteLine("Similar Artist ID: " + artist_ID + "\n");
                this.local_worker.PlayMyArtistByID(artist_ID);
                break;

            case "INFO_MUSICA_ACTUAL":
                string music_info = this.local_worker.getSongTrackInfo();
                tts.Speak("Você está a ouvir " + music_info);
                break;

            case "OUVIR_XUTOS_E_PONTAPÉS":
                Console.WriteLine("A ouvir Xutos e Pontapés.\n");
                this.local_worker.PlayMyArtistByID(this.xutos_ID);
                //tts.Speak("Você está a ouvir Xutos e Pontapés!");
                break;

            case "OUVIR_JOAO_PEDRO_PAIS":
                Console.WriteLine("A ouvir João Pedro Pais...\n");
                this.local_worker.PlayMyArtistByID(this.joaopedropais_ID);
                //tts.Speak("Você está a ouvir João Pedro Pais!");
                break;

            case "OUVIR_GNR":
                Console.WriteLine("A ouvir GNR...\n");
                this.local_worker.PlayMyArtistByID(this.GNR_ID);
                //tts.Speak("Você está a ouvir João Pedro Pais!");
                break;

            case "OUVIR_NOVIDADES":
                Console.WriteLine("A ouvir Novidades...\n");
                String featured_playlist = this.web_worker.GetFeaturedPlayLists();
                this.local_worker.PlayFeaturedPlayListByID(featured_playlist);
                break;

            case "OUVIR_PLAYLISTS":
                List <SimplePlaylist> playlists      = this.web_worker.GetMyPlayLists();
                List <string>         name_playlists = new List <string>();
                playlists.ForEach(playlist => name_playlists.Add(playlist.Name));
                this.local_worker.getMyPlayLists(name_playlists);
                break;

            case "MUDAR_VOZ_MASCULINA":
                tts.ChangeGenderVoice(Microsoft.Speech.Synthesis.VoiceGender.Male);
                tts.Speak("Voz masculina");
                break;

            case "MUDAR_VOZ_FEMININA":
                tts.ChangeGenderVoice(Microsoft.Speech.Synthesis.VoiceGender.Female);
                tts.Speak("Voz feminina");
                break;

            default:
                Console.WriteLine("Invalid message command input! Try again\n");
                break;
            }

            //switch (command)
            //{
            //    case "menuprincipal":
            //        worker.goToHomeFolder();
            //        break;
            //    case "pesquisar":
            //        worker.search(json.Musica.ToString());
            //        break;

            //    case "navegar":
            //        switch (json.EscolherNavegaçao.ToString())
            //        {
            //            case "relevantes":
            //                worker.browseFeatured();
            //                break;
            //            case "podcast":
            //                worker.browsePodcasts();
            //                break;
            //            case "cartas":
            //                worker.browseCharts();
            //                break;
            //            case "genero":
            //                worker.browseGenreMoods();
            //                break;
            //            case "novo":
            //                worker.browseNewReleases();
            //                break;
            //            case "descoberta":
            //                worker.browseDiscover();
            //                break;
            //        }
            //        break;

            //    case "biblioteca":
            //        worker.goToLibrary();
            //        break;

            //    case "mostrar":
            //        switch (json.EscolherTema.ToString())
            //        {
            //            case "playlists":
            //                worker.showPlaylists();
            //                break;

            //            case "feitasparamim":
            //                worker.showMadeForYou();
            //                break;

            //            case "músicas":
            //                worker.showSongs();
            //                break;

            //            case "albuns":
            //                worker.showAlbuns();
            //                break;

            //            case "artistas":
            //                worker.showArtists();
            //                break;

            //            case "podcasts":
            //                worker.showPodcasts();
            //                break;
            //        }
            //        break;

            //    case "criar":
            //        switch (json.EscolherObjecto.ToString())
            //        {
            //            case "playlists":
            //                worker.createPlayList(json.EscolherPlaylist.ToString());
            //                break;
            //        }
            //        break;
            //}

            //Dynamic Playlists command
            try
            {
                this.local_worker.PlayMyPlayListByID(tmp_playlist_Dict[command]);
            }
            catch (KeyNotFoundException ex)
            {
                Console.WriteLine("Key not found exception!");
            }
        }
Exemplo n.º 24
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            switch ((string)json.recognized[0].ToString())
            {
            case "FIND_IN_PAGE":
                lastCall = "FIND_IN_PAGE";
                SearchTextInPage((string)json.recognized[1].ToString());
                break;

            case "SYNONYMS":
                lastCall = "SYNONYMS";
                searchSynonyms((string)json.recognized[1].ToString());
                break;

            case "SEARCH_QUERY":
                lastCall = "SEARCH_QUERY";
                Search((string)json.recognized[1].ToString() + " " + (string)json.recognized[2].ToString() + " " + (string)json.recognized[3].ToString());
                break;

            case "MINIMIZE":
                lastCall = "MINIMIZE";
                Minimize();
                break;

            case "MAXIMIZE":
                lastCall = "MAXIMIZE";
                Maximize();
                break;

            case "BACK":
                lastCall = "BACK";
                GoBack();
                break;

            case "FORWARD":
                lastCall = "FORWARD";
                GoForward();
                break;

            case "QUIT_CHROME":
                lastCall = "QUIT_CHROME";
                QuitChrome();
                break;

            case "CLOSE_TAB":
                lastCall = "CLOSE_TAB";
                CloseTab();
                break;

            case "REFRESH":
                lastCall = "REFRESH";
                Refresh();
                break;

            case "ZOOM_IN":
                lastCall = "ZOOM_IN";
                break;

            case "ZOOM_OUT":
                lastCall = "ZOOM_OUT";
                break;

            case "SCROLL_UP":
                lastCall = "SCROLL_UP";
                break;

            case "SCROLL_DOWN":
                lastCall = "SCROLL_DOWN";
                break;

            case "OPEN_SETTINGS":
                lastCall = "OPEN_SETTINGS";
                OpenSettings();
                break;

            case "OPEN_DOWNLOADS":
                lastCall = "OPEN_DOWNLOADS";
                OpenDownloads();
                break;

            case "OPEN_TAB":
                lastCall = "OPEN_TAB";
                NewTab(TabName(), defaultUrl);
                break;

            case "OPEN_INCOGNITO":
                lastCall = "OPEN_INCOGNITO";
                OpenIncognitoTab();
                break;

            case "A_BIT":
                if (lastCall == "ZOOM_IN")
                {
                    ZoomIn(2);
                }
                if (lastCall == "ZOOM_OUT")
                {
                    ZoomOut(2);
                }
                if (lastCall == "SCROLL_UP")
                {
                    ScrollUp(200);
                }
                if (lastCall == "SCROLL_DOWN")
                {
                    ScrollDown(200);
                }
                break;

            case "A_LOT":
                if (lastCall == "ZOOM_IN")
                {
                    ZoomIn(10);
                }
                if (lastCall == "ZOOM_OUT")
                {
                    ZoomOut(10);
                }
                if (lastCall == "SCROLL_UP")
                {
                    ScrollUp(400);
                }
                if (lastCall == "SCROLL_DOWN")
                {
                    ScrollDown(400);
                }
                break;
            }
        }
Exemplo n.º 25
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            Console.WriteLine(json.recognized);
            switch ((string)json.recognized[1].ToString())
            {
            case "muteR":
                _client.SendMessageAsync("!MUTEALL");
                t.Speak("Todos os utilizadores levaram mute.");
                break;

            case "unmuteR":
                _client.SendMessageAsync("!UNMUTEALL");
                t.Speak("Todos os utilizadores levaram unmute.");
                break;

            case "leave":
                _client.SendMessageAsync("!MOVEAFKALL");
                t.Speak("Todos os utilizadores foram retirados da sala.");
                break;

            case "invite":
                _client.SendMessageAsync("!UNMOVEAFKALL");
                t.Speak("Todos os utilizadores foram repostos na sala.");
                break;

            case "bola":
                string          url    = "http://feeds.ojogo.pt/OJ-Futebol";
                XmlReader       reader = XmlReader.Create(url);
                SyndicationFeed feed   = SyndicationFeed.Load(reader);
                reader.Close();
                String subject = "";
                int    i       = 0;
                foreach (SyndicationItem item in feed.Items)
                {
                    subject += item.Title.Text + ".\n";
                    i++;
                    if (i == 5)
                    {
                        break;
                    }
                }
                t.Speak(subject);
                break;

            case "tempo":
                string URL = "http://api.openweathermap.org/data/2.5/weather?q=Aveiro&APPID=6fcebaa15d35d3672004b399373a1279&units=metric";
                Console.WriteLine(URL);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                request.Method      = "GET";
                request.ContentType = "application/json";

                try
                {
                    String      temperatura = "";
                    String      info        = "";
                    WebResponse webResponse = request.GetResponse();
                    using (Stream webStream = webResponse.GetResponseStream() ?? Stream.Null)
                        using (StreamReader responseReader = new StreamReader(webStream))
                        {
                            string  response = responseReader.ReadToEnd();
                            dynamic tojson2  = JsonConvert.DeserializeObject(response);

                            Console.Out.WriteLine((string)tojson2.main.temp.ToString());
                            temperatura = (string)tojson2.main.temp.ToString();
                            info        = translate((string)tojson2.weather[0].description.ToString());
                        }

                    t.Speak("Meteorologia em Aveiro.\n" + info + ".\n " + temperatura + " graus Celcius.");
                }
                catch (Exception es)
                {
                    Console.Out.WriteLine("-----------------");
                    Console.Out.WriteLine(es.Message);
                    t.Speak("Algo de errado aconteceu");
                }
                break;
            }
        }
Exemplo n.º 26
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            //json.recognized
            Console.WriteLine(json);
            Console.WriteLine("0: ");
            Console.WriteLine(json.recognized[0].ToString());
            Console.WriteLine("1: ");
            Console.WriteLine(json.recognized[1].ToString());



            //TODO: See where should have the method cleanAllConfirmations()
            //https://docs.microsoft.com/en-us/office/vba/api/powerpoint.slide
            switch ((string)json.recognized[0].ToString())
            {
            //TODO: pôr tudo o que está para baixo aqui dentro
            case "openPowerPoint":

                oPowerPoint   = new PowerPoint.Application();
                oPresentation = oPowerPoint.Presentations.Add();
                examplePresentation();
                openpowerpoint   = true;
                presentationMode = false;
                break;

            case "slide":
                switch ((string)json.recognized[1].ToString())
                {
                case "NEXT":
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1].Select();
                    break;

                case "NEXT_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Next();
                    break;

                case "PREVIOUS":
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex - 1].Select();
                    break;

                case "PREVIOUS_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Previous();
                    break;

                case "JUMP_TO":
                    oPresentation.Slides[Int32.Parse(json.recognized[3].ToString())].Select();
                    break;

                case "JUMP_TO_SLIDE_PRESENTATION":
                    oPresentation.SlideShowWindow.View.GotoSlide(Int32.Parse(json.recognized[3].ToString()));
                    break;
                }
                break;

            case "read":
                switch ((string)json.recognized[1].ToString())
                {
                case "TITLE":
                    var title = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].Shapes.Title.TextFrame.TextRange.Text;
                    SendMsg_Tts(title, "speak");
                    break;

                case "TEXT":
                    var text = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].Shapes[2].TextFrame.TextRange.Text;
                    SendMsg_Tts(text, "speak");
                    break;

                case "NOTE":
                    var notas = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].NotesPage.Shapes[2].TextFrame.TextRange.Text;
                    SendMsg_Tts(notas, "speak");
                    break;

                case "TITLE_PRESENTATION":
                    var title_pres = oPresentation.SlideShowWindow.View.Slide.Shapes.Title.TextFrame.TextRange.Text;
                    SendMsg_Tts(title_pres, "speak");
                    break;

                case "TEXT_PRESENTATION":
                    var text_pres = oPresentation.SlideShowWindow.View.Slide.Shapes[2].TextFrame.TextRange.Text;
                    SendMsg_Tts(text_pres, "speak");
                    break;

                case "NOTE_PRESENTATION":
                    var note_pres = oPresentation.SlideShowWindow.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text;
                    SendMsg_Tts(note_pres, "speak");
                    break;
                }
                break;

            case "1":
                switch ((string)json.recognized[1].ToString())
                {
                case "CropI":
                    Console.WriteLine("DO CROP IN!");
                    SendMsg_Tts("Crop In encontra-se ativo.", "speak");
                    tShape.PictureFormat.CropLeft   = imgWidth * 20 / 100;
                    tShape.PictureFormat.CropRight  = imgWidth * 20 / 100;
                    tShape.PictureFormat.CropBottom = imgHeight * 20 / 100;
                    tShape.PictureFormat.CropTop    = imgHeight * 20 / 100;

                    break;
                }
                break;

            case "2":
                switch ((string)json.recognized[1].ToString())
                {
                case "CropO":
                    Console.WriteLine("DO CROP OUT!");
                    //crop Picture
                    SendMsg_Tts("Crop Out encontra-se ativo.", "speak");
                    tShape.PictureFormat.CropLeft   = imgWidth * (20 / 100);
                    tShape.PictureFormat.CropRight  = imgWidth * (20 / 100);
                    tShape.PictureFormat.CropBottom = imgHeight * (20 / 100);
                    tShape.PictureFormat.CropTop    = imgHeight * (20 / 100);

                    break;
                }
                break;

            case "3":
                switch ((string)json.recognized[1].ToString())
                {
                case "NextR":
                    if (presentationMode == true)
                    {
                        oPresentation.SlideShowWindow.View.Next();
                    }
                    else
                    {
                        oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1].Select();
                    }
                    break;
                }
                break;

            case "5":
                switch ((string)json.recognized[1].ToString())
                {
                case "PreviouL":
                    Console.WriteLine("DO PREVIOUS!");
                    if (presentationMode == true)
                    {
                        oPresentation.SlideShowWindow.View.Previous();
                    }
                    else
                    {
                        oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex - 1].Select();
                    }
                    break;
                }
                break;

            case "6":
                switch ((string)json.recognized[1].ToString())
                {
                case "ThemaR":
                    switch ((string)json.recognized[3].ToString())
                    {
                    case "1":
                        SendMsg_Tts("Tema 1 encontra-se ativo.", "speak");

                        string dir = @"C:\Program Files (x86)\Microsoft Office\";
                        if (Directory.Exists(dir))
                        {
                            oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Facet.thmx");
                        }
                        else
                        {
                            oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Facet.thmx");
                        }


                        break;

                    case "2":
                        SendMsg_Tts("Tema 2 encontra-se ativo.", "speak");

                        string dir1 = @"C:\Program Files (x86)\Microsoft Office\";
                        if (Directory.Exists(dir1))
                        {
                            oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Gallery.thmx");
                        }
                        else
                        {
                            oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Gallery.thmx");
                        }
                        break;

                    case "3":
                        SendMsg_Tts("Tema 3 encontra-se ativo.", "speak");

                        string dir2 = @"C:\Program Files (x86)\Microsoft Office\";
                        if (Directory.Exists(dir2))
                        {
                            oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Ion.thmx");
                        }
                        else
                        {
                            oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Ion.thmx");
                        }
                        break;
                    }
                    break;
                }
                break;

            case "7":
                switch ((string)json.recognized[1].ToString())
                {
                case "ZoomI":
                    Console.WriteLine("DO ZOOM IN!");
                    SendMsg_Tts("O modo Zoom In encontra-se ativo.", "speak");
                    tShape.ScaleHeight(1.2f, Microsoft.Office.Core.MsoTriState.msoFalse);
                    tShape.ScaleWidth(1.2f, Microsoft.Office.Core.MsoTriState.msoFalse);


                    break;
                }
                break;


            case "8":
                switch ((string)json.recognized[1].ToString())
                {
                case "ZoomO":
                    SendMsg_Tts("O modo Zoom Out encontra-se ativo.", "speak");
                    Console.WriteLine("DO ZOOM OUT!");
                    tShape.ScaleHeight(0.8f, Microsoft.Office.Core.MsoTriState.msoFalse);
                    tShape.ScaleWidth(0.8f, Microsoft.Office.Core.MsoTriState.msoFalse);

                    break;
                }
                break;


            case "4":
                switch ((string)json.recognized[1].ToString())
                {
                case "Open":

                    Console.WriteLine("OPEN Presentation Mode!");
                    oPresentation.SlideShowSettings.Run();
                    presentationMode = true;
                    SendMsg_Tts("open presentation grammer", "presentation");
                    SendMsg_Tts("O modo apresentação encontra-se ativo.", "speak");
                    break;
                }
                break;

            case "0":
                switch ((string)json.recognized[1].ToString())
                {
                case "Close":
                    Console.WriteLine("DO CLOSE!");
                    oPresentation.SlideShowWindow.View.Exit();
                    presentationMode = false;
                    SendMsg_Tts("change to edition grammer", "stop_presentation");
                    SendMsg_Tts("O modo apresentação foi desativado.", "speak");
                    break;
                }
                break;

            case "presentation":
                switch ((string)json.recognized[0].ToString())
                {
                case "START":
                    SendMsg_Tts("O modo apresentação foi ativado.", "speak");
                    oPresentation.SlideShowSettings.Run();
                    break;

                case "STOP_PRESENTATION":
                    SendMsg_Tts("O modo apresentação foi ativado.", "speak");
                    oPresentation.SlideShowWindow.View.Exit();
                    break;
                }
                break;


            case "close":
                oPowerPoint.Quit();
                System.Diagnostics.Process[] pros = System.Diagnostics.Process.GetProcesses();
                for (int i = 0; i < pros.Count(); i++)
                {
                    if (pros[i].ProcessName.ToLower().Contains("powerpnt"))
                    {
                        pros[i].Kill();
                    }
                }
                presentationMode = false;
                SendMsg_Tts("Power Point foi fechado", "speak");

                break;
            }
        }
Exemplo n.º 27
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            Console.WriteLine(json);
            Console.WriteLine("Recognize: " + (string)json.recognized[1].ToString());
            Console.WriteLine("OPEN Power Point!");


            switch ((string)json.recognized[1].ToString())
            {
            case "CropI":
                Console.WriteLine("DO CROP IN!");

                tShape.PictureFormat.CropLeft   = imgWidth * 20 / 100;
                tShape.PictureFormat.CropRight  = imgWidth * 20 / 100;
                tShape.PictureFormat.CropBottom = imgHeight * 20 / 100;
                tShape.PictureFormat.CropTop    = imgHeight * 20 / 100;

                break;

            case "CropO":
                Console.WriteLine("DO CROP OUT!");
                //crop Picture

                tShape.PictureFormat.CropLeft   = imgWidth * (20 / 100);
                tShape.PictureFormat.CropRight  = imgWidth * (20 / 100);
                tShape.PictureFormat.CropBottom = imgHeight * (20 / 100);
                tShape.PictureFormat.CropTop    = imgHeight * (20 / 100);
                break;

            case "ZoomI":
                Console.WriteLine("DO ZOOM IN!");

                tShape.ScaleHeight(1.2f, Microsoft.Office.Core.MsoTriState.msoFalse);
                tShape.ScaleWidth(1.2f, Microsoft.Office.Core.MsoTriState.msoFalse);


                break;

            case "ZoomO":
                Console.WriteLine("DO ZOOM OUT!");
                tShape.ScaleHeight(0.8f, Microsoft.Office.Core.MsoTriState.msoFalse);
                tShape.ScaleWidth(0.8f, Microsoft.Office.Core.MsoTriState.msoFalse);

                break;

            case "ThemaR":
                Console.WriteLine("DO ADD THEME!");
                string dir = @"C:\Program Files (x86)\Microsoft Office\";
                if (Directory.Exists(dir))
                {
                    oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Facet.thmx");
                }
                else
                {
                    oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Facet.thmx");
                }
                break;

            case "Open":
                Console.WriteLine("OPEN Presentation Mode!");
                oPresentation.SlideShowSettings.Run();
                presentationMode = true;
                break;

            case "PreviouL":
                Console.WriteLine("DO PREVIOUS!");

                if (presentationMode == true)
                {
                    oPresentation.SlideShowWindow.View.Previous();
                }
                else
                {
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex - 1].Select();
                }
                break;

            case "NextR":
                Console.WriteLine("DO NEXT!");

                if (presentationMode == true)
                {
                    oPresentation.SlideShowWindow.View.Next();
                }
                else
                {
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1].Select();
                }

                break;

            case "Close":
                Console.WriteLine("DO CLOSE!");
                oPresentation.SlideShowWindow.View.Exit();
                presentationMode = false;
                break;
            }
        }
Exemplo n.º 28
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            InputSimulator inputsim = new InputSimulator();

            double confidence = Double.Parse((string)json.recognized[0].ToString());

            String command = (string)json.recognized[1].ToString();

            String command2 = (string)json.recognized[2].ToString();

            String details = (string)json.recognized[3].ToString();

            String weapon = (string)json.recognized[4].ToString();


            if (t.getSpeech() == true)
            {
                return;
            }

            if (confidence < 0.3)
            {
                t.Speak("Desculpe, pode repetir?");
            }

            else
            {
                textbox_output_mmi.Text = " " + command + " " + command2 + " " + details + " " + weapon + " ";

                switch (command)
                {
                // SPEECH
                // QUANTOS/QUANTAS
                case "HOWMANY":
                    switch (command2)
                    {
                    // RONDAS
                    case "ROUNDS":
                    {
                        switch (details)
                        {
                        // FALTAM PARA O FIM DO JOGO
                        case "LEFT":
                        {
                            // GET ROUNDS LEFT UNTIL END OF GAME

                            t.Speak("Faltam " + (30 - gamestate.round_number) + " rondas");
                            break;
                        }

                        // FALTAM PARA O INTERVALO
                        case "LEFT_HALF":
                        {
                            // GET ROUNDS LEFT UNTIL HALFTIME
                            if (gamestate.round_number >= 15)
                            {
                                t.Speak(" Já estás na segunda parte do jogo!");
                            }
                            else if (gamestate.round_number == 0)
                            {
                                t.Speak(" O jogo ainda não começou!");
                            }
                            else
                            {
                                t.Speak("Faltam " + (15 - gamestate.round_number) + " rondas para o intervalo");
                            }
                            break;
                        }
                        }
                        break;
                    }

                    // BALAS TENHO
                    case "BULLETS":
                    {
                        t.Speak(" Tens " + gamestate.bullets + " balas restantes");
                        if (gamestate.bullets <= (0.1 * gamestate.max_bullets))
                        {
                            t.Speak(" Aconselho-te a recarregar.");
                        }
                        break;
                    }

                    // MORTES NUMA RONDA
                    case "KILLS":
                    {
                        switch (details)
                        {
                        case "HAVE_ROUND":
                        {
                            t.Speak("Mataste " + gamestate.roundkills + " nesta ronda");
                            break;
                        }

                        case "HAVE":
                        {
                            t.Speak("Tens um total de " + gamestate.total_kills + " mortes");
                            break;
                        }
                        }

                        break;
                    }

                    // TOTAL DE OBITOS
                    case "DEATHS":
                    {
                        t.Speak("Morreste " + gamestate.total_deaths);
                        break;
                    }

                    // ESPETADORES
                    case "SPECTATORES":
                    {
                        t.Speak("Temos no total " + gamestate.spectators + "espetadores");
                        break;
                    }
                    }
                    break;

                // QUANTO/QUANTA
                case "HOWMUCH":
                    switch (command2)
                    {
                    // DINHEIRO
                    case "MONEY":
                    {
                        switch (details)
                        {
                        // TENHO
                        case "HAVE":
                        {
                            t.Speak("Tens " + gamestate.money + " dólares.");
                            break;
                        }

                        // CUSTA UM/UMA
                        case "COST":
                        {
                            switch (weapon)
                            {
                            // AK-47
                            case "AK47":
                            {
                                t.Speak(" Uma AK-47 custa " + Prices.ak47 + " dólares");
                                break;
                            }

                            // DEAGLE
                            case "DEAGLE":
                            {
                                t.Speak(" Uma Desert Eagle custa " + Prices.deagle + " dólares");
                                break;
                            }

                            // AWP
                            case "AWP":
                            {
                                t.Speak(" Uma AWP custa " + Prices.awp + " dólares");
                                break;
                            }

                            // DEFUSE
                            case "DEFUSE":
                            {
                                t.Speak(" O Defuse custa " + Prices.defuse + " dólares");
                                break;
                            }

                            // COLETE CAPACETE
                            case "KELVAR_CAP":
                            {
                                t.Speak(" O Colete e o capacete custa " + Prices.kelvar_cap + " dólares");
                                break;
                            }

                            // P250
                            case "P250":
                            {
                                t.Speak(" Uma P250 custa " + Prices.p250 + " dólares");
                                break;
                            }

                            // MP7
                            case "MP7":
                            {
                                t.Speak(" Uma MP7 custa " + Prices.mp7 + " dólares");
                                break;
                            }

                            // UMP45
                            case "UMP45":
                            {
                                t.Speak(" Uma UMP45 custa " + Prices.ump45 + " dólares");
                                break;
                            }
                            }
                            break;
                        }

                        // FALTA-ME PARA COMPRAR UMA
                        case "LEFT":
                        {
                            switch (weapon)
                            {
                            // AK-47
                            case "AK47":
                            {
                                if (gamestate.money < Prices.ak47)
                                {
                                    t.Speak(" Faltam-te " + (Prices.ak47 - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Consegues comprar uma A K 47 e sobrar " + (gamestate.money - Prices.ak47) + " dólares.");
                                }
                                break;
                            }

                            // DEAGLE
                            case "DEAGLE":
                            {
                                if (gamestate.money < Prices.deagle)
                                {
                                    t.Speak(" Faltam-te " + (Prices.deagle - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Consegues comprar uma Deagle e sobrar " + (gamestate.money - Prices.deagle) + " dólares.");
                                }
                                break;
                            }

                            // AWP
                            case "AWP":
                            {
                                if (gamestate.money < Prices.awp)
                                {
                                    t.Speak(" Faltam-te " + (Prices.awp - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Consegues comprar uma A W P e sobrar " + (gamestate.money - Prices.awp) + " dólares.");
                                }
                                break;
                            }

                            // DEFUSE
                            case "DEFUSE":
                            {
                                if (gamestate.money < Prices.defuse)
                                {
                                    t.Speak(" Faltam-te " + (Prices.defuse - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Consegues comprar o Defuse e sobrar " + (gamestate.money - Prices.defuse) + " dólares.");
                                }
                                break;
                            }

                            // COLETE CAPACETE
                            case "KELVAR_CAP":
                            {
                                if (gamestate.money < Prices.kelvar_cap)
                                {
                                    t.Speak(" Faltam-te " + (Prices.kelvar_cap - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Consegues comprar o Colete e capacete e sobrar " + (gamestate.money - Prices.kelvar_cap) + " dólares.");
                                }
                                break;
                            }

                            // P250
                            case "P250":
                            {
                                if (gamestate.money < Prices.p250)
                                {
                                    t.Speak(" Faltam-te " + (Prices.p250 - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Consegues comprar uma P250 e sobrar " + (gamestate.money - Prices.p250) + " dólares.");
                                }
                                break;
                            }

                            // MP7
                            case "MP7":
                            {
                                if (gamestate.money < Prices.mp7)
                                {
                                    t.Speak(" Faltam-te " + (Prices.mp7 - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Consegues comprar uma M P 7 e sobrar " + (gamestate.money - Prices.mp7) + " dólares.");
                                }
                                break;
                            }

                            // UMP45
                            case "UMP45":
                            {
                                if (gamestate.money < Prices.ump45)
                                {
                                    t.Speak(" Faltam-te " + (Prices.ump45 - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Consegues comprar uma U M P 45 e sobrar " + (gamestate.money - Prices.ump45) + " dólares.");
                                }
                                break;
                            }
                            }
                            break;
                        }
                        }
                        break;
                    }

                    // VIDA
                    case "HEALTH":
                    {
                        switch (details)
                        {
                        // TENHO
                        case "HAVE":
                        {
                            t.Speak("Tens " + gamestate.health + "pontos de vida");
                            break;
                        }
                        }
                        break;
                    }

                    // ARMADURA
                    case "ARMOUR":
                    {
                        switch (details)
                        {
                        // TENHO
                        case "HAVE":
                        {
                            t.Speak("Tens " + gamestate.armour + "pontos de armadura");
                            break;
                        }
                        }
                        break;
                    }
                    }
                    break;

                // TENHO
                case "HAVE":
                {
                    switch (command2)
                    {
                    //DINHEIRO
                    case "MONEY":
                    {
                        switch (details)
                        {
                        //SUFICIENTE PARA COMPRAR UM/UMA
                        case "ENOUGH_FOR":
                        {
                            switch (weapon)
                            {
                            // AK-47
                            case "AK47":
                            {
                                if (gamestate.money < Prices.ak47)
                                {
                                    t.Speak(" Não, faltam-te" + (Prices.ak47 - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Tens dinehiro para comprar uma AK-47 e sobrar " + (gamestate.money - Prices.ak47) + " dólares.");
                                }
                                break;
                            }

                            // DEAGLE
                            case "DEAGLE":
                            {
                                if (gamestate.money < Prices.deagle)
                                {
                                    t.Speak(" Não, faltam-te " + (Prices.deagle - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Tens dinehiro para comprar uma Deagle e sobrar " + (gamestate.money - Prices.deagle) + " dólares.");
                                }
                                break;
                            }

                            // AWP
                            case "AWP":
                            {
                                if (gamestate.money < Prices.awp)
                                {
                                    t.Speak("Não, faltam-te " + (Prices.awp - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Tens dinehiro para comprar uma AWP e sobrar " + (gamestate.money - Prices.awp) + " dólares.");
                                }
                                break;
                            }

                            // DEFUSE
                            case "DEFUSE":
                            {
                                if (gamestate.money < Prices.defuse)
                                {
                                    t.Speak("Não, faltam-te " + (Prices.defuse - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Tens dinehiro para comprar o Defuse e sobrar " + (gamestate.money - Prices.defuse) + " dólares.");
                                }
                                break;
                            }

                            // COLETE CAPACETE
                            case "KELVAR_CAP":
                            {
                                if (gamestate.money < Prices.kelvar_cap)
                                {
                                    t.Speak("Não, faltam-te " + (Prices.kelvar_cap - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Tens dinehiro para comprar o Colete e Capacete e sobrar " + (gamestate.money - Prices.kelvar_cap) + " dólares.");
                                }
                                break;
                            }

                            // P250
                            case "P250":
                            {
                                if (gamestate.money < Prices.p250)
                                {
                                    t.Speak("Não, faltam-te " + (Prices.p250 - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Tens dinehiro para comprar uma P250 e sobrar " + (gamestate.money - Prices.p250) + " dólares.");
                                }
                                break;
                            }

                            // MP7
                            case "MP7":
                            {
                                if (gamestate.money < Prices.mp7)
                                {
                                    t.Speak("Não, faltam-te " + (Prices.mp7 - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Tens dinehiro para comprar uma M P 7 e sobrar " + (gamestate.money - Prices.mp7) + " dólares.");
                                }
                                break;
                            }

                            // UMP45
                            case "UMP45":
                            {
                                if (gamestate.money < Prices.ump45)
                                {
                                    t.Speak("Não, faltam-te " + (Prices.ump45 - gamestate.money) + " dólares");
                                }
                                else
                                {
                                    t.Speak(" Tens dinehiro para comprar uma U M P 45 e sobrar " + (gamestate.money - Prices.ump45) + " dólares.");
                                }
                                break;
                            }
                            }
                            break;
                        }
                        }
                        break;
                    }
                    }
                    break;
                }

                // COMPRA-ME UM/UMA
                case "BUY_ME":
                {
                    switch (weapon)
                    {
                    // AK-47
                    case "AK47":
                    {
                        if (gamestate.money < Prices.ak47)
                        {
                            t.Speak(" Não consigo, faltam-te" + (Prices.ak47 - gamestate.money) + " dólares");
                        }
                        else
                        {
                            // CÓDIGO PARA DAR INPUT DA TECLA: VK_6 ( Tecla 6 do teclado )
                            inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_6);

                            t.Speak(" Compraste uma A K 47 e sobraram " + (gamestate.money - Prices.ak47) + " dólares.");
                        }
                        break;
                    }

                    // DEAGLE
                    case "DEAGLE":
                    {
                        if (gamestate.money < Prices.deagle)
                        {
                            t.Speak(" Não consigo, faltam-te " + (Prices.deagle - gamestate.money) + " dólares");
                        }
                        else
                        {
                            // CÓDIGO PARA DAR INPUT DA TECLA: VK_8 ( Tecla 8 do teclado )
                            inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_8);

                            t.Speak(" Compraste uma Deagle e sobraram " + (gamestate.money - Prices.deagle) + " dólares.");
                        }
                        break;
                    }

                    // AWP
                    case "AWP":
                    {
                        if (gamestate.money < Prices.awp)
                        {
                            t.Speak("Não consigo, faltam-te " + (Prices.awp - gamestate.money) + " dólares");
                        }
                        else
                        {
                            // CÓDIGO PARA DAR INPUT DA TECLA: VK_7 ( Tecla 7 do teclado )
                            inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_7);

                            t.Speak(" Compraste uma A W P e sobraram " + (gamestate.money - Prices.awp) + " dólares.");
                        }
                        break;
                    }

                    // DEFUSE
                    case "DEFUSE":
                    {
                        if (gamestate.money < Prices.defuse)
                        {
                            t.Speak("Não consigo, faltam-te " + (Prices.defuse - gamestate.money) + " dólares");
                        }
                        else
                        {
                            // CÓDIGO PARA DAR INPUT DA TECLA: VK_9 ( Tecla 9 do teclado )
                            inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_9);

                            t.Speak(" Compraste o Defuse e sobraram " + (gamestate.money - Prices.defuse) + " dólares.");
                        }
                        break;
                    }

                    // COLETE CAPACETE
                    case "KELVAR_CAP":
                    {
                        if (gamestate.money < Prices.kelvar_cap)
                        {
                            t.Speak("Não consigo, faltam-te " + (Prices.kelvar_cap - gamestate.money) + " dólares");
                        }
                        else
                        {
                            // CÓDIGO PARA DAR INPUT DA TECLA: VK_0 ( Tecla 0 do teclado )
                            inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_0);

                            t.Speak(" Compraste o Colete e capacete e sobraram " + (gamestate.money - Prices.kelvar_cap) + " dólares.");
                        }
                        break;
                    }

                    // P250
                    case "P250":
                    {
                        if (gamestate.money < Prices.p250)
                        {
                            t.Speak("Não consigo, faltam-te " + (Prices.p250 - gamestate.money) + " dólares");
                        }
                        else
                        {
                            // CÓDIGO PARA DAR INPUT DA TECLA: VK_P ( Tecla P do teclado )
                            inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_P);

                            t.Speak(" Compraste uma P250 e sobraram " + (gamestate.money - Prices.p250) + " dólares.");
                        }
                        break;
                    }

                    // MP7
                    case "MP7":
                    {
                        if (gamestate.money < Prices.mp7)
                        {
                            t.Speak("Não consigo, faltam-te " + (Prices.mp7 - gamestate.money) + " dólares");
                        }
                        else
                        {
                            // CÓDIGO PARA DAR INPUT DA TECLA: VK_H ( Tecla H do teclado )
                            inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_H);

                            t.Speak(" Compraste uma M P 7 e sobraram " + (gamestate.money - Prices.mp7) + " dólares.");
                        }
                        break;
                    }

                    // UMP45
                    case "UMP45":
                    {
                        if (gamestate.money < Prices.ump45)
                        {
                            t.Speak("Não consigo, faltam-te " + (Prices.ump45 - gamestate.money) + " dólares");
                        }
                        else
                        {
                            // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                            inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_K);

                            t.Speak(" Compraste uma U M P 45 e sobraram " + (gamestate.money - Prices.ump45) + " dólares.");
                        }
                        break;
                    }
                    }
                    break;
                }

                // ABRE-ME O CSGO
                case "OPEN_CSGO":
                {
                    t.Speak(" Abrindo o Counter Strike ");
                    Process.Start(@"C:\Program Files (x86)\Steam\Steam.exe", "-applaunch 730 -console +exec autoexec +exec autoexec");
                    break;
                }

                // GESTURES
                // AGACHAR
                case "CROUCH":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyDown(VirtualKeyCode.LCONTROL);
                    Thread.Sleep(1000);

                    break;
                }

                // DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB DAB
                case "DAB":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_Y);
                    Thread.Sleep(100);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_D);
                    Thread.Sleep(50);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_A);
                    Thread.Sleep(50);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_B);
                    Thread.Sleep(50);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.RETURN);
                    Thread.Sleep(50);
                    break;
                }

                // CHEERS
                case "HEY":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_X);
                    Thread.Sleep(25);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_3);
                    break;
                }

                // AGUENTA ESTE SÍTIO
                case "HOLD":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_Z);
                    Thread.Sleep(25);
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_4);
                    break;
                }

                // EQUIPA!
                case "TEAM":
                {
                    switch (command2)
                    {
                    //AGUENTEM ESTE SÍTIO
                    case "HOLD":
                    {
                        // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                        inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_X);
                        Thread.Sleep(25);
                        inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_3);
                        break;
                    }

                    // EXCELENTE!
                    case "HEY":
                    {
                        // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                        inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_Z);
                        Thread.Sleep(25);
                        inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_4);
                        break;
                    }
                    }
                    break;
                }

                // RECARREGA
                case "RELOAD":
                {
                    // CÓDIGO PARA DAR INPUT DA TECLA: VK_K ( Tecla K do teclado )
                    inputsim.Keyboard.KeyPress(VirtualKeyCode.VK_R);
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
        }
Exemplo n.º 29
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var doc = XDocument.Parse(e.Message);
            var com = doc.Descendants("command").FirstOrDefault().Value;

            dynamic json = JsonConvert.DeserializeObject(com);



            switch (json.recognized[0].ToString())
            {
            case "cidades":
                service.ShowPlace(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsMain();
                if (res.Count() > 0)
                {
                    writeToFile(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Comidas":
                bool check = service.ShowFood(json.recognized[1].ToString());
                while (!check)
                {
                    System.Threading.Thread.Sleep(1000);
                }
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Tipodeestabelecimento":
                service.ShowEstablishment(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Limpar":
                service.Clear();
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsMain();
                if (res.Count() > 0)
                {
                    writeToFile(res);
                    res.ForEach(Console.WriteLine);
                }

                break;

            case "Restaurantes":
                Console.WriteLine("Restaurante detected");
                res.ForEach(Console.WriteLine);
                Console.WriteLine(json.recognized[1].ToString());
                service.clickRestaurant(res, json.recognized[1].ToString());
                break;

            case "TipodeReserva":
                service.ShowReserves(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Cozinhasepratos":
                service.ShowKitchenTypes(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Preco":
                service.ShowPrice(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Caracteristicasdorestaurante":
                service.ShowCharacteristics(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Bonspara":
                service.ShowGoodFor(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Refeicoes":
                service.ShowMeals(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Restricoesalimentares":
                service.ShowRestrictions(json.recognized[1].ToString());
                System.Threading.Thread.Sleep(500);
                res = service.getAllRestaurantsFilter();
                if (res.Count() > 0)
                {
                    writeToFile2(res);
                    res.ForEach(Console.WriteLine);
                }
                break;

            case "Mais":
                switch (json.recognized[1].ToString())
                {
                case "Tipo de estabelecimento":
                    service.openMoreType();
                    break;

                case "Características do restaurante":
                    service.openMoreCharact();
                    break;

                case "Bons para":
                    service.openGoodFor();
                    break;

                case "Cozinhas e pratos":
                    service.openKitchenDishes();
                    break;
                }



                break;
            }
        }