示例#1
0
        public async Task TestItemTransfer()
        {
            var processorNodeGuid = Guid.NewGuid();
            var processor         = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectNodeGrain <int, int> >(processorNodeGuid);
            await processor.SetFunction(new SerializableFunc <int, int>(_ => _));

            var itemsToSend = new List <int> {
                -1, 5, 30
            };

            var provider     = GrainClient.GetStreamProvider(StreamProvider);
            var testProvider = new StreamMessageSenderComposite <int>(provider, 1);
            await processor.SubscribeToStreams(await testProvider.GetOutputStreams());

            var testConsumer = new TransactionalStreamListConsumer <int>(provider);

            await SubscribeConsumer(processor, testConsumer);

            var tid = TransactionGenerator.GenerateTransactionId();
            await testProvider.StartTransaction(tid);

            await testProvider.SendMessage(new ItemMessage <int>(itemsToSend));

            await testProvider.EndTransaction(tid);

            CollectionAssert.AreEquivalent(itemsToSend, testConsumer.Items);

            await testProvider.TearDown();
        }
示例#2
0
        internal void GenerateTestTransactions()
        {
            var physicianKeys    = EncryptionHandler.GenerateNewKeys();
            var tempTransactions = new TransactionGenerator(physicianKeys.PrivateKey);

            var physicianRegistration = tempTransactions.InitializeAsNewPhysician(physicianKeys.PublicKey, "Austria", "Vienna", "Der Herbert");
            var physicianVoting       = transactionGenerator.GenerateVotingTransaction(physicianRegistration.TransactionId, true);

            var patientRegistration = tempTransactions.GeneratePatientRegistrationTransaction("Austria", "Vienna", "1992");
            var treatment           = tempTransactions.GenerateTreatmentTransaction(physicianRegistration.TransactionId, patientRegistration.TransactionId);
            var symptom             = tempTransactions.GenerateSymptomTransaction(treatment.TransactionId, new List <string>()
            {
                "R05", "R50.80"
            });
            var diagnoses = tempTransactions.GenerateDiagnosesTransaction(treatment.TransactionId, new List <string>()
            {
                "B34.2"
            });

            node.OnReceiveTransaction(physicianRegistration);
            node.OnReceiveTransaction(physicianVoting);
            Thread.Sleep(4000);
            node.OnReceiveTransaction(patientRegistration);
            node.OnReceiveTransaction(treatment);
            Thread.Sleep(1000);
            node.OnReceiveTransaction(symptom);
            node.OnReceiveTransaction(diagnoses);
        }
示例#3
0
        internal void SetupNewPublisher(string country, string region, string entityName)
        {
            var keys = EncryptionHandler.GenerateNewKeys();

            transactionGenerator = new TransactionGenerator(keys.PrivateKey);
            ITransaction registration = transactionGenerator.InitializeAsNewPublisher(keys.PublicKey, country, region, entityName);

            node.User = new UserProperties()
            {
                Username = currentUser
                ,
                Keys = keys
                ,
                PublisherAddress = registration.TransactionId
            };

            if (!node.IsChainInitialized())
            {
                ITransaction vote = transactionGenerator.GenerateVotingTransaction(registration.TransactionId, true);
                node.RequestChainInitialization(registration, vote);
            }
            else
            {
                node.OnReveiceTransaction(registration);
            }
        }
示例#4
0
        public void TransactionGeneration()
        {
            var keys = EncryptionHandler.GenerateNewKeys();
            TransactionGenerator transactionGenerator = new TransactionGenerator(keys.PrivateKey);
            var registration = transactionGenerator.InitializeAsNewPublisher(keys.PublicKey, "Austria", "Vienna", "Master");

            Assert.IsTrue(registration.ValidateTransactionIntegrity(keys.PublicKey));
        }
 private void GenerateTransactions()
 {
     for (int i = 0; i < TransactionAmount; i++)
     {
         Transactions[i] = TransactionGenerator
                           .GenerateTransaction(Assets[i % AssetAmount], Categories[i % CategoryAmount]);
     }
 }
示例#6
0
        public async Task <Guid> EnumerateToSubscribers(Guid?transactionId = null)
        {
            var tId = TransactionGenerator.GenerateTransactionId(transactionId);
            await OutputProducer.StartTransaction(tId);

            await OutputProducer.SendMessage(new ItemMessage <ContainerElement <T> >(Elements));

            await OutputProducer.EndTransaction(tId);

            return(tId);
        }
示例#7
0
        private void LoadState()
        {
            if (HasSavedState())
            {
                //Load Node state
                var           nodeState  = FileHandler.Read(currentUser + FileHandler.UserState_NodePath);
                XmlSerializer serializer = new XmlSerializer(node.GetType());
                node                 = (PhysicianNode)serializer.Deserialize(new StringReader(nodeState));
                currentUser          = node.User.Username;
                transactionGenerator = new TransactionGenerator(node.User.UserAddress, node.User.Keys.PrivateKey);

                //Load Patient file
                var patientState = FileHandler.Read(currentUser + FileHandler.UserState_PatientPath);
                serializer = new XmlSerializer(patients.GetType());
                patients   = (List <Entities.Patient>)serializer.Deserialize(new StringReader(patientState));
            }
        }
示例#8
0
        internal void LoadState()
        {
            if (HasSavedState())
            {
                var           nodeState  = FileHandler.Read(currentUser + FileHandler.UserState_NodePath);
                XmlSerializer serializer = new XmlSerializer(node.GetType());
                node                 = (PublisherNode)serializer.Deserialize(new StringReader(nodeState));
                currentUser          = node.User.Username;
                transactionGenerator = new TransactionGenerator(node.User.UserAddress, node.User.Keys.PrivateKey);

                //TODO read server state
                var serverState = FileHandler.Read(currentUser + FileHandler.UserState_ServerPath);
                serializer     = new XmlSerializer(serverSettings.GetType());
                serverSettings = (ServerAddress)serializer.Deserialize(new StringReader(serverState));
                node.SetSelfAddress(serverSettings);
            }
        }
示例#9
0
        internal void Start()
        {
            LoadState();
            transactionGenerator = new TransactionGenerator(node.User.UserAddress, node.User.Keys.PrivateKey);
            node.LoadChain();

            server = new Server
            {
                Services = { PublisherServer.BindService(new PublisherServerImpl(node, node, serverSettings)) },
                Ports    = { new ServerPort(serverSettings.Ip, serverSettings.Port, ServerCredentials.Insecure) }
            };
            server.Start();

            RequestChainDelta();
            UpdateKnownNodes();

            StartPublishing();
        }
示例#10
0
        public void ActAndAssert(EvaluateRulesTestInput input, List <GeneratedTransaction> output)
        {
            // Act
            var result = new TransactionGenerator().Generate(input.Rules, input.BankRows);

            // Assert
            Assert.AreEqual(result.Count, output.Count);
            Assert.AreEqual(result.Count, output.Count);
            Assert.AreEqual(result.Count, output.Count);

            for (int i = 0; i < result.Count; i++)
            {
                var a = JsonConvert.SerializeObject(result[i]);
                var b = JsonConvert.SerializeObject(output[i]);
                Assert.AreEqual(a, b);
            }
            // Do this for other objects as well
        }
示例#11
0
文件: Misc.cs 项目: szum7/MoneyStats
        public void TestRuleEvaluation()
        {
            // Arrange
            var generator = new TransactionGenerator();

#if true
            var data = new RuleEvalData()
            {
                RuleIds = new List <int> {
                    1
                }, BankRowIds = new List <int> {
                    7, 8, 9
                }
            };
#endif
#if false
            var data = new RuleEvalData()
            {
                RuleIds = new List <int> {
                    3
                }, BankRowIds = new List <int> {
                    15, 16, 17, 18, 19, 20
                }
            };
            var data = new RuleEvalData()
            {
                RuleIds = new List <int> {
                    2
                }, BankRowIds = new List <int> {
                    10, 11, 12, 13, 14
                }
            };
#endif

            var bankRows = new BankRowRepository().GetOnIds(data.BankRowIds);
            var rules    = new RuleRepository().GetOnIdsWithEntitiesInDepth(data.RuleIds);

            // Act
            generator.Generate(rules, bankRows);

            // Assert
            Assert.AreEqual(1, 1);
        }
示例#12
0
        private async Task TestMultiLevelDataPass <TIn, TOut>(
            Func <StreamMessageSenderComposite <TIn>, DefaultStreamProcessorAggregateFactory, Task <IStreamProcessorChain <TOut, DefaultStreamProcessorAggregateFactory> > >
            createStreamProcessingChainFunc, List <List <TIn> > inputChunks, List <List <TOut> > outputChunks,
            Action <List <TOut>, List <TOut> > resultAssertion)
        {
            if (inputChunks.Count != outputChunks.Count)
            {
                throw new ArgumentException();
            }

            var source = new StreamMessageSenderComposite <TIn>(_provider, 2);

            var query = await createStreamProcessingChainFunc(source, _factory);

            var queryOutputStreams = await query.GetOutputStreams();

            var resultConsumer = new TestTransactionalTransactionalStreamConsumerAggregate <TOut>(_provider);
            await resultConsumer.SetInput(queryOutputStreams);

            Assert.AreEqual(2, queryOutputStreams.Count);
            Assert.AreEqual(0, resultConsumer.Items.Count);

            for (int i = 0; i < inputChunks.Count; i++)
            {
                var input          = inputChunks[i];
                var expectedOutput = outputChunks[i];

                var tid = TransactionGenerator.GenerateTransactionId();
                await source.StartTransaction(tid);

                await source.SendMessage(new ItemMessage <TIn>(input));

                await source.EndTransaction(tid);

                resultAssertion(expectedOutput, resultConsumer.Items);
                resultConsumer.Items.Clear();
            }

            await query.TearDown();

            await resultConsumer.TearDown();
        }
示例#13
0
        public async Task TestOneLevelSelectManyDataPass()
        {
            var inputChunks = new List <int>()
            {
                5, 213, 23, -21, 23, 99
            }.BatchIEnumerable(2).ToList();
            var outputChunks = inputChunks.SelectMany(i => i).Select(i => (i > 0) ? Enumerable.Range(0, i).ToList() : i.SingleValueToList()).ToList();

            var source  = new StreamMessageSenderComposite <int>(_provider, 2);
            var factory = new DefaultStreamProcessorAggregateFactory(GrainFactory);
            var query   = await source.SimpleSelectMany(i => (i > 0)?Enumerable.Range(0, i) : i.SingleValueToList(), factory);

            var queryOutputStreams = await query.GetOutputStreams();

            var resultConsumer = new TestTransactionalTransactionalStreamConsumerAggregate <int>(_provider);
            await resultConsumer.SetInput(queryOutputStreams);

            Assert.AreEqual(2, queryOutputStreams.Count);
            Assert.AreEqual(0, resultConsumer.Items.Count);

            for (int i = 0; i < inputChunks.Count; i++)
            {
                var input          = inputChunks[i];
                var expectedOutput = new List <int>();
                expectedOutput.AddRange(outputChunks[2 * i]);
                expectedOutput.AddRange(outputChunks[2 * i + 1]);

                var tid = TransactionGenerator.GenerateTransactionId();
                await source.StartTransaction(tid);

                await source.SendMessage(new ItemMessage <int>(input));

                await source.EndTransaction(tid);

                CollectionAssert.AreEquivalent(expectedOutput, resultConsumer.Items);
                resultConsumer.Items.Clear();
            }

            await query.TearDown();

            await resultConsumer.TearDown();
        }
示例#14
0
        public void RegistrateAndVotePhysician()
        {
            #region Set up Publisher
            var keysPublisher = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorPublisher = new TransactionGenerator(keysPublisher.PrivateKey);
            var registrationPublisher = transactionGeneratorPublisher.InitializeAsNewPublisher(keysPublisher.PublicKey, "Austria", "Vienna", "Publisher");
            var votePublisher         = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPublisher.TransactionId, true);

            PublisherNode publisher = new PublisherNode();
            publisher.User = new NodeManagement.Entities.UserProperties()
            {
                Keys        = keysPublisher,
                UserAddress = registrationPublisher.TransactionId,
                Username    = "******"
            };

            publisher.InitializeEmptyChain(registrationPublisher, votePublisher);

            Assert.IsTrue(publisher.participantHandler.HasPublisher(registrationPublisher.TransactionId));
            #endregion

            #region Generate registration for physician
            var keysPhysician = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorPhyisician = new TransactionGenerator(keysPhysician.PrivateKey);
            var registrationPhysician = transactionGeneratorPhyisician.InitializeAsNewPhysician(keysPhysician.PublicKey, "Austria", "Vienna", "Physician");
            var votePhysician         = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPhysician.TransactionId, true);
            #endregion

            publisher.OnReceiveTransaction(registrationPhysician);

            Assert.IsFalse(publisher.participantHandler.HasPhysician(registrationPhysician.TransactionId));

            publisher.OnReceiveTransaction(votePhysician);

            publisher.BundleOpenTransactionsManually();
            publisher.PublishOpenBlocks(publisher);

            Assert.IsTrue(publisher.participantHandler.HasPhysician(registrationPhysician.TransactionId));
        }
示例#15
0
        public void AddTransactionToBlock()
        {
            var keys = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGenerator = new TransactionGenerator(keys.PrivateKey);
            var registration = transactionGenerator.InitializeAsNewPublisher(keys.PublicKey, "Austria", "Vienna", "Master");

            Block block = new Block();

            block.Index     = 0;
            block.Publisher = registration.TransactionId;

            block.AddTransaction(registration);
            Assert.IsTrue(block.TransactionList.Count == 1);

            block.AddTransaction(registration);
            Assert.IsTrue(block.TransactionList.Count == 2);

            block.Sign(keys.PrivateKey);
            Assert.IsTrue(block.ValidateBlockIntegrity(keys.PublicKey));
        }
示例#16
0
        public void AddBlockToChain()
        {
            var keys = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGenerator = new TransactionGenerator(keys.PrivateKey);
            var registration = transactionGenerator.InitializeAsNewPublisher(keys.PublicKey, "Austria", "Vienna", "Master");
            var vote         = transactionGenerator.GenerateVotingTransaction(registration.TransactionId, true);

            Block block = new Block();

            block.Index     = 0;
            block.Publisher = registration.TransactionId;

            block.AddTransaction(registration);
            block.AddTransaction(vote);
            block.Sign(keys.PrivateKey);

            Chain chain = new Chain();

            chain.Add(block);

            Assert.IsTrue(chain.ValidateContextual(new ParticipantHandler(), null));
        }
示例#17
0
        internal void StartAsNewPublisher(string country, string region, string entityName, ServerAddress selfAddress, ServerAddress initializerAddress)
        {
            var keys = EncryptionHandler.GenerateNewKeys();

            transactionGenerator = new TransactionGenerator(keys.PrivateKey);
            ITransaction registration = transactionGenerator.InitializeAsNewPublisher(keys.PublicKey, country, region, entityName);

            node.User = new UserProperties()
            {
                Username = currentUser
                ,
                Keys = keys
                ,
                UserAddress = registration.TransactionId
            };

            serverSettings = selfAddress;
            node.SetSelfAddress(serverSettings);

            Start();

            if (initializerAddress != null)
            {
                RegisterAt(initializerAddress);
                UpdateKnownNodes();
            }

            if (!node.IsChainInitialized())
            {
                ITransaction vote = transactionGenerator.GenerateVotingTransaction(registration.TransactionId, true);
                node.InitializeEmptyChain(registration, vote);
            }
            else
            {
                node.OnReceiveTransaction(registration);
            }
        }
示例#18
0
        public async Task TestItemAggregation()
        {
            var aggregate = GrainClient.GrainFactory.GetGrain <IStreamProcessorSelectAggregate <int, int> >(Guid.NewGuid());
            await aggregate.SetFunction(new SerializableFunc <int, int>(_ => _));

            var itemsToSend = new List <int> {
                1, 5, 32, -12
            };

            var provider       = GrainClient.GetStreamProvider(StreamProvider);
            var inputAggregate = new StreamMessageSenderComposite <int>(provider, 2);

            await aggregate.SetInput(await inputAggregate.GetOutputStreams());

            Assert.AreEqual(2, (await aggregate.GetOutputStreams()).Count);

            var consumerAggregate = new TestTransactionalTransactionalStreamConsumerAggregate <int>(provider);
            await consumerAggregate.SetInput(await aggregate.GetOutputStreams());

            var tid = TransactionGenerator.GenerateTransactionId();
            await inputAggregate.StartTransaction(tid);

            await inputAggregate.SendMessage(new ItemMessage <int>(itemsToSend));

            await inputAggregate.EndTransaction(tid);

            var resultItems = consumerAggregate.Items;

            Assert.AreEqual(4, resultItems.Count);
            CollectionAssert.AreEquivalent(itemsToSend, resultItems);

            Assert.IsFalse(await consumerAggregate.AllConsumersTearDownCalled());
            await inputAggregate.TearDown();

            Assert.IsTrue(await consumerAggregate.AllConsumersTearDownCalled());
        }
示例#19
0
        internal void StartAsNewPhysician(string country, string region, string fullname, ServerAddress initializerAddress)
        {
            var keys = EncryptionHandler.GenerateNewKeys();

            transactionGenerator = new TransactionGenerator(keys.PrivateKey);
            ITransaction registration = transactionGenerator.InitializeAsNewPhysician(keys.PublicKey, country, region, fullname);

            node.User = new UserProperties()
            {
                Username = currentUser
                ,
                Keys = keys
                ,
                UserAddress = registration.TransactionId
            };

            Start();

            node.AddServerAddress(initializerAddress);
            UpdateKnownNodes();
            UpdatePendingPhysicians();

            node.SendTransaction(registration);
        }
示例#20
0
 public Importer(WriteConfig writeConfig)
 {
     this.writeConfig     = writeConfig;
     cardGenerator        = new CardGenerator();
     transactionGenerator = new TransactionGenerator(writeConfig.NumberOfCardBulk * writeConfig.CardBulkSize);
 }
示例#21
0
        public void ConsolidateChains()
        {
            #region Set up Publisher A
            var keysA = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorA = new TransactionGenerator(keysA.PrivateKey);
            var registrationA = transactionGeneratorA.InitializeAsNewPublisher(keysA.PublicKey, "Austria", "Vienna", "PublisherA");
            var voteA         = transactionGeneratorA.GenerateVotingTransaction(registrationA.TransactionId, true);

            PublisherNode publisherA = new PublisherNode();
            publisherA.User = new NodeManagement.Entities.UserProperties()
            {
                Keys        = keysA,
                UserAddress = registrationA.TransactionId,
                Username    = "******"
            };

            publisherA.InitializeEmptyChain(registrationA, voteA);
            #endregion

            #region Set up Publisher B
            var keysB = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorB = new TransactionGenerator(keysB.PrivateKey);
            var registrationB = transactionGeneratorB.InitializeAsNewPublisher(keysB.PublicKey, "Austria", "Vienna", "PublisherB");

            PublisherNode publisherB = new PublisherNode();
            publisherB.User = new NodeManagement.Entities.UserProperties()
            {
                Keys        = keysB,
                UserAddress = registrationB.TransactionId,
                Username    = "******"
            };

            publisherB.OnReceiveChain(publisherA.GetChain());

            publisherB.OnReceiveTransaction(registrationB);
            publisherB.BundleOpenTransactionsManually();
            publisherB.PublishOpenBlocks(publisherB);
            #endregion

            #region Authorize Publisher B
            publisherA.OnReceiveChain(publisherB.GetChainDelta(0));

            Assert.AreEqual(publisherA.GetChain().AsXML(), publisherB.GetChain().AsXML());

            var voteB = transactionGeneratorA.GenerateVotingTransaction(registrationB.TransactionId, true);
            publisherA.OnReceiveTransaction(voteB);
            publisherA.BundleOpenTransactionsManually();
            publisherA.PublishOpenBlocks(publisherA);
            publisherB.OnReceiveChain(publisherA.GetChainDelta(1));

            Assert.AreEqual(publisherA.GetChain().AsXML(), publisherB.GetChain().AsXML());
            #endregion

            var transactionA = transactionGeneratorA.GenerateVotingTransaction(registrationB.TransactionId, true);
            var transactionB = transactionGeneratorB.GenerateVotingTransaction(registrationA.TransactionId, true);
            var transactionC = transactionGeneratorB.GenerateVotingTransaction(registrationA.TransactionId, true);

            #region Send transactions to publishers
            publisherA.OnReceiveTransaction(transactionA);
            publisherA.BundleOpenTransactionsManually();
            publisherA.PublishOpenBlocks(publisherA);

            publisherB.OnReceiveTransaction(transactionB);
            publisherB.BundleOpenTransactionsManually();
            publisherB.PublishOpenBlocks(publisherB);

            publisherB.OnReceiveTransaction(transactionC);
            publisherB.BundleOpenTransactionsManually();
            publisherB.PublishOpenBlocks(publisherB);
            #endregion

            publisherA.OnReceiveChain(publisherB.GetChainDelta(2));

            var hit = from t in publisherA.GetChain().GetTransactions()
                      where t.TransactionId == transactionA.TransactionId
                      select t;
            Assert.AreEqual(hit.Count(), 0);

            publisherA.BundleOpenTransactionsManually();
            publisherA.PublishOpenBlocks(publisherA);

            hit = from t in publisherA.GetChain().GetTransactions()
                  where t.TransactionId == transactionA.TransactionId
                  select t;
            Assert.AreEqual(1, hit.Count());
        }
示例#22
0
        public void ProcessPatientData()
        {
            #region Set up Publisher
            var keysPublisher = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorPublisher = new TransactionGenerator(keysPublisher.PrivateKey);
            var registrationPublisher = transactionGeneratorPublisher.InitializeAsNewPublisher(keysPublisher.PublicKey, "Austria", "Vienna", "Publisher");
            var votePublisher         = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPublisher.TransactionId, true);

            PublisherNode publisher = new PublisherNode();
            publisher.User = new NodeManagement.Entities.UserProperties()
            {
                Keys        = keysPublisher,
                UserAddress = registrationPublisher.TransactionId,
                Username    = "******"
            };

            publisher.InitializeEmptyChain(registrationPublisher, votePublisher);
            Assert.IsTrue(publisher.participantHandler.HasPublisher(registrationPublisher.TransactionId));
            #endregion

            #region Register physician
            var keysPhysician = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorPhyisician = new TransactionGenerator(keysPhysician.PrivateKey);
            var registrationPhysician = transactionGeneratorPhyisician.InitializeAsNewPhysician(keysPhysician.PublicKey, "Austria", "Vienna", "Physician");
            var votePhysician         = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPhysician.TransactionId, true);

            publisher.OnReceiveTransaction(registrationPhysician);
            publisher.OnReceiveTransaction(votePhysician);

            publisher.BundleOpenTransactionsManually();
            publisher.PublishOpenBlocks(publisher);

            Assert.IsTrue(publisher.participantHandler.HasPhysician(registrationPhysician.TransactionId));
            #endregion

            var patientA = transactionGeneratorPhyisician.GeneratePatientRegistrationTransaction("Austria", "Vienna", "1990");

            publisher.OnReceiveTransaction(patientA);

            Assert.IsTrue(publisher.participantHandler.parkedPatients.Contains(patientA));
            Assert.IsFalse(publisher.participantHandler.HasPatient(patientA.TransactionId));

            publisher.BundleOpenTransactionsManually();
            publisher.PublishOpenBlocks(publisher);

            Assert.IsTrue(publisher.participantHandler.parkedPatients.Contains(patientA));
            Assert.IsFalse(publisher.participantHandler.HasPatient(patientA.TransactionId));

            for (int i = 0; i < 2; i++)
            {
                publisher.OnReceiveTransaction(
                    transactionGeneratorPhyisician.GeneratePatientRegistrationTransaction("Austria", "Vienna", "1990")
                    );
            }

            Assert.IsTrue(publisher.participantHandler.parkedPatients.Contains(patientA));
            Assert.IsFalse(publisher.participantHandler.HasPatient(patientA.TransactionId));

            publisher.EvaluateParkedTransactions();
            publisher.BundleOpenTransactionsManually();
            publisher.PublishOpenBlocks(publisher);

            Assert.IsFalse(publisher.participantHandler.parkedPatients.Contains(patientA));
            Assert.IsTrue(publisher.participantHandler.HasPatient(patientA.TransactionId));
        }
示例#23
0
        public void MeasureTransactionProcessing()
        {
            #region Set up Publisher
            var keysPublisher = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorPublisher = new TransactionGenerator(keysPublisher.PrivateKey);
            var registrationPublisher = transactionGeneratorPublisher.InitializeAsNewPublisher(keysPublisher.PublicKey, "Austria", "Vienna", "Publisher");
            var votePublisher         = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPublisher.TransactionId, true);

            PublisherNode publisher = new PublisherNode();
            publisher.User = new NodeManagement.Entities.UserProperties()
            {
                Keys        = keysPublisher,
                UserAddress = registrationPublisher.TransactionId,
                Username    = "******"
            };

            publisher.InitializeEmptyChain(registrationPublisher, votePublisher);
            Assert.IsTrue(publisher.participantHandler.HasPublisher(registrationPublisher.TransactionId));
            #endregion

            var referencePhysicianKeys      = EncryptionHandler.GenerateNewKeys();
            var referencePhysicianGenerator = new TransactionGenerator(referencePhysicianKeys.PrivateKey);
            var referencePhysician          = referencePhysicianGenerator.InitializeAsNewPhysician(referencePhysicianKeys.PrivateKey, "Austria", "Vienna", "Physician");
            var referencePhysicianVote      = transactionGeneratorPublisher.GenerateVotingTransaction(referencePhysician.TransactionId, true);

            var referencePatient   = referencePhysicianGenerator.GeneratePatientRegistrationTransaction("Austria", "Vienna", "1990");
            var referenceTreatment = referencePhysicianGenerator.GenerateTreatmentTransaction(referencePhysician.TransactionId, referencePatient.TransactionId);

            publisher.OnReceiveTransaction(referencePhysician);
            publisher.OnReceiveTransaction(referencePhysicianVote);
            publisher.OnReceiveTransaction(referencePatient);
            publisher.OnReceiveTransaction(referenceTreatment);

            publisher.BundleOpenTransactionsManually();
            publisher.PublishOpenBlocks(publisher);

            Assert.AreEqual(1, publisher.GetChain().Blockhead.Index);

            Random random = new Random();

            for (int i = 0; i < 50000; i++)
            {
                int choice = random.Next(1, 6);

                switch (choice)
                {
                case 1:
                    var keysNewPhysician = EncryptionHandler.GenerateNewKeys();

                    TransactionGenerator transactionGeneratorNewPhysician = new TransactionGenerator(keysNewPhysician.PrivateKey);
                    var transaction = transactionGeneratorNewPhysician.InitializeAsNewPhysician(keysNewPhysician.PublicKey, "Austria", "Vienna", "Physician");

                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    publisher.OnReceiveTransaction(transaction);
                    stopwatch.Stop();

                    string log = "PHYSICIAN\t"
                                 + (i % maxBlockSize)
                                 + "\t" + maxBlockSize
                                 + "\t" + publisher.GetChain().Blockhead.Index
                                 + "\t" + publisher.GetChain().GetTransactions().Count
                                 + "\t" + stopwatch.ElapsedMilliseconds
                                 + "\t" + GetRAMUsage()
                                 + "\n";
                    FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log);
                    break;

                case 2:
                    transaction = referencePhysicianGenerator.GeneratePatientRegistrationTransaction("Austria", "Vienna", "Patient");

                    stopwatch = new Stopwatch();
                    stopwatch.Start();
                    publisher.OnReceiveTransaction(transaction);
                    stopwatch.Stop();

                    log = "PATIENT\t"
                          + (i % maxBlockSize)
                          + "\t" + maxBlockSize
                          + "\t" + publisher.GetChain().Blockhead.Index
                          + "\t" + publisher.GetChain().GetTransactions().Count
                          + "\t" + stopwatch.ElapsedMilliseconds
                          + "\t" + GetRAMUsage()
                          + "\n";
                    FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log);
                    break;

                case 3:
                    var patients = (from x in publisher.GetChain().GetTransactions()
                                    where x.GetType() == typeof(PatientRegistrationTransaction)
                                    select x.TransactionId).ToList();
                    var p = patients.Count() > 1 ? patients[random.Next(1, patients.Count()) - 1] : referencePatient.TransactionId;
                    transaction = referencePhysicianGenerator.GenerateTreatmentTransaction(referencePhysician.TransactionId, p);

                    stopwatch = new Stopwatch();
                    stopwatch.Start();
                    publisher.OnReceiveTransaction(transaction);
                    stopwatch.Stop();

                    log = "TREATMENT\t"
                          + (i % maxBlockSize)
                          + "\t" + maxBlockSize
                          + "\t" + publisher.GetChain().Blockhead.Index
                          + "\t" + publisher.GetChain().GetTransactions().Count
                          + "\t" + stopwatch.ElapsedMilliseconds
                          + "\t" + GetRAMUsage()
                          + "\n";
                    FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log);
                    break;

                case 4:
                    var treatments = (from x in publisher.GetChain().GetTransactions()
                                      where x.GetType() == typeof(TreatmentTransaction)
                                      select x.TransactionId).ToList();
                    var t = treatments.Count() > 1 ? treatments[random.Next(1, treatments.Count()) - 1] : referenceTreatment.TransactionId;
                    transaction = referencePhysicianGenerator.GenerateSymptomTransaction(t, new List <string>()
                    {
                        "Symptom"
                    });

                    stopwatch = new Stopwatch();
                    stopwatch.Start();
                    publisher.OnReceiveTransaction(transaction);
                    stopwatch.Stop();

                    log = "SYMPTOM\t"
                          + (i % maxBlockSize)
                          + "\t" + maxBlockSize
                          + "\t" + publisher.GetChain().Blockhead.Index
                          + "\t" + publisher.GetChain().GetTransactions().Count
                          + "\t" + stopwatch.ElapsedMilliseconds
                          + "\t" + GetRAMUsage()
                          + "\n";
                    FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log);
                    break;

                case 5:
                    transaction = transactionGeneratorPublisher.GenerateVotingTransaction(referencePhysician.TransactionId, true);

                    stopwatch = new Stopwatch();
                    stopwatch.Start();
                    publisher.OnReceiveTransaction(transaction);
                    stopwatch.Stop();

                    log = "VOTING\t"
                          + (i % maxBlockSize)
                          + "\t" + maxBlockSize
                          + "\t" + publisher.GetChain().Blockhead.Index
                          + "\t" + publisher.GetChain().GetTransactions().Count
                          + "\t" + stopwatch.ElapsedMilliseconds
                          + "\t" + GetRAMUsage()
                          + "\n";
                    FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log);
                    break;

                default:
                    break;
                }

                publisher.participantHandler.EvaluateParkedTransactions();

                if (i % maxBlockSize == 0)
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();
                    publisher.BundleOpenTransactionsManually();
                    publisher.PublishOpenBlocks(publisher);
                    stopwatch.Stop();

                    string log = "BLOCK\t"
                                 + (i % maxBlockSize)
                                 + "\t" + maxBlockSize
                                 + "\t" + publisher.GetChain().Blockhead.Index
                                 + "\t" + publisher.GetChain().GetTransactions().Count
                                 + "\t" + stopwatch.ElapsedMilliseconds
                                 + "\n";
                    FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\BlockLog.txt", log);

                    stopwatch = new Stopwatch();
                    stopwatch.Start();
                    publisher.ValidateChain();
                    stopwatch.Stop();

                    log = "VALIDATION\t"
                          + (i % maxBlockSize)
                          + "\t" + maxBlockSize
                          + "\t" + publisher.GetChain().Blockhead.Index
                          + "\t" + publisher.GetChain().GetTransactions().Count
                          + "\t" + stopwatch.ElapsedMilliseconds
                          + "\n";
                    FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\ValidationLog.txt", log);

                    QueryNode query = new QueryNode();
                    query.UpdateChain(publisher.GetChain());

                    stopwatch = new Stopwatch();
                    stopwatch.Start();
                    query.ExtractData((PatientRegistrationTransaction p) => true,
                                      (TreatmentTransaction t) => true,
                                      (SymptomsTransaction s) => true,
                                      (DiagnosesTransaction d) => true);
                    stopwatch.Stop();

                    log = "QUERY\t"
                          + (i % maxBlockSize)
                          + "\t" + maxBlockSize
                          + "\t" + publisher.GetChain().Blockhead.Index
                          + "\t" + publisher.GetChain().GetTransactions().Count
                          + "\t" + stopwatch.ElapsedMilliseconds
                          + "\n";
                    FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\QueryLog.txt", log);
                }
            }
        }
示例#24
0
 public BankSimulator(UIHelper uiHelper, int numTellers, int numCustomers, int maxTransaction,
                      decimal customerBalance, decimal bankBalance, decimal customerGoal)
 {
     bank = new Bank(uiHelper, CtSource.Token, this, numTellers, numCustomers, customerBalance, bankBalance, customerGoal);
     transactionGenerator = new TransactionGenerator(uiHelper, CtSource.Token, bank.Queue, bank.Customers, maxTransaction);
 }
示例#25
0
        public void RegistrateAndVotePublisher()
        {
            #region Set up Publisher A
            var keysA = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorA = new TransactionGenerator(keysA.PrivateKey);
            var registrationA = transactionGeneratorA.InitializeAsNewPublisher(keysA.PublicKey, "Austria", "Vienna", "PublisherA");
            var voteA         = transactionGeneratorA.GenerateVotingTransaction(registrationA.TransactionId, true);

            PublisherNode publisherA = new PublisherNode();
            publisherA.User = new NodeManagement.Entities.UserProperties()
            {
                Keys        = keysA,
                UserAddress = registrationA.TransactionId,
                Username    = "******"
            };

            publisherA.InitializeEmptyChain(registrationA, voteA);

            Assert.IsTrue(publisherA.participantHandler.HasPublisher(registrationA.TransactionId));
            #endregion

            #region Set up Publisher B
            var keysB = EncryptionHandler.GenerateNewKeys();

            TransactionGenerator transactionGeneratorB = new TransactionGenerator(keysB.PrivateKey);
            var registrationB = transactionGeneratorB.InitializeAsNewPublisher(keysB.PublicKey, "Austria", "Vienna", "PublisherB");

            PublisherNode publisherB = new PublisherNode();
            publisherB.User = new NodeManagement.Entities.UserProperties()
            {
                Keys        = keysB,
                UserAddress = registrationB.TransactionId,
                Username    = "******"
            };

            publisherB.OnReceiveChain(publisherA.GetChain());

            publisherB.OnReceiveTransaction(registrationB);
            publisherB.BundleOpenTransactionsManually();
            publisherB.PublishOpenBlocks(publisherB);
            #endregion

            Assert.IsFalse(publisherA.participantHandler.HasPublisher(registrationB.TransactionId));
            Assert.IsFalse(publisherB.participantHandler.HasPublisher(registrationB.TransactionId));

            #region Authorize Publisher B
            publisherA.OnReceiveChain(publisherB.GetChainDelta(0));

            Assert.AreEqual(publisherA.GetChain().AsXML(), publisherB.GetChain().AsXML());

            var voteB = transactionGeneratorA.GenerateVotingTransaction(registrationB.TransactionId, true);
            publisherA.OnReceiveTransaction(voteB);
            publisherA.BundleOpenTransactionsManually();
            publisherA.PublishOpenBlocks(publisherA);
            publisherB.OnReceiveChain(publisherA.GetChainDelta(1));

            Assert.AreEqual(publisherA.GetChain().AsXML(), publisherB.GetChain().AsXML());
            #endregion

            Assert.IsTrue(publisherA.participantHandler.HasPublisher(registrationB.TransactionId));
            Assert.IsTrue(publisherB.participantHandler.HasPublisher(registrationB.TransactionId));
        }
示例#26
0
 public PhysicianController()
 {
     node = new PhysicianNode();
     transactionGenerator = new TransactionGenerator();
 }