public ReceiptPrinter(LogClient log) { //m_log = log; m_printString = ""; }
// Public Methods // ======================================================================================== // ---------------------------------------------------------------------------------------- // Constructor with all fields // addr: IP address // port: port number // server: true if we are the server, false if we are the client // srcid: our id Ex: "VLS1" // destid: id of target Ex: "MFC1", "IOC1" ... // toacknak: time to wait for ack before re-sending (in seconds) // datalen: length of telegram, pad telegram if shorter than datalen. // fillchar: character to pad with // binary: true: telegrams are binary (IO) false: telegrams are ASCII (data) // tokeepalive: time to wait before sending keep alive mesage (seconds) 0 = disabled // ---------------------------------------------------------------------------------------- public ViaStdProto(IPAddress addr, int port, bool server, string srcid, string destid, int toacknak, int datalen, char fillchar, bool binary, int tokeepalive) { m_addr = addr; m_port = port; m_server = server; m_srcid = srcid; m_destid = destid; m_datalen = datalen; m_fillchar = fillchar; m_binary = binary; m_recSeqNum = 0; m_sendSeqNum = 1; m_readBuf = new ViaTelegram(); m_writeBuf = new ViaTelegram(); m_numResends = 0; m_recQ = new ConcurrentQueue<string>(); m_readQ = new ConcurrentQueue<string>(); m_dataWriteQueue = new ConcurrentQueue<string>(); m_ackWriteQueue = new ConcurrentQueue<int>(); m_keepaliveStr = "00 keep alive telegram "; m_socketLog = null;// MainWindow.logBook.requestLog("Kiosk_Socket" + m_port + ".log"); m_socketLog.log(LogTools.getStatusString("ViaStdProto", "ViaStdProto", "Creating socket: \n" + "Addr = " + m_addr + "\tPort = " + m_port + "\tServer = " + m_server + "\tSrc ID = " + m_srcid + "\tDest ID = " + m_destid + "\tData Length = " + m_datalen + "\tBinary = " + m_binary)); m_recvAccumulator = ""; if (toacknak <= 0) { toacknak = 5000; //default the value to 5 seconds if no value was passed } m_toacknak = new TimeSpan(0, 0, 0, 0, toacknak); m_sendTimeout = m_toacknak; m_toKeepaliveSend = new TimeSpan(0, 0, tokeepalive); m_toKeepaliveRecv = new TimeSpan(0, 0, 2*tokeepalive); m_lastConnected = DateTime.Now; }
// --------------------------------------------------------------------- // Creates a streamwriter that will write to the given file name. // --------------------------------------------------------------------- public LogClient requestLog(string filename) { StreamWriter sw; filename = LogTools.safeFileName(filename); string filePath = m_logPath + filename; try { if (m_logStreamwriters.ContainsKey(filename)) { sw = m_logStreamwriters[filename]; } else { FileStream fs = new FileStream(filePath, FileMode.Append); sw = new StreamWriter(fs); m_logStreamwriters.TryAdd(filename, sw); //check for dir and create if necessary //todo } } catch (IOException e) { App.AppEventLog.WriteEntry(LogTools.getExceptionString(m_threadName, "requestLog", e)); throw e; } LogClient lc = new LogClient(filename,this); return lc; //return sw; }