// UnifiedPOSのイベントを表すメソッドの引数がCamelケースではなくPascalケースになっていますが、
// これはWSDLでの命名を踏襲しているからです。
// 新たに追加したものは、MSDNのクラスライブラリ開発のデザインガイドに従います。
// privateなフィールドに関しては上記デザインガイドに記述がないですが、
// パラメータやauto変数との区別を目的に、"_"をプレフィクスしたcamelケースを用います。
// このコードはサンプルです。
// シングルトンで動作させるように宣言されているため、staticメソッドで、デリゲートを伝播させます。

using System;
using System.Collections.Generic;
using System.ServiceModel;

//サンプルコードでは、個々のクラスがどの名前空間・アセンブリに
//属しているのか表現するため、あえてusingは使用しない。
//using UnifiedPOS.POSPrinterEvents;

namespace Console_POSPrinterConsumerBiDirectionSample
{
    [ServiceBehavior(Namespace = "http://www.nrf-arts.org/UnifiedPOS/POSPrinterEvents/", InstanceContextMode = InstanceContextMode.Single)]
    public class POSPrinterEventService : UnifiedPOS.POSPrinterEvents.V1_4.POSPrinterEvent
    {

        Dictionary<int, string> StatusConvertToString = new Dictionary<int, string>()
            {
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_COVER_OK, "CoverOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_COVER_OPEN, "CoverOpen" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_IDLE, "Idle" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_CARTRIDGE_EMPTY, "JournalCartridgeEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_CARTRIDGE_NEAREMPTY, "JournalCartridgeNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_CARTRIDGE_OK, "JournalCartridgeOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_COVER_OK, "JournalCoverOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_COVER_OPEN, "JournalCoverOpen" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_EMPTY, "JournalEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_HEAD_CLEANING, "JournalHeadCleaning" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_NEAREMPTY, "JournalNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_JRN_PAPEROK, "JournalPaperOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_POWER_OFF, "PowerOff" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_POWER_OFFLINE, "PowerOffline" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_POWER_OFF_OFFLINE, "PowerOffOffline" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_POWER_ONLINE, "PowerOnline" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_CARTRIDGE_EMPTY, "ReceiptCartridgeEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_CARTRIDGE_NEAREMPTY, "ReceiptCartridgeNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_CARTRIDGE_OK, "ReceiptCartridgeOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_COVER_OK, "ReceiptCoverOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_COVER_OPEN, "ReceiptCoverOpen" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_EMPTY, "ReceiptEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_HEAD_CLEANING, "ReceiptHeadCleaning" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_NEAREMPTY, "ReceiptNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_REC_PAPEROK, "ReceiptPaperOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_CARTRIDGE_EMPTY, "SlipCartridgeEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_CARTRIDGE_NEAREMPTY, "SlipCartridgeNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_CARTRIDGE_OK, "SlipCartridgeOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_COVER_OK, "SlipCoverOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_COVER_OPEN, "SlipCoverOpen" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_EMPTY, "SlipEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_HEAD_CLEANING, "SlipHeadCleaning" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_NEAREMPTY, "SlipNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.PTR_SUE_SLP_PAPEROK, "SlipPaperOK" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_UF_COMPLETE, "UpdateFirmwareComplete" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_UF_COMPLETE_DEV_NOT_RESTORED, "UpdateFirmwareCompleteDeviceNotRestored" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_UF_FAILED_DEV_NEEDS_FIRMWARE, "UpdateFirmwareFailedDeviceNeedsFirmware" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_UF_FAILED_DEV_OK, "UpdateFirmwareFailedDeviceOk" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_UF_FAILED_DEV_UNKNOWN, "UpdateFirmwareFailedDeviceUnknown" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_UF_FAILED_DEV_UNRECOVERABLE, "UpdateFirmwareFailedDeviceUnrecoverable" },
                { UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_UF_PROGRESS, "UpdateFirmwareProgress" },
            };

        #region POSPrinterEvent Member

        public virtual UnifiedPOS.POSPrinterEvents.V1_4.DirectIOData DirectIOEvent(string ConsumerID, string Source, int EventID, DateTime TimeStamp, int EventNumber, int Data, object Obj)
        {
            Console.WriteLine("{0}, {1}, DirectIOEvent, {2}, {3}, {4}", EventID, TimeStamp, EventNumber, Data, Obj);
            return  new UnifiedPOS.POSPrinterEvents.V1_4.DirectIOData();
        }

        public virtual UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse ErrorEvent(string ConsumerID, string Source, int EventID, DateTime TimeStamp, UnifiedPOS.POSPrinterEvents.V1_4.ErrorCode ErrorCode, int ErrorCodeExtended, UnifiedPOS.POSPrinterEvents.V1_4.ErrorLocus ErrorLocus, UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse ErrorResponse)
        {
            Console.WriteLine("{0}, {1}, ErrorEvent, {2}, {3}, {4}, {5}", EventID, TimeStamp, ErrorCode, ErrorCodeExtended, ErrorLocus, ErrorResponse);
            return UnifiedPOS.POSPrinterEvents.V1_4.ErrorResponse.ER_CLEAR;
        }

        public virtual void OutputCompleteEvent(string ConsumerID, string Source, int EventID, DateTime TimeStamp, int OutputID)
        {
            Console.WriteLine("{0}, {1}, OutputCompleteEvent, {2}", EventID, TimeStamp, OutputID);
        }

        public virtual void StatusUpdateEvent(string ConsumerID, string Source, int EventID, DateTime TimeStamp, int Status)
        {
            int p = UnifiedPOS.POSPrinterEvents.V1_4.Status.SUE_UF_PROGRESS;
            Console.WriteLine("{0}, {1}, StatusUpdateEvent, {2}", EventID, TimeStamp, (Status > p && Status < p + 100) ? StatusConvertToString[p] + " + " + (Status - p) : StatusConvertToString[Status]);
        }

        #endregion

    }
}
