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 CanBindNode() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 9000); node.Close(); }
public void BarReturnsCorrectString() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 11003); var foo = (Foo)new Distributed<Foo>(node, "foo"); var bar = foo.ConstructBar(); Assert.Equal("Hello, World!", bar.GetHelloWorldString()); }
public void NodeBindsAndClosesCleanly() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 9001); node.Close(); var second = new LocalNode(); second.Bind(IPAddress.Loopback, 9001); second.Close(); }
public void TwoNodesCanNotRunInTheSameProcessOnTheSamePort() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 9004); var second = new LocalNode(); Assert.Throws<SocketException>(() => second.Bind(IPAddress.Loopback, 9004)); node.Close(); }
public void DoesNotThrowExceptionWhenDirectlyConstructingInsideDistributedContext() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 11001); Assert.DoesNotThrow(() => { new Distributed<InterceptNewInstructionTest>(node, "hello"); }); }
public void TwoNodesCanRunInTheSameProcessOnDifferentPorts() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 9002); var second = new LocalNode(); second.Bind(IPAddress.Loopback, 9003); node.Close(); second.Close(); }
public void DoesNotThrowExceptionWhenIndirectlyConstructingInsideDistributedContext() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 11002); Assert.DoesNotThrow(() => { var foo = (Foo)new Distributed<Foo>(node, "foo"); var bar = foo.ConstructBar(); }); }
public void BarReturnsCorrectString() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 11003); var foo = (Foo) new Distributed <Foo>(node, "foo"); var bar = foo.ConstructBar(); Assert.Equal("Hello, World!", bar.GetHelloWorldString()); }
public void DoesNotThrowExceptionWhenDirectlyConstructingInsideDistributedContext() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 11001); Assert.DoesNotThrow(() => { new Distributed <InterceptNewInstructionTest>(node, "hello"); }); }
public void DoesNotThrowExceptionWhenIndirectlyConstructingInsideDistributedContext() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 11002); Assert.DoesNotThrow(() => { var foo = (Foo) new Distributed <Foo>(node, "foo"); var bar = foo.ConstructBar(); }); }
public void TwoNodesCanNotRunInTheSameProcessOnTheSamePort() { var node = new LocalNode(); node.Bind(IPAddress.Loopback, 9004); var second = new LocalNode(); Assert.Throws <SocketException>(() => second.Bind(IPAddress.Loopback, 9004)); node.Close(); }
public void InvokeOnSameNode() { // Set up nodes. var first = new LocalNode(); first.Bind(IPAddress.Loopback, 9002); // Create the bar object in the first node. var barFirst = (Bar)new Distributed<Bar>(first, "bar"); // Assert that the second bar returns the right value. Assert.Equal("Hello, World!", barFirst.GetHelloWorldString()); // Close nodes. first.Close(); }
public void InvokeOnSameNode() { // Set up nodes. var first = new LocalNode(); first.Bind(IPAddress.Loopback, 9002); // Create the bar object in the first node. var barFirst = (Bar) new Distributed <Bar>(first, "bar"); // Assert that the second bar returns the right value. Assert.Equal("Hello, World!", barFirst.GetHelloWorldString()); // Close nodes. first.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 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(); } }
/// <summary> /// Runs the asset manager side-by-side with another XNA program /// (for example the main game) and then rebinds the IoC providers /// for asset management so that assets can be changed in real-time. /// </summary> /// <param name="kernel"> /// The kernel. /// </param> /// <param name="startProcess"> /// The start Process. /// </param> /// <returns> /// The <see cref="Process"/>. /// </returns> public static Process RunAndConnect(IKernel kernel, bool startProcess) { #if FALSE var node = new LocalNode(); node.Bind(IPAddress.Loopback, 9838); #endif Process process = null; if (startProcess) { var assemblyPath = Assembly.GetExecutingAssembly().Location; var directory = new FileInfo(assemblyPath).Directory; var filename = Path.Combine(directory.FullName, "ProtogameAssetManager.exe"); if (!File.Exists(filename)) { throw new FileNotFoundException( "You must have ProtogameAssetManager.exe in " + "the same directory as your game."); } process = new Process(); process.StartInfo = new ProcessStartInfo { FileName = filename, Arguments = "--connect" }; process.EnableRaisingEvents = true; process.Exited += (sender, e) => { Environment.Exit(1); }; process.Start(); } #if FALSE var assetManagerProvider = new NetworkedAssetManagerProvider(node, kernel); kernel.Bind <IAssetManagerProvider>().ToMethod(x => assetManagerProvider); // Wait until the networked asset manager is ready. while (!assetManagerProvider.IsReady && (process == null || !process.HasExited)) { Thread.Sleep(100); } #endif return(process); }
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 InvokeAcrossNodes() { // Set up nodes. var first = new LocalNode(); var second = new LocalNode(); first.Bind(IPAddress.Loopback, 9004); second.Bind(IPAddress.Loopback, 9005); // Create the bar object in the first node. new Distributed<Bar>(first, "bar"); // Retrieve it on the second node. var barSecond = (Bar)new Distributed<Bar>(second, "bar"); // Assert that the second bar returns the right value. Assert.Equal("Hello, World!", barSecond.GetHelloWorldString()); // Close nodes. first.Close(); second.Close(); }
public void InvokeAcrossNodes() { // Set up nodes. var first = new LocalNode(); var second = new LocalNode(); first.Bind(IPAddress.Loopback, 9004); second.Bind(IPAddress.Loopback, 9005); // Create the bar object in the first node. new Distributed <Bar>(first, "bar"); // Retrieve it on the second node. var barSecond = (Bar) new Distributed <Bar>(second, "bar"); // Assert that the second bar returns the right value. Assert.Equal("Hello, World!", barSecond.GetHelloWorldString()); // Close nodes. first.Close(); second.Close(); }
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(); } }
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(); }