Example #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="printJob">management base object as a print job</param>
        /// <param name="host">host name</param>
        public PrintJobData(ManagementBaseObject printJob, string host)
        {
            if (printJob == null)
            {
                return;
            }

            ServerHost    = host;
            PrintJob      = printJob;
            PrintJobTitle = new PrintJobTitle();

            try
            {
                JobStatus = new PrintJobStatus(PrintJobStatusEnum.None, null);

                string name;
                int    id;

                // extract printer name and job Id
                PrintHelper.ExtractNameAndId(printJob, out name, out id);

                PrintJobTitle.PrinterName = name;
                PrintJobTitle.JobID       = id;
                PrintJobTitle.Document    = printJob.Properties["Document"].Value.ToString();
                PrintJobTitle.Host        = printJob.Properties["HostPrintQueue"].Value.ToString();
                if (!string.IsNullOrWhiteSpace(PrintJobTitle.Host))
                {
                    PrintJobTitle.Host = PrintJobTitle.Host.Replace("\\", "").Trim();
                }

                PrintJobTitle.Owner = printJob.Properties["Owner"].Value.ToString();

                Color = false;
                string color = printJob.Properties["Color"].Value.ToString();
                if (!string.IsNullOrWhiteSpace(color))
                {
                    if (color.ToLower() != "monochrome")
                    {
                        Color = true;
                    }
                }

                JobStatus = printJob.JobStatus();

                int totalPages = -1;
                int.TryParse(printJob.Properties["TotalPages"].Value.ToString(), out totalPages);
                PrintJobTitle.TotalPages = totalPages;
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Wrong PrintJobData", ex);
            }
        }
        public PrintJobTitle(ManagementBaseObject printJob)
        {
            try
            {
                string prnterName;
                int    prntJobID;
                PrintHelper.ExtractNameAndId(printJob, out prnterName, out prntJobID);

                PrinterName = prnterName;
                JobID       = prntJobID;
                Document    = PrintHelper.ExtractDocumentName(printJob);
                Host        = PrintHelper.ExtractHost(printJob);
                Owner       = PrintHelper.ExtractOwner(printJob);
                if (!string.IsNullOrWhiteSpace(Host))
                {
                    Host = Host.Replace("\\", "").Trim();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex);
            }
        }