private void onInitialize(EventArgs args) { Config = ConfigFile.Read(); ChatHandler.Config = Config; Commands.ChatCommands.Add(new TShockAPI.Command(Permissions.Use, doDiscord, "bridge", "discord")); Client = new BridgeClient(this); // Install the command service Client.UsingCommands(x => { x.PrefixChar = Config.BotPrefix; x.HelpMode = HelpMode.Private; x.CustomPrefixHandler = m => { // Do not require a prefix for private message commands (not counting bots, naturally) if (!m.User.IsBot && m.Channel.IsPrivate && m.Channel == m.User.PrivateChannel) { return(0); } else { return(-1); } }; }); initDiscordCommands(); Logins = new LoginManager(Client); }
private ClientLauncher( ClientService clientService, JavaClientLauncher javaClientLauncher, REEFFileNames reefFileNames, IConfigurationSerializer configurationSerializer, DriverClientParameters driverRuntimeProto, IRuntimeProtoProvider runtimeProtoProvider) { _clientService = clientService; _javaClientLauncher = javaClientLauncher; _reefFileNames = reefFileNames; _configurationSerializer = configurationSerializer; _driverClientConfiguration = driverRuntimeProto.Proto; runtimeProtoProvider.SetParameters(_driverClientConfiguration); _grpcServer = new Server { Services = { BridgeClient.BindService(clientService) }, Ports = { new ServerPort("localhost", 0, ServerCredentials.Insecure) } }; _grpcServer.Start(); Log.Log(Level.Info, "Server port any {0}", _grpcServer.Ports.Any()); foreach (var serverPort in _grpcServer.Ports) { Log.Log(Level.Info, "Server port {0}", serverPort.BoundPort); _grpcServerPort = serverPort.BoundPort; } }
public static async void Main() { // resolve a static proxy var studentService = BridgeClient.Resolve <IStudentService>(); // call server just by calling the function var students = await studentService.GetAllStudents(); // use the results directly foreach (var student in students) { var name = student.Name; var age = DateTime.Now.Year - student.DateOfBirth.Year; Console.WriteLine($"{name} is {age} years old"); } try { var result = await studentService.CatchMeIfYouCan(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void SetupSensors(GameObject agent, string sensors, BridgeClient bridgeClient) { var available = Simulator.Web.Config.Sensors.ToDictionary(sensor => sensor.Name); var prefabs = RuntimeSettings.Instance.SensorPrefabs.ToDictionary(sensor => GetSensorType(sensor)); var parents = new Dictionary <string, GameObject>() { { string.Empty, agent }, }; var requested = JSONNode.Parse(sensors).Children.ToList(); while (requested.Count != 0) { int requestedCount = requested.Count; foreach (var parent in parents.Keys.ToArray()) { var parentObject = parents[parent]; for (int i = 0; i < requested.Count; i++) { var item = requested[i]; if (item["parent"].Value == parent) { var name = item["name"].Value; var type = item["type"].Value; SensorConfig config; if (!available.TryGetValue(type, out config)) { throw new Exception($"Unknown sensor type {type} for {gameObject.name} vehicle"); } var sensor = CreateSensor(agent, parentObject, prefabs[type].gameObject, item); sensor.GetComponent <SensorBase>().Name = name; sensor.name = name; SIM.LogSimulation(SIM.Simulation.SensorStart, name); if (bridgeClient != null) { sensor.GetComponent <SensorBase>().OnBridgeSetup(bridgeClient.Bridge); } parents.Add(name, sensor); requested.RemoveAt(i); i--; } } } if (requestedCount == requested.Count) { throw new Exception($"Failed to create {requested.Count} sensor(s), cannot determine parent-child relationship"); } } }
public static void Run() { QUnit.Module("Service Registration Tests"); //QUnit.Test("Cable.Resolve throws exception if interface not reflectable", assert => //{ // try // { // var service = Client.Resolve<INonReflectable>(); // } // catch (ArgumentException ex) // { // assert.Equal(ex.Message, "The interface does not have any methods, if there are any methods then annotate the interface with the [Reflectable] attribute"); // } //}); //QUnit.Test("Cable.Resolve throws an exception if type is not an interface", assert => //{ // try // { // var service = Client.Resolve<int>(); // } // catch (ArgumentException ex) // { // var msg = ex.Message; // assert.Equal(msg, "Type Int32 must be an interface"); // } //}); //QUnit.Test("Cable.Resolve throws exception if reflectable interface does not have methods", assert => //{ // try // { // var service = Client.Resolve<IReflectable>(); // } // catch (ArgumentException ex) // { // var msg = ex.Message; // assert.Equal(msg, "The interface does not have any methods, if there are any methods then annotate the interface with the [Reflectable] attribute"); // } //}); QUnit.Test("Cable.Resolve doesn't throw exception on reflectable interface where all methods have return type of Task", assert => { var service = BridgeClient.Resolve <IService>(); assert.Equal(true, Script.IsDefined(service)); }); }
public GameObject SpawnAgent(AgentConfig config) { var go = Instantiate(config.Prefab); go.name = config.Name; var agentController = go.GetComponent <AgentController>(); agentController.Config = config; SIM.LogSimulation(SIM.Simulation.VehicleStart, config.Name); ActiveAgents.Add(go); agentController.GTID = ++SimulatorManager.Instance.GTIDs; BridgeClient bridgeClient = null; if (config.Bridge != null) { bridgeClient = go.AddComponent <BridgeClient>(); bridgeClient.Init(config.Bridge); if (config.Connection != null) { var split = config.Connection.Split(':'); if (split.Length != 2) { throw new Exception("Incorrect bridge connection string, expected HOSTNAME:PORT"); } bridgeClient.Connect(split[0], int.Parse(split[1])); } } SIM.LogSimulation(SIM.Simulation.BridgeTypeStart, config.Bridge != null ? config.Bridge.Name : "None"); if (!string.IsNullOrEmpty(config.Sensors)) { SetupSensors(go, config.Sensors, bridgeClient); } agentController.AgentSensors.AddRange(agentController.GetComponentsInChildren <SensorBase>(true)); go.transform.position = config.Position; go.transform.rotation = config.Rotation; agentController.Init(); return(go); }
public GameObject SpawnAgent(AgentConfig config) { var go = Instantiate(config.Prefab, transform); go.name = config.Name; var agentController = go.GetComponent <AgentController>(); agentController.SensorsChanged += AgentControllerOnSensorsChanged; agentController.Config = config; agentController.Config.AgentGO = go; SIM.LogSimulation(SIM.Simulation.VehicleStart, config.Name); ActiveAgents.Add(agentController.Config); agentController.GTID = ++SimulatorManager.Instance.GTIDs; agentController.Config.GTID = agentController.GTID; BridgeClient bridgeClient = null; if (config.Bridge != null) { bridgeClient = go.AddComponent <BridgeClient>(); bridgeClient.Init(config.Bridge); if (config.Connection != null) { var split = config.Connection.Split(':'); if (split.Length != 2) { throw new Exception("Incorrect bridge connection string, expected HOSTNAME:PORT"); } bridgeClient.Connect(split[0], int.Parse(split[1])); } } SIM.LogSimulation(SIM.Simulation.BridgeTypeStart, config.Bridge != null ? config.Bridge.Name : "None"); var sensorsController = go.AddComponent <SensorsController>(); agentController.AgentSensorsController = sensorsController; sensorsController.SetupSensors(config.Sensors); //Add required components for distributing rigidbody from master to clients var network = Loader.Instance.Network; if (network.IsClusterSimulation) { HierarchyUtilities.ChangeToUniqueName(go); if (network.IsClient) { //Disable controller and dynamics on clients so it will not interfere mocked components agentController.enabled = false; var vehicleDynamics = agentController.GetComponent <IVehicleDynamics>() as MonoBehaviour; if (vehicleDynamics != null) { vehicleDynamics.enabled = false; } } //Change the simulation type only if it's not set in the prefab var distributedRigidbody = go.GetComponent <DistributedRigidbody>(); if (distributedRigidbody == null) { distributedRigidbody = go.AddComponent <DistributedRigidbody>(); distributedRigidbody.SimulationType = DistributedRigidbody.MockingSimulationType.ExtrapolateVelocities; } //Add the rest required components for cluster simulation ClusterSimulationUtilities.AddDistributedComponents(go); } go.transform.position = config.Position; go.transform.rotation = config.Rotation; agentController.Init(); #if UNITY_EDITOR // TODO remove hack for editor opaque with alpha clipping 2019.3.3 Array.ForEach(go.GetComponentsInChildren <Renderer>(), renderer => { foreach (var m in renderer.materials) { m.shader = Shader.Find(m.shader.name); } }); Array.ForEach(go.GetComponentsInChildren <DecalProjector>(), decal => { decal.material.shader = Shader.Find(decal.material.shader.name); }); #endif return(go); }
static void Main(string[] args) { bool exitLoop = false; while (!exitLoop) { Console.WriteLine(); Console.WriteLine("Please type the number of type of design patterns to veiw"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Creational"); Console.WriteLine("2 - Structural"); Console.WriteLine("3 - Behaivoral"); ConsoleKeyInfo keyInfo = Console.ReadKey(); Console.WriteLine(); switch (keyInfo.KeyChar.ToString()) { case "0": exitLoop = true; break; case "1": while (!exitLoop) { Console.WriteLine("Please select Creational Pattern to demo:"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Simple Factory"); Console.WriteLine("2 - Factory Method"); Console.WriteLine("3 - Abstract Factory"); Console.WriteLine("4 - Builder"); Console.WriteLine("5 - Fluent Interface"); Console.WriteLine("6 - Prototype"); Console.WriteLine("7 - Singleton"); keyInfo = Console.ReadKey(); Console.WriteLine(); switch (keyInfo.KeyChar.ToString()) { case "0": exitLoop = true; break; case "1": SimpleFactoryClient simpleFactoryClient = new SimpleFactoryClient(); simpleFactoryClient.PrintSimpleFactory(); break; case "2": FactoryMethodClient factoryMethodClient = new FactoryMethodClient(); factoryMethodClient.PrintFactoryMethod(); break; case "3": AbstractFactoryClient abstractFactoryClient = new AbstractFactoryClient(); abstractFactoryClient.PrintAbstractFactory(); break; case "4": BuilderClient builderClient = new BuilderClient(); builderClient.PrintBuilder(); break; case "5": FluentInterfaceClient fluentInterfaceClient = new FluentInterfaceClient(); fluentInterfaceClient.PrintFluentInterface(); break; case "6": PrototypeClient prototypeClient = new PrototypeClient(); prototypeClient.PrintPrototype(); break; case "7": SingletonClient singletonClient = new SingletonClient(); singletonClient.PrintSingleton(); break; default: Console.WriteLine("Selection must be 0-7"); break; } } exitLoop = false; break; case "2": while (!exitLoop) { Console.WriteLine("Please select Structural Pattern to demo:"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Adapter"); Console.WriteLine("2 - Facade"); Console.WriteLine("3 - Decorator"); Console.WriteLine("4 - Bridge"); Console.WriteLine("5 - Composite"); Console.WriteLine("6 - Proxy"); Console.WriteLine("7 - Flyweight"); keyInfo = Console.ReadKey(); Console.WriteLine(); switch (keyInfo.KeyChar.ToString()) { case "0": exitLoop = true; break; case "1": AdapterClient adapterClient = new AdapterClient(); adapterClient.PrintAdapter(); break; case "2": FacadeClient facadeClient = new FacadeClient(); facadeClient.PrintFacade(); break; case "3": DecoratorClient decoratorClient = new DecoratorClient(); decoratorClient.PrintDecorator(); break; case "4": BridgeClient bridgeClient = new BridgeClient(); bridgeClient.PrintBridge(); break; case "5": CompositeClient compositeClient = new CompositeClient(); compositeClient.PrintComposite(); break; case "6": ProxyClient proxyClient = new ProxyClient(); proxyClient.PrintProxy(); break; case "7": FlyweightClient flyweightClient = new FlyweightClient(); flyweightClient.PrintFlyweight(); break; default: Console.WriteLine("Selection must be 0-7"); break; } } exitLoop = false; break; case "3": while (!exitLoop) { Console.WriteLine("Please select Behaivoral Pattern to demo:"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Iterator"); Console.WriteLine("2 - Observer"); Console.WriteLine("3 - Chain Of Responsibility"); Console.WriteLine("4 - State"); Console.WriteLine("5 - Template"); Console.WriteLine("6 - Command"); Console.WriteLine("7 - Visitor"); Console.WriteLine("8 - Strategy"); Console.WriteLine("9 - Interpreter"); Console.WriteLine("10 - Mediator"); Console.WriteLine("11 - Memento"); string entered = Console.ReadLine(); Console.WriteLine(); switch (entered) { case "0": exitLoop = true; break; case "1": IteratorClient iteratorClient = new IteratorClient(); iteratorClient.PrintIterator(); break; case "2": ObserverClient observerClient = new ObserverClient(); observerClient.PrintObserver(); break; case "3": ChainOfResponsibilityClient chainOfResponsibilityClient = new ChainOfResponsibilityClient(); chainOfResponsibilityClient.PrintChainOfResponsibility(); break; case "4": StateClient stateClient = new StateClient(); stateClient.PrintState(); break; case "5": TemplateClient templateClient = new TemplateClient(); templateClient.PrintTemplate(); break; case "6": CommandClient commandClient = new CommandClient(); commandClient.PrintCommand(); break; case "7": VisitorClient visitorClient = new VisitorClient(); visitorClient.PrintVisitor(); break; case "8": StrategyClient strategyClient = new StrategyClient(); strategyClient.PrintStrategy(); break; case "9": InterpreterClient interpreterClient = new InterpreterClient(); interpreterClient.PrintInterpreter(); break; case "10": MediatorClient mediatorClient = new MediatorClient(); mediatorClient.PrintMediator(); break; case "11": MementoClient mementoClient = new MementoClient(); mementoClient.PrintMemento(); break; default: Console.WriteLine("Selection must be 0-11"); break; } } exitLoop = false; break; default: Console.WriteLine("Must enter number 0 -3"); break; } } Console.WriteLine("End of Design Patterns examples"); Console.WriteLine("Type any key to exit"); Console.ReadKey(); }
public GameObject SpawnAgent(AgentConfig config) { var go = Instantiate(config.Prefab, transform); go.name = config.Name; // set it inactive until we can be sure setting up sensors etc worked without exceptions and it AgentController was initialized go.SetActive(false); var agentController = go.GetComponent <AgentController>(); agentController.Config = config; agentController.Config.AgentGO = go; var lane = go.AddComponent <VehicleLane>(); var baseLink = go.GetComponentInChildren <BaseLink>(); if (baseLink == null) { baseLink = new GameObject("BaseLink").AddComponent <BaseLink>(); baseLink.transform.SetParent(go.transform, false); } ActiveAgents.Add(agentController.Config); agentController.GTID = ++SimulatorManager.Instance.GTIDs; agentController.Config.GTID = agentController.GTID; BridgeClient bridgeClient = null; if (config.Bridge != null) { bridgeClient = go.AddComponent <BridgeClient>(); bridgeClient.Init(config.Bridge); if (!String.IsNullOrEmpty(config.Connection)) { bridgeClient.Connect(config.Connection); } } var sensorsController = go.AddComponent <SensorsController>(); agentController.AgentSensorsController = sensorsController; //Add required components for distributing rigidbody from master to clients var network = Loader.Instance.Network; if (network.IsClusterSimulation) { HierarchyUtilities.ChangeToUniqueName(go); if (network.IsClient) { //Disable controller and dynamics on clients so it will not interfere mocked components agentController.enabled = false; var vehicleDynamics = agentController.GetComponent <IVehicleDynamics>() as MonoBehaviour; if (vehicleDynamics != null) { vehicleDynamics.enabled = false; } } //Change the simulation type only if it's not set in the prefab var distributedRigidbody = go.GetComponent <DistributedRigidbody>(); if (distributedRigidbody == null) { distributedRigidbody = go.AddComponent <DistributedRigidbody>(); distributedRigidbody.SimulationType = DistributedRigidbody.MockingSimulationType.ExtrapolateVelocities; } //Add the rest required components for cluster simulation ClusterSimulationUtilities.AddDistributedComponents(go); } go.transform.position = config.Position; go.transform.rotation = config.Rotation; sensorsController.SetupSensors(config.Sensors); agentController.Init(); go.SetActive(true); return(go); }
public GameObject SpawnAgent(AgentConfig config) { var go = Instantiate(config.Prefab, transform); go.name = config.Name; // set it inactive until we can be sure setting up sensors etc worked without exceptions and it AgentController was initialized go.SetActive(false); var controller = go.GetComponent <IAgentController>(); if (controller == null) { Debug.LogWarning($"{nameof(IAgentController)} implementation not found on the {config.Name} vehicle. This vehicle can't be used as an ego vehicle."); } else { controller.Config = config; controller.Config.AgentGO = go; ActiveAgents.Add(controller.Config); controller.GTID = ++SimulatorManager.Instance.GTIDs; controller.Config.GTID = controller.GTID; } var lane = go.AddComponent <VehicleLane>(); var baseLink = go.GetComponentInChildren <BaseLink>(); if (baseLink == null) { baseLink = new GameObject("BaseLink").AddComponent <BaseLink>(); baseLink.transform.SetParent(go.transform, false); } var sensorsController = go.GetComponent <ISensorsController>() ?? go.AddComponent <SensorsController>(); if (controller != null) { controller.AgentSensorsController = sensorsController; } //Add required components for distributing rigidbody from master to clients var network = Loader.Instance.Network; if (network.IsClusterSimulation) { HierarchyUtilities.ChangeToUniqueName(go); //Add the rest required components for cluster simulation ClusterSimulationUtilities.AddDistributedComponents(go); if (network.IsClient) { controller?.DisableControl(); } } BridgeClient bridgeClient = null; if (config.BridgeData != null) { var dir = Path.Combine(Simulator.Web.Config.PersistentDataPath, "Bridges"); var vfs = VfsEntry.makeRoot(dir); Simulator.Web.Config.CheckDir(vfs.GetChild(config.BridgeData.AssetGuid), Simulator.Web.Config.LoadBridgePlugin); bridgeClient = go.AddComponent <BridgeClient>(); config.Bridge = BridgePlugins.Get(config.BridgeData.Type); bridgeClient.Init(config.Bridge); if (!String.IsNullOrEmpty(config.Connection)) { bridgeClient.Connect(config.Connection); } } go.transform.position = config.Position; go.transform.rotation = config.Rotation; sensorsController.SetupSensors(config.Sensors); controller?.Init(); if (SimulatorManager.Instance.IsAPI) { SimulatorManager.Instance.EnvironmentEffectsManager.InitRainVFX(go.transform); } go.SetActive(true); return(go); }
public MessageHub(BridgeClient client) { this.client = client; }
public void AddPublisher(BridgeClient publisher) { UnityEngine.Debug.Log("AddPublisher in CyberBridge is not implemented."); return; }
static void Main(string[] args) { //FactoryMethod var shipFactory = new ShipFactory(); var fabricMethodClient = new FabricMethodClient(shipFactory); fabricMethodClient.Deliver(); var cargoFactory = new CargoFactory(); fabricMethodClient.SetTransportFactory(cargoFactory); fabricMethodClient.Deliver(); //AbstractFactory var humanFactory = new HumanUnitFactory(); var abstractFactoryClient = new AbstractFactoryClient(humanFactory); abstractFactoryClient.DoSquad(); var orkFactory = new OrkUnitFactory(); abstractFactoryClient.SetUnitFactory(orkFactory); abstractFactoryClient.DoSquad(); //Builder var opossumBuilder = new OpossumBuilder(); var director = new Director(opossumBuilder); var sectionalUnit = director.GetUnit(); sectionalUnit.DoStuff(); var baldBuilder = new BaldBuilder(); director.SetBuilder(baldBuilder); sectionalUnit = director.GetUnit(); sectionalUnit.DoStuff(); //Prototype var prototype = new PrototypeSample(2); prototype.SetProperty(1.0f); prototype.DoStuff(); var clone = (PrototypeSample)prototype.Clone(); clone.DoStuff(); //Singleton Singleton.Instance.SingletonScream(); //Adapter var adapterClient = new AdapterClient(); adapterClient.DoStuff(); //Bridge var bridgeClient = new BridgeClient(); bridgeClient.DoStuff(); //Composite var compositeClient = new CompositeClient(); compositeClient.DoStuff(); //Decorator var decoratorClient = new DecoratorClient(); decoratorClient.DoStuff(); //Facade var facadeClient = new Facade(); facadeClient.DoStuff(); //Flyweight var flyweightClient = new FlyweightClient(); flyweightClient.DoStuff(); //Proxy var proxyClient = new ProxyClient(); proxyClient.DoStuff(); //CoR var corClient = new CoRClient(); corClient.DoStuff(); //Command var commandClient = new CommandClient(); commandClient.DoStuff(); //Iterator var iteratorClient = new IteratorClient(); iteratorClient.DoStuff(); //Mediator var mediatorClient = new MediatorClient(); mediatorClient.DoStuff(); //Memento var mementoClient = new MementoClient(); mementoClient.DoStuff(); //Observer var observerClient = new ObserverClient(); observerClient.DoStuff(); //Strategy var strategyClient = new StrategyClient(); strategyClient.DoStuff(); //TemplateMethod var templateMethodClient = new TemplateMethodClient(); templateMethodClient.DoStuff(); //Visitor var visitorClient = new VisitorClient(); visitorClient.DoStuff(); }
public static async void Main() { var Server = BridgeClient.Resolve <IService>(); Log(Server); QUnit.Module("Nancy Client Tests"); QUnit.Test("Client is working", assert => assert.Equal(true, true)); QUnit.Test("Client.Resolve<IService>() is defined", assert => assert.Equal(Script.IsDefined(Server), true)); var stringResult = await Server.String("hello"); QUnit.Test("IService.String()", assert => assert.Equal(stringResult, true)); var now = new DateTime(2016, 12, 19, 20, 30, 0); var objectsResult = await Server.StringIntCharDateTime("hello there", 5, 'a', now); QUnit.Test("IService.StringIntCharDateTime()", assert => { assert.Equal(objectsResult.Length, 4); assert.Equal(objectsResult[0], "hello there"); assert.Equal(objectsResult[1], 5); assert.Equal(objectsResult[2], 'a'); var dateFromObjects = (DateTime)objectsResult[3]; DatesEqual(assert, dateFromObjects, now); }); var wrappedDateTime = new WrappedDateTime { Value = new DateTime(2017, 10, 12, 20, 30, 0) }; var echoedWrappedDateTime = await Server.EchoWrappedDateTime(wrappedDateTime); QUnit.Test("IService.EchoWrappedDateTime()", assert => { DatesEqual(assert, echoedWrappedDateTime.Value, wrappedDateTime.Value); }); int int32 = 20; long int64 = 35L; double Double = 2.0; decimal Decimal = 2.3454m; var numericResults = await Server.NumericPrimitives ( int32, int64, Double, Decimal ); QUnit.Test("IService.NumericPrimitives()", assert => { assert.Equal(numericResults.Length, 4); assert.Equal(numericResults[0].As <int>() == int32, true); assert.Equal(numericResults[1].As <long>() == int64, true); assert.Equal(numericResults[2].As <double>() == Double, true); assert.Equal(numericResults[3].As <decimal>() == Decimal, true); }); int[] arrayOfInts = { 1, 2, 3 }; var resultArrayOfInts = await Server.ArrayOfInts(arrayOfInts); QUnit.Test("IService.ArrayofInts()", assert => { for (var i = 0; i < arrayOfInts.Length; i++) { assert.Equal(arrayOfInts[i], resultArrayOfInts[i]); } }); string[] arrOfStringsReturningInts = { "1", "two", "three" }; var intArrayResult = await Server.ArrayOfStringsReturningInts(arrOfStringsReturningInts); QUnit.Test("IService.ArrayOfStringsReturningInts()", assert => { assert.Equal(intArrayResult[0], 1); assert.Equal(intArrayResult[1], 3); assert.Equal(intArrayResult[2], 5); }); int[] ints1 = { 1, 2, 3 }; string[] strings1 = { "", "hello" }; char[] chars = { 'a', 'b', 'c', 'd' }; var lengthsOfArrays = await Server.ArraysAsArguments(ints1, strings1, chars); QUnit.Test("IService.ArraysAsArguments()", assert => { assert.Equal(lengthsOfArrays[0], 3); assert.Equal(lengthsOfArrays[1], 2); assert.Equal(lengthsOfArrays[2], 4); }); int[] generinInts = { 1, 2, 3, 4, 5 }; var listOfGenericInts = generinInts.Select(x => new Generic <int> { Value = x }).ToList(); var listResult = await Server.MapGenericInsToListOfInts(listOfGenericInts); QUnit.Test("IService.MapGenericInsToListOfInts()", assert => { assert.Equal(listResult.Sum(), 15); }); var inputDouble1 = 2.523; var inputDouble2 = 5.342; var outputDouble1 = await Server.EchoDouble(inputDouble1); var outputDouble2 = await Server.EchoDouble(inputDouble2); QUnit.Test("IService.EchoDouble()", assert => { assert.Equal(inputDouble1, outputDouble1); assert.Equal(inputDouble2, outputDouble2); }); var echoedEnum = await Server.EchoEnumAsync(ExampleEnum.One); QUnit.Test("IService.EchoEnumAsync()", assert => { Script.Call("console.log", echoedEnum); assert.Equal(echoedEnum == ExampleEnum.One, true); }); var wrappedDouble1 = new WrappedDouble { Value = 4.45 }; var wrappedDouble2 = new WrappedDouble { Value = 2.0 }; var echoedWrappedDouble1 = await Server.EchoWrappedDouble(wrappedDouble1); var echoedWrappedDouble2 = await Server.EchoWrappedDouble(wrappedDouble2); QUnit.Test("IService.EchoWrappedDouble()", assert => { assert.Equal(wrappedDouble1.Value, echoedWrappedDouble1.Value); assert.Equal(wrappedDouble2.Value, echoedWrappedDouble2.Value); }); var resultIntArrayNoArgs = await Server.NoArgumentsReturningIntArray(); QUnit.Test("IService.NoArgumentsReturningIntArray()", assert => { assert.Equal(resultIntArrayNoArgs[0], 1); assert.Equal(resultIntArrayNoArgs[1], 2); assert.Equal(resultIntArrayNoArgs[2], 3); assert.Equal(resultIntArrayNoArgs[3], 4); assert.Equal(resultIntArrayNoArgs[4], 5); }); var resultStringNoArgs = await Server.NoArgumentsReturningString(); QUnit.Test("IService.NoArgumentsReturningString()", assert => { assert.Equal(resultStringNoArgs, "Result"); }); QUnit.Test("IService.SyncAdd()", assert => { assert.Equal(Server.SyncAdd(1, 1), 2); assert.Equal(Server.SyncAdd(5, 6), 11); assert.Equal(Server.SyncAdd(2, 3), 5); }); QUnit.Test("IService.NowPlusHoursSync()", assert => { var result = Server.NowPlusHoursSync(5); assert.Equal(result.Hour == (DateTime.Now.AddHours(5).Hour), true); }); var resultSumOfMatrixOfInt = await Server.SumOfMatrixOfInt(new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } }); QUnit.Test("IService.SumOfMatrixOfInt()", assert => { assert.Equal(resultSumOfMatrixOfInt, 45); }); int[][] matrix = { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } }; string[][] stringMatrix = { new string[] { "Hello", "its", "Me" } }; var multipleMatrixElementCount = await Server.MatrixMultipleArgs(matrix, stringMatrix); QUnit.Test("IService.MatrixMultipleArgs()", assert => { assert.Equal(multipleMatrixElementCount, 12); }); var listOfInts = new List <int>(); listOfInts.Add(42); listOfInts.Add(55); var echoedListOfInts = await Server.EchoListOfInt(listOfInts); QUnit.Test("IService.EchoListOfInt()", assert => { assert.Equal(echoedListOfInts[0], listOfInts[0]); assert.Equal(echoedListOfInts[1], listOfInts[1]); }); var longMatrix = new long[][] { new long[] { 1L, 2L, 3L, 4L, 5L } }; var longMatrixSum = await Server.SumMatrixOfLong(longMatrix); QUnit.Test("IService.SumMatrixOfLong()", assert => assert.Equal(longMatrixSum == 15L, true)); var date = new DateTime(1996, 11, 13, 0, 0, 0, 20); var person = new Person { Age = 20, Name = "Mike", Money = 22.399m, IsMarried = false, DateOfBirth = date }; QUnit.Test("IService.EchoPerson()", assert => { var syncEchoedPerson = Server.EchoPerson(person); assert.Equal(syncEchoedPerson.Name, "Mike"); assert.Equal(syncEchoedPerson.Age, 20); assert.Equal(syncEchoedPerson.Money == 22.399m, true); DatesEqual(assert, date, syncEchoedPerson.DateOfBirth); assert.Equal(syncEchoedPerson.IsMarried, false); }); var personTask = await Server.EchoTaskPerson(person); QUnit.Test("IService.EchoTaskPerson()", assert => { assert.Equal(personTask.Name, "Mike"); assert.Equal(personTask.Age, 20); assert.Equal(personTask.Money == 22.399m, true); DatesEqual(assert, date, personTask.DateOfBirth); assert.Equal(personTask.IsMarried, false); }); var myAge = await Server.HowOld(person); QUnit.Test("IService.HowOld()", assert => assert.Equal(myAge, 20)); var numList = new List <int>(); numList.AddRange(new int[] { 1, 2, 3, 4, 5 }); var sumArray = await Server.IEnumerableSum(new int[] { 1, 2, 3, 4, 5 }); var sumList = await Server.IEnumerableSum(numList); QUnit.Test("IService.IEnumerableSum()", assert => { assert.Equal(sumArray, 15); assert.Equal(sumList, 15); }); var genericInt = await Server.GenericInt(new Generic <int> { Value = 5 }); QUnit.Test("IService.GenericInt()", assert => { assert.Equal(genericInt, 5); }); var simpleGeneric = await Server.GenericSimpleNested(new Generic <SimpleNested> { Value = new SimpleNested { Int = 10, String = "MyStr", Long = 20L, Double = 2.5, Decimal = 3.5m } }); QUnit.Test("IService.GenericSimpleNested()", assert => { assert.Equal(simpleGeneric.Int, 10); assert.Equal(simpleGeneric.String, "MyStr"); assert.Equal(simpleGeneric.Long == 20L, true); assert.Equal(simpleGeneric.Double, 2.5); assert.Equal(simpleGeneric.Decimal == 3.5m, true); }); var genericPersonArg = new Generic <Person> { Value = person }; var genericPerson = await Server.EchoGenericPerson(genericPersonArg); QUnit.Test("IService.EchoGenericPerson()", assert => { assert.Equal(genericPerson.Value.Name, "Mike"); assert.Equal(genericPerson.Value.Age, 20); assert.Equal(genericPerson.Value.Money == 22.399m, true); DatesEqual(assert, date, genericPerson.Value.DateOfBirth); assert.Equal(genericPerson.Value.IsMarried, false); }); var genericFstSnd = new DoubleGeneric <int, string> { First = 10, Second = "Zaid" }; var resultFirst = await Server.ReturnFirst(genericFstSnd); var resultSecond = await Server.ReturnSecond(genericFstSnd); QUnit.Test("IService.ReturnFirst() and IService.ReturnSecond()", assert => { assert.Equal(resultFirst, 10); assert.Equal(resultSecond, "Zaid"); }); var nullResult = await Server.EchoNullString(); QUnit.Test("IService.EchoNullString()", assert => assert.Equal(nullResult, null)); }
public HomeController(BridgeClient bridgeClient) { // TODO: Find better way to initialize singleton this.bridgeClient = bridgeClient; }
public GameObject SpawnAgent(AgentConfig config) { var go = Instantiate(config.Prefab, transform); go.name = config.Name; var agentController = go.GetComponent <AgentController>(); agentController.SensorsChanged += AgentControllerOnSensorsChanged; agentController.Config = config; SIM.LogSimulation(SIM.Simulation.VehicleStart, config.Name); ActiveAgents.Add(go); agentController.GTID = ++SimulatorManager.Instance.GTIDs; BridgeClient bridgeClient = null; if (config.Bridge != null) { bridgeClient = go.AddComponent <BridgeClient>(); bridgeClient.Init(config.Bridge); if (config.Connection != null) { var split = config.Connection.Split(':'); if (split.Length != 2) { throw new Exception("Incorrect bridge connection string, expected HOSTNAME:PORT"); } bridgeClient.Connect(split[0], int.Parse(split[1])); } } SIM.LogSimulation(SIM.Simulation.BridgeTypeStart, config.Bridge != null ? config.Bridge.Name : "None"); var sensorsController = go.AddComponent <SensorsController>(); agentController.AgentSensorsController = sensorsController; sensorsController.SetupSensors(config.Sensors); //Add required components for distributing rigidbody from master to clients var network = SimulatorManager.Instance.Network; if (network.IsMaster) { if (go.GetComponent <DistributedObject>() == null) { go.AddComponent <DistributedObject>(); } var distributedRigidbody = go.GetComponent <DistributedRigidbody>(); if (distributedRigidbody == null) { distributedRigidbody = go.AddComponent <DistributedRigidbody>(); } distributedRigidbody.SimulationType = MockedRigidbody.MockingSimulationType.ExtrapolateVelocities; } else if (network.IsClient) { //Disable controller and dynamics on clients so it will not interfere mocked components agentController.enabled = false; var vehicleDynamics = agentController.GetComponent <VehicleDynamics>(); if (vehicleDynamics != null) { vehicleDynamics.enabled = false; } //Add mocked components if (go.GetComponent <MockedObject>() == null) { go.AddComponent <MockedObject>(); } var mockedRigidbody = go.GetComponent <MockedRigidbody>(); if (mockedRigidbody == null) { mockedRigidbody = go.AddComponent <MockedRigidbody>(); } mockedRigidbody.SimulationType = MockedRigidbody.MockingSimulationType.ExtrapolateVelocities; } go.transform.position = config.Position; go.transform.rotation = config.Rotation; agentController.Init(); return(go); }