Exemplo n.º 1
0
        private async void RealizedPrescriptionBlockChainInit()
        {
            blockChainClient_realized = new BlockChainClient(NetworkUtils.GetLocalIPAddress().ToString(), "6067");

            realizedPrescriptions = new BlockChain(blockChainClient_realized, "realizedPrescriptionsBlockChain");

            blockChainServer_realized = new BlockChainServer(realizedPrescriptions, NetworkUtils.GetLocalIPAddress().ToString(), "6067");
            blockChainServer_realized.Start();

            foreach (string ipAddress in availableIpAddresses)
            {
                if (!ipAddress.Equals(NetworkUtils.GetLocalIPAddress().ToString()))
                {
                    blockChainClient_realized.Connect(ipAddress, "6067");
                }
            }

            if (realizedPrescriptions.blockChainClient.GetNumberOfConnectedPeers() >= 2)
            {
                realizedPrescriptions.UpdateBlockChain();
            }
            else
            {
                TraceingManager.Message(LogMessages.LessThen2pearsMessage);
            }
            TraceingManager.Message(LogMessages.RealizedPrescryptionsBlockChainInitializedMessage);
        }
Exemplo n.º 2
0
        public bool RealizePrescription(string prescriptionId, string pharmacistId)
        {
            if (realizedPrescriptions.blockChainClient.GetNumberOfConnectedPeers() >= 2)
            {
                if (realizedPrescriptions.Find(prescriptionId) == null)
                {
                    Block block = prescriptions.Find(prescriptionId);

                    if (block != null)
                    {
                        block.GetPrescription().pharmacistId = pharmacistId;

                        realizedPrescriptions.Add(block.GetPrescription());

                        return(true);
                    }
                    else
                    {
                        // TODO Logger
                        // Prescription not found.
                        return(false);
                    }
                }
                else
                {
                    // TODO Logger
                    // Prescription is already realized.
                    return(false);
                }
            }

            TraceingManager.Message(LogMessages.LessThen2pearsMessage);
            return(false);
        }
Exemplo n.º 3
0
        public int GetNumberOfRealizedPrescriptions()
        {
            if (realizedPrescriptions.blockChainClient.GetNumberOfConnectedPeers() >= 2)
            {
                return(realizedPrescriptions.GetSize() - 1);
            }

            TraceingManager.Message(LogMessages.LessThen2pearsMessage);
            return(0);
        }
Exemplo n.º 4
0
        public async void InitializeBlockChains()
        {
            TraceingManager.InitializeTraceing();
            availableIpAddresses = new List <string>();

            NetworkPing networkPing = new NetworkPing();

            await Task.WhenAll(networkPing.RunPingAsync()).ContinueWith(t =>
            {
                availableIpAddresses = networkPing.availableIpAddresses;
                PrescriptionBlockChainInit();
                RealizedPrescriptionBlockChainInit();
            });
        }
Exemplo n.º 5
0
        public bool AddPrescription(string patientId, string doctorId, DateTime validSinceDate, ObservableCollection <Medicine> medicines)
        {
            if (prescriptions.blockChainClient.GetNumberOfConnectedPeers() >= 2)
            {
                Prescription prescription = new Prescription(patientId,
                                                             doctorId, DateTime.Now, validSinceDate, medicines);

                prescriptions.Add(prescription);
                return(true);
            }
            else
            {
                TraceingManager.Message(LogMessages.LessThen2pearsMessage);
                return(false);
            }
        }
Exemplo n.º 6
0
        public ObservableCollection <Prescription> GetAllRealizedPrescriptions()
        {
            if (realizedPrescriptions.blockChainClient.GetNumberOfConnectedPeers() >= 2)
            {
                ObservableCollection <Prescription> realizedPrescriptionsCollection = new ObservableCollection <Prescription>();

                List <Block> blocks = realizedPrescriptions.GetAll();

                foreach (Block block in blocks)
                {
                    realizedPrescriptionsCollection.Add(block.GetPrescription());
                }

                return(realizedPrescriptionsCollection);
            }

            TraceingManager.Message(LogMessages.LessThen2pearsMessage);
            return(null);
        }
Exemplo n.º 7
0
        public bool Compare(List <Block> ownBlocks, List <Block> gotBlocks)
        {
            int index = ownBlocks.Count - MAX_NUMBER_OF_COMPARED_BLOCKS - 1;

            if (index < 0)
            {
                index = 0;
            }

            int indexGotBlocks = 0;

            for (int i = index; i < ownBlocks.Count; i++)
            {
                if (indexGotBlocks >= gotBlocks.Count)
                {
                    return(false);
                }

                if (!ownBlocks[i].GetHash().Equals(gotBlocks[indexGotBlocks].GetHash()))
                {
                    TraceingManager.Message(LogMessages.NotEqualHashMessage + OwnerName + i);
                    return(false);
                }
                if (!ownBlocks[i].GetHash().Equals(gotBlocks[indexGotBlocks].GenerateHash()))
                {
                    TraceingManager.Message(LogMessages.IncorrectHashMessage + OwnerName + i);
                    return(false);
                }
                if (!gotBlocks[indexGotBlocks].GetHash().Equals(gotBlocks[indexGotBlocks].GenerateHash()))
                {
                    TraceingManager.Message(LogMessages.IncorrectHashMessage + OwnerName + i);
                    return(false);
                }

                indexGotBlocks++;
            }
            return(true);
        }
Exemplo n.º 8
0
        public ObservableCollection <Prescription> GetAllPrescriptionsByDoctor(string doctorId)
        {
            if (prescriptions.blockChainClient.GetNumberOfConnectedPeers() >= 2)
            {
                ObservableCollection <Prescription> prescriptionsCollection = new ObservableCollection <Prescription>();

                List <Block> blocks = prescriptions.GetAll();

                foreach (Block block in blocks)
                {
                    if (block.GetPrescription().doctorId.Equals(doctorId))
                    {
                        prescriptionsCollection.Add(block.GetPrescription());
                    }
                }

                return(prescriptionsCollection);
            }
            else
            {
                TraceingManager.Message(LogMessages.LessThen2pearsMessage);
                return(null);
            }
        }