/// <summary>
 /// Constructor.
 /// </summary>
 public ServerHeaders(MainWindow _window, Server _currentServer)
 {
     ActiveWindow = _window;
     ActiveServer = _currentServer;
     Width = 500;
     Height = 550;
     Resizable = true;
     Title = Director.Properties.Resources.DefaultServerHeaders;
     Icon = Image.FromResource(DirectorImages.EDIT_CONTENT_ICON);
     _initializeComponents();
 }
        public static Boolean SerializeAll(Server server, string fileToSave, List<Scenario> ScenarioList)
        {
            errorMessage = "";
            tmpDirectory = Export.createTempDirectory(true);
            if (tmpDirectory == null)
            {
                errorMessage = Export.errorMessage;
                return false;
            }
            //serialization of server
            if (!SerializeServer(server))
                return false;

            //serialization of scenarios
            if (!SerializeScenarios(ScenarioList))
                return false;

            try
            {
                //delete original zip if exists
                if (File.Exists(fileToSave))
                    File.Delete(fileToSave);
            }
            catch (Exception e)
            {
                errorMessage = Director.Properties.Resources.ExportSerialScenariosEx + e.Message;
                return false;
            }

            try
            {
                //archive created files
                ZipUtil.CreateArchiveFromFolder(fileToSave, tmpDirectory.FullName);
            }
            catch(Exception e)
            {
                errorMessage = Director.Properties.Resources.ExportZipCompressionEx + e.Message;
                return false;
            }
            return true;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="server"></param>
        public ExportWindow(Server server)
        {
            // Set active server
            ActiveServer = server;

            /// Title and Initial size
            Title = Director.Properties.Resources.ExportDialog;

            // Set icon
            Icon = Image.FromResource(DirectorImages.SAVE_SCENARIO_ICON);

            // Set default size
            Width = 450;
            Height = 500;

            // This window can not be maximalized
            Resizable = false;

            // Center screen
            InitialLocation = WindowLocation.CenterScreen;

            // Initialize content
            _initializeComponents();
        }
Beispiel #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="_s"></param>
        /// <param name="_file"></param>
        public static bool ProcessPostmanFile(Server _s, String _file)
        {
            // Read file to variable
            String content = "";
            try
            {
                using (StreamReader sr = new StreamReader(_file))
                {
                    content = sr.ReadToEnd();
                }
            }
            catch
            {
                MessageDialog.ShowError(Director.Properties.Resources.CannotReadFromFile);
                return false;
            }

            PostmanServer s = new PostmanServer();
            try
            {
                JObject o = JObject.Parse(content);
                s.name = (String) o["name"];
                s.requests = new List<PostmanRequest>();

                foreach (JObject re in o["requests"])
                {
                    var tmp = new PostmanRequest();
                    tmp.name = (String)re["name"];
                    tmp.method = (String)re["method"];
                    tmp.url = (String)re["url"];
                    tmp.headers = (String)re["headers"];

                    // Data
                    if (((String)re["dataMode"]) == "raw")
                    {
                        tmp.data = (String)re["data"];
                    }

                    s.requests.Add(tmp);
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
                MessageDialog.ShowError(Director.Properties.Resources.InvalidPostmanFile);
                return false;
            }

            // Set server header?
            if (_s.Name == null || _s.Name.Length == 0)
                _s.Name = s.name;

            if (_s.Url == null || _s.Url.Length == 0)
            {
                _s.Url = s.requests.Count > 0 ? s.requests[0].url : "";
            }

            // Create scenario
            var scNew = _s.CreateNewScenario();
            scNew.Name = s.name;

            foreach (var pr in s.requests)
            {
                var tmp = scNew.CreateNewRequest();
                tmp.Name = pr.name;
                tmp.HTTP_METHOD = pr.method;
                tmp.RequestTemplateType = ContentTypeUtils.GuessContentType (pr.data);
                tmp.RequestTemplate = pr.data;
                tmp.Url = pr.url;

                // Create headers
                foreach (var h in pr.HeaderList)
                {
                    tmp.Headers.Add(new Header()
                    {
                        Name = h.name, Value = h.value
                    });
                }
            }

            return true;
        }
Beispiel #5
0
        /// <summary>
        /// Set server instance.
        /// </summary>
        /// <param name="server">Server.</param>
        public void SetServer(Server server)
        {
            // Fill columns
            ActiveServer = server;

            // SKip change event
            ServerName.Changed -= ServerName_Changed;
            ServerName.Text = server.Name;
            ServerName.Changed += ServerName_Changed;
            ServerURL.Text = server.GetUrl();
            AuthUserName.Text = server.AuthName;
            AuthUserPassword.Password = server.AuthPassword;
            AuthRequired.State = (server.Authentication) ? CheckBoxState.On : CheckBoxState.Off;

            // Set frequency running
            if (server.RunningFrequency >= 0)
                FrequencyRunning.SelectedIndex = server.RunningFrequency;

            // Refresh data
            AuthRequired_Toggled(null, null);

            // Refresh data in server emails
            EmailWidget.SetServer(ActiveServer);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="_server"></param>
        public ScenarioList(Server _server)
        {
            // Intialize components
            ActiveServer = _server;

            // Init
            _initializeComponents();

            // Height
            HeightRequest = 270;
            MinHeight = 270;
        }
Beispiel #7
0
        /// <summary>
        /// Create new server and add server to server store!
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CreateNewServer(object sender, EventArgs e)
        {
            // Create server
            UServer = new Server(Director.Properties.Resources.NewServerString,
                Director.Properties.Resources.NewServerURL);

            // Add server to tree store
            ClearCurrentServerTree();

            // Add node
            UServer.TreePosition = CreateTreeItem(null, UServer.Name, ServerImage, UServer);

            // Disable server menu
            NewServer.Sensitive = false;

            // Disable server menu mac!
            NewServer.Clicked -= CreateNewServer;

            // Enable close server
            EnableServerButtons();
        }
Beispiel #8
0
 /// <summary>
 /// Close server menu.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void CloseServer_Clicked(object sender, EventArgs e)
 {
     bool res = MessageDialog.Confirm(Director.Properties.Resources.MessageBoxCloseScenario, Command.Ok);
     if (res)
     {
         UServer = null;
         ClearCurrentServerTree();
         UpdateControlView(null, null);
         DisableServerButtons();
     }
     RunningObjects.Clear();
 }
Beispiel #9
0
        /// <summary>
        /// Start apiary import.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ApiaryImport_Clicked(object sender, EventArgs e)
        {
            // Info
            MessageDialog.ShowMessage(Director.Properties.Resources.InfoApiarySnowcrash);

            // Show open file dialog
            OpenFileDialog of = new OpenFileDialog(Director.Properties.Resources.SelectJsonFile);
            of.Multiselect = false;
            of.Filters.Add(new FileDialogFilter("Json files", "*.json"));
            if (of.Run())
            {
                Server tmp = UServer;
                if (tmp == null)
                {
                    tmp = new Server();
                }

                // Process result
                Boolean result = Apiary.ProcessApiaryFile(tmp, of.FileName);

                // Set again
                UServer = tmp;

                if (result)
                {
                    // Refresh tree
                    RefreshServerTreeView();

                    // Enable close sceanrio
                    EnableServerButtons();
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Open new scenario.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenNewServer(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog(Director.Properties.Resources.DialogOpenScenario);
            dlg.Multiselect = false;
            dlg.Filters.Add(new FileDialogFilter("Director files", "*.adfe"));
            if (dlg.Run())
            {
                try
                {
                    UServer = Deserialization.DeserializeAll(dlg.FileNames[0]);

                    String messageType = Director.Properties.Resources.ImportResult;
                    if (UServer == null)
                    {
                        MessageDialog.ShowMessage(messageType, Deserialization.errorMessage);
                        return;
                    }
                }
                catch
                {
                    MessageDialog.ShowError(Director.Properties.Resources.DialogInvalidFile);
                    return;
                }
                // Refresh tree
                RefreshServerTreeView();

                // Enable close sceanrio
                EnableServerButtons();
            }
        }
        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 Boolean SerializeServer(Server server)
 {
     try
     {
         XmlSerializer serializer = new XmlSerializer(typeof(Server));
         using (TextWriter writer = new StreamWriter(Path.Combine(tmpDirectory.FullName, Export.serverOverview)))
         {
             //serialization of server
             serializer.Serialize(writer, server);
         }
     }
     catch (Exception e)
     {
         errorMessage = Director.Properties.Resources.ExportSerialServerEx + e.Message;
         return false;
     }
     return true;
 }
Beispiel #13
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="_s"></param>
        /// <param name="_file"></param>
        public static bool ProcessApiaryFile(Server _s, String _file)
        {
            // Read file to variable
            String content = "";
            try
            {
                using (StreamReader sr = new StreamReader(_file))
                {
                    content = sr.ReadToEnd();
                }
            }
            catch
            {
                MessageDialog.ShowError(Director.Properties.Resources.CannotReadFromFile);
                return false;
            }

            // Parse content
            ApiaryServer s;
            try
            {
                s = JsonConvert.DeserializeObject<ApiaryServer>(content);
            }
            catch
            {
                MessageDialog.ShowError(Director.Properties.Resources.InvalidApiaryFile);
                return false;
            }

            // Set URL
            String url = "";
            while (true)
            {
                var d = new Dialog();
                d.Title = Director.Properties.Resources.FillEndPointUrl;
                d.Width = 340;
                d.Icon = Image.FromResource(DirectorImages.EDIT_ICON);

                VBox DialogContent = new VBox();
                DialogContent.PackStart(new Label(Director.Properties.Resources.FillEndPointUrl));
                TextEntry NewValidUrl = new TextEntry();
                if (url.Length == 0)
                    NewValidUrl.Text = "http://example.com";
                DialogContent.PackStart(NewValidUrl, true, true);

                d.Buttons.Add(new DialogButton(Director.Properties.Resources.ButtonOK, Command.Ok));
                d.Buttons.Add(new DialogButton(Director.Properties.Resources.ButtonStorno, Command.Cancel));
                d.Content = DialogContent;

                var c = d.Run();

                if (c == Command.Ok)
                {
                    Uri _newUri;

                    // Uri validation
                    if (Uri.TryCreate(NewValidUrl.Text, UriKind.Absolute, out _newUri))
                    {
                        url = _newUri.AbsoluteUri;
                        d.Dispose();
                        break;
                    }
                    else
                    {
                        MessageDialog.ShowError(Director.Properties.Resources.InvalidUrlError);
                    }
                }
                else
                {
                    d.Dispose();
                    return false;
                }
                d.Dispose();
            }

            // Fill data
            if (_s.Name == null || _s.Name.Length == 0)
                _s.Name = s.name;

            if (_s.Url == null || _s.Url.Length == 0)
                _s.Url = url;

            // Z resources group vyrobit scenare
            foreach (var group in s.resourceGroups)
            {
                var scNew = _s.CreateNewScenario();
                scNew.Name = group.name;

                // Z akcí - example vyrobit requesty
                foreach (var resource in group.resources)
                {
                    foreach (var action in resource.actions)
                    {
                        var reqNew = scNew.CreateNewRequest();
                        reqNew.Name = string.Format("{0}/{1}", resource.name, action.name);
                        reqNew.HTTP_METHOD = action.method;

                        // Create URL
                        if (resource.uriTemplate.StartsWith("/") && url.EndsWith("/"))
                        {
                            reqNew.Url = url.Substring(0, url.Length - 1) + resource.uriTemplate;
                        }
                        else
                            reqNew.Url = url + resource.uriTemplate;

                        // Get first request
                        var req = (action.examples.Count > 0 && action.examples[0].requests.Count > 0) ? action.examples[0].requests[0] : null;
                        var res = (action.examples.Count > 0 && action.examples[0].responses.Count > 0) ? action.examples[0].responses[0] : null;

                        if (req != null)
                        {
                            // Content type
                            reqNew.RequestTemplateType = ContentTypeUtils.GuessContentType (req.body);
                            reqNew.RequestTemplate = req.body;

                            // Headers
                            foreach (var h in req.headers)
                            {
                                reqNew.Headers.Add(new Header()
                                {
                                    Name = h.name, Value = h.value
                                });
                            }
                        }

                        if (res != null)
                        {
                            // Content type
                            reqNew.ResponseTemplateType = ContentTypeUtils.GuessContentType (res.body);
                            // Set body
                            reqNew.ResponseTemplate = res.body;
                        }
                    }
                }
            }

            return true;
        }
Beispiel #14
0
        /// <summary>
        /// Set server to email list view.
        /// </summary>
        /// <param name="_server">_server.</param>
        public void SetServer(Server _server)
        {
            // Servers
            ActiveServer = _server;

            // Clear items
            EmailItems.Clear();

            // Clear list content
            EmailListContent.Clear();

            // Add all emails from Server
            int x = 0;
            foreach (Email i in ActiveServer.Emails)
            {
                var tmp = new EmailListItem(this, i, (x%2 == 0) ? Colors.White : Colors.LightGray);
                if (!Email.IsValid(i.UserEmail))
                {
                    tmp.BackgroundColor = Colors.Red;
                }
                EmailListContent.PackStart(tmp);
                EmailItems.Add(tmp);
                x++;
            }
        }