示例#1
0
        private static void WriteControlFile(LPRJob job, NetworkStream stream, string machineName, string userName, string jobIdentifier)
        {
            var controlFile = new StringBuilder();

            controlFile.Append($"H{machineName}\n");
            controlFile.Append($"P{userName}\n");
            controlFile.Append($"{job.FileType}dfA{jobIdentifier}\n");
            if (job.InputFile != null)
            {
                controlFile.Append($"N{job.InputFile.GetType().Name}\n");
            }
            else
            {
                controlFile.Append($"N{job.Path}\n");
            }

            if (job.Class != null)
            {
                controlFile.Append($"C{job.Class}\n");
            }
            if (job.JobName != null)
            {
                controlFile.Append($"J{job.JobName}\n");
            }

            stream.WriteASCII($"\x02{controlFile.Length} cfA{jobIdentifier}\n");
            CheckResult(stream);

            stream.WriteASCII(controlFile.ToString());
            stream.WriteByte(0);
            CheckResult(stream);
        }
示例#2
0
        private static void WriteDataFile(LPRJob job, NetworkStream stream, string jobIdentifier)
        {
            long fileSize;

            if (job.InputFile != null)
            {
                fileSize = job.InputFile.Length;
            }
            else
            {
                fileSize = new FileInfo(job.Path).Length;
            }

            stream.WriteASCII($"\x03{fileSize} dfA{jobIdentifier}\n");
            CheckResult(stream);

            Stream fileStream;

            if (job.InputFile != null)
            {
                fileStream = job.InputFile;
            }
            else
            {
                fileStream = new FileStream(job.Path, FileMode.Open);
            }

            fileStream.CopyTo(stream);
            stream.WriteByte(0);
            CheckResult(stream);
        }
示例#3
0
 protected bool Equals(LPRJob other)
 {
     return(string.Equals(Server, other.Server) &&
            string.Equals(Printer, other.Printer) &&
            string.Equals(Path, other.Path) &&
            string.Equals(FileType, other.FileType) &&
            string.Equals(Class, other.Class) &&
            string.Equals(JobName, other.JobName) &&
            SendDataFileFirst == other.SendDataFileFirst &&
            SunOsCompatibility == other.SunOsCompatibility);
 }
示例#4
0
        public Task PrintFileAsync(LPRJob job)
        {
            var client      = new TcpClient();
            var connectInfo = new ConnectInfo <LPRJob>
            {
                Client = client,
                Job    = job,
            };

            return(Task.Factory.FromAsync(client.BeginConnect, client.EndConnect, job.Server, LPRPort, connectInfo)
                   .ContinueWith(OnConnectLPR));
        }