Пример #1
0
        bool UpdateRegisterInfo(School school, DuplexMessage commandMessage)
        {
            var registerOk   = false;
            var registerInfo = commandMessage.GetContent <RegisterInfo>();

            if (registerInfo != null)
            {
                school.ClientPubKey = registerInfo.ClientPubKey;
                school.UniqueToken  = registerInfo.ClientMacAddr;
                metaRepository.AddOrUpdateSchool(school, (updateOk) =>
                {
                    DuplexMessage resultMessage;
                    if (updateOk)
                    {
                        resultMessage = DuplexMessage.CreateCallbackMessage(commandMessage);
                    }
                    else
                    {
                        resultMessage = DuplexMessage.CreateCallbackMessage(commandMessage, ErrorCode.RegisterFailed);
                    }

                    Return(resultMessage);
                });
                registerOk = true;
            }
            return(registerOk);
        }
Пример #2
0
        protected override DuplexMessage DoExecute(DuplexMessage commandMessage)
        {
            DuplexMessage resultMessage = null;
            var           school        = metaRepository
                                          .GetAllSchools()
                                          .ByIdentifier(commandMessage.Header.Identifier);

            if (school != null)
            {
                if (UpdateRegisterInfo(school, commandMessage))
                {
                    resultMessage = DuplexMessage.CreateAckMessage(commandMessage);
                }
                else
                {
                    resultMessage = DuplexMessage.CreateCallbackMessage(commandMessage, ErrorCode.RegisterFailed);
                }
            }
            else
            {
                resultMessage = DuplexMessage.CreateCallbackMessage(commandMessage, ErrorCode.RegisterFailed);
            }

            return(resultMessage);
        }
Пример #3
0
        protected override DuplexMessage DoExecute(DuplexMessage commandMessage)
        {
            Log.Error(ErrorCode.BadProtocalVersion, new Exception("error"));
            var content = commandMessage.GetContent <Customer>();

            return(DuplexMessage.CreateCallbackMessage(commandMessage, content));
        }
Пример #4
0
        protected override DuplexMessage DoExecute(DuplexMessage commandMessage)
        {
            IoSession     session       = null;
            DuplexMessage resultMessage = null;

            if (identifierManager.TryGetSessonIdByIdentifier(commandMessage.Header.Identifier, out session))
            {
                var connectors = session.Service
                                 .ManagedSessions
                                 .Values
                                 .Where(s => s.Id != session.Id)
                                 .Select(s => s.GetAttribute <string>(KeyName.SESSION_IDENTIFIER))
                                 .ToList();
                resultMessage = DuplexMessage.CreateCallbackMessage(commandMessage, connectors);
                resultMessage.Header.FilterType   |= MessageFilterType.Crypto;
                resultMessage.Header.SerializeMode = Rpc.Net.Message.Serializer.SerializeMode.Json;
            }
            else
            {
                resultMessage = DuplexMessage.CreateCallbackMessage(commandMessage);
            }
            return(resultMessage);
        }
 public override void MessageReceived(INextFilter nextFilter, IoSession session, object message)
 {
     using (var scope = ObjectHost.Host.BeginLifetimeScope())
     {
         var commandMessage = message as DuplexMessage;
         if (commandMessage != null)
         {
             if (commandMessage.Header.CommandCode == CommandCode.Authentication)
             {
                 var school = metaRepository
                              .GetAllSchools()
                              .ByIdentifier(commandMessage.Header.Identifier);
                 if (school != null && school.UniqueToken.Equals(
                         commandMessage.GetContent <AuthInfo>().Mac, StringComparison.OrdinalIgnoreCase))
                 {
                     session.SetAttributeIfAbsent(KeyName.SESSION_IDENTIFIER, commandMessage.Header.Identifier);
                     identifierManager.SetSessonIdentifier(commandMessage.Header.Identifier, session);
                     nextFilter.FilterWrite(session,
                                            new DefaultWriteRequest(
                                                DuplexMessage.CreateCallbackMessage(commandMessage)));
                 }
                 else
                 {
                     nextFilter.FilterWrite(session,
                                            new DefaultWriteRequest(
                                                DuplexMessage.CreateAckMessage(commandMessage, ErrorCode.AuthenticationFailed)));
                 }
             }
             else if (
                 commandMessage.Header.CommandCode == CommandCode.Register ||
                 commandMessage.Header.CommandCode == CommandCode.Heartbeat)
             {
                 nextFilter.MessageReceived(session, message);
             }
             else
             {
                 if (!session.ContainsAttribute(KeyName.SESSION_IDENTIFIER))
                 {
                     nextFilter.FilterWrite(session, new DefaultWriteRequest(
                                                DuplexMessage.CreateAckMessage(commandMessage, ErrorCode.UnauthorizedCommand)));
                 }
                 else
                 {
                     var identifier = session.GetAttribute <string>(KeyName.SESSION_IDENTIFIER);
                     if (identifier.Equals(commandMessage.Header.Identifier))
                     {
                         nextFilter.MessageReceived(session, message);
                     }
                     else
                     {
                         nextFilter.FilterWrite(session, new DefaultWriteRequest(
                                                    DuplexMessage.CreateAckMessage(commandMessage, ErrorCode.UnauthorizedCommand)));
                     }
                 }
             }
         }
         else
         {
             nextFilter.FilterWrite(session, new DefaultWriteRequest(
                                        DuplexMessage.CreateAckMessage(
                                            Guid.NewGuid().ToByteArray().ToBase64(),
                                            MessageVersion.V1,
                                            CommandCode.UnAssigned,
                                            ErrorCode.IllegalCommandRequest)));
         }
     }
 }