Example #1
0
        public static void Export(Server UServer, String fileName)
        {
            // Create structures
            List <ExportScenario> scenarios = new List <ExportScenario>();

            foreach (var s in UServer.Scenarios)
            {
                var tmp = new ExportScenario()
                {
                    Name = s.Name
                };

                foreach (var r in s.Requests)
                {
                    tmp.Requests.Add(new ExportRequest()
                    {
                        Name = r.Name, Method = r.HTTP_METHOD, URL = r.Url
                    });
                }

                foreach (KeyValuePair <string, string> entry in s.customVariables)
                {
                    tmp.Variables.Add(new ExportScenarioVariable()
                    {
                        Name = entry.Key, Value = entry.Value
                    });
                }
                scenarios.Add(tmp);
            }

            try
            {
                // Remove file if exists!
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                // Create serializer
                XmlSerializer serializer = new XmlSerializer(typeof(List <ExportScenario>));

                // Create writer
                using (TextWriter writer = new StreamWriter(fileName))
                {
                    serializer.Serialize(writer, scenarios);
                }

                MessageDialog.ShowMessage(Director.Properties.Resources.VariableExportSuccess);
            }
            catch
            {
                MessageDialog.ShowError(Director.Properties.Resources.ErrorExportVariables);
            }
        }
        public static void Export(Server UServer, String fileName)
        {
            // Create structures
            List<ExportScenario> scenarios = new List<ExportScenario>();

            foreach (var s in UServer.Scenarios)
            {
                var tmp = new ExportScenario()
                {
                    Name = s.Name
                };

                foreach (var r in s.Requests)
                {
                    tmp.Requests.Add(new ExportRequest()
                    {
                        Name = r.Name, Method = r.HTTP_METHOD, URL = r.Url
                    });
                }

                foreach (KeyValuePair<string, string> entry in s.customVariables)
                {
                    tmp.Variables.Add(new ExportScenarioVariable()
                    {
                        Name = entry.Key, Value = entry.Value
                    });
                }
                scenarios.Add(tmp);
            }

            try
            {
                // Remove file if exists!
                if (File.Exists(fileName))
                    File.Delete(fileName);

                // Create serializer
                XmlSerializer serializer = new XmlSerializer(typeof(List<ExportScenario>));

                // Create writer
                using (TextWriter writer = new StreamWriter(fileName))
                {
                    serializer.Serialize(writer, scenarios);
                }

                MessageDialog.ShowMessage(Director.Properties.Resources.VariableExportSuccess);
            }
            catch
            {
                MessageDialog.ShowError(Director.Properties.Resources.ErrorExportVariables);
            }
        }