public override int HandleCommand(CommandContext context, ISyncResult result)
 {
     try
     {
         SessionRequestCommand sRequestCommand = SessionRequestCommand.ParseFrom(context.sSerializeObject);
         if (!sRequestCommand.HasCommandId)
         {
             CLRLogger.GetInstance().LogDevError("commandID error.");
             result.SetSerializedString("commandID error.");
             return(-1);
         }
         byte[] invokeResult = _dicFunc[sRequestCommand.CommandId].Invoke(sRequestCommand);
         if (null == invokeResult)
         {
             return(-1);
         }
         result.SetSerializedObject(invokeResult);
         return(0);
     }
     catch (Exception ex)
     {
         CLRLogger.GetInstance().LogDevError("HandleCommand error:" + ex.Message);
         return(-1);
     }
 }
Exemple #2
0
        override /// <summary>
        /// HandleCommand
        /// </summary>
        /// <param name="pContext">CommandContext</param>
        /// <param name="pSyncResult">ISyncResult</param>
        /// <returns>int</returns>
        public int HandleCommand(CommandContext pContext, ISyncResult pSyncResult)
        {
            var guid = Guid.NewGuid().ToString();

            string commandId = pContext != null?pContext.iCommandId.ToString() : string.Empty;

            GlobalDefinition.LoggerWrapper.LogDevInfo("####################Receive Command.#######################" +
                                                      guid + "########commandid:" + commandId);

            if (null == pContext || null == pSyncResult)
            {
                GlobalDefinition.LoggerWrapper.LogDevInfo(
                    "####################processed Command.#######################" + guid + "########commandid:" +
                    commandId);
                GlobalDefinition.LoggerWrapper.LogDevError("ICLRCommandHandler's param is null.");
                return(0);
            }

            if (null == CmdMap || null == CmdMapByte)
            {
                GlobalDefinition.LoggerWrapper.LogDevInfo(
                    "####################processed Command.#######################" + guid + "########commandid:" +
                    commandId);
                GlobalDefinition.LoggerWrapper.LogDevError("Not initialize the CmdMap");
                return(0);
            }

            if (CmdMap.ContainsKey(pContext.iCommandId))
            {
                string result = CmdMap[pContext.iCommandId](pContext);

                pSyncResult.SetSerializedString(result);
            }
            else if (CmdMapByte.ContainsKey(pContext.iCommandId))
            {
                byte[] result = CmdMapByte[pContext.iCommandId](pContext);

                pSyncResult.SetSerializedObject(result);
            }
            else
            {
                GlobalDefinition.LoggerWrapper.LogDevInfo(
                    "####################processed Command.#######################" + guid + "########commandid:" +
                    commandId);
                GlobalDefinition.LoggerWrapper.LogDevError("Not process this command id: " +
                                                           pContext.iCommandId.ToString());
                return(0);
            }

            GlobalDefinition.LoggerWrapper.LogDevInfo(pSyncResult.GetSerializedString());

            GlobalDefinition.LoggerWrapper.LogDevInfo("####################processed Command.#######################" +
                                                      guid + "########commandid:" + commandId);
            return(0);
        }
Exemple #3
0
        public override int HandleCommand(CommandContext context, ISyncResult result)
        {
            //return base.HandleCommand(context, result);

            lock (lockObj)
            {
                Console.WriteLine("HandleCommand");

                PatientRemoteObject rObject = SerializeObj.Desrialize <PatientRemoteObject>(context.sSerializeObject);

                Console.WriteLine("InvokeTag:\t" + rObject.InvokeTag);

                switch (rObject.InvokeTag)
                {
                case "NewPatient":
                    _patientManager.NewPatient(rObject.Paramters.First() as Patient);
                    result.SetSerializedObject(SerializeObj.Serialize(true));
                    break;

                case "DeletePatient":
                    _patientManager.DeletePatient((ulong)(rObject.Paramters.First()));
                    result.SetSerializedObject(SerializeObj.Serialize(true));
                    break;

                case "ModifyPatient":
                    _patientManager.ModifyPatient(rObject.Paramters.First() as Patient);
                    result.SetSerializedObject(SerializeObj.Serialize(true));
                    break;

                case "GetPatients":
                    IList <Patient> patientList = _patientManager.GetPatients();
                    result.SetSerializedObject(SerializeObj.Serialize <IList <Patient> >(patientList));
                    break;

                default:
                    break;
                }
            }

            return(0);
        }
 /// <summary>
 /// handle command
 /// </summary>
 /// <param name="context">CommandContext</param>
 /// <param name="result">ISyncResult</param>
 /// <returns></returns>
 public override int HandleCommand(CommandContext context, ISyncResult result)
 {
     try
     {
         SessionRequestCommand sCommand = SessionRequestCommand.ParseFrom(context.sSerializeObject);
         if (!sCommand.HasCommandId || sCommand.ParametersCount < 1)
         {
             result.SetSerializedObject(new byte[] {});
             return(-1);
         }
         ByteString invokeResult = _funDic[sCommand.CommandId].Invoke(sCommand);
         if (null == invokeResult)
         {
             return(-1);
         }
         result.SetSerializedObject(invokeResult.ToByteArray());
         return(0);
     }
     catch (Exception ex)
     {
         CLRLogger.GetInstance().LogDevError("HandleCommand error:" + ex.Message);
         return(-1);
     }
 }