private void openSimulationPage(object sender, MouseButtonEventArgs e) { if (sender is TextBlock textBlock) { var productId = textBlock.Tag; Pid.Text = productId.ToString(); if (File.Exists(@"Resources\json\simulationProduct\" + productId + ".json")) { var json = File.ReadAllText(@"Resources\json\simulationProduct\" + productId + ".json"); SimulationProductInfo simulationProductInfo = JsonConvert.DeserializeObject <SimulationProductInfo>(json); ProductTitle.Text = simulationProductInfo.title; ProductAnnotation.Text = simulationProductInfo.annotation; requestType.SelectedIndex = simulationProductInfo.method; samplenoSource.SelectedIndex = simulationProductInfo.protocol; ipAddress.Text = simulationProductInfo.ip; port.Text = simulationProductInfo.port.ToString(); uri.Text = simulationProductInfo.uri; contentType.SelectedIndex = simulationProductInfo.contentType; //jsonContext.Document = simulationProductInfo.jsonContext; //responseJsonContext1.Document = simulationProductInfo.responseJsonContext1; //responseJsonContext2.Document = simulationProductInfo.responseJsonContext2; setContext(jsonContext, simulationProductInfo.jsonContext); setContext(responseJsonContext1, simulationProductInfo.responseJsonContext1); setContext(responseJsonContext2, simulationProductInfo.responseJsonContext2); } else { MessageBox.Show("空"); } } }
private void save(object sender, RoutedEventArgs e) { if (!Pid.Text.Equals("0")) { SimulationProductInfo info = new SimulationProductInfo(); info.title = ProductTitle.Text; info.annotation = ProductAnnotation.Text; info.method = requestType.SelectedIndex; info.protocol = samplenoSource.SelectedIndex; info.ip = ipAddress.Text; info.port = int.Parse(port.Text); info.uri = uri.Text; info.contentType = contentType.SelectedIndex; info.jsonContext = getContext(jsonContext, @"Resources\json\simulationProduct\jsonContext.xaml"); info.responseJsonContext2 = getContext(responseJsonContext2, @"Resources\json\simulationProduct\responseJsonContext2.xaml"); string json = JsonConvert.SerializeObject(info); FileUtils.writeJsonFile(@"Resources\json\simulationProduct\" + Pid.Text + ".json", json); MessageBox.Show("保存"); } }