MessageEditor.cs
3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//*************************************************************************************************
// MessageEditor.cs
// Owner: Mahipal Kante
//
// UI of Editor for Web Service Request Body
// The Web Service response can be plain XML or 'application/soap+msbin1'
// (binary - used by Silverlight application with WCF RIA) or JSON
//
// Copyright(c) Microsoft Corporation, 2010
//*************************************************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using WebTest.WebService.Plugin.ResultTab;
using WebTest.WebService.Plugin.Runtime;
namespace WebTest.WebService.Plugin.MessageEditors
{
internal partial class MessageEditor : UserControl
{
/// <summary>
///
/// </summary>
/// <param name="contentHandler">Handler for given content type</param>
public MessageEditor(ContentHandler contentHandler)
{
InitializeComponent();
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.TabChanged);
this.xmlTreeView = new XmlTreeView(this.treeViewRequest);
this.contentHandler = contentHandler;
this.xmlTreeView.ShowXML(contentHandler.XmlDocument);
this.requestTextBox.Text = contentHandler.XmlString;
ContextMenu treeContextMenu = new ContextMenu();
this.treeParameterizeMenuItem = new MenuItem("Parameterize");
treeContextMenu.MenuItems.Add(treeParameterizeMenuItem);
this.treeViewRequest.ContextMenu = treeContextMenu;
this.treeParameterizeMenuItem.MenuItems.Clear();
this.treeParameterizeMenuItem.MenuItems.Add(new MenuItem("Type Parameter", AddParameter));
Connect connect = Connect.GetInstance();
if (connect != null)
{
this.webTestDetail = connect.GetActiveWebTest();
}
requestXMLEditor.Visible = (this.webTestDetail != null);
if (this.webTestDetail != null)
{
List<string> parameters = this.webTestDetail.GetParameterList();
foreach (string parameter in parameters)
{
this.treeParameterizeMenuItem.MenuItems.Add(new MenuItem(parameter, AddParameter));
}
}
}
/// <summary>
/// Makes sure both tabs are synced with the current changes that are done in Text Box
/// </summary>
public void UpdateContent()
{
if (this.tabControl1.SelectedTab.Equals(this.tabPage2))
{
this.contentHandler.XmlString = this.requestTextBox.Text;
}
}
private void AddParameter(object sender, EventArgs e)
{
MenuItem menuItem = sender as MenuItem;
if (menuItem == null)
{
return;
}
this.xmlTreeView.AddParameter(menuItem.Text);
}
private void TabChanged(object sender, EventArgs e)
{
if (this.tabControl1.SelectedTab.Equals(this.tabPage1))
{
this.contentHandler.XmlString = this.requestTextBox.Text;
xmlTreeView.ShowXML(this.contentHandler.XmlDocument);
}
else
{
this.requestTextBox.Text = this.contentHandler.XmlString;
}
}
private void requestXMLEditor_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Connect.GetInstance().ShowInXMLEditor("Request Content", this.requestTextBox.Text);
}
private ContentHandler contentHandler;
private WebTestDetail webTestDetail;
private XmlTreeView xmlTreeView;
private MenuItem treeParameterizeMenuItem;
}
}