Esempio n. 1
0
 //Actor给Actor发送ActorMessage类型的信心
 public void SendMsg(ActorMessage msg)
 {
     lock (m_lockobj)
     {
         m_msgQueue.Enqueue(msg);
     }
 }
        public async System.Threading.Tasks.Task <Event> PublishEvent(ActorMessage source, ActorMessage destination, IMessageBroker messageBroker, EventAggregator.RoutingFilter routingFilter)
        {
            if (destination.Type == "TestEvent")
            {
                var @event = new HomeCenter.SourceGenerators.Tests.TestEvent();
                @event.SetProperties(source);
                @event.SetProperties(destination);
                await messageBroker.Publish(@event, routingFilter);

                return(@event);
            }
            else if (destination.Type == "TestEvent2")
            {
                var @event = new HomeCenter.SourceGenerators.Tests.TestEvent2();
                @event.SetProperties(source);
                @event.SetProperties(destination);
                await messageBroker.Publish(@event, routingFilter);

                return(@event);
            }

            var ev = new Event();

            ev.SetProperties(source);
            ev.SetProperties(destination);
            await messageBroker.Publish(ev, routingFilter);

            return(ev);
        }
        public async Task <Event> PublishEvent(ActorMessage source, ActorMessage destination,
                                               IMessageBroker messageBroker, RoutingFilter routingFilter)
        {
            if (destination.Type == "TestEvent")
            {
                var @event = new TestEvent();
                @event.SetProperties(source);
                @event.SetProperties(destination);
                await messageBroker.Publish(@event, routingFilter);

                return(@event);
            }

            if (destination.Type == "TestEvent2")
            {
                var @event = new TestEvent2();
                @event.SetProperties(source);
                @event.SetProperties(destination);
                await messageBroker.Publish(@event, routingFilter);

                return(@event);
            }

            var ev = new Event();

            ev.SetProperties(source);
            ev.SetProperties(destination);
            await messageBroker.Publish(ev, routingFilter);

            return(ev);
        }
Esempio n. 4
0
        public void SendWithTranslate(ActorMessage source, ActorMessage destination, string address)
        {
            var command = _messageGenerator.CreateCommand(destination.Type);

            command.SetProperties(source);
            command.SetProperties(destination);

            Send(command, address);
        }
		// This method blocks by calling TryReceive repeatidly, always sure to return a good result
		public bool TryReceive(out ActorMessage<MessageArgs> message)
		{
			message = default(ActorMessage<MessageArgs>);
			
			ActorMessage<MessageArgs> temp = message;
			bool result = Receive((m) => temp = m);
			message = temp;
			
			return result;
		}
Esempio n. 6
0
    //Actor给Actor发送string类型的信息
    public void SendMsg(string msg)
    {
        var m = new ActorMessage();

        m.msg = msg;
        lock (m_lockobj)
        {
            m_msgQueue.Enqueue(m);
        }
    }
Esempio n. 7
0
 //Actor给Actor发送ActorMessage类型的信心
 public void SendMsg(ActorMessage msg)
 {
     if (msg == null)
     {
         return;
     }
     lock (m_lockobj)
     {
         m_msgQueue.Enqueue(msg);
     }
 }
Esempio n. 8
0
    //Actor给Actor发送Packet类型的信息
    public void SendMsg(Packet packet)
    {
        var m = new ActorMessage()
        {
            packet = packet
        };

        lock (m_lockobj)
        {
            m_msgQueue.Enqueue(m);
        }
    }
Esempio n. 9
0
    //Actor给Actor发送string类型的信息
    public void SendMsg(string msg)
    {
        if (string.IsNullOrEmpty(msg))
        {
            return;
        }
        var m = new ActorMessage();

        m.msg = msg;
        lock (m_lockobj)
        {
            m_msgQueue.Enqueue(m);
        }
    }
Esempio n. 10
0
        private static void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Published message for actor.");
            Console.ForegroundColor = _defaultConsoleForeground;
            ActorMessage actorMessage = new ActorMessage
            {
                Command   = $"power={_cnt++}",
                Timestamp = DateTime.UtcNow
            };

            string payload = JsonConvert.SerializeObject(actorMessage);

            mqttClient.PublishAsync("D6B02D87-FBDD-4D52-BA31-9A0623D8E67A/actors/switch1", payload).Wait();
        }
Esempio n. 11
0
    //Actor给Actor发送Packet类型的信息
    public void SendMsg(Packet packet)
    {
        if (packet == null)
        {
            return;
        }
        var m = new ActorMessage()
        {
            packet = packet
        };

        lock (m_lockobj)
        {
            m_msgQueue.Enqueue(m);
        }
    }
Esempio n. 12
0
 protected override void ReceiveMsg(ActorMessage actorMsg)
 {
     if (!string.IsNullOrEmpty(actorMsg.msg))
     {
         var cmds = actorMsg.msg.Split(SplitChar);
         if (cmds[0] == CreatePlayerActorStr)
         {
             var agentId = System.Convert.ToUInt32(cmds[1]);
             CreatePlayerActorCallback(agentId);
         }
         else if (cmds[0] == DestroyPlayerActorStr)
         {
             var agentId = System.Convert.ToUInt32(cmds[1]);
             DestroyPlayerActorCallback(agentId); //销毁PlayerActor
         }
     }
 }
Esempio n. 13
0
 protected override void ReceiveMsg(ActorMessage actorMsg)
 {
     if (actorMsg == null)
     {
         return;
     }
     if (!string.IsNullOrEmpty(actorMsg.msg))
     {
         HandleMsgStr(actorMsg.msg);
     }
     if (actorMsg.packet != null)
     {
         //处理ActorMessage中携带Packet内容的情况
         Packet packet = actorMsg.packet;
         HandlePacket(packet);
     }
 }
Esempio n. 14
0
 private IEnumerator Dispatch()
 {
     while (!m_isStop)
     {
         if (m_msgQueue.Count > 0)
         {
             ActorMessage msg = null;
             lock (m_lockobj)
             {
                 msg = m_msgQueue.Dequeue();
             }
             ReceiveMsg(msg);
         }
         else
         {
             yield return(null);
         }
     }
 }
Esempio n. 15
0
        public Task PublishWithTranslate(ActorMessage source, ActorMessage destination, RoutingFilter filter = null)
        {
            var ev = _messageGenerator.CreateEvent(source, destination);

            return(Publish(ev, filter));
        }
Esempio n. 16
0
 public static TResult Response <TActor, TResult>(this ActorMessage <TActor, TResult> message, TResult result)
     where TActor : IActorGrain => result;
Esempio n. 17
0
 public CommandJob(ActorMessage message) => Message = message;
Esempio n. 18
0
 internal abstract void OnActorMessageReceived(ActorMessage actorData);
Esempio n. 19
0
 /// <summary>
 /// Helper method to use when building task responses for strongly typed messages which return results.
 /// If the type of returned result is changed in message declaration this will help catching it at compile time.
 /// </summary>
 /// <example>
 /// <para>
 ///     class Query : ActorMessage&lt;MyActor,int&gt;{}
 /// </para>
 /// <para>
 ///     Task&lt;object&gt; On(Query x) => x.TaskResult(42);
 /// </para>
 /// </example>
 /// <param name="message">The strongly typed message</param>
 /// <param name="result">The result to return</param>
 /// <typeparam name="TActor">The type of the actor to which this message belongs</typeparam>
 /// <typeparam name="TResult">The type of the returned result</typeparam>
 /// <returns>The value passed to <paramref name="result"/> argument wrapped in Task&lt;object&gt;</returns>
 public static Task <object> TaskResult <TActor, TResult>(this ActorMessage <TActor, TResult> message, TResult result)
     where TActor : IActorGrain, IGrainWithStringKey => Task.FromResult <object>(result);
Esempio n. 20
0
 public Task <Event> PublishWithTranslate(ActorMessage source, ActorMessage destination, RoutingFilter filter = null)
 {
     throw new NotImplementedException();
 }
Esempio n. 21
0
 //虚方法,用于子类重写
 protected virtual void ReceiveMsg(ActorMessage msg)
 {
 }
Esempio n. 22
0
 public Task <Event> PublishWithTranslate(ActorMessage source, ActorMessage destination, RoutingFilter filter = null)
 {
     return(_messageGenerator.PublishEvent(source, destination, this, filter));
 }
Esempio n. 23
0
 protected override void ReceiveMsg(ActorMessage actorMsg)
 {
     if (!string.IsNullOrEmpty(actorMsg.msg))
     {
     }
 }
Esempio n. 24
0
 public void SendWithTranslate(ActorMessage source, ActorMessage destination, string address)
 {
     throw new NotImplementedException();
 }
Esempio n. 25
0
 /// <summary>
 /// Helper method to use when building responses for strongly typed messages which return results.
 /// If the type of returned result is changed in message declaration this will help catching it at compile time.
 /// </summary>
 /// <example>
 /// <para>
 ///     class Query : ActorMessage&lt;MyActor,int&gt;{}
 /// </para>
 /// <para>
 ///     int On(Query x) => x.Result(42);
 /// </para>
 /// </example>
 /// <param name="message">The strongly typed message</param>
 /// <param name="result">The result to return</param>
 /// <typeparam name="TActor">The type of the actor to which this message belongs</typeparam>
 /// <typeparam name="TResult">The type of the returned result</typeparam>
 /// <returns>The value passed to <paramref name="result"/> argument</returns>
 public static TResult Result <TActor, TResult>(this ActorMessage <TActor, TResult> message, TResult result)
     where TActor : IActorGrain, IGrainWithStringKey => result;
    public async System.Threading.Tasks.Task <HomeCenter.Model.Messages.Events.Event> PublishEvent(ActorMessage source, ActorMessage destination, HomeCenter.Model.Core.IMessageBroker messageBroker, HomeCenter.Broker.RoutingFilter routingFilter)
    {
        if (destination.Type == "DipswitchEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Device.DipswitchEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }
        else if (destination.Type == "InfraredEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Device.InfraredEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }
        else if (destination.Type == "MotionEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Device.MotionEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }
        else if (destination.Type == "PinValueChangedEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Device.PinValueChangedEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }
        else if (destination.Type == "PowerStateChangeEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Device.PowerStateChangeEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }
        else if (destination.Type == "PropertyChangedEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Device.PropertyChangedEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }
        else if (destination.Type == "SerialResultEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Device.SerialResultEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }
        else if (destination.Type == "ComponentStartedEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Service.ComponentStartedEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }
        else if (destination.Type == "SystemStartedEvent")
        {
            var @event = new HomeCenter.Model.Messages.Events.Service.SystemStartedEvent();
            @event.SetProperties(source);
            @event.SetProperties(destination);
            await messageBroker.Publish(@event, routingFilter);

            return(@event);
        }

        {
            var ev = new HomeCenter.Model.Messages.Events.Event();
            ev.SetProperties(source);
            ev.SetProperties(destination);
            await messageBroker.Publish(ev, routingFilter);

            return(ev);
        }
    }
Esempio n. 27
0
 internal override void OnActorMessageReceived(ActorMessage actorData)
 {
     Console.ForegroundColor = ConsoleColor.Yellow;
     Console.WriteLine($"Received message for topic: {actorData.Command}");
     Console.ForegroundColor = _defaultConsoleColor;
 }