public void WhenHealthVaultCcrTransformedToFhir_ThenValuesEqual()
        {
            string        cdaXmlRaw = SampleUtil.GetSampleContent("CCR.xml");
            XPathDocument xpDoc     = DocumentReferenceHelper.GetXPathDocumentFromXml(cdaXmlRaw);

            CCR ccr = new CCR();

            ccr.TypeSpecificData = xpDoc;

            var documentReference = ccr.ToFhir() as DocumentReference;

            Assert.IsNotNull(documentReference);
            Assert.IsNotNull(documentReference.Type);
            Assert.AreEqual(documentReference.Content.Count, 1);
            Assert.IsNotNull(documentReference.Content[0].Attachment);
            Assert.IsNotNull(documentReference.Content[0].Attachment.Data);
            Assert.IsNotNull(documentReference.Content[0].Attachment.ContentType, "application/xml");

            string ccrXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(ccr.TypeSpecificData.CreateNavigator());
            string ccrContentBase64Encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(ccrXml));

            string fhirAttachmentDataBase64Encoded = Convert.ToBase64String(documentReference.Content[0].Attachment.Data);

            Assert.AreEqual(fhirAttachmentDataBase64Encoded, ccrContentBase64Encoded);
        }
        public void WhenHealthVaultCcrTransformedToFhirToHealthVault_ThenValuesEqual()
        {
            string inputCcrXmlRaw = SampleUtil.GetSampleContent("CCR.xml");

            XPathDocument xpDoc = DocumentReferenceHelper.GetXPathDocumentFromXml(inputCcrXmlRaw) ?? throw new Exception("Invalid XML");

            CCR inputCcr = new CCR();

            inputCcr.TypeSpecificData = xpDoc;

            var documentReference = inputCcr.ToFhir() as DocumentReference;

            var ccr = documentReference.ToHealthVault() as CCR;

            XPathDocument ccrXPathDoc = DocumentReferenceHelper.GetXPathDocumentFromXml(inputCcrXmlRaw) ?? throw new Exception("Invalid XML");

            // XML gets generated using a common method in order to use in Assert.AreEqual
            string inputCcrXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(ccrXPathDoc.CreateNavigator());

            Assert.IsNotNull(ccr);
            Assert.IsNotNull(ccr.TypeSpecificData);

            string ccrXml = DocumentReferenceHelper.GetXmlFromXPathNavigator(ccr.TypeSpecificData.CreateNavigator());

            Assert.AreEqual(inputCcrXml, ccrXml);
        }
        internal static DocumentReference ToFhirInternal(CCR ccr, DocumentReference documentReference)
        {
            string xml = ThingBaseToFhirDocumentReference.GetXmlFromXPathNavigator(ccr.TypeSpecificData.CreateNavigator());

            ThingBaseToFhirDocumentReference.XmlToDocumentReference(documentReference, xml);

            return(documentReference);
        }
Ejemplo n.º 4
0
        internal static CCR ToCCR(this DocumentReference documentReference)
        {
            var contentComponent = documentReference.GetFirstContentComponentWithData();

            CCR ccr = documentReference.ToThingBase <CCR>();

            string        xml   = Encoding.UTF8.GetString(contentComponent.Attachment.Data);
            XPathDocument xpDoc = ThingBaseToFhirDocumentReference.GetXPathNavigatorFromXml(xml);

            ccr.TypeSpecificData = xpDoc;

            return(ccr);
        }
        public void WhenHealthVaultThingIsTransformedToFhirDocumentReference_ThenTypeAndStatusAndIndexedFieldsSet()
        {
            string        cdaXmlRaw = SampleUtil.GetSampleContent("CCR.xml");
            XPathDocument xpDoc     = DocumentReferenceHelper.GetXPathDocumentFromXml(cdaXmlRaw);

            CCR ccr = new CCR();

            ccr.TypeSpecificData = xpDoc;
            ccr.EffectiveDate    = new NodaTime.LocalDateTime(2016, 05, 09, 3, 36, 55);

            var documentReference = ccr.ToFhir() as DocumentReference;

            Assert.IsNotNull(documentReference);
            Assert.IsNotNull(documentReference.Type);
            Assert.IsNotNull(documentReference.Status);
            Assert.AreEqual(documentReference.Status, DocumentReferenceStatus.Current);
            Assert.IsNotNull(documentReference.Indexed);

            var indexed = documentReference.Indexed.Value;
            var indexedLocalDateTime = new NodaTime.LocalDateTime(indexed.Year, indexed.Month, indexed.Day, indexed.Hour, indexed.Minute, indexed.Second);

            Assert.AreEqual(indexedLocalDateTime, ccr.EffectiveDate.Value);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.Title           = "TS3GameBot by MrDj and Exp111";
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Green;

            #region CredCheck

            if (!CredManager.CredCheck(CredPathJson))
            {
                MyCreds = CredManager.CreateCreds();
                JsonSerialization.WriteToJsonFile <Creds>(CredPathJson, MyCreds);
            }
            else
            {
                MyCreds = JsonSerialization.ReadFromJsonFile <Creds>(CredPathJson);
                if (MyCreds == null)
                {
                    throw new Exception("shit");
                }
            }

            #endregion

            Console.Clear();

            #region DBConnection
            Console.WriteLine("Connecting to Database...");
            ConnectionResult CResult = DbInterface.CheckConnection();
            switch (CResult)
            {
            case ConnectionResult.OK:
                Console.WriteLine("Connected!");
                break;

            case ConnectionResult.SQLERROR:
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nCould not connect to Database! Error: " + CResult + " Check your Settings! (" + CredPathJson + ")\n\nPress Enter to exit");
                while (Console.ReadKey(true).Key != ConsoleKey.Enter)
                {
                }
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Green;
                return;

            //	break;

            case ConnectionResult.UNKNOWN:
            default:
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nCould not connect to Database! Error: " + CResult + "\n\nPress Enter to exit");
                while (Console.ReadKey(true).Key != ConsoleKey.Enter)
                {
                }
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Green;
                return;
                //	break;
            }
            Console.WriteLine(DbInterface.GetPlayerCount() + " Players found!");            // Making an Initial DB call, to get rid of the Delay on the first Commnand

            #endregion

            #region TS3Connection
            Console.WriteLine("Connecting to TeamSpeak Server...");

            TS3QueryInfo ts3ServerInfo;
            if (MyCreds.TS3InfoList.Count > 1)
            {
                Console.WriteLine("You have more than 1 TS3 Server configured!\nPlease choose 1 of the following:\n");
                foreach (var item in MyCreds.TS3InfoList)
                {
                    Console.WriteLine("[" + item.Key + "] on " + item.Value.ServerAddress);
                }
                Console.Write("> ");
                String input = Console.ReadLine();
                ts3ServerInfo = MyCreds.TS3InfoList.Where(e => e.Key.ToLower().Equals(input.ToLower())).FirstOrDefault().Value;
                while (ts3ServerInfo == null)
                {
                    Console.WriteLine("Not found. Try Again!");
                    Console.Write("> ");
                    ts3ServerInfo = MyCreds.TS3InfoList.Where(e => e.Key.ToLower().Equals(Console.ReadLine().ToLower())).First().Value;
                }
            }
            else
            {
                ts3ServerInfo = MyCreds.TS3InfoList.First().Value;
            }

            switch (GameBot.Instance.Login(ts3ServerInfo).GetAwaiter().GetResult())
            {
            case ConnectionResult.OK:
                Console.WriteLine("Connected!");
                break;

            case ConnectionResult.SOCKET:
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nCould not connect to TeamSpeak Server! Is the Server offline?\n\nPress Enter to exit");
                while (Console.ReadKey(true).Key != ConsoleKey.Enter)
                {
                }
                return;

            //	break;
            case ConnectionResult.QUERY:
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nPlease Enter the correct Login Credentials! (" + CredPathJson + ")\n\nPress Enter to exit");
                while (Console.ReadKey(true).Key != ConsoleKey.Enter)
                {
                }
                return;

            //	break;

            case ConnectionResult.UNKNOWN:
            default:
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nCould not connect to TeamSpeak Server!\n\nPress Enter to exit");
                while (Console.ReadKey(true).Key != ConsoleKey.Enter)
                {
                }
                return;
                //	break;
            }
            #endregion

            #region ThreadStuff
            Thread botThread = new Thread(RunBot);
            botThread.Start();
            #endregion



            ConsoleCommandManager.RegisterCommands();             // Registering all Console Commands

            List <String> commandArgs = new List <string>();
            Console.WriteLine("Welcome to Dj's GameBot!\nUse 'help' for a list of commands.\nUse 'help <command>' for Usage of given Command.");

            while (Running)
            {
                Console.Write("> ");
                commandArgs.Clear();
                String             shit = Console.ReadLine().Trim();
                ConsoleCommandBase cmd;

                String[] parts = shit.Split(" ");

                for (int i = 1; i < parts.Length; i++)
                {
                    commandArgs.Add(parts[i]);                     // Putin all the args in a List
                }

                try
                {
                    cmd = ConsoleCommandManager.Commands[parts[0].ToLower()];                     // Getting the Command Assosciated to the give Command

                    CCR result = ConsoleCommandManager.ExecuteCommand(cmd, commandArgs);          // Tempsaving the Result

                    #region ErrorHandling for Console Commands
                    switch (result)
                    {
                    case CCR.OK:
                        break;

                    case CCR.WRONGPARAM:
                        Console.WriteLine(cmd.GetUsage());
                        break;

                    case CCR.INVALIDPARAM:
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Invalid Parameter! ");
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine(cmd.GetUsage());
                        break;

                    case CCR.PLAYERNOTFOUND:
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Player not Found!");
                        Console.ForegroundColor = ConsoleColor.Green;
                        break;

                    case CCR.BELOWZERO:
                    case CCR.NOTENOUGHPOINTS:
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Points can't go below 0!");
                        Console.ForegroundColor = ConsoleColor.Green;
                        break;

                    case CCR.UNKNOWN:
                    default:
                        Console.BackgroundColor = ConsoleColor.Red;
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine("\nUnknown Error appeared! Code: " + result + "\n");
                        Console.BackgroundColor = ConsoleColor.Black;
                        Console.ForegroundColor = ConsoleColor.Green;
                        break;
                    }
                    #endregion
                }
                catch (KeyNotFoundException)                 // If the given command is not found withing the Commands Dictionary
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unknown Command '" + shit.Split(" ")[0] + "'!");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Beep();
                }
            }
            // Changing the Color back to normal
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Clear();             // Clearing the Console
            // Waiting for the Bot Thread to finish
            while (!botThread.IsAlive)
            {
                Console.WriteLine("Waiting for Bot Thread to finish!");
            }
        }
 // Register the type on the generic ThingToFhir partial class
 public static DocumentReference ToFhir(this CCR ccr)
 {
     return(CcrToFhir.ToFhirInternal(ccr, ToFhirInternal <DocumentReference>(ccr)));
 }