示例#1
0
        static void Main(string[] args)
        {
            ProxyClient proxyClient = new ProxyClient(Int32.Parse(args[0]));

            proxyClient.Start();

            ProxyServer.logger.Info("Proxy Starting");
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
示例#2
0
        public static void Route(byte[] bytes, ProxyClient proxyClient)
        {
            try
            {
                IActor actor;
                Entity entity = MessageUtil.ByteArrayToEntity(bytes);

                if (entity.id == "ping")
                {
                    return;
                }

                string typeName = entity.destination;
                string threadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
                string id       = typeName + threadId;

                if (MessageRouter.actors.TryGetValue(id, out actor))
                {
                    actor.PostInit(proxyClient);
                    actor.OnReceive(entity);
                }
                else
                {
                    Type type = Type.GetType(typeName);
                    if (type == null)
                    {
                        MessageRouter.logger.Info(typeName + " is null");
                        return;
                    }
                    actor = Activator.CreateInstance(type) as IActor;
                    if (MessageRouter.actors.TryAdd(id, actor))
                    {
                        actor.PostInit(proxyClient);
                        actor.OnReceive(entity);
                    }
                    else
                    {
                        MessageRouter.logger.Info("Unable to add actor " + id);
                    }
                }
            } catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#3
0
 public void PostInit(ProxyClient pc)
 {
     proxyClient = pc;
 }