Esempio n. 1
0
        private void LogPrintJob(PrintJobData job)
        {
            Guid printJobClientId = Guid.Empty;

            // If extracting the ID fails, then do not report data on this job
            try
            {
                if (!string.IsNullOrEmpty(job.Document))
                {
                    printJobClientId = UniqueFile.ExtractId(job.Document.ToUpperInvariant());
                }
            }
            catch (FormatException)
            {
                TraceFactory.Logger.Warn("Bad document name: " + job.Document);
                // Do nothing.
                return;
            }

            if (printJobClientId == Guid.Empty)
            {
                return;
            }

            PrintServerJobLog logger = null;

            MonitoredQueueInfoCache printQueue = GetQueueInfo(job.PrinterName);

            if (printQueue != null)
            {
                logger = new PrintServerJobLog(printJobClientId, job, printQueue);
            }
            else
            {
                logger = new PrintServerJobLog(printJobClientId, job);
            }

            try
            {
                _dataLogger.SubmitAsync(logger);
                TraceFactory.Logger.Debug("Data posted to data log service.");
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error("Error posting data to the data log service.", ex);
            }
        }
Esempio n. 2
0
        private MonitoredQueueInfoCache GetQueueInfo(string queueName)
        {
            MonitoredQueueInfoCache cachedInfo = null;

            try
            {
                //Try to retrieve from the cache
                if (!_cache.TryGetValue(queueName, out cachedInfo))
                {
                    cachedInfo = new MonitoredQueueInfoCache(queueName)
                    {
                        PrintServer   = Environment.MachineName,
                        PrintServerOS = Environment.OSVersion.ToString()
                    };
                    _cache.Add(queueName, cachedInfo);
                }

                // Refresh queue data if older than 5 minutes
                if (cachedInfo.QueueSettingsRetrieved < DateTime.Now.AddMinutes(-5))
                {
                    PrintQueue queue = PrintQueueController.GetPrintQueue(queueName);
                    cachedInfo.Refresh(queue);

                    PrintJobRenderLocation location = PrintQueueController.GetJobRenderLocation(queue);
                    if (location != PrintJobRenderLocation.Unknown)
                    {
                        cachedInfo.RenderOnClient = (location == PrintJobRenderLocation.Client);
                    }
                    else
                    {
                        cachedInfo.RenderOnClient = null;
                    }

                    cachedInfo.QueueSettingsRetrieved = DateTime.Now;
                }
            }
            catch (Win32Exception ex)
            {
                TraceFactory.Logger.Error("Unable to get queue data for {0}".FormatWith(queueName), ex);
            }

            return(cachedInfo);
        }