public static void AddPrinter(PrinterInfo info)
 {
     Logger.DebugFormat("adding printer {0} ({1})", info.PrinterID, info.ShortName);
     lock (ManagementLock)
     {
         PrinterDictionary[info.PrinterID] = info;
     }
 }
示例#2
0
 public static void AddPrinter(PrinterInfo info)
 {
     Logger.DebugFormat("adding printer {0} ({1})", info.PrinterID, info.ShortName);
     lock (ManagementLock)
     {
         PrinterDictionary[info.PrinterID] = info;
     }
 }
 public PrinterInfoDrop(PrinterInfo info)
 {
     Info = info;
 }
示例#4
0
        public static void LoadConfig()
        {
            JObject jobject;

            Logger.Info("loading config");

            // set up defaults
            HttpListenPort            = 8080;
            LpdListenPort             = 515;
            JobDirectory              = Path.Combine(Util.ProgramDirectory, "Jobs");
            DeletionAgeMinutesOptions = new [] { 15, 30, 60, 120 };

            using (var r = new StreamReader(new FileStream(Path.Combine(Util.ProgramDirectory, "Config.json"), FileMode.Open, FileAccess.Read), Encoding.UTF8))
            {
                jobject = JObject.Parse(r.ReadToEnd());
            }

            if (jobject["HttpListenPort"] != null)
            {
                HttpListenPort = (int)jobject["HttpListenPort"];
            }

            if (jobject["LpdListenPort"] != null)
            {
                LpdListenPort = (int)jobject["LpdListenPort"];
            }

            if (jobject["JobDirectory"] != null)
            {
                JobDirectory = (string)jobject["JobDirectory"];
                if (!Path.IsPathRooted(JobDirectory))
                {
                    JobDirectory = Path.Combine(Util.ProgramDirectory, JobDirectory);
                }
            }

            if (jobject["DeletionAgeMinutesOptions"] != null)
            {
                DeletionAgeMinutesOptions = jobject["DeletionAgeMinutesOptions"].Select(opt => (int)opt).ToArray();
            }

            if (jobject["Printers"] != null)
            {
                foreach (JObject printer in jobject["Printers"])
                {
                    var shortName  = (string)printer["ShortName"];
                    var connection = (string)printer["Connection"];

                    uint distributionFactor = 1;
                    if (printer["DistributionFactor"] != null)
                    {
                        distributionFactor = (uint)printer["DistributionFactor"];
                    }

                    ISender sender;
                    if (connection == "LPD")
                    {
                        var lpdSender = new LpdSender
                        {
                            Host      = (string)printer["Host"],
                            QueueName = (string)printer["Queue"]
                        };
                        if (printer["Port"] != null)
                        {
                            lpdSender.Port = (int)printer["Port"];
                        }
                        sender = lpdSender;
                    }
                    else
                    {
                        throw new ArgumentException("unknown printer connection '" + connection + "'");
                    }

                    var printerInfo = new PrinterInfo
                    {
                        DistributionFactor = distributionFactor,
                        ShortName          = shortName,
                        Sender             = sender
                    };
                    Management.AddPrinter(printerInfo);
                }
            }
        }
 public PrinterInfoDrop(PrinterInfo info)
 {
     Info = info;
 }
示例#6
0
        public static void LoadConfig()
        {
            JObject jobject;

            Logger.Info("loading config");

            // set up defaults
            HttpListenPort = 8080;
            LpdListenPort = 515;
            JobDirectory = Path.Combine(Util.ProgramDirectory, "Jobs");
            DeletionAgeMinutesOptions = new [] { 15, 30, 60, 120 };

            using (var r = new StreamReader(new FileStream(Path.Combine(Util.ProgramDirectory, "Config.json"), FileMode.Open, FileAccess.Read), Encoding.UTF8))
            {
                jobject = JObject.Parse(r.ReadToEnd());
            }

            if (jobject["HttpListenPort"] != null)
            {
                HttpListenPort = (int)jobject["HttpListenPort"];
            }

            if (jobject["LpdListenPort"] != null)
            {
                LpdListenPort = (int)jobject["LpdListenPort"];
            }

            if (jobject["JobDirectory"] != null)
            {
                JobDirectory = (string)jobject["JobDirectory"];
                if (!Path.IsPathRooted(JobDirectory))
                {
                    JobDirectory = Path.Combine(Util.ProgramDirectory, JobDirectory);
                }
            }

            if (jobject["DeletionAgeMinutesOptions"] != null)
            {
                DeletionAgeMinutesOptions = jobject["DeletionAgeMinutesOptions"].Select(opt => (int) opt).ToArray();
            }

            if (jobject["Printers"] != null)
            {
                foreach (JObject printer in jobject["Printers"])
                {
                    var shortName = (string)printer["ShortName"];
                    var connection = (string)printer["Connection"];

                    uint distributionFactor = 1;
                    if (printer["DistributionFactor"] != null)
                    {
                        distributionFactor = (uint)printer["DistributionFactor"];
                    }

                    ISender sender;
                    if (connection == "LPD")
                    {
                        var lpdSender = new LpdSender
                        {
                            Host = (string) printer["Host"],
                            QueueName = (string) printer["Queue"]
                        };
                        if (printer["Port"] != null)
                        {
                            lpdSender.Port = (int)printer["Port"];
                        }
                        sender = lpdSender;
                    }
                    else
                    {
                        throw new ArgumentException("unknown printer connection '" + connection + "'");
                    }

                    var printerInfo = new PrinterInfo
                    {
                        DistributionFactor = distributionFactor,
                        ShortName = shortName,
                        Sender = sender
                    };
                    Management.AddPrinter(printerInfo);
                }
            }
        }