public static LocalPatientRecords ReadFile(string file)
        {
            PatientRecordsSerializer serializer = new PatientRecordsSerializer();

            try
            {
                string xml = string.Empty;
                using (StreamReader reader = new StreamReader(file))
                {
                    xml = reader.ReadToEnd();
                    reader.Close();
                }
                return(serializer.Deserialize(xml));
            }
            catch { }
            return(new LocalPatientRecords());
        }
        public static bool WriteFile(string file, LocalPatientRecords lpr)
        {
            bool ok = false;
            PatientRecordsSerializer serializer = new PatientRecordsSerializer();

            try
            {
                string xml = serializer.Serialize(lpr).OuterXml;
                using (StreamWriter writer = new StreamWriter(file, false))
                {
                    writer.Write(xml.Trim());
                    writer.Flush();
                    writer.Close();
                }
                ok = true;
            }
            catch { }
            return(ok);
        }
        private static void Main(string[] args)
        {
            HVProxyTest         myHVProxyTest         = new HVProxyTest();
            LocalPatientRecords myLocalPatientRecords = new LocalPatientRecords();
            string filePath = null;

            try
            {
                if (args.Count() == 0)
                {
                    Console.WriteLine("{0}", myUsage);
                    return;
                }

                Arguments CommandLine = new Arguments(args);

                if (CommandLine["deserialize"] != null)   // ****  DE-SERIALIZE LOCAL PATIENT RECORDS FROM FILE
                {
                    Console.WriteLine("\nImport patient records.  File name?  ");
                    filePath = Console.ReadLine();
                    myLocalPatientRecords = PatientRecordsSerializer.ReadFile(filePath);
                    foreach (PatientRecord pr in myLocalPatientRecords.PatientRecords)
                    {
                        Console.WriteLine("PatientId={0}\tLocalRecordId={1}\tPersonId={2}\tRecordId={3}", pr.PatientId, pr.ApplicationRecordId, pr.PersonId, pr.RecordId);
                    }
                }

                if (CommandLine["createconnection"] != null)  // **** TEST CREATE CONNECTION
                {
                    Console.WriteLine("\nTest CreateConnectionRequest API\n");
                    Console.WriteLine("Local patient name?  ");
                    string patientName = Console.ReadLine();
                    Console.WriteLine("Local patient identifier?  ");
                    string patientId = Console.ReadLine();
                    Console.WriteLine("Local patient eMail?  ");
                    string patientEmail = Console.ReadLine();
                    Console.WriteLine("Secret question?  ");
                    string secretQuestion = Console.ReadLine();
                    Console.WriteLine("Secret answer?  ");
                    string secretAnswer = Console.ReadLine();

                    //
                    PatientRecord patientRecord = new PatientRecord(patientId, patientName, patientEmail, secretQuestion, secretAnswer, null, null, null, null, null, "requested");
                    TestCreateConnection(myHVApplicationToken, ref patientRecord);
                    myLocalPatientRecords.PatientRecords.Add(patientRecord);

                    //
                    Console.WriteLine("Go validate the connection request using the provided URL and key, then return to this session.  \nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["getconnections"] != null)   // **** TEST GET VALIDATED CONNECTIONS
                {
                    Console.WriteLine("\nTest GetValidatedConnections API\n");

                    //
                    TestGetValidatedConnections(myHVApplicationToken, ref myLocalPatientRecords);

                    //
                    Console.WriteLine("\nUse the connections info listed above for subsequent API tests. \nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["getthings"] != null)   // **** TEST GET-THINGS
                {
                    Console.WriteLine("\nTest GetThings API\n");
                    Console.WriteLine("HV PersonId?  ");
                    string personId = Console.ReadLine();
                    Console.WriteLine("HV RecordId?  ");
                    string recordId = Console.ReadLine();

                    //
                    TestGetThings(myHVApplicationToken, personId, recordId, ref myHVProxyTest.myTypeIds);

                    //
                    Console.WriteLine("\nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["putthing"] != null)    // **** TEST PUT-THING
                {
                    Console.WriteLine("\nTest PutThing API\n");
                    Console.WriteLine("HV PersonId?  ");
                    string personId = Console.ReadLine();
                    Console.WriteLine("HV RecordId?  ");
                    string recordId = Console.ReadLine();

                    //
                    TestPutThing(myHVApplicationToken, personId, recordId);

                    //
                    Console.WriteLine("\nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["putthings"] != null)    // **** TEST PUT-THINGS
                {
                    Console.WriteLine("\nTest PutThings API\n");
                    Console.WriteLine("HV PersonId?  ");
                    string personId = Console.ReadLine();
                    Console.WriteLine("HV RecordId?  ");
                    string recordId = Console.ReadLine();

                    //
                    TestPutThings(myHVApplicationToken, personId, recordId);

                    //
                    Console.WriteLine("\nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["getupdatedrecords"] != null)   // **** TEST GET UPDATED RECORDS
                {
                    Console.WriteLine("\nTest GetUpdatedRecords API\n");

                    //
                    TestGetUpdatedRecords(myHVApplicationToken);

                    //
                    Console.WriteLine("\nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["deleteconnection"] != null)   // **** TEST DELETE PENDING CONNECTION
                {
                    Console.WriteLine("\nTest DeletePendingConnection API\n");
                    Console.WriteLine("Local patient identifier?  ");
                    string patientId = Console.ReadLine();

                    //
                    TestDeletePendingConnection(myHVApplicationToken, patientId);

                    //
                    Console.WriteLine("\nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["revokeapplication"] != null)   // **** TEST REVOKE APPLICATION CONNECTION
                {
                    Console.WriteLine("\nTest RevokeApplicationConnection API\n");
                    Console.WriteLine("HV PersonId?  ");
                    string personId = Console.ReadLine();
                    Console.WriteLine("HV RecordId?  ");
                    string recordId = Console.ReadLine();

                    //
                    TestRevokeApplicationConnection(myHVApplicationToken, personId, recordId);

                    //
                    Console.WriteLine("\nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["DOPU"] != null)   // **** TEST THE DROP-OFF PICK-UP API
                {
                    Console.WriteLine("\nTest Drop-Off and Pick-Up API\n");
                    Console.WriteLine("Local patient identifier?  ");
                    string patientId = Console.ReadLine();
                    Console.WriteLine("Local patient eMail?  ");
                    string patientEmail = Console.ReadLine();
                    Console.WriteLine("Secret question?  ");
                    string secretQuestion = Console.ReadLine();
                    Console.WriteLine("Secret answer?  ");
                    string secretAnswer = Console.ReadLine();

                    //
                    TestDropOffPickUp(myHVApplicationToken, patientId, patientEmail, secretQuestion, secretAnswer);

                    //
                    Console.WriteLine("\nPress any key to continue; 'q' to quit...\n");
                    if (Console.ReadKey().KeyChar == 'q')
                    {
                        return;
                    }
                }

                if (CommandLine["serialize"] != null)   // **** Serialize local patient records to file
                {
                    Console.WriteLine("\nExport patient records.  File name?  ");
                    filePath = Console.ReadLine();
                    PatientRecordsSerializer.WriteFile(filePath, myLocalPatientRecords);
                }

                // TO-DO : ADD OTHER API TESTS HERE.
            }
            catch (Exception ex)
            {
                Console.WriteLine("\nException : {0}\n{1}\n{2}", ex.Message, ex.InnerException.Message, ex.InnerException.StackTrace);
            }

            Console.WriteLine("\nPress any key to exit...\n");
            Console.ReadKey();
            return;
        }  // Main