/// <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); }
/// <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); }