Ejemplo n.º 1
0
 /// <summary>
 /// 命令分发上下文。单条命令
 /// </summary>
 /// <param name="command"></param>
 /// <param name = "responder"></param>
 public DistributeContext(MessageBase command, NodeDescriptor responder)
 {
     if (command == null)
     {
         throw new ArgumentNullException("command");
     }
     if (responder == null)
     {
         throw new ArgumentNullException("responder");
     }
     this._acDomain = responder.AcDomain;
     this.Command = command;
     this.Responder = responder;
     #region 如果是head命令类型去掉信息值以减小体积
     DataItem[] infoId = command.DataTuple.IdItems.Items;
     DataItem[] infoValue;
     // 使用ID映射字典转化ID,同时如果是head命令类型去掉信息值以减小体积
     if (Verb.Get.Equals(command.Verb)
         || Verb.Head.Equals(command.Verb))
     {
         infoValue = null;
     }
     else
     {
         infoValue = command.DataTuple.ValueItems.Items;
     }
     #endregion
     this.Result = new QueryResult(command);
 }
Ejemplo n.º 2
0
        public override NotifyResult notified(EditorComponent from, MessageBase msg)
        {
            switch (msg.MsgType)
            {
                case MessageType.Editor:
                    Domain domain = null;
                    switch (msg.getNote<SceneEditorNote>())
                    {
                        case SceneEditorNote.DocInitDone:
                            domain = DomainManager.Instance().getDomain(this);
                            mUI.EntityMng = domain.getCurrentDoc().EntityMng as SceneEntityManager;
                            break;

                    }
                    switch (msg.getNote<CommonEntityNode>())
                    {
                        case CommonEntityNode.SelectedEntityChanged:
                            domain = DomainManager.Instance().getDomain(this);
                            mUI.EntityMng = domain.getCurrentDoc().EntityMng as SceneEntityManager;
                            mUI.refreshPropertyGrid();
                            break;
                    }
                    break;
            }
            return NotifyResult.Pending;
        }
    public override bool Send(short msgType, MessageBase msg)
    {
        Type messageType = msg.GetType();
        //Because of the problem with child spawning we intercept normal spawns and replace it with our own if we are under the correct conditions
        //This is highly illegal never do this
        if (messageType.Name == "ObjectSpawnMessage")
        {
            NetworkInstanceId networkId = (NetworkInstanceId) messageType.GetField("netId").GetValue(msg);

            GameObject foundObject = NetworkServer.FindLocalObject(networkId);
            if (foundObject == null)
                return base.Send(msgType, msg);

            ChildIdentity childId = foundObject.GetComponent<ChildIdentity>();
            if (childId == null)
                return base.Send(msgType, msg);

            byte[] payload = (byte[]) messageType.GetField("payload").GetValue(msg);

            //Intercept the message with a child message
            return base.Send(ChildSpawnMessage.MessageId, new ChildSpawnMessage(childId, payload));
        }

        return base.Send(msgType, msg);
    }
Ejemplo n.º 4
0
 public override NotifyResult notified(EditorComponent from, MessageBase msg)
 {
     switch (msg.MsgType)
     {
         case MessageType.Doc:
             switch (msg.getNote<SceneEditorNote>())
             {
                 case SceneEditorNote.DocInitDone:
                     mUI.initialize();
                     break;
             }
             break;
         case MessageType.NewDoc:
             mUI.initialize();
             break;
         case MessageType.Editor:
             switch (msg.getNote<CommonEntityNode>())
             {
                 case CommonEntityNode.EntityCreated:
                     mUI.refreshEntityTree(null);
                     break;
             }
             break; ;
     }
     return NotifyResult.Pending;
 }
Ejemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        // example of loading csv file
        csv = CSVLoader.Instance;
        //TextAsset txt = csv.loadFile(1, 1, "Alocer_Dania");
        unit = new Unit();
        unit.readCharCSV(1, "Lancelot_Tartare");
        //Debug.Log("step Name: " + BLance.getName());

        // including fade and transition
        fm = FadeManager.Instance;

        // example of sound playing
        snd = SoundManager.Instance;
        //snd.PlayBGM(0);

        // example of random value
        util = UtilCommon.Instance;

        // example of using ClassBase
        cb = ClassBase.Instance;

        ps = ParameterScreen.Instance;
        ps.inactivateGuages();

        mb = MessageBase.Instance;

        ms = MapScreen.Instance;
        //ms.showMap();

        DontDestroyOnLoad(this.gameObject);
    }
Ejemplo n.º 6
0
 private void TCPNetworkReceiver_OnIncommingMessage(MessageBase mess, ushort port1)
 {
     base.BeginThreadSaveAction(() =>
     {
         Actions.Add("IN  : " + mess.InfoState.ToString());
     });
 }
Ejemplo n.º 7
0
 private void NetworkbaseOnOnMessageSend(MessageBase mess, ushort port1)
 {
     base.BeginThreadSaveAction(() =>
     {
         Actions.Add("OUT : " + mess.InfoState.ToString());
     });
 }
Ejemplo n.º 8
0
 /// <summary> 
 /// 发送消息 
 /// </summary> 
 public void SendMessage(MessageBase msg, IPEndPoint remoteIP)
 {
     DoWriteLog("正在发送消息:" + msg);
      if (msg == null) return;
      byte[] buffer = ObjectSerializer.Serialize(msg);
      _server.Send(buffer, buffer.Length, remoteIP);
      DoWriteLog("消息已发送.");
 }
Ejemplo n.º 9
0
 private void OnMessageExpandRightPanel(EditorComponent from, MessageBase msg)
 {
     if (msg.Messages.Count != 0)
     {
         string info0 = msg.Messages[0];
         m_modelview_form.setRightPanelExpand(info0 == "true");
     }
 }
Ejemplo n.º 10
0
 private void onAfterModelCreatedMessage(EditorComponent from, MessageBase msg)
 {
     //if (Doc.CurrentDynamicModel != null)
     //{
     //    BoneListUI.updateBoneList(Doc.CurrentDynamicModel.RootBone);
     //}
     //else
     //    BoneListUI.updateBoneList(null);
 }
Ejemplo n.º 11
0
 private Message GetMessage(MessageBase message)
 {
     return new Message
                {
                    Formatter = new XmlMessageFormatter(new[] {message.GetType()}),
                    Label = message.GetType().FullName,
                    Body = message
                };
 }
Ejemplo n.º 12
0
        /// <summary>
        /// 初始化一个新的响应配置。
        /// </summary>
        /// <param name="bus">总线。</param>
        /// <param name="message">请求消息。</param>
        /// <exception cref="ArgumentNullException"><paramref name="bus"/> 或 <paramref name="message"/> 为 null。</exception>
        public ResponseConfigurator(IBus bus, MessageBase message)
        {
            if (bus == null)
                throw new ArgumentNullException("bus");
            if (message == null)
                throw new ArgumentNullException("message");

            _bus = bus;
            _message = message;
        }
Ejemplo n.º 13
0
 protected override MessageBase CopyImpl(MessageBase clone)
 {
     // Instantiate the clone, if a derived type hasn't already.
     if (clone == null) clone = new AsyncMessage();
     // Allow base type(s) to copy their state into the new clone.
     base.CopyImpl(clone);
     // Copy our state into the clone.
     ((AsyncMessage)clone)._correlationId = _correlationId;
     return clone;
 }
Ejemplo n.º 14
0
 protected override MessageBase CopyImpl(MessageBase clone)
 {
     // Instantiate the clone, if a derived type hasn't already.
     if (clone == null) clone = new RemotingMessage();
     // Allow base type(s) to copy their state into the new clone.
     base.CopyImpl(clone);
     // Copy our state into the clone.
     ((RemotingMessage)clone)._source = _source;
     ((RemotingMessage)clone)._operation = _operation;
     return clone;
 }
Ejemplo n.º 15
0
        public override NotifyResult notified(EditorComponent from, MessageBase msg)
        {
            NotifyResult nr = base.notified(from, msg);

            if (msg.MsgType == MessageType.NewDoc)
            {
                m_current_doc.newDoc();
            }

            return nr;
        }
Ejemplo n.º 16
0
        public bool RecvMsg(MessageBase msg)
        {
            bool ret = false;

            using (MessageQueue queue = MessageQueue.Create(@". \myqueue"))
            {
                queue.Label = "First Queue";

            }

            return ret;
        }
Ejemplo n.º 17
0
        public virtual void Send(MessageBase input)
        {
            _logger.Debug("Send Message.");

            try
            {
                Message message = GetMessage(input);
                _messageQueue.Send(message);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                _logger.Error(ex.StackTrace);
            }
        }
Ejemplo n.º 18
0
        public IMessage DeserializeMessage(object message)
        {
            string receivedMessage = message as string;
            // Small hack
            receivedMessage = receivedMessage.Replace("params", "parameters");

            CallObject receivedCall = JsonSerializer.Deserialize<CallObject>(receivedMessage);
            MessageBase deserializedMessage = new MessageBase();
            deserializedMessage.ID = receivedCall.id;
            if(receivedCall.parameters != null)
                deserializedMessage.Parameters = new List<object> (receivedCall.parameters);
            if (receivedCall.result != null)
                deserializedMessage.Result = receivedCall.result;
            deserializedMessage.MethodName = receivedCall.method;
            deserializedMessage.Type = GetMessageType(receivedCall);
            return deserializedMessage;
        }
Ejemplo n.º 19
0
        public override NotifyResult notified(EditorComponent from, MessageBase msg)
        {
            switch (msg.MsgType)
            {
                case MessageType.Doc:
                    switch (msg.getNote<SceneEditorNote>())
                    {
                        case SceneEditorNote.DocInitDone:
                            Domain domain = DomainManager.Instance().getDomain(this);
                            mEntityMng = domain.getCurrentDoc().EntityMng as SceneEntityManager;
                            mWorld = domain.getCurrentDoc().World as SceneWorld;
                            break;
                    }
                    break; ;
            }

            return base.notified(from, msg);
        }
Ejemplo n.º 20
0
        internal void InitializeForSend( IController parent, Converter converter, uint cmd, uint flags, object payload )
        {
            Packet header = parent.NewPacket();

            header.m_cmd   = cmd;
            header.m_flags = flags;

            m_parent              = parent;

            m_raw                 = new MessageRaw ();
            m_base                = new MessageBase();
            m_base.m_header       = header;
            m_base.m_payload      = payload;

            if(payload != null)
            {                
                m_raw.m_payload = converter.Serialize( payload );

                m_base.m_header.m_size    = (uint)m_raw.m_payload.Length;
                m_base.m_header.m_crcData = CRC.ComputeCRC( m_raw.m_payload, 0 );
            }
        }
Ejemplo n.º 21
0
 public abstract void ProcessEvent(MessageBase msg);
Ejemplo n.º 22
0
 public IncomingMessage( IController parent, MessageRaw raw, MessageBase messageBase)
 {
     m_parent = parent;
     m_raw    = raw;
     m_base   = messageBase;
 }
Ejemplo n.º 23
0
 public void Respond(MessageBase packet, ResponseStatus statusCode = ResponseStatus.Default)
 {
     Respond(MessageHelper.Create(OpCode, packet), statusCode);
 }
Ejemplo n.º 24
0
 public void SendMsg(MessageBase msg)
 {
     NPCManager.Instance.SendMessage(msg);
 }
Ejemplo n.º 25
0
 byte[] MsgToByte(MessageBase msg)
 {
     _writer.SeekZero();
     _writer.Write(msg);
     return(_writer.ToArray());
 }
Ejemplo n.º 26
0
 public VideoMessage(MessageBase receivedMsg) : base(receivedMsg)
 {
     MsgType = "video";
 }
Ejemplo n.º 27
0
 public void SendToClient(int connectionId, short msgType, MessageBase msg)
 {
     NetworkServer.SendToClient(connectionId, msgType, msg);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Message handler for getting files.
 /// </summary>
 /// <param name="obj"></param>
 private async void OnIndexGettingFiles(MessageBase obj)
 {
     await _dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                () => IndexPrompt = "Getting all files");
 }
Ejemplo n.º 29
0
        private MessageBase ReadMessaging(JsonReader reader, Type objectType, object existingValue,
            JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.StartObject)
                throw new JsonReaderException("Messaging Message must be a JSON Object");

            MessageBase msg = new MessageBase();

            for (reader.Read(); reader.TokenType != JsonToken.EndObject; reader.Read())
            {
                if (reader.TokenType != JsonToken.PropertyName)
                    throw new JsonReaderException("JSON format error, JSON Object must have property");

                string propertyName = (string)reader.Value;
                switch (propertyName)
                {
                    case "destination":
                        reader.Read();
                        if (reader.TokenType != JsonToken.String)
                            throw new JsonReaderException("Messaging Message 'destination' must be JSON String");
                        msg.destination = (string)reader.Value;
                        break;
                    case "messageId":
                         reader.Read();
                         if (reader.TokenType != JsonToken.String)
                             throw new JsonReaderException("Messaging Message 'messageId' must be JSON String");
                         msg.messageId = (string)reader.Value;
                        break;
                    case "timestamp":
                        reader.Read();
                        if (reader.TokenType != JsonToken.Integer)
                            throw new JsonReaderException("Messaging Message 'timestamp' must be JSON Number");
                        msg.timestamp = (long)reader.Value;
                        break;
                    case "timeToLive":
                        reader.Read();
                        if (reader.TokenType != JsonToken.Integer)
                            throw new JsonReaderException("Messaging Message 'timeToLive' must be JSON Number");
                        msg.timeToLive = (long)reader.Value;
                        break;
                    case "headers":
                        reader.Read();
                        if (reader.TokenType != JsonToken.StartObject)
                            throw new JsonReaderException("Messaging Message headers must be object");
                        Dictionary<string, object> h = serializer.Deserialize<Dictionary<string, object>>(reader);
                        msg.headers = h;
                        break;
                    case "clientId":
                        reader.Read();
                        //cant definite clientId just a GUID string
                        switch (reader.TokenType)
                        {
                            case JsonToken.String:
                                Guid guid = new Guid();
                                if (Guid.TryParse((string)reader.Value, out guid))
                                {
                                    msg.clientId = reader.Value;
                                }
                                else
                                {
                                    //maybe not appear
                                    ByteArray array = new ByteArray();
                                    byte[] bytes = Encoding.Default.GetBytes((string)reader.Value);
                                    array.WriteBytes(bytes, 0, bytes.Length);
                                    msg.clientId = array;
                                }
                                break;
                            case JsonToken.Null:
                                msg.clientId = reader.Value;
                                break;
                            default:
                                throw new NotSupportedException("Messaging Message clientId only support GUID JSON String, please report this");
                                break;
                        }

                        break;
                    case "body":
                        reader.Read();
                        switch (reader.TokenType)
                        {
                            case JsonToken.StartArray:
                                ArrayList list = new ArrayList();
                                for (reader.Read(); reader.TokenType != JsonToken.EndArray; reader.Read())
                                {
                                    switch (reader.TokenType)
                                    {
                                        case JsonToken.Null:
                                        case JsonToken.Boolean:
                                        case JsonToken.Integer:
                                        case JsonToken.Float:
                                        case JsonToken.String:
                                            list.Add(reader.Value);
                                            break;
                                        default:
                                            throw new NotSupportedException("Messaging Message body[] only support JSON Boolean/Number/String, please report this");
                                    }
                                }
                                msg.body = list.ToArray();
                                break;
                            case JsonToken.StartObject:
                                reader.Read();
                                if (reader.TokenType != JsonToken.EndObject)
                                    throw new NotSupportedException("Messaging Message body{} only support Empty JSON Object, please report this");
                                msg.body = new ASObject();
                                break;
                            default:
                                throw new NotSupportedException("Messaging Message body only support JSON Array/Object, please report this");
                                break;
                        }
                        break;

                }
            }
            return msg;
        }
 public UnSubscribeEvtMessage(MessageBase receivedMsg) : base(receivedMsg)
 {
     Event = "unsubscribe";
 }
Ejemplo n.º 31
0
 /// <summary>
 ///     Serializes a standard uNet message
 /// </summary>
 /// <param name="opCode"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public static IMessage Create(short opCode, MessageBase message)
 {
     _writer.SeekZero();
     message.Serialize(_writer);
     return(_factory.Create(opCode, _writer.ToArray()));
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Creates a message by serializing a standard Unet message
 /// </summary>
 /// <param name="opCode"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public IMessage Message(short opCode, MessageBase message)
 {
     return(MessageHelper.Create(opCode, message));
 }
Ejemplo n.º 33
0
 public DarkCallDisplayPart(MessageBase <DarkCallDisplayPart> customNotificationBase)
 {
     _customNotificationBase = customNotificationBase;
     DataContext             = customNotificationBase;
     InitializeComponent();
 }
Ejemplo n.º 34
0
        public Authorization Authenticate(string challenge, WebRequest webRequest, ICredentials credentials)
        {
            HttpWebRequest request = webRequest as HttpWebRequest;

            if (request == null)
            {
                return(null);
            }

            NetworkCredential cred = credentials.GetCredential(request.RequestUri, "NTLM");

            if (cred == null)
            {
                return(null);
            }

            string userName = cred.UserName;
            string domain   = cred.Domain;
            string password = cred.Password;

            if (userName == null || userName == "")
            {
                return(null);
            }

            if (String.IsNullOrEmpty(domain))
            {
                int idx = userName.IndexOf('\\');
                if (idx == -1)
                {
                    idx = userName.IndexOf('/');
                }
                if (idx >= 0)
                {
                    domain   = userName.Substring(0, idx);
                    userName = userName.Substring(idx + 1);
                }
            }

            bool completed = false;

            if (message == null)
            {
                Type1Message type1 = new Type1Message();
                type1.Domain = domain;
                type1.Host   = "";               // MS does not send it
                type1.Flags |= NtlmFlags.NegotiateNtlm2Key;
                message      = type1;
            }
            else if (message.Type == 1)
            {
                // Should I check the credentials?
                if (challenge == null)
                {
                    message = null;
                    return(null);
                }

                Type2Message type2 = new Type2Message(Convert.FromBase64String(challenge));
                if (password == null)
                {
                    password = "";
                }

                Type3Message type3 = new Type3Message(type2);
                type3.Username = userName;
                type3.Password = password;
                type3.Domain   = domain;
                message        = type3;
                completed      = true;
            }
            else
            {
                // Should I check the credentials?
                // type must be 3 here
                if (challenge == null || challenge == String.Empty)
                {
                    Type1Message type1 = new Type1Message();
                    type1.Domain = domain;
                    type1.Host   = "";                   // MS does not send it
                    message      = type1;
                }
                else
                {
                    completed = true;
                }
            }

            string token = "NTLM " + Convert.ToBase64String(message.GetBytes());

            return(new Authorization(token, completed));
        }
Ejemplo n.º 35
0
        /// <summary>
        /// 接收信息,并解析
        /// </summary>
        /// <param name="cleint"></param>
        void OnReceiveData(ClientSocket clintSocket)
        {
            ByteArray readBuff = clintSocket.ReadBuff;

            // 基本消息长度判断(一个协议头为 4)
            if (readBuff.Length <= 4 || readBuff.ReadIndex < 0)
            {
                Debug.Log("数据小于 4");
                return;
            }

            int readIndex = readBuff.ReadIndex;

            byte[] bytes = readBuff.Bytes;

            //解析协议头,获得中的长度
            int bodyLength = BitConverter.ToInt32(bytes, readIndex);

            // (分包处理)判断接收消息长度是否小于包体长度+包头长度,如果小于,代表接收到的消息不全(返回,不做处理,等下一次全了在处理),大于则代表消息全了(也有可能有粘包存在)
            if (readBuff.Length < bodyLength + 4)
            {
                Debug.Log("数据不完整");
                return;
            }

            // 移动到消息体位置
            readBuff.ReadIndex += 4;

            // 解析协议名称
            int          nameCount = 0;
            ProtocolEnum protocol  = ProtocolEnum.None;

            try
            {
                protocol = MessageBase.DecodeName(readBuff.Bytes, readBuff.ReadIndex, out nameCount);
            }
            catch (Exception ex)
            {
                Debug.LogError("解析协议名称 Error :" + ex);
                CloseClient(clintSocket);
                return;
            }

            // 协议名称为空
            if (protocol == ProtocolEnum.None)
            {
                Debug.LogError("OnReceiveData MessageBase.DecodeName() Fail :");
                CloseClient(clintSocket);
                return;
            }

            // 解析协议内容
            readBuff.ReadIndex += nameCount;

            int bodyCount = bodyLength - nameCount;

            MessageBase messageBase = null;

            try
            {
                messageBase = MessageBase.Decode(protocol, readBuff.Bytes, readBuff.ReadIndex, bodyCount);
                if (messageBase == null)
                {
                    Debug.LogError("{0} 解析协议内容 Error ", protocol.ToString());
                    CloseClient(clintSocket);
                    return;
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("解析协议内容 Error :" + ex);
                CloseClient(clintSocket);
                return;
            }

            // 移动读取位置,并且继续判断移动数据
            readBuff.ReadIndex += bodyCount;
            readBuff.CheckAndMoveBytes();

            //通过反射,分发消息(解析完数据,对应的处理)
            MethodInfo methodInfo = typeof(MessageHandler).GetMethod(protocol.ToString());

            object[] o = { clintSocket, messageBase };
            if (methodInfo != null)
            {
                methodInfo.Invoke(null, o);
            }
            else
            {
                Debug.LogError("OnReceiveData Invok Fail:" + protocol.ToString());
            }


            // 继续读取消息(粘包现象处理)
            if (readBuff.Length > 4)
            {
                OnReceiveData(clintSocket);
            }
        }
Ejemplo n.º 36
0
 internal void Receive(MessageBase messageBase)
 {
     var received = this.MessageReceived;
     if (received != null)
         received (this, new MessageReceivedEventArgs (this, messageBase));
 }
Ejemplo n.º 37
0
 public MusicMessage(MessageBase receivedMsg) : base(receivedMsg)
 {
     MsgType = "music";
 }
Ejemplo n.º 38
0
 public static T GetAttribute <T>(this MessageBase instance) where T : Attribute
 {
     return(instance.GetType().GetCustomAttributes(typeof(T), true).FirstOrDefault() as T);
 }
Ejemplo n.º 39
0
 public void SendToClientOfPlayer(GameObject player, short msgType, MessageBase msg)
 {
     NetworkServer.SendToClientOfPlayer(player, msgType, msg);
 }
Ejemplo n.º 40
0
 public override NotifyResult notified(EditorComponent from, MessageBase msg)
 {
     return NotifyResult.Succeed;
 }
Ejemplo n.º 41
0
 public override void ProcessEvent(MessageBase msg)
 {
 }
 public override bool SendUnreliable(short msgType, MessageBase msg)
 {
   this.m_LocalClient.InvokeHandlerOnClient(msgType, msg, 1);
   return true;
 }
Ejemplo n.º 43
0
 public ClickEvtMessage(MessageBase receivedMsg) : base(receivedMsg)
 {
     Event = "CLICK";
 }
Ejemplo n.º 44
0
 public int Send(MessageBase message, IPeerSender peer)
 {
     return(_shamanSender.Send(message, new DeliveryOptions(message.IsReliable, message.IsOrdered), peer));
 }
Ejemplo n.º 45
0
 public void SendToAll(short msgType, MessageBase msg)
 {
     NetworkServer.SendToAll(msgType, msg);
 }
Ejemplo n.º 46
0
        public override NotifyResult notified(EditorComponent from, MessageBase msg)
        {
            if (msg.MsgType != MessageType.Log || msg.Messages.Count < 1)
                return NotifyResult.Pending;

            if(msg.Messages.Count == 1)
                m_log_form.addNewLog(msg.Messages[0]);
            else if (msg.Messages.Count > 1)
            {
                string msgex = msg.Messages[0] + ": " +DateTime.Now.ToString() + ": " + msg.Messages[1];
                m_log_form.addNewLog(msgex);
            }

            return NotifyResult.Succeed;
        }
        public Authorization Authenticate(string challenge, WebRequest webRequest, ICredentials credentials)
        {
            HttpWebRequest request = webRequest as HttpWebRequest;

            if (request == null)
            {
                return(null);
            }

            NetworkCredential cred = credentials.GetCredential(request.RequestUri, "NTLM");

            if (cred == null)
            {
                return(null);
            }

            string userName = cred.UserName;
            string domain   = cred.Domain;
            string password = cred.Password;

            if (userName == null || userName == "")
            {
                return(null);
            }
            domain = domain != null && domain.Length > 0 ? domain : request.Headers ["Host"];

            bool completed = false;

            if (message == null)
            {
                Type1Message type1 = new Type1Message();
                type1.Domain = domain;
                message      = type1;
            }
            else if (message.Type == 1)
            {
                // Should I check the credentials?
                if (challenge == null)
                {
                    message = null;
                    return(null);
                }

                Type2Message type2 = new Type2Message(Convert.FromBase64String(challenge));
                if (password == null)
                {
                    password = "";
                }

                Type3Message type3 = new Type3Message();
                type3.Domain    = domain;
                type3.Username  = userName;
                type3.Challenge = type2.Nonce;
                type3.Password  = password;
                message         = type3;
                completed       = true;
            }
            else
            {
                // Should I check the credentials?
                // type must be 3 here
                if (challenge == null || challenge == String.Empty)
                {
                    Type1Message type1 = new Type1Message();
                    type1.Domain = domain;
                    message      = type1;
                }
                else
                {
                    completed = true;
                }
            }

            string token = "NTLM " + Convert.ToBase64String(message.GetBytes());

            return(new Authorization(token, completed));
        }
Ejemplo n.º 48
0
 public CookieGuardedMessage(MessageBase guardedMessage, string commandId, int cookieExpirationDays = 365) : this(guardedMessage, commandId, cookieExpirationDays, null)
 {
 }
 public ResultMessage(MessageBase message)
 {
     this.Service = message.Service;
     this.Id = message.Id;
     this.Type = message.Type;
 }
Ejemplo n.º 50
0
        public async Task <IdentifyResponse> IdentifyChild(FPCaptureRs vm)
        {
            IdentifyResponse returnModel = new IdentifyResponse();
            IdentifyRequest  request     = new IdentifyRequest();

            request.Id = Guid.NewGuid();
            request.FingerprintRecord                              = new DsdAfis.Core.FingerBiometrics.FingerprintRecord();
            request.FingerprintRecord.Id                           = 0;
            request.FingerprintRecord.Active                       = false;
            request.FingerprintRecord.DateTime                     = DateTime.Now;
            request.FingerprintRecord.FingerprintSet               = new DsdAfis.Core.FingerBiometrics.FingerprintSet();
            request.FingerprintRecord.FingerprintSet.Dpi           = 500;
            request.FingerprintRecord.FingerprintSet.ImageEncoding = "WSQ";
            request.FingerprintRecord.FingerprintSet.ImageHeight   = 512;
            request.FingerprintRecord.FingerprintSet.ImageWidth    = 512;
            List <Fingerprint> fingers     = new List <Fingerprint>();
            Fingerprint        blankFinger = null;

            fingers.Add(blankFinger);
            foreach (Finger f in vm.Fingers)
            {
                if (f.Sequence > 0)
                {
                    Fingerprint finger = new Fingerprint();
                    switch (f.Name)
                    {
                    case "1":
                        finger.Code = FingerCode.RightThumb;
                        break;

                    case "6":
                        finger.Code = FingerCode.LeftThumb;
                        break;
                    }
                    finger.EncodedImage = f.Print;
                    fingers.Add(finger);
                }
                else
                {
                    fingers.Add(null);
                }
            }
            request.FingerprintRecord.FingerprintSet.Fingerprints = fingers.ToArray();

            using (var client = new HttpClient())
            {
                //Passing service base url
                client.BaseAddress = new Uri(ConfigurationManager.AppSettings["WebApiUrl"]);

                client.DefaultRequestHeaders.Clear();
                //Define request data format
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.PostAsync(
                    "api/afis/identify", new StringContent(request.Json, Encoding.UTF8, "application/json"));

                if (response.IsSuccessStatusCode)
                {
                    return(MessageBase.Deserialize <IdentifyResponse>(response.Content.ReadAsStringAsync().Result));
                }
                else
                {
                    return(returnModel);
                }
            }
        }
 public override bool SendByChannel(short msgType, MessageBase msg, int channelId)
 {
   this.m_LocalClient.InvokeHandlerOnClient(msgType, msg, channelId);
   return true;
 }
Ejemplo n.º 52
0
 public ScreenResultMessage(MessageBase message)
     : base(message)
 {
     this.Type = message.Type ?? 'S';
 }
Ejemplo n.º 53
0
 internal String GetIndent(int indentLevel)
 {
     return(MessageBase.GetIndent(indentLevel));
 }
Ejemplo n.º 54
0
 internal String GetFieldSeparator(int indentLevel)
 {
     return(MessageBase.GetFieldSeparator(indentLevel));
 }
Ejemplo n.º 55
0
 /// <summary>
 /// Message handler for index starting event.
 /// </summary>
 /// <param name="obj"></param>
 private async void OnIndexStarted(MessageBase obj)
 {
     await _dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                () => IsScanActive = true);
 }
Ejemplo n.º 56
0
        public void HandleClient(TcpClient Tcp, Stream TheStream)
        {
            try
            {
                BinaryFormatter bf = new BinaryFormatter();
                while (true)
                {
                    MessageBase             mb      = (MessageBase)bf.Deserialize(TheStream);
                    UsersAndMessagesManager manager = new UsersAndMessagesManager();

                    if (mb is TextMessage)
                    {
                        TextMessage messageToSend = new TextMessage();
                        messageToSend = (TextMessage)mb;
                        RouteMessages(messageToSend, TheStream);
                        manager.InsertNewMessageToDB(messageToSend.SenderId, messageToSend.Message);
                    }
                    else if (mb is DisconnectionMessage)
                    {
                        DisconnectionMessage disconnect = new DisconnectionMessage();
                        disconnect = (DisconnectionMessage)mb;
                        ClientDisconnected(this, new ConnectingAndDisconnectingEventArgs(disconnect.CurrenUser.Name));
                        DisconnectUser(disconnect.CurrenUser);
                        CurrentClientOnLine(this, new CurrentUsersOnLineEventArgs(mb.CurrenUser.Name, mb.CurrenUser.ID, 'B'));
                        ClientCounter(this, new EventArgs());
                        TextMessage byeMessageFromServer = new TextMessage()
                        {
                            Message = "[**Server message**]: " + disconnect.CurrenUser.Name + " left"
                        };
                        RouteMessages(byeMessageFromServer, TheStream);
                        manager.UpdateLastSeenWhenDisconnecting(disconnect.CurrenUser.ID);
                    }
                    else if (mb is MessageBase)
                    {
                        //verify if details are unique
                        if (mb.CurrenUser.IsNew == true)
                        {
                            bool checkUniqueDetails = manager.CheckIfUserIdExistInDb(mb.CurrenUser.ID, mb.CurrenUser.Name);
                            if (checkUniqueDetails)
                            {
                                MessageBase m = mb;
                                m.op.NewUserIdlsAlreadyExistInDB = true;
                                bf.Serialize(TheStream, m);
                                return;
                            }
                            manager.InsertNewUserToDB(mb.CurrenUser.ID, mb.CurrenUser.Name, mb.CurrenUser.Password);
                        }
                        else
                        {
                            char verifyUserBeforeLogIn = manager.MatchingTheDetailsOfLogingUser(mb.CurrenUser.ID, mb.CurrenUser.Name, mb.CurrenUser.Password);
                            if (verifyUserBeforeLogIn == 'a' || verifyUserBeforeLogIn == 'b' || verifyUserBeforeLogIn == 'd')
                            {
                                MessageBase m = mb;
                                m.op.ErrorState = verifyUserBeforeLogIn;
                                bf.Serialize(TheStream, m);
                                return;
                            }
                        }

                        bf.Serialize(TheStream, mb);
                        _clientList.Add(mb.CurrenUser);
                        mb.CurrenUser.Stream = TheStream;
                        ClientAccepted(this, new ConnectingAndDisconnectingEventArgs(mb.CurrenUser.Name.ToString()));
                        CurrentClientOnLine(this, new CurrentUsersOnLineEventArgs(mb.CurrenUser.Name, mb.CurrenUser.ID, 'A'));
                        ClientCounter(this, new EventArgs());
                        TextMessage welcomeMessageFromServer = new TextMessage()
                        {
                            Message = "[**Server message**]: " + mb.CurrenUser.Name + " joined "
                        };
                        RouteMessages(welcomeMessageFromServer, TheStream);
                    }
                }
            }
            catch (SerializationException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (IOException)
            { }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 57
0
 /// <summary>
 /// Sends <paramref name="message"/> to the other end of the connection.
 /// </summary>
 /// <param name="message">The message to send.</param>
 /// <exception cref="System.ArgumentNullException"><paramref name="message"/> is <c>null</c>.</exception>
 public void Send(MessageBase message)
 {
     var mqueue = ((List<MessageBase>)session["mqueue"]);
     lock (mqueue)
         mqueue.Add (message);
 }
Ejemplo n.º 58
0
 public bool CanHandle(MessageBase message)
 {
     return(message is XboxInputMessage);
 }
Ejemplo n.º 59
0
 protected override MessageBase CopyImpl(MessageBase clone)
 {
     // Instantiate the clone, if a derived type hasn't already.
     if (clone == null) clone = new CommandMessage();
     // Allow base type(s) to copy their state into the new clone.
     base.CopyImpl(clone);
     // Copy our state into the clone.
     //((CommandMessage)clone)._messageRefType = _messageRefType;
     ((CommandMessage)clone)._operation = _operation;
     return clone;
 }
Ejemplo n.º 60
0
 public void Handle(MessageBase message)
 {
     device.SendInput(message as XboxInputMessage);
 }