private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { this.SelectedRow = (DataSet1.DataTableCmdRow)((System.Data.DataRowView)e.AddedItems[0]).Row; var obj = libSharedProject.ProtolV1Commands.ProtocolV1Base.ConvertJsonStingToObj(this.SelectedRow.JSON); this.ReflectionText = GetInfo(obj); this.SelectedCmd = obj; //var obj = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(this.SelectedRow.JSON); //if (obj.GetValue(this.protocolV1Kennung).ToString() == nameof(libSharedProject.ProtolV1Commands.TestCmd)) //{ // this.SelectedCmd = (libSharedProject.ProtolV1Commands.TestCmd)obj.ToObject(typeof(libSharedProject.ProtolV1Commands.TestCmd)); //} //else //{ // this.SelectedCmd = obj; //} } catch (Exception ex) { this.AddInfoTextLine(ex.Message); } }
public async Task SendCmd(DataSet1.DataTableCmdRow row) { var newSendRow = this.SendTable.NewDataTableCmdRow(); newSendRow.ItemArray = (object[])(row.ItemArray.Clone()); newSendRow.TimeStamp = DateTime.Now; this.SendTable.AddDataTableCmdRow(newSendRow); // newSendRow = this.ReceiveTable.NewDataTableCmdRow(); //newSendRow.ItemArray = (object[])(row.ItemArray.Clone()); //newSendRow.TimeStamp = DateTime.Now; //newSendRow.Info = "Test"; //this.ReceiveTable.AddDataTableCmdRow(newSendRow); this.SendText(row.JSON); }
/// <summary> /// Empfängt Commands von der Oberfläche /// </summary> /// <param name="param">Empfangenes Command</param> public async void CommandReceived(object param) { try { switch (param as string) { case "File Open": //DataContractSerializer Microsoft.Win32.OpenFileDialog openFileDialog1 = new Microsoft.Win32.OpenFileDialog(); //if (this.TypeFileDirectory != string.Empty) //{ // openFileDialog1.InitialDirectory = System.IO.Path.Combine(this.TypeFileDirectory, "NMEA"); //} openFileDialog1.Filter = "xml files (*.xml)|*.xml"; // "json files (*.json)|*.json";//; if (openFileDialog1.ShowDialog() == true) { string file = openFileDialog1.FileName; var temp = ConfigFile.Deserialize(file); //this.SelectedCmd = null; //this.CommandList.Clear(); //this.SendList.Clear(); //this.ReceiveList.Clear(); //foreach (var item in temp.CommandList2) //{ // this.CommandList2.Add(item); //} //foreach (var item in temp.CommandList) //{ // this.CommandList.Add(item); //} //foreach (var item in temp.SendList) //{ // SendList.Add(item); //} //foreach (var item in temp.ReceiveList) //{ // ReceiveList.Add(item); //} foreach (var item in temp.CommandTable.Rows) { var newRow = this.CommandTable.NewDataTableCmdRow(); newRow.ItemArray = (object[])((System.Data.DataRow)item).ItemArray.Clone(); this.CommandTable.AddDataTableCmdRow(newRow); } } break; case "File Save": if (string.IsNullOrEmpty(this.ConfigFile.FileName)) { this.CommandReceived("File SaveAs"); } else { this.ConfigFile.CommandTable = this.CommandTable; this.ConfigFile.SendTable = this.SendTable; this.ConfigFile.ReceiveTable = this.ReceiveTable; //this.ConfigFile.CommandList = this.CommandList; //this.ConfigFile.SendList = this.SendList; //this.ConfigFile.ReceiveList = this.ReceiveList; this.ConfigFile.Serialize(this.ConfigFile.FileName); } break; case "File SaveAs": try { Microsoft.Win32.SaveFileDialog saveFileDialog1 = new Microsoft.Win32.SaveFileDialog(); //if (this.TypeFileDirectory != string.Empty) //{ // saveFileDialog1.InitialDirectory = System.IO.Path.Combine(this.TypeFileDirectory, "NMEA"); //} //DataContractSerializer saveFileDialog1.Filter = "xml files (*.xml)|*.xml"; // "json files (*.json)|*.json";// ; if (saveFileDialog1.ShowDialog() == true) { string file = saveFileDialog1.FileName; this.ConfigFile.CommandTable = this.CommandTable; this.ConfigFile.SendTable = this.SendTable; this.ConfigFile.ReceiveTable = this.ReceiveTable; //this.ConfigFile.CommandList = this.CommandList; //this.ConfigFile.SendList = this.SendList; //this.ConfigFile.ReceiveList = this.ReceiveList; this.ConfigFile.Serialize(file); } } catch (Exception ex) { MessageBox.Show(ex.Message); } break; case "Start TCP Client": this.Client.HostNameOrIp = this.Host; this.Client.Port = this.Port; this.AddInfoTextLine(string.Format("Client Start Beginn -> Host: {0}, Port: {1}", this.Client.HostNameOrIp, this.Client.Port)); this.Client.Start(); this.AddInfoTextLine("Client Start: Ende"); break; case "Stop TCP Client": this.AddInfoTextLine("Client Stop: Beginn"); this.Client.Stop(); this.AddInfoTextLine("Client Stop: Ende"); break; case "Send TextBlock": this.SendText(this.ValueSendText); break; case "Send Data": this.SendData(this.ValueSendData.ToArray()); break; case "Send Selected Command": await this.SendCmd(this.SelectedRow); break; case "Create Json": string json = CreateJsonString(this.SelectedCmd); this.AddInfoTextLine(json); break; case "Clear Selected Commands": this.CommandTable.Rows.Clear(); //this.CommandList.Clear(); break; case "Send All Selected Commands": foreach (var item in this.CommandTable.Rows) { DataSet1.DataTableCmdRow row = (DataSet1.DataTableCmdRow)item; await this.SendCmd(row); } //foreach (var item in this.CommandList) //{ // await this.SendObj(item.Value); //} break; //case "Send Selected Send": // //await this.SendObj(this.SelectedCmd); // await this.SendCmd(this.SelectedRow); // break; //case "Clear Send Commands": // //this.SendList.Clear(); // this.SendTable.Rows.Clear(); // break; //case "Send Selected Receive": // await this.SendObj(this.SelectedCmd); // break; //case "Clear Receive Commands": // //this.ReceiveList.Clear(); // this.ReceiveTable.Rows.Clear(); // break; //case "Send SelectedObject": // await this.SendObj(this.SelectedCmd); // break; default: this.AddInfoTextLine(string.Format("Command {0} not Implemented", param.ToString())); break; } } catch (Exception ex) { MessageBox.Show(ExceptionHandling.GetExceptionText(new System.Exception(string.Format("Exception In: {0}", CallerName()), ex))); } }