public void disconnectAll() { IMethodResult result = new SleepMethodResult(500); foreach (KeyValuePair <string, PrinterZebra> kvPrinter in m_printersCache) { PrinterZebra printer = (PrinterZebra)kvPrinter.Value; printer.disconnect(result); } }
public PrinterZebra addPrinterWithID(string ID, Int32 port, PrinterZebra.EPrinterConnectionType type) { if (m_printersCache.ContainsKey(ID)) { return m_printersCache[ID]; } PrinterZebraImpl.PrinterZebra newPrinter = new PrinterZebraImpl.PrinterZebra(); newPrinter.ID = ID; newPrinter.Port = port; newPrinter.connectionType = type; m_printersCache.Add(ID, newPrinter); return newPrinter; }
private void processMessage(rho.protocol.client.IClientMethod clientMethod) { try { lock (g_syncObject) { rho.protocol.server.IMethodHodler selectHolder = null; if (clientMethod.PrinterID.Length == 0) { PrinterZebraSingleton singleton = PrinterManager.Instance.getPrinterSingleton(); selectHolder = m_factorySingleton.convert(clientMethod); if (selectHolder != null) { rho.MethodRunnable <PrinterZebraSingleton> c = new rho.MethodRunnable <PrinterZebraSingleton>(selectHolder); c.runInObject(singleton); } } else { PrinterZebra printer = PrinterManager.Instance.getPrinterByID(clientMethod.PrinterID); printer.applicationForm = m_applicationForm; selectHolder = m_factory.convert(clientMethod); if (selectHolder != null) { rho.MethodRunnable <PrinterZebra> c = new rho.MethodRunnable <PrinterZebra>(selectHolder); c.runInObject(printer); } } } } catch (System.Exception ex) { Logger.Write("Catch main extension: " + ex.Message); } processEndofAnswer(); }
private void tryToConnectInFoundPrinters(IMethodResult oResult) { IMethodResult result = new SleepMethodResult(500); List <string> badPrinters = new List <string>(); Logger.Write("tryToConnect start [found printers]"); List <string> printerKeys = PrinterManager.Instance.getPrintersKeys(); foreach (string printerKey in printerKeys) { PrinterZebra printer = PrinterManager.Instance.getPrinter(printerKey); string deviceAdress = printer.ID; Int32 port = printer.Port; Logger.Write("searching in address [found printers]: " + deviceAdress); ConnecttionJob job = tryToConnect(port, deviceAdress, ZebraConstants.connectionTimeout, printer.connectionType); if (job.Connection != null) { Logger.Write("Found printer on address [found printers]: " + deviceAdress); sendConnectResult(job.FriendlyName, deviceAdress, port, printer.connectionType, oResult); job.Close(); } else { Logger.Write("remove printer on address [found printers]: " + deviceAdress + " from cache."); badPrinters.Add(printerKey); } } PrinterManager.Instance.removePrinters(badPrinters); }
public ConnecttionJob tryToConnect(Int32 port, string deviceAdress, int timeout, PrinterZebra.EPrinterConnectionType connType) { Logger.Write("tryToConnect: " + port.ToString() + ", " + deviceAdress + ", " + timeout.ToString()); ConnecttionJob job = new ConnecttionJob(); job.MaxTimeoutForRead = 0; job.TimeToWaitForMoreData = 0; job.Port = port; job.Address = deviceAdress; job.ConnectionType = connType; job.Connect(timeout); return job; }
public void sendConnectResult(string deviceName, string deviceAdress, Int32 devicePort, PrinterZebra.EPrinterConnectionType connType, IMethodResult oResult) { IReadOnlyDictionary<string, string> printerResult = new IReadOnlyDictionary<string, string>(); printerResult[ZebraConstants.HK_STATUS] = ZebraConstants.PRINTER_STATUS_SUCCESS; printerResult[ZebraConstants.HK_PRINTER_ID] = deviceAdress; printerResult[ZebraConstants.PROPERTY_DEVICE_ADDRESS] = deviceAdress; printerResult[ZebraConstants.PROPERTY_DEVICE_PORT] = devicePort.ToString(); printerResult[ZebraConstants.PROPERTY_PRINTER_TYPE] = ZebraConstants.PRINTER_TYPE_ZEBRA; printerResult[ZebraConstants.PROPERTY_DEVICE_NAME] = deviceName; if (connType == PrinterZebra.EPrinterConnectionType.eBluetooth) { printerResult[ZebraConstants.PROPERTY_CONNECTION_TYPE] = ZebraConstants.CONNECTION_TYPE_BLUETOOTH; } else if (connType == PrinterZebra.EPrinterConnectionType.eTCP) { printerResult[ZebraConstants.PROPERTY_CONNECTION_TYPE] = ZebraConstants.CONNECTION_TYPE_TCP; } else if (connType == PrinterZebra.EPrinterConnectionType.eOnBoard) { printerResult[ZebraConstants.PROPERTY_CONNECTION_TYPE] = ZebraConstants.CONNECTION_TYPE_ON_BOARD; } else if (connType == PrinterZebra.EPrinterConnectionType.eUSB) { printerResult[ZebraConstants.PROPERTY_CONNECTION_TYPE] = ZebraConstants.CONNECTION_TYPE_USB; } oResult.set(printerResult); }