예제 #1
0
        protected override void PrepareMessageToProcessInCurrentChannel(IFreeformEntity_Msg request, ref IFreeformEntity_Msg response)
        {
            if (request.EntityPrimaryTarget is FFTgt_H2G_GIM_GameIDInfo)
            {
                //response = FreeformEntityFactory.CreateEntity<FFMsg_G2H>(FF_FlowDirection.G2H,
                //          new FFCreateEntityRequest_G2H_Secured()
                //          {
                //              Command = FF_AppId_G2H_Commands.ResponseRequest,
                //              MessageType = FF_AppId_G2H_MessageTypes.FreeForm,
                //              SessionID = FF_AppId_SessionIds.Security,
                //              TransactionID = 0xB1,
                //              IPAddress = request.IpAddress,
                //          });
                //FFTgt_B2B_Security tgt = new FFTgt_B2B_Security_Secured()
                //{
                //    SecurityData = new FFTgt_B2B_Security_KeyExchange_Request(),
                //};
                //response.AddTarget(tgt);
                // initiate a key exchange (ticket)
                //var msgTicket = FreeformEncryptionHelper.InitKeyExchangeStartG2H(request.IpAddress, FF_AppId_SessionIds.Security, this.NewTransactionId);
                //var msgEFT = FreeformEncryptionHelper.InitKeyExchangeStartG2H(request.IpAddress, FF_AppId_SessionIds.ECash, this.NewTransactionId);
                //this.ExecuteCurrentRequests(msgTicket, msgEFT);
            }

            response = null;
        }
 protected void ExecuteNextStep(IFreeformEntity_Msg request)
 {
     if (this.NextStep != null)
     {
         this.NextStep.Execute(request);
     }
 }
예제 #3
0
        protected override void PrepareMessageToProcessInCurrentChannel(IFreeformEntity_Msg request, ref IFreeformEntity_Msg response)
        {
            if (request.EntityPrimaryTarget is FFTgt_H2G_GIM_GameIDInfo)
            {
                //response = FreeformEntityFactory.CreateEntity<FFMsg_G2H>(FF_FlowDirection.G2H,
                //          new FFCreateEntityRequest_G2H_Secured()
                //          {
                //              Command = FF_AppId_G2H_Commands.ResponseRequest,
                //              MessageType = FF_AppId_G2H_MessageTypes.FreeForm,
                //              SessionID = FF_AppId_SessionIds.Security,
                //              TransactionID = 0xB1,
                //              IPAddress = request.IpAddress,
                //          });
                //FFTgt_B2B_Security tgt = new FFTgt_B2B_Security_Secured()
                //{
                //    SecurityData = new FFTgt_B2B_Security_KeyExchange_Request(),
                //};
                //response.AddTarget(tgt);
                // initiate a key exchange (ticket)
                //var msgTicket = FreeformEncryptionHelper.InitKeyExchangeStartG2H(request.IpAddress, FF_AppId_SessionIds.Security, this.NewTransactionId);
                //var msgEFT = FreeformEncryptionHelper.InitKeyExchangeStartG2H(request.IpAddress, FF_AppId_SessionIds.ECash, this.NewTransactionId);
                //this.ExecuteCurrentRequests(msgTicket, msgEFT);
            }

            response = null;
        }
        internal static IFreeformEntity_Msg InitKeyExchangeEndG2H_SIM(this FreeformSecurityTableCollection secTables,
                                                                      IFreeformEntity_Msg request)
        {
            // store the partial key of the host
            FFTgt_B2B_Security_KeyExchange_PartialKey tgt = request.EntityPrimaryTarget as FFTgt_B2B_Security_KeyExchange_PartialKey;
            SECURITY_KEY_INDEX keyIndex = FreeformEncryptionHelper.GetSecurityKeyIndex(request);

            byte[] gmuPartialKey = secTables.CreatePartialKeyGmu(keyIndex);
            secTables.StoreOtherPartialKeyGmu(keyIndex, tgt.PartialKey);
            secTables.CreateCommonKey(keyIndex);

            // send the partial key of the gmu
            IFreeformEntity_Msg response = request.CopyTo(FF_FlowDirection.G2H, new FFCreateEntityRequest_G2H_ResponseRequired()
            {
                MessageType       = FF_AppId_G2H_MessageTypes.FreeForm,
                Command           = FF_AppId_G2H_Commands.ResponseRequest,
                SkipTransactionId = true,
            });
            FFTgt_B2B_Security tgt2 = new FFTgt_B2B_Security()
            {
                SecurityData = new FFTgt_B2B_Security_KeyExchange_End()
                {
                    PartialKey = gmuPartialKey,
                }
            };

            response.AddTarget(tgt2);
            return(response);
        }
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Execute"))
            {
                bool result = default(bool);
                string key = string.Empty;

                try
                {
                    key = request.IpAddress;
                    _isExecuting = true;
                    result = _msgHandler.Execute(request);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
                finally
                {
                    _isExecuting = false;
                }

                return result;
            }
        }
        internal override IFreeformEntity CreateEntityInternal(byte[] buffer, object extra)
        {
            // create the entity and parse
            IFreeformEntity_Msg entity = _messageParser.ParseBuffer(null, buffer) as IFreeformEntity_Msg;

            if (entity == null)
            {
                Log.Warning("Invalid message passed (Unable to convert the message)");
                return(null);
            }
            else if (!entity.IsValid)
            {
                Log.Warning(string.Format("Invalid message passed (Checksum mismatch => Actual : {0:D}), Calculated : {1:D})", entity.Checksum, entity.ChecksumCalculated));
                entity.Dispose();
                return(null);
            }
            entity.IpAddress = extra.ToString();

            // valid message
            _targetParser.ParseBuffer(entity, entity, entity.EntityData, 0, entity.DataLength);

            // convert the encrypted targets
            if (entity.EncryptedTarget != null &&
                entity.Targets.Contains(entity.EncryptedTarget))
            {
                FFTgt_B2B_Encrypted encryptedTarget = entity.EncryptedTarget as FFTgt_B2B_Encrypted;
                entity.Targets.Remove(encryptedTarget);
                _targetParser.ParseBuffer(entity, entity, encryptedTarget.DecryptedData, 0, encryptedTarget.DecryptedData.Length);
            }
            return(entity);
        }
예제 #7
0
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Execute"))
            {
                bool   result = default(bool);
                string key    = string.Empty;

                try
                {
                    key          = request.IpAddress;
                    _isExecuting = true;
                    result       = _msgHandler.Execute(request);
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
                finally
                {
                    _isExecuting = false;
                }

                return(result);
            }
        }
 internal void CopyTo(IFreeformEntity_Msg message)
 {
     using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "CopyTo"))
     {
         try
         {
             //FF_AppId_SessionIds sessionId = message.SessionID;
             //if (_transactionIds.ContainsKey(sessionId))
             //{
             //    int transactionId = _transactionIds[sessionId];
             //    if (transactionId > 0)
             //    {
             //        message.TransactionID = transactionId;
             //        _transactionIds[sessionId] = 0;
             //    }
             //}
             if (this.IsValid)
             {
                 message.SessionID     = this.SessionID;
                 message.TransactionID = this.TransactionID;
             }
         }
         catch (Exception ex)
         {
             method.Exception(ex);
         }
     }
 }
예제 #9
0
        public IFreeformEntity_Msg CopyTo(FF_FlowDirection direction, FFCreateEntityRequest request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "CopyTo"))
            {
                IFreeformEntity_Msg result = null;

                try
                {
                    result            = FreeformEntityFactory.CreateEntity <IFreeformEntity_Msg>(direction, request);
                    result.IpAddress  = this.IpAddress;
                    result.DeviceType = this.DeviceType;
                    result.SessionID  = this.SessionID;
                    if (!request.SkipTransactionId)
                    {
                        result.TransactionID = this.TransactionID;
                    }
                    result.IsSecured = this.IsSecured;
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
예제 #10
0
        public bool Send(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Send"))
            {
                bool result = default(bool);

                try
                {
                    if (request == null)
                    {
                        method.Info("Unable to send message. request is empty");
                        return(false);
                    }

                    using (UdpFreeformEntity entity = new UdpFreeformEntity())
                    {
                        entity.Address    = request.IpAddress2;
                        entity.EntityData = request;
                        result            = this.Send(entity);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
예제 #11
0
        public bool Send(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(LOGGER, this.DYN_MODULE_NAME, "Send"))
            {
                bool result = default(bool);

                try
                {
                    if (request == null)
                    {
                        method.Info("Unable to send message. request is empty");
                        return false;
                    }

                    using (UdpFreeformEntity entity = new UdpFreeformEntity())
                    {
                        entity.Address = request.IpAddress2;
                        entity.EntityData = request;
                        result = this.Send(entity);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
예제 #12
0
        protected override IMonitorEntity CreateEntityInternal(IMonitorEntity parent, IFreeformEntity request)
        {
            IFreeformEntity_Msg msgFF  = request as IFreeformEntity_Msg;
            IMonitorEntity_Msg  msgMon = this.CreateMonitorMessage();

            msgMon.IpAddress = msgFF.IpAddress;
            return(msgMon);
        }
예제 #13
0
        protected override IFreeformEntity CreateEntityInternal(IMonitorEntity parent, IMonitorEntity request)
        {
            IMonitorEntity_Msg  monMsg = request as IMonitorEntity_Msg;
            IFreeformEntity_Msg ffMsg  = this.CreateFreeformMessage();

            ffMsg.IpAddress = monMsg.IpAddress;
            return(ffMsg);
        }
예제 #14
0
 internal static FFMsg_H2G PrintTicketAck(string ipAddress, IFreeformEntity_Msg request)
 {
     return(WrapMessageAndReturnH2G(ipAddress, FF_AppId_H2G_PollCodes.FreeformNoResponse,
                                    FF_FlowInitiation.Host, new FFTgt_H2G_Ticket_Printed_Response()
     {
         Status = FF_AppId_ResponseStatus_Types.Success,
     }));
 }
예제 #15
0
 protected byte[] CreatePartialKeyHost(IFreeformEntity_Msg message)
 {
     return(this.CreatePartialKey(message,
                                  (s, ki) =>
     {
         return s.CreatePartialKeyHost(ki);
     }));
 }
예제 #16
0
 internal static FFMsg_H2G PrintTicketAck(string ipAddress, IFreeformEntity_Msg request)
 {
     return WrapMessageAndReturnH2G(ipAddress, FF_AppId_H2G_PollCodes.FreeformNoResponse, 
         FF_FlowInitiation.Host, new FFTgt_H2G_Ticket_Printed_Response()
     {
         Status = FF_AppId_ResponseStatus_Types.Success,
     });
 }
예제 #17
0
 protected override bool OnProcessMessageCustom(CoreLib.ILogMethod method, IFreeformEntity_Msg request)
 {
     // initiate a key exchange (ticket)
     var msgTicket = this.Factory.SecurityTables.InitKeyExchangeStartG2H_SIM(request.IpAddress, FF_AppId_SessionIds.Security, this.NewTransactionId);
     var msgEFT = this.Factory.SecurityTables.InitKeyExchangeStartG2H_SIM(request.IpAddress, FF_AppId_SessionIds.ECash, this.NewTransactionId);
     this.ExecuteCurrentRequests(msgTicket, msgEFT);
     return true;
 }
예제 #18
0
        public IExecutionStep Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessMessage"))
            {
                try
                {
                    ExecutionStep step = null;
                    this.ExecutionResult = ExecutionStepResult.None;
                    ExecutionStepKeyValue pair =
                        new ExecutionStepKeyValue(request.EntityUniqueKeyString, request.FlowDirection);
                    string uniqueKey = pair.FullKey;

                    // current execution step
                    if (this.CanExecute(pair, request))
                    {
                        step = this;
                    }
                    // next step is responsible
                    else if (_nextStep != null &&
                             _nextStep.CanExecute(pair, request))
                    {
                        step = _nextStep as ExecutionStep;
                    }
                    // any of the next steps is responsible
                    else if (_hasNextSteps)
                    {
                        if (_nextStepsCached.ContainsKey(uniqueKey))
                        {
                            step = _nextStepsCached[uniqueKey];
                        }
                        else
                        {
                            foreach (var nextStep in this.NextSteps)
                            {
                                if (nextStep.CanExecute(pair, request))
                                {
                                    step = nextStep as ExecutionStep;
                                    _nextStepsCached.Add(uniqueKey, step);
                                    break;
                                }
                            }
                        }
                    }

                    // any thing is responsible?
                    if (step != null)
                    {
                        return(step.ExecuteInternal(method, request));
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(null);
            }
        }
예제 #19
0
        //public IFFMsgHandlerExecutor FFMsgHandlerExecutor { get; set; }

        internal _FFMsgHandlerFactory GetFactory(IFreeformEntity_Msg request)
        {
            return(_gmuFactories.GetOrAdd(request.IpAddress,
                                          (k) =>
            {
                return new _FFMsgHandlerFactory(request.IpAddress, _createMessageHandler(), this.DeviceType,
                                                _entities, GetSecurityTables(request.IpAddress));
            }));
        }
예제 #20
0
        protected override bool OnProcessMessageCustom(CoreLib.ILogMethod method, IFreeformEntity_Msg request)
        {
            // initiate a key exchange (ticket)
            var msgTicket = this.Factory.SecurityTables.InitKeyExchangeStartG2H_SIM(request.IpAddress, FF_AppId_SessionIds.Security, this.NewTransactionId);
            var msgEFT    = this.Factory.SecurityTables.InitKeyExchangeStartG2H_SIM(request.IpAddress, FF_AppId_SessionIds.ECash, this.NewTransactionId);

            this.ExecuteCurrentRequests(msgTicket, msgEFT);
            return(true);
        }
        internal static void InitSecurityData(IFreeformEntity_Msg message, FFTgt_B2B_Security_Data securityData)
        {
            FFTgt_B2B_Security tgt = new FFTgt_B2B_Security_ResponseRequired()
            {
                SecurityData = securityData,
            };

            message.AddTarget(tgt);
        }
예제 #22
0
        private bool PostMessageToProcessInCurrentChannel(ILogMethod method, IFreeformEntity_Msg request)
        {
            IFreeformEntity_Msg response = null;

            this.PrepareMessageToProcessInCurrentChannel(request, ref response);
            if (response != null)
            {
                return(ExecutionStepFactory.Current.Execute(response));
            }
            return(false);
        }
        internal static SECURITY_KEY_INDEX GetSecurityKeyIndex(this IFreeformEntity_Msg message)
        {
            int sessionId = (int)message.SessionID;
            SECURITY_KEY_INDEX keyIndex = SECURITY_KEY_INDEX.NO_KEY;

            if (_securityKeys.ContainsKey(sessionId))
            {
                keyIndex = _securityKeys[sessionId];
            }
            return(keyIndex);
        }
        internal bool PersistRequestResponseMapItem(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "PersistRequestResponseMapItem"))
            {
                try
                {
                    if (request.EntityPrimaryTarget == null)
                    {
                        return(false);
                    }
                    string typeName = request.EntityPrimaryTarget.GetType().Name;
                    RequestResponseMapItem mapItem = null;
                    bool copyTo = false;

                    // save the request/response map item
                    if (request is FFMsg_G2H &&
                        _requestResponseMappings.IsKey1Exists(typeName))
                    {
                        mapItem = _requestResponseMappings.GetValueFromKey1(typeName);
                    }
                    // get the request/response map item
                    else if (request is FFMsg_H2G &&
                             _requestResponseMappings.IsKey2Exists(typeName))
                    {
                        mapItem = _requestResponseMappings.GetValueFromKey2(typeName);
                        copyTo  = true;
                    }

                    // copy from/to request/response map item
                    if (mapItem != null)
                    {
                        if (copyTo)
                        {
                            mapItem.CopyTo(request);
                        }
                        else
                        {
                            mapItem.CopyFrom(request);
                        }
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(false);
            }
        }
        void OnExecutorDelayLoading_ProcessItem(IFreeformEntity_Msg request)
        {
            var factory = GetFactory(request);

            do
            {
                if (!factory.IsExecuting)
                {
                    break;
                }
            } while (!_teWait.Wait(_tsWait));

            factory.Execute(request);
        }
예제 #26
0
 public FFTgtExecutionContext(IFreeformEntity_Msg sourceMessage)
 {
     this.SourceMessage = sourceMessage;
     this.FlowDirection = this.SourceMessage.FlowDirection;
     _freeformTargets = new Lazy<List<IFreeformEntity>>(() =>
     {
         return new List<IFreeformEntity>();
     });
     _monitorTargets = new Lazy<List<MonitorEntity_MsgTgt>>(() =>
     {
         return new List<MonitorEntity_MsgTgt>();
     });
     _monitorMeters = new Lazy<MonTgt_G2H_Meters>(() =>
     {
         return new MonTgt_G2H_Meters();
     });
 }
        internal bool Persist(IFreeformEntity_Msg request, IFreeformEntity_MsgTgt target)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "PersistRequestResponseMapItem"))
            {
                try
                {
                    string typeName = FFMsgHandler.CreateSessionTargetKey((int)request.SessionID, target.TypeKey);
                    RequestResponseMapItem mapItem = null;
                    bool copyTo = false;

                    // save the request/response map item
                    if (request is FFMsg_G2H &&
                        this.IsKey1Exists(typeName))
                    {
                        mapItem = this.GetValueFromKey1(typeName);
                    }
                    // get the request/response map item
                    else if (request is FFMsg_H2G &&
                             this.IsKey2Exists(typeName))
                    {
                        mapItem = this.GetValueFromKey2(typeName);
                        copyTo  = true;
                    }

                    // copy from/to request/response map item
                    if (mapItem != null)
                    {
                        if (copyTo)
                        {
                            mapItem.CopyTo(request);
                        }
                        else
                        {
                            mapItem.CopyFrom(request);
                        }
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(false);
            }
        }
 internal void CopyFrom(IFreeformEntity_Msg message)
 {
     using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "CopyFrom"))
     {
         try
         {
             this.SessionID     = message.SessionID;
             this.TransactionID = message.TransactionID;
             this.IsValid       = true;
             //_transactionIds.AddOrUpdate2(message.SessionID, message.TransactionID);
         }
         catch (Exception ex)
         {
             method.Exception(ex);
         }
     }
 }
예제 #29
0
        private bool PostMessageToProcessInExternalChannel(ILogMethod method, IFreeformEntity_Msg request)
        {
            IFreeformEntity_Msg response = null;

            this.PrepareMessageToProcessInExternalChannel(request, ref response);
            if (response != null)
            {
                if (response is FFMsg_G2H)
                {
                    return(_processMessageG2H(method, response as FFMsg_G2H));
                }
                else if (response is FFMsg_H2G)
                {
                    return(_processMessageH2G(method, response as FFMsg_H2G));
                }
            }
            return(false);
        }
        internal static IFreeformEntity_Msg InitKeyExchangePartialKeyH2G_GMU(this FreeformSecurityTableCollection secTables,
                                                                             IFreeformEntity_Msg request)
        {
            SECURITY_KEY_INDEX keyIndex = FreeformEncryptionHelper.GetSecurityKeyIndex(request);

            byte[] hostPartialKey       = secTables.CreatePartialKeyHost(keyIndex);
            IFreeformEntity_Msg message = request.CopyTo(FF_FlowDirection.H2G, new FFCreateEntityRequest_H2G_ResponseRequired()
            {
                PollCode = FF_AppId_H2G_PollCodes.FreeformResponse,
            });

            InitSecurityData(message,
                             new FFTgt_B2B_Security_KeyExchange_PartialKey()
            {
                PartialKey = hostPartialKey,
            });
            return(message);
        }
예제 #31
0
        //protected SECURITY_KEY_INDEX GetSecurityKeyIndex(IFreeformEntity_Msg message)
        //{
        //    int sessionId = (int)message.SessionID;
        //    SECURITY_KEY_INDEX keyIndex = SECURITY_KEY_INDEX.NO_KEY;
        //    if (_securityKeys.ContainsKey(sessionId)) keyIndex = _securityKeys[sessionId];
        //    return keyIndex;
        //}

        private byte[] CreatePartialKey(IFreeformEntity_Msg message, Func <FreeformSecurityTableCollection, SECURITY_KEY_INDEX, byte[]> create)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "CreatePartialKey"))
            {
                byte[] result = default(byte[]);

                try
                {
                    result = create(this.Factory.SecurityTables, message.GetSecurityKeyIndex());
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ProcessMessage"))
            {
                bool result = default(bool);

                try
                {
                    if (request == null ||
                        request.IpAddress.IsEmpty())
                    {
                        return(false);
                    }

                    string key = request.IpAddress;
                    _ExecutionStepFactory factory = GetFactory(request);

                    // new or existing transaction id
                    if (!factory.PersistRequestResponseMapItem(request) &&
                        request.TransactionID <= 0)
                    {
                        request.TransactionID = NewTransactionId;
                    }

                    // immediate execution or delayed execution
                    if (factory.IsExecuting)
                    {
                        _executorDelayLoading.QueueWorkerItem(request);
                        result = true;
                    }
                    else
                    {
                        result = factory.Execute(request);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
        internal static IFreeformEntity_Msg InitKeyExchangeStatusH2G_GMU(this FreeformSecurityTableCollection secTables,
                                                                         IFreeformEntity_Msg request)
        {
            // store the partial key of the gmu
            FFTgt_B2B_Security_KeyExchange_End tgt = request.EntityPrimaryTarget as FFTgt_B2B_Security_KeyExchange_End;
            SECURITY_KEY_INDEX keyIndex            = FreeformEncryptionHelper.GetSecurityKeyIndex(request);

            secTables.StoreOtherPartialKeyHost(keyIndex, tgt.PartialKey);
            secTables.CreateCommonKey(keyIndex);

            IFreeformEntity_Msg message = request.CopyTo(FF_FlowDirection.H2G, new FFCreateEntityRequest_H2G_ResponseRequired()
            {
                PollCode = FF_AppId_H2G_PollCodes.FreeformNoResponse,
            });

            InitSecurityData(message,
                             new FFTgt_B2B_Security_KeyExchange_Status()
            {
                Status = (request.EntityPrimaryTarget is FFTgt_B2B_Security_PartialKey ?
                          FF_AppId_ResponseStatus_Types.Success :
                          FF_AppId_ResponseStatus_Types.Fail),
            });
            return(message);
        }
예제 #34
0
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ProcessMessage"))
            {
                bool result = default(bool);

                try
                {
                    if (request == null ||
                        request.IpAddress.IsEmpty())
                    {
                        return(false);
                    }

                    string key = request.IpAddress;
                    _FFMsgHandlerFactory factory = GetFactory(request);

                    // immediate execution or delayed execution
                    if (factory.IsExecuting)
                    {
                        _executorDelayLoading.QueueWorkerItem(request);
                        result = true;
                    }
                    else
                    {
                        result = factory.Execute(request);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(result);
            }
        }
 protected virtual void CopyToInternal(IFreeformEntity_Msg message) { }
예제 #36
0
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "ProcessMessage(G2H)"))
            {
                bool result = default(bool);
                string ipAddress = string.Empty;

                try
                {
                    using (FFTgtExecutionContext context = new FFTgtExecutionContext(request))
                    {
                        Stack<IFreeformEntity> st = new Stack<IFreeformEntity>();
                        request.CopyTo(st);

                        // push all the grandchildren into stack and process again
                        while (st.Count != 0)
                        {
                            IFreeformEntity_MsgTgt target = st.Pop() as IFreeformEntity_MsgTgt;
                            if (target == null || target.IsLeafNode) continue;

                            _requestResponseMappings.Persist(request, target);
                            string targetKey = CreateSessionTargetKey((int)request.SessionID, target.TypeKey);
                            if (_targetHandlers.ContainsKey(targetKey))
                            {
                                _HandlerInfo info = _targetHandlers[targetKey];
                                context.HandlerAttribute = info.HandlerAttribute;
                                info.Handler.Execute(context, target);
                            }

                            target.CopyTo(st);
                        }

                        if (request.TransactionID <= 0)
                        {
                            request.TransactionID = FFMsgHandlerFactory.NewTransactionId;
                        }

                        if (request.SessionID != FF_AppId_SessionIds.Internal)
                        {
                            // ok everything processed, now do the external or internal processing
                            if (request.FlowDirection == FF_FlowDirection.G2H)
                            {
                                // add the monitor meters
                                if (context.MonitorMeters.IsValueCreated)
                                {
                                    context.MonitorTargets.Value.Add(context.MonitorMeters.Value);
                                }
                                _msgTransmitter.ProcessMessage(request as FFMsg_G2H, context.MonitorTargets.Value);
                            }
                            else if (request.FlowDirection == FF_FlowDirection.H2G)
                            {
                                _msgTransmitter.ProcessMessage(request as FFMsg_H2G);
                            }

                            // process the internal messages
                            if (context.FreeformTargets != null &&
                                context.FreeformTargets.Count > 0)
                            {
                                FFMsg_H2G h2gMessage = null;
                                foreach (var freeformEntity in context.FreeformTargets)
                                {
                                    if (freeformEntity is IFreeformEntity_Msg)
                                    {
                                        FFMsgHandlerFactory.Current.Execute(freeformEntity as IFreeformEntity_Msg);
                                    }
                                    else if (freeformEntity is IFreeformEntity_MsgTgt)
                                    {
                                        if (h2gMessage == null)
                                        {
                                            h2gMessage = FreeformEntityFactory.CreateEntity<FFMsg_H2G>(FF_FlowDirection.H2G,
                                                new FFCreateEntityRequest_H2G()
                                                {
                                                    IPAddress = request.IpAddress,
                                                    PollCode = FF_AppId_H2G_PollCodes.FreeformNoResponse,
                                                    SessionID = request.SessionID,
                                                    TransactionID = request.TransactionID,
                                                });
                                        }
                                        h2gMessage.Targets.Add(freeformEntity as IFreeformEntity_MsgTgt);
                                    }
                                }

                                if (h2gMessage != null)
                                {
                                    FFMsgHandlerFactory.Current.Execute(h2gMessage);
                                }

                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
        //public IFFMsgHandlerExecutor FFMsgHandlerExecutor { get; set; }

        internal _FFMsgHandlerFactory GetFactory(IFreeformEntity_Msg request)
        {
            return _gmuFactories.GetOrAdd(request.IpAddress,
                (k) =>
                {
                    return new _FFMsgHandlerFactory(request.IpAddress, _createMessageHandler(),  this.DeviceType,
                        _entities, GetSecurityTables(request.IpAddress));
                });
        }
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ProcessMessage"))
            {
                bool result = default(bool);

                try
                {
                    if (request == null ||
                        request.IpAddress.IsEmpty())
                    {
                        return false;
                    }

                    string key = request.IpAddress;
                    _FFMsgHandlerFactory factory = GetFactory(request);

                    // immediate execution or delayed execution
                    if (factory.IsExecuting)
                    {
                        _executorDelayLoading.QueueWorkerItem(request);
                        result = true;
                    }
                    else
                    {
                        result = factory.Execute(request);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
 protected override void PrepareMessageToProcessInCurrentChannel(IFreeformEntity_Msg request, ref IFreeformEntity_Msg response)
 {
     response = this.Factory.SecurityTables.InitKeyExchangeStatusH2G_GMU(request);
 }
        void OnExecutorDelayLoading_ProcessItem(IFreeformEntity_Msg request)
        {
            var factory = GetFactory(request);
            do
            {
                if (!factory.IsExecuting)
                    break;
            } while (!_teWait.Wait(_tsWait));

            factory.Execute(request);
        }
 internal _ExecutionStepFactory GetFactory(IFreeformEntity_Msg request)
 {
     return _gmuFactories.AddOrGet(request.IpAddress,
         () => { return new _ExecutionStepFactory(request.IpAddress, _entities, GetSecurityTables(request.IpAddress)); });
 }
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ProcessMessage"))
            {
                bool result = default(bool);

                try
                {
                    if (request == null ||
                        request.IpAddress.IsEmpty())
                    {
                        return false;
                    }

                    string key = request.IpAddress;
                    _ExecutionStepFactory factory = GetFactory(request);

                    // new or existing transaction id
                    if (!factory.PersistRequestResponseMapItem(request)
                        && request.TransactionID <= 0)
                    {
                        request.TransactionID = NewTransactionId;
                    }

                    // immediate execution or delayed execution
                    if (factory.IsExecuting)
                    {
                        _executorDelayLoading.QueueWorkerItem(request);
                        result = true;
                    }
                    else
                    {
                        result = factory.Execute(request);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return result;
            }
        }
        internal bool PersistRequestResponseMapItem(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "PersistRequestResponseMapItem"))
            {
                try
                {
                    if (request.EntityPrimaryTarget == null) return false;
                    string typeName = request.EntityPrimaryTarget.GetType().Name;
                    RequestResponseMapItem mapItem = null;
                    bool copyTo = false;

                    // save the request/response map item
                    if (request is FFMsg_G2H &&
                        _requestResponseMappings.IsKey1Exists(typeName))
                    {
                        mapItem = _requestResponseMappings.GetValueFromKey1(typeName);
                    }
                    // get the request/response map item
                    else if (request is FFMsg_H2G &&
                            _requestResponseMappings.IsKey2Exists(typeName))
                    {
                        mapItem = _requestResponseMappings.GetValueFromKey2(typeName);
                        copyTo = true;
                    }

                    // copy from/to request/response map item
                    if (mapItem != null)
                    {
                        if (copyTo)
                        {
                            mapItem.CopyTo(request);
                        }
                        else
                        {
                            mapItem.CopyFrom(request);
                        }
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return false;
            }
        }
 internal override ExecutionStep ExecuteInternal(CoreLib.ILogMethod method, IFreeformEntity_Msg request)
 {
     return base.ExecuteInternal(method, request);
 }
 public override bool CanExecute(ExecutionStepKeyValue pair, IFreeformEntity_Msg request)
 {
     return base.CanExecute(pair, request);
 }
예제 #46
0
 internal override ExecutionStep ExecuteInternal(ILogMethod method, IFreeformEntity_Msg request)
 {
     return(base.ExecuteInternal(method, request));
 }
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Execute"))
            {
                bool result = default(bool);
                string key = string.Empty;

                try
                {
                    key = request.IpAddress;
                    ExecutionStepDictionary steps = _executionSteps;
                    _isExecuting = true;

                    //_gmuExecutionStepsExecuting.AddOrUpdate(key, true, (k, b) => { return true; });

                    //if (!_gmuExecutionSteps.ContainsKey(key))
                    //{
                    //    steps = new ExecutionStepDictionary();
                    //    steps.Entity.GmuIpAddress = key;
                    //    steps.CreateExecutionSteps(ExecutionStepFactory.Current.DeviceType, _messageWiseSteps, _groupedSteps);
                    //    _gmuExecutionSteps.Add(key, steps);
                    //    _entities.Add(steps.Entity);
                    //}
                    //else
                    //{
                    //    steps = _gmuExecutionSteps[key];
                    //}

                    if (steps != null)
                    {
                        // has clients
                        bool hasClients = false;
                        ExCommsExecutionStepEntity entity = steps.Entity;
                        IExecutionStep execStepCurrent = null;
                        IExecutionStep execStepLatest = null;
                        entity.Steps.Clear();

                        if (ExCommsServerImpl.Current != null)
                            hasClients = ExCommsServerImpl.Current.HasStepChangedClients;

#if !OLD_CODE
                        // 1. find the execution step by message 
                        string messageKey = request.EntityUniqueKeyDirection;
                        if (_messageWiseSteps.ContainsKey(messageKey))
                        {
                            var stepList = _messageWiseSteps[messageKey];
                            if (stepList.Count == 1)
                            {
                                execStepCurrent = stepList[0];
                            }
                        }

                        // execute the step
                        if (execStepCurrent != null)
                        {
                            // last step
                            IExecutionStep execStepLast = (steps.Current ?? steps.Start);
                            if (hasClients && execStepLast != null)
                                entity.Steps.Add(execStepLast.GetType().Name);

                            // execute the current step
                            execStepLatest = execStepCurrent.Execute(request);

                            //// move to or set to next step
                            //if (execStepLatest != null &&
                            //    execStepLatest.ExecutionResult == ExecutionStepResult.Success)
                            //{
                            //    if (execStepLatest.NextStep != null)
                            //    {
                            //        if (execStepLatest.MoveToNextStep)
                            //        {
                            //            if (hasClients && execStepLatest.NextStep != null)
                            //                entity.Steps.Add(execStepLatest.NextStep.GetType().Name);
                            //            execStepLatest = execStepLatest.NextStep.Execute(request);
                            //        }

                            //        //if (execStepLatest.SetNextStep)
                            //        //{
                            //        //    if (hasClients)
                            //        //        entity.Steps.Add(execStepLatest.GetType().Name);
                            //        //    execStepLatest = execStepLatest.NextStep;
                            //        //    execStepLatest.ExecutionResult = ExecutionStepResult.Success;
                            //        //}
                            //    }
                            //}

                            if (execStepLatest != null &&
                                execStepLatest.ExecutionResult == ExecutionStepResult.Success &&
                                !Object.ReferenceEquals(steps.Current, execStepLatest))
                            {
                                steps.Current = execStepLatest;
                            }
                        }
#else
                        // last step
                        IExecutionStep step = (steps.Current ?? steps.Start);
                        if (hasClients && step != null)
                            entity.Steps.Add(step.GetType().Name);

                        // previous step
                        if (step.ExecutionResult == ExecutionStepResult.Failed &&
                            step.PrevStep != null) step = step.PrevStep;

                        // execute the current step
                        if (hasClients && step != null)
                            entity.Steps.Add(step.GetType().Name);
                        IExecutionStep step2 = step.Execute(request);

                        // move to or set to next step
                        if (step2 != null &&
                            step2.ExecutionResult == ExecutionStepResult.Success)
                        {
                            if (step2.NextStep != null)
                            {
                                if (step2.MoveToNextStep)
                                {
                                    if (hasClients && step2.NextStep != null)
                                        entity.Steps.Add(step2.NextStep.GetType().Name);
                                    step2 = step2.NextStep.Execute(request);
                                }

                                if (step2.SetNextStep)
                                {
                                    if (hasClients)
                                        entity.Steps.Add(step2.GetType().Name);
                                    step2 = step2.NextStep;
                                    step2.ExecutionResult = ExecutionStepResult.Success;
                                }
                            }
                        }

                        if (step2 != null &&
                            step2.ExecutionResult == ExecutionStepResult.Success &&
                            !Object.ReferenceEquals(steps.Current, step2))
                        {
                            steps.Current = step2;
                        }
#endif

                        if (hasClients)
                        {
                            if (execStepLatest != null)
                                entity.Steps.Add(execStepLatest.UniqueKey);
                            ExCommsServerImpl.Current.OnNotifyExecutionStepChanged(entity);
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
                finally
                {
                    //_gmuExecutionStepsExecuting.AddOrUpdate(key, false, (k, b) => { return false; });
                    _isExecuting = false;
                }

                return result;
            }
        }
 public bool PostMessageToTransceiver(IFreeformEntity_Msg request)
 {
     return _ffTranceiver.Send(request);
 }
예제 #49
0
 public bool PostMessageToGMU(IFreeformEntity_Msg message)
 {
     return _serverInstance.PostMessageToTransceiver(message);
 }
 internal override ExecutionStep ExecuteInternal(CoreLib.ILogMethod method, IFreeformEntity_Msg request)
 {
     this.ExecuteNextStep(request);
     return this;
 }
예제 #51
0
 public override bool CanExecute(ExecutionStepKeyValue pair, IFreeformEntity_Msg request)
 {
     return request.EntityPrimaryTarget is FFTgt_H2G_GIM_GameIDInfo;
 }