Example #1
0
        internal async Task TransmitObjectAsync <T>(string identifier, string target, T obj) where T : class
        {
            string  payload = MessageSerializer.SerializeData(obj);
            Message msg     = this.MessageFactory.CreateMessageRequest(identifier, this.ProcessName, target, payload);

            await this.SendAsync(msg);
        }
Example #2
0
        internal async Task <TResult> TransmitObjectAsync <T, TResult>(string identifier, string target, T obj) where T : class
        {
            string         payload = MessageSerializer.SerializeData(obj);
            Message        msg     = this.MessageFactory.CreateMessageRequest(identifier, this.ProcessName, target, payload);
            Task <TResult> t       = this.HandleTransmissionResultAsync <TResult>(msg.ID);

            await this.SendAsync(msg);

            return(await t);
        }
Example #3
0
        internal string GetProcessesData(string origin)
        {
            List <RemoteProcessData> res = new List <RemoteProcessData>();

            foreach ((string stateName, BaseClientState _) in this.States)
            {
                if (!stateName.Equals(origin))
                {
                    res.Add(new RemoteProcessData(stateName));
                }
            }

            return(MessageSerializer.SerializeData(res));
        }
Example #4
0
        /// <summary>
        /// Registers an event handler that will be fired whenever the transmission for the specified identifier is received
        /// </summary>
        /// <typeparam name="T">The data type we expect to receive</typeparam>
        /// <typeparam name="TResult">The data type we are sending back</typeparam>
        /// <param name="identifier">The transmission identifier</param>
        /// <param name="handler">The handler to be called when receiving a transmission</param>
        public void OnTransmission <T, TResult>(string identifier, Func <RemoteProcess, T, TResult> handler)
        {
            if (this.TransmissionHandlers.ContainsKey(identifier))
            {
                throw new NonUniqueIdentifierException(identifier);
            }

            this.TransmissionHandlers.Add(identifier, msg =>
            {
                T data             = msg.GetData <T>();
                RemoteProcess proc = this.GetProcess(msg.OriginName);
                TResult result     = handler(proc, data);

                return(MessageSerializer.SerializeData(result));
            });
        }