Esempio n. 1
0
 /// <summary>
 /// Throws an exception when session context is null
 /// </summary>
 ///<param name="sessionContext">Context of the session</param>
 ///<exception cref="ArgumentNullException">Thrown when session context is null</exception>
 internal protected void CheckIfSessionContextIsNull(DrsrServerSessionContext sessionContext)
 {
     if (sessionContext == null)
     {
         throw new ArgumentNullException("sessionContext");
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Sends RPC response to the client
        /// </summary>
        /// <param name="sessionContext">The session context of the RPC response to send</param>
        /// <param name="messageToSend">The RPC response to send</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when sessionContext or messageToSend is null.
        /// </exception>
        public void SendRpcCallResponse(DrsrServerSessionContext sessionContext, DrsrResponseStub messageToSend)
        {
            CheckIfSessionContextIsNull(sessionContext);

            if (messageToSend == null)
            {
                throw new ArgumentNullException("messageToSend");
            }

            sessionContext.UpdateSessionContextWithMessageSent(sessionContext.InterfaceType, messageToSend);
            rpceLayerServer.SendResponse(
                sessionContext.RpceLayerSessionContext,
                messageToSend.Encode(sessionContext));
        }
Esempio n. 3
0
        public T ExpectRpcCall <T>(
            DrsrRpcInterfaceType interfaceType,
            TimeSpan timeout,
            out DrsrServerSessionContext sessionContext)
            where T : DrsrRequestStub
        {
            RpceServerSessionContext rpceSessionContext;
            ushort opnum;

            byte[] requestStub = rpceLayerServer.ExpectCall(timeout, out rpceSessionContext, out opnum);

            if ((interfaceType == DrsrRpcInterfaceType.DSAOP &&
                 !Enum.IsDefined(typeof(DsaopMethodOpnums), (ushort)opnum)) ||
                (interfaceType == DrsrRpcInterfaceType.DRSUAPI &&
                 !Enum.IsDefined(typeof(DrsuapiMethodOpnums), (ushort)opnum)))
            {
                throw new InvalidOperationException("An invalid method is invoked");
            }

            //If there isn't a corresponding Drsr session context, it's a new session
            if (contextManager.LookupSessionContext(rpceSessionContext, out sessionContext))
            {
                sessionContext.RpceLayerSessionContext = rpceSessionContext;
            }

            T t;

            if (typeof(T) == typeof(DrsrRequestStub))
            {
                t = (T)DrsrUtility.CreateDrsrRequestStub(interfaceType, opnum);
            }
            else
            {
                t = (T)Activator.CreateInstance(typeof(T));
                if ((ushort)t.Opnum != opnum)
                {
                    throw new InvalidOperationException("An unexpected method call is received");
                }
            }

            //Decode the request stub
            t.Decode(sessionContext, requestStub);

            //Update the session context
            sessionContext.UpdateSessionContextWithMessageReceived(interfaceType, t);
            return(t);
        }
 /// <summary>
 ///  Look up the DRSR session context using the session context of RPCE
 /// </summary>
 /// <param name="rpceSessionContext">The RPCE layer session context</param>
 /// <param name="sessionContext">The corresponding DRSR session context</param>
 /// <returns>Whether the rpce session is a new session</returns>
 internal bool LookupSessionContext(
     RpceServerSessionContext rpceSessionContext,
     out DrsrServerSessionContext sessionContext)
 {
     lock (lockObj)
     {
         if (sessionContextMap.ContainsKey(rpceSessionContext))
         {
             sessionContext = sessionContextMap[rpceSessionContext];
             return(false);
         }
         else
         {
             sessionContext = new DrsrServerSessionContext();
             sessionContextMap[rpceSessionContext] = sessionContext;
             return(true);
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Remove a session context from the context manager
 /// </summary>
 /// <param name="sessionContext">The session context to remove</param>
 /// <exception cref="ArgumentNullException">Thrown when sessionContext is null.</exception>
 public void RemoveSessionContext(DrsrServerSessionContext sessionContext)
 {
     CheckIfSessionContextIsNull(sessionContext);
     contextManager.RemoveSessionContext(sessionContext.RpceLayerSessionContext);
 }