protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
        {
            string token = invokerContext.Hub.Context.QueryString["token"];

            ErrorLogger.Log(exceptionContext.Error, TokenResolver.Resolve(token).UserName);
            base.OnIncomingError(exceptionContext, invokerContext);
        }
        public DynamicMethodTokenResolver(DynamicMethod dynamicMethod)
        {
            var resolverField = typeof(DynamicMethod).GetField(
                "m_resolver", BindingFlags.Instance | BindingFlags.NonPublic);
            var resolver = resolverField?.GetValue(dynamicMethod);

            if (resolver == null)
            {
                throw new ArgumentException("The dynamic method's IL has not been finalized.");
            }

            tokenResolver = (TokenResolver)resolver.GetType()
                            .GetMethod("ResolveToken", BindingFlags.Instance | BindingFlags.NonPublic)
                            .CreateDelegate(typeof(TokenResolver), resolver);
            stringResolver    = (StringResolver)resolver.GetType().GetMethod("GetStringLiteral", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(StringResolver), resolver);
            signatureResolver = (SignatureResolver)resolver.GetType().GetMethod("ResolveSignature", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(SignatureResolver), resolver);

            getTypeFromHandleUnsafe = (GetTypeFromHandleUnsafe)typeof(Type).GetMethod("GetTypeFromHandleUnsafe", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { typeof(IntPtr) }, null).CreateDelegate(typeof(GetTypeFromHandleUnsafe), null);
            var runtimeType = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeType");

            var runtimeMethodHandleInternal = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeMethodHandleInternal");

            getMethodBase = runtimeType.GetMethod("GetMethodBase", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { runtimeType, runtimeMethodHandleInternal }, null);
            runtimeMethodHandleInternalCtor = runtimeMethodHandleInternal.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(IntPtr) }, null);

            var runtimeFieldInfoStub = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeFieldInfoStub");

            runtimeFieldHandleStubCtor = runtimeFieldInfoStub.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(IntPtr), typeof(object) }, null);
            getFieldInfo = runtimeType.GetMethod("GetFieldInfo", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { runtimeType, typeof(RuntimeTypeHandle).Assembly.GetType("System.IRuntimeFieldInfo") }, null);
        }
 public override Task OnConnected()
 {
     if (!TokenResolver.Resolve(Context.QueryString["token"]).Authorized ||
         TokenResolver.Resolve(Context.QueryString["token"]).Role != "Admin")
     {
         // Logout User
         return(null);
     }
     return(base.OnConnected());
 }
        public void Test_TokenResolver_Token_Null()
        {
            var resolver = new TokenResolver();

            var val = resolver.Resolve(null, new object[]
            {
                null,
                new { A = (string)null },
                new { A = 123 }
            });
        }
        public async Task Test_TokenResolver_OnlyDictionary_String_Object_Is_Supportted()
        {
            var resolver = new TokenResolver();

            var val = await resolver.ResolveAsync(new TokenResult(new CurlyBracketDefinition(), "{A}", "{A} 123", 0), new Dictionary <object, object>
            {
                { "A", "Duy" }
            });

            val.Should().Be("Duy");
        }
        public async Task Test_TokenResolver_Dictionary()
        {
            var resolver = new TokenResolver();

            var val = await resolver.ResolveAsync(new TokenResult(new CurlyBracketDefinition(), "{A}", "{A} 123", 0), new Dictionary <string, object>
            {
                { "A", "Duy" }
            });

            val.Should().Be("Duy");
        }
        public async Task Test_TokenResolver_Async()
        {
            var resolver = new TokenResolver();

            var val = await resolver.ResolveAsync(new TokenResult(new CurlyBracketDefinition(), "{A}", "{A} 123", 0), new object[]
            {
                null,
                new { A = (string)null },
                new { A = 123 }
            });

            val.Should().Be(123);
        }
Example #8
0
        /// <summary>
        ///  1- register member to offline state
        ///  2- send notification that he is offline
        /// </summary>
        public void MemberOffline()
        {
            string userName = TokenResolver.Resolve(Context.QueryString["token"]).UserName;

            if (_unitOfWork.MemberHubDataRepository.CheckKeyExistOnlineMembers(Context.ConnectionId))
            {
                _unitOfWork.MemberHubDataRepository.RemoveFromOnlineMembers(Context.ConnectionId);
                if (!_unitOfWork.MemberHubDataRepository.CheckValueExistOnlineMembers(userName))
                {
                    Clients.Group(userName + "MemberStatus").changeState(false);
                }
            }
        }
        protected override async Task <ResourceResponse> ProcessOutgoingActivityAsync(ITurnContext turnContext, Activity activity, CancellationToken cancellationToken)
        {
            if (activity == null)
            {
                throw new ArgumentNullException(nameof(activity));
            }

            // Check if we have token responses from OAuth cards.
            TokenResolver.CheckForOAuthCards(this, Logger, turnContext, activity, cancellationToken);

            // The ServiceUrl for streaming channels begins with the string "urn" and contains
            // information unique to streaming connections. Now that we know that this is a streaming
            // activity, process it in the streaming pipeline.
            // Process streaming activity.
            return(await SendStreamingActivityAsync(activity).ConfigureAwait(false));
        }
        public DynamicMethodTokenResolver(DynamicMethod dynamicMethod)
        {
            object resolver = typeof(DynamicMethod).GetField("m_resolver", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dynamicMethod);

            _tokenResolver     = (TokenResolver)resolver.GetType().GetMethod("_resolveToken", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(TokenResolver), resolver);
            _stringResolver    = (StringResolver)resolver.GetType().GetMethod("GetStringLiteral", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(StringResolver), resolver);
            _signatureResolver = (SignatureResolver)resolver.GetType().GetMethod("ResolveSignature", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(SignatureResolver), resolver);

            _getTypeFromHandleUnsafe = (GetTypeFromHandleUnsafe)typeof(Type).GetMethod("GetTypeFromHandleUnsafe", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { typeof(IntPtr) }, null).CreateDelegate(typeof(GetTypeFromHandleUnsafe), null);
            Type runtimeType = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeType");

            Type runtimeMethodHandleInternal = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeMethodHandleInternal");

            _getMethodBase = runtimeType.GetMethod("GetMethodBase", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { runtimeType, runtimeMethodHandleInternal }, null);
            _runtimeMethodHandleInternalCtor = runtimeMethodHandleInternal.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(IntPtr) }, null);

            Type runtimeFieldInfoStub = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeFieldInfoStub");

            _runtimeFieldHandleStubCtor = runtimeFieldInfoStub.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(IntPtr), typeof(object) }, null);
            _getFieldInfo = runtimeType.GetMethod("GetFieldInfo", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { runtimeType, typeof(RuntimeTypeHandle).Assembly.GetType("System.IRuntimeFieldInfo") }, null);
        }
Example #11
0
        /// <summary>
        /// Maps a data contract type to an xsi:type name and namespace during serialization.
        /// </summary>
        /// <param name="dataContractType">The type to map.</param>
        /// <param name="declaredType">The type declared in the data contract.</param>
        /// <param name="knownTypeResolver">The known type resolver.</param>
        /// <param name="typeName">The xsi:type name.</param>
        /// <param name="typeNamespace">The xsi:type namespace.</param>
        /// <returns>true if mapping succeeded; otherwise, false.</returns>
        public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            if (dataContractType == typeof(ServiceResponse))
            {
                XmlDictionary dictionary = new XmlDictionary();
                typeName      = dictionary.Add("ServiceResponse");
                typeNamespace = dictionary.Add(ServiceNamespace);
                return(true);
            }

            if (dataContractType == typeof(ServiceRequest <TAuthenticationToken>))
            {
                XmlDictionary dictionary = new XmlDictionary();
                typeName      = dictionary.Add("ServiceRequest");
                typeNamespace = dictionary.Add(ServiceNamespace);
                return(true);
            }

            bool result = TokenResolver.TryResolveType(dataContractType, declaredType, knownTypeResolver, out typeName, out typeNamespace);

            if (result)
            {
                return(true);
            }

            result = EventDataResolver.TryResolveType(dataContractType, declaredType, knownTypeResolver, out typeName, out typeNamespace);
            if (result)
            {
                return(true);
            }

            result = TryResolveUnResolvedType(dataContractType, declaredType, knownTypeResolver, ref typeName, ref typeNamespace);
            if (result)
            {
                return(true);
            }

            // Defer to the known type resolver
            return(knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace));
        }
Example #12
0
        /// <summary>
        /// 1- Check User Identity
        /// 2- Register for Notifications
        /// 3- Return Friend Relations List
        /// </summary>
        /// <returns></returns>
        public IEnumerable <FriendRelationDTO> SetupMemberEnvironment()
        {
            // Validate User
            string username;

            if (TokenResolver.Resolve(Context.QueryString["token"]).Authorized)
            {
                username = TokenResolver.Resolve(Context.QueryString["token"]).UserName;
            }
            else
            {
                throw new UnauthorizedAccessException("User is Unauthorized.");
            }
            var user = _unitOfWork.MembersRepository.GetUser(username);

            if (user == null)
            {
                throw new NullReferenceException("User is not existed.");
            }

            MemberOnline(username);

            IEnumerable <Relation> relations = _unitOfWork.RelationsRepository.GetRelations(user.Id);

            Groups.Add(Context.ConnectionId, username + "Member");


            IEnumerable <FriendRelationDTO> friendList = Mapper.Map <IEnumerable <Relation>,
                                                                     IEnumerable <FriendRelationDTO> >(relations)
                                                         .Select(c => { c.State = _unitOfWork.MemberHubDataRepository.CheckValueExistOnlineFriends(c.Id); return(c); });

            foreach (var i in relations)
            {
                RegisterMemberForNotification(i.Id);
            }

            return(friendList);
        }
Example #13
0
        /// <summary>
        /// Maps the specified xsi:type name and namespace to a data contract type during deserialization.
        /// </summary>
        /// <returns>
        /// The type the xsi:type name and namespace is mapped to.
        /// </returns>
        /// <param name="typeName">The xsi:type name to map.</param>
        /// <param name="typeNamespace">The xsi:type namespace to map.</param>
        /// <param name="declaredType">The type declared in the data contract.</param>
        /// <param name="knownTypeResolver">The known type resolver.</param>
        public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
        {
            if (typeNamespace == ServiceNamespace)
            {
                if (typeName == "ServiceResponse")
                {
                    return(typeof(ServiceResponse));
                }

                if (typeName == "ServiceRequest")
                {
                    return(typeof(ServiceRequest <TAuthenticationToken>));
                }
            }

            Type result = TokenResolver.ResolveName(typeName, typeNamespace, declaredType, knownTypeResolver);

            if (result != null)
            {
                return(result);
            }

            result = EventDataResolver.ResolveName(typeName, typeNamespace, declaredType, knownTypeResolver);
            if (result != null)
            {
                return(result);
            }

            result = ResolveUnResolvedName(typeName, typeNamespace, declaredType, knownTypeResolver);
            if (result != null)
            {
                return(result);
            }

            // Defer to the known type resolver
            return(knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null));
        }
        public void Test_TokenResolver_Data_Null()
        {
            var resolver = new TokenResolver();

            var val = resolver.Resolve(new TokenResult(new CurlyBracketDefinition(), "{A}", "{A} 123", 0), null);
        }
        public void Test_TokenResolver_Data_Empty()
        {
            var resolver = new TokenResolver();

            var val = resolver.Resolve(new TokenResult(new CurlyBracketDefinition(), "{A}", "{A} 123", 0), new object[0]);
        }
Example #16
0
        protected void RestoreMethod(int index, byte[] byteILs, ushort maxStack, byte[] byteLocalSig, CORINFO_EH_CLAUSE[] clauses, TokenResolver tokenResolver)
        {
            MethodDef           methodDef;
            JitMethodBodyReader methodBodyReader;

            methodDef        = _context.DumpedModuleDef.ResolveMethod((uint)index + 1);
            methodBodyReader = new JitMethodBodyReader(_context.DumpedModuleDef, methodDef.Parameters)
            {
                TokenResolver = tokenResolver
            };
            methodDef.FreeMethodBody();
            methodDef.Body = methodBodyReader.CreateCilBody(byteILs, maxStack, byteLocalSig, clauses);
        }
Example #17
0
        private object ConvertToOperand(int instructionOffset, MSILOpCode opcode, byte[] rawoperand)
        {
            try
            {
                switch (opcode.OperandType)
                {
                case OperandType.Argument:
                    ParameterDefinition paramDef = GetParameter(BitConverter.ToInt16(rawoperand, 0));
                    if (paramDef == null)
                    {
                        return(BitConverter.ToInt16(rawoperand, 0));
                    }
                    return(paramDef);

                case OperandType.ShortArgument:
                    paramDef = GetParameter(rawoperand[0]);
                    if (paramDef == null)
                    {
                        return(rawoperand[0]);
                    }
                    return(paramDef);

                case OperandType.Float32:
                    return(BitConverter.ToSingle(rawoperand, 0));

                case OperandType.Float64:
                    return(BitConverter.ToDouble(rawoperand, 0));

                case OperandType.InstructionTable:

                    int   length     = BitConverter.ToInt32(rawoperand, 0);
                    int[] offsets    = new int[length];
                    int   nextOffset = instructionOffset + (length * 4) + opcode.Bytes.Length + 4;
                    for (int i = 0; i < length; i++)
                    {
                        int index   = (i + 1) * sizeof(int);
                        int roffset = BitConverter.ToInt32(rawoperand, index);
                        offsets[i] = roffset + nextOffset;
                    }

                    return(offsets);

                case OperandType.InstructionTarget:
                    return(BitConverter.ToInt32(rawoperand, 0) + instructionOffset + opcode.Bytes.Length + sizeof(int));

                case OperandType.ShortInstructionTarget:
                    return(ASMGlobals.ByteToSByte(rawoperand[0]) + instructionOffset + opcode.Bytes.Length + sizeof(byte));

                case OperandType.Int8:
                    return(ASMGlobals.ByteToSByte(rawoperand[0]));

                case OperandType.Int32:
                    return(BitConverter.ToInt32(rawoperand, 0));

                case OperandType.Int64:
                    return(BitConverter.ToInt64(rawoperand, 0));

                case OperandType.Token:
                case OperandType.Field:
                case OperandType.Method:
                case OperandType.Type:
                    uint metadata = BitConverter.ToUInt32(rawoperand, 0);
                    try
                    {
                        object operand = TokenResolver.ResolveMember(metadata);

                        if (operand is ISpecification)
                        {
                            operand = (operand as ISpecification).TransformWith(MethodBody.Method);
                        }

                        return(operand);
                    }
                    catch { return(new TypeReference(string.Empty, "TOKEN:" + metadata.ToString("X8"), null)); }

                case OperandType.ShortVariable:
                    VariableDefinition varDef = GetVariable(rawoperand[0]);
                    if (varDef == null)
                    {
                        return(rawoperand[0]);
                    }
                    return(varDef);

                case OperandType.Variable:
                    varDef = GetVariable(BitConverter.ToInt16(rawoperand, 0));
                    if (varDef == null)
                    {
                        return(rawoperand[0]);
                    }
                    return(varDef);

                case OperandType.Signature:
                    return(BitConverter.ToInt32(rawoperand, 0));

                case OperandType.String:
                    return(TokenResolver.ResolveString(BitConverter.ToUInt32(rawoperand, 0)));
                }
            }
            catch { }

            return(null);
        }
Example #18
0
 public DelimOp(string delim, string name = null, string desc = null, ParseRule parseRule = null, SyntaxRequirement addReq = null, int order = 100, SyntaxGenerator syntax = null, TokenResolver resolve = null, bool printable = true, bool breaking = true)
     : base(delim, name, desc, parseRule, addReq, printable, breaking)
 {
     this.order = order; isSyntaxValid = syntax; this.resolve = resolve;
 }