//加载模块和子UI的Button (子UI的Button生成时隐藏) void LoadModuleButton(List <Module> data) { for (int i = 0; i < data.Count; i++)// SaveInfo temp in data) { GameObject button = Instantiate(ProductButton); //button.transform.SetParent(DataMsg.parent[0]); button.transform.parent = DataMsg.parent[0]; button.transform.localScale = Vector3.one; ModuleManager module = button.AddComponent <ModuleManager>(); // 为每个按钮添加脚本 module.initModule(data[i]); // 初始化 GameObjectPool.Add(button); // 保存后用于切换panel时删除实例物体 for (int j = 0; j < data[i].SubList.Count; j++) { GameObject subbutton = Instantiate(ProductButton1);//ProductButton: Button 的预制体 subbutton.SetActive(false); subbutton.transform.SetParent(DataMsg.parent[0]); subbutton.transform.localScale = Vector3.one; SubManager sub = subbutton.AddComponent <SubManager>(); sub.initModule(data[i].SubList[j]); module.SubObj.Add(subbutton); GameObjectPool.Add(subbutton); // 保存后用于切换panel时删除实例物体 } } DataMsg.IsShowFinish = true; // ChackActiveCount(image1); // 是否显示向下箭头 }
private static async Task <int> RunMainAsync() { try { var servicecollection = new ServiceCollection(); SubManager.Parse(servicecollection, typeof(AccountCoreHandler).Assembly); //注册handle servicecollection.AddSingleton <IClientFactory, ClientFactory>(); //注册Client获取方法 servicecollection.AddSingleton <ISerializer, ProtobufSerializer>(); //注册序列化组件 servicecollection.AddRabbitMQ <MessageInfo>(); //注册RabbitMq为默认消息队列 servicecollection.AddLogging(logging => logging.AddConsole()); servicecollection.PostConfigure <RabbitConfig>(c => { c.UserName = "******"; c.Password = "******"; c.Hosts = new[] { "127.0.0.1:5672" }; c.MaxPoolSize = 100; c.VirtualHost = "/"; }); var provider = servicecollection.BuildServiceProvider(); using (var client = await StartClientWithRetries()) { var manager = provider.GetService <ISubManager>(); await manager.Start(new[] { "Core", "Read", "Rep" }); var aActor = client.GetGrain <IAccount>(1); var bActor = client.GetGrain <IAccount>(2); while (true) { Console.WriteLine("Press Enter for times..."); var length = int.Parse(Console.ReadLine()); var stopWatch = new Stopwatch(); stopWatch.Start(); var tasks = new Task[length * 2]; Parallel.For(0, length, i => { tasks[i * 2] = aActor.AddAmount(1000); //1用户充值1000 tasks[i * 2 + 1] = aActor.Transfer(2, 500); //转给2用户500 }); await Task.WhenAll(tasks); stopWatch.Stop(); Console.WriteLine($"{length * 2}次操作完成,耗时:{stopWatch.ElapsedMilliseconds}ms"); await Task.Delay(200); Console.WriteLine($"End:1的余额为{await aActor.GetBalance()},2的余额为{await bActor.GetBalance()}"); } } } catch (Exception e) { Console.WriteLine(e); return(1); } }
private static async Task <IClusterClient> StartClientWithRetries(int initializeAttemptsBeforeFailing = 5) { var siloAddress = IPAddress.Loopback; var gatewayPort = 30000; int attempt = 0; IClusterClient client; while (true) { try { client = new ClientBuilder() .ConfigureCluster(options => { options.ClusterId = "helloworldcluster"; }) .UseStaticClustering(options => options.Gateways.Add((new IPEndPoint(siloAddress, gatewayPort)).ToGatewayUri())) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IAccount).Assembly).WithReferences()) .ConfigureLogging(logging => logging.AddConsole()) .ConfigureServices((servicecollection) => { SubManager.Parse(servicecollection, typeof(AccountCoreHandler).Assembly); //注册handle servicecollection.AddSingleton <IOrleansClientFactory, OrleansClientFactory>(); //注册Client获取方法 servicecollection.AddSingleton <ISerializer, ProtobufSerializer>(); //注册序列化组件 servicecollection.AddRabbitMQ <MessageInfo>(); //注册RabbitMq为默认消息队列 servicecollection.PostConfigure <RabbitConfig>(c => { c.UserName = "******"; c.Password = "******"; c.Hosts = new[] { "127.0.0.1:5672" }; c.MaxPoolSize = 100; c.VirtualHost = "/"; }); }) .Build(); await client.Connect(); OrleansClientFactory.Init(client); Console.WriteLine("Client successfully connect to silo host"); break; } catch (SiloUnavailableException) { attempt++; Console.WriteLine($"Attempt {attempt} of {initializeAttemptsBeforeFailing} failed to initialize the Orleans client."); if (attempt > initializeAttemptsBeforeFailing) { throw; } await Task.Delay(TimeSpan.FromSeconds(4)); } } return(client); }
private static async Task <int> RunMainAsync() { var servicecollection = new ServiceCollection(); SubManager.Parse(servicecollection, typeof(AccountCoreHandler).Assembly); //注册handle servicecollection.AddSingleton <IClientFactory, ClientFactory>(); //注册Client获取方法 servicecollection.AddSingleton <ISerializer, ProtobufSerializer>(); //注册序列化组件 servicecollection.AddRabbitMQ <MessageInfo>(); //注册RabbitMq为默认消息队列 servicecollection.AddLogging(logging => logging.AddConsole()); servicecollection.PostConfigure <RabbitConfig>(c => { c.UserName = "******"; c.Password = "******"; c.Hosts = new[] { "192.168.125.230:5672" }; c.MaxPoolSize = 100; c.VirtualHost = "/"; }); var provider = servicecollection.BuildServiceProvider(); try { using (var client = await StartClientWithRetries()) { var manager = provider.GetService <ISubManager>(); await manager.Start(new[] { "Core", "Read", "Rep" }); while (true) { // var actor = client.GetGrain<IAccount>(0); // Console.WriteLine("Press Enter for times..."); Console.WriteLine("start"); var length = 1000;// int.Parse(Console.ReadLine()); var stopWatch = new Stopwatch(); stopWatch.Start(); await Task.WhenAll(Enumerable.Range(0, length).Select(x => client.GetGrain <IAccount>(0).AddAmount(1000).AsTask())); stopWatch.Stop(); Console.WriteLine($"{length }次操作完成,耗时:{stopWatch.ElapsedMilliseconds}ms"); await Task.Delay(200); Console.WriteLine($"余额为{await client.GetGrain<IAccount>(0).GetBalance()}"); } } } catch (Exception e) { Console.WriteLine(e); return(1); } }
private static async Task <IClusterClient> StartClientWithRetries(int initializeAttemptsBeforeFailing = 5) { int attempt = 0; IClusterClient client; while (true) { try { client = new ClientBuilder() .UseLocalhostClustering() .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IAccount).Assembly).WithReferences()) .ConfigureLogging(logging => logging.AddConsole().SetMinimumLevel(LogLevel.Warning)) .ConfigureServices((servicecollection) => { SubManager.Parse(servicecollection, typeof(AccountToDbHandler).Assembly); //注册handle servicecollection.AddSingleton <IOrleansClientFactory, OrleansClientFactory>(); //注册Client获取方法 servicecollection.AddSingleton <ISerializer, ProtobufSerializer>(); //注册序列化组件 servicecollection.AddRabbitMQ <MessageInfo>(); //注册RabbitMq为默认消息队列 servicecollection.PostConfigure <RabbitConfig>(c => { c.UserName = "******"; c.Password = "******"; c.Hosts = new[] { "127.0.0.1:5672" }; c.MaxPoolSize = 100; c.VirtualHost = "/"; }); }) .Build(); await client.Connect(); OrleansClientFactory.Init(client); Console.WriteLine("Client successfully connect to silo host"); break; } catch (SiloUnavailableException) { attempt++; Console.WriteLine($"Attempt {attempt} of {initializeAttemptsBeforeFailing} failed to initialize the Orleans client."); if (attempt > initializeAttemptsBeforeFailing) { throw; } await Task.Delay(TimeSpan.FromSeconds(4)); } } return(client); }
// Use this for initialization void Start() { sub = Instantiate(subPrefab, Vector3.zero, Quaternion.identity, world); player = Instantiate(playerPrefab, Vector3.zero, Quaternion.identity, world); mapDisplay = Instantiate(mapDisplayPrefab, Vector3.zero, Quaternion.identity); mapDisplay.transform.SetParent(ui, false); stage.Build(); subManager = sub.GetComponentInChildren <SubManager>(); subManager.stage = stage; subManager.position = new SubPosition(); subManager.position.row = stage.startRow; subManager.position.nextRow = stage.startRow; subManager.gameState = gameState; AddCargoToSub(); mapDisplay.GetComponent <MapController>().subManager = subManager; sub.GetComponentInChildren <Parascope>().map = mapDisplay.GetComponent <MapController>(); gameState.isInMission = true; missionStartTime = Time.time; }
public void Execute(NebulaUser user, params string[] args) { SubManager.ExecuteCommands(user, args); }
private static async Task <int> RunMainAsync() { var servicecollection = new ServiceCollection(); SubManager.Parse(servicecollection, typeof(AccountCoreHandler).Assembly); //注册handle servicecollection.AddSingleton <IClientFactory, ClientFactory>(); //注册Client获取方法 servicecollection.AddSingleton <ISerializer, ProtobufSerializer>(); //注册序列化组件 servicecollection.AddRabbitMQ <MessageInfo>(); //注册RabbitMq为默认消息队列 servicecollection.AddLogging(logging => logging.AddConsole()); servicecollection.PostConfigure <RabbitConfig>(c => { c.UserName = "******"; c.Password = "******"; c.Hosts = new[] { "127.0.0.1:5672" }; c.MaxPoolSize = 100; c.VirtualHost = "/"; }); var provider = servicecollection.BuildServiceProvider(); try { using (var client = await StartClientWithRetries()) { var manager = provider.GetService <ISubManager>(); await manager.Start(new[] { "Core", "Read", "Rep" }); while (true) { Console.WriteLine("Press Enter to count...X100"); var actorAcount = int.Parse(Console.ReadLine()) * 100; IAccount[] actors = new IAccount[actorAcount]; for (int i = 0; i < actorAcount; i++) { actors[i] = client.GetGrain <IAccount>(i); } Console.WriteLine("Press Enter for times..."); var length = int.Parse(Console.ReadLine()); var stopWatch = new Stopwatch(); stopWatch.Start(); for (int i = 0; i < length; i++) { var transfer = false; await Task.WhenAll(Enumerable.Range(0, actorAcount).Select(async x => { if (!transfer) { await actors[x].AddAmount(1000); transfer = true; } else { await actors[x - 1].Transfer(x, 500); transfer = false; } })); } stopWatch.Stop(); Console.WriteLine($"{length * actorAcount}次操作完成,耗时:{stopWatch.ElapsedMilliseconds}ms"); await Task.Delay(200); for (int i = 0; i < actorAcount; i++) { Console.WriteLine($"End:{i}的余额为{await actors[i].GetBalance()}"); } } } } catch (Exception e) { Console.WriteLine(e); return(1); } }
public SharedSessionsSubCommand() { SubManager.RegisterCommand(new SharedSessionCreateRoomCommand()); SubManager.RegisterCommand(new SharedSessionListRoomsCommand()); }
private static void Intermediate_OOP3Characteristics() { // 1. Class basic 1 Console.WriteLine("=================== Class basic 1 ================"); var classTest = new ClassTest_Basic1("Jini", 32, 'F'); Console.WriteLine(string.Format("{0}:{1}:{2}", classTest.Name, classTest.Age, classTest.Gender)); Console.WriteLine(classTest.GetCustomerData()); // event // event subscription : += //classTest.NameChanged += ClassTest_NameChanged; //classTest.BalanceChanged += ClassTest_BalanceChanged; classTest.Name = "Jane"; // overloading method Console.WriteLine(classTest.Foo(1D)); Console.WriteLine(classTest.Foo(1)); Console.WriteLine(classTest.Foo(1F, 2)); Console.WriteLine(classTest.Foo(2, 1F)); // 2. Class basic 2 Encapsulation Console.WriteLine("======== OOP characteristic 1 of 3: Encapsulation ======"); var classTest_Basic2 = new ClassTest_Basic2 { CurrentPrice = 50, SharesOwned = 100, BenchmarkPrice = 49.99M }; Console.WriteLine(classTest_Basic2.Worth); Console.WriteLine(classTest_Basic2.BenchmarkPrice); Console.WriteLine(classTest_Basic2.BenchmarkShare); // 3. Property: Indexer Console.WriteLine("=================== Property: Indexer ================"); var classTest2 = new ClassTest_Indexer(); Console.WriteLine(classTest2[3]); // fox classTest2[3] = "kangaroo"; Console.WriteLine(classTest2[3]); // kangaroo // partial class and partial method // only explanation // 4. Class Inheritance Console.WriteLine("====== OOP characteristic 2 of 3: Class Inheritance ======"); Stock msft = new Stock { Name = "MSFT", SharesOwned = 1000 }; Console.WriteLine(msft.Name); // MSFT Console.WriteLine(msft.SharesOwned); // 1000 House mansion = new House { Name = "Mansion", Mortgage = 250000 }; Console.WriteLine(mansion.Name); // Mansion Console.WriteLine(mansion.Mortgage); // 250000 // 5. Reference Conversion Console.WriteLine("=================== Reference Conversion ================"); // Upcast & Downcast // An upcast creates a base class reference from a subclass reference: Stock msft2 = new Stock(); Asset a = msft2; // After the upcast, the two variables still references the same Stock object: Console.WriteLine("Data Type Comparison: "); Console.WriteLine(a == msft2); // True // A downcast operation creates a subclass reference from a base class reference. Stock msft3 = new Stock(); Asset a2 = msft3; // Upcast Stock s2 = (Stock)a2; // Downcast Console.WriteLine(s2.SharesOwned); // <No error> Console.WriteLine(s2 == a2); // True Console.WriteLine(s2 == msft3); // True // A downcast requires an explicit cast because it can potentially fail at runtime: House h = new House(); Asset a3 = h; // Upcast always succeeds // Stock s3 = (Stock)a3; // ERROR: Downcast fails: a3 is not a Stock // TEST: is and as operator // 6. virtaul Function Console.WriteLine("========== virtual function, sealed, abstract ========"); var manager = new Manager(70000, "*****@*****.**", "Jini"); Console.WriteLine(manager.ToString()); // sealed class var subManager = new SubManager(5000, "*****@*****.**", "John"); Console.WriteLine(subManager.ToString()); // 7. abstract class Dog dog = new Dog(); Console.WriteLine(dog.Describe()); // 8. Polymorphism // A variable of type x can refer to an object that subclasses x. // The Display method below accepts an Asset. This means means we can pass it any subtype: Console.WriteLine("========= OOP characteristic 3 of 3: Class Polymorphism ========"); Display(new Stock2 { Name = "MSFT", SharesOwned = 1000 }); Display(new House2 { Name = "Mansion", Mortgage = 100000 }); }