Exemple #1
0
        protected override bool StartInternal()
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "StartInternal"))
            {
                bool result = default(bool);

                try
                {
                    _socket = new TcpSocketServer(_parameter.PortNo, _parameter.ClientThreads);
                    string boundAddress = _socket.LocalEndPoint.ToString();
                    method.InfoV("Socket bind address : {0}", boundAddress);

                    // bind the socket
                    result = _socket.Bind();
                    if (result)
                    {
                        method.InfoV("Socket was successfully bounded to : {0}", boundAddress);
                        _socket.ReceivedBytes += OnSocket_ReceivedBytes;
                    }
                    else
                    {
                        method.InfoV("!!! Unable to bind the socket on : {0}", boundAddress);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
Exemple #2
0
        protected override bool StartInternal()
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "StartInternal"))
            {
                bool result = default(bool);

                try
                {
                    // receiver socket
                    if (_parameter.IPAddress.IsEmpty())
                    {
                        _parameter.IPAddress = Extensions.GetIpAddressString(-1);
                    }
                    _socketReceiver = new UdpSocketClientServer(_parameter.IPAddress, _parameter.PortNo);
                    string boundAddress = _socketReceiver.LocalEndPoint.ToString();
                    method.InfoV("Socket bind address : {0}", boundAddress);

                    if (!_parameter.MulticastIP.IsEmpty() &&
                        !_parameter.InterfaceIP.IsEmpty())
                    {
                        result = _socketReceiver.BindMulticastIP(_parameter.MulticastIP, _parameter.InterfaceIP);
                        method.InfoV("Socket multicast address : {0}, {1}", _parameter.MulticastIP, _parameter.InterfaceIP);
                    }
                    else
                    {
                        result = _socketReceiver.Bind();
                    }

                    if (result)
                    {
                        method.InfoV("Socket was successfully bounded to : {0}", boundAddress);
                        if (Extensions.UseTaskInsteadOfThread)
                        {
                            Extensions.CreateLongRunningTask(this.OnListen);
                        }
                        else
                        {
                            Extensions.CreateThreadAndStart(new System.Threading.ThreadStart(this.OnListen));
                        }
                    }
                    else
                    {
                        method.InfoV("!!! Unable to bind the socket on : {0}", boundAddress);
                    }

                    // sender socket
                    _socketTransmitter = new UdpSocketClientClient();
                    result             = _socketTransmitter.Bind();
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
        private void Initialize(bool checkItemCount, string threadSuffix)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Initialize"))
            {
                try
                {
                    _uniqueKey = "AsyncTaskThreadPoolExecutor_" + Guid.NewGuid().ToString();
                    method.InfoV("{0} : Capacity : {1:D}, Queue Capacity : {2:D}", _uniqueKey, this.Capacity, this.QueueCapacity);

                    this.RegisterForShutdown();
                    this.ExecutorService.AddExecutor(this);

                    for (int i = 0; i < this.Capacity; i++)
                    {
                        AsyncTaskThreadExecutor <T> executor = new AsyncTaskThreadExecutor <T>(this.ThreadExecutorService, this.QueueCapacity, checkItemCount, threadSuffix);
                        executor.ProcessItem          += new ExecutorProcessItemHandler <T>(OnExecutor_ProcessItem);
                        executor.ProcessItemCompleted += new ExecutorProcessItemCompletedHandler2 <T>(OnExecutor_ProcessItemCompleted);
                        executor.ContainerIndex        = i;

                        _workerThreads.Add(executor);
                        _activeWorkersCount.Add(executor.UniqueKey, new ThreadHashValue()
                        {
                            Executor  = executor,
                            ItemCount = 0
                        });
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
        protected override bool OnExecuteInternal(MonitorExecutionContext context, MonitorEntity_MsgTgt target)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "OnExecuteInternal"))
            {
                bool       result  = default(bool);
                MonMsg_G2H request = context.G2HMessage;
                MonTgt_G2H_Status_NovoTicketCreate tgtSrc = target as MonTgt_G2H_Status_NovoTicketCreate;

                try
                {
                    InstallationDetailsForMSMQ dbData = request.Extra as InstallationDetailsForMSMQ;
                    int installationNo = request.InstallationNo;

                    method.InfoV("Creating novo ticket for {0:D} Ticket value {1:D} Ticket Number {2:D}", installationNo, tgtSrc.TicketAmount, tgtSrc.TicketNumber);
                    result = ExCommsDataContext.Current.InsertTicket(installationNo, dbData.Machine_No,
                                                                     installationNo, tgtSrc.TicketAmount, tgtSrc.TicketNumber, tgtSrc.PrintDate);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
Exemple #5
0
        protected override void OnShutDownCalled()
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "OnShutDownCalled"))
            {
                try
                {
                    base.OnShutDownCalled();

                    //Debugger.Break();
                    if (this.TrackItems)
                    {
                        this.LogTrackItems(":BEFORE:");
                    }
                    if (this.FlushItemsBeforeClose)
                    {
                        // wait untill all the items finished
                        this.WaitForItemsToFlush();
                    }
                    if (this.TrackItems)
                    {
                        this.LogTrackItems(":AFTER:");
                    }
                    this.ThreadExecutorService.AwaitTermination(TimeSpan.Zero);

                    method.InfoV("Shutdown called. {0} has finished his work.", _uniqueKey);
                    this.Shutdown();
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
Exemple #6
0
 protected virtual void WaitForItemsToFlush()
 {
     using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "WaitForItemsToFlush"))
     {
         try
         {
             int iteration = 0;
             while (!this.ThreadExecutorService.WaitForShutdown(100))
             {
                 int count = this.GetActiveItems();
                 if (count > 0)
                 {
                     if (iteration > 50)
                     {
                         method.InfoV("$$$ ({0:D}) thread executors have items to finish. So waiting for them to finish.", count);
                         iteration = 0;
                     }
                     else
                     {
                         iteration++;
                     }
                 }
                 else
                 {
                     method.Info("$$$ All the thread executors have finished their work. So can safely shutdown them now.");
                     break;
                 }
             }
         }
         catch (Exception ex)
         {
             method.Exception(ex);
         }
     }
 }
Exemple #7
0
        private void OnReceiveUdpEntityFromSocket(UdpSocketReceiveData message)
        {
            using (ILogMethod method = Log.LogMethod("", "OnReceiveUdpEntityFromSocket"))
            {
                try
                {
                    // create the raw entity message
                    string ipAddress = ((System.Net.IPEndPoint)message.RemoteEndpoint).Address.ToStringSafe();
                    method.InfoV("RECV_SOCK : Received from {0} / {1:D}",
                                 ipAddress, message.BufferLength);
                    UdpFreeformEntity udpEntity = FreeformEntityFactory.CreateUdpEntity(FF_FlowDirection.H2G, message.Buffer, ipAddress);
                    if (udpEntity == null ||
                        udpEntity.RawData == null ||
                        udpEntity.RawData.Length == 0)
                    {
                        method.Info("RECV_SOCK : Unable to parse the data from socket (Invalida message format).");
                        return;
                    }

                    // convert the freeform entity message
                    IFreeformEntity ffEntity = FreeformEntityFactory.CreateEntity(FF_FlowDirection.H2G, udpEntity);
                    if (ffEntity == null)
                    {
                        method.Info("RECV_SOCK : Unable to create the freeform entity from udp entity message.");
                        return;
                    }

                    // process the message
                    udpEntity.EntityData = ffEntity;
                    method.InfoV("RECV_SOCK (Success) : {0} [{1}] was received for processing.",
                                 udpEntity, udpEntity.ProcessDate.ToStringSafe());

                    if (this.ReceiveUdpEntityData != null)
                    {
                        this.ReceiveUdpEntityData(udpEntity);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
Exemple #8
0
 public void Unsubscribe(Contracts.DTO.Freeform.ExCommsServerCallbackTypes callbackType, Contracts.DTO.UnsubscribeRequestEntity request)
 {
     using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Unsubscribe"))
     {
         try
         {
             method.InfoV("Unsubcribe : {0}", callbackType.ToString());
             _callbacks[callbackType].Value.Unsubscribe();
         }
         catch (Exception ex)
         {
             method.Exception(ex);
         }
     }
 }
Exemple #9
0
 protected virtual void LogTrackItems(string prefix)
 {
     using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "LogTrackItems"))
     {
         try
         {
             foreach (KeyValuePair <string, E> pair in _itemWorkerThreads)
             {
                 string key   = pair.Key;
                 E      value = pair.Value;
                 method.InfoV("%%% ({3} => ) Thread : {0:D}, Item Key : {1}, Item Count : {2:D}", value.WorkerThreadId, key,
                              value[key], prefix);
             }
         }
         catch (Exception ex)
         {
             method.Exception(ex);
         }
     }
 }
        protected virtual bool AddFaultEvent(MonitorExecutionContext context, MonitorEntity_MsgTgt target, string description, bool polled)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "AddFaultEvent"))
            {
                bool result = default(bool);

                try
                {
                    MonMsg_G2H request = context.G2HMessage;
                    method.InfoV("FAULT EVENT : Inserting fault event for {0:D}/{1:D}", target.FaultSource, target.FaultType);
                    result = this.AddFaultEvent(request.InstallationNo, target.FaultSource, target.FaultType,
                                                description, polled, request.FaultDate);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
        public virtual void AddBufferEntityParser(Type gmuIdEnum, Type appIdEnum, IFFParser parser, FFTgtParseBufferHandler action)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "AddBufferEntityParser"))
            {
                try
                {
                    //Array gmuIdValues = Enum.GetValues(gmuIdEnum);
                    //Array appIdValues = Enum.GetValues(appIdEnum);

                    //if (gmuIdValues.Length == appIdValues.Length)
                    //{
                    //    for (int i = 0; i < gmuIdValues.Length; i++)
                    //    {
                    //        this.AddBufferEntityParser((int)gmuIdValues.GetValue(i), (int)appIdValues.GetValue(i), parser, action);
                    //    }
                    //}
                    string[] gmuIdNames = Enum.GetNames(gmuIdEnum);
                    foreach (var gmuIdName in gmuIdNames)
                    {
                        try
                        {
                            object gmuIdValue = Enum.Parse(gmuIdEnum, gmuIdName, true);
                            object appIdValue = Enum.Parse(appIdEnum, gmuIdName, true);
                            this.AddBufferEntityParser((int)gmuIdValue, (int)appIdValue, parser, action);
                        }
                        catch (Exception ex)
                        {
                            method.InfoV("::: ENUM ERROR : Unable to convert from ({0}) to ({1})", gmuIdEnum.FullName, appIdEnum.FullName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
Exemple #12
0
        public void Unsubscribe(Contracts.Dto.Freeform.ExCommsServerCallbackTypes callbackType, Contracts.Dto.UnsubscribeRequestEntity request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Unsubscribe"))
            {
                try
                {
                    method.InfoV("Unsubcribe : {0}", callbackType.ToString());

                    switch (callbackType)
                    {
                    case BMC.ExComms.Contracts.Dto.Freeform.ExCommsServerCallbackTypes.RawMessage:
                        _callbackRawMessage.Unsubscribe();
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
Exemple #13
0
        public override void QueueWorkerItem(T item)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "QueueWorkerItem"))
            {
                E executor = null;
                if (this.ExecutorService.IsShutdown)
                {
                    return;
                }
                string itemKey = string.Empty;

                lock (_lockList)
                {
                    try
                    {
                        if (!item.Equals(default(T)))
                        {
                            // find the executor
                            itemKey = item.UniqueKey;
                            if (_itemWorkerThreads.ContainsKey(itemKey))
                            {
                                executor = _itemWorkerThreads[itemKey];
                            }
                            else
                            {
                                executor = this.GetFreeThreadExecutor(item);
                                method.InfoV("Found Thread Index : {0:D} for item key : {1}", executor.ContainerIndex, itemKey);
                                _itemWorkerThreads.Add(itemKey, executor);
                            }
                        }

                        if (executor != null)
                        {
                            // if full, wait until some items consumed
                            while (this.IsQueueFull(executor, item))
                            {
                                Log.Description(method.PROC, "Queue is full. Thread pool is blocked for : " + itemKey);
                                if (this.ExecutorService.IsShutdown)
                                {
                                    break;
                                }
                                _fullWaiters++;

                                try
                                {
                                    lock (_lockFullEvent)
                                    {
                                        Monitor.Exit(_lockList);
                                        Log.Debug(method.PROC, "Locked : " + _uniqueKey);
                                        Monitor.Wait(_lockFullEvent);
                                        Log.Debug(method.PROC, "Unlocked : " + _uniqueKey);
                                        Monitor.Enter(_lockList);
                                    }
                                }
                                finally
                                {
                                    _fullWaiters--;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        method.Exception(ex);
                    }
                    finally
                    {
                        if (!this.ExecutorService.IsShutdown)
                        {
                            this.DoWorkItem(executor, item);
                        }
                    }
                }
            }
        }
Exemple #14
0
        private void DoWork()
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "DoWork"))
            {
                try
                {
                    _workerThreadId = Thread.CurrentThread.ManagedThreadId;
                    _threadName     = Thread.CurrentThread.Name;
                    if (_threadName.IsEmpty())
                    {
                        _threadName = "Thread_" + Thread.CurrentThread.ManagedThreadId.ToString();
                    }
                    method.InfoV("( {0}::DoWork ) {1} started on the thread : {2:D}", _threadName, _uniqueKey, _workerThreadId);

                    while (!_executorService2.WaitForShutdown())
                    {
                        T item = default(T);

                        try
                        {
                            byte signalItem = _signalQueue.Dequeue();
                            do
                            {
                                _dataFound     = 0;
                                _dataProcessed = 0;
                                if (_executorService2.IsShutdown)
                                {
                                    method.InfoV("( {0}::DoWork ) Shutdown called. Thread : {1:D} is exiting now.", _threadName, _workerThreadId);
                                    break;
                                }

                                int queuesCount = _dataQueues.Count;
                                Parallel.ForEach <KeyValuePair <string, ConcurrentQueue <ThreadExecutorItem <T> > > >(_dataQueues,
                                                                                                                      (KeyValuePair <string, ConcurrentQueue <ThreadExecutorItem <T> > > p, ParallelLoopState ps) =>
                                {
                                    int taskId     = Task.CurrentId.SafeValue();
                                    int queueCount = 0;
                                    if (_executorService2.WaitTokenSource.IsCancellationRequested)
                                    {
                                        ps.Stop();
                                    }
                                    ConcurrentQueue <ThreadExecutorItem <T> > queue = p.Value;
                                    queueCount = queue.Count;

                                    // data found to process
                                    if (queueCount > 0)
                                    {
                                        try
                                        {
                                            ThreadExecutorItem <T> executorItem = null;
                                            if (queue.TryDequeue(out executorItem))
                                            {
                                                _dataFound++;
                                                _dataProcessed++;
                                                method.DebugV("( {0}::DoWork_PLStart::{1} ) Item Count : {2:D}", _threadName, p.Key, queueCount);

                                                if (_executorService2.IsShutdown)
                                                {
                                                    method.InfoV("( {0}::DoWork ) Shutdown called. Thread : {1:D} is exiting now.", _threadName, _workerThreadId);
                                                    ps.Stop();
                                                }
                                                if (executorItem == null)
                                                {
                                                    method.InfoV("( {0}::DoWork ) Shutdown called. Invalid executor item received.", _threadName);
                                                    return;
                                                }

                                                // actual item
                                                method.DebugV("( {0}::DoWork ) Thread : {1:D}, Queue Size : {2:D}", _threadName, _workerThreadId, queue.Count);
                                                item = executorItem.Item;

                                                // still have item
                                                if (_executorService2.IsShutdown)
                                                {
                                                    method.InfoV("( {0}::DoWork ) Shutdown called. Thread : {1:D} is exiting now.", _threadName, _workerThreadId);
                                                    ps.Stop();
                                                }

                                                // actual processing and processing completion
                                                if (!item.Equals(default(T)))
                                                {
                                                    this.OnProcessItem(item);
                                                    this.OnProcessItemCompleted(executorItem);
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            method.Exception(ex);
                                        }
                                        finally
                                        {
                                            method.DebugV("( {0}::DoWork_PLEnd::{1} ) Item Count : {2:D}", _threadName, p.Key, queueCount);
                                        }
                                    }
                                    else
                                    {
                                        method.DebugV("( {0}::DoWork_PLStartEnd::{1} ) Item Count : {3:D}", _threadName, p.Key, queueCount);
                                    }
                                });

                                if (_dataProcessed > 0 &&
                                    ((_itemCount - _dataProcessed) >= 0))
                                {
                                    int newCount = (_itemCount - _dataProcessed);
                                    Interlocked.Exchange(ref _itemCount, newCount);
                                    method.DebugV("( {0}::DoWork_ItemComplete ) Queue Count : {1:D}, Item Count : {2:D}", _threadName, queuesCount, _itemCount);
                                }
                                if (_executorService2.WaitForShutdown())
                                {
                                    break;
                                }
                            } while (_dataFound > 0);
                        }
                        catch (Exception ex)
                        {
                            method.Exception(ex);
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
                finally
                {
                    method.InfoV("( {0}::DoWork ) Shutdown called. Thread : {1:D} has finished its work.", _threadName, _workerThreadId);
                    this.Shutdown();
                }
            }
        }
        private void OnReceiveUdpEntityFromSocket(UdpSocketReceiveData message)
        {
            using (ILogMethod method = Log.LogMethod(LOGGER, this.DYN_MODULE_NAME, "OnReceiveUdpEntityFromSocket"))
            {
                try
                {
                    // create the raw entity message
                    method.InfoV("RECV_SOCK : Received from {0} / {1:D}",
                                 message.RemoteEndpoint.ToString(), message.BufferLength);
                    UdpFreeformEntity udpEntity = FreeformEntityFactory.CreateUdpEntity(FF_FlowDirection.G2H, message.Buffer);
                    if (udpEntity == null ||
                        udpEntity.RawData == null ||
                        udpEntity.RawData.Length == 0)
                    {
                        method.Info("RECV_SOCK : Unable to parse the data from socket (Invalida message format).");
                        if (udpEntity != null &&
                            udpEntity.Address != null)
                        {
                            // send the nack
                            this.Send(FreeformEntityFactory.CreateH2GMessageAckNack(udpEntity.AddressString, true));
                        }
                        return;
                    }

                    // convert the freeform entity message
                    FFMsg_G2H g2hMessage = FreeformEntityFactory.CreateEntity(FF_FlowDirection.G2H, udpEntity) as FFMsg_G2H;
                    if (g2hMessage == null)
                    {
                        method.Info("RECV_SOCK : Unable to create the freeform entity from udp entity message.");
                        // send the nack
                        this.Send(FreeformEntityFactory.CreateH2GMessageAckNack(udpEntity.AddressString, true));
                        return;
                    }

                    // send the ack message (if necessary)
                    FFMsg_H2G msgAck = FreeformEntityFactory.CreateH2GMessageAckNack(udpEntity.AddressString, g2hMessage.Command);
                    if (msgAck != null)
                    {
                        this.Send(msgAck);
                    }

                    // process the message
                    udpEntity.EntityData = g2hMessage;
                    method.InfoV("RECV_SOCK (Success) : {0} [{1}] was received for processing.",
                                 udpEntity, udpEntity.ProcessDate.ToStringSafe());
                    if (_configStore.LogRawFreeformMessages)
                    {
                        string udpEntityString = udpEntity.ToStringRaw(FF_FlowDirection.G2H);
                        Log.Info(udpEntityString);
                        LOGGER.WriteLogInfo(udpEntityString + Environment.NewLine);
                        LOGGER_UDP_RECV.WriteLogInfo(udpEntity.ProcessDate.ToStringSafe());
                        LOGGER_UDP_RECV.WriteLogInfo(udpEntityString + Environment.NewLine);
                    }
                    this.OnReceiveFromSocket(udpEntity);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
        protected override bool OnExecuteInternal(MonitorExecutionContext context, MonitorEntity_MsgTgt target)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "OnExecuteInternal"))
            {
                MonMsg_G2H msgSrc = context.G2HMessage;
                MonTgt_G2H_Ticket_Redemption_Close tgtSrc = target as MonTgt_G2H_Ticket_Redemption_Close;
                ICallWebService ticketService             = CallWebServiceFactory.Current;

                try
                {
                    long   ticketAmount   = 0;
                    long   ticketType     = 0;
                    string barcode        = tgtSrc.Barcode;
                    string stockNo        = msgSrc.Asset;
                    string playerCardNo   = msgSrc.CardNumber;
                    string siteCode       = msgSrc.SiteCode;
                    string ticketSiteCode = barcode.Substring(0, 4);
                    int    installationNo = msgSrc.InstallationNo;
                    int?   voucherID      = 0;
                    long   retCode        = 0;
                    bool   isLocalTicket  = false;
                    bool   sendAck        = false;
                    method.InfoV("TICKET_REDEEM_CLOSE: Local Site Code : {0}, Ticket Site Code : {1}", siteCode, ticketSiteCode);

                    if (tgtSrc.Amount > 0 &&
                        tgtSrc.Status == FF_AppId_TicketRedemption_Close_Status.Success)
                    {
                        // is TIS printed ticket
                        if (ticketService.IsTISPrintedTicketPrefix(barcode))
                        {
                            method.InfoV("TICKET_REDEEM_CLOSE (TIS): TIS Printed Ticket ({0})", barcode);

                            if (ExCommsDataContext.Current.RedeemTicketComplete(barcode, stockNo, ref voucherID, siteCode, playerCardNo))
                            {
                                method.Info("TICKET_REDEEM_CLOSE (TIS): Send ticket: " + barcode + " redeem information to TIS");
                                ticketService.TisTicketRedeemComplete(barcode);
                                method.Info("TICKET_REDEEM_CLOSE (TIS): Redeem information send to TIS for ticket: " + barcode);
                            }
                            else
                            {
                                method.Info("TICKET_REDEEM_CLOSE: Problem while sending the Tkt Redeem complete msg to DB!");
                                tgtSrc.Status = FF_AppId_TicketRedemption_Close_Status.CouponRejectedbySystem;
                            }
                        }
                        // cross ticketing enabled and ticket site code not matched
                        else if (_configStore.IsCrossTicketingEnabled)//CrossTickeing From Setting
                        {
                            method.InfoV("TICKET_REDEEM_CLOSE (CROSS SITE): Ticket Printed in Site {1} ({0})", barcode, ticketSiteCode);

                            // local site
                            if (!siteCode.IgnoreCaseCompare(ticketSiteCode))
                            {
                                isLocalTicket = true;
                            }
                            else
                            {
                                //foreign site
                                if (installationNo == 0 ||
                                    string.IsNullOrEmpty(stockNo))
                                {
                                    method.Info("TICKET_REDEEM_CLOSE (CROSS SITE): Installation detail for ticket " + barcode + " in " + installationNo.ToString() + " for DeviceID " + stockNo);
                                    if (ticketService.TicketRedeemComplete(barcode, stockNo, out retCode) != 0)
                                    {
                                        method.Info("TICKET_REDEEM_CLOSE (CROSS SITE): Problem while sending the Tkt Redeem complete msg to WS!");
                                        tgtSrc.Status = FF_AppId_TicketRedemption_Close_Status.CouponRejectedbySystem;
                                    }
                                }
                                else
                                {
                                    method.Info("TICKET_REDEEM_CLOSE (CROSS SITE): Stored Installation detail for ticket " + barcode + " in " + installationNo.ToString() + " for DeviceID" + stockNo);
                                    if (ticketService.TicketRedeemComplete(barcode, stockNo, out retCode) != 0)
                                    {
                                        method.Info("TICKET_REDEEM_CLOSE (CROSS SITE): Stored Problem while sending the Tkt Redeem complete msg to WS!");
                                        tgtSrc.Status = FF_AppId_TicketRedemption_Close_Status.CouponRejectedbySystem;
                                    }
                                }
                            }
                        }
                        // local site ticket
                        else
                        {
                            isLocalTicket = true;
                        }
                        sendAck = true;
                    }

                    // local site ticket
                    if (isLocalTicket)
                    {
                        method.Info("TICKET_REDEEM_CLOSE (LOCAL): Ticket: " + barcode + " Sitecode : " + siteCode + " Inst  : " + installationNo.ToString());
                        if (!ExCommsDataContext.Current.RedeemTicketComplete(barcode, stockNo, ref voucherID, siteCode, playerCardNo))
                        {
                            method.Info("TICKET_REDEEM_CLOSE (LOCAL):Problem while sending the Tkt Redeem complete msg to DB!");
                        }
                        else
                        {
                            method.InfoV("TICKET_REDEEM_CLOSE (LOCAL): Success while redeeming amount for Barcode : {0}", barcode);
                        }
                    }
                    else
                    {
                        //else nota a valid amount or redeem status
                        method.Info("TICKET_REDEEM_CLOSE: No proper Ticket Redeemption!");
                        this.TicketReedeemFail(tgtSrc, msgSrc, ticketService, ref voucherID);
                        sendAck = true;
                    }

                    // send the acknowledgement
                    if (sendAck)
                    {
                        method.Info("TICKET_REDEEM_CLOSE: Sending redeem complete acknowledement");
                        MonTgt_H2G_Ticket_Redemption_Close response = new MonTgt_H2G_Ticket_Redemption_Close()
                        {
                            Status = (tgtSrc.Status == FF_AppId_TicketRedemption_Close_Status.Success) ? FF_AppId_ResponseStatus_Types.Success : FF_AppId_ResponseStatus_Types.Fail
                        };
                        context.H2GTargets.Add(response);
                        method.Info("TICKET_REDEEM_CLOSE: Successfully sent redeem complete acknowledement");
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(true);
            }
        }
        protected override bool OnExecuteInternal(MonitorExecutionContext context, MonitorEntity_MsgTgt target)
        {
            using (ILogMethod method = Log.LogMethod("MonitorHandler_GIM", "OnExecuteInternal"))
            {
                try
                {
                    MonMsg_G2H msgSrc = context.G2HMessage;
                    MonTgt_G2H_GIM_GameIDInfo tgtSrc = target as MonTgt_G2H_GIM_GameIDInfo;
                    method.Info("GIM (CALL): IP Address : " + msgSrc.IpAddress +
                                ", Asset No : " + tgtSrc.AssetNumber.ToStringSafe() +
                                ", GMU No : " + tgtSrc.GMUNumber.ToStringSafe() +
                                ", Serial No : " + tgtSrc.SerialNumber.ToStringSafe());

                    int?   installationNo  = 0;
                    int?   assetNo         = 0;
                    string pokerGamePrefix = string.Empty;

                    if (ExCommsDataContext.Current.InsertGMULogin(tgtSrc, msgSrc.IpAddress,
                                                                  ref installationNo, ref assetNo, ref pokerGamePrefix))
                    {
                        int       assetNoInt    = assetNo.SafeValue();
                        IPAddress hostIPAddress = null;

                        // get the ip address
                        if (_configExchange.Honeyframe_Cashmaster_Exchange_EnableDhcp == 1)
                        {
                            hostIPAddress = _configExchange.Honeyframe_Cashmaster_BMCDHCP_ServerIP.ToIPAddress();
                        }
                        else
                        {
                            hostIPAddress = _configExchange.Honeyframe_Cashmaster_Exchange_interface.ToIPAddress();
                        }
                        method.InfoV("GIM (Success): Installation no ({1:D}), Asset No : {2:D}, Game Prefix : {3} for IP : {0}, from Host : {4}",
                                     msgSrc.IpAddress, installationNo, assetNoInt,
                                     pokerGamePrefix, hostIPAddress.ToString());
                        int installationNo2 = installationNo.SafeValue();

                        if (installationNo2 > 0)
                        {
                            MonMsg_H2G msgDest = new MonMsg_H2G()
                            {
                                InstallationNo = installationNo2,
                                IpAddress      = msgSrc.IpAddress,
                            };
                            MonTgt_H2G_GIM_GameIDInfo tgtDest = new MonTgt_H2G_GIM_GameIDInfo();
                            tgtDest.SourceAddress          = hostIPAddress;
                            tgtDest.EnableNetworkMessaging = true;
                            if (_configStore.Iview3AssetNum)
                            {
                                tgtDest.AssetNumberInt  = assetNoInt;
                                tgtDest.PokerGamePrefix = pokerGamePrefix.ToString();
                            }

                            // update the installation no
                            ExMonitorServerImpl.Current
                            .UpdateCommsServerHostAddress(installationNo2, msgSrc.HostIpAddress)
                            .UpdateInstallatioIpAddress(installationNo2, msgSrc.IpAddress);

                            // add the target and process
                            msgSrc.InstallationNo = installationNo2;
                            msgDest.Targets.Add(tgtDest);
                            context.H2GMessage = msgDest;
                            return(true);
                        }
                    }
                    else
                    {
                        method.InfoV("GIM (Failure): Unable to get the installation no for IP : {0}", msgSrc.IpAddress);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
                return(false);
            }
        }
Exemple #18
0
        protected override bool OnExecuteInternal(MonitorExecutionContext context, MonitorEntity_MsgTgt target)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "OnExecuteInternal"))
            {
                MonMsg_G2H msgSrc = context.G2HMessage;
                MonTgt_G2H_Ticket_Redemption_Request tgtSrc = target as MonTgt_G2H_Ticket_Redemption_Request;
                ICallWebService ticketService = CallWebServiceFactory.Current;

                try
                {
                    long   ticketAmount   = 0;
                    long   ticketType     = 0;
                    string barcode        = tgtSrc.Barcode;
                    string stockNo        = msgSrc.Asset;
                    string playerCardNo   = msgSrc.CardNumber;
                    string siteCode       = msgSrc.SiteCode;
                    string ticketSiteCode = barcode.Substring(0, 4);
                    method.InfoV("TICKET_REDEEM_START: Local Site Code : {0}, Ticket Site Code : {1}", siteCode, ticketSiteCode);

                    // is TIS printed ticket
                    if (ticketService.IsTISPrintedTicketPrefix(barcode))
                    {
                        method.InfoV("TICKET_REDEEM_START (TIS): TIS Printed Ticket ({0})", barcode);
                        short tisTicketType = 0;
                        short tisRetCode    = 0;

                        if (ticketService.TisTicketRedeemStart(barcode, stockNo, playerCardNo, out ticketAmount, out tisTicketType, out tisRetCode) != 0)
                        {
                            /*Rejecting the Ticket*/
                            method.InfoV("TICKET_REDEEM_START (TIS): Error while redeeming amount for Barcode : {0}", barcode);
                            ticketAmount = 0;
                            ticketType   = 0;
                        }
                        else
                        {
                            method.InfoV("TICKET_REDEEM_START (TIS): Success while redeeming amount for Barcode : {0}", barcode);
                            ticketType = tisTicketType;
                        }
                    }
                    // cross ticketing enabled and ticket site code not matched
                    else if (_configStore.IsCrossTicketingEnabled &&
                             !siteCode.IgnoreCaseCompare(ticketSiteCode))//CrossTickeing From Setting
                    {
                        method.InfoV("TICKET_REDEEM_START (CROSS SITE): Ticket Printed in Site {1} ({0})", barcode, ticketSiteCode);
                        long siteTicketType = 0;
                        long siteRetCode    = 0;

                        if (ticketService.TicketRedeemStart(barcode, stockNo, out ticketAmount, out siteTicketType, out siteRetCode) != 0)
                        {
                            /*Rejecting the Ticket*/
                            method.InfoV("TICKET_REDEEM_START (CROSS SITE): Error while redeeming amount for Barcode : {0}", barcode);
                            ticketAmount = 0;
                            ticketType   = 0;
                        }
                        else
                        {
                            method.InfoV("TICKET_REDEEM_START (TIS): Success while redeeming amount for Barcode : {0}", barcode);
                            ticketType = siteTicketType;
                        }
                    }
                    // ticket printed in local site
                    else
                    {
                        int?localAmount     = 0;
                        int?localRetCode    = 0;
                        int?localTicketType = 0;

                        string barCodeTemp = barcode;
                        if (!ExCommsDataContext.Current.RedeemTicketStart(ref barCodeTemp, stockNo, siteCode, 0, playerCardNo,
                                                                          ref localAmount, ref localRetCode, ref localTicketType))
                        {
                            /*Rejecting the Ticket*/
                            method.InfoV("TICKET_REDEEM_START (LOCAL SITE): Error while redeeming amount for Barcode : {0}, Error Code : {1:D}", barcode, localRetCode.SafeValue());
                            ticketAmount = 0;
                            ticketType   = 0;
                        }
                        else
                        {
                            method.InfoV("TICKET_REDEEM_START (LOCAL): Success while redeeming amount for Barcode : {0}", barcode);
                            ticketAmount = localAmount.SafeValue();
                            ticketType   = localTicketType.SafeValue();
                        }
                    }

                    MonTgt_H2G_Ticket_Redemption_Response response = new MonTgt_H2G_Ticket_Redemption_Response()
                    {
                        Amount  = ticketAmount,
                        Barcode = barcode,
                        Type    = (FF_AppId_TicketTypes)ticketType
                    };
                    context.H2GTargets.Add(response);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(true);
            }
        }