public DictionarySerializationTests() { pofContext = new PofContext().With(x => { x.RegisterPortableObjectType(1, typeof(SerializableClass)); }); pofSerializer = new PofSerializer(pofContext); }
public void Run() { var context = new PofContext(); context.MergeContext(new CustomPofContext(1000, dummyRemoteService)); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, new LogicController(10)); serializer.Serialize(writer, new LogicController(20)); } ms.Position = 0; VerifyNoMoreInteractions(); using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { var instance1 = serializer.Deserialize <LogicController>(reader); var instance2 = serializer.Deserialize <LogicController>(reader); VerifyNoMoreInteractions(); instance1.Execute(); Verify(dummyRemoteService, Once()).DoSomething(10); VerifyNoMoreInteractions(); instance2.Execute(); Verify(dummyRemoteService, Once()).DoSomething(20); VerifyNoMoreInteractions(); } } }
public void PolymorphismTest() { var testObj1 = new TestClass(new object[] { 0xCDCDCDCD, "herp", new byte[] { 0xEE, 0xDD, 0xCC, 0xDD, 0xEE, 0xCC, 0xFF } }); var context = new PofContext(); context.RegisterPortableObjectType(0xFF, typeof(TestClass)); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, testObj1); } Console.WriteLine(ms.ToArray().ToHex()); ms.Position = 0; using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { var readObj1 = serializer.Deserialize <TestClass>(reader); AssertTrue(testObj1.Value.Take(2).SequenceEqual(readObj1.Value.Take(2))); AssertTrue(((IEnumerable <byte>)testObj1.Value[2]).SequenceEqual((IEnumerable <byte>)readObj1.Value[2])); } } }
public TrinketProxyEgg() { streamFactory = new StreamFactory(); processProxy = new ProcessProxy(); var pofContext = new PofContext().With(x => { x.MergeContext(new DspPofContext()); x.MergeContext(new TrinketsApiPofContext()); x.MergeContext(new TrinketsImplPofContext()); }); ICollectionFactory collectionFactory = new CollectionFactory(); IFileSystemProxy fileSystemProxy = new FileSystemProxy(streamFactory); IThreadingProxy threadingProxy = new ThreadingProxy(new ThreadingFactory(), new SynchronizationFactory()); var dnsProxy = new DnsProxy(); INetworkingProxy networkingProxy = new NetworkingProxy(new SocketFactory(new TcpEndPointFactory(dnsProxy), new NetworkingInternalFactory(threadingProxy, streamFactory)), new TcpEndPointFactory(dnsProxy)); pofSerializer = new PofSerializer(pofContext); PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer); ProxyGenerator proxyGenerator = new ProxyGenerator(); var serviceClientFactory = new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory); // construct libdsp local service node ClusteringConfiguration clusteringConfiguration = new ClientClusteringConfiguration(); ServiceClient localServiceClient = serviceClientFactory.Construct(clusteringConfiguration); keepaliveObjects.Add(localServiceClient); temporaryFileService = localServiceClient.GetService<TemporaryFileService>(); var processInjector = new ProcessInjectorImpl(); ProcessInjectionConfiguration processInjectionConfiguration = new ProcessInjectionConfigurationImpl(injectionAttempts: 10, injectionAttemptsDelay: 200); processInjectionService = new ProcessInjectionServiceImpl(processInjector, processInjectionConfiguration); IDtpNodeFactory transportNodeFactory = new DefaultDtpNodeFactory(); BootstrapConfigurationGenerator bootstrapConfigurationGenerator = new BootstrapConfigurationGeneratorImpl(); trinketInternalUtilities = new TrinketInternalUtilitiesImpl(fileSystemProxy); trinketDtpServerFactory = new TrinketDtpServerFactoryImpl(streamFactory, transportNodeFactory, bootstrapConfigurationGenerator); }
public void Run() { const string rootName = "root"; const string rootLeftName = "root_left"; const string rootRightName = "root_right"; const string rootRightRightName = "root_right_right"; var context = new PofContext(); context.RegisterPortableObjectType(0, typeof(Node)); var serializer = new PofSerializer(context); var rootRightRight = new Node(rootRightName, null, null); var rootRight = new Node(rootRightName, null, rootRightRight); var rootLeft = new Node(rootLeftName, null, null); var root = new Node("root", rootLeft, rootRight); using (var ms = new MemoryStream()) using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, root); ms.Position = 0; var newRoot = serializer.Deserialize <Node>(reader); AssertEquals(root, newRoot); } }
public void Run() { var nowUtc = DateTime.UtcNow; var nowLocal = DateTime.Now; Console.WriteLine(nowUtc); Console.WriteLine(nowLocal); var context = new PofContext().With(x => x.RegisterPortableObjectType(0, typeof(DummyType))); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, new DummyType(nowUtc, new [] { nowUtc, nowUtc, nowUtc })); serializer.Serialize(writer, new DummyType(nowLocal, new[] { nowUtc, nowUtc, nowUtc })); } ms.Position = 0; using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { var nowUtcWrapper = serializer.Deserialize <DummyType>(reader); var nowLocalWrapper = serializer.Deserialize <DummyType>(reader); Console.WriteLine(nowUtcWrapper.Time); Console.WriteLine(nowLocalWrapper.Time); AssertEquals(nowUtc.ToUniversalTime(), nowUtcWrapper.Time.ToUniversalTime()); AssertEquals(nowUtc.ToUniversalTime(), nowLocalWrapper.Time.ToUniversalTime()); AssertEquals(nowUtc.ToUniversalTime(), nowUtcWrapper.AlsoTime.ToUniversalTime()); AssertEquals(nowUtc.ToUniversalTime(), nowLocalWrapper.AlsoTime.ToUniversalTime()); AssertTrue(nowUtcWrapper.Times.All(time => time.ToUniversalTime().Equals(nowUtc.ToUniversalTime()))); AssertTrue(nowLocalWrapper.Times.All(time => time.ToUniversalTime().Equals(nowUtc.ToUniversalTime()))); } } }
public void ImportingTaskStart() { var temporaryDirectory = TemporaryFileService.AllocateTemporaryDirectory(TimeSpan.FromHours(1)); DirectoryHelpers.DirectoryCopy(Modification.RepositoryPath, temporaryDirectory, true); Directory.Move(temporaryDirectory, finalRepositoryPath); Modification = ModificationLoader.FromPath(finalRepositoryPath); PhaseFactory.SetModification(Modification); ViewModel.SetModification(Modification); var enabledComponent = Modification.GetComponent <EnabledComponent>(); enabledComponent.IsEnabled = true; var thumbnailDirectory = Path.Combine(finalRepositoryPath, "thumbnails"); FileSystemProxy.PrepareDirectory(thumbnailDirectory); var thumbnailGenerationTask = Task.Factory.StartNew(() => { using (var ms = new MemoryStream()) using (var writer = new BinaryWriter(ms)) { PofSerializer.Serialize(writer, new ThumbnailGenerationParameters { DestinationDirectory = thumbnailDirectory, SourceDirectory = importedDirectoryPath, ThumbnailsToGenerate = 3 }); ExeggutorService.SpawnHatchling( "thumbnail-generator", new SpawnConfiguration { InstanceName = "thumbnail-generator-" + DateTime.UtcNow.GetUnixTime(), Arguments = ms.GetBuffer() }); var thumbnailComponent = Modification.GetComponent <ThumbnailComponent>(); thumbnailComponent.SelectThumbnailIfUnselected(); } }, TaskCreationOptions.LongRunning); var contentDirectory = Path.Combine(finalRepositoryPath, "content"); FileSystemProxy.PrepareDirectory(contentDirectory); for (var i = 0; i < relativeImportedFilePaths.Length; i++) { var sourceFile = Path.Combine(importedDirectoryPath, relativeImportedFilePaths[i]); var destinationFile = Path.Combine(contentDirectory, relativeImportedFilePaths[i]); FileSystemProxy.PrepareParentDirectory(destinationFile); FileSystemProxy.CopyFile(sourceFile, destinationFile); UpdateProgress(0.333 * ((double)i / relativeImportedFilePaths.Length)); } LeagueBuildUtilities.ResolveModification(Modification, CancellationToken.None); UpdateProgress(0.666); LeagueBuildUtilities.CompileModification(Modification, CancellationToken.None); UpdateProgress(1); thumbnailGenerationTask.Wait(); PhaseManager.Transition(PhaseFactory.Idle()); }
public static void CheckConfiguration <TPortableObject>(IPofContext context, TPortableObject testObj) where TPortableObject : IPortableObject { var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { serializer.Serialize(ms, testObj); ms.Position = 0; var deserialized = serializer.Deserialize <TPortableObject>(ms); NMockitoStatic.AssertEquals(testObj, deserialized); } }
public ThumbnailGenerationEgg() { collectionFactory = new CollectionFactory(); var streamFactory = new StreamFactory(); var processProxy = new ProcessProxy(); threadingProxy = new ThreadingProxy(new ThreadingFactory(), new SynchronizationFactory()); pofContext = new PofContext().With(x => { x.MergeContext(new ManagementPofContext()); x.MergeContext(new ThumbnailGeneratorApiPofContext()); }); pofSerializer = new PofSerializer(pofContext); networkingProxy = new NetworkingProxy(new SocketFactory(new TcpEndPointFactory(new DnsProxy()), new NetworkingInternalFactory(threadingProxy, streamFactory)), new TcpEndPointFactory(new DnsProxy())); thumbnailGeneratorService = new ThumbnailGeneratorServiceImpl(); }
public void Run() { var context = new PofContext(); context.RegisterPortableObjectType(1, typeof(TestClass)); var serializer = new PofSerializer(context); var testObj1 = new TestClass(EnumerateValues()); var testObj2 = new TestClass(new object[] { null, null }); var testObj3 = new TestClass(new List <object> { 2, "string", null }); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, testObj1); serializer.Serialize(writer, testObj2); serializer.Serialize(writer, testObj3); } ms.Position = 0; using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { var readObj1 = serializer.Deserialize <TestClass>(reader); var a = ((IEnumerable <object>)testObj1.Value).ToArray(); var b = ((IEnumerable <object>)readObj1.Value).ToArray(); AssertEquals(5, a.Length); AssertEquals(5, b.Length); for (var i = 0; i < b.Length; i++) { var ai = a[i]; var bi = b[i]; if (ai is IEnumerable && !(ai is string)) { AssertTrue(((IEnumerable <object>)ai).SequenceEqual((IEnumerable <object>)bi)); } else { AssertEquals(ai, bi); } } var readObj2 = serializer.Deserialize <TestClass>(reader); AssertTrue(((IEnumerable <object>)testObj2.Value).SequenceEqual((IEnumerable <object>)readObj2.Value)); var readObj3 = serializer.Deserialize <TestClass>(reader); AssertTrue(((IEnumerable <object>)testObj3.Value).SequenceEqual((IEnumerable <object>)readObj3.Value)); } } }
public void ComplexTest() { var context = new PofContext(); context.RegisterPortableObjectType(0, typeof(DummyClass <>)); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { var writtenTypes = new Type[] { typeof(int), typeof(DummyClass <>), typeof(DummyClass <int>) }; Debug.WriteLine("Written Types: " + writtenTypes.Join(", ")); serializer.Serialize(ms, writtenTypes); ms.Position = 0; var readTypes = serializer.Deserialize <Type[]>(ms); // AssertEquals(readType, writtenType); Debug.WriteLine(" Read Types: " + readTypes.Join(", ")); } }
public void NestedDictionariesTest() { var testObj = new Wrapper <SCG.Dictionary <int, SCG.Dictionary <int, bool[]>[]>[]>(Util.Generate(10, i => MakeSubDictionary(i))); var context = new PofContext().With(x => x.RegisterPortableObjectType(0, typeof(Wrapper <>))); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, (object)testObj); } ms.Position = 0; using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { serializer.Deserialize(reader); } } }
public void SimpleTest() { var context = new PofContext(); context.RegisterPortableObjectType(0, typeof(DummyClass <>)); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { var writtenType = typeof(DummyClass <int>); Debug.WriteLine("Written Type: " + writtenType); serializer.Serialize(ms, writtenType); ms.Position = 0; var readType = serializer.Deserialize <Type>(ms); AssertEquals(readType, writtenType); Debug.WriteLine(" Read Type: " + readType); } }
public void RunTest() { const string name1 = "Henry has a first name!"; const string name2 = "Larry doesn't have a last name!"; var key1 = new PersonKey(name1); var key2 = new PersonKey(name2); var personEntry1 = new PersonEntry(key1, 10); var personEntry2 = new PersonEntry(key2, 5); var thresholdsByKey = new Dictionary <PersonKey, int>(); thresholdsByKey.Add(key1, 30); thresholdsByKey.Add(key2, 2); var levelRemovalProcessor = new RemovalByLevelThresholdProcessor(thresholdsByKey); var friendClearingProcessor = new FriendClearingProcessor(); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, levelRemovalProcessor); serializer.Serialize(writer, friendClearingProcessor); } ms.Position = 0; Console.WriteLine(ms.ToArray().ToHex()); using (var reader = new BinaryReader(ms)) { levelRemovalProcessor = serializer.Deserialize <RemovalByLevelThresholdProcessor>(reader); friendClearingProcessor = serializer.Deserialize <FriendClearingProcessor>(reader); } } var entry1 = new Entry <PersonKey, PersonEntry>(key1, personEntry1); var entry2 = new Entry <PersonKey, PersonEntry>(key2, personEntry2); friendClearingProcessor.Process(entry1); friendClearingProcessor.Process(entry2); levelRemovalProcessor.Process(entry1); levelRemovalProcessor.Process(entry2); assertTrue(entry1.IsPresent()); assertFalse(entry2.IsPresent()); }
public static int Main() { ICollectionFactory collectionFactory = new CollectionFactory(); ProxyGenerator proxyGenerator = new ProxyGenerator(); IThreadingFactory threadingFactory = new ThreadingFactory(); ISynchronizationFactory synchronizationFactory = new SynchronizationFactory(); IThreadingProxy threadingProxy = new ThreadingProxy(threadingFactory, synchronizationFactory); IDnsProxy dnsProxy = new DnsProxy(); ITcpEndPointFactory tcpEndPointFactory = new TcpEndPointFactory(dnsProxy); IStreamFactory streamFactory = new StreamFactory(); INetworkingInternalFactory networkingInternalFactory = new NetworkingInternalFactory(threadingProxy, streamFactory); ISocketFactory socketFactory = new SocketFactory(tcpEndPointFactory, networkingInternalFactory); INetworkingProxy networkingProxy = new NetworkingProxy(socketFactory, tcpEndPointFactory); IPofContext pofContext = new ClientPofContext(); IPofSerializer pofSerializer = new PofSerializer(pofContext); PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer); var serviceConfiguration = new ClientClusteringConfiguration(); var serviceClientFactory = new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory); var localEndPoint = tcpEndPointFactory.CreateLoopbackEndPoint(serviceConfiguration.Port); var reconnectAttempts = 10; var reconnectDelay = 1000; var serviceClient = TryConnectToEndpoint(reconnectAttempts, reconnectDelay, serviceClientFactory, serviceConfiguration); if (serviceClient == null) { Console.Error.WriteLine("Failed to connect to endpoint."); return(1); } else { var dispatcher = new DispatcherCommand("registered commands"); dispatcher.RegisterCommand(new ShutdownCommand(serviceClient)); // dispatcher.RegisterCommand(new ModCommand(serviceClient)); dispatcher.RegisterCommand(new ExitCommand()); dispatcher.RegisterCommand(new ServiceCommand(serviceClient)); var repl = new DargonREPL(dispatcher); repl.Run(); return(0); } }
public void Run() { var context = new PofContext(); context.RegisterPortableObjectType(1, typeof(Box)); var serializer = new PofSerializer(context); var obj = new object[] { null, 1, 2, 3 }; var box = new Box(obj); using (var ms = new MemoryStream()) using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, box); serializer.Serialize(writer, null); ms.Position = 0; var newBox = serializer.Deserialize <Box>(reader); var nullBox = serializer.Deserialize <Box>(reader); AssertEquals(box, newBox); AssertNull(nullBox); } }
public TrinketProxyEgg() { streamFactory = new StreamFactory(); processProxy = new ProcessProxy(); var pofContext = new PofContext().With(x => { x.MergeContext(new DspPofContext()); x.MergeContext(new TrinketsApiPofContext()); x.MergeContext(new TrinketsImplPofContext()); }); ICollectionFactory collectionFactory = new CollectionFactory(); IFileSystemProxy fileSystemProxy = new FileSystemProxy(streamFactory); IThreadingProxy threadingProxy = new ThreadingProxy(new ThreadingFactory(), new SynchronizationFactory()); var dnsProxy = new DnsProxy(); INetworkingProxy networkingProxy = new NetworkingProxy(new SocketFactory(new TcpEndPointFactory(dnsProxy), new NetworkingInternalFactory(threadingProxy, streamFactory)), new TcpEndPointFactory(dnsProxy)); pofSerializer = new PofSerializer(pofContext); PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer); ProxyGenerator proxyGenerator = new ProxyGenerator(); var serviceClientFactory = new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory); // construct libdsp local service node ClusteringConfiguration clusteringConfiguration = new ClientClusteringConfiguration(); ServiceClient localServiceClient = serviceClientFactory.Construct(clusteringConfiguration); keepaliveObjects.Add(localServiceClient); temporaryFileService = localServiceClient.GetService <TemporaryFileService>(); var processInjector = new ProcessInjectorImpl(); ProcessInjectionConfiguration processInjectionConfiguration = new ProcessInjectionConfigurationImpl(injectionAttempts: 10, injectionAttemptsDelay: 200); processInjectionService = new ProcessInjectionServiceImpl(processInjector, processInjectionConfiguration); IDtpNodeFactory transportNodeFactory = new DefaultDtpNodeFactory(); BootstrapConfigurationGenerator bootstrapConfigurationGenerator = new BootstrapConfigurationGeneratorImpl(); trinketInternalUtilities = new TrinketInternalUtilitiesImpl(fileSystemProxy); trinketDtpServerFactory = new TrinketDtpServerFactoryImpl(streamFactory, transportNodeFactory, bootstrapConfigurationGenerator); }
public static int Main() { ICollectionFactory collectionFactory = new CollectionFactory(); ProxyGenerator proxyGenerator = new ProxyGenerator(); IThreadingFactory threadingFactory = new ThreadingFactory(); ISynchronizationFactory synchronizationFactory = new SynchronizationFactory(); IThreadingProxy threadingProxy = new ThreadingProxy(threadingFactory, synchronizationFactory); IDnsProxy dnsProxy = new DnsProxy(); ITcpEndPointFactory tcpEndPointFactory = new TcpEndPointFactory(dnsProxy); IStreamFactory streamFactory = new StreamFactory(); INetworkingInternalFactory networkingInternalFactory = new NetworkingInternalFactory(threadingProxy, streamFactory); ISocketFactory socketFactory = new SocketFactory(tcpEndPointFactory, networkingInternalFactory); INetworkingProxy networkingProxy = new NetworkingProxy(socketFactory, tcpEndPointFactory); IPofContext pofContext = new ClientPofContext(); IPofSerializer pofSerializer = new PofSerializer(pofContext); PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer); var serviceConfiguration = new ClientClusteringConfiguration(); var serviceClientFactory = new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory); var localEndPoint = tcpEndPointFactory.CreateLoopbackEndPoint(serviceConfiguration.Port); var reconnectAttempts = 10; var reconnectDelay = 1000; var serviceClient = TryConnectToEndpoint(reconnectAttempts, reconnectDelay, serviceClientFactory, serviceConfiguration); if (serviceClient == null) { Console.Error.WriteLine("Failed to connect to endpoint."); return 1; } else { var dispatcher = new DispatcherCommand("registered commands"); dispatcher.RegisterCommand(new ShutdownCommand(serviceClient)); // dispatcher.RegisterCommand(new ModCommand(serviceClient)); dispatcher.RegisterCommand(new ExitCommand()); dispatcher.RegisterCommand(new ServiceCommand(serviceClient)); var repl = new DargonREPL(dispatcher); repl.Run(); return 0; } }
private ServiceClientFactoryImpl CreateServiceClientFactory(params PofContext[] pofContexts) { var proxyGenerator = new ProxyGenerator(); ICollectionFactory collectionFactory = new CollectionFactory(); IThreadingFactory threadingFactory = new ThreadingFactory(); ISynchronizationFactory synchronizationFactory = new SynchronizationFactory(); IThreadingProxy threadingProxy = new ThreadingProxy(threadingFactory, synchronizationFactory); IDnsProxy dnsProxy = new DnsProxy(); ITcpEndPointFactory tcpEndPointFactory = new TcpEndPointFactory(dnsProxy); IStreamFactory streamFactory = new StreamFactory(); INetworkingInternalFactory networkingInternalFactory = new NetworkingInternalFactory(threadingProxy, streamFactory); ISocketFactory socketFactory = new SocketFactory(tcpEndPointFactory, networkingInternalFactory); INetworkingProxy networkingProxy = new NetworkingProxy(socketFactory, tcpEndPointFactory); PofContext pofContext = new DspPofContext(); pofContexts.ForEach(pofContext.MergeContext); IPofSerializer pofSerializer = new PofSerializer(pofContext); PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer); PortableObjectBoxConverter portableObjectBoxConverter = new PortableObjectBoxConverter(streamFactory, pofSerializer); InvokableServiceContextFactory invokableServiceContextFactory = new InvokableServiceContextFactoryImpl(collectionFactory, portableObjectBoxConverter); return(new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory)); }
public void NestedArraysTest() { var dict = new SCG.Dictionary <int, float[][]>(); var random = new Random(0); for (var i = 0; i < 10; i++) { dict.Add(i, Util.Generate(i, x => Util.Generate(x, y => (float)random.NextDouble()))); } var context = new PofContext(); context.RegisterPortableObjectType(1, typeof(Wrapper)); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, new Wrapper(dict)); } ms.Position = 0; Console.WriteLine(ms.ToArray().ToHex()); using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { var wrapperCopy = (Wrapper)serializer.Deserialize(reader); var dictClone = (SCG.Dictionary <int, float[][]>)wrapperCopy.Value; AssertTrue(new ICL.HashSet <int>(dict.Keys).SetEquals(dictClone.Keys)); random = new Random(); for (var i = 0; i < 10; i++) { var arr = dict[i]; for (var j = 0; j < arr.Length; j++) { AssertTrue(new ICL.HashSet <float>(arr[j]).SetEquals(dictClone[i][j])); } } } } }
public void RunTest() { const string name1 = "Henry has a first name!"; const string name2 = "Larry doesn't have a last name!"; var key1 = new PersonKey(Guid.NewGuid(), name1); var key2 = new PersonKey(Guid.NewGuid(), name2); var personEntry1 = new PersonEntry(key1, 10); var personEntry2 = new PersonEntry(key2, 5); personEntry1.Friends.Add(new PersonFriend(0xAEF8329dF, "Mark")); personEntry2.Friends.Add(new PersonFriend(0xF8372D33F, "Henry")); personEntry2.Friends.Add(new PersonFriend(0x47928C3ED, "Jane")); var thresholdsByKey = new Dictionary <PersonKey, int>(); thresholdsByKey.Add(key1, 30); thresholdsByKey.Add(key2, 2); var levelRemovalProcessor = new RemovalByLevelThresholdProcessor(thresholdsByKey); var friendClearingProcessor = new FriendClearingProcessor(); var serializer = new PofSerializer(context); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, levelRemovalProcessor); serializer.Serialize(writer, friendClearingProcessor); } ms.Position = 0; Console.WriteLine(ms.ToArray().ToHex()); using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { levelRemovalProcessor = serializer.Deserialize <RemovalByLevelThresholdProcessor>(reader); friendClearingProcessor = serializer.Deserialize <FriendClearingProcessor>(reader); } } var entry1 = new Entry <PersonKey, PersonEntry>(key1, personEntry1); var entry2 = new Entry <PersonKey, PersonEntry>(key2, personEntry2); var originalEntry1 = entry1; var originalEntry2 = entry2; using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, entry1); serializer.Serialize(writer, entry2); } ms.Position = 0; Console.WriteLine(ms.ToArray().ToHex()); using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { entry1 = serializer.Deserialize <Entry <PersonKey, PersonEntry> >(reader); int frameLength = reader.ReadInt32(); var frameBody = reader.ReadBytes(frameLength); using (var innerMs = new MemoryStream(frameBody)) using (var innerReader = new BinaryReader(innerMs, Encoding.UTF8, true)) { entry2 = (Entry <PersonKey, PersonEntry>)serializer.Deserialize(innerReader, SerializationFlags.Lengthless, null); } } } friendClearingProcessor.Process(entry1); friendClearingProcessor.Process(entry2); levelRemovalProcessor.Process(entry1); levelRemovalProcessor.Process(entry2); AssertTrue(entry1.IsPresent()); AssertFalse(entry2.IsPresent()); using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { serializer.Serialize(writer, entry1); serializer.Serialize(writer, entry2); } ms.Position = 0; Console.WriteLine(ms.ToArray().ToHex()); using (var reader = new BinaryReader(ms, Encoding.UTF8, true)) { entry1 = serializer.Deserialize <Entry <PersonKey, PersonEntry> >(reader); entry2 = serializer.Deserialize <Entry <PersonKey, PersonEntry> >(reader); } } AssertTrue(entry1.IsPresent()); AssertFalse(entry2.IsPresent()); }
public static void EntryPoint(int i, CourierNetwork network) { ICollectionFactory collectionFactory = new CollectionFactory(); ObjectPoolFactory objectPoolFactory = new DefaultObjectPoolFactory(collectionFactory); IThreadingFactory threadingFactory = new ThreadingFactory(); ISynchronizationFactory synchronizationFactory = new SynchronizationFactory(); IThreadingProxy threadingProxy = new ThreadingProxy(threadingFactory, synchronizationFactory); GuidProxy guidProxy = new GuidProxyImpl(); IPofContext courierPofContext = new DargonCourierImplPofContext(); IPofSerializer courierSerializer = new PofSerializer(courierPofContext); Guid localIdentifier = guidProxy.NewGuid(); var endpoint = new CourierEndpointImpl(courierSerializer, localIdentifier, "node" + i); var networkContext = network.Join(endpoint); var networkBroadcaster = new NetworkBroadcasterImpl(endpoint, networkContext, courierSerializer); var messageContextPool = objectPoolFactory.CreatePool(() => new UnacknowledgedReliableMessageContext()); var unacknowledgedReliableMessageContainer = new UnacknowledgedReliableMessageContainer(messageContextPool); var messageDtoPool = objectPoolFactory.CreatePool(() => new CourierMessageV1()); var messageTransmitter = new MessageTransmitterImpl(guidProxy, courierSerializer, networkBroadcaster, unacknowledgedReliableMessageContainer, messageDtoPool); var messageSender = new MessageSenderImpl(guidProxy, unacknowledgedReliableMessageContainer, messageTransmitter); var acknowledgeDtoPool = objectPoolFactory.CreatePool(() => new CourierMessageAcknowledgeV1()); var messageAcknowledger = new MessageAcknowledgerImpl(networkBroadcaster, unacknowledgedReliableMessageContainer, acknowledgeDtoPool); var periodicAnnouncer = new PeriodicAnnouncerImpl(threadingProxy, courierSerializer, endpoint, networkBroadcaster); periodicAnnouncer.Start(); var periodicResender = new PeriodicResenderImpl(threadingProxy, unacknowledgedReliableMessageContainer, messageTransmitter); periodicResender.Start(); ReceivedMessageFactory receivedMessageFactory = new ReceivedMessageFactoryImpl(courierSerializer); MessageRouter messageRouter = new MessageRouterImpl(receivedMessageFactory); var peerRegistry = new PeerRegistryImpl(courierSerializer); var networkReceiver = new NetworkReceiverImpl(endpoint, networkContext, courierSerializer, messageRouter, messageAcknowledger, peerRegistry); networkReceiver.Initialize(); messageRouter.RegisterPayloadHandler <string>(m => { // Console.WriteLine(i + ": " + m.Payload); }); Thread.Sleep(3000); if (i == 0) { while (true) { for (var j = 0; j < 50; j++) { Console.WriteLine(unacknowledgedReliableMessageContainer.GetUnsentMessagesRemaining() + " pending"); var stopwatch = new Stopwatch(); stopwatch.Start(); var messagesRemaining = unacknowledgedReliableMessageContainer.GetUnsentMessagesRemaining(); var peers = peerRegistry.EnumeratePeers().ToArray(); for (var k = 0; k < 10000; k++) { foreach (var peer in peers) { messageSender.SendReliableUnicast(peer.Id, "Message " + j + " hello from " + i + ", " + peer.Id, MessagePriority.Low); } } var messagesAcked = unacknowledgedReliableMessageContainer.GetUnsentMessagesRemaining() - messagesRemaining + 10000; Console.WriteLine("Got " + (messagesAcked * peers.Length) + " acks in " + stopwatch.ElapsedMilliseconds + "ms (" + (messagesAcked * peers.Length / stopwatch.Elapsed.TotalSeconds) + " per second) " + messagesRemaining + " remaining"); Thread.Sleep(1); } for (var j = 0; j < 1000; j++) { Console.WriteLine(unacknowledgedReliableMessageContainer.GetUnsentMessagesRemaining() + " pending"); Thread.Sleep(1); } } } }
public RemoteCachePuppet(DistributedConfiguration configuration, NodeSession session) { this.configuration = configuration; this.session = session; this.serializer = new PofSerializer(configuration.PofContext); }
public static void Main(string[] args) { InitializeLogging(); // construct libwarty dependencies ICollectionFactory collectionFactory = new CollectionFactory(); // construct libwarty-proxies dependencies IStreamFactory streamFactory = new StreamFactory(); IFileSystemProxy fileSystemProxy = new FileSystemProxy(streamFactory); IThreadingFactory threadingFactory = new ThreadingFactory(); ISynchronizationFactory synchronizationFactory = new SynchronizationFactory(); IThreadingProxy threadingProxy = new ThreadingProxy(threadingFactory, synchronizationFactory); IDnsProxy dnsProxy = new DnsProxy(); ITcpEndPointFactory tcpEndPointFactory = new TcpEndPointFactory(dnsProxy); INetworkingInternalFactory networkingInternalFactory = new NetworkingInternalFactory(threadingProxy, streamFactory); ISocketFactory socketFactory = new SocketFactory(tcpEndPointFactory, networkingInternalFactory); INetworkingProxy networkingProxy = new NetworkingProxy(socketFactory, tcpEndPointFactory); IProcessProxy processProxy = new ProcessProxy(); // construct Castle.Core dependencies ProxyGenerator proxyGenerator = new ProxyGenerator(); // construct Platform Root Portable Object Format dependencies IPofContext pofContext = new PlatformPofContext(); IPofSerializer pofSerializer = new PofSerializer(pofContext); // construct libdargon.management dependencies var managementServerEndpoint = tcpEndPointFactory.CreateAnyEndPoint(kPlatformManagementPort); IMessageFactory managementMessageFactory = new MessageFactory(); IManagementSessionFactory managementSessionFactory = new ManagementSessionFactory(collectionFactory, threadingProxy, pofSerializer, managementMessageFactory); ILocalManagementServerContext managementServerContext = new LocalManagementServerContext(collectionFactory, managementSessionFactory); IManagementContextFactory managementContextFactory = new ManagementContextFactory(pofContext); ILocalManagementRegistry localManagementServerRegistry = new LocalManagementRegistry(pofSerializer, managementContextFactory, managementServerContext); IManagementServerConfiguration managementServerConfiguration = new ManagementServerConfiguration(managementServerEndpoint); var server = new LocalManagementServer(threadingProxy, networkingProxy, managementSessionFactory, managementServerContext, managementServerConfiguration); server.Initialize(); // construct system-state dependencies ICache <string, string> systemStateCache = new InMemoryCache <string, string>("SystemState", new ICacheIndex[0]); var platformSystemState = new PlatformSystemStateImpl(systemStateCache); localManagementServerRegistry.RegisterInstance(new PlatformSystemStateMob(platformSystemState)); // construct platform foundational dependencies ICacheFactory cacheFactory = new CacheFactory(); PlatformCacheService platformCacheService = new PlatformCacheServiceImpl(collectionFactory, cacheFactory).With(x => x.Initialize()); Caches specializedCaches = new Caches(platformCacheService); SpecializedCacheService specializedCacheService = new SpecializedCacheServiceImpl(specializedCaches); // construct backend account service dependencies ICache <string, long> emailToAccountIdCache = new InMemoryCache <string, long>(Accounts.Hydar.CacheNames.kEmailToAccountIdCache, new ICacheIndex[0]); ICache <long, AccountInformation> accountInfoByIdCache = new InMemoryCache <long, AccountInformation>(Accounts.Hydar.CacheNames.kAccountInfoByIdCache, new ICacheIndex[0]); IDistributedCounter accountIdCounter = specializedCacheService.GetCountingCache(Accounts.Hydar.CacheNames.kAccountIdCountingCacheName); IPasswordUtilities passwordUtilities = new PasswordUtilities(); AccountCache accountCache = new AccountCache(emailToAccountIdCache, accountInfoByIdCache, accountIdCounter, passwordUtilities); var accountService = new AccountServiceImpl(accountCache); localManagementServerRegistry.RegisterInstance(new AccountCacheMob(accountCache)); // construct frontend identity service dependencies ICache <string, Identity> identityByTokenHydarCache = new InMemoryCache <string, Identity>(Draek.Identities.Hydar.CacheNames.kIdentityByTokenCache, new ICacheIndex[0]); AuthenticationTokenFactory authenticationTokenFactory = new AuthenticationTokenFactoryImpl(); IdentityByTokenCache identityByTokenCache = new IdentityByTokenCacheImpl(identityByTokenHydarCache); IAuthenticationServiceConfiguration authenticationServiceConfiguration = new AuthenticationServiceConfiguration(platformSystemState); AuthenticationService authenticationService = new AuthenticationServiceImpl(accountService, authenticationTokenFactory, identityByTokenCache, authenticationServiceConfiguration); var identityService = new IdentityServiceProxyImpl(authenticationService); localManagementServerRegistry.RegisterInstance(new AuthenticationServiceMob(authenticationService)); localManagementServerRegistry.RegisterInstance(new IdentityCacheMob(identityByTokenCache)); localManagementServerRegistry.RegisterInstance(new AuthenticationServiceConfigurationMob(authenticationServiceConfiguration)); Application.Run(); }