Пример #1
0
        public void create_transport_type_if_missing()
        {
            var collection = new TransportCollection(new JasperOptions());
            var transport  = collection.Get <FakeTransport>();

            collection.Get <FakeTransport>()
            .ShouldBeSameAs(transport);
        }
Пример #2
0
        public void try_to_get_endpoint_from_invalid_transport()
        {
            var collection = new TransportCollection(new JasperOptions());

            Exception <InvalidOperationException> .ShouldBeThrownBy(() =>
            {
                collection.TryGetEndpoint("wrong://server".ToUri());
            });
        }
Пример #3
0
        public void all_endpoints()
        {
            var collection = new TransportCollection(new JasperOptions());

            collection.ListenAtPort(2222);
            collection.PublishAllMessages().ToPort(2223);

            // 2 default local queues + the 2 added here
            collection.AllEndpoints()
            .Length.ShouldBe(5);
        }
Пример #4
0
        public void add_transport()
        {
            var transport = Substitute.For <ITransport>();

            transport.Protocol.Returns("fake");

            var collection = new TransportCollection(new JasperOptions())
            {
                transport
            };

            collection.ShouldContain(transport);
        }
        protected override void RemoveCommandExecute(object obj)
        {
            if (!IsRemoveCommited())
            {
                return;
            }

            var transport = obj as TransportModel;

            if (TransportCollection != null && TransportCollection.Count > 0 && transport != null)
            {
                TransportCollection.Remove(transport);
            }
        }
Пример #6
0
        public JasperOptions(string assemblyName)
        {
            Transports = new TransportCollection(this);
            Services   = _applicationServices;

            establishApplicationAssembly(assemblyName);

            Advanced = new AdvancedSettings(ApplicationAssembly);

            _baseServices = new JasperServiceRegistry(this);

            _baseServices.AddSingleton(Advanced.CodeGeneration);

            deriveServiceName();
        }
 public override void ConvertDataFromDTO <T>(T item)
 {
     if (typeof(T) == typeof(LaborDetail.Item))
     {
         var model = (item as LaborDetail.Item);
         foreach (var vehicle in model.Vehicles)
         {
             var       _Vehicle = _directoryManager.VehiclesCollection.FirstOrDefault(x => x.Id == vehicle.Vehicle.Identity);
             var       _Driver  = _directoryManager.EmployeesCollection.FirstOrDefault(x => x.Id == vehicle.Driver.Identity);
             UnitModel _Unit    = null;
             if (vehicle.Unit != null)
             {
                 _Unit = _directoryManager.UnitsCollection.FirstOrDefault(x => x.Id == vehicle.Unit.Identity);
             }
             var transportModel = TransportModel.ConvertToModel(_Vehicle, _Unit, (vehicle.Speed.HasValue ? vehicle.Speed.Value : 0), vehicle.WorkWidth, _Driver);
             transportModel.LaborDetailVehicleId = vehicle.Identity;
             TransportCollection.Add(transportModel);
         }
     }
 }
Пример #8
0
        static void Initialize(NetCollection netCollection, TransportCollection transportCollection, Transform customPrefabs, string prefabName, string transportName)
        {
            Debug.Log("Traffic++: Initializing " + prefabName);

            NetInfo originalBusLine = netCollection.m_prefabs.Where(p => p.name == prefabName).FirstOrDefault();

            if (originalBusLine == null)
            {
                throw new KeyNotFoundException(prefabName + " was not found on " + netCollection.name);
            }

            GameObject instance = GameObject.Instantiate <GameObject>(originalBusLine.gameObject);;

            instance.name = prefabName;
            instance.transform.SetParent(customPrefabs);
            GameObject.Destroy(instance.GetComponent <TransportLineAI>());
            instance.AddComponent <BusTransportLineAI>();

            NetInfo busLine = instance.GetComponent <NetInfo>();

            busLine.m_prefabInitialized = false;
            busLine.m_netAI             = null;

            MethodInfo initMethod = typeof(NetCollection).GetMethod("InitializePrefabs", BindingFlags.Static | BindingFlags.NonPublic);

            Initializer.QueuePrioritizedLoadingAction((IEnumerator)initMethod.Invoke(null, new object[] { netCollection.name, new[] { busLine }, new string[] { prefabName } }));

            // transport
            TransportInfo originalTransportInfo = transportCollection.m_prefabs.Where(p => p.name.Contains(transportName)).FirstOrDefault();

            if (originalTransportInfo == null)
            {
                throw new KeyNotFoundException(transportName + " Transport Info not found on " + transportCollection.name);
            }

            originalTransportInfo.m_netInfo = busLine;
        }
Пример #9
0
        public void publish_mechanism_with_multiple_subscribers()
        {
            var collection = new TransportCollection(new JasperOptions());

            collection.Publish(x =>
            {
                x.MessagesFromNamespace("One");
                x.MessagesFromNamespace("Two");

                x.ToPort(3333);
                x.ToPort(4444);
            });

            var endpoint3333 = collection.TryGetEndpoint("tcp://localhost:3333".ToUri());
            var endpoint4444 = collection.TryGetEndpoint("tcp://localhost:4444".ToUri());

            endpoint3333.Subscriptions[0]
            .ShouldBe(new Subscription {
                Scope = RoutingScope.Namespace, Match = "One"
            });

            endpoint3333.Subscriptions[1]
            .ShouldBe(new Subscription {
                Scope = RoutingScope.Namespace, Match = "Two"
            });

            endpoint4444.Subscriptions[0]
            .ShouldBe(new Subscription {
                Scope = RoutingScope.Namespace, Match = "One"
            });

            endpoint4444.Subscriptions[1]
            .ShouldBe(new Subscription {
                Scope = RoutingScope.Namespace, Match = "Two"
            });
        }
Пример #10
0
 public TransportRuntime(IMessagingRoot root)
 {
     _root       = root;
     _transports = root.Options.Transports;
 }
 protected override void AddCommandExecute(object obj)
 {
     TransportCollection.Add(TransportModel.ConvertToModel(Vehicle, Unit, Speed.Value, Width, Driver));
 }
Пример #12
0
        /*
         * In here I'm changing the prefabs to have my classes. This way, every time the game instantiates
         * a prefab that I've changed, that object will run my code.
         * The prefabs aren't available at the moment of creation of this class, that's why I keep trying to
         * run it on update. I want to make sure I make the switch as soon as they exist to prevent the game
         * from instantianting objects without my code.
         */
        void TryReplacePrefabs()
        {
            NetCollection       beautificationNetCollection        = null;
            NetCollection       roadsNetCollection                 = null;
            NetCollection       publicTansportNetCollection        = null;
            VehicleCollection   garbageVehicleCollection           = null;
            VehicleCollection   policeVehicleCollection            = null;
            VehicleCollection   publicTansportVehicleCollection    = null;
            VehicleCollection   healthCareVehicleCollection        = null;
            VehicleCollection   fireDepartmentVehicleCollection    = null;
            VehicleCollection   industrialVehicleCollection        = null;
            TransportCollection publicTransportTransportCollection = null;
            ToolController      toolController = null;

            try
            {
                // NetCollections
                beautificationNetCollection = TryGetComponent <NetCollection>("Beautification");
                if (beautificationNetCollection == null)
                {
                    return;
                }

                roadsNetCollection = TryGetComponent <NetCollection>("Road");
                if (roadsNetCollection == null)
                {
                    return;
                }

                publicTansportNetCollection = TryGetComponent <NetCollection>("Public Transport");
                if (publicTansportNetCollection == null)
                {
                    return;
                }

                // VehicleCollections
                garbageVehicleCollection = TryGetComponent <VehicleCollection>("Garbage");
                if (garbageVehicleCollection == null)
                {
                    return;
                }

                policeVehicleCollection = TryGetComponent <VehicleCollection>("Police Department");
                if (policeVehicleCollection == null)
                {
                    return;
                }

                publicTansportVehicleCollection = TryGetComponent <VehicleCollection>("Public Transport");
                if (publicTansportVehicleCollection == null)
                {
                    return;
                }

                healthCareVehicleCollection = TryGetComponent <VehicleCollection>("Health Care");
                if (healthCareVehicleCollection == null)
                {
                    return;
                }

                fireDepartmentVehicleCollection = TryGetComponent <VehicleCollection>("Fire Department");
                if (fireDepartmentVehicleCollection == null)
                {
                    return;
                }

                industrialVehicleCollection = TryGetComponent <VehicleCollection>("Industrial");
                if (industrialVehicleCollection == null)
                {
                    return;
                }

                // Transports
                publicTransportTransportCollection = TryGetComponent <TransportCollection>("Public Transport");
                if (publicTransportTransportCollection == null)
                {
                    return;
                }

                // Tools
                toolController = TryGetComponent <ToolController>("Tool Controller");
                if (toolController == null)
                {
                    return;
                }
            }
            catch (Exception e)
            {
                Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " getting required components: " + e.Message + "\n" + e.StackTrace + "\n");
                return;
            }

            Debug.Log("Traffic++: Queueing prefabs for loading...");

            Singleton <LoadingManager> .instance.QueueLoadingAction(ActionWrapper(() =>
            {
                try
                {
                    // roads
                    ZonablePedestrianPathAI.Initialize(beautificationNetCollection, transform);
                    ZonablePedestrianBridgeAI.Initialize(beautificationNetCollection, transform);
                    LargeRoadWithBusLanesAI.Initialize(roadsNetCollection, transform);
                    LargeRoadWithBusLanesBridgeAI.Initialize(roadsNetCollection, transform);

                    if ((CSLTraffic.Options & OptionsManager.ModOptions.GhostMode) != OptionsManager.ModOptions.GhostMode)
                    {
                        // Transports
                        BusTransportLineAI.Initialize(publicTansportNetCollection, publicTansportVehicleCollection, publicTransportTransportCollection, transform);

                        // vehicles
                        CustomAmbulanceAI.Initialize(healthCareVehicleCollection, transform);
                        CustomBusAI.Initialize(publicTansportVehicleCollection, transform);
                        CustomCargoTruckAI.Initialize(industrialVehicleCollection, transform);
                        CustomFireTruckAI.Initialize(fireDepartmentVehicleCollection, transform);
                        CustomGarbageTruckAI.Initialize(garbageVehicleCollection, transform);
                        CustomHearseAI.Initialize(healthCareVehicleCollection, transform);
                        CustomPoliceCarAI.Initialize(policeVehicleCollection, transform);

                        //Tools
                        CustomTransportTool.Initialize(toolController);
                    }

                    // Localization
                    UpdateLocalization();

                    AddQueuedActionsToLoadingQueue();
                }
                catch (KeyNotFoundException knf)
                {
                    Debug.Log("Traffic++: Error initializing a prefab: " + knf.Message + "\n" + knf.StackTrace + "\n");
                }
                catch (Exception e)
                {
                    Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " initializing prefabs: " + e.Message + "\n" + e.StackTrace + "\n");
                }
            }));

            m_initialized = true;

            Debug.Log("Traffic++: Prefabs queued for loading.");
        }
Пример #13
0
        public static void Initialize(NetCollection collection, VehicleCollection vehicleCollection, TransportCollection transportCollection, Transform customPrefabs)
        {
            if (sm_initialized)
            {
                return;
            }

            Initialize(collection, transportCollection, customPrefabs, "Bus Line", "Bus");
            //Initialize(collection, transportCollection, customPrefabs, "Metro Line", "Metro");


            sm_initialized = true;
        }