Пример #1
0
        public void testSendRecvServerTransport()
        {
            const String     connectionString = "bnmq://localhost:3333";
            TransportFactory conFactory       = new TransportFactory();

            try {
                conFactory.TransportMessageCoderFactory = new ASN1TransportMessageCoderFactory();
                ITransport server = conFactory.getServerTransport(new Uri(connectionString));
                Assert.NotNull(server);
                server.start();
                ITransport client = conFactory.getClientTransport(new Uri(connectionString));
                Assert.NotNull(client);
                client.start();

                byte[] buffer = new byte[] { 0x01, 0x02, 0x03, 0x04 };
                for (int i = 0; i < 255; i++)
                {
                    client.sendAsync(buffer);
                }
                Thread.Sleep(500);
                server.close();
                client.close();
            }
            finally {
                conFactory.close();
            }
            Console.WriteLine("Finished: testSendRecvServerTransport");
        }
        protected virtual void Awake()
        {
#if UNITY_WEBGL && !UNITY_EDITOR
            // Force to use websocket transport if it's running as webgl
            if (transportFactory == null || !transportFactory.CanUseWithWebGL)
            {
                transportFactory = gameObject.AddComponent <WebSocketTransportFactory>();
            }
#else
            if (useWebSocket)
            {
                if (transportFactory == null || !transportFactory.CanUseWithWebGL)
                {
                    transportFactory = gameObject.AddComponent <WebSocketTransportFactory>();
                }
            }
            else
            {
                if (transportFactory == null)
                {
                    transportFactory = gameObject.AddComponent <LiteNetLibTransportFactory>();
                }
            }
#endif
            transport = TransportFactory.Build();

            if (offlineTransport == null)
            {
                offlineTransport = new OfflineTransport();
            }

            Client = new LiteNetLibClient(this);
            Server = new LiteNetLibServer(this);
        }
Пример #3
0
        public static void Run(TransportFactory factory, string address)
        {
            Console.WriteLine($"Hosting server at {address}");

            using (var transport = factory.Make <Request, Response>())
                using (var serversAccessor = transport.AcceptServers(address, (inMemory, outMemory) => new Service(outMemory).Invoke))
                {
                    serversAccessor.Error += (sender, args) => Console.WriteLine($"IPC: {args.Exception.Message}");

                    serversAccessor.Connected += (sender, args) =>
                                                 Console.WriteLine($"Connected: {args.Component.InputMemory.Name} -> {args.Component.OutputMemory.Name}");

                    serversAccessor.Disconnected += (sender, args) =>
                                                    Console.WriteLine($"Disconnected: {args.Component.InputMemory.Name} -> {args.Component.OutputMemory.Name}");

                    Console.WriteLine("Press Ctrl+C to exit.");

                    using (var exit = new ManualResetEvent(false))
                    {
                        Console.CancelKeyPress += (sender, args) => { args.Cancel = true; exit.Set(); };
                        exit.WaitOne();
                    }

                    Console.WriteLine("Exiting...");

                    foreach (var server in serversAccessor.Servers) // Just to trigger Disconnected events
                    {
                        server.Dispose();
                    }
                }
        }
        public void testCall()
        {
            const String     connectionString = "bnmq://localhost:3333";
            TransportFactory conFactory       = new TransportFactory();

            try {
                conFactory.TransportMessageCoderFactory = (new ASN1TransportMessageCoderFactory());

                ITransport server = conFactory.getServerTransport(new Uri(connectionString));
                Assert.NotNull(server);
                CallMessageListener cl = new CallMessageListener(this);
                server.addConnectionListener(cl);
                server.addReader(cl);
                Thread.Sleep(500);
                server.start();

                ITransport client = conFactory.getClientTransport(new Uri(connectionString));
                Assert.NotNull(client);
                client.start();
                MessageEnvelope result = client.call(createMessage("Call"), 10);
                Console.WriteLine("Result call received with Id:" + result.Id + " has been received successfully");
                client.close();
                server.close();
            }
            finally {
                conFactory.close();
            }
            Console.WriteLine("Finished: testCall");
        }
        public void testTakeMessage()
        {
            const String     connectionString = "bnmq://localhost:3333";
            TransportFactory conFactory       = new TransportFactory();

            try {
                conFactory.TransportMessageCoderFactory = new ASN1TransportMessageCoderFactory();

                ITransport server = conFactory.getServerTransport(new Uri(connectionString));
                Assert.NotNull(server);
                MessageListener ml = new MessageListener(this);
                server.addConnectionListener(ml);
                server.addReader(ml);
                server.start();

                ITransport client = conFactory.getClientTransport(new Uri(connectionString));
                ml = new MessageListener(this);
                client.addConnectionListener(ml);
                client.addReader(ml);
                Assert.NotNull(client);
                client.start();

                client.send(createMessage("AAAaasasasasassas"));
                client.sendAsync(createMessage("Two"));
                Thread.Sleep(1500);
                client.close();
                server.close();
            }
            finally {
                conFactory.close();
            }
            Console.WriteLine("Finished: testTakeMessage");
        }
        public void testAsyncCall()
        {
            const String     connectionString = "bnmq://localhost:3333";
            TransportFactory conFactory       = new TransportFactory();

            try {
                conFactory.TransportMessageCoderFactory = (new ASN1TransportMessageCoderFactory());

                ITransport server = conFactory.getServerTransport(new Uri(connectionString));
                Assert.NotNull(server);
                CallMessageListener cl = new CallMessageListener(this);
                server.addConnectionListener(cl);
                server.addReader(cl);
                server.start();

                ITransport client = conFactory.getClientTransport(new Uri(connectionString));
                Assert.NotNull(client);
                client.start();
                client.callAsync(createMessage("CallAsync"), new AsyncCallMessageListener());
                Thread.Sleep(500);

                client.close();
                server.close();
            }
            finally {
                conFactory.close();
            }
            Console.WriteLine("Finished: testCall");
        }
Пример #7
0
        public GameInfo CreateTestWorld(List <WorldObject> worldObjects)
        {
            bool newWorld = false;

            // Create players
            List <Player> playerList  = new List <Player>();
            const int     playerCount = 2;

            for (int i = 0; i < playerCount; i++)
            {
                var newPlayer = new Player {
                    Name = Constants.DefaultPlayerInfo.NamesAndColors[i].Item1
                };
                newPlayer.InitializeContent(Content);
                newPlayer.Cash        = 5000;
                newPlayer.PlayerColor = Constants.DefaultPlayerInfo.NamesAndColors[i].Item2;

                newPlayer.Avatar = Content.Load <Texture2D>(Constants.DefaultPlayerInfo.AvatarImages[i]);

                newPlayer.CareerType = CareerType.CollegeCareer;
                newPlayer.Accept(TransportFactory.GetInstance().GetTransport(TransportType.PlaneCar));
                playerList.Add(newPlayer);

                // Give them all their assets for testing
                if (i != 1)
                {
                    continue;
                }
                {
                    newPlayer.Accept(new Partner());
                    newPlayer.Accept(new Pet());
                    newPlayer.Accept(new PassportStamp(IslandType.Jungle));
                    newPlayer.Accept(new Loan(-4000));
                    newPlayer.Accept(new PassportStamp(IslandType.City));
                    newPlayer.Accept(new PassportStamp(IslandType.Beach));
                    newPlayer.Accept(new PassportStamp(IslandType.Jungle));
                    newPlayer.Accept(new PassportStamp(IslandType.Snow));
                    newPlayer.Accept(new PassportStamp(IslandType.City));
                    newPlayer.Accept(new PassportStamp(IslandType.City));
                    newPlayer.Accept(new Child());
                    newPlayer.Accept(new Child());
                    newPlayer.Accept(new Child());

                    newPlayer.Accept(new Pet());
                    newPlayer.Accept(new Child());
                    newPlayer.Accept(new Loan(-4000));
                    newPlayer.Accept(new Loan(-43450));

                    newPlayer.Accept(new House(12123, "Awesome House", "Images/AlertIcons/House"));
                }
            }

            var gameInfo = new GameInfo(worldObjects == null || newWorld ? CreateBasicEmptyWorld(Content) : worldObjects, playerList.ToArray(), 100, GameRuleType.Passport)
            {
                Manager = Manager as CustomManager
            };

            return(gameInfo);
        }
        public void TestCreate()
        {
            TransportFactory tf = new TransportFactory();
            Transport        t;

            t = tf.create("Bus Stop");
            Assert.AreEqual("Bus Stop", t.getName());
        }
Пример #9
0
        public static ServerFactory NewListener(string uri,
                                                Resources resources, MyCuaeServerFactory implFactory)
        {
            Resources res = InitResources(resources);
            Transport <ServerFactory> listener = TransportFactory.GetListener(uri, res);

            return(new MyServerFactory(listener, implFactory));
        }
        public void ReturnMustBeZeroFromJadLog()
        {
            Mock <IItem> mock = new Mock <IItem>();

            ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.JADLOG);
            ItemResult         itemResult        = availableStrategy.Calculate(mock.Object);

            Assert.True(itemResult.Total == 0);
        }
        public void ReturnMustBeZeroFromTotalExpress()
        {
            Mock <IItem> mock = new Mock <IItem>();

            ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.TOTALEXPRESS);
            ItemResult         itemResult        = availableStrategy.Calculate(mock.Object);

            Assert.True(itemResult.Total == 0);
        }
        public void Should_CreateMessageBusWithAzureServiceBusTransport()
        {
            var busControl = TransportFactory.Create(
                TransportType.AzureServiceBus,
                (_) => { }
                );

            Assert.IsType <MassTransitBus>(busControl);
        }
        public void Should_CreateMessageBusWithInMemoryTransport()
        {
            var busControl = TransportFactory.Create(
                TransportType.InMemory,
                (_) => { }
                );

            Assert.IsType <MassTransitBus>(busControl);
        }
        public void MustReturnTaxFromFedex()
        {
            Mock <IItem> mock = new Mock <IItem>();
            IItem        item = mock.Object;

            ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.FEDEX);
            ItemResult         itemResult        = availableStrategy.Calculate(item);

            Assert.Equal(0.65, itemResult.TransportTax);
        }
 public override void SetUp()
 {
     base.SetUp();
     ObjectFactory.Configure(x => x.AddRegistry <TerminalSendGridStructureMapBootstrapper.LiveMode>());
     ObjectFactory.Configure(cfg => cfg.For <ITransport>().Use(c => TransportFactory.CreateWeb(c.GetInstance <IConfigRepository>())));
     ObjectFactory.Configure(cfg => cfg.For <IEmailPackager>().Use(c => new SendGridPackager(c.GetInstance <IConfigRepository>())));
     TerminalBootstrapper.ConfigureTest();
     _crate          = ObjectFactory.GetInstance <ICrateManager>();
     activityPayload = GetActivityResult().Result;
 }
Пример #16
0
        public void Run()
        {
            if (auditQueueAddress == null)
            {
                return;
            }

            inputTransport = TransportFactory.GetTransport(OnTransportMessageReceived);
            inputTransport.Start(auditQueueAddress);
        }
        public void MustReturnTaxFromTotalExpress()
        {
            Mock <IItem> mock = new Mock <IItem>();
            IItem        item = mock.Object;

            ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.TOTALEXPRESS);
            ItemResult         itemResult        = availableStrategy.Calculate(item);

            Assert.Equal(0.15, itemResult.TransportTax);
        }
 public void testTransport()
 {
     //create instance of factory
     TransportFactory f = new TransportFactory();
     //create instance from factory
     Transport p = f.create("Transport");
     //check that it is right type
     Type t = new Transport().GetType();
     Assert.IsInstanceOfType(t, p);
 }
        public void Should_CreateMessageBusWithRabbitMqBusTransport()
        {
            var busControl = TransportFactory.Create(
                TransportType.RabbitMq,
                (_) => { }
                );

            Console.WriteLine(busControl.GetType());

            Assert.IsType <MassTransitBus>(busControl);
        }
        public void test_transport()
        {
            //create instance of factory
            TransportFactory f = new TransportFactory();
            //create instance from factory
            Transport p = f.create("Transport");
            //check that it is right type
            Type t = new Transport().GetType();

            Assert.IsInstanceOfType(t, p);
        }
Пример #21
0
        public void Method_OpenNewTestListener()
        {
            TransportFactory.Define("blah", new TcpTransportFactory(false));

            string uri = "blah://localhost:4040";

            MainTest1Listener implFactory = new MainTest1Listener();

            listener = Test1Helper.NewListener(uri, null, implFactory);
            listener.TransportControl(TransportConsts.START_AND_WAIT_UP, 4000);
        }
Пример #22
0
        public IConnection CreateConnection(string userName, string password)
        {
            Connection connection = null;

            try
            {
                // Strip off the activemq prefix, if it exists.
                Uri uri = new Uri(URISupport.stripPrefix(brokerUri.OriginalString, "stomp:"));

                Tracer.InfoFormat("Connecting to: {0}", uri.ToString());

                ITransport transport = TransportFactory.CreateTransport(uri);

                connection = new Connection(uri, transport, this.ClientIdGenerator);

                connection.UserName = userName;
                connection.Password = password;

                ConfigureConnection(connection);

                if (this.clientId != null)
                {
                    connection.DefaultClientId = this.clientId;
                }

                connection.ITransport.Start();

                return(connection);
            }
            catch (NMSException e)
            {
                try
                {
                    connection.Close();
                }
                catch
                {
                }

                throw e;
            }
            catch (Exception e)
            {
                try
                {
                    connection.Close();
                }
                catch
                {
                }

                throw NMSExceptionSupport.Create("Could not connect to broker URL: " + this.brokerUri + ". Reason: " + e.Message, e);
            }
        }
        public void MustReturnTaxFromCorreios()
        {
            Mock <IItem> mock = new Mock <IItem>();
            IItem        item = mock.Object;

            ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.CORREIOS);

            ItemResult itemResult = availableStrategy.Calculate(item);

            Assert.Equal(0.80, itemResult.TransportTax);
        }
Пример #24
0
        private bool buildBackups()
        {
            try
            {
                backupMutex.WaitOne();
                if (!disposed && Backup && backups.Count < BackupPoolSize)
                {
                    List <Uri> connectList = ConnectList;
                    foreach (BackupTransport bt in backups)
                    {
                        if (bt.Disposed)
                        {
                            backups.Remove(bt);
                        }
                    }

                    foreach (Uri uri in connectList)
                    {
                        if (ConnectedTransportURI != null && !ConnectedTransportURI.Equals(uri))
                        {
                            try
                            {
                                BackupTransport bt = new BackupTransport(this);
                                bt.Uri = uri;
                                if (!backups.Contains(bt))
                                {
                                    ITransport t = TransportFactory.CompositeConnect(uri);
                                    t.Command   = new CommandHandler(bt.onCommand);
                                    t.Exception = new ExceptionHandler(bt.onException);
                                    t.Start();
                                    bt.Transport = t;
                                    backups.Add(bt);
                                }
                            }
                            catch (Exception e)
                            {
                                Tracer.DebugFormat("Failed to build backup: {0}", e.Message);
                            }
                        }

                        if (backups.Count < BackupPoolSize)
                        {
                            break;
                        }
                    }
                }
            }
            finally
            {
                backupMutex.ReleaseMutex();
            }

            return(false);
        }
Пример #25
0
        public IConnection CreateConnection(string userName, string password)
        {
            Connection connection = null;

            try
            {
                Tracer.InfoFormat("Connecting to: {0}", brokerUri.ToString());

                ITransport transport = TransportFactory.CreateTransport(brokerUri);

                connection = new Connection(brokerUri, transport, this.ClientIdGenerator);

                connection.UserName = userName;
                connection.Password = password;

                ConfigureConnection(connection);

                if (this.clientId != null)
                {
                    // Set the connection factory version as the default, the user can
                    // still override this via a call to Connection.ClientId = XXX
                    connection.DefaultClientId = this.clientId;
                }

                connection.ITransport.Start();

                return(connection);
            }
            catch (NMSException e)
            {
                try
                {
                    connection.Close();
                }
                catch
                {
                }

                throw e;
            }
            catch (Exception e)
            {
                try
                {
                    connection.Close();
                }
                catch
                {
                }

                throw NMSExceptionSupport.Create("Could not connect to broker URL: " + this.brokerUri + ". Reason: " + e.Message, e);
            }
        }
Пример #26
0
    private void HandleRetrieveResponses()
    {
        var transportType = TransportFactory.GetTransportType();                           // Gets transport protocol for the producer we need to use (Email, File, ect.)
        var producer      = ServiceLocator.Current.GetInstance <IProducer>(transportType); // Gets a producer from the IoC container for the specified transportType

        var responses = producer.GetResponses();

        foreach (var response in responseFiles)
        {
            Context.Parent.Tell(new ConsumerActor.Consume(response));
        }
    }
Пример #27
0
 /// <summary>
 /// Does the connect.
 /// </summary>
 public void DoConnect()
 {
     try
     {
         TransportFactory.AsyncCompositeConnect(_uri, _setTransport);
     }
     catch (Exception e)
     {
         _transport.Failure = e;
         Tracer.DebugFormat("Connect fail to: {0}, reason: {1}", _uri, e.Message);
     }
 }
        public void ReturnMustBeGreaterThanZeroFromTotalExpress()
        {
            Mock <IItem> mock = new Mock <IItem>();

            mock.SetupProperty(item => item.Quantity, 5);
            mock.SetupProperty(item => item.Price, 125.5);

            ICalculateStrategy availableStrategy = TransportFactory.GetAvailableStrategy(AvailableTransports.TOTALEXPRESS);
            ItemResult         itemResult        = availableStrategy.Calculate(mock.Object);

            Assert.True(itemResult.Total > 0);
        }
Пример #29
0
        /// <summary>
        /// Initializes the application.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            bool FSEM = true;

            Graphics.SynchronizeWithVerticalRetrace = true;
            if (FSEM)
            {
                //Getting the maximum supported resolution.
                var maxResolution = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;

                //Setting the game to start in full screen mode.
                Graphics.PreferredBackBufferWidth  = maxResolution.Width;
                Graphics.PreferredBackBufferHeight = maxResolution.Height;
                Graphics.ToggleFullScreen();
            }
            else
            {
                Graphics.PreferredBackBufferWidth  = 1224;
                Graphics.PreferredBackBufferHeight = 550;
            }
            Graphics.ApplyChanges();

            ((CustomManager)Manager).MainWindow = MainWindow;
            MainWindow.Alpha              = 0;
            MainWindow.StayOnBack         = true;
            MainWindow.CloseButtonVisible = false;

            StorageDevice.BeginShowSelector(result => { _storageDevice = StorageDevice.EndShowSelector(result); }, null);
            Persister.DepdencyInjection(_storageDevice);

            WorldLoader.SetInstance(new WorldLoader(this, Content));
            TransportFactory.SetInstance(new TransportFactory(Content));

            InitScreenManager();

            _music          = _backgroundMusic.CreateInstance();
            _music.IsLooped = true;
            _music.Play();


            // Toggles admin mode when 'Admin Please' is typed
            _AdminListener = new InputListener {
                // "Admin please"
                Keys = new[] {
                    Keys.A, Keys.D, Keys.M, Keys.I, Keys.N,
                    Keys.Space,
                    Keys.P, Keys.L, Keys.E, Keys.A, Keys.S, Keys.E
                },
                Callback = ChangeAdminMode
            };
        }
Пример #30
0
        private bool BuildBackups()
        {
            lock (backupMutex)
            {
                if (!disposed && Backup && backups.Count < BackupPoolSize)
                {
                    List <Uri> connectList = ConnectList;
                    foreach (BackupTransport bt in backups)
                    {
                        if (bt.Disposed)
                        {
                            backups.Remove(bt);
                        }
                    }

                    foreach (Uri uri in connectList)
                    {
                        if (ConnectedTransportURI != null && !ConnectedTransportURI.Equals(uri))
                        {
                            try
                            {
                                BackupTransport bt = new BackupTransport(this)
                                {
                                    Uri = uri
                                };

                                if (!backups.Contains(bt))
                                {
                                    ITransport t = TransportFactory.CompositeConnect(uri);
                                    t.Command   = bt.OnCommand;
                                    t.Exception = bt.OnException;
                                    t.Start();
                                    bt.Transport = t;
                                    backups.Add(bt);
                                }
                            }
                            catch (Exception e)
                            {
                                Tracer.DebugFormat("Failed to build backup: {0}", e.Message);
                            }
                        }

                        if (backups.Count == BackupPoolSize)
                        {
                            break;
                        }
                    }
                }
            }

            return(false);
        }
Пример #31
0
        public TradeableProperty TradeProperty(Player purchaser)
        {
            var transportFactory = new TransportFactory();

            TradeableProperty tradeableProperty = transportFactory.create("Railway Station");

            // The trader should be the banker as they own the property
            Trader trader = Banker.Access();

            trader.TradeProperty(ref tradeableProperty, ref purchaser, tradeableProperty.GetPrice(), Decimal.Zero);

            return(tradeableProperty);
        }
Пример #32
0
        /// <summary>
        /// Create a new instance for handling UDP connections providing
        /// specified ordering requirements.
        /// </summary>
        /// <param name="ordering"></param>
        public UdpConnector(Ordering ordering)
        {
            log = LogManager.GetLogger(GetType());

            switch (ordering)
            {
                case Ordering.Unordered:
                    factory = new TransportFactory<UdpClient>(
                        BaseUdpTransport.UnorderedProtocolDescriptor,
                        h => new UdpClientTransport(h),
                        t => t is UdpClientTransport);
                    return;
                case Ordering.Sequenced:
                    factory = new TransportFactory<UdpClient>(
                        BaseUdpTransport.SequencedProtocolDescriptor,
                        h => new UdpSequencedClientTransport(h),
                        t => t is UdpSequencedClientTransport);
                    return;
                default: throw new InvalidOperationException("Unsupported ordering type: " + ordering);
            }
        }
Пример #33
0
        /// <summary>
        /// Create a new instance using the provided transport factory
        /// </summary>
        /// <param name="factory"></param>
        public UdpConnector(TransportFactory<UdpClient> factory)
        {
            log = LogManager.GetLogger(GetType());

            this.factory = factory;
        }