
// WS-POS version 1.3 参照実装
// 2013/05/23 12:43:59

using UnifiedPOS.POSPrinter.V1_4;
using System;
using System.Collections.Generic;

using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Text.RegularExpressions;
using System.Reflection;
using WSPOSInitiative.Common;

namespace WSPOSInitiative.POSPrinter
{
    /// <summary>
    /// POSPrinterの参照実装基底クラス
    /// </summary>
    public class POSPrinterServiceProviderBehaviorCore : ServiceProviderBehavior, UnifiedPOS.POSPrinter.V1_4.POSPrinter, IDisposable
    {
        #region POSPrinter Enumration Converter

        protected static Dictionary<Enum, Enum> Convert = new Dictionary<Enum, Enum>()
            {
                { Microsoft.PointOfService.PowerReporting.Advanced, PowerReporting.PR_ADVANCED },
                { Microsoft.PointOfService.PowerReporting.None, PowerReporting.PR_NONE },
                { Microsoft.PointOfService.PowerReporting.Standard, PowerReporting.PR_STANDARD },
                { PowerReporting.PR_ADVANCED, Microsoft.PointOfService.PowerReporting.Advanced },
                { PowerReporting.PR_NONE, Microsoft.PointOfService.PowerReporting.None },
                { PowerReporting.PR_STANDARD, Microsoft.PointOfService.PowerReporting.Standard },

                { Microsoft.PointOfService.PowerNotification.Disabled, PowerNotification.PN_DISABLED },
                { Microsoft.PointOfService.PowerNotification.Enabled, PowerNotification.PN_ENABLED},
                { PowerNotification.PN_DISABLED, Microsoft.PointOfService.PowerNotification.Disabled },
                { PowerNotification.PN_ENABLED, Microsoft.PointOfService.PowerNotification.Enabled },

                { Microsoft.PointOfService.PowerState.Off, PowerState.PS_OFF},
                { Microsoft.PointOfService.PowerState.Offline, PowerState.PS_OFFLINE },
                { Microsoft.PointOfService.PowerState.OffOffline, PowerState.PS_OFF_OFFLINE },
                { Microsoft.PointOfService.PowerState.Online, PowerState.PS_ONLINE },
                { Microsoft.PointOfService.PowerState.Unknown, PowerState.PS_UNKNOWN },
                { PowerState.PS_OFF, Microsoft.PointOfService.PowerState.Off },
                { PowerState.PS_OFFLINE, Microsoft.PointOfService.PowerState.Offline },
                { PowerState.PS_OFF_OFFLINE, Microsoft.PointOfService.PowerState.OffOffline },
                { PowerState.PS_ONLINE, Microsoft.PointOfService.PowerState.Online },
                { PowerState.PS_UNKNOWN, Microsoft.PointOfService.PowerState.Unknown },

                { Microsoft.PointOfService.ControlState.Busy, ControlState.S_BUSY },
                { Microsoft.PointOfService.ControlState.Closed, ControlState.S_CLOSED },
                { Microsoft.PointOfService.ControlState.Error, ControlState.S_ERROR },
                { Microsoft.PointOfService.ControlState.Idle, ControlState.S_IDLE },
                { ControlState.S_BUSY, Microsoft.PointOfService.ControlState.Busy },
                { ControlState.S_CLOSED, Microsoft.PointOfService.ControlState.Closed },
                { ControlState.S_ERROR, Microsoft.PointOfService.ControlState.Error },
                { ControlState.S_IDLE, Microsoft.PointOfService.ControlState.Idle },

                { Microsoft.PointOfService.HealthCheckLevel.External, HealthCheckLevel.CH_EXTERNAL },
                { Microsoft.PointOfService.HealthCheckLevel.Interactive, HealthCheckLevel.CH_INTERACTIVE },
                { Microsoft.PointOfService.HealthCheckLevel.Internal, HealthCheckLevel.CH_INTERNAL },
                { HealthCheckLevel.CH_EXTERNAL, Microsoft.PointOfService.HealthCheckLevel.External },
                { HealthCheckLevel.CH_INTERACTIVE, Microsoft.PointOfService.HealthCheckLevel.Interactive },
                { HealthCheckLevel.CH_INTERNAL, Microsoft.PointOfService.HealthCheckLevel.Internal },

                { Microsoft.PointOfService.CompareFirmwareResult.Different, CompareFirmwareResult.CFV_FIRMWARE_DIFFERENT },
                { Microsoft.PointOfService.CompareFirmwareResult.Newer, CompareFirmwareResult.CFV_FIRMWARE_NEWER },
                { Microsoft.PointOfService.CompareFirmwareResult.Older, CompareFirmwareResult.CFV_FIRMWARE_OLDER },
                { Microsoft.PointOfService.CompareFirmwareResult.Same, CompareFirmwareResult.CFV_FIRMWARE_SAME },
                { Microsoft.PointOfService.CompareFirmwareResult.Unknown, CompareFirmwareResult.CFV_FIRMWARE_UNKNOWN },
                { CompareFirmwareResult.CFV_FIRMWARE_DIFFERENT, Microsoft.PointOfService.CompareFirmwareResult.Different },
                { CompareFirmwareResult.CFV_FIRMWARE_NEWER, Microsoft.PointOfService.CompareFirmwareResult.Newer },
                { CompareFirmwareResult.CFV_FIRMWARE_OLDER, Microsoft.PointOfService.CompareFirmwareResult.Older },
                { CompareFirmwareResult.CFV_FIRMWARE_SAME, Microsoft.PointOfService.CompareFirmwareResult.Same },
                { CompareFirmwareResult.CFV_FIRMWARE_UNKNOWN, Microsoft.PointOfService.CompareFirmwareResult.Unknown },

                { Microsoft.PointOfService.ErrorCode.Busy, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_BUSY },
                { Microsoft.PointOfService.ErrorCode.Claimed, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_CLAIMED },
                { Microsoft.PointOfService.ErrorCode.Closed, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_CLOSED },
                { Microsoft.PointOfService.ErrorCode.Deprecated, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_DEPRECATED },
                { Microsoft.PointOfService.ErrorCode.Disabled, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_DISABLED },
                { Microsoft.PointOfService.ErrorCode.Exists, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_EXISTS },
                { Microsoft.PointOfService.ErrorCode.Extended, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_EXTENDED },
                { Microsoft.PointOfService.ErrorCode.Failure, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_FAILURE },
                { Microsoft.PointOfService.ErrorCode.Illegal, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_ILLEGAL },
                { Microsoft.PointOfService.ErrorCode.NoExist, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_NOEXIST },
                { Microsoft.PointOfService.ErrorCode.NoHardware, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_NOHARDWARE },
                { Microsoft.PointOfService.ErrorCode.NoService, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_NOSERVICE },
                { Microsoft.PointOfService.ErrorCode.NotClaimed, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_NOTCLAIMED },
                { Microsoft.PointOfService.ErrorCode.Offline, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_OFFLINE },
                //{ Microsoft.PointOfService.ErrorCode.Success, UnifiedPOS.POSPrinter.V1_4.ErrorCode.SUCCESS },
                { Microsoft.PointOfService.ErrorCode.Timeout, UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_TIMEOUT },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_BUSY, Microsoft.PointOfService.ErrorCode.Busy },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_CLAIMED, Microsoft.PointOfService.ErrorCode.Claimed },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_CLOSED, Microsoft.PointOfService.ErrorCode.Closed },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_DEPRECATED, Microsoft.PointOfService.ErrorCode.Deprecated },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_DISABLED, Microsoft.PointOfService.ErrorCode.Disabled },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_EXISTS, Microsoft.PointOfService.ErrorCode.Exists },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_EXTENDED, Microsoft.PointOfService.ErrorCode.Extended },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_FAILURE, Microsoft.PointOfService.ErrorCode.Failure },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_ILLEGAL, Microsoft.PointOfService.ErrorCode.Illegal },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_NOEXIST, Microsoft.PointOfService.ErrorCode.NoExist },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_NOHARDWARE, Microsoft.PointOfService.ErrorCode.NoHardware },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_NOSERVICE, Microsoft.PointOfService.ErrorCode.NoService },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_NOTCLAIMED, Microsoft.PointOfService.ErrorCode.NotClaimed },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_OFFLINE, Microsoft.PointOfService.ErrorCode.Offline },
                //{ UnifiedPOS.POSPrinter.V1_4.ErrorCode.SUCCESS, Microsoft.PointOfService.ErrorCode.Success },
                { UnifiedPOS.POSPrinter.V1_4.ErrorCode.E_TIMEOUT, Microsoft.PointOfService.ErrorCode.Timeout },

                { Microsoft.PointOfService.CharacterSetCapability.Alpha, CharacterSetCapability.PTR_CCS_ALPHA},
                { Microsoft.PointOfService.CharacterSetCapability.Ascii, CharacterSetCapability.PTR_CCS_ASCII},
                { Microsoft.PointOfService.CharacterSetCapability.Kana, CharacterSetCapability.PTR_CCS_KANA },
                { Microsoft.PointOfService.CharacterSetCapability.Kanji, CharacterSetCapability.PTR_CCS_KANJI },
                { Microsoft.PointOfService.CharacterSetCapability.Unicode, CharacterSetCapability.PTR_CCS_UNICODE },
                { CharacterSetCapability.PTR_CCS_ALPHA, Microsoft.PointOfService.CharacterSetCapability.Alpha },
                { CharacterSetCapability.PTR_CCS_ASCII, Microsoft.PointOfService.CharacterSetCapability.Ascii },
                { CharacterSetCapability.PTR_CCS_KANA, Microsoft.PointOfService.CharacterSetCapability.Kana },
                { CharacterSetCapability.PTR_CCS_KANJI, Microsoft.PointOfService.CharacterSetCapability.Kanji },
                { CharacterSetCapability.PTR_CCS_UNICODE, Microsoft.PointOfService.CharacterSetCapability.Unicode },

                { Microsoft.PointOfService.PrinterCartridgeNotify.Disabled, PrinterCartridgeNotify.PTR_CN_DISABLED },
                { Microsoft.PointOfService.PrinterCartridgeNotify.Enabled, PrinterCartridgeNotify.PTR_CN_ENABLED },
                { PrinterCartridgeNotify.PTR_CN_DISABLED, Microsoft.PointOfService.PrinterCartridgeNotify.Disabled },
                { PrinterCartridgeNotify.PTR_CN_ENABLED, Microsoft.PointOfService.PrinterCartridgeNotify.Enabled },

                { Microsoft.PointOfService.PrinterErrorLevel.Fatal, PrinterErrorLevel.PTR_EL_FATAL},
                { Microsoft.PointOfService.PrinterErrorLevel.None, PrinterErrorLevel.PTR_EL_NONE},
                { Microsoft.PointOfService.PrinterErrorLevel.Recoverable, PrinterErrorLevel.PTR_EL_RECOVERABLE},
                { PrinterErrorLevel.PTR_EL_FATAL, Microsoft.PointOfService.PrinterErrorLevel.Fatal },
                { PrinterErrorLevel.PTR_EL_NONE, Microsoft.PointOfService.PrinterErrorLevel.None },
                { PrinterErrorLevel.PTR_EL_RECOVERABLE, Microsoft.PointOfService.PrinterErrorLevel.Recoverable },

                { Microsoft.PointOfService.PrinterStation.Journal, PrinterStation.PTR_S_JOURNAL},
                //{ Microsoft.PointOfService.PrinterStation.None, PrinterStation.PTR_S_NONE},
                { Microsoft.PointOfService.PrinterStation.Receipt, PrinterStation.PTR_S_RECEIPT },
                { Microsoft.PointOfService.PrinterStation.Slip, PrinterStation.PTR_S_SLIP },
                { Microsoft.PointOfService.PrinterStation.TwoReceiptJournal, PrinterStation.PTR_TWO_RECEIPT_JOURNAL },
                { Microsoft.PointOfService.PrinterStation.TwoSlipJournal, PrinterStation.PTR_TWO_SLIP_JOURNAL },
                { Microsoft.PointOfService.PrinterStation.TwoSlipReceipt, PrinterStation.PTR_TWO_SLIP_RECEIPT },
                { PrinterStation.PTR_S_JOURNAL, Microsoft.PointOfService.PrinterStation.Journal },
                //{ PrinterStation.PTR_S_NONE, Microsoft.PointOfService.PrinterStation.None },
                { PrinterStation.PTR_S_RECEIPT, Microsoft.PointOfService.PrinterStation.Receipt },
                { PrinterStation.PTR_S_SLIP, Microsoft.PointOfService.PrinterStation.Slip },
                { PrinterStation.PTR_TWO_RECEIPT_JOURNAL, Microsoft.PointOfService.PrinterStation.TwoReceiptJournal },
                { PrinterStation.PTR_TWO_SLIP_JOURNAL, Microsoft.PointOfService.PrinterStation.TwoSlipJournal },
                { PrinterStation.PTR_TWO_SLIP_RECEIPT, Microsoft.PointOfService.PrinterStation.TwoSlipReceipt },

                { Microsoft.PointOfService.MapMode.Dots, MapMode.PTR_MM_DOTS},
                { Microsoft.PointOfService.MapMode.English, MapMode.PTR_MM_ENGLISH},
                { Microsoft.PointOfService.MapMode.Metric, MapMode.PTR_MM_METRIC},
                { Microsoft.PointOfService.MapMode.Twips, MapMode.PTR_MM_TWIPS},
                { MapMode.PTR_MM_DOTS, Microsoft.PointOfService.MapMode.Dots },
                { MapMode.PTR_MM_ENGLISH, Microsoft.PointOfService.MapMode.English },
                { MapMode.PTR_MM_METRIC, Microsoft.PointOfService.MapMode.Metric },
                { MapMode.PTR_MM_TWIPS, Microsoft.PointOfService.MapMode.Twips },

                { Microsoft.PointOfService.PageModePrintDirection.BottomToTop, PageModePrintDirection.PTR_PD_BOTTOM_TO_TOP },
                { Microsoft.PointOfService.PageModePrintDirection.LeftToRight, PageModePrintDirection.PTR_PD_LEFT_TO_RIGHT },
                //{ Microsoft.PointOfService.PageModePrintDirection.None, PageModePrintDirection.PTR_PD_NONE },
                { Microsoft.PointOfService.PageModePrintDirection.RightToLeft, PageModePrintDirection.PTR_PD_RIGHT_TO_LEFT },
                { Microsoft.PointOfService.PageModePrintDirection.TopToBottom, PageModePrintDirection.PTR_PD_TOP_TO_BOTTOM },
                { PageModePrintDirection.PTR_PD_BOTTOM_TO_TOP, Microsoft.PointOfService.PageModePrintDirection.BottomToTop },
                { PageModePrintDirection.PTR_PD_LEFT_TO_RIGHT, Microsoft.PointOfService.PageModePrintDirection.LeftToRight },
                //{ PageModePrintDirection.PTR_PD_NONE, Microsoft.PointOfService.PageModePrintDirection.None },
                { PageModePrintDirection.PTR_PD_RIGHT_TO_LEFT, Microsoft.PointOfService.PageModePrintDirection.RightToLeft },
                { PageModePrintDirection.PTR_PD_TOP_TO_BOTTOM, Microsoft.PointOfService.PageModePrintDirection.TopToBottom },

                { Microsoft.PointOfService.Rotation.Left90, Rotation.PTR_RP_LEFT90 },
                { Microsoft.PointOfService.Rotation.Normal, Rotation.PTR_RP_NORMAL },
                { Microsoft.PointOfService.Rotation.Right90, Rotation.PTR_RP_RIGHT90 },
                { Microsoft.PointOfService.Rotation.Rotate180, Rotation.PTR_RP_ROTATE180},
                { Rotation.PTR_RP_LEFT90, Microsoft.PointOfService.Rotation.Left90 },
                { Rotation.PTR_RP_NORMAL, Microsoft.PointOfService.Rotation.Normal },
                { Rotation.PTR_RP_RIGHT90, Microsoft.PointOfService.Rotation.Right90 },
                { Rotation.PTR_RP_ROTATE180, Microsoft.PointOfService.Rotation.Rotate180 },

                { Microsoft.PointOfService.PrinterCartridgeStates.Cleaning, PrinterCartridgeStates.PTR_CART_CLEANING},
                { Microsoft.PointOfService.PrinterCartridgeStates.Empty, PrinterCartridgeStates.PTR_CART_EMPTY },
                { Microsoft.PointOfService.PrinterCartridgeStates.NearEnd, PrinterCartridgeStates.PTR_CART_NEAREND },
                { Microsoft.PointOfService.PrinterCartridgeStates.OK, PrinterCartridgeStates.PTR_CART_OK },
                { Microsoft.PointOfService.PrinterCartridgeStates.Removed, PrinterCartridgeStates.PTR_CART_REMOVED },
                { Microsoft.PointOfService.PrinterCartridgeStates.Unknown, PrinterCartridgeStates.PTR_CART_UNKNOWN },
                { PrinterCartridgeStates.PTR_CART_CLEANING, Microsoft.PointOfService.PrinterCartridgeStates.Cleaning },
                { PrinterCartridgeStates.PTR_CART_EMPTY, Microsoft.PointOfService.PrinterCartridgeStates.Empty },
                { PrinterCartridgeStates.PTR_CART_NEAREND, Microsoft.PointOfService.PrinterCartridgeStates.NearEnd },
                { PrinterCartridgeStates.PTR_CART_OK, Microsoft.PointOfService.PrinterCartridgeStates.OK },
                { PrinterCartridgeStates.PTR_CART_REMOVED, Microsoft.PointOfService.PrinterCartridgeStates.Removed },
                { PrinterCartridgeStates.PTR_CART_UNKNOWN, Microsoft.PointOfService.PrinterCartridgeStates.Unknown },

                { Microsoft.PointOfService.PrinterSide.Opposite, PrinterSide.PTR_PS_OPPOSITE },
                { Microsoft.PointOfService.PrinterSide.Side1, PrinterSide.PTR_PS_SIDE1 },
                { Microsoft.PointOfService.PrinterSide.Side2, PrinterSide.PTR_PS_SIDE2 },
                { Microsoft.PointOfService.PrinterSide.Unknown, PrinterSide.PTR_PS_UNKNOWN },
                { PrinterSide.PTR_PS_OPPOSITE, Microsoft.PointOfService.PrinterSide.Opposite },
                { PrinterSide.PTR_PS_SIDE1, Microsoft.PointOfService.PrinterSide.Side1 },
                { PrinterSide.PTR_PS_SIDE2, Microsoft.PointOfService.PrinterSide.Side2 },
                { PrinterSide.PTR_PS_UNKNOWN, Microsoft.PointOfService.PrinterSide.Unknown },

                { Microsoft.PointOfService.PageModePrintControl.Cancel, PageModePrintControl.PTR_PM_CANCEL },
                { Microsoft.PointOfService.PageModePrintControl.Normal, PageModePrintControl.PTR_PM_NORMAL },
                { Microsoft.PointOfService.PageModePrintControl.PageMode, PageModePrintControl.PTR_PM_PAGE_MODE },
                { Microsoft.PointOfService.PageModePrintControl.PrintSave, PageModePrintControl.PTR_PM_PRINT_SAVE },
                { PageModePrintControl.PTR_PM_CANCEL, Microsoft.PointOfService.PageModePrintControl.Cancel },
                { PageModePrintControl.PTR_PM_NORMAL, Microsoft.PointOfService.PageModePrintControl.Normal },
                { PageModePrintControl.PTR_PM_PAGE_MODE, Microsoft.PointOfService.PageModePrintControl.PageMode },
                { PageModePrintControl.PTR_PM_PRINT_SAVE, Microsoft.PointOfService.PageModePrintControl.PrintSave },

                { Microsoft.PointOfService.BarCodeTextPosition.Above, BarCodeTextPosition.PTR_BC_TEXT_ABOVE},
                { Microsoft.PointOfService.BarCodeTextPosition.Below, BarCodeTextPosition.PTR_BC_TEXT_BELOW},
                { Microsoft.PointOfService.BarCodeTextPosition.None, BarCodeTextPosition.PTR_BC_TEXT_NONE},
                { BarCodeTextPosition.PTR_BC_TEXT_ABOVE, Microsoft.PointOfService.BarCodeTextPosition.Above },
                { BarCodeTextPosition.PTR_BC_TEXT_BELOW, Microsoft.PointOfService.BarCodeTextPosition.Below },
                { BarCodeTextPosition.PTR_BC_TEXT_NONE, Microsoft.PointOfService.BarCodeTextPosition.None },

                { Microsoft.PointOfService.PrinterLogoLocation.Bottom, PrinterLogoLocation.PTR_L_BOTTOM},
                { Microsoft.PointOfService.PrinterLogoLocation.Top, PrinterLogoLocation.PTR_L_TOP},
                { PrinterLogoLocation.PTR_L_BOTTOM, Microsoft.PointOfService.PrinterLogoLocation.Bottom },
                { PrinterLogoLocation.PTR_L_TOP, Microsoft.PointOfService.PrinterLogoLocation.Top },

                { Microsoft.PointOfService.PrinterTransactionControl.Normal, PrinterTransactionControl.PTR_TP_NORMAL},
                { Microsoft.PointOfService.PrinterTransactionControl.Transaction, PrinterTransactionControl.PTR_TP_TRANSACTION},
                { PrinterTransactionControl.PTR_TP_NORMAL, Microsoft.PointOfService.PrinterTransactionControl.Normal },
                { PrinterTransactionControl.PTR_TP_TRANSACTION, Microsoft.PointOfService.PrinterTransactionControl.Transaction },
            };

        protected static Dictionary<Enum, Enum> EventConvert = new Dictionary<Enum, Enum>()
            {
                { Microsoft.PointOfService.ErrorCode.Busy, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_BUSY },
                { Microsoft.PointOfService.ErrorCode.Claimed, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_CLAIMED },
                { Microsoft.PointOfService.ErrorCode.Closed, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_CLOSED },
                { Microsoft.PointOfService.ErrorCode.Deprecated, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_DEPRECATED },
                { Microsoft.PointOfService.ErrorCode.Disabled, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_DISABLED },
                { Microsoft.PointOfService.ErrorCode.Exists, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_EXISTS },
                { Microsoft.PointOfService.ErrorCode.Extended, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_EXTENDED },
                { Microsoft.PointOfService.ErrorCode.Failure, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_FAILURE },
                { Microsoft.PointOfService.ErrorCode.Illegal, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_ILLEGAL },
                { Microsoft.PointOfService.ErrorCode.NoExist, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_NOEXIST },
                { Microsoft.PointOfService.ErrorCode.NoHardware, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_NOHARDWARE },
                { Microsoft.PointOfService.ErrorCode.NoService, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_NOSERVICE },
                { Microsoft.PointOfService.ErrorCode.NotClaimed, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_NOTCLAIMED },
                { Microsoft.PointOfService.ErrorCode.Offline, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_OFFLINE },
                //{ Microsoft.PointOfService.ErrorCode.Success, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.SUCCESS },
                { Microsoft.PointOfService.ErrorCode.Timeout, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_TIMEOUT },

                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_BUSY, Microsoft.PointOfService.ErrorCode.Busy },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_CLAIMED, Microsoft.PointOfService.ErrorCode.Claimed },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_CLOSED, Microsoft.PointOfService.ErrorCode.Closed },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_DEPRECATED, Microsoft.PointOfService.ErrorCode.Deprecated },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_DISABLED, Microsoft.PointOfService.ErrorCode.Disabled },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_EXISTS, Microsoft.PointOfService.ErrorCode.Exists },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_EXTENDED, Microsoft.PointOfService.ErrorCode.Extended },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_FAILURE, Microsoft.PointOfService.ErrorCode.Failure },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_ILLEGAL, Microsoft.PointOfService.ErrorCode.Illegal },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_NOEXIST, Microsoft.PointOfService.ErrorCode.NoExist },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_NOHARDWARE, Microsoft.PointOfService.ErrorCode.NoHardware },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_NOSERVICE, Microsoft.PointOfService.ErrorCode.NoService },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_NOTCLAIMED, Microsoft.PointOfService.ErrorCode.NotClaimed },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_OFFLINE, Microsoft.PointOfService.ErrorCode.Offline },
                //{ UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.SUCCESS, Microsoft.PointOfService.ErrorCode.Success },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode.E_TIMEOUT, Microsoft.PointOfService.ErrorCode.Timeout },

                { Microsoft.PointOfService.ErrorLocus.Input, UnifiedPOS.POSPrinterEvents.V1_4.ErrorLocus.EL_INPUT },
                { Microsoft.PointOfService.ErrorLocus.InputData, UnifiedPOS.POSPrinterEvents.V1_4.ErrorLocus.EL_INPUT_DATA },
                { Microsoft.PointOfService.ErrorLocus.Output, UnifiedPOS.POSPrinterEvents.V1_4.ErrorLocus.EL_OUTPUT },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorLocus.EL_INPUT, Microsoft.PointOfService.ErrorLocus.Input },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorLocus.EL_INPUT_DATA, Microsoft.PointOfService.ErrorLocus.InputData },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorLocus.EL_OUTPUT, Microsoft.PointOfService.ErrorLocus.Output },

                { Microsoft.PointOfService.ErrorResponse.Clear, UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse.ER_CLEAR },
                { Microsoft.PointOfService.ErrorResponse.ContinueInput, UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse.ER_CONTINUEINPUT },
                { Microsoft.PointOfService.ErrorResponse.Retry, UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse.ER_RETRY },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse.ER_CLEAR, Microsoft.PointOfService.ErrorResponse.Clear },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse.ER_CONTINUEINPUT, Microsoft.PointOfService.ErrorResponse.ContinueInput },
                { UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse.ER_RETRY, Microsoft.PointOfService.ErrorResponse.Retry },

                // Long Polling時の受信の名前空間はデバイスの名前空間にEventsがサフィックスされない
                // Events are not suffixed to the name space of event class which is received by PollForUPOSEvent
                { UnifiedPOS.POSPrinter.V1_4.ErrorResponse.ER_CLEAR, Microsoft.PointOfService.ErrorResponse.Clear },
                { UnifiedPOS.POSPrinter.V1_4.ErrorResponse.ER_CONTINUEINPUT, Microsoft.PointOfService.ErrorResponse.ContinueInput },
                { UnifiedPOS.POSPrinter.V1_4.ErrorResponse.ER_RETRY, Microsoft.PointOfService.ErrorResponse.Retry },

            };

        #endregion

        /// <summary>
        /// 派生クラスからコンストラクタに渡されるDeviceControlDescriptionを格納
        /// </summary>
        private string _deviceControlDescription;

        /// <summary>
        /// 派生クラスからコンストラクタに渡されるDeviceControlVersionを格納
        /// </summary>
        private UposVersion _deviceControlVersion;

        /// <summary>
        /// 派生クラスからコンストラクタに渡されるWS-POSVersionを格納
        /// </summary>
        private UposVersion _wsposVersion;


        public virtual int GetCapRecRuledLine(string ConsumerID)
        {
            return PrinterLineDirection.None;
        }

        public virtual int GetCapSlpRuledLine(string ConsumerID)
        {
            return PrinterLineDirection.None;
        }

        public virtual void DrawRuledLine(string ConsumerID, PrinterStation Station, PositionList PositionList, int LineDirection, int LineWidth, PrinterLineStyle LineStyle, int LineColor)
        {
            try
            {
                throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "The printer does not support drawing ruled lines.", new FaultCode("Server"));
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }



        #region Constructor

        /// <summary>
        /// 呼び出せないようにprivateで宣言されています
        /// It is declared as private so that it cannot call. 
        /// </summary>
        private POSPrinterServiceProviderBehaviorCore()
        {
        }

        /// <summary>
        /// コンストラクタ
        /// Constructor
        /// </summary>
        /// <param name="deviceControlDescription">DeviceControlDescription string</param>
        /// <param name="deviceControlVersion">Version value of DeviceControlVersion</param>
        /// <param name="wsposVersion">Version value of WS-POS</param>
        /// <param name="providerSessionTimeoutCheckPeriod">プロバイダのセッションタイムアウトをチェックする間隔（秒）| Interval to check the session timeout of the provider (second)</param>
        public POSPrinterServiceProviderBehaviorCore(string deviceControlDescription, UposVersion deviceControlVersion, UposVersion wsposVersion, int providerSessionTimeoutCheckPeriod)
            : base(providerSessionTimeoutCheckPeriod)
        {
            _deviceControlDescription = deviceControlDescription;
            _deviceControlVersion = deviceControlVersion;
            _wsposVersion = wsposVersion;
        }

        #endregion

        #region POSPrinter Member

        #region POSPrinter Properties

        public virtual int GetOutputID(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                    {
                        result = ConcretizationDevice(sessionContext.Device).OutputId;
                    });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual CharacterSetCapability GetCapCharacterSet(string ConsumerID)
        {
            try
            {
                CharacterSetCapability result = CharacterSetCapability.PTR_CCS_ALPHA;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (CharacterSetCapability)Convert[ConcretizationDevice(sessionContext.Device).CapCharacterSet];
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapConcurrentJrnRec(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapConcurrentJrnRec;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapConcurrentJrnSlp(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapConcurrentJrnSlp;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapConcurrentRecSlp(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapConcurrentRecSlp;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapCoverSensor(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapCoverSensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapMapCharacterSet(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapMapCharacterSet;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapTransaction(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapTransaction;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnPresent(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnPresent;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrn2Color(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrn2Color;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnBold(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnBold;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnDhigh(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnDHigh;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnDwide(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnDWide;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnDwideDhigh(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnDWideDHigh;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnEmptySensor(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnEmptySensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnItalic(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnItalic;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnNearEndSensor(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnNearEndSensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapJrnUnderline(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapJrnUnderline;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetCapJrnCartridgeSensor(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).CapJrnCartridgeSensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual int GetCapJrnColor(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).CapJrnColor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual bool GetCapRecPresent(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecPresent;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRec2Color(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRec2Color;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecBarCode(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecBarCode;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecBitmap(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecBitmap;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecBold(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecBold;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecDhigh(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecDHigh;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecDwide(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecDWide;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecDwideDhigh(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecDWideDHigh;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecEmptySensor(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecEmptySensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecItalic(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecItalic;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecLeft90(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecLeft90;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecNearEndSensor(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecNearEndSensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecPapercut(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecPaperCut;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecRight90(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecRight90;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecRotate180(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecRotate180;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecStamp(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecStamp;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecUnderline(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapRecUnderline;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetCapRecCartridgeSensor(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).CapRecCartridgeSensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual int GetCapRecColor(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).CapRecColor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual int GetCapRecMarkFeed(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).CapRecMarkFeed;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual bool GetCapSlpPresent(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpPresent;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpFullslip(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpFullSlip;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlp2Color(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlp2Color;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpBarCode(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpBarCode;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpBitmap(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpBitmap;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpBold(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpBold;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpDhigh(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpDHigh;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpDwide(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpDWide;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpDwideDhigh(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpDWideDHigh;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpEmptySensor(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpEmptySensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpItalic(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpItalic;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpLeft90(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpLeft90;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpNearEndSensor(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpNearEndSensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpRight90(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpRight90;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpRotate180(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpRotate180;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpUnderline(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpUnderline;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpBothSidesPrint(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CapSlpBothSidesPrint;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetCapSlpCartridgeSensor(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).CapSlpCartridgeSensor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual int GetCapSlpColor(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).CapSlpColor;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual bool GetAsyncMode(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).AsyncMode;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetAsyncMode(string ConsumerID, bool AsyncMode)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).AsyncMode = AsyncMode;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PrinterCartridgeNotify GetCartridgeNotify(string ConsumerID)
        {
            try
            {
                PrinterCartridgeNotify result = PrinterCartridgeNotify.PTR_CN_DISABLED;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (PrinterCartridgeNotify)Convert[ConcretizationDevice(sessionContext.Device).CartridgeNotify];
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetCartridgeNotify(string ConsumerID, PrinterCartridgeNotify CartridgeNotify)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).CartridgeNotify = (Microsoft.PointOfService.PrinterCartridgeNotify)Convert[CartridgeNotify];
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetCharacterSet(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CharacterSet;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetCharacterSet(string ConsumerID, int CharacterSet)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).CharacterSet = CharacterSet;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual CharacterSetList GetCharacterSetList(string ConsumerID)
        {
            try
            {
                CharacterSetList value = new CharacterSetList();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value.AddRange(ConcretizationDevice(sessionContext.Device).CharacterSetList);
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCoverOpen(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).CoverOpen;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PrinterErrorLevel GetErrorLevel(string ConsumerID)
        {
            try
            {
                PrinterErrorLevel result = PrinterErrorLevel.PTR_EL_NONE;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (PrinterErrorLevel)Convert[ConcretizationDevice(sessionContext.Device).ErrorLevel];
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PrinterStation GetErrorStation(string ConsumerID)
        {
            try
            {
                PrinterStation result = PrinterStation.PTR_S_RECEIPT;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (PrinterStation)Convert[ConcretizationDevice(sessionContext.Device).ErrorStation];
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual string GetErrorString(string ConsumerID)
        {
            try
            {
                string result = null;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).ErrorString; ;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual FontTypefaceList GetFontTypefaceList(string ConsumerID)
        {
            try
            {
                FontTypefaceList value = new FontTypefaceList();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value.AddRange(ConcretizationDevice(sessionContext.Device).FontTypefaceList);
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetFlagWhenIdle(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).FlagWhenIdle;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetFlagWhenIdle(string ConsumerID, bool FlagWhenIdle)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).FlagWhenIdle = FlagWhenIdle;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetMapCharacterSet(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).MapCharacterSet;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetMapCharacterSet(string ConsumerID, bool MapCharacterSet)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).MapCharacterSet = MapCharacterSet;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual MapMode GetMapMode(string ConsumerID)
        {
            try
            {
                MapMode result = MapMode.PTR_MM_DOTS;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (MapMode)Convert[ConcretizationDevice(sessionContext.Device).MapMode];
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetMapMode(string ConsumerID, MapMode MapMode)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).MapMode = (Microsoft.PointOfService.MapMode)Convert[MapMode];
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual Rotation GetRotateSpecial(string ConsumerID)
        {
            try
            {
                Rotation result = Rotation.PTR_RP_NORMAL;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (Rotation)Convert[ConcretizationDevice(sessionContext.Device).RotateSpecial];
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetRotateSpecial(string ConsumerID, Rotation RotateSpecial)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).RotateSpecial = (Microsoft.PointOfService.Rotation)Convert[RotateSpecial];
                });

            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetJrnLineChars(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).JrnLineChars;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetJrnLineChars(string ConsumerID, int JrnLineChars)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).JrnLineChars = JrnLineChars;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual LineCharsList GetJrnLineCharsList(string ConsumerID)
        {
            try
            {
                LineCharsList value = new LineCharsList();
                
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value.AddRange(ConcretizationDevice(sessionContext.Device).JrnLineCharsList);
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetJrnLineHeight(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).JrnLineHeight;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetJrnLineHeight(string ConsumerID, int JrnLineHeight)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).JrnLineHeight = JrnLineHeight;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetJrnLineSpacing(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).JrnLineSpacing;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetJrnLineSpacing(string ConsumerID, int JrnLineSpacing)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).JrnLineSpacing = JrnLineSpacing;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetJrnLineWidth(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).JrnLineWidth;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetJrnLetterQuality(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).JrnLetterQuality;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetJrnLetterQuality(string ConsumerID, bool JrnLetterQuality)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                     ConcretizationDevice(sessionContext.Device).JrnLetterQuality = JrnLetterQuality;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetJrnEmpty(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).JrnEmpty;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetJrnNearEnd(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).JrnNearEnd;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PrinterCartridgeStates GetJrnCartridgeState(string ConsumerID)
        {
            try
            {
                PrinterCartridgeStates result = PrinterCartridgeStates.PTR_CART_UNKNOWN;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (PrinterCartridgeStates)Convert[ConcretizationDevice(sessionContext.Device).JrnCartridgeState];
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetJrnCurrentCartridge(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).JrnCurrentCartridge;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void SetJrnCurrentCartridge(string ConsumerID, int JrnCurrentCartridge)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).JrnCurrentCartridge = (Microsoft.PointOfService.PrinterColors)JrnCurrentCartridge;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual int GetRecLineChars(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecLineChars;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetRecLineChars(string ConsumerID, int RecLineChars)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).RecLineChars = RecLineChars;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual LineCharsList GetRecLineCharsList(string ConsumerID)
        {
            try
            {
                LineCharsList value = new LineCharsList();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value.AddRange(ConcretizationDevice(sessionContext.Device).RecLineCharsList);
                });
                
                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetRecLineHeight(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecLineHeight;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetRecLineHeight(string ConsumerID, int RecLineHeight)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).RecLineHeight = RecLineHeight;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetRecLineSpacing(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecLineSpacing;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetRecLineSpacing(string ConsumerID, int RecLineSpacing)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).RecLineSpacing = RecLineSpacing;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetRecLineWidth(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecLineWidth;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetRecLetterQuality(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecLetterQuality;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetRecLetterQuality(string ConsumerID, bool RecLetterQuality)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).RecLetterQuality = RecLetterQuality;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetRecEmpty(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecEmpty;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetRecNearEnd(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecNearEnd;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetRecSidewaysMaxLines(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecSidewaysMaxLines;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetRecSidewaysMaxChars(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecSidewaysMaxChars;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetRecLinesToPaperCut(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).RecLinesToPaperCut;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual RotationList GetRecBarCodeRotationList(string ConsumerID)
        {
            try
            {
                RotationList value = new RotationList();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    //value.AddRange(from el in ConcretizationDevice(sessionContext.Device).RecBarCodeRotationList select (Rotation)Convert[el]);
                    var rbcrl = ConcretizationDevice(sessionContext.Device).RecBarCodeRotationList;
                    foreach (var rbcr in rbcrl)
                    {
                        value.Add((Rotation)Convert[rbcr]);
                    }
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual RotationList GetRecBitmapRotationList(string ConsumerID)
        {
            try
            {
                RotationList value = new RotationList();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    //value.AddRange(from el in ConcretizationDevice(sessionContext.Device).RecBitmapRotationList select (Rotation)Convert[el]);
                    var rbrl = ConcretizationDevice(sessionContext.Device).RecBitmapRotationList;
                    foreach (var rbr in rbrl)
                    {
                        value.Add((Rotation)Convert[rbr]);
                    }
                });
                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PrinterCartridgeStates GetRecCartridgeState(string ConsumerID)
        {
            try
            {
                PrinterCartridgeStates result = PrinterCartridgeStates.PTR_CART_UNKNOWN;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (PrinterCartridgeStates)Convert[ConcretizationDevice(sessionContext.Device).RecCartridgeState];
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetRecCurrentCartridge(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = (int)ConcretizationDevice(sessionContext.Device).RecCurrentCartridge;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void SetRecCurrentCartridge(string ConsumerID, int RecCurrentCartridge)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).RecCurrentCartridge = (Microsoft.PointOfService.PrinterColors)RecCurrentCartridge;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual int GetSlpLineChars(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpLineChars;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetSlpLineChars(string ConsumerID, int SlpLineChars)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).SlpLineChars = SlpLineChars;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual LineCharsList GetSlpLineCharsList(string ConsumerID)
        {
            try
            {
                LineCharsList value = new LineCharsList();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value.AddRange(ConcretizationDevice(sessionContext.Device).SlpLineCharsList);
                });
                
                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetSlpLineHeight(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpLineHeight;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetSlpLineHeight(string ConsumerID, int SlpLineHeight)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).SlpLineHeight = SlpLineHeight;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetSlpLineSpacing(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpLineSpacing;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetSlpLineSpacing(string ConsumerID, int SlpLineSpacing)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).SlpLineSpacing = SlpLineSpacing;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetSlpLineWidth(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpLineWidth;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetSlpLetterQuality(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpLetterQuality;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetSlpLetterQuality(string ConsumerID, bool SlpLetterQuality)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).SlpLetterQuality = SlpLetterQuality;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetSlpEmpty(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpEmpty;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetSlpNearEnd(string ConsumerID)
        {
            try
            {
                bool result = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpNearEnd;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetSlpSidewaysMaxLines(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpSidewaysMaxLines;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetSlpSidewaysMaxChars(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpSidewaysMaxChars;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetSlpMaxLines(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpMaxLines;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetSlpLinesNearEndToEnd(string ConsumerID)
        {
            try
            {
                int result = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    result = ConcretizationDevice(sessionContext.Device).SlpLinesNearEndToEnd;
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual RotationList GetSlpBarCodeRotationList(string ConsumerID)
        {
            try
            {
                RotationList value = new RotationList();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    // value.AddRange(from el in ConcretizationDevice(sessionContext.Device).SlpBarCodeRotationList select (Rotation)Convert[el]);
                    var sbccrl = ConcretizationDevice(sessionContext.Device).SlpBarCodeRotationList;
                    foreach (var sbccr in sbccrl)
                    {
                        value.Add((Rotation)Convert[sbccr]);
                    };
                });
                
                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual RotationList GetSlpBitmapRotationList(string ConsumerID)
        {
            try
            {
                RotationList value = new RotationList();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    //value.AddRange(from el in ConcretizationDevice(sessionContext.Device).SlpBitmapRotationList select (Rotation)Convert[el]);
                    var sbrl = ConcretizationDevice(sessionContext.Device).SlpBitmapRotationList;
                    foreach (var sbr in sbrl)
                    {
                        value.Add((Rotation)Convert[sbr]);
                    };
                });
                
                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PrinterSide GetSlpPrintSide(string ConsumerID)
        {
            try
            {
                PrinterSide value = PrinterSide.PTR_PS_UNKNOWN;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (PrinterSide)Convert[ConcretizationDevice(sessionContext.Device).SlpPrintSide];
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PrinterCartridgeStates GetSlpCartridgeState(string ConsumerID)
        {
            try
            {
                PrinterCartridgeStates value = PrinterCartridgeStates.PTR_CART_UNKNOWN;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (PrinterCartridgeStates)Convert[ConcretizationDevice(sessionContext.Device).SlpCartridgeState];
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetSlpCurrentCartridge(string ConsumerID)
        {
            try
            {
                int value = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (int)ConcretizationDevice(sessionContext.Device).SlpCurrentCartridge;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void SetSlpCurrentCartridge(string ConsumerID, int SlpCurrentCartridge)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).SlpCurrentCartridge = (Microsoft.PointOfService.PrinterColors)SlpCurrentCartridge;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual bool GetCapConcurrentPageMode(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).CapConcurrentPageMode;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapRecPageMode(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).CapRecPageMode;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapSlpPageMode(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).CapSlpPageMode;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual Point GetPageModeArea(string ConsumerID)
        {
            try
            {
                System.Drawing.Point value = System.Drawing.Point.Empty;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).PageModeArea;
                });

                return new Point() { X = value.X, Y = value.Y };
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual int GetPageModeDescriptor(string ConsumerID)
        {
            try
            {
                int value = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (int)ConcretizationDevice(sessionContext.Device).PageModeDescriptor;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual int GetPageModeHorizontalPosition(string ConsumerID)
        {
            try
            {
                int value = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).PageModeHorizontalPosition;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetPageModeHorizontalPosition(string ConsumerID, int PageModeHorizontalPosition)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).PageModeHorizontalPosition = PageModeHorizontalPosition;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual Rectangle GetPageModePrintArea(string ConsumerID)
        {
            try
            {
                System.Drawing.Rectangle value = System.Drawing.Rectangle.Empty;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).PageModePrintArea;
                });

                return new Rectangle() { Height = value.Height, Width = value.Width, X = value.X, Y = value.Y };
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void SetPageModePrintArea(string ConsumerID, Rectangle PageModePrintArea)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).PageModePrintArea = new System.Drawing.Rectangle(PageModePrintArea.X, PageModePrintArea.Y, PageModePrintArea.Width, PageModePrintArea.Height);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual PageModePrintDirection GetPageModePrintDirection(string ConsumerID)
        {
            try
            {
                PageModePrintDirection value = PageModePrintDirection.PTR_PD_LEFT_TO_RIGHT;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (PageModePrintDirection)Convert[ConcretizationDevice(sessionContext.Device).PageModePrintDirection];
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetPageModePrintDirection(string ConsumerID, PageModePrintDirection PageModePrintDirection)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).PageModePrintDirection = (Microsoft.PointOfService.PageModePrintDirection)Convert[PageModePrintDirection];
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PrinterStation GetPageModeStation(string ConsumerID)
        {
            try
            {
                PrinterStation value = PrinterStation.PTR_S_RECEIPT;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (PrinterStation)Convert[ConcretizationDevice(sessionContext.Device).PageModeStation];
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetPageModeStation(string ConsumerID, PrinterStation PageModeStation)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).PageModeStation = (Microsoft.PointOfService.PrinterStation)Convert[PageModeStation];
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual int GetPageModeVerticalPosition(string ConsumerID)
        {
            try
            {
                int value = 0;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).PageModeVerticalPosition;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetPageModeVerticalPosition(string ConsumerID, int PageModeVerticalPosition)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).PageModeVerticalPosition = PageModeVerticalPosition;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PowerReporting GetCapPowerReporting(string ConsumerID)
        {
            try
            {
                PowerReporting value = PowerReporting.PR_NONE;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (PowerReporting)Convert[ConcretizationDevice(sessionContext.Device).CapPowerReporting];
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapStatisticsReporting(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).CapStatisticsReporting;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapUpdateStatistics(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).CapUpdateStatistics;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual string GetCheckHealthText(string ConsumerID)
        {
            try
            {
                string value = null;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).CheckHealthText;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetClaimed(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).Claimed;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetDeviceEnabled(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).DeviceEnabled;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetDeviceEnabled(string ConsumerID, bool DeviceEnabled)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).DeviceEnabled = DeviceEnabled;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetFreezeEvents(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).FreezeEvents;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetFreezeEvents(string ConsumerID, bool FreezeEvents)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).FreezeEvents = FreezeEvents;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PowerNotification GetPowerNotify(string ConsumerID)
        {
            try
            {
                PowerNotification value = PowerNotification.PN_DISABLED;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (PowerNotification)Convert[ConcretizationDevice(sessionContext.Device).PowerNotify];
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual void SetPowerNotify(string ConsumerID, PowerNotification PowerNotify)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).PowerNotify = (Microsoft.PointOfService.PowerNotification)Convert[PowerNotify];
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual PowerState GetPowerState(string ConsumerID)
        {
            try
            {
                PowerState value = PowerState.PS_UNKNOWN;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (PowerState)Convert[ConcretizationDevice(sessionContext.Device).PowerState];
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual ControlState GetState(string ConsumerID)
        {
            try
            {
                ControlState value = ControlState.S_CLOSED;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = (ControlState)Convert[ConcretizationDevice(sessionContext.Device).State];
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapCompareFirmwareVersion(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).CapCompareFirmwareVersion;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }
        public virtual bool GetCapUpdateFirmware(string ConsumerID)
        {
            try
            {
                bool value = false;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).CapUpdateFirmware;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual string GetDeviceControlDescription(string ConsumerID)
        {
            base.GetSessionContext(ConsumerID); // セッションタイムアウトをクリアするために取得する
            return _deviceControlDescription;
        }

        public virtual UposVersion GetDeviceControlVersion(string ConsumerID)
        {
            base.GetSessionContext(ConsumerID); // セッションタイムアウトをクリアするために取得する
            return _deviceControlVersion;
        }

        public virtual string GetDeviceServiceDescription(string ConsumerID)
        {
            try
            {
                string value = null;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).ServiceObjectDescription;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual UposVersion GetDeviceServiceVersion(string ConsumerID)
        {
            try
            {
                Version value = null;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).ServiceObjectVersion;
                });
                
                return new UposVersion() { Build = value.Build, Major = value.Major, Minor = value.Minor };
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }

        }

        public virtual string GetPhysicalDeviceDescription(string ConsumerID)
        {
            try
            {
                string value = null;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).DeviceDescription;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual string GetPhysicalDeviceName(string ConsumerID)
        {
            try
            {
                string value = null;

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    value = ConcretizationDevice(sessionContext.Device).DeviceName;
                });

                return value;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        #endregion

        #region POSPrinter Methods

        public virtual string GetEncryptedClaimedConsumerID()
        {
            try
            {
                var consumerIDs = base.GetAllSessionIDs();

                string claimedConsumerID = null;

            LOOP_START:

                foreach (var id in consumerIDs)
                {
                    try
                    {
                        if (claimedConsumerID != null)
                        {
                            break;
                        }

                        var sessionContext = base.GetSessionContext(id);
                        sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                        {
                            if (ConcretizationDevice(sessionContext.Device).Claimed)
                            {
                                claimedConsumerID = id;
                            }
                        });
                    }
                    catch (KeyNotFoundException)
                    {
                        ;// 時間差で削除された
                    }
                    catch (InvalidOperationException)
                    {
                        goto LOOP_START;// 時間差で削除された
                    }
                    catch (Microsoft.PointOfService.PosControlException)
                    {
                        ;// Closeされた
                    }
                }

                if (claimedConsumerID != null)
                {
                    return base.EncryptConsumerID(claimedConsumerID);
                }
                else
                {
                    return null;
                }
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void OpenSession(string ConsumerID, string EndpointAddress)
        {
            try
            {
                UnifiedPOS.POSPrinterEvents.V1_4.POSPrinterEvent deviceEvent = null;
                if (EndpointAddress != null)
                {
                    ChannelFactory<UnifiedPOS.POSPrinterEvents.V1_4.POSPrinterEvent> factory =
                        new ChannelFactory<UnifiedPOS.POSPrinterEvents.V1_4.POSPrinterEvent>("POSPrinterEventPort", new EndpointAddress(EndpointAddress));

                    deviceEvent = factory.CreateChannel();
                }

                ISessionContext sessionContext = base.CreateSessionContext(ConsumerID, deviceEvent);

                sessionContext.ServiceDirectIOEvent += new EventHandler<Microsoft.PointOfService.DirectIOEventArgs>(SessionContext_ServiceDirectIOEvent);
                sessionContext.ServiceDataEvent += new EventHandler<Microsoft.PointOfService.DataEventArgs>(SessionContext_ServiceDataEvent);
                sessionContext.ServiceErrorEvent += new EventHandler<Microsoft.PointOfService.DeviceErrorEventArgs>(SessionContext_ServiceErrorEvent);
                sessionContext.ServiceOutputCompleteEvent += new EventHandler<Microsoft.PointOfService.OutputCompleteEventArgs>(SessionContext_ServiceOutputCompleteEvent);
                sessionContext.ServiceStatusUpdateEvent += new EventHandler<Microsoft.PointOfService.StatusUpdateEventArgs>(SessionContext_ServiceStatusUpdateEvent);

                foreach (ServiceEndpoint Endpoint in OperationContext.Current.Host.Description.Endpoints)
                {
                    if (Endpoint.Address.Equals(OperationContext.Current.Channel.LocalAddress))
                    {
                        ConfigDeviceBehavior ConfigDevice = Endpoint.Behaviors.Find<ConfigDeviceBehavior>();
                        if (ConfigDevice != null)
                        {
                            sessionContext.DeviceName = ConfigDevice.deviceName;
                            sessionContext.ProviderSessionTimeout = ConfigDevice.providerSessionTimeout;
                            sessionContext.EventPollingTimeout = ConfigDevice.eventPollingTimeout > 0 ? ConfigDevice.eventPollingTimeout * 1000 : ConfigDevice.eventPollingTimeout;
                            sessionContext.EventResponseTimeout = ConfigDevice.eventResponseTimeout > 0 ? ConfigDevice.eventResponseTimeout * 1000 : ConfigDevice.eventResponseTimeout;
                            sessionContext.CodePageConversion = ConfigDevice.codePageConversion;
                        }
                    }
                }

                base.AddSession(ConsumerID, sessionContext);
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void OpenDevice(string ConsumerID)
        {
            try
            {
                ISessionContext sessionContext = GetSessionContext(ConsumerID);

                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    base.OpenDeviceInSessionContext(sessionContext, "PosPrinter", sessionContext.DeviceName);

                    var device = ConcretizationDevice(sessionContext.Device);
                    device.Open();
                    //device.DataEvent += new Microsoft.PointOfService.DataEventHandler(sessionContext.DeviceDataEventHandler);
                    device.DirectIOEvent += new Microsoft.PointOfService.DirectIOEventHandler(sessionContext.DeviceDirectIOEventHandler);
                    device.ErrorEvent += new Microsoft.PointOfService.DeviceErrorEventHandler(sessionContext.DeviceErrorEventHandler);
                    device.OutputCompleteEvent += new Microsoft.PointOfService.OutputCompleteEventHandler(sessionContext.DeviceOutputCompleteEventHandler);
                    device.StatusUpdateEvent += new Microsoft.PointOfService.StatusUpdateEventHandler(sessionContext.DeviceStatusUpdateEventHandler);

                    sessionContext.IsLegacySO = false;
                    try
                    {
                        // OPOS Legacy SO の場合は BinaryConversion を設定する。設定に成功するならば LegacySOと判断する。
                        var legacyDevice = (Microsoft.PointOfService.ILegacyControlObject)device;
                        sessionContext.IsLegacySO = true;
                        legacyDevice.BinaryConversion = Microsoft.PointOfService.BinaryConversion.Nibble;
                    }
                    catch  { }
                }
                );
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void CloseDevice(string ConsumerID)
        {
            try
            {
                ISessionContext sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    DisposeDevice(sessionContext);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void CloseSession(string ConsumerID)
        {
            try
            {
                ISessionContext sessionContext = base.GetSessionContext(ConsumerID);
                CloseSessionResources(sessionContext);

                base.RemoveSessionContext(ConsumerID);
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual void ClearPrintArea(string ConsumerID)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).ClearPrintArea();
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void PageModePrint(string ConsumerID, PageModePrintControl Control)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).PageModePrint((Microsoft.PointOfService.PageModePrintControl)Convert[Control]);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void BeginInsertion(string ConsumerID, int Timeout)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).BeginInsertion(Timeout);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void BeginRemoval(string ConsumerID, int Timeout)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).BeginRemoval(Timeout);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void ChangePrintSide(string ConsumerID, PrinterSide Side)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).ChangePrintSide((Microsoft.PointOfService.PrinterSide)Convert[Side]);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void CutPaper(string ConsumerID, int Percentage)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).CutPaper(Percentage);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void EndInsertion(string ConsumerID)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).EndInsertion();
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void EndRemoval(string ConsumerID)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).EndRemoval();
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void MarkFeed(string ConsumerID, int Type)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).MarkFeed((Microsoft.PointOfService.PrinterMarkFeeds)Type);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void PrintBarCode(string ConsumerID, PrinterStation Station, string Data, int Symbology, int Height, int Width, int Alignment, BarCodeTextPosition TextPosition)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var value = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, Data);
                    ConcretizationDevice(sessionContext.Device).PrintBarCode((Microsoft.PointOfService.PrinterStation)Convert[Station], base.ProcessEscapeSequence(value), (Microsoft.PointOfService.BarCodeSymbology)Symbology, Height, Width, Alignment, (Microsoft.PointOfService.BarCodeTextPosition)Convert[TextPosition]);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void PrintBitmap(string ConsumerID, PrinterStation Station, string FileName, int Width, int Alignment)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                var device = ConcretizationDevice(sessionContext.Device);
                UriToTempFileHelper.UriToTempFileExecuteTargetMethod(FileName, !device.AsyncMode, (tempFileName) =>
                    {
                        sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                        {
                            sessionContext.TempFileNamesForDeleteWhenCloseDevice.Add(tempFileName);
                            device.PrintBitmap((Microsoft.PointOfService.PrinterStation)Convert[Station], tempFileName, Width, Alignment);
                        });
                    });
            }
            catch (NotSupportedException nsex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), nsex);
                UposException uex = new UposException();
                uex.ErrorCode = ErrorCode.E_ILLEGAL;
                uex.ErrorCodeExtended = 0;
                throw new FaultException<UposException>(uex, nsex.Message);
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void PrintImmediate(string ConsumerID, PrinterStation Station, string Data)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var value = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, Data);
                    ConcretizationDevice(sessionContext.Device).PrintImmediate((Microsoft.PointOfService.PrinterStation)Convert[Station], base.ProcessEscapeSequence(value));
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual void PrintNormal(string ConsumerID, PrinterStation Station, string Data)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var value = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, Data);
                    ConcretizationDevice(sessionContext.Device).PrintNormal((Microsoft.PointOfService.PrinterStation)Convert[Station], base.ProcessEscapeSequence(value));
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual void PrintTwoNormal(string ConsumerID, PrinterStation Station, string Data1, string Data2)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var value1 = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, Data1);
                    var value2 = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, Data2);
                    ConcretizationDevice(sessionContext.Device).PrintTwoNormal((Microsoft.PointOfService.PrinterStation)Convert[Station], base.ProcessEscapeSequence(value1), base.ProcessEscapeSequence(value2));
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual void RotatePrint(string ConsumerID, PrinterStation Station, int Rotation)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).RotatePrint((Microsoft.PointOfService.PrinterStation)Convert[Station], (Microsoft.PointOfService.PrintRotation)Rotation);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void SetBitmap(string ConsumerID, int BitmapNumber, PrinterStation Station, string FileName, int Width, int Alignment)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                var device = ConcretizationDevice(sessionContext.Device);
                UriToTempFileHelper.UriToTempFileExecuteTargetMethod(FileName, true, (tempFileName) =>
                {
                    sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                    {
                        sessionContext.TempFileNamesForDeleteWhenCloseDevice.Add(tempFileName);
                        device.SetBitmap(BitmapNumber, (Microsoft.PointOfService.PrinterStation)Convert[Station], tempFileName, Width, Alignment);
                    });
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void SetLogo(string ConsumerID, PrinterLogoLocation Location, string Data)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var value = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, Data);
                    ConcretizationDevice(sessionContext.Device).SetLogo((Microsoft.PointOfService.PrinterLogoLocation)Convert[Location], base.ProcessEscapeSequence(value));
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual void TransactionPrint(string ConsumerID, PrinterStation Station, PrinterTransactionControl Control)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).TransactionPrint((Microsoft.PointOfService.PrinterStation)Convert[Station], (Microsoft.PointOfService.PrinterTransactionControl)Convert[Control]);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void ValidateData(string ConsumerID, PrinterStation Station, string Data)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var value = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, Data);
                    ConcretizationDevice(sessionContext.Device).ValidateData((Microsoft.PointOfService.PrinterStation)Convert[Station], base.ProcessEscapeSequence(value));
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual void PrintMemoryBitmap(string ConsumerID, PrinterStation Station, byte[] Data, BitmapType type, int Width, int Alignment)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    System.Drawing.Bitmap value = new System.Drawing.Bitmap(new System.IO.MemoryStream(Data));
                    ConcretizationDevice(sessionContext.Device).PrintMemoryBitmap((Microsoft.PointOfService.PrinterStation)Convert[Station], value, Width, Alignment);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual void ClearOutput(string ConsumerID)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).ClearOutput();
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void CheckHealth(string ConsumerID, HealthCheckLevel Level)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).CheckHealth((Microsoft.PointOfService.HealthCheckLevel)Convert[Level]);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void Claim(string ConsumerID, int Timeout)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    ConcretizationDevice(sessionContext.Device).Claim(Timeout);
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual DirectIOData DirectIO(string ConsumerID, int Command, int Data, object Obj)
        {
            try
            {
                Microsoft.PointOfService.DirectIOData value = new Microsoft.PointOfService.DirectIOData();

                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    string artsB = (string)Obj;
                    var str = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, artsB);
                    value = ConcretizationDevice(sessionContext.Device).DirectIO(Command, Data, str);
                });
                return new DirectIOData() { Data = value.Data, Obj = base.ConvertStringToARTSBinary(sessionContext.IsLegacySO, sessionContext.CodePageConversion, (string)value.Object) };
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void Release(string ConsumerID)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var freezeEvents = ConcretizationDevice(sessionContext.Device).FreezeEvents;
                    ConcretizationDevice(sessionContext.Device).FreezeEvents = true;
                    base.WaitForEventHandlerReturned(sessionContext);

                    ConcretizationDevice(sessionContext.Device).Release();
                    base.DeleteAsyncTemporaryFiles(sessionContext);

                    ConcretizationDevice(sessionContext.Device).FreezeEvents = freezeEvents;
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void ResetStatistics(string ConsumerID, StatisticList StatisticsBuffer)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var device = ConcretizationDevice(sessionContext.Device);

                    var value = new List<string>(); foreach (var s in StatisticsBuffer) { value.Add(s.Name); }　// .NET FW 3のため、Linq使用不可 var value = from el in StatisticsBuffer select el.Name;;
                    switch (value.Count)
                    {
                        case 0:
                            device.ResetStatistics();
                            break;
                        case 1:
                            string name = value[0];
                            switch (name)
                            {
                                case StatisticCategories.All:
                                    device.ResetStatistics(Microsoft.PointOfService.StatisticCategories.All);
                                    break;
                                case StatisticCategories.Manufacturer:
                                    device.ResetStatistics(Microsoft.PointOfService.StatisticCategories.Manufacturer);
                                    break;
                                case StatisticCategories.Upos:
                                    device.ResetStatistics(Microsoft.PointOfService.StatisticCategories.Upos);
                                    break;
                                default:
                                    device.ResetStatistic(name);
                                    break;
                            }
                            break;
                        default:
                            device.ResetStatistics(value.ToArray());
                            break;
                    }
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual string RetrieveStatistics(string ConsumerID, StatisticList StatisticsBuffer)
        {
            try
            {
                string res = null;
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var device = ConcretizationDevice(sessionContext.Device);
                    var value = new List<string>(); foreach (var s in StatisticsBuffer) { value.Add(s.Name); }　// .NET FW 3のため、Linq使用不可 var value = from el in StatisticsBuffer select el.Name;;
                    switch (value.Count)
                    {
                        case 0:
                            res = device.RetrieveStatistics();
                            break;
                        case 1:
                            string name = value[0];
                            switch (name)
                            {
                                case StatisticCategories.All:
                                    res = device.RetrieveStatistics(Microsoft.PointOfService.StatisticCategories.All);
                                    break;
                                case StatisticCategories.Manufacturer:
                                    res = device.RetrieveStatistics(Microsoft.PointOfService.StatisticCategories.Manufacturer);
                                    break;
                                case StatisticCategories.Upos:
                                    res = device.RetrieveStatistics(Microsoft.PointOfService.StatisticCategories.Upos);
                                    break;
                                default:
                                    res = device.RetrieveStatistic(name);
                                    break;
                            }
                            break;
                        default:
                            res = device.RetrieveStatistics(value.ToArray());
                            break;
                    }
                });
                return res;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void UpdateStatistics(string ConsumerID, StatisticList StatisticsBuffer)
        {
            try
            {
                var sessionContext = base.GetSessionContext(ConsumerID);
                sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                {
                    var device = ConcretizationDevice(sessionContext.Device);
                    var value = new List<Microsoft.PointOfService.Statistic>(); foreach (var s in StatisticsBuffer) { value.Add(new Microsoft.PointOfService.Statistic(s.Name, s.Value)); } // var value = from el in StatisticsBuffer select new Microsoft.PointOfService.Statistic(el.Name, el.Value);
                    switch (value.Count)
                    {
                        case 0:
                            device.UpdateStatistics(value.ToArray());
                            break;
                        case 1:
                            Microsoft.PointOfService.Statistic statistic = value[0];
                            switch (statistic.Name)
                            {
                                case StatisticCategories.All:
                                    device.UpdateStatistics(Microsoft.PointOfService.StatisticCategories.All, statistic.Value);
                                    break;
                                case StatisticCategories.Manufacturer:
                                    device.UpdateStatistics(Microsoft.PointOfService.StatisticCategories.Manufacturer, statistic.Value);
                                    break;
                                case StatisticCategories.Upos:
                                    device.UpdateStatistics(Microsoft.PointOfService.StatisticCategories.Upos, statistic.Value);
                                    break;
                                default:
                                    device.UpdateStatistic(statistic.Name, statistic.Value);
                                    break;
                            }
                            break;
                        default:
                            device.UpdateStatistics(value.ToArray());
                            break;
                    }
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual CompareFirmwareResult CompareFirmwareVersion(string ConsumerID, string FirmwareFileName)
        {
            try
            {
                CompareFirmwareResult result = CompareFirmwareResult.CFV_FIRMWARE_UNKNOWN;

                UriToTempFileHelper.UriToTempFileExecuteTargetMethod(FirmwareFileName, true, (tempFileName) =>
                {
                    var sessionContext = base.GetSessionContext(ConsumerID);
                    sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                    {
                        sessionContext.TempFileNamesForDeleteWhenCloseDevice.Add(tempFileName);
                        result = (CompareFirmwareResult)Convert[ConcretizationDevice(sessionContext.Device).CompareFirmwareVersion(tempFileName)];
                    });
                });

                return result;
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        public virtual void UpdateFirmware(string ConsumerID, string FirmwareFileName)
        {
            try
            {
                UriToTempFileHelper.UriToTempFileExecuteTargetMethod(FirmwareFileName, false, (tempFileName) =>
                {
                    var sessionContext = base.GetSessionContext(ConsumerID);
                    sessionContext.DeviceThread.ExecuteOnWorkerThread(() =>
                    {
                        sessionContext.TempFileNamesForDeleteWhenCloseDevice.Add(tempFileName);
                        ConcretizationDevice(sessionContext.Device).UpdateFirmware(tempFileName);
                    });
                });
            }
            catch (Microsoft.PointOfService.PosControlException pex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), pex);
                UposException uex = new UposException();
                uex.ErrorCode = (ErrorCode)Convert[pex.ErrorCode];
                uex.ErrorCodeExtended = pex.ErrorCodeExtended;
                throw new FaultException<UposException>(uex, pex.Message);
            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual UposVersion GetWSPOSVersion()
        {
            return _wsposVersion;
        }

        #endregion

        #region POSPrinter Events

        /// <summary>
        /// サービス内でのDataEventハンドラ
        /// DataEvent handler in the service
        /// </summary>
        /// <param name="sender">Sender instance</param>
        /// <param name="e">Event argument</param>
        protected override void SessionContext_ServiceDataEvent(object sender, Microsoft.PointOfService.DataEventArgs e)
        {
            try
            {
                ISessionContext sessionContext = sender as ISessionContext;

                // デバイスをCloseする際に、このイベントハンドラが実行中でないことを確認するためのフラグを設定する。
                // When Closing a device, the flag for checking that this event handler is not going.
                sessionContext.UPOSEventHandlingOnGoing = true;

                if (sessionContext.ConsumerEventPort != null)
                {
                    // 双方向通信
                    // LegacySOのSTAからのRPC呼び出しに伴うアパートメントブロックによるデッドロックを回避するため、ワーカスレッドで呼び出します。
                    // Bi-directional communication: 
                    // In order to avoid the deadlock by the apartment block accompanying the RPC call from STA of LegacySO, it is called by a worker thread. 
                    System.Threading.Thread eventCallThread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
                    {
                        var deviceEvent = ConcretizationConsumerEventPort(sessionContext.ConsumerEventPort);
                        bool isTimeoutHappened = false;
                        do
                        {
                            try
                            {
                                //deviceEvent.DataEvent(sessionContext.ConsumerID, sessionContext.Device.ToString(), e.EventId, e.TimeStamp, e.Status);
                            }
                            catch (Exception ex)
                            {
                                if (ex is TimeoutException || ex is EndpointNotFoundException)
                                {
                                    isTimeoutHappened = true;
                                    // レスポンスが帰ってこない場合、再度通知します。
                                    // タイムアウトになり続けた場合、ProviderSessionTimeout値によって
                                    // セッションが閉じられるまでこれを続けます。
                                    // When a response does not come back, it notifies again. 
                                    // When it continues being timing out, this is continued until a 
                                    // session is closed by the ProviderSessionTimeout value. 
                                    if (sessionContext.IsClosed)
                                    {
                                        base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, and session closed.");
                                        break;
                                    }
                                    base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, then retry.");
                                }
                                else
                                {
                                    break;
                                }
                            }
                        } while (isTimeoutHappened);
                    }));
                    eventCallThread.Start();
                    eventCallThread.Join();
                }
                else
                {
                    // ロングポーリング
                    // Long polling

                    // PollForUPOSEventでの待ちに対して通知する
                    // Notifying wait in PollForUPOSEvent

                    sessionContext.DeviceEventArgs = e;
                    sessionContext.DeviceEventHappened.Signal();

                    // EventResponseの呼び出しを待つ
                    // It waits for the call of EventResponse.
                    sessionContext.SetEventResponseCalled.Wait(sessionContext.EventResponseTimeout);
                }
            }
            catch (ObjectDisposedException ex)
            {
                // 待ち合わせ中にセッションが閉じた場合
                // WaitOneがObjectDisposedException例外をスローします。
                // デバイス側は異常ではないため、例外をデバイスにスローせず
                // 記録ログのみ書きます
                // When a session closes during waiting 
                // WaitOne will throw of the ObjectDisposedException exception. 
                // Since the device side is not unusual, it does not throw the exception 
                // to a device, but only writes log records. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            catch (Exception ex)
            {
                // デバイスからのイベントハンドラ内部での例外はデバイスによってハンドリングされないため
                // ログは書き込みますが例外をデバイスにスローしません
                // Since the exception inside the event handler from a device is not handled by the device, 
                // although a log writes in, it does not throw the exception to a device. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            finally
            {
                ISessionContext sessionContext = sender as ISessionContext;
                sessionContext.UPOSEventHandlingOnGoing = false;
            }
        }

        /// <summary>
        /// サービス内でのDirectIOEventハンドラ
        /// </summary>
        /// <param name="sender">送信者インスタンス</param>
        /// <param name="e">イベント引数</param>
        protected override void SessionContext_ServiceDirectIOEvent(object sender, Microsoft.PointOfService.DirectIOEventArgs e)
        {
            try
            {
                ISessionContext sessionContext = sender as ISessionContext;

                // デバイスをCloseする際に、このイベントハンドラが実行中でないことを確認するためのフラグを設定する。
                // When Closing a device, the flag for checking that this event handler is not going.
                sessionContext.UPOSEventHandlingOnGoing = true;

                if (sessionContext.ConsumerEventPort != null)
                {
                    // 双方向通信
                    // LegacySOのSTAからのRPC呼び出しに伴うアパートメントブロックによるデッドロックを回避するため、ワーカスレッドで呼び出します。
                    // Bi-directional communication: 
                    // In order to avoid the deadlock by the apartment block accompanying the RPC call from STA of LegacySO, it is called by a worker thread. 
                    System.Threading.Thread eventCallThread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
                    {
                        var deviceEvent = ConcretizationConsumerEventPort(sessionContext.ConsumerEventPort);
                        bool isTimeoutHappened = false;
                        do
                        {
                            try
                            {
                                string artsB = (string)e.Object;
                                var str = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, artsB);
                                var value = deviceEvent.DirectIOEvent(sessionContext.ConsumerID, sessionContext.Device.ToString(), e.EventId, e.TimeStamp, e.EventNumber, e.Data, str);
                                e.Data = value.Data;
                                e.Object = base.ConvertStringToARTSBinary(sessionContext.IsLegacySO, sessionContext.CodePageConversion, (string)value.Obj);
                            }
                            catch (Exception ex)
                            {
                                if (ex is TimeoutException || ex is EndpointNotFoundException)
                                {
                                    isTimeoutHappened = true;
                                    // レスポンスが帰ってこない場合、再度通知します。
                                    // タイムアウトになり続けた場合、ProviderSessionTimeout値によって
                                    // セッションが閉じられるまでこれを続けます。
                                    // When a response does not come back, it notifies again. 
                                    // When it continues being timing out, this is continued until a 
                                    // session is closed by the ProviderSessionTimeout value. 
                                    if (sessionContext.IsClosed)
                                    {
                                        base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, and session closed.");
                                        break;
                                    }
                                    base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, then retry.");
                                }
                                else
                                {
                                    break;
                                }
                            }
                        } while (isTimeoutHappened);
                    }));
                    eventCallThread.Start();
                    eventCallThread.Join();
                }
                else
                {
                    // ロングポーリング
                    // Long polling

                    // PollForUPOSEventでの待ちに対して通知する
                    // Notifying wait in PollForUPOSEvent

                    sessionContext.DeviceEventArgs = e;
                    sessionContext.DeviceEventHappened.Signal();

                    // EventResponseの呼び出しをまつ
                    if (sessionContext.SetEventResponseCalled.Wait(sessionContext.EventResponseTimeout))
                    {
                        DirectIOData value = sessionContext.DeviceEventResponse as DirectIOData;

                        e.Data = value.Data;
                        e.Object = base.ConvertARTSBinaryToString(sessionContext.IsLegacySO, sessionContext.CodePageConversion, (string)value.Obj);
                    }
                }
            }
            catch (ObjectDisposedException ex)
            {
                // 待ち合わせ中にセッションが閉じた場合
                // WaitOneがObjectDisposedException例外をスローします。
                // デバイス側は異常ではないため、例外をデバイスにスローせず
                // 記録ログのみ書きます
                // When a session closes during waiting 
                // WaitOne will throw of the ObjectDisposedException exception. 
                // Since the device side is not unusual, it does not throw the exception 
                // to a device, but only writes log records. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            catch (Exception ex)
            {
                // デバイスからのイベントハンドラ内部での例外はデバイスによってハンドリングされないため
                // ログは書き込みますが例外をデバイスにスローしません
                // Since the exception inside the event handler from a device is not handled by the device, 
                // although a log writes in, it does not throw the exception to a device. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            finally
            {
                ISessionContext sessionContext = sender as ISessionContext;
                sessionContext.UPOSEventHandlingOnGoing = false;
            }
        }

        /// <summary>
        /// サービス内でのErrorEvventハンドラ
        /// </summary>
        /// <param name="sender">送信者インスタンス</param>
        /// <param name="e">イベント引数</param>
        protected override void SessionContext_ServiceErrorEvent(object sender, Microsoft.PointOfService.DeviceErrorEventArgs e)
        {
            try
            {
                ISessionContext sessionContext = sender as ISessionContext;

                // デバイスをCloseする際に、このイベントハンドラが実行中でないことを確認するためのフラグを設定する。
                // When Closing a device, the flag for checking that this event handler is not going.
                sessionContext.UPOSEventHandlingOnGoing = true;

                if (sessionContext.ConsumerEventPort != null)
                {
                    // 双方向通信
                    // LegacySOのSTAからのRPC呼び出しに伴うアパートメントブロックによるデッドロックを回避するため、ワーカスレッドで呼び出します。
                    // Bi-directional communication: 
                    // In order to avoid the deadlock by the apartment block accompanying the RPC call from STA of LegacySO, it is called by a worker thread. 
                    System.Threading.Thread eventCallThread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
                    {
                        var deviceEvent = ConcretizationConsumerEventPort(sessionContext.ConsumerEventPort);
                        bool isTimeoutHappened = false;
                        do
                        {
                            try
                            {
                                var value = deviceEvent.ErrorEvent(sessionContext.ConsumerID, sessionContext.Device.ToString(), e.EventId, e.TimeStamp, (UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode)EventConvert[e.ErrorCode], e.ErrorCodeExtended, (UnifiedPOS.POSPrinterEvents.V1_4.ErrorLocus)EventConvert[e.ErrorLocus], (UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse)EventConvert[e.ErrorResponse]);
                                e.ErrorResponse = (Microsoft.PointOfService.ErrorResponse)EventConvert[value];
                            }
                            catch (Exception ex)
                            {
                                if (ex is TimeoutException || ex is EndpointNotFoundException)
                                {
                                    isTimeoutHappened = true;
                                    // レスポンスが帰ってこない場合、再度通知します。
                                    // タイムアウトになり続けた場合、ProviderSessionTimeout値によって
                                    // セッションが閉じられるまでこれを続けます。
                                    // When a response does not come back, it notifies again. 
                                    // When it continues being timing out, this is continued until a 
                                    // session is closed by the ProviderSessionTimeout value. 
                                    if (sessionContext.IsClosed)
                                    {
                                        base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, and session closed.");
                                        e.ErrorResponse = Microsoft.PointOfService.ErrorResponse.Clear;
                                        break;
                                    }
                                    base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, then retry.");
                                }
                                else
                                {
                                    break;
                                }
                            }
                        } while (isTimeoutHappened);
                    }));
                    eventCallThread.Start();
                    eventCallThread.Join();
                }
                else
                {
                    // ロングポーリング
                    // Long polling

                    // PollForUPOSEventでの待ちに対して通知する
                    // Notifying wait in PollForUPOSEvent

                    sessionContext.DeviceEventArgs = e;
                    sessionContext.DeviceEventHappened.Signal();

                    // SetEventResponseの呼び出しを待つ
                    if (sessionContext.SetEventResponseCalled.Wait(sessionContext.EventResponseTimeout))
                    {
                        ErrorResponse value = (ErrorResponse)sessionContext.DeviceEventResponse;
                        e.ErrorResponse = (Microsoft.PointOfService.ErrorResponse)EventConvert[value];
                    }
                    else
                    {
                        e.ErrorResponse = Microsoft.PointOfService.ErrorResponse.Clear;
                    }
                }
            }
            catch (ObjectDisposedException ex)
            {
                // 待ち合わせ中にセッションが閉じた場合
                // WaitOneがObjectDisposedException例外をスローします。
                // デバイス側は異常ではないため、例外をデバイスにスローせず
                // 記録ログのみ書きます
                // When a session closes during waiting 
                // WaitOne will throw of the ObjectDisposedException exception. 
                // Since the device side is not unusual, it does not throw the exception 
                // to a device, but only writes log records. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            catch (Exception ex)
            {
                // デバイスからのイベントハンドラ内部での例外はデバイスによってハンドリングされないため
                // ログは書き込みますが例外をデバイスにスローしません
                // Since the exception inside the event handler from a device is not handled by the device, 
                // although a log writes in, it does not throw the exception to a device. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            finally
            {
                ISessionContext sessionContext = sender as ISessionContext;
                sessionContext.UPOSEventHandlingOnGoing = false;
            }
        }

        /// <summary>
        /// サービス内でのOutputCompleteEventハンドラ
        /// </summary>
        /// <param name="sender">送信者インスタンス</param>
        /// <param name="e">イベント引数</param>
        protected override void SessionContext_ServiceOutputCompleteEvent(object sender, Microsoft.PointOfService.OutputCompleteEventArgs e)
        {
            try
            {
                ISessionContext sessionContext = sender as ISessionContext;

                // デバイスをCloseする際に、このイベントハンドラが実行中でないことを確認するためのフラグを設定する。
                // When Closing a device, the flag for checking that this event handler is not going.
                sessionContext.UPOSEventHandlingOnGoing = true;

                if (sessionContext.ConsumerEventPort != null)
                {
                    // 双方向通信
                    // LegacySOのSTAからのRPC呼び出しに伴うアパートメントブロックによるデッドロックを回避するため、ワーカスレッドで呼び出します。
                    // Bi-directional communication: 
                    // In order to avoid the deadlock by the apartment block accompanying the RPC call from STA of LegacySO, it is called by a worker thread. 
                    System.Threading.Thread eventCallThread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
                    {
                        var deviceEvent = ConcretizationConsumerEventPort(sessionContext.ConsumerEventPort);
                        bool isTimeoutHappened = false;
                        do
                        {
                            try
                            {
                                deviceEvent.OutputCompleteEvent(sessionContext.ConsumerID, sessionContext.Device.ToString(), e.EventId, e.TimeStamp, e.OutputId);
                            }
                            catch (Exception ex)
                            {
                                if (ex is TimeoutException || ex is EndpointNotFoundException)
                                {
                                    isTimeoutHappened = true;
                                    // レスポンスが帰ってこない場合、再度通知します。
                                    // タイムアウトになり続けた場合、ProviderSessionTimeout値によって
                                    // セッションが閉じられるまでこれを続けます。
                                    // When a response does not come back, it notifies again. 
                                    // When it continues being timing out, this is continued until a 
                                    // session is closed by the ProviderSessionTimeout value. 
                                    if (sessionContext.IsClosed)
                                    {
                                        base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, and session closed.");
                                        break;
                                    }
                                    base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, then retry.");
                                }
                                else
                                {
                                    break;
                                }
                            }
                        } while (isTimeoutHappened);
                    }));
                    eventCallThread.Start();
                    eventCallThread.Join();
                }
                else
                {
                    // ロングポーリング
                    // Long polling

                    // PollForUPOSEventでの待ちに対して通知する
                    // Notifying wait in PollForUPOSEvent

                    sessionContext.DeviceEventArgs = e;
                    sessionContext.DeviceEventHappened.Signal();

                    // SetEventResponseの呼び出しを待つ
                    sessionContext.SetEventResponseCalled.Wait(sessionContext.EventResponseTimeout);
                }
            }
            catch (ObjectDisposedException ex)
            {
                // 待ち合わせ中にセッションが閉じた場合
                // WaitOneがObjectDisposedException例外をスローします。
                // デバイス側は異常ではないため、例外をデバイスにスローせず
                // 記録ログのみ書きます
                // When a session closes during waiting 
                // WaitOne will throw of the ObjectDisposedException exception. 
                // Since the device side is not unusual, it does not throw the exception 
                // to a device, but only writes log records. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            catch (Exception ex)
            {
                // デバイスからのイベントハンドラ内部での例外はデバイスによってハンドリングされないため
                // ログは書き込みますが例外をデバイスにスローしません
                // Since the exception inside the event handler from a device is not handled by the device, 
                // although a log writes in, it does not throw the exception to a device. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            finally
            {
                ISessionContext sessionContext = sender as ISessionContext;
                sessionContext.UPOSEventHandlingOnGoing = false;
            }
        }

        /// <summary>
        /// サービス内でのStatusUpdateEventハンドラ
        /// </summary>
        /// <param name="sender">送信者インスタンス</param>
        /// <param name="e">イベント引数</param>
        protected override void SessionContext_ServiceStatusUpdateEvent(object sender, Microsoft.PointOfService.StatusUpdateEventArgs e)
        {
            try
            {
                ISessionContext sessionContext = sender as ISessionContext;

                // デバイスをCloseする際に、このイベントハンドラが実行中でないことを確認するためのフラグを設定する。
                // When Closing a device, the flag for checking that this event handler is not going.
                sessionContext.UPOSEventHandlingOnGoing = true;

                if (sessionContext.ConsumerEventPort != null)
                {
                    // 双方向通信
                    // LegacySOのSTAからのRPC呼び出しに伴うアパートメントブロックによるデッドロックを回避するため、ワーカスレッドで呼び出します。
                    // Bi-directional communication: 
                    // In order to avoid the deadlock by the apartment block accompanying the RPC call from STA of LegacySO, it is called by a worker thread. 
                    System.Threading.Thread eventCallThread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
                    {
                        var deviceEvent = ConcretizationConsumerEventPort(sessionContext.ConsumerEventPort);
                        bool isTimeoutHappened = false;
                        do
                        {
                            try
                            {
                                deviceEvent.StatusUpdateEvent(sessionContext.ConsumerID, sessionContext.Device.ToString(), e.EventId, e.TimeStamp, e.Status);
                            }
                            catch (Exception ex)
                            {
                                if (ex is TimeoutException || ex is EndpointNotFoundException)
                                {
                                    isTimeoutHappened = true;
                                    // レスポンスが帰ってこない場合、再度通知します。
                                    // タイムアウトになり続けた場合、ProviderSessionTimeout値によって
                                    // セッションが閉じられるまでこれを続けます。
                                    // When a response does not come back, it notifies again. 
                                    // When it continues being timing out, this is continued until a 
                                    // session is closed by the ProviderSessionTimeout value. 
                                    if (sessionContext.IsClosed)
                                    {
                                        base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, and session closed.");
                                        break;
                                    }
                                    base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "Network timeout when event notify, then retry.");
                                }
                                else
                                {
                                    break;
                                }
                            }
                        } while (isTimeoutHappened);
                    }));
                    eventCallThread.Start();
                    eventCallThread.Join();
                }
                else
                {
                    // ロングポーリング
                    // Long polling

                    // PollForUPOSEventでの待ちに対して通知する
                    // Notifying wait in PollForUPOSEvent

                    sessionContext.DeviceEventArgs = e;
                    sessionContext.DeviceEventHappened.Signal();

                    // SetEventResponseの呼び出しを待つ
                    sessionContext.SetEventResponseCalled.Wait(sessionContext.EventResponseTimeout);
                }
            }
            catch (ObjectDisposedException ex)
            {
                // 待ち合わせ中にセッションが閉じた場合
                // WaitOneがObjectDisposedException例外をスローします。
                // デバイス側は異常ではないため、例外をデバイスにスローせず
                // 記録ログのみ書きます
                // When a session closes during waiting 
                // WaitOne will throw of the ObjectDisposedException exception. 
                // Since the device side is not unusual, it does not throw the exception 
                // to a device, but only writes log records. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            catch (Exception ex)
            {
                // デバイスからのイベントハンドラ内部での例外はデバイスによってハンドリングされないため
                // ログは書き込みますが例外をデバイスにスローしません
                // Since the exception inside the event handler from a device is not handled by the device, 
                // although a log writes in, it does not throw the exception to a device. 
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
            }
            finally
            {
                ISessionContext sessionContext = sender as ISessionContext;
                sessionContext.UPOSEventHandlingOnGoing = false;
            }
        }


        public virtual POSPrinterEvent PollForUPOSEvent(string ConsumerID)
        {
            try
            {
                ISessionContext sessionContext = base.GetSessionContext(ConsumerID);
                if (sessionContext.ConsumerEventPort != null)
                {
                    // 双方向通信でOpenSessionを呼び出した場合はPollForUPOSEventは使えません
                    // PollForUPOSEvent cannot be used when OpenSession is called by bi-directional communication. 
                    throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "bi-direction mode.", new FaultCode("Server"));
                }

                // このセッションで、既にPollForUPOSEventが呼ばれていた場合に前のPollForUPOSEventを終了して新たに待ち始めます。
                // これは、前のPollForUPOSEvent待ち時にネットワークが切断され、待ち時間内にアプリから再度PollForUPOSEventされたケースを想定しています。
                // これをしなくともセッションタイムアウトで解放されるので、最終的にリークはしませんが、アプリケーションにとって、
                // 既に(ネットワークの)エラーになった前のPollForUPOSEventが終わるまで新たにイベントがとれないというのは問題になります。
                // In this session, when PollForUPOSEvent is already called, front PollForUPOSEvent is ended and it newly begins to wait. 
                // A network is disconnected at the time of front PollForUPOSEvent waiting, and this assumes the case again PollForUPOSEvent from the application in waiting time. 
                // Since it is released by session timeout even if it does not carry out this, finally leak is not carried out, 
                // but it becomes a problem that an event cannot newly be taken until PollForUPOSEvent before already becoming an network) error finishes for application. 
                lock (sessionContext)
                {
                    if (sessionContext.IsPollingNow)
                    {
                        // 自分以外のスレッドがPollForUPOSEventしているなら前のスレッドに
                        // 終了するように通知する
                        // If threads other than themselves are PollForUPOSEvent(ing), 
                        // it will be reported that it ends to a front thread.
                        sessionContext.OtherPollForUPOSEventCalled.Signal();
                        // 前のスレッドの終了を待つ（すぐに待ち終わります）
                        // It waits for the end of a front thread (it finishes waiting immediately). 
                        sessionContext.PreviousPollForUPOSEventEnded.Wait(sessionContext.EventPollingTimeout);
                    }
                }
                sessionContext.IsPollingNow = true;

                IEventWait[] waits = new IEventWait[2];
                waits[0] = sessionContext.DeviceEventHappened;
                waits[1] = sessionContext.OtherPollForUPOSEventCalled;

                int signaledIndex = sessionContext.DeviceEventHappened.WaitForAny(waits, sessionContext.EventPollingTimeout);

                try
                {
                    if (signaledIndex != 0)
                    {
                        // タイムアウトまたは他のPollForUPOSEventによって待ちが中断
                        // Waiting is interrupted by timeout or other PollForUPOSEvent(s). 
                        base.LogWriteLineMessage(MethodBase.GetCurrentMethod(), "PollForUPOSEvent aborted by timeout or other PollForUPOSEvent call.");

                        return null;
                    }
                    if (sessionContext.DeviceEventArgs is Microsoft.PointOfService.DirectIOEventArgs)
                    {
                        Microsoft.PointOfService.DirectIOEventArgs e = sessionContext.DeviceEventArgs as Microsoft.PointOfService.DirectIOEventArgs;

                        POSPrinterEvent posServiceEvent = new POSPrinterEvent();
                        posServiceEvent.DirectIOEvent = new DirectIOEvent();

                        posServiceEvent.DirectIOEvent.Source = sessionContext.Device.ToString();
                        posServiceEvent.DirectIOEvent.EventID = e.EventId;
                        posServiceEvent.DirectIOEvent.TimeStamp = e.TimeStamp;
                        posServiceEvent.DirectIOEvent.EventNumber = e.EventNumber;
                        posServiceEvent.DirectIOEvent.Data = e.Data;
                        posServiceEvent.DirectIOEvent.Obj = base.ConvertStringToARTSBinary(sessionContext.IsLegacySO, sessionContext.CodePageConversion, (string)e.Object);;

                        return posServiceEvent;
                    }
                    else if (sessionContext.DeviceEventArgs is Microsoft.PointOfService.DataEventArgs)
                    {
                        Microsoft.PointOfService.DataEventArgs e = sessionContext.DeviceEventArgs as Microsoft.PointOfService.DataEventArgs;

                        POSPrinterEvent posServiceEvent = new POSPrinterEvent();
                        //posServiceEvent.DataEvent = new DataEvent();

                        //posServiceEvent.DataEvent.Source = sessionContext.Device.ToString();
                        //posServiceEvent.DataEvent.EventID = e.EventId;
                        //posServiceEvent.DataEvent.TimeStamp = e.TimeStamp;
                        //posServiceEvent.DataEvent.Status = e.Status;

                        return posServiceEvent;
                    }
                    else if (sessionContext.DeviceEventArgs is Microsoft.PointOfService.DeviceErrorEventArgs)
                    {
                        Microsoft.PointOfService.DeviceErrorEventArgs e = sessionContext.DeviceEventArgs as Microsoft.PointOfService.DeviceErrorEventArgs;

                        POSPrinterEvent posServiceEvent = new POSPrinterEvent();
                        posServiceEvent.ErrorEvent = new ErrorEvent();

                        posServiceEvent.ErrorEvent.Source = sessionContext.Device.ToString();
                        posServiceEvent.ErrorEvent.EventID = e.EventId;
                        posServiceEvent.ErrorEvent.TimeStamp = e.TimeStamp;
                        posServiceEvent.ErrorEvent.ErrorCode = (ErrorCode)EventConvert[e.ErrorCode];
                        posServiceEvent.ErrorEvent.ErrorCodeExtended = e.ErrorCodeExtended;
                        posServiceEvent.ErrorEvent.ErrorLocus = (ErrorLocus)EventConvert[e.ErrorLocus];
                        posServiceEvent.ErrorEvent.ErrorResponse = (ErrorResponse)EventConvert[e.ErrorResponse];

                        return posServiceEvent;
                    }
                    else if (sessionContext.DeviceEventArgs is Microsoft.PointOfService.OutputCompleteEventArgs)
                    {
                        Microsoft.PointOfService.OutputCompleteEventArgs e = sessionContext.DeviceEventArgs as Microsoft.PointOfService.OutputCompleteEventArgs;

                        POSPrinterEvent posServiceEvent = new POSPrinterEvent();
                        posServiceEvent.OutputCompleteEvent = new OutputCompleteEvent();

                        posServiceEvent.OutputCompleteEvent.Source = sessionContext.Device.ToString();
                        posServiceEvent.OutputCompleteEvent.EventID = e.EventId;
                        posServiceEvent.OutputCompleteEvent.TimeStamp = e.TimeStamp;
                        posServiceEvent.OutputCompleteEvent.OutputID = e.OutputId;

                        return posServiceEvent;
                    }
                    else if (sessionContext.DeviceEventArgs is Microsoft.PointOfService.StatusUpdateEventArgs)
                    {
                        Microsoft.PointOfService.StatusUpdateEventArgs e = sessionContext.DeviceEventArgs as Microsoft.PointOfService.StatusUpdateEventArgs;

                        POSPrinterEvent posServiceEvent = new POSPrinterEvent();
                        posServiceEvent.StatusUpdateEvent = new StatusUpdateEvent();

                        posServiceEvent.StatusUpdateEvent.Source = sessionContext.Device.ToString();
                        posServiceEvent.StatusUpdateEvent.EventID = e.EventId;
                        posServiceEvent.StatusUpdateEvent.TimeStamp = e.TimeStamp;
                        posServiceEvent.StatusUpdateEvent.Status = e.Status;

                        return posServiceEvent;
                    }
                    else
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_FAILURE }, "Invalid Device Event type.", new FaultCode("Server"));
                    }
                }
                finally
                {
                    sessionContext.IsPollingNow = false;
                    if (signaledIndex == 1)
                    {
                        sessionContext.PreviousPollForUPOSEventEnded.Signal();
                    }
                }
            }
            catch (Exception ex)
            {
                // 待ち合わせ中にセッションが閉じられると
                // WaitEventHandleハンドルがDisposeされるため
                // ObjectDisposedException例外がスローされます。
                // 例外処理そのものはException例外の処理と同じですが、
                // 待ち合わせ中のセッションタイムアウトの考慮をした記録として
                // コメントを残します
                // If a session is closed during waiting, 
                // since a WaitEventHandle handle is Dispose(d),
                // ObjectDisposedException exception is thrown. 
                // Although the exception handling itself is the same as processing of an Exception exception, 
                // leave this comment as a record of the session timed out while waiting for a consideration

                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }

        public virtual void SetEventResponse(string ConsumerID, POSPrinterEventResponse Response)
        {
            try
            {
                ISessionContext sessionContext = base.GetSessionContext(ConsumerID);
                if (sessionContext.ConsumerEventPort != null)
                {
                    // 双方向通信でOpenSessionを呼び出した場合はSetEventResponseは使えません
                    // SetEventResponse cannot be used when OpenSession is called by bi-directional communication. 
                    throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "bi-direction mode.", new FaultCode("Server"));
                }

                if (Response.DirectIOEventResponse != null)
                {
                    var sessionContextArgs = sessionContext.DeviceEventArgs as Microsoft.PointOfService.DirectIOEventArgs;
                    if (sessionContextArgs == null)
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid Operation.", new FaultCode("Server"));
                    }
                    if (Response.DirectIOEventResponse.EventID != sessionContextArgs.EventId)
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid EventID.", new FaultCode("Server"));
                    }
                    sessionContext.DeviceEventResponse = Response.DirectIOEventResponse.DirectIOData;
                }
                //else if (Response.DataEventResponse != null)
                //{
                //    var sessionContextArgs = sessionContext.DeviceEventArgs as Microsoft.PointOfService.DataEventArgs;
                //    if (sessionContextArgs == null)
                //    {
                //        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid Operation.", new FaultCode("Server"));
                //    }
                //    if (Response.DataEventResponse.EventID != sessionContextArgs.EventId)
                //    {
                //        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid EventID.", new FaultCode("Server"));
                //    }
                //}
                else if (Response.ErrorEventResponse != null)
                {
                    var sessionContextArgs = sessionContext.DeviceEventArgs as Microsoft.PointOfService.DeviceErrorEventArgs;
                    if (sessionContextArgs == null)
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid Operation.", new FaultCode("Server"));
                    }
                    if (Response.ErrorEventResponse.EventID != sessionContextArgs.EventId)
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid EventID.", new FaultCode("Server"));
                    }
                    sessionContext.DeviceEventResponse = Response.ErrorEventResponse.ErrorResponse;
                }
                else if (Response.OutputCompleteEventResponse != null)
                {
                    var sessionContextArgs = sessionContext.DeviceEventArgs as Microsoft.PointOfService.OutputCompleteEventArgs;
                    if (sessionContextArgs == null)
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid Operation.", new FaultCode("Server"));
                    }
                    if (Response.OutputCompleteEventResponse.EventID != sessionContextArgs.EventId)
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid EventID.", new FaultCode("Server"));
                    }
                }
                else if (Response.StatusUpdateEventResponse != null)
                {
                    var sessionContextArgs = sessionContext.DeviceEventArgs as Microsoft.PointOfService.StatusUpdateEventArgs;
                    if (sessionContextArgs == null)
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid Operation.", new FaultCode("Server"));
                    }
                    if (Response.StatusUpdateEventResponse.EventID != sessionContextArgs.EventId)
                    {
                        throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid EventID.", new FaultCode("Server"));
                    }
                }
                else
                {
                    throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid EventResponse argument.", new FaultCode("Server"));
                }

                // イベントレスポンスの設定が終わったのでデバイスのイベントハンドラを動かす
                // Since a setup of the event response finished, the event handler of a device is started. 
                sessionContext.SetEventResponseCalled.Signal();

            }
            catch (Exception ex)
            {
                base.LogWriteLineException(MethodBase.GetCurrentMethod(), ex);
                throw;
            }
        }


        #endregion

        #endregion

        #region IDisposable Member

        public override void Dispose()
        {
            base.Dispose();
        }

        #endregion

        /// <summary>
        /// セッションIDのチェック用メソッド
        /// チェックした結果、セッションIDが不正の場合は例外をスローする。
        /// セッションマネージャの内部やServiceBaseでの実装ではなく、
        /// ServiceBaseで抽象メソッドとして定義し、各デバイスサービスに実装させているのは、
        /// UposExceptionクラスがUPOS共通ではなく、各デバイスのネームスペースに所属しているため。
        /// 共通部分のコードでは、UposExceptionを書けない。
        /// A method to check SessionID.
        /// If the SessionID is incorrect, an exception is thrown. 
        /// Since a UposException class belongs to the name space of each device rather than common to UPOS, 
        /// this is defined as an abstract method in ServiceBase and implemented in each device service 
        /// instead of an implementation as a ServiceBase or inside of Session Manager.
        /// </summary>
        /// <param name="consumerID">Session ID</param>
        /// <param name="throwWhenExistId">true時は、すでにIDがセッションマネージャに登録されていたら例外をスローする。false時はIDがセッションマネージャに登録されていないならば例外をスローする |At the time of true, if ID is already registered into the session manager, this throws an exception. </param>
        protected override void ValidateSessionID(string consumerID, bool throwWhenExistId)
        {
            if (!base.IsValidSessionID(consumerID))
            {
                throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Invalid sessionID.", new FaultCode("Server"));
            }

            if (throwWhenExistId)
            {
                if (base.IsExistSession(consumerID))
                {
                    throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Duplicated sessionID.", new FaultCode("Server"));
                }
            }
            else
            {
                if (!base.IsExistSession(consumerID))
                {
                    throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_ILLEGAL }, "Not Active sessionID.", new FaultCode("Server"));
                }
            }
        }

        /// <summary>
        /// 指定されたセッションに関連されたリソースを解放します
        /// Releases the resources that are related to the specified session.
        /// </summary>
        /// <param name="sessionContext">セッションコンテキスト | Session context</param>
        protected override void CloseSessionResources(ISessionContext sessionContext)
        {
            DisposeDevice(sessionContext);
            base.CloseSessionBase(sessionContext, null, SessionContext_ServiceDirectIOEvent, SessionContext_ServiceErrorEvent, SessionContext_ServiceOutputCompleteEvent, SessionContext_ServiceStatusUpdateEvent);
        }

        /// <summary>
        /// 指定されたセッションに関連されたデバイスのインスタンスを破棄します。
        /// Destory the instance of the device associated with the specified session.
        /// </summary>
        /// <param name="sessionContext">セッションコンテキスト|Session Context</param>
        protected virtual void DisposeDevice(ISessionContext sessionContext)
        {
            if (sessionContext.Device == null)
            {
                // CloseDeviceの後にCloseDeviceを呼び出された場合、
                // すでにインスタンスは破棄されているので、なにもしない。
                // If called the CloseDevice after CloseDevice, 
                // Because instances are discarded already, nothing is done. 
                return;
            }

            var device = ConcretizationDevice(sessionContext.Device);

            if (device.State != Microsoft.PointOfService.ControlState.Closed)
            {
                device.FreezeEvents = true;
                base.WaitForEventHandlerReturned(sessionContext);

                device.Close();
                device.DirectIOEvent -= sessionContext.DeviceDirectIOEventHandler;
                device.ErrorEvent -= sessionContext.DeviceErrorEventHandler;
                device.OutputCompleteEvent -= sessionContext.DeviceOutputCompleteEventHandler;
                device.StatusUpdateEvent -= sessionContext.DeviceStatusUpdateEventHandler;
                //device.DataEvent -= sessionContext.DeviceDataEventHandler;
                sessionContext.Device = null;

                base.DeleteAsyncTemporaryFiles(sessionContext);
            }
        }

        /// <summary>
        /// デバイスを明示的にダウンキャストする
        /// このリファレンスを基に多数のデバイス（種類）をコーディングする際、
        /// デバイス種別へのダウンキャストコーディングの変更箇所を減らすためにこれを用いる
        /// 
        /// Downcast device explicitly.
        /// When coding on many devices (types) based on this reference, 
        /// the use of this in order to reduce the change in the downcast coding to the device type.
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        protected virtual Microsoft.PointOfService.PosPrinter ConcretizationDevice(Microsoft.PointOfService.PosDevice device)
        {
            if (device == null)
            {
                throw new FaultException<UposException>(new UposException() { ErrorCode = ErrorCode.E_CLOSED }, "Closed", new FaultCode("Server"));
            }

            return device as Microsoft.PointOfService.PosPrinter;
        }

        /// <summary>
        /// クライアントへのイベントポートを明示的にダウンキャストする
        /// このリファレンスを基に多数のデバイス（種類）をコーディングする際、
        /// デバイス種別へのダウンキャストコーディングの変更箇所を減らすためにこれを用いる
        /// 
        /// Event port to the client to downcast explicitly.
        /// When coding on many devices (types) based on this reference, 
        /// the use of this in order to reduce the change in the downcast coding to the device type
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        protected virtual UnifiedPOS.POSPrinterEvents.V1_4.POSPrinterEvent ConcretizationConsumerEventPort(object deviceEvent)
        {
            return deviceEvent as UnifiedPOS.POSPrinterEvents.V1_4.POSPrinterEvent;
        }

    }
}
