示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:LeanIPC.RPCPeer"/> class.
        /// </summary>
        /// <param name="connection">The connection to use for invoking methods.</param>
        /// <param name="allowedTypes">The types on which remote execution is allowed</param>
        /// <param name="filterPredicate">A predicate function used to filter which methods can be invoked</param>
        public RPCPeer(InterProcessConnection connection, Type[] allowedTypes, Func <System.Reflection.MemberInfo, object[], bool> filterPredicate)
        {
            m_connection = connection ?? throw new ArgumentNullException(nameof(connection));
            m_connection.AddMessageHandler(HandleMessage);
            if (allowedTypes != null)
            {
                if (allowedTypes.Length != 0 && filterPredicate == null)
                {
                    filterPredicate = (a, b) => true;
                }

                foreach (var at in allowedTypes)
                {
                    m_allowedTypes.Add(at, filterPredicate);
                }
            }

            m_typeSerializer = m_connection.TypeSerializer ?? throw new ArgumentNullException(nameof(m_connection.TypeSerializer));
            m_remoteObjects  = m_connection.RemoteHandler ?? throw new ArgumentNullException(nameof(m_connection.RemoteHandler));
        }
示例#2
0
 /// <summary>
 /// Registers a new message handler
 /// </summary>
 /// <param name="handler">The handler to use.</param>
 public void AddMessageHandler(Func <ParsedMessage, Task <bool> > handler)
 {
     m_connection.AddMessageHandler(handler);
 }