/// <summary>
        /// Adds the specified client data to the list of monitored queues.
        /// </summary>
        /// <param name="clientData">The client data.</param>
        public void Add(CitrixQueueClientData clientData)
        {
            if (clientData == null)
            {
                throw new ArgumentNullException("clientData");
            }

            lock (_registryEntriesLock)
            {
                List <PrinterRegistryEntry> list;
                if (!_registryEntries.TryGetValue(clientData.HostName, out list))
                {
                    _registryEntries.Add(clientData.HostName, list = new List <PrinterRegistryEntry>());
                }

                // Set the session start time locally so the clocks sync better
                clientData.SessionStart = DateTime.Now;
                list.Add(new PrinterRegistryEntry(clientData));
                TraceFactory.Logger.Debug("ADDED {0}:{1}".FormatWith(clientData.HostName, clientData.QueueName));

                //if (!_watcherStarted)
                //{
                //    //_watcher.Start();
                //    //_watcherStarted = true;
                //    _fileWriteTimer.Start();
                //}
            }
        }
        private void installer_PrintQueueInstalled(object sender, LocalPrintQueueInstalledEventArgs e)
        {
            // Figure out how long it will be before this worker is started.  This is important because
            // the Citrix print queue creation monitor has a cleanup timer, and it tries to talk to the
            // worker to determine if it doesn't respond.  If the worker is gone, then this will fail
            // and any registered queues being monitored will be purged.  This can also fail if the q
            // worker hasn't started yet because of this delay.  So send this information through with
            // the ClientData below so the monitor doesn't prematurely whack any registered queues.

            TimeSpan startupDelay;
            TimeSpan minStartupDelay = _minStartupDelay;
            TimeSpan maxStartupDelay = _maxStartupDelay;
            TimeSpan timeBuffer      = new TimeSpan(0, 30, 0);

            if (_randomizeStartupDelay)
            {
                startupDelay = maxStartupDelay.Add(timeBuffer);
            }
            else
            {
                startupDelay = minStartupDelay.Add(timeBuffer);
            }

            CitrixQueueClientData clientData = new CitrixQueueClientData
            {
                QueueName    = e.QueueName,
                HostName     = Environment.MachineName,
                UserName     = _credential.UserName,
                PrintDriver  = e.DriverName,
                SessionId    = SystemManifest.SessionId,
                StartupDelay = startupDelay
            };

            var endpoint = new Uri("http://{0}:{1}/{2}".FormatWith(_citrixServer, _credential.Port, WcfService.VirtualResource));

            clientData.EndPoint = endpoint;
            TraceFactory.Logger.Debug("Client Endpoint {0}".FormatWith(endpoint));

            _printClientData.Add(clientData);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PrinterRegistryEntry"/> class.
 /// </summary>
 public PrinterRegistryEntry(CitrixQueueClientData data)
 {
     _clientData = data;
 }