static void Main(string[] args) { // parse args if (args.Length < 4 || args.Length > 6) { UsageAndExit(); } var pseudoUri = new Uri(string.Format("lpd://{0}", args[0])); var host = pseudoUri.Host; var port = 515; if (!pseudoUri.IsDefaultPort) { port = pseudoUri.Port; } var queue = args[1]; var user = args[2]; var localFilename = args[3]; var remoteFilename = (args.Length > 4) ? args[4] : Path.GetFileName(localFilename); var localHostname = (args.Length > 5) ? args[5] : System.Net.Dns.GetHostName().Split('.')[0]; // sanity check var fileInfo = new FileInfo(localFilename); if (!fileInfo.Exists) { Console.Error.WriteLine("Local file '{0}' does not exist!", localFilename); UsageAndExit(); } var fileSize = fileInfo.Length; // prepare the JobInfo var jobInfo = new JobInfo { DataFilePath = localFilename, DataFileSize = fileSize, DocumentName = remoteFilename, HostName = localHostname, Status = JobInfo.JobStatus.ReadyToPrint, TimeOfArrival = DateTimeOffset.Now, UserName = user }; // prepare the sender var sender = new LpdSender { Host = host, Port = port, QueueName = queue }; sender.Send(jobInfo); Console.WriteLine("Job sent."); }
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 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); } } }