Exemple #1
0
        static void Main(string[] args)
        {
            AnekaApplication <AnekaThread, ThreadManager> app = null;

            while (true)
            {
                try
                {
                    // Aneka Configuration
                    Logger.Start();
                    Configuration conf = Configuration.GetConfiguration(@"C:\xampp\htdocs\EdgeLens\Aneka\conf.xml");
                    app = new AnekaApplication <AnekaThread, ThreadManager>(conf);

                    // Wait for input
                    while (!File.Exists(input))
                    {
                        Console.WriteLine("Waiting for input");
                        System.Threading.Thread.Sleep(1000);
                    }

                    HelloWorld  hw = new HelloWorld(masterIP);
                    AnekaThread th = new AnekaThread(hw.PrintHello, app);
                    th.Start();
                    th.Join();
                    hw = (HelloWorld)th.Target;
                    Console.WriteLine("Job done");
                    File.Delete(input);
                }
                finally
                {
                    app.StopExecution();
                    Logger.Stop();
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            AnekaApplication <AnekaThread, ThreadManager> app = null;

            try
            {
                Logger.Start();
                Configuration conf = Configuration.GetConfiguration("C:/Aneka/conf.xml");

                app = new AnekaApplication <AnekaThread, ThreadManager>(conf);
                HelloWorld  hw = new HelloWorld();
                AnekaThread th = new AnekaThread(hw.PrintHello, app);
                th.Start();
                th.Join();
                hw = (HelloWorld)th.Target;
                Console.WriteLine("Value: " + hw.result);
            }
            finally
            {
                app.StopExecution();
                Logger.Stop();
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            AnekaApplication <AnekaThread, ThreadManager> app = null;

            try
            {
                while (true)
                {
                    Logger.Start();
                    Configuration conf =
                        Configuration.GetConfiguration(@"C:\Aneka\conf.xml");

                    while (Analyze() == false)
                    {
                        System.Threading.Thread.Sleep(500);
                        continue;
                    }
                    Console.WriteLine("Data Parsed");
                    app = new AnekaApplication <AnekaThread, ThreadManager>(conf);


                    List <int>[] partitions = new List <int> [2];
                    int          maxSize    = (int)Math.Ceiling(list.Count / (double)2);
                    int          k          = 0;
                    for (int i = 0; i < 2; i++)
                    {
                        partitions[i] = new List <int>();
                        for (int j = k; j < k + maxSize; j++)
                        {
                            if (j >= list.Count)
                            {
                                break;
                            }
                            partitions[i].Add(intlist[j]);
                        }
                        k += maxSize;
                    }
                    HelloWorld    hw  = new HelloWorld(partitions[0]);
                    HelloWorld    hw2 = new HelloWorld(partitions[1]);
                    AnekaThread[] th  = new AnekaThread[2];


                    th[0] = new AnekaThread(hw.PrintHello, app);
                    th[1] = new AnekaThread(hw2.PrintHello, app);
                    th[0].Start();
                    th[1].Start();

                    th[0].Join();
                    hw = (HelloWorld)th[0].Target;
                    Console.WriteLine(hw.len);
                    Console.WriteLine(partitions[0].Count());
                    foreach (var val in partitions[0])
                    {
                        Console.WriteLine("Value in partitions[0] : " + val);
                    }


                    Console.WriteLine("Check : " + hw.check);
                    Console.WriteLine("Value : {0} , NodeId:{1},SubmissionTime:{2},Completion Time{3}", hw.result, th[0].NodeId, th[0].SubmissionTime, th[0].CompletionTime);
                    Console.WriteLine("Minimum : {0}", hw.min);
                    Console.WriteLine("Count : {0}", hw.count);

                    th[1].Join();
                    hw2 = (HelloWorld)th[1].Target;
                    foreach (var val in partitions[1])
                    {
                        Console.WriteLine("Value in partitions[1] : " + val);
                    }
                    Console.WriteLine(hw2.len);
                    Console.WriteLine(partitions[1].Count());

                    Console.WriteLine("Value : {0} , NodeId:{1},SubmissionTime:{2},Completion Time{3}", hw2.result, th[1].NodeId, th[1].SubmissionTime, th[1].CompletionTime);
                    Console.WriteLine("Minimum : {0}", hw2.min);
                    Console.WriteLine("Count : {0}", hw2.count);

                    totalcount = hw.count + hw2.count;
                    if (hw.min < hw2.min)
                    {
                        minima = hw.min;
                    }
                    else
                    {
                        minima = hw2.min;
                    }

                    Console.WriteLine("Result : " + totalcount + ", " + minima);

                    int    line_to_edit    = 1; // Warning: 1-based indexing!
                    string sourceFile      = path;
                    string destinationFile = @"C:\xampp\htdocs\HealthKeeper\result.txt";

                    // Read the appropriate line from the file.
                    string lineToWrite = null;
                    using (StreamReader reader = new StreamReader(sourceFile))
                    {
                        for (int i = 1; i <= line_to_edit; ++i)
                        {
                            lineToWrite = reader.ReadLine();
                        }
                    }

                    if (lineToWrite == null)
                    {
                        throw new InvalidDataException("Line does not exist in " + sourceFile);
                    }

                    // Read the old file.
                    string[] lines = File.ReadAllLines(sourceFile);

                    lines[0] = totalcount + "," + minima;
                    System.IO.File.WriteAllLines(destinationFile, lines);
                    lines[0] = "Analyze = Done";
                    System.IO.File.WriteAllLines(sourceFile, lines);
                }
            }
            catch (Exception e)
            {
                Console.Write(e.StackTrace);
            }
            finally
            {
                app.StopExecution();
                Logger.Stop();
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
            RSAParameters            RSAPublicKeyInfo         = RSA.ExportParameters(false);
            RSAParameters            RSAPrivateKeyInfo        = RSA.ExportParameters(true);
            AnekaApplication <AnekaThread, ThreadManager> app = null;

            Console.WriteLine("Initialized Master");
            try
            {
                // Initialize Blockchain
                var myBlockChain = new Blockchain();
                Console.WriteLine("Hash : " + myBlockChain.GetLatestBlock().hash);

                while (true)
                {
                    // Start Aneka
                    Logger.Start();
                    Configuration conf =
                        Configuration.GetConfiguration("conf.xml");

                    // Analyze data.txt
                    while (Analyze() == false)
                    {
                        System.Threading.Thread.Sleep(500);
                        continue;
                    }
                    Console.WriteLine("Data Parsed");

                    // Start Aneks application
                    app = new AnekaApplication <AnekaThread, ThreadManager>(conf);

                    // Parse data.txt
                    List <int>[] partitions = new List <int> [2];
                    int          maxSize    = (int)Math.Ceiling(list.Count / (double)2);
                    int          k          = 0;
                    for (int i = 0; i < 2; i++)
                    {
                        partitions[i] = new List <int>();
                        for (int j = k; j < k + maxSize; j++)
                        {
                            if (j >= list.Count)
                            {
                                break;
                            }
                            partitions[i].Add(intlist[j]);
                        }
                        k += maxSize;
                    }

                    oldhash = myBlockChain.GetLatestBlock().hash;

                    // Add data partitions to blockchain (assuming no exception in signature validation below)
                    myBlockChain.AddBlock(partitions[0]);
                    Console.WriteLine("Hash value : " + myBlockChain.GetLatestBlock().hash);
                    myBlockChain.AddBlock(partitions[1]);
                    Console.WriteLine("Hash value : " + myBlockChain.GetLatestBlock().hash);

                    newhash = myBlockChain.GetLatestBlock().hash;

                    // Signature makes sure the transaction is legit (as private key in invisible)
                    // Initialize 2 HelloWorld objects for two data halves
                    signature = SignData(string.Join(";", partitions[0].Select(x => x.ToString()).ToArray()), RSAPrivateKeyInfo);
                    HelloWorld hw = new HelloWorld(partitions[0], signature, RSAPublicKeyInfo, oldhash, newhash);
                    signature = SignData(string.Join(";", partitions[1].Select(x => x.ToString()).ToArray()), RSAPrivateKeyInfo);
                    HelloWorld hw2 = new HelloWorld(partitions[1], signature, RSAPublicKeyInfo, oldhash, newhash);

                    // Declare Aneka thread array
                    AnekaThread[] th = new AnekaThread[2];

                    // Initialize Aneka threads with PrintHello method
                    th[0] = new AnekaThread(hw.PrintHello, app);
                    th[1] = new AnekaThread(hw2.PrintHello, app);

                    // Start threads
                    th[0].Start();
                    th[1].Start();

                    // Wait for first thread to finish
                    th[0].Join();
                    hw = (HelloWorld)th[0].Target;
                    foreach (var val in partitions[0])
                    {
                        Console.WriteLine("Value in partitions[0] : " + val);
                    }

                    Console.WriteLine("Check : " + hw.check);
                    Console.WriteLine("Value : {0} , NodeId:{1},SubmissionTime:{2},Completion Time{3}", hw.result, th[0].NodeId, th[0].SubmissionTime, th[0].CompletionTime);
                    Console.WriteLine("Minimum : {0}", hw.min);
                    Console.WriteLine("Count : {0}", hw.count);

                    // Wait for second thread to finish
                    th[1].Join();
                    hw2 = (HelloWorld)th[1].Target;
                    foreach (var val in partitions[1])
                    {
                        Console.WriteLine("Value in partitions[1] : " + val);
                    }

                    Console.WriteLine("Check : " + hw2.check);
                    Console.WriteLine("Value : {0} , NodeId:{1},SubmissionTime:{2},Completion Time{3}", hw2.result, th[1].NodeId, th[1].SubmissionTime, th[1].CompletionTime);
                    Console.WriteLine("Minimum : {0}", hw2.min);
                    Console.WriteLine("Count : {0}", hw2.count);

                    // Verify data not tampered
                    if (hw.checkhash == false && hw2.checkhash == false)
                    {
                        throw new Exception("Data tampered in Master!");
                    }
                    Console.WriteLine("Checked for data temper. No data has been modified.");

                    // Validate blockchain
                    myBlockChain.ValidateChain();
                    Console.WriteLine("Blockchain Validation checked!");

                    // Compile all results
                    allData = allData.Concat(partitions[0]).Concat(partitions[1]).ToList();

                    // Publish results in result.txt
                    totalcount = hw.count + hw2.count;
                    if (hw.min < hw2.min)
                    {
                        minima = hw.min;
                    }
                    else
                    {
                        minima = hw2.min;
                    }

                    Console.WriteLine("Result : " + totalcount + ", " + minima);

                    int    line_to_edit    = 1; // Warning: 1-based indexing!
                    string sourceFile      = path;
                    string destinationFile = @"C:\xampp\htdocs\HealthKeeper\result.txt";

                    // Read the appropriate line from the file.
                    string lineToWrite = null;
                    using (StreamReader reader = new StreamReader(sourceFile))
                    {
                        for (int i = 1; i <= line_to_edit; ++i)
                        {
                            lineToWrite = reader.ReadLine();
                        }
                    }

                    if (lineToWrite == null)
                    {
                        throw new InvalidDataException("Line does not exist in " + sourceFile);
                    }

                    // Read the old file.
                    string[] lines     = new string[3];
                    string[] linestemp = File.ReadAllLines(sourceFile);
                    lines[1] = linestemp[1];

                    lines[0] = totalcount + "," + minima;
                    lines[2] = string.Join(",", allData.Select(x => x.ToString()).ToArray());
                    System.IO.File.WriteAllLines(destinationFile, lines);
                    linestemp[0] = "Analyze = Done";
                    System.IO.File.WriteAllLines(sourceFile, linestemp);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                app.StopExecution();
                Logger.Stop();
            }
        }
Exemple #5
0
        static void Main(string[] args)
        {
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
            RSAParameters            RSAPublicKeyInfo         = RSA.ExportParameters(false);
            RSAParameters            RSAPrivateKeyInfo        = RSA.ExportParameters(true);
            AnekaApplication <AnekaThread, ThreadManager> app = null;

            Console.WriteLine("Initialized Master");
            try
            {
                // Initialize Blockchain
                var myBlockChain = new Blockchain();
                Console.WriteLine("Hash : " + myBlockChain.GetLatestBlock().hash);

                while (true)
                {
                    // Start Aneka
                    Logger.Start();
                    Configuration conf =
                        Configuration.GetConfiguration(@"C:\xampp\htdocs\HealthKeeper\Aneka\conf.xml");

                    // Analyze data.txt
                    while (Analyze() == false)
                    {
                        System.Threading.Thread.Sleep(500);
                        continue;
                    }
                    Console.WriteLine("Data Parsed");

                    // Start Aneks application
                    app = new AnekaApplication <AnekaThread, ThreadManager>(conf);

                    // Parse data.txt
                    List <int>[] partitions1 = new List <int> [2];
                    int          maxSize     = (int)Math.Ceiling(list1.Count / (double)2);
                    int          k           = 0;
                    for (int i = 0; i < 2; i++)
                    {
                        partitions1[i] = new List <int>();
                        for (int j = k; j < k + maxSize; j++)
                        {
                            if (j >= list1.Count)
                            {
                                break;
                            }
                            partitions1[i].Add(intlist1[j]);
                        }
                        k += maxSize;
                    }
                    List <int>[] partitions2 = new List <int> [2];
                    maxSize = (int)Math.Ceiling(list2.Count / (double)2);
                    k       = 0;
                    for (int i = 0; i < 2; i++)
                    {
                        partitions2[i] = new List <int>();
                        for (int j = k; j < k + maxSize; j++)
                        {
                            if (j >= list2.Count)
                            {
                                break;
                            }
                            partitions2[i].Add(intlist2[j]);
                        }
                        k += maxSize;
                    }

                    oldhash = myBlockChain.GetLatestBlock().hash;

                    // Add data partitions to blockchain (assuming no exception in signature validation below)
                    myBlockChain.AddBlock(partitions1[0]);
                    Console.WriteLine("Hash value : " + myBlockChain.GetLatestBlock().hash);
                    myBlockChain.AddBlock(partitions1[1]);
                    Console.WriteLine("Hash value : " + myBlockChain.GetLatestBlock().hash);

                    newhash = myBlockChain.GetLatestBlock().hash;

                    // Signature makes sure the transaction is legit (as private key in invisible)
                    // Initialize 2 HelloWorld objects for two data halves
                    signature = SignData(string.Join(";", partitions1[0].Select(x => x.ToString()).ToArray()), RSAPrivateKeyInfo);
                    HelloWorld hw = new HelloWorld(partitions1[0], partitions2[0], signature, RSAPublicKeyInfo, oldhash, newhash);
                    signature = SignData(string.Join(";", partitions1[1].Select(x => x.ToString()).ToArray()), RSAPrivateKeyInfo);
                    HelloWorld hw2 = new HelloWorld(partitions1[1], partitions2[1], signature, RSAPublicKeyInfo, oldhash, newhash);

                    // Declare Aneka thread array
                    AnekaThread[] th = new AnekaThread[2];
                    Console.WriteLine("Aneka thread array declared");

                    // Initialize Aneka threads with PrintHello method
                    th[0] = new AnekaThread(hw.PrintHello, app);
                    th[1] = new AnekaThread(hw2.PrintHello, app);

                    // Start threads
                    th[0].Start();
                    th[1].Start();

                    Console.WriteLine("Data sent for analysis");

                    // Wait for first thread to finish
                    th[0].Join();
                    hw = (HelloWorld)th[0].Target;
                    foreach (var val in partitions1[0])
                    {
                        Console.WriteLine("SpO2 Value in partitions[0] : " + val);
                    }
                    foreach (var val in partitions2[0])
                    {
                        Console.WriteLine("BPM Value in partitions[0] : " + val);
                    }

                    Console.WriteLine("Check : " + hw.check);
                    Console.WriteLine("Value : {0} , NodeId:{1},SubmissionTime:{2},Completion Time{3}", hw.result, th[0].NodeId, th[0].SubmissionTime, th[0].CompletionTime);
                    Console.WriteLine("Minimum : {0}", hw.min);
                    Console.WriteLine("Count : {0}", hw.count);
                    Console.WriteLine("Minimum BPM : {0}", hw.minbpm);
                    Console.WriteLine("Maximum BPM : {0}", hw.maxbpm);
                    Console.WriteLine("Sum BPM : {0}", hw.sumbpm);

                    // Wait for second thread to finish
                    th[1].Join();
                    hw2 = (HelloWorld)th[1].Target;
                    foreach (var val in partitions1[1])
                    {
                        Console.WriteLine("SpO2 Value in partitions[1] : " + val);
                    }
                    foreach (var val in partitions2[1])
                    {
                        Console.WriteLine("BPM Value in partitions[1] : " + val);
                    }

                    Console.WriteLine("Check : " + hw2.check);
                    Console.WriteLine("Value : {0} , NodeId:{1},SubmissionTime:{2},Completion Time{3}", hw2.result, th[1].NodeId, th[1].SubmissionTime, th[1].CompletionTime);
                    Console.WriteLine("Minimum : {0}", hw2.min);
                    Console.WriteLine("Count : {0}", hw2.count);
                    Console.WriteLine("Minimum BPM : {0}", hw2.minbpm);
                    Console.WriteLine("Maximum BPM : {0}", hw2.maxbpm);
                    Console.WriteLine("Sum BPM : {0}", hw2.sumbpm);

                    // Verify data not tampered
                    if (hw.checkhash == false && hw2.checkhash == false)
                    {
                        throw new Exception("Data tampered in Master!");
                    }
                    Console.WriteLine("Checked for data tamper. No data has been modified.");

                    // Validate blockchain
                    myBlockChain.ValidateChain();
                    Console.WriteLine("Blockchain Validation checked!");

                    // Compile all results
                    allData = allData.Concat(partitions1[0]).Concat(partitions1[1]).ToList();

                    // Publish results in result.txt
                    totalcount = hw.count + hw2.count;
                    totalsum   = hw.sumbpm + hw2.sumbpm;
                    if (hw.min < hw2.min)
                    {
                        minima = hw.min;
                    }
                    else
                    {
                        minima = hw2.min;
                    }
                    if (totalcount < 5)
                    {
                        sev = "None";
                    }
                    else if (totalcount < 15)
                    {
                        sev = "Mild";
                    }
                    else if (totalcount < 30)
                    {
                        sev = "Moderate";
                    }
                    else
                    {
                        sev = "Highly severe";
                    }
                    if (hw.minbpm < hw2.minbpm)
                    {
                        minbpm = hw.minbpm;
                    }
                    else
                    {
                        minbpm = hw2.minbpm;
                    }
                    if (hw.maxbpm > hw2.maxbpm)
                    {
                        maxbpm = hw.maxbpm;
                    }
                    else
                    {
                        maxbpm = hw2.maxbpm;
                    }
                    avgbpm = (hw.sumbpm + hw2.sumbpm) / list2.Count();
                    if (avgbpm < 60)
                    {
                        diag = "High Probability of Bradycardia";
                    }
                    else if (avgbpm > 100)
                    {
                        diag = "High Probability of Tachycardia";
                    }
                    else
                    {
                        diag = "Normal ECG";
                    }

                    Console.WriteLine("Result SpO2 : " + totalcount + ", " + minima);
                    Console.WriteLine("Result BPM : " + minbpm + ", " + maxbpm + ", " + avgbpm);

                    int    line_to_edit    = 1; // Warning: 1-based indexing!
                    string sourceFile      = path;
                    string destinationFile = @"C:\xampp\htdocs\HealthKeeper\Aneka\result.txt";

                    // Read the appropriate line from the file.
                    string lineToWrite = null;
                    using (StreamReader reader = new StreamReader(sourceFile))
                    {
                        for (int i = 1; i <= line_to_edit; ++i)
                        {
                            lineToWrite = reader.ReadLine();
                        }
                    }

                    if (lineToWrite == null)
                    {
                        throw new InvalidDataException("Line does not exist in " + sourceFile);
                    }

                    // Read the old file.
                    string[] lines     = new string[8];
                    string[] linestemp = File.ReadAllLines(sourceFile);

                    lines[0] = "For 1 hour of Sleep Apnea Data :";
                    lines[1] = "AHI (Apnea-hypopnea index) = " + totalcount;
                    lines[2] = "Minimum Oxygen Level = " + minima;
                    lines[3] = "Disease severity = " + sev;
                    lines[4] = "Minimum Heart Rate = " + minbpm;
                    lines[5] = "Maximum Heart Rate = " + maxbpm;
                    lines[6] = "Average Heart Rate = " + avgbpm;
                    lines[7] = "Diagnosis : " + diag;
                    System.IO.File.WriteAllLines(destinationFile, lines);
                    linestemp[0] = "Analysis Done = true";
                    System.IO.File.WriteAllLines(sourceFile, linestemp);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                app.StopExecution();
                Logger.Stop();
            }
        }