private void EditEntry()
        {
            var row = GetFirstPrintServerSelectedRow();

            if (row != null)
            {
                var server = row.DataBoundItem as FrameworkServer;

                FrameworkServerProxy proxy = new FrameworkServerProxy(server);

                // The user will now edit the print properties of this server.
                using (FrameworkServerEditForm form = new FrameworkServerEditForm(_controller, proxy))
                {
                    if (form.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    else
                    {
                        // Copy the working copy (proxy) data back to the server object, and then
                        // save these changes to the database.
                        proxy.CopyTo(server);
                        SaveChanges();
                    }
                }
            }
        }
        private DialogResult EditEntry(FrameworkServerProxy proxy)
        {
            DialogResult result = DialogResult.None;

            using (FrameworkServerEditForm form = new FrameworkServerEditForm(_controller, proxy))
            {
                result = form.ShowDialog();
                if (result == DialogResult.OK)
                {
                    _unsavedChanges = true;
                }
            }

            return(result);
        }
        /// <summary>
        /// Adds a new Framework Server with Print properties and retrieves it's print queues.
        /// </summary>
        private bool AddNewServer(string serverName, Guid serverId)
        {
            // The server doesn't exist in configuration, so try to query it and load
            // that information so it can be reviewed and edited by the user.
            Cursor = Cursors.WaitCursor;
            string error = string.Empty;
            FrameworkServerProxy proxy = new FrameworkServerProxy(serverName);
            bool success = _controller.QueryServer(proxy, out error);

            Cursor = Cursors.Default;

            // If there is a failure reading server and/or the user doesn't want to continue, then return
            if (!success && !ContinueEditing(proxy, error))
            {
                return(false);
            }

            FrameworkServer server = new FrameworkServer()
            {
                FrameworkServerId = serverId
            };

            // Add Print as a server type for this server before editing
            FrameworkServerType serverType = _controller.GetServerType(ServerType.Print);

            proxy.ServerTypes.Add(serverType);

            using (FrameworkServerEditForm form = new FrameworkServerEditForm(_controller, proxy))
            {
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                proxy.CopyTo(server);
                //Save the new server to the database at this point.  If there is an error getting
                //print queues, the server data will be preserved.
                _controller.AddNewServer(server);
                _printServers.Add(server);
                SaveChanges();
            }

            // Scan the server for queues.
            AddServerQueues(server);

            return(true);
        }
        /// <summary>
        /// Updates the server properties of an existing FrameworkServer to a Print Server.
        /// Scans the server for Print Queues and adds them to the database.
        /// </summary>
        private bool UpdateServerProperties(FrameworkServer server)
        {
            // Before displaying the server properties, add the Print Property to this server entry if it's not already there.
            if (!server.ServerTypes.Any(x => x.Name.Equals(ServerType.Print.ToString(), StringComparison.OrdinalIgnoreCase)))
            {
                server.ServerTypes.Add(_controller.GetServerType(ServerType.Print));
                SaveChanges();
            }

            // Instantiate the proxy class against the server, which will be used to edit the properties
            FrameworkServerProxy proxy = new FrameworkServerProxy(server);

            using (FrameworkServerEditForm form = new FrameworkServerEditForm(_controller, proxy))
            {
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }

                // Copy the working copy (proxy) data back to the server object
                proxy.CopyTo(server);
                //At this point we want to save in case the refreshing of the queues fails for some reason
                SaveChanges();
            }

            // If the grid isn't already showing the FrameworkServer, then add it.
            int index = GetDataBoundItemIndex(server.FrameworkServerId);

            if (index == -1)
            {
                _printServers.Add(server);
            }

            // The server was not a print server before, so we will need to refresh the print queues.
            AddServerQueues(server);

            return(true);
        }