private void editQueue_ToolStripButton_Click(object sender, EventArgs e)
        {
            RemotePrintQueue queue  = SelectedQueue;
            FrameworkServer  server = SelectedServer;

            if (server == null)
            {
                MessageBox.Show("Please select a Print Server.", "Print Server not selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TraceFactory.Logger.Error("No Print Server selected for editing queue");
                return;
            }
            if (queue == null)
            {
                MessageBox.Show("Please select a Print Queue.", "Print Queue Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                TraceFactory.Logger.Error("Failed to get print queue. No Print Queue selected");
                return;
            }

            // Determine if this server is categorized as an ePrint server.  If it is, then allow the user
            // to edit ePrint related information.  Otherwise it will treat it as a standard print server.
            string ePrintType = ServerType.ePrint.ToString();

            if (server.ServerTypes.Any(x => x.Name.Equals(ePrintType, StringComparison.OrdinalIgnoreCase)))
            {
                string queueName = InputDialog.Show("ePrint email address", "Edit ePrint Email Address", queue.Name);
                if (!string.IsNullOrEmpty(queueName))
                {
                    EditQueue(queue, SelectedServer, queueName);
                }
            }
        }
示例#2
0
        private void LoadPrintQueues(string serverName)
        {
            List <RemotePrintQueue> queues = null;

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                queues = RemotePrintQueue.SelectByPrintServerName(context, serverName).ToList();
            }

            _printQueueNode.Nodes.Clear();
            foreach (RemotePrintQueue queue in queues)
            {
                TreeNode queueNode = _printQueueNode.Nodes.Add(queue.Name);
                foreach (ResourceWindowsCategory counter in _printQueueCounterNames)
                {
                    BuildTree(counter, queueNode);
                }
            }

            // Only display the Print Queue Node if the selected server has queues.
            if (_printQueueNode.Nodes.Count > 0)
            {
                available_TreeView.Nodes.Add(_printQueueNode);
            }
        }
        /// <summary>
        /// Processes queues that are in the database but don't show up on the server anymore.
        /// The user is prompted to remove these queues if they choose, but if the queues
        /// are still referenced within an activity then they can't be deleted.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="queuesOnServer">The queues on server.</param>
        /// <returns></returns>
        private bool FindMissingServerQueues(FrameworkServer server, Collection <string> queuesOnServer)
        {
            bool changesExist = false;

            // There are queues that no longer exist on the server, ask the user what they want
            // to do.  Should they keep the information around, but inactive, or should they
            // remove the queue entry from the database?
            Collection <RemotePrintQueue> queuesMissingOnServer = new Collection <RemotePrintQueue>();

            foreach (var item in _controller.Context.RemotePrintQueues.Where(n => n.PrintServerId == server.FrameworkServerId))
            {
                if (!queuesOnServer.Contains(item.Name))
                {
                    queuesMissingOnServer.Add(item);
                }
            }

            SortableBindingList <PrintQueueInUse> queuesInUse        = _controller.SelectQueuesInUse(server);
            Collection <Tuple <string, string> >  queuesAndScenarios = new Collection <Tuple <string, string> >();

            foreach (string queueName in queuesMissingOnServer.Select(q => q.Name))
            {
                PrintQueueInUse queue = queuesInUse.Where(q => q.QueueName == queueName).FirstOrDefault();

                if (queue != null)
                {
                    queuesAndScenarios.Add(new Tuple <string, string>(queueName, queue.ScenarioName));
                }
                else
                {
                    queuesAndScenarios.Add(new Tuple <string, string>(queueName, string.Empty));
                }
            }

            if (queuesMissingOnServer.Count > 0)
            {
                changesExist = true;

                // If there are queues missing on the server, the user selects which queues to forcefully remove from the database, EVEN IF THEY ARE BEING USED IN A SCENARIO
                using (PrintQueueRefreshForm form = new PrintQueueRefreshForm(queuesAndScenarios, Properties.Resources.RemoveQueues.FormatWith('\n'), "Remove", "Remove Missing Queues From Database", "Force Remove"))
                {
                    DialogResult result = form.ShowDialog(this);
                    if (result == DialogResult.OK)
                    {
                        foreach (string queue in form.SelectedQueues)
                        {
                            RemotePrintQueue remoteQueue = queuesMissingOnServer.Where(q => q.Name == queue).FirstOrDefault();
                            _controller.Context.RemotePrintQueues.Remove(remoteQueue);
                        }

                        SaveChanges();
                        RefreshQueueDisplay(server);
                    }
                }
            }

            return(changesExist);
        }
        private static RemotePrintQueue CreatePrintQueue(string name, string platform, string inventoryId)
        {
            RemotePrintQueue queue = new RemotePrintQueue();

            queue.RemotePrintQueueId = SequentialGuid.NewGuid();
            queue.Name      = name;
            queue.PrinterId = inventoryId;
            queue.Active    = true;

            return(queue);
        }
 /// <summary>
 /// Because Queue name is part of the primary key, we can't just change the name.
 /// We have to delete the old one and add it new.  This will work as long as the
 /// new name doesn't already exist.
 /// </summary>
 /// <param name="queueToDelete"></param>
 /// <param name="server"></param>
 /// <param name="newQueueName"></param>
 private void EditQueue(RemotePrintQueue queueToDelete, FrameworkServer server, string newQueueName)
 {
     if (CanRemoveQueue(queueToDelete))
     {
         RemoveQueue(queueToDelete);
         if (!ManuallyAddQueue(server, newQueueName))
         {
             //At this point the data context is in a bad state.  Reload.
             ReloadForm();
         }
     }
 }
        private void removeAssociation_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GridViewRowInfo row = printQueue_GridView.SelectedRows.FirstOrDefault();

            if (row != null)
            {
                GridViewCellInfo otherCell = row.Cells[QueueColumns.Name];

                RemotePrintQueue queue = _controller.Context.RemotePrintQueues.Where(x => x.Name == otherCell.Value.ToString()).FirstOrDefault();
                _controller.Context.RemotePrintQueues.Remove(queue);
                _controller.Context.SaveChanges();

                row.Delete();

                printQueue_GridView.Refresh();
            }
        }
        /// <summary>
        /// Processes queues that are resident on the Print Server but missing from
        /// the database.  The user has the option of adding these new queues to the
        /// database.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="queuesOnServer">The queues on server.</param>
        /// <returns></returns>
        private bool FindMissingDatabaseQueues(FrameworkServer server, Collection <string> queuesOnServer)
        {
            bool changesExist = false;

            // Determine if any of the queues found above for the print server are missing
            // from the database.
            Collection <string> queuesMissingInDatabase = new Collection <string>();

            foreach (string name in queuesOnServer)
            {
                // If the queue name doesn't already exist in the queues for the server then add it.
                // Note: We don't need to use n.Name.Equals(name, StringComparison.OrdinalIgnoreCase) because the LINQ is translated into SQL which is case insensitive
                bool exists = _controller.Context.RemotePrintQueues.Any(n => n.PrintServerId == server.FrameworkServerId && n.Name == name);

                if (!exists)
                {
                    queuesMissingInDatabase.Add(name);
                }
            }

            if (queuesMissingInDatabase.Count > 0)
            {
                changesExist = true;

                // If there are queues missing in the database, the user is prompted to select which ones to add to it.
                using (PrintQueueRefreshForm form = new PrintQueueRefreshForm(queuesMissingInDatabase, Properties.Resources.AddQueues, "Add", "Add Missing Queues To Database"))
                {
                    DialogResult result = form.ShowDialog(this);
                    if (result == DialogResult.OK)
                    {
                        foreach (string queue in form.SelectedQueues)
                        {
                            RemotePrintQueue newQueue = CreatePrintQueue(queue);
                            newQueue.PrintServer = server;

                            _controller.Context.RemotePrintQueues.Add(newQueue);
                        }

                        SaveChanges();
                        RefreshQueueDisplay(server);
                    }
                }
            }

            return(changesExist);
        }
        private bool CanRemoveQueue(RemotePrintQueue queue)
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                List <string> queueUsages = GetScenariosUsingQueue(context, queue.RemotePrintQueueId.ToString()).ToList();

                if (queueUsages.Any())
                {
                    StringBuilder listString = new StringBuilder("\n");
                    listString.Append(string.Join(",\n", queueUsages));
                    listString.Append("\n\n");
                    MessageBox.Show(Resources.QueuesInUse.FormatWith(queue.Name, listString), "Remove Queue", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }

                return(true);
            }
        }
        private bool ManuallyAddQueue(FrameworkServer server, string queueName)
        {
            RemotePrintQueue queue = CreatePrintQueue(queueName);

            queue.PrintServerId = server.FrameworkServerId;
            _controller.Context.RemotePrintQueues.Add(queue);

            try
            {
                //This will throw if there is already an existing queue with the same name for the selected server.
                SaveChanges();
            }
            catch (UpdateException)
            {
                MessageBox.Show("'{0}' already exists.".FormatWith(queueName), "Add {0} Queue".FormatWith(_serverType.ToString()), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                _controller.Context.RemotePrintQueues.Remove(queue);
                SetDefaultCursor();
                return(false);
            }
            RefreshQueueDisplay(server);
            return(true);
        }
        /// <summary>
        /// Manually remove a print queue from a print server.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void removeQueue_ToolStripButton_Click(object sender, EventArgs e)
        {
            RemotePrintQueue queue = SelectedQueue;

            if (queue != null)
            {
                if (CanRemoveQueue(queue))
                {
                    DialogResult dialogResult = MessageBox.Show
                                                (
                        Properties.Resources.RemoveQueueManually.FormatWith(queue.Name),
                        "Remove Queue",
                        MessageBoxButtons.OKCancel,
                        MessageBoxIcon.Question
                                                );

                    if (dialogResult == DialogResult.OK)
                    {
                        RemoveQueue(queue);
                        SaveChanges();
                    }
                }
            }
        }
 private void RemoveQueue(RemotePrintQueue queue)
 {
     _controller.Context.RemotePrintQueues.Remove(queue);
     _printQueues.Remove(queue);
 }