コード例 #1
0
        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();
                }
            }
        }
コード例 #2
0
        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);
                    }
        }
コード例 #3
0
ファイル: Puppeteer.cs プロジェクト: briankchan/libimdg
 public DistributedConfiguration(string name, string masterAddress, int port, PofContext pofContext)
 {
     this.name          = name;
     this.masterAddress = masterAddress;
     this.port          = port;
     this.pofContext    = pofContext;
 }
コード例 #4
0
        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())));
                }
            }
        }
コード例 #5
0
        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]));
                }
            }
        }
コード例 #6
0
 public DictionarySerializationTests()
 {
     pofContext = new PofContext().With(x => {
         x.RegisterPortableObjectType(1, typeof(SerializableClass));
     });
     pofSerializer = new PofSerializer(pofContext);
 }
コード例 #7
0
        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);
        }
コード例 #8
0
 public PortableObjectIT()
 {
     context = new PofContext();
     context.RegisterPortableObjectType(0x11223344, typeof(PersonKey));
     context.RegisterPortableObjectType(0x55667788, typeof(PersonEntry));
     context.RegisterPortableObjectType(0x778899AA, typeof(RemovalByLevelThresholdProcessor));
     context.RegisterPortableObjectType(0x30291dea, typeof(FriendClearingProcessor));
 }
コード例 #9
0
 public LocalPuppeteerServer(ICachePuppeteer <K, V> puppeteer, DistributedConfiguration configuration)
 {
     this.cancellationToken = cancellationTokenSource.Token;
     this.puppeteer         = puppeteer;
     this.configuration     = configuration;
     this.pofContext        = configuration.PofContext;
     this.listenerThread    = new Thread(ListenerThreadStart).With(t => { t.IsBackground = true; }).With(t => t.Start());
     this.processorThread   = new Thread(ProcessorThreadStart).With(t => { t.IsBackground = false; }).With(t => t.Start());
 }
コード例 #10
0
 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();
 }
コード例 #11
0
        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();
        }
コード例 #12
0
        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));
                }
            }
        }
コード例 #13
0
        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(", "));
            }
        }
コード例 #14
0
        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);
                }
            }
        }
コード例 #15
0
        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);
            }
        }
コード例 #16
0
        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);
        }
コード例 #17
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);
                    }
        }
コード例 #18
0
        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]));
                        }
                    }
                }
            }
        }
コード例 #19
0
 public PofContextTests()
 {
     testObj = new PofContext();
 }
コード例 #20
0
ファイル: Puppeteer.cs プロジェクト: briankchan/libimdg
 public UniformlyDistributedConfiguration(int port, PofContext pofContext, int redundancyCount, uint hashesPerBucket = 0x00002000FU)
     : base(port, pofContext)
 {
     this.redundancyCount = redundancyCount;
     this.hashesPerBucket = hashesPerBucket;
 }