// 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_2.POSPrinterEvent
    {

        Dictionary<int, string> StatusConvertToString = new Dictionary<int, string>()
            {
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.CoverOK, "CoverOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.CoverOpen, "CoverOpen" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.Idle, "Idle" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalCartridgeEmpty, "JournalCartridgeEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalCartridgeNearEmpty, "JournalCartridgeNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalCartridgeOK, "JournalCartridgeOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalCoverOK, "JournalCoverOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalCoverOpen, "JournalCoverOpen" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalEmpty, "JournalEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalHeadCleaning, "JournalHeadCleaning" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalNearEmpty, "JournalNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.JournalPaperOK, "JournalPaperOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.PowerOff, "PowerOff" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.PowerOffline, "PowerOffline" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.PowerOffOffline, "PowerOffOffline" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.PowerOnline, "PowerOnline" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptCartridgeEmpty, "ReceiptCartridgeEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptCartridgeNearEmpty, "ReceiptCartridgeNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptCartridgeOK, "ReceiptCartridgeOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptCoverOK, "ReceiptCoverOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptCoverOpen, "ReceiptCoverOpen" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptEmpty, "ReceiptEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptHeadCleaning, "ReceiptHeadCleaning" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptNearEmpty, "ReceiptNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.ReceiptPaperOK, "ReceiptPaperOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipCartridgeEmpty, "SlipCartridgeEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipCartridgeNearEmpty, "SlipCartridgeNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipCartridgeOK, "SlipCartridgeOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipCoverOK, "SlipCoverOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipCoverOpen, "SlipCoverOpen" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipEmpty, "SlipEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipHeadCleaning, "SlipHeadCleaning" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipNearEmpty, "SlipNearEmpty" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.SlipPaperOK, "SlipPaperOK" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.UpdateFirmwareComplete, "UpdateFirmwareComplete" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.UpdateFirmwareCompleteDeviceNotRestored, "UpdateFirmwareCompleteDeviceNotRestored" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.UpdateFirmwareFailedDeviceNeedsFirmware, "UpdateFirmwareFailedDeviceNeedsFirmware" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.UpdateFirmwareFailedDeviceOk, "UpdateFirmwareFailedDeviceOk" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.UpdateFirmwareFailedDeviceUnknown, "UpdateFirmwareFailedDeviceUnknown" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.UpdateFirmwareFailedDeviceUnrecoverable, "UpdateFirmwareFailedDeviceUnrecoverable" },
                { UnifiedPOS.POSPrinterEvents.V1_2.Status.UpdateFirmwareProgress, "UpdateFirmwareProgress" },
            };

        #region POSPrinterEvent Member

        public virtual UnifiedPOS.POSPrinterEvents.V1_2.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_2.DirectIOData();
        }

        public virtual UnifiedPOS.POSPrinterEvents.V1_2.ErrorResponse ErrorEvent(string ConsumerID, string Source, int EventID, DateTime TimeStamp, UnifiedPOS.POSPrinterEvents.V1_2.ErrorCode ErrorCode, int ErrorCodeExtended, UnifiedPOS.POSPrinterEvents.V1_2.ErrorLocus ErrorLocus, UnifiedPOS.POSPrinterEvents.V1_2.ErrorResponse ErrorResponse)
        {
            Console.WriteLine("{0}, {1}, ErrorEvent, {2}, {3}, {4}, {5}", EventID, TimeStamp, ErrorCode, ErrorCodeExtended, ErrorLocus, ErrorResponse);
            return UnifiedPOS.POSPrinterEvents.V1_2.ErrorResponse.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_2.Status.UpdateFirmwareProgress;
            Console.WriteLine("{0}, {1}, StatusUpdateEvent, {2}", EventID, TimeStamp, (Status > p && Status < p + 100) ? StatusConvertToString[p] + " + " + (Status - p) : StatusConvertToString[Status]);
        }

        #endregion

    }
}
