private bool PrintDoc(FileSendOnNet file)
        {
            PclFileID = this.PostFile2Server();
            if (!String.IsNullOrWhiteSpace(PclFileID))
            {
                /**Post提交成功**下载文件*/
                String PclFileName = null;
                Thread.Sleep(300);
                int TimeCount = 0;
                while (String.IsNullOrEmpty(PclFileName = this.DownloadPCLFile()))
                {
                    //未准备好
                    if (TimeCount++ < 10)
                    {
                        Thread.Sleep(500);
                    }
                }


                if (!String.IsNullOrEmpty(PclFileName))
                {
                    /*--下载成功-*/
                    SendPCL2Printer s2p = new SendPCL2Printer();
                    return(s2p.SendFile2Printer(PclFileName, file.GetPrinterName()));
                }
            }
            return(false);
        }
Пример #2
0
/**
 *
 *
 *
 * */
//public bool ReadFileHeader(Socket socketClient, CommunicationType type, String filename)
//{
//        FileSendOnNet myFile = new FileSendOnNet(filename);
//        if (type == CommunicationType.Send2Receive)
//        {
//            myFile.SendFileRequestedCmd_SendFile(socketClient);
//        }
//        else if (type == CommunicationType.Send2Print)
//        {
//            myFile.SendFileRequestedCmd_PrintFile(socketClient);
//        }
//        else
//        {
//            Debug.Assert(false);
//        }

//        return true;
//}

/**
 *
 *
 *
 * */
        /* private static CommunicationType RcvOperationHeader(Socket client)
         * {
         *   FileSendOnNet myFile = new FileSendOnNet();
         *   return  myFile.RcvFileRequestedCmd(client);
         * }*/
        /**
         *
         *
         *
         * */
        private static FileSendOnNet RcvOperationHeader_EXT(Socket client)
        {
            FileSendOnNet myFile = new FileSendOnNet();

            myFile.RcvFileRequestedCmd(client);
            return(myFile);
        }
 public PrintDocThread(FileSendOnNet filefullpath)
 {
     this.Init();
     file           = filefullpath;
     printerOnLocal = new ParseFileOnLocal2Print(file);
     printerOnNet   = new ParseFileOnNet2Print(file);
 }
Пример #4
0
        /**
         *       保存提交信息到本地,
         *写入提交记录
         *
         */
        public void WriteSubmitRecord2Disk_NoPay(FileSendOnNet fson)
        {
            /*
             * 文件拷贝
             */
            {
                String from = fson.FileFullPath;
                String to   = GetFileFullPath_SubmitDocPath() + fson.GetFileName();
                File.Move(from, to);
                fson.FileFullPath = to;
            }

            this.Wait();
            try
            {
                PrintRecordItem PRI = new PrintRecordItem(fson);

                PRI.WriteSubmitRecord2Disk(true);

                PrintSubmitItems.Add(PRI);
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(this.GetType(), e);
            }
            this.Release();
        }
        private static bool ReadServerPermission(Socket client)
        {
#if ReceiveTimeout
            client.ReceiveTimeout = PhonePcCommunication.RecvTimeOut;
#endif
            FileSendOnNet fileRcv = new FileSendOnNet();
            return(fileRcv.ReadServerPermission(client));
        }
Пример #6
0
/**
 *
 * TCP 服务器接收文件时发生
 *
 * */
        public static bool RcvFileFromClient(Socket client)
        {
            /*接受文件头*/

            //请求头
            FileSendOnNet     fson  = RcvOperationHeader_EXT(client);
            CommunicationType cType = fson.GetCommunicationType();

            if (cType == CommunicationType.Send2Print)
            {
                //打印文件
                SendServerPermission(client);
                RcvFileRawData2Print(client);
            }
            else if (cType == CommunicationType.Send2Receive)
            {
                //发送文件
                SendServerPermission(client);
                RcvFileRawData2Save(client);
            }
            else if (cType == CommunicationType.GetPrinterListXml)
            {
                //客户获取打印机列表
                //发送本地打印机列表XML文件
                SendServerPermission(client);
                SendPrinterList(client);
            }
            else if (cType == CommunicationType.Send2PrintNoPay)
            {
                //打印文件--未付款
                //返回客户端,订单号。
                SendServerPermission(client);
                //接受文件到本地磁盘
                RcvFileRawData2Save_NoPay(client);
                //PrintRecord pp = new PrintRecord();
                //pp.WriteRecord2Disk(file);
            }
            else if (cType == CommunicationType.GetPriceById)
            {
                //客户获取价格
                //
                SendServerPermission(client);
                SendPrinterPrice(client, fson);
                //String id fson.GetProperty("orderid_suffix","");

                //SendPrinterList(client);
            }
            else
            {
                //Debug.Assert(false);
            }

            /*返回客户端权限*/
            return(true);
        }
Пример #7
0
 public void WriteRecord2Disk(FileSendOnNet fson)
 {
     try
     {
         PrintRecordItem PRI      = new PrintRecordItem(fson);
         String          FilePath = GetFileFullPath();
         PRI.WriteThisRecord2Disk(FilePath);
     }catch (Exception e) {
         LogHelper.WriteLog(this.GetType(), e);
     }
 }
Пример #8
0
 public PrintRecordItem(FileSendOnNet sson)
 {
     this._phoneNumber = sson._PhoneNumber;
     this._phoneType   = sson._PhoneType;
     this._androidOs   = sson._OsNumber;
     this.PParamcopies = sson.PParamcopies;
     this.PParamcolor  = sson.PParamcolor;
     this.PParamRange  = sson.PParamRange;
     this.PParam2Paper = sson.PParam2Paper;
     this.Paper_Type   = "自动适应纸张大小";
     this.PrinterName  = sson.GetPrinterName();
 }
        public static FileSendOnNet RcvFileRawData2Save(Socket client)
        {
            FileSendOnNet fileRcv = RcvFileRawData(client);

            if (fileRcv.mFileFullPath == null)
            {
            }
            else
            {
                OpenFileInExploer(fileRcv);
            }
            return(fileRcv);
        }
        private static bool SendFileRawData(Socket socketClient, String filepath, IPAddress address, int port)
        {
            FileSendOnNet file = new FileSendOnNet(filepath);

            if (socketClient.Connected == false)
            {
                socketClient.Connect(address, port);
            }

            file.SendFileInfo(socketClient);
            file.SendFile(socketClient);

            return(true);
        }
        public static FileSendOnNet RcvFileRawData2Print(Socket client)
        {
            FileSendOnNet fileRcv = RcvFileRawData(client);

            if (fileRcv.mFileFullPath == null)
            {
                Debug.WriteLine("打印命令:未接受到完整文件");
            }
            else
            {
                PrintDocThread pdt = new PrintDocThread(fileRcv);
                pdt.StartPrint();
            }



            return(fileRcv);
        }
Пример #12
0
        /// <summary>
        /// 保存到,未付款打印队列
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public static FileSendOnNet RcvFileRawData2Save_NoPay(Socket client)
        {
            FileSendOnNet fileRcv = RcvFileRawData(client);

            if (fileRcv.mFileFullPath == null)
            {
            }
            else
            {
                //文件拷贝带走。

                //OpenFileInExploer(fileRcv);
                //保存到提交记录

                PrintRecord pp = new PrintRecord();
                pp.WriteSubmitRecord2Disk_NoPay(fileRcv);
            }
            return(fileRcv);
        }
Пример #13
0
        /**
         *发送本机下挂的所有打印机
         *
         *
         */
        public static void SendPrinterPrice(Socket client, FileSendOnNet fson)
        {
            String orderid       = fson.GetProperty("orderid_suffix", "");
            String cmd           = fson.GetProperty("cmd", "");
            String asyncNotify_t = fson.GetProperty("ppneedasyncnotify", "false");

            if ("getprice".Equals(cmd))
            {
                if (!String.IsNullOrEmpty(orderid))
                {
                    PrintRecordItem pri = PrintSubmitItems.QueryId(orderid);
                    if (pri != null)
                    {
                        String price_t = pri.GetPriceJson();
                        client.Send(System.Text.Encoding.UTF8.GetBytes(price_t));
                        return;
                    }
                }
            }
            else if ("PrintDoc".Equals(cmd))
            {
                //已经付费---打印之
                if (!String.IsNullOrEmpty(orderid))
                {
                    PrintRecordItem pri = PrintSubmitItems.QueryId(orderid);
                    if (pri != null)
                    {
                        String result_t = pri.GetPrintCompletedJson();
                        client.Send(System.Text.Encoding.UTF8.GetBytes(result_t));
                        return;
                    }

                    if ("true".Equals(asyncNotify_t))
                    {
                        LogHelper.WriteLogError(typeof(PhonePcCommunication), "需要异步通知" + pri.WriteSubmitRecord2Disk(false));
                    }
                }
            }
            else
            {
            }
        }
/**
 *
 *
 */
        public static void OpenFileInExploer(FileSendOnNet fileRcv)
        {
            Process[] wordProcesses = Process.GetProcessesByName("explorer");
            bool      processExit   = false;

            foreach (Process p in wordProcesses)
            {
                if (p.MainWindowTitle == fileRcv.GetFolder())
                {
                    processExit = true;
                }
                else
                {
                }
            }
            if (processExit == false)
            {
                System.Diagnostics.Process.Start("Explorer.exe", @"/select," + fileRcv.mFileFullPath);
            }
        }
Пример #15
0
        /// <summary>
        /// 现阶段只打印一次
        /// </summary>
        /// <returns></returns>
        public String GetPrintCompletedJson()
        {
            lock (this) {
                JObject       jo_t    = new JObject();
                FileSendOnNet fileRcv = new FileSendOnNet();
                fileRcv.Parse4PrintRecord(this);

                if (this.PrintOnce == true)
                {
                    jo_t.Add("result", "fali");
                    jo_t.Add("ServerInfo", "has print once");
                    return(jo_t.ToString());
                }

                if (fileRcv.mFileFullPath == null)
                {
                    jo_t.Add("result", "fali");
                    jo_t.Add("ServerInfo", "no file");
                }
                else
                {
                    PrintDocThread pdt      = new PrintDocThread(fileRcv);
                    String         reslut_t = pdt.PrintDocment();
                    if (String.IsNullOrEmpty(reslut_t))
                    {
                        jo_t.Add("result", "success");
                        this.PrintOnce = true;
                    }
                    else
                    {
                        jo_t.Add("result", "fali");
                        jo_t.Add("ServerInfo", reslut_t);
                    }
                }
                //jo_t.Add("price2pay", this._Price);
                return(jo_t.ToString());
            }
        }
/**
 *
 *
 *
 * */
        private static bool SendOperationHeader(Socket socketClient, CommunicationType type, String filename)
        {
            FileSendOnNet myFile = new FileSendOnNet(filename);

            if (type == CommunicationType.Send2Receive)
            {
                myFile.SendFileRequestedCmd_SendFile(socketClient);
            }
            else if (type == CommunicationType.Send2Print)
            {
                myFile.SendFileRequestedCmd_PrintFile(socketClient);
            }
            else if (type == CommunicationType.GetPrinterListXml)
            {
                myFile.SendFileRequestedCmd_GetPrinters(socketClient);
            }
            else
            {
                Debug.Assert(false);
            }

            return(true);
        }
Пример #17
0
 public PrintRecordItem(FileSendOnNet sson)
 {
     /*-----------------------------------*/
     this._OrderId        = sson.GetOrderId();
     this._OrderId_Suffix = sson.GetOrderId_Suffix();
     this._UserName       = sson.GetUserName();
     this._HavePay        = sson.GetPrice2Pay();
     this._Price          = sson.GetPrice2Pay();
     this._FileFullPath   = sson.FileFullPath;
     /*-----------------------------------*/
     this._phoneNumber  = sson._PhoneNumber;
     this._phoneType    = sson._PhoneType;
     this._androidOs    = sson._OsNumber;
     this._PParamcopies = sson.PParamcopies;
     this._PParamcolor  = sson.PParamcolor;
     this._PParamRange  = sson.PParamRange;
     this._PParam2Paper = sson.PParam2Paper;
     this._Paper_Type   = "自动适应纸张大小";
     this._PrinterName  = sson.GetPrinterName();
     //this.PrinterDriveName = PrintLocal.GetPrinterDrivenName(this._PrinterName);
     this.PrinterDriveName = sson.GetPrinterDriveName();
     this._AsyncNofify     = sson.GetProperty("ppneedasyncnotify", "false");
 }
        private bool PrintDoc(FileSendOnNet file)
        {
            String FilePath = file.mFileFullPath;
            int    flag     = 0;

            PCLConvertCS.PCLConvert pc    = new PCLConvertCS.PCLConvert();
            PCLConvertCS.PDFConvert pcpdf = new PCLConvertCS.PDFConvert();
            string fileOut = file.GetPCLprnfullPath();
            string printer;
            string result = null;

            if (file.GetPrinterName().Equals(""))
            {
                printer = PrintLocal.GetPCLPrinter();
            }
            else
            {
                printer = file.GetPrinterName();
            }

            if (FilePath.ToLower().EndsWith("doc") || FilePath.ToLower().EndsWith("docx"))
            {
                //Step 1
                try{
                    result = pc.WordToPCL(readArgs(FilePath), fileOut, printer);
                    if (result != null)
                    {
                        LogHelper.WriteLog(this.GetType(), "WORD2PCL 转换失败" + result);
                        result = pc.Word2PDFToPCL(readArgs(FilePath), fileOut, printer);
                    }
                }catch (Exception e) {
                    LogHelper.WriteLog(this.GetType(), e.Message);
                }
                finally {
                    if (result == null)
                    {
                        flag = 1;    //转换成功
                    }
                }
            }
            if (FilePath.ToLower().EndsWith("pdf"))
            {
                try
                {
                    result = pcpdf.ConvertPdf2pcl(readArgs(FilePath), fileOut);
                    if (result == null)
                    {
                        flag = 1;     //装换成功
                    }
                    else
                    {
                        //转换失败
                    }
                }
                catch (Exception e)
                {
                    LogHelper.WriteLog(this.GetType(), e.Message);
                }
            }
            if (FilePath.ToLower().EndsWith("jpg") || FilePath.ToLower().EndsWith("jpeg") || FilePath.ToLower().EndsWith("JPEG"))
            {
                result = pc.JPGToPCL(FilePath, fileOut);
                if (result == null)
                {
                    flag = 1;
                }
            }
            if (FilePath.ToLower().EndsWith("xlsx") || FilePath.ToLower().EndsWith("xlsm") || FilePath.ToLower().EndsWith("xls"))
            {
#if false
                string sPath = System.IO.Path.GetTempPath() + System.IO.Path.GetFileName(FilePath).Replace(".", "_") + ".pdf";
                Method m     = new Method();

                if (m.Convert2PDF(FilePath, sPath, Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF))
                {
                    string result = pcpdf.ConvertPdf2pcl(readArgs(sPath), fileOut);
                    if (result == null)
                    {
                        flag = 1;
                    }
                }
#else
                string sPath = System.IO.Path.GetTempPath() + System.IO.Path.GetFileNameWithoutExtension(FilePath) + Guid.NewGuid().ToString() + ".pdf";
                Method m     = new Method();

                if (m.Convert2PDF(FilePath, sPath, Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF))
                {
#if true
                    result = pcpdf.ConvertPdf2pcl(readArgs(sPath), fileOut);
#else
                    string result = "测试";
#endif
                    if (result == null)
                    {
                        flag = 1;
                    }
                }
#endif
            }
            if (flag == 1)
            {
                //文件转换成功-发送到打印机
                LogHelper.WriteLog(this.GetType(), "文件转换成功");
                SendPCL2Printer s2p = new SendPCL2Printer();
                return(s2p.SendFile2Printer(fileOut, printer));
            }
            else
            {
                LogHelper.WriteLog(this.GetType(), "文件转换:" + result + "&&&" + FilePath);
                //文件转换失败
                return(false);
            }
            //return false;
        }
Пример #19
0
        public static FileSendOnNet RcvFileRawData(Socket client)
        {
            FileSendOnNet fileRcv        = new FileSendOnNet();
            long          FileLength     = 0;
            long          ReceivedLength = 0;
            FileStream    fs             = null;

            try
            {
                ;
                if (fileRcv.RcvFileHeader(client))
                {
#if true
                    LogHelper.WriteLog(typeof(PhonePcCommunication), "+++++++开始接受文件:" + fileRcv.GetFileName());
#endif
                    fs         = new FileStream(fileRcv.mFileFullPath, FileMode.Create);
                    FileLength = fileRcv.FileSize;
                    int    RcvOneReadFile = 0;
                    byte[] recvBytes      = new byte[1024];
                    //1.2接收文件内容
                    while (ReceivedLength < FileLength)
                    {
                        long UnReadLength = FileLength - ReceivedLength;
                        if (UnReadLength == 0)
                        {
                            break;
                        }
                        //有数据
                        RcvOneReadFile = client.Receive(
                            recvBytes,
                            0,
                            recvBytes.Length,
                            SocketFlags.None);

                        if (RcvOneReadFile == 0)
                        {
                            Thread.Sleep(200);
                            if (client.Available > 0)
                            {
                            }
                            else
                            {
                                Thread.Sleep(200);
                            }
                        }
                        else
                        {
                            ReceivedLength += RcvOneReadFile;
                            fs.Write(recvBytes, 0, RcvOneReadFile);
                        }
                    }
                }
            }
            catch (IOException e)
            {
                Debug.WriteLine("Request error: " + e);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Request error: " + ex);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Flush();
                    fs.Close();
                    fs.Dispose();
                }
                //  int test_t=-1;
                //  byte[] recvBytes = new byte[1024];
                if (ReceivedLength == FileLength)
                {
#if true
                    LogHelper.WriteLog(typeof(PhonePcCommunication), "-------文件【已接受】:" + fileRcv.GetFileName());
#endif
                    //test_t = client.Receive(
                    //           recvBytes,
                    //           0,
                    //           recvBytes.Length ,
                    //           SocketFlags.None);
                }
                else
                {
#if true
                    LogHelper.WriteLog(typeof(PhonePcCommunication), "********文件【接收失败】:" + fileRcv.GetFileName());
#endif
                    fileRcv.mFileFullPath = null;
                    DeleteFile(fileRcv);
                }
            }

            return(fileRcv);
        }
        public static FileSendOnNet RcvFileRawData(Socket client)
        {
            FileSendOnNet fileRcv        = new FileSendOnNet();
            long          FileLength     = 0;
            long          ReceivedLength = 0;
            FileStream    fs             = null;

            try
            {
                ;
                if (fileRcv.RcvFileHeader(client))
                {
                    fs         = new FileStream(fileRcv.mFileFullPath, FileMode.Create);
                    FileLength = fileRcv.FileSize;
                    int    RcvOneReadFile = 0;
                    byte[] recvBytes      = new byte[1024 * 1024];
                    //1.2接收文件内容
                    while (ReceivedLength < FileLength)
                    {
                        long UnReadLength = FileLength - ReceivedLength;
                        if (UnReadLength == 0)
                        {
                            break;
                        }
                        //有数据
                        RcvOneReadFile = client.Receive(
                            recvBytes,
                            0,
                            recvBytes.Length,
                            SocketFlags.None);

                        if (RcvOneReadFile == 0)
                        {
                            Thread.Sleep(200);
                            if (client.Available > 0)
                            {
                            }
                            else
                            {
                                //  break;
                            }
                        }
                        else
                        {
                            ReceivedLength += RcvOneReadFile;
                            fs.Write(recvBytes, 0, RcvOneReadFile);
                        }
                    }
                }
            }
            catch (IOException e)
            {
                Debug.WriteLine("Request error: " + e);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Request error: " + ex);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Flush();
                    fs.Close();
                }
                int    test_t    = -1;
                byte[] recvBytes = new byte[1024];
                if (ReceivedLength == FileLength)
                {
                    test_t = client.Receive(
                        recvBytes,
                        0,
                        recvBytes.Length,
                        SocketFlags.None);
                }
                else
                {
                    fileRcv.mFileFullPath = null;
                    DeleteFile(fileRcv);
                }
            }

            return(fileRcv);
        }
/**
 *
 *
 */
        public static void DeleteFile(FileSendOnNet fileRcv)
        {
            LibCui.DeleteFile(fileRcv.mFileFullPath);
        }
        private bool PrintDoc(FileSendOnNet file)
        {
            String FilePath = file.mFileFullPath;
            int    flag     = 0;

            PCLConvertCS.PCLConvert pc    = new PCLConvertCS.PCLConvert();
            PCLConvertCS.PDFConvert pcpdf = new PCLConvertCS.PDFConvert();
            string fileOut = file.GetPCLprnfullPath();
            string printer;

            if (file.GetPrinterName().Equals(""))
            {
                printer = PrintLocalPrint.LocalPrinter.DefaultPrinter();
            }
            else
            {
                printer = file.GetPrinterName();
            }

            if (FilePath.ToLower().EndsWith("doc") || FilePath.ToLower().EndsWith("docx"))
            {
                string result = pc.WordToPCL(readArgs(FilePath), fileOut, printer);
                if (result == null)
                {
                    flag = 1;
                }
            }
            if (FilePath.ToLower().EndsWith("pdf"))
            {
                string result = pcpdf.ConvertPdf2pcl(readArgs(FilePath), fileOut);
                if (result == null)
                {
                    flag = 1;
                }
            }
            if (FilePath.ToLower().EndsWith("jpg") || FilePath.ToLower().EndsWith("jpeg") || FilePath.ToLower().EndsWith("JPEG"))
            {
                string result = pc.JPGToPCL(FilePath, fileOut);
                if (result == null)
                {
                    flag = 1;
                }
            }
            if (FilePath.ToLower().EndsWith("xlsx") || FilePath.ToLower().EndsWith("xlsm") || FilePath.ToLower().EndsWith("xls"))
            {
#if false
                string sPath = System.IO.Path.GetTempPath() + System.IO.Path.GetFileName(FilePath).Replace(".", "_") + ".pdf";
                Method m     = new Method();

                if (m.Convert2PDF(FilePath, sPath, Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF))
                {
                    string result = pcpdf.ConvertPdf2pcl(readArgs(sPath), fileOut);
                    if (result == null)
                    {
                        flag = 1;
                    }
                }
#else
                string sPath = System.IO.Path.GetTempPath() + System.IO.Path.GetFileNameWithoutExtension(FilePath) + Guid.NewGuid().ToString() + ".pdf";
                Method m     = new Method();

                if (m.Convert2PDF(FilePath, sPath, Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF))
                {
#if true
                    string result = pcpdf.ConvertPdf2pcl(readArgs(sPath), fileOut);
#else
                    string result = "测试";
#endif
                    if (result == null)
                    {
                        flag = 1;
                    }
                }
#endif
            }
            if (flag == 1)
            {
                //文件转换成功-发送到打印机
                SendPCL2Printer s2p = new SendPCL2Printer();

                return(s2p.SendFile2Printer(fileOut, printer));
            }
            else
            {
                Debug.Assert(false);
                //文件转换失败
                return(false);
            }
        }
 public ParseFileOnLocal2Print(FileSendOnNet filefullpath)
 {
     file = filefullpath;
 }
        private static void SendServerPermission(Socket client)
        {
            FileSendOnNet fileRcv = new FileSendOnNet();

            fileRcv.SendServerPermission(client);
        }
/**
 *
 *
 *
 * */
//public bool ReadFileHeader(Socket socketClient, CommunicationType type, String filename)
//{
//        FileSendOnNet myFile = new FileSendOnNet(filename);
//        if (type == CommunicationType.Send2Receive)
//        {
//            myFile.SendFileRequestedCmd_SendFile(socketClient);
//        }
//        else if (type == CommunicationType.Send2Print)
//        {
//            myFile.SendFileRequestedCmd_PrintFile(socketClient);
//        }
//        else
//        {
//            Debug.Assert(false);
//        }

//        return true;
//}

/**
 *
 *
 *
 * */
        private static CommunicationType RcvOperationHeader(Socket client)
        {
            FileSendOnNet myFile = new FileSendOnNet();

            return(myFile.RcvFileRequestedCmd(client));
        }