public void NodeIsReusable() { this.AssertNoActiveConnections(); var other = new LocalNode(); var node = new LocalNode(); try { other.Bind(IPAddress.Loopback, 12002); node.Bind(IPAddress.Loopback, 12000); node.GetService <IClientConnector>().Connect(IPAddress.Loopback, 12002); Assert.Equal(2, node.GetService <IClientLookup>().GetAll().Count()); node.Close(); node.Bind(IPAddress.Loopback, 12001); Assert.Equal(1, node.GetService <IClientLookup>().GetAll().Count()); } finally { other.Close(); node.Close(); } this.AssertNoActiveConnections(); }
public void TestFetchHandler() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 10001); try { var constructor = node.GetService <IMessageConstructor>(); var serializer = node.GetService <IObjectWithTypeSerializer>(); var storage = node.GetService <IObjectStorage>(); storage.Put(new LiveEntry { Key = ID.NewHash("hello"), Owner = node.Self, Value = 40 }); var fetchMessage = constructor.ConstructFetchMessage(ID.NewHash("hello")); fetchMessage.Sender = node.Self; var handler = node.GetService <FetchMessageHandler>(); handler.Handle(fetchMessage); var sideChannel = node.GetService <IMessageSideChannel>(); Assert.True( sideChannel.Has(x => x.Type == MessageType.FetchResult), "side channel does not report message"); var result = sideChannel.WaitUntil(x => x.Type == MessageType.FetchResult, 100); Assert.Equal(1, result.FetchResult.Length); var value = serializer.Deserialize(result.FetchResult.First().Value); Assert.IsType <int>(value); Assert.Equal(40, (int)value); } finally { node.Close(); } }
public void TestFetchHandler() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 10001); try { var constructor = node.GetService<IMessageConstructor>(); var serializer = node.GetService<IObjectWithTypeSerializer>(); var storage = node.GetService<IObjectStorage>(); storage.Put(new LiveEntry { Key = ID.NewHash("hello"), Owner = node.Self, Value = 40 }); var fetchMessage = constructor.ConstructFetchMessage(ID.NewHash("hello")); fetchMessage.Sender = node.Self; var handler = node.GetService<FetchMessageHandler>(); handler.Handle(fetchMessage); var sideChannel = node.GetService<IMessageSideChannel>(); Assert.True( sideChannel.Has(x => x.Type == MessageType.FetchResult), "side channel does not report message"); var result = sideChannel.WaitUntil(x => x.Type == MessageType.FetchResult, 100); Assert.Equal(1, result.FetchResult.Length); var value = serializer.Deserialize(result.FetchResult.First().Value); Assert.IsType<int>(value); Assert.Equal(40, (int)value); } finally { node.Close(); } }
public void InvocationIsCorrectForServer() { // Set up nodes. var first = new LocalNode(Architecture.ServerClient, Caching.PushOnChange) { IsServer = true }; var second = new LocalNode(Architecture.ServerClient, Caching.PushOnChange); first.Bind(IPAddress.Loopback, 9004); second.Bind(IPAddress.Loopback, 9005); // Connect the second node to the first. second.GetService <IClientConnector>().Connect(IPAddress.Loopback, 9004); // Create the bar object in the first node. var barFirst = (Semantic) new Distributed <Semantic>(first, "semantic"); // Retrieve it on the second node. var barSecond = (Semantic) new Distributed <Semantic>(second, "semantic"); // Set the property. barFirst.Value = "Hello, World!"; // If we try and call any of the methods from the server, they should // all work. Assert.Equal("Hello, World!", barFirst.GetException()); Assert.Equal("Hello, World!", barFirst.GetIgnore()); Assert.Equal("Hello, World!", barFirst.GetValue()); // If we try and call barSecond.GetException, we should get an exception // because we are not a server. Assert.Throws <MemberAccessException>(() => barSecond.GetException()); // If we try and call barSecond.GetIgnore, we should get a null value // because we are not a server. Assert.Equal(null, barSecond.GetIgnore()); // If we try and call barSecond.GetValue, we should get "Hello, World!" Assert.Equal("Hello, World!", barSecond.GetValue()); // Close nodes. first.Close(); second.Close(); }
public void InvocationIsCorrectForServer() { // Set up nodes. var first = new LocalNode(Architecture.ServerClient, Caching.PushOnChange) { IsServer = true }; var second = new LocalNode(Architecture.ServerClient, Caching.PushOnChange); first.Bind(IPAddress.Loopback, 9004); second.Bind(IPAddress.Loopback, 9005); // Connect the second node to the first. second.GetService<IClientConnector>().Connect(IPAddress.Loopback, 9004); // Create the bar object in the first node. var barFirst = (Semantic)new Distributed<Semantic>(first, "semantic"); // Retrieve it on the second node. var barSecond = (Semantic)new Distributed<Semantic>(second, "semantic"); // Set the property. barFirst.Value = "Hello, World!"; // If we try and call any of the methods from the server, they should // all work. Assert.Equal("Hello, World!", barFirst.GetException()); Assert.Equal("Hello, World!", barFirst.GetIgnore()); Assert.Equal("Hello, World!", barFirst.GetValue()); // If we try and call barSecond.GetException, we should get an exception // because we are not a server. Assert.Throws<MemberAccessException>(() => barSecond.GetException()); // If we try and call barSecond.GetIgnore, we should get a null value // because we are not a server. Assert.Equal(null, barSecond.GetIgnore()); // If we try and call barSecond.GetValue, we should get "Hello, World!" Assert.Equal("Hello, World!", barSecond.GetValue()); // Close nodes. first.Close(); second.Close(); }
public void NodeIsReusable() { this.AssertNoActiveConnections(); var other = new LocalNode(); var node = new LocalNode(); try { other.Bind(IPAddress.Loopback, 12002); node.Bind(IPAddress.Loopback, 12000); node.GetService<IClientConnector>().Connect(IPAddress.Loopback, 12002); Assert.Equal(2, node.GetService<IClientLookup>().GetAll().Count()); node.Close(); node.Bind(IPAddress.Loopback, 12001); Assert.Equal(1, node.GetService<IClientLookup>().GetAll().Count()); } finally { other.Close(); node.Close(); } this.AssertNoActiveConnections(); }
internal static void Main(string[] args) { var connectToRunningGame = false; var options = new OptionSet { { "connect", "Internal use only (used by the game client).", v => connectToRunningGame = true } }; try { options.Parse(args); } catch (OptionException ex) { Console.Write("ProtogameAssetManager.exe: "); Console.WriteLine(ex.Message); Console.WriteLine("Try `ProtogameAssetManager.exe --help` for more information."); return; } // Deploy the correct MojoShader DLL. MojoShaderDeploy.Deploy(); var kernel = new StandardKernel(); kernel.Load <Protogame2DIoCModule>(); kernel.Load <ProtogameAssetIoCModule>(); kernel.Load <ProtogameEventsIoCModule>(); kernel.Load <ProtogamePlatformingIoCModule>(); kernel.Load <AssetManagerIoCModule>(); // Only allow the source load strategies. kernel.Unbind <ILoadStrategy>(); kernel.Bind <ILoadStrategy>().To <RawTextureLoadStrategy>(); kernel.Bind <ILoadStrategy>().To <RawModelLoadStrategy>(); kernel.Bind <ILoadStrategy>().To <RawEffectLoadStrategy>(); kernel.Bind <ILoadStrategy>().To <LocalSourceLoadStrategy>(); kernel.Bind <ILoadStrategy>().To <EmbeddedSourceLoadStrategy>(); kernel.Bind <ILoadStrategy>().To <EmbeddedCompiledLoadStrategy>(); var runningFile = new FileInfo(Assembly.GetExecutingAssembly().Location); var workingDirectoryInfo = new DirectoryInfo(Environment.CurrentDirectory); var scannedUnique = new List <string>(); foreach (var file in runningFile.Directory.GetFiles("*.dll")) { if (scannedUnique.Contains(file.FullName)) { continue; } Console.WriteLine("Scanning " + file.Name); try { RegisterEditorsFromAssembly(Assembly.LoadFrom(file.FullName), kernel); scannedUnique.Add(file.FullName); } catch (BadImageFormatException) { } catch (FileLoadException) { } } foreach (var file in runningFile.Directory.GetFiles("*.exe")) { if (scannedUnique.Contains(file.FullName)) { continue; } Console.WriteLine("Scanning " + file.Name); try { RegisterEditorsFromAssembly(Assembly.LoadFrom(file.FullName), kernel); scannedUnique.Add(file.FullName); } catch (BadImageFormatException) { } catch (FileLoadException) { } } foreach (var file in workingDirectoryInfo.GetFiles("*.dll")) { if (scannedUnique.Contains(file.FullName)) { continue; } Console.WriteLine("Scanning " + file.Name); try { RegisterEditorsFromAssembly(Assembly.LoadFrom(file.FullName), kernel); scannedUnique.Add(file.FullName); } catch (BadImageFormatException) { } catch (FileLoadException) { } } foreach (var file in workingDirectoryInfo.GetFiles("*.exe")) { if (scannedUnique.Contains(file.FullName)) { continue; } Console.WriteLine("Scanning " + file.Name); try { RegisterEditorsFromAssembly(Assembly.LoadFrom(file.FullName), kernel); scannedUnique.Add(file.FullName); } catch (BadImageFormatException) { } catch (FileLoadException) { } } #if FALSE if (connectToRunningGame) { var node = new LocalNode(Architecture.ServerClient, Caching.PushOnChange); node.Bind(IPAddress.Loopback, 9837); node.GetService <IClientConnector>().Connect(IPAddress.Loopback, 9838); var assetManagerProvider = new NetworkedAssetManagerProvider(node, kernel); kernel.Bind <IAssetManagerProvider>().ToMethod(x => assetManagerProvider); } else #endif kernel.Bind <IAssetManagerProvider>().To <LocalAssetManagerProvider>().InSingletonScope(); using (var game = new AssetManagerGame(kernel)) { game.Run(); } }
internal static void Main(string[] args) { var connectToRunningGame = false; var options = new OptionSet { { "connect", "Internal use only (used by the game client).", v => connectToRunningGame = true } }; try { options.Parse(args); } catch (OptionException ex) { Console.Write("ProtogameAssetManager.exe: "); Console.WriteLine(ex.Message); Console.WriteLine("Try `ProtogameAssetManager.exe --help` for more information."); return; } // Deploy the correct MojoShader DLL. MojoShaderDeploy.Deploy(); var kernel = new StandardKernel(); kernel.Load<Protogame2DIoCModule>(); kernel.Load<ProtogameAssetIoCModule>(); kernel.Load<ProtogameEventsIoCModule>(); kernel.Load<ProtogamePlatformingIoCModule>(); kernel.Load<AssetManagerIoCModule>(); // Only allow the source load strategies. kernel.Unbind<ILoadStrategy>(); kernel.Bind<ILoadStrategy>().To<RawTextureLoadStrategy>(); kernel.Bind<ILoadStrategy>().To<RawModelLoadStrategy>(); kernel.Bind<ILoadStrategy>().To<RawEffectLoadStrategy>(); kernel.Bind<ILoadStrategy>().To<LocalSourceLoadStrategy>(); kernel.Bind<ILoadStrategy>().To<EmbeddedSourceLoadStrategy>(); kernel.Bind<ILoadStrategy>().To<EmbeddedCompiledLoadStrategy>(); var runningFile = new FileInfo(Assembly.GetExecutingAssembly().Location); var workingDirectoryInfo = new DirectoryInfo(Environment.CurrentDirectory); var scannedUnique = new List<string>(); foreach (var file in runningFile.Directory.GetFiles("*.dll")) { if (scannedUnique.Contains(file.FullName)) continue; Console.WriteLine("Scanning " + file.Name); try { RegisterEditorsFromAssembly(Assembly.LoadFrom(file.FullName), kernel); scannedUnique.Add(file.FullName); } catch (BadImageFormatException) { } catch (FileLoadException) { } } foreach (var file in runningFile.Directory.GetFiles("*.exe")) { if (scannedUnique.Contains(file.FullName)) continue; Console.WriteLine("Scanning " + file.Name); try { RegisterEditorsFromAssembly(Assembly.LoadFrom(file.FullName), kernel); scannedUnique.Add(file.FullName); } catch (BadImageFormatException) { } catch (FileLoadException) { } } foreach (var file in workingDirectoryInfo.GetFiles("*.dll")) { if (scannedUnique.Contains(file.FullName)) continue; Console.WriteLine("Scanning " + file.Name); try { RegisterEditorsFromAssembly(Assembly.LoadFrom(file.FullName), kernel); scannedUnique.Add(file.FullName); } catch (BadImageFormatException) { } catch (FileLoadException) { } } foreach (var file in workingDirectoryInfo.GetFiles("*.exe")) { if (scannedUnique.Contains(file.FullName)) continue; Console.WriteLine("Scanning " + file.Name); try { RegisterEditorsFromAssembly(Assembly.LoadFrom(file.FullName), kernel); scannedUnique.Add(file.FullName); } catch (BadImageFormatException) { } catch (FileLoadException) { } } #if FALSE if (connectToRunningGame) { var node = new LocalNode(Architecture.ServerClient, Caching.PushOnChange); node.Bind(IPAddress.Loopback, 9837); node.GetService<IClientConnector>().Connect(IPAddress.Loopback, 9838); var assetManagerProvider = new NetworkedAssetManagerProvider(node, kernel); kernel.Bind<IAssetManagerProvider>().ToMethod(x => assetManagerProvider); } else #endif kernel.Bind<IAssetManagerProvider>().To<LocalAssetManagerProvider>().InSingletonScope(); using (var game = new AssetManagerGame(kernel)) { game.Run(); } }