/// <summary> /// Query string download completed event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void QueryCompleted(object sender, DownloadStringCompletedEventArgs e) { ResultsBox.Focus(); try { var resultObj = parser.Deserialize <dynamic>(e.Result); query.city = resultObj["name"]; query.country = resultObj["sys"]["country"]; query.weather = resultObj["weather"][0]["main"]; query.weatherDesc = resultObj["weather"][0]["description"]; query.latitude = resultObj["coord"]["lat"]; query.longitude = resultObj["coord"]["lon"]; query.temperature = resultObj["main"]["temp"]; query.pressure = resultObj["main"]["pressure"]; query.humidity = resultObj["main"]["humidity"]; if (query.country.Equals("CA")) { query.country = "Canada"; } else if (query.country.Equals("US")) { query.country = "United States"; } ResultsBox.Text = query.ToString(); } catch { ResultsBox.Text = "An error occured obtaining city information, please double check name and try again!"; } }
private void ReadCommands(string result, string status) { if (Maps.Stop) { return; } var b = speechSyn.Voice.Gender; string CommandName = ""; string Answer = ""; string CommandType = ""; speechSyn.SelectVoiceByHints(VoiceGender.Female);//female speaks if (SpeechBox.InvokeRequired && Maps.IsSleeping == false) { SpeechBox.Invoke(new MethodInvoker(delegate { SpeechBox.Text = result + "\n" + SpeechBox.Text; }));//shows what user said } CommandType = common.GetCommandTypeFromAliasInLocal(Conn, result);//get data from db if (OldCommandsBox.InvokeRequired && Maps.IsSleeping == false && CommandType != "" && CommandType != null) { OldCommandsBox.Invoke(new MethodInvoker(delegate { OldCommandsBox.Text = "Type:" + CommandType + "\n" + OldCommandsBox.Text; }));//shows command } switch (CommandType) { case "Chat": Answer = common.GetAnswersInLocal(Conn, result); if (OldCommandsBox.InvokeRequired) { OldCommandsBox.Invoke(new MethodInvoker(delegate { OldCommandsBox.Text = ":" + result + "\n" + OldCommandsBox.Text; })); //shows command } break; case "System": CommandName = common.GetCommandNameFromAliasInLocal(Conn, result); if (OldCommandsBox.InvokeRequired) { OldCommandsBox.Invoke(new MethodInvoker(delegate { OldCommandsBox.Text = ":" + CommandName + " \n" + OldCommandsBox.Text; })); //shows command } Answer = commands.dic[CommandName].Execute(); break; case "C#": CommandName = common.GetCommandNameFromAliasInLocal(Conn, result); if (OldCommandsBox.InvokeRequired) { OldCommandsBox.Invoke(new MethodInvoker(delegate { OldCommandsBox.Text = ":" + CommandName + " \n" + OldCommandsBox.Text; })); //shows command } Answer = commands.dic[CommandName].Execute(); break; default: Dictionary <string, List <string> > CommandNameAndParameters = common.GetCommandNameAndParameters(Conn, result); List <string> Commands = new List <string>(); string currentCommandName = ""; string[] paramArray = null; foreach (var item in CommandNameAndParameters) { paramArray = item.Value.ToArray(); Commands.AddRange(item.Value); currentCommandName = item.Key; } string Answ = string.Join(",", Commands.ToArray()); Answ += currentCommandName; if (ResultsBox.InvokeRequired && Maps.IsSleeping == false) { ResultsBox.Invoke(new MethodInvoker(delegate { ResultsBox.Text = Answ + "\n" + ResultsBox.Text; })); //shows answer } try { if (currentCommandName != "") { Answer = commands.dic[currentCommandName].Execute(paramArray); } } catch (Exception e) { } break; } if (ResultsBox.InvokeRequired && Maps.IsSleeping == false) { ResultsBox.Invoke(new MethodInvoker(delegate { ResultsBox.Text = Answer + "\n" + ResultsBox.Text; }));//shows answer } if (Maps.IsSleeping == false && Maps.Mute == false) { speechSyn.SpeakAsync(Answer);//speaks.. } }