Example #1
0
        public virtual void RenderErrorsList(HtmlTextWriter writer)
        {
            if (HasNonAborts(_errorList))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "errorlist");
                writer.AddAttribute(HtmlTextWriterAttribute.Id, "errorlist");
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "HideError(this)");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);


                bool first = true;
                foreach (Exception exception in _errorList)
                {
                    if (!(exception is AbortException))
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            writer.Write("<br>");
                        }
                        ShowErrorsForm.RenderError(writer, exception);
                    }
                }

                writer.RenderEndTag();

                _errorList.Clear();
            }
        }
        public void ParseEmptyPrimitive()
        {
            string xmlString = "<someString xmlns='http://hl7.org/fhir' id='4' />";
            ErrorList errors = new ErrorList();
            FhirString result = (FhirString)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsNotNull(result);
            Assert.IsNull(result.Value);
            Assert.AreEqual("4", result.LocalId.ToString());

            xmlString = "<someString xmlns='http://hl7.org/fhir' id='4' value='' />";
            errors.Clear();
            result = (FhirString)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsNotNull(result);
            Assert.IsNull(result.Value);
            Assert.AreEqual("4", result.LocalId.ToString());

            string jsonString = "{ \"someString\" : { \"_id\" : \"4\" } }";
            errors.Clear();
            result = (FhirString)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsNotNull(result);
            Assert.IsNull(result.Value);
            Assert.AreEqual("4", result.LocalId.ToString());

            jsonString = "{ \"someString\" : { \"_id\" : \"4\", \"value\" : \"\" } }";
            errors.Clear();
            result = (FhirString)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsNotNull(result);
            Assert.IsNull(result.Value);
            Assert.AreEqual("4", result.LocalId.ToString());
        }
        public void ParseJsonNativeTypes()
        {
            string json = "{ testExtension: { url: { value : \"http://bla.com\" }," +
                          "valueInteger: { value: 14 } } }";
            string json2 = "{ testExtension: { url: { value : \"http://bla.com\" }," +
                           "valueBoolean: { value: true } } }";

            var errors = new ErrorList();
            var result = (Extension)FhirParser.ParseElementFromJson(json, errors);

            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(14, ((Integer)result.Value).Value.Value);

            errors.Clear();
            result = (Extension)FhirParser.ParseElementFromJson(json2, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(true, ((FhirBoolean)result.Value).Value.Value);

            string jsonWrong = "{ testExtension: { url: { value : \"http://bla.com\" }," +
                               "valueInteger: { value: \"14\" } } }";

            errors.Clear();
            result = (Extension)FhirParser.ParseElementFromJson(jsonWrong, errors);
            Assert.IsTrue(errors.Count() > 0);
            Assert.IsTrue(errors.ToString().Contains("Expected") &&
                          errors.ToString().Contains("Boolean"), errors.ToString());
        }
Example #4
0
        public void ParseExtendedPrimitiveWithOtherElements()
        {
            string xmlString =
                @"<birthDate xmlns='http://hl7.org/fhir' value='1972-11-30'>
                    <crap />
                    <extension>
                       <url value='http://hl7.org/fhir/profile/@iso-21090#nullFlavor' />
                       <valueCode value='UNK' />
                    </extension>
                  </birthDate>";

            ErrorList errors = new ErrorList();
            Date      result = (Date)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.AreNotEqual(0, errors.Count);
            Assert.IsTrue(errors.ToString().Contains("crap"));

            xmlString =
                @"<birthDate xmlns='http://hl7.org/fhir' value='1972-11-30'>
                    <crap xmlns=""http://furore.com"" />
                    <extension>
                       <url value='http://hl7.org/fhir/profile/@iso-21090#nullFlavor' />
                       <valueCode value='UNK' />
                    </extension>
                  </birthDate>";

            errors.Clear();
            result = (Date)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.AreNotEqual(0, errors.Count);
            Assert.IsTrue(errors.ToString().Contains("crap"));


            string jsonString = @"{ ""birthDate"" : 
                                { 
                                    ""value"" : ""1972-11-30"",
                                    ""crap"" : {},
                                    ""extension"" : [
                                    {
                                        ""url"" : { ""value"" : ""http://hl7.org/fhir/profile/@iso-21090#nullFlavor"" },
                                        ""valueCode"" : { ""value"" : ""UNK"" }
                                    } ]
                                }
                            }";

            errors.Clear();
            result = (Date)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.AreNotEqual(0, errors.Count);
            Assert.IsTrue(errors.ToString().Contains("crap"));
        }
Example #5
0
 /// <summary>Clears the results.</summary>
 public void Reset()
 {
     Root  = null;
     Logic = "";
     Expressions.Clear();
     ErrorList.Clear();
 }
        public void BinaryParsing()
        {
            string xmlString = @"<Binary id='pic1' contentType='image/gif' xmlns='http://hl7.org/fhir'>R0lGODlhEwARAPcAAAAAAAAA/+9aAO+1AP/WAP/eAP/eCP/eEP/eGP/nAP/nCP/nEP/nIf/nKf/nUv/nWv/vAP/vCP/vEP/vGP/vIf/vKf/vMf/vOf/vWv/vY//va//vjP/3c//3lP/3nP//tf//vf///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEAAAEALAAAAAATABEAAAi+AAMIDDCgYMGBCBMSvMCQ4QCFCQcwDBGCA4cLDyEGECDxAoAQHjxwyKhQAMeGIUOSJJjRpIAGDS5wCDly4AALFlYOgHlBwwOSNydM0AmzwYGjBi8IHWoTgQYORg8QIGDAwAKhESI8HIDgwQaRDI1WXXAhK9MBBzZ8/XDxQoUFZC9IiCBh6wEHGz6IbNuwQoSpWxEgyLCXL8O/gAnylNlW6AUEBRIL7Og3KwQIiCXb9HsZQoIEUzUjNEiaNMKAAAA7</Binary>";

            ErrorList errors = new ErrorList();
            Binary result = (Binary)FhirParser.ParseResourceFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());

            Assert.AreEqual("image/gif", result.ContentType);
            Assert.AreEqual(993, result.Content.Length);
            Assert.IsTrue(Encoding.ASCII.GetString(result.Content).StartsWith("GIF89a"));

            byte[] data = result.Content;
            File.WriteAllBytes(@"c:\temp\test.gif", data);

            string json = "{ Binary: { contentType : \"image/gif\", " +
                        "content: \"R0lGODlhEwARAPcAAAAAAAAA/+9aAO+1AP/WAP/eAP/eCP/eEP/eGP/nAP/nCP/nEP/nIf/nKf/nUv/nWv/vAP/vCP/vEP/vGP/vIf/vKf/vMf/vOf/vWv/vY//va//vjP/3c//3lP/3nP//tf//vf///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEAAAEALAAAAAATABEAAAi+AAMIDDCgYMGBCBMSvMCQ4QCFCQcwDBGCA4cLDyEGECDxAoAQHjxwyKhQAMeGIUOSJJjRpIAGDS5wCDly4AALFlYOgHlBwwOSNydM0AmzwYGjBi8IHWoTgQYORg8QIGDAwAKhESI8HIDgwQaRDI1WXXAhK9MBBzZ8/XDxQoUFZC9IiCBh6wEHGz6IbNuwQoSpWxEgyLCXL8O/gAnylNlW6AUEBRIL7Og3KwQIiCXb9HsZQoIEUzUjNEiaNMKAAAA7\" } }";
            errors.Clear();
            result = (Binary)FhirParser.ParseResourceFromJson(json, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());

            Assert.AreEqual("image/gif", result.ContentType);
            Assert.AreEqual(993, result.Content.Length);
            Assert.IsTrue(Encoding.ASCII.GetString(result.Content).StartsWith("GIF89a"));
        }
Example #7
0
    public void GetObjectByComponent()
    {
        ErrorList.Clear();
        Debug.Log(componentName);
        List <GameObject> allObject    = GetAllObjectsInScene();
        List <GameObject> componentObj = new List <GameObject>();

        foreach (GameObject nowObj in allObject)
        {
            if (nowObj.GetComponent(componentName))
            {
                if (nowObj.GetComponent <Text>().text.Contains(Name))
                {
                    ErrorList.Add(nowObj);
                }
            }
        }
//		if(componentObj.Count > 0){
//			Selection.objects = componentObj.ToArray();
//
//		}else{
//			Selection.objects = componentObj.ToArray();
//			Debug.Log("no Object");
//		}
    }
Example #8
0
        public void ParseSimpleComposite()
        {
            string xmlString = @"<testCoding id='x4' xmlns='http://hl7.org/fhir'>
                                    <system value='http://hl7.org/fhir/sid/icd-10' />
                                    <code value='G44.1' />
                                 </testCoding>";

            ErrorList errors = new ErrorList();
            Coding    result = (Coding)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual("x4", result.LocalId.ToString());
            Assert.AreEqual("G44.1", result.Code);
            Assert.AreEqual("http://hl7.org/fhir/sid/icd-10", result.System.ToString());
            Assert.IsNull(result.Display);

            string jsonString = "{ \"testCoding\" : { \"_id\" : \"x4\", " +
                                "\"system\": { \"value\" : \"http://hl7.org/fhir/sid/icd-10\" }, " +
                                "\"code\": { \"value\" : \"G44.1\" } } }";

            errors.Clear();
            result = (Coding)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual("x4", result.LocalId);
            Assert.AreEqual("G44.1", result.Code);
            Assert.AreEqual("http://hl7.org/fhir/sid/icd-10", result.System.ToString());
            Assert.IsNull(result.Display);
        }
Example #9
0
        public void ParseExtendedPrimitive()
        {
            string xmlString =
                @"<birthDate xmlns='http://hl7.org/fhir' value='1972-11-30'>
                    <extension>
                       <url value='http://hl7.org/fhir/profile/@iso-21090#nullFlavor' />
                       <valueCode value='UNK' />
                    </extension>
                  </birthDate>";

            ErrorList errors = new ErrorList();
            Date      result = (Date)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.AreEqual(0, errors.Count, errors.ToString());
            verifyParseExtendedPrimitive(result);

            string jsonString = @"{ ""birthDate"" : 
                                { 
                                    ""value"" : ""1972-11-30"",
                                    ""extension"" : [
                                    {
                                        ""url"" : { ""value"" : ""http://hl7.org/fhir/profile/@iso-21090#nullFlavor"" },
                                        ""valueCode"" : { ""value"" : ""UNK"" }
                                    } ]
                                }
                            }";

            errors.Clear();
            result = (Date)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.AreEqual(0, errors.Count);
            verifyParseExtendedPrimitive(result);
        }
Example #10
0
        public void ParsePerformance()
        {
            //string file = @"..\..\..\loinc.json";
            string file = @"..\..\..\..\..\publish\diagnosticreport-example.xml";

            int repeats = 20;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            ErrorList errors = new ErrorList();

            for (int i = 0; i < repeats; i++)
            {
                errors.Clear();
                var xmlr = XmlReader.Create(file);
                //var jsonr = new JsonTextReader(new System.IO.StreamReader(file));
                //var rep = FhirParser.ParseResource(jsonr, errors);
                var rep = FhirParser.ParseResource(xmlr, errors);
            }

            Assert.IsTrue(errors.Count == 0, errors.ToString());

            sw.Stop();

            FileInfo f          = new FileInfo(file);
            long     bytesPerMs = f.Length * repeats / sw.ElapsedMilliseconds;

            File.WriteAllText(@"c:\temp\speedtest.txt", bytesPerMs.ToString() + " bytes per ms");
            //  Assert.IsTrue(bytesPerMs > 10*1024);       // > 10k per ms (Speed is of course very dependent on debug/release and machine)
        }
Example #11
0
        public void BinaryParsing()
        {
            string xmlString = @"<Binary id='pic1' contentType='image/gif' xmlns='http://hl7.org/fhir'>R0lGODlhEwARAPcAAAAAAAAA/+9aAO+1AP/WAP/eAP/eCP/eEP/eGP/nAP/nCP/nEP/nIf/nKf/nUv/nWv/vAP/vCP/vEP/vGP/vIf/vKf/vMf/vOf/vWv/vY//va//vjP/3c//3lP/3nP//tf//vf///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEAAAEALAAAAAATABEAAAi+AAMIDDCgYMGBCBMSvMCQ4QCFCQcwDBGCA4cLDyEGECDxAoAQHjxwyKhQAMeGIUOSJJjRpIAGDS5wCDly4AALFlYOgHlBwwOSNydM0AmzwYGjBi8IHWoTgQYORg8QIGDAwAKhESI8HIDgwQaRDI1WXXAhK9MBBzZ8/XDxQoUFZC9IiCBh6wEHGz6IbNuwQoSpWxEgyLCXL8O/gAnylNlW6AUEBRIL7Og3KwQIiCXb9HsZQoIEUzUjNEiaNMKAAAA7</Binary>";

            ErrorList errors = new ErrorList();
            Binary    result = (Binary)FhirParser.ParseResourceFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count() == 0, errors.ToString());

            Assert.AreEqual("image/gif", result.ContentType);
            Assert.AreEqual(993, result.Content.Length);
            Assert.IsTrue(Encoding.ASCII.GetString(result.Content).StartsWith("GIF89a"));

            byte[] data = result.Content;
            File.WriteAllBytes(@"c:\temp\test.gif", data);

            string json = "{ Binary: { contentType : \"image/gif\", " +
                          "content: \"R0lGODlhEwARAPcAAAAAAAAA/+9aAO+1AP/WAP/eAP/eCP/eEP/eGP/nAP/nCP/nEP/nIf/nKf/nUv/nWv/vAP/vCP/vEP/vGP/vIf/vKf/vMf/vOf/vWv/vY//va//vjP/3c//3lP/3nP//tf//vf///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEAAAEALAAAAAATABEAAAi+AAMIDDCgYMGBCBMSvMCQ4QCFCQcwDBGCA4cLDyEGECDxAoAQHjxwyKhQAMeGIUOSJJjRpIAGDS5wCDly4AALFlYOgHlBwwOSNydM0AmzwYGjBi8IHWoTgQYORg8QIGDAwAKhESI8HIDgwQaRDI1WXXAhK9MBBzZ8/XDxQoUFZC9IiCBh6wEHGz6IbNuwQoSpWxEgyLCXL8O/gAnylNlW6AUEBRIL7Og3KwQIiCXb9HsZQoIEUzUjNEiaNMKAAAA7\" } }";

            errors.Clear();
            result = (Binary)FhirParser.ParseResourceFromJson(json, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());

            Assert.AreEqual("image/gif", result.ContentType);
            Assert.AreEqual(993, result.Content.Length);
            Assert.IsTrue(Encoding.ASCII.GetString(result.Content).StartsWith("GIF89a"));
        }
        private bool validations()
        {
            ErrorList.Clear();
            PasswordError = false;
            EmailError    = false;
            UsernameError = false;
            if (Email == null || !(Email.Contains("@")))
            {
                //den einai egkyro to email peta kapoio error
                EmailError = true;
                ErrorList.Add("Please input a valid email.");
            }
            if (Username == null || Username.Length <= 2)
            {
                UsernameError = true;
                ErrorList.Add("Please input a username length greater than 2.");
            }

            if ((Password != ConfirmPassword) || (Password == null || ConfirmPassword == null))
            {
                PasswordError = true;
                ErrorList.Add("Password doesn't match.");
            }
            if (PasswordError || EmailError || UsernameError)
            {
                return(false);
            }
            return(true);
        }
Example #13
0
        public void ValidateProperty(object value, [CallerMemberName] string propertyName = null)
        {
            lock (_lock)
            {
                var validationContext = new ValidationContext(this, null, null);
                validationContext.MemberName = propertyName;
                var validationResults = new List <ValidationResult>();
                Validator.TryValidateProperty(value, validationContext, validationResults);

                //clear previous _errors from tested property
                if (_errors.ContainsKey(propertyName))
                {
                    _errors.Remove(propertyName);
                }
                OnErrorsChanged(propertyName);
                HandleValidationResults(validationResults);
            }

            //add to listo que a viewmodel usa para exibir
            ErrorList.Clear();
            foreach (var x in _errors)
            {
                foreach (var y in x.Value)
                {
                    ErrorList.Add(y.ToString());
                }
            }
        }
Example #14
0
        public void NarrativeParsing()
        {
            string xmlString = @"<testNarrative xmlns='http://hl7.org/fhir'>
                                    <status value='generated' />
                                    <div xmlns='http://www.w3.org/1999/xhtml'>Whatever</div>
                                 </testNarrative>";

            ErrorList errors = new ErrorList();
            Narrative result = (Narrative)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(Narrative.NarrativeStatus.Generated, result.Status.Value);
            Assert.IsTrue(result.Div != null);

            xmlString = @"<testNarrative xmlns='http://hl7.org/fhir'>
                             <status value='generated' />
                             <xhtml:div xmlns:xhtml='http://www.w3.org/1999/xhtml'>Whatever</xhtml:div>
                          </testNarrative>";
            errors.Clear();

            result = (Narrative)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(Narrative.NarrativeStatus.Generated, result.Status.Value);
            Assert.IsTrue(result.Div != null);

            xmlString = @"<testNarrative xmlns='http://hl7.org/fhir' xmlns:xhtml='http://www.w3.org/1999/xhtml'>
                              <status value='generated' />
                              <xhtml:div>Whatever</xhtml:div>
                          </testNarrative>";
            errors.Clear();

            result = (Narrative)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(Narrative.NarrativeStatus.Generated, result.Status.Value);
            Assert.IsTrue(result.Div != null);

            string jsonString = "{ \"testNarrative\" : {" +
                                "\"status\" : { \"value\" : \"generated\" }, " +
                                "\"div\" : " +
                                "\"<div xmlns='http://www.w3.org/1999/xhtml'>Whatever</div>\" } }";

            errors.Clear();
            result = (Narrative)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(Narrative.NarrativeStatus.Generated, result.Status.Value);
            Assert.IsTrue(result.Div != null);
        }
Example #15
0
        /// <summary>
        /// Peuple la structure du modèle objet en paramètre à partir d'un fichier Eap.
        /// </summary>
        /// <returns>La collection de message d'erreurs au format NVortex.</returns>
        public override ICollection <ModelRoot> Parse()
        {
            ErrorList.Clear();
            _modelRootList = new List <ModelRoot>();
            foreach (string modelFile in ModelFiles)
            {
                DisplayMessage("Analyse du fichier " + modelFile);
                using (FileStream stream = new FileStream(modelFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                    _currentEap = new XmlDocument();
                    _currentEap.Load(stream);
                }

                _currentNsManager = new XmlNamespaceManager(_currentEap.NameTable);
                _currentNsManager.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
                _currentNsManager.AddNamespace("uml", "http://schema.omg.org/spec/UML/2.1");
                _currentNsManager.AddNamespace("xmi", "http://schema.omg.org/spec/XMI/2.1");
                _currentNsManager.AddNamespace("thecustomprofile", "http://www.sparxsystems.com/profiles/thecustomprofile/1.0");

                XmlNode extensionNode = _currentEap.SelectSingleNode(NodeExtension, _currentNsManager);
                XmlNode modelNode     = _currentEap.SelectSingleNode(NodeModel, _currentNsManager);

                string    modelNodeName = modelNode.SelectSingleNode(NodePackageModel, _currentNsManager).Attributes[PropertyName].Value;
                ModelRoot root          = new ModelRoot()
                {
                    ModelFile = modelFile,
                    Label     = modelNodeName,
                    Name      = ConvertModelName(modelNodeName)
                };
                _currentModelRoot = root;

                DisplayMessage("==> Parsing du modèle " + root.Label + "(" + root.Name + ")");

                DisplayMessage("--> Lecture des domaines.");
                string  domainsId             = _currentEap.SelectSingleNode(NodeDomainsDefinition, _currentNsManager).Attributes[PropertyBasePackage].Value;
                XmlNode domainsNode           = _currentEap.SelectSingleNode(string.Format(NodeDomainsByIdRef, domainsId), _currentNsManager);
                XmlNode extensionElementsNode = _currentEap.SelectSingleNode(NodeExtensionElements, _currentNsManager);
                BuildModelDomains(domainsNode, extensionElementsNode, modelFile);

                DisplayMessage("--> Lecture des namespaces.");
                List <string> namespaceNodeIdList = new List <string>();
                foreach (XmlNode namespaceIdNode in _currentEap.SelectNodes(NodeNamespaceDefinition, _currentNsManager))
                {
                    namespaceNodeIdList.Add(namespaceIdNode.Attributes[PropertyBasePackage].Value);
                }

                BuildModelNamespaces(extensionElementsNode, namespaceNodeIdList, modelFile);

                DisplayMessage("--> Lecture des héritages.");
                XmlNode extensionConnectorsNode = _currentEap.SelectSingleNode(NodeExtensionConnectors, _currentNsManager);
                BuildModelNamespaceGeneralizations(extensionConnectorsNode, modelFile);

                DisplayMessage("--> Lecture des associations.");
                BuildModelNamespaceAssociations(extensionConnectorsNode, modelFile);

                _modelRootList.Add(root);
            }

            return(_modelRootList);
        }
Example #16
0
        public void CatchTagListParseErrors()
        {
            ErrorList errors = new ErrorList();
            var tl = FhirParser.ParseTagListFromXml(xmlTagListE1, errors);
            Assert.IsTrue(errors.Count != 0, errors.ToString());
            errors.Clear();
            tl = FhirParser.ParseTagListFromXml(xmlTagListE2, errors);
            Assert.IsTrue(errors.Count != 0, errors.ToString());
            errors.Clear();

            tl = FhirParser.ParseTagListFromJson(jsonTagListE1, errors);
            Assert.IsTrue(errors.Count != 0, errors.ToString());
            errors.Clear();
            tl = FhirParser.ParseTagListFromJson(jsonTagListE2, errors);
            Assert.IsTrue(errors.Count != 0, errors.ToString());
            errors.Clear();
        }
        public void NarrativeParsing()
        {
            string xmlString = @"<testNarrative xmlns='http://hl7.org/fhir'>
                                    <status value='generated' />
                                    <div xmlns='http://www.w3.org/1999/xhtml'>Whatever</div>
                                 </testNarrative>";

            ErrorList errors = new ErrorList();
            Narrative result = (Narrative)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(Narrative.NarrativeStatus.Generated, result.Status.Value);
            Assert.IsTrue(result.Div != null);

            xmlString = @"<testNarrative xmlns='http://hl7.org/fhir'>
                             <status value='generated' />
                             <xhtml:div xmlns:xhtml='http://www.w3.org/1999/xhtml'>Whatever</xhtml:div>
                          </testNarrative>";
            errors.Clear();

            result = (Narrative)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(Narrative.NarrativeStatus.Generated, result.Status.Value);
            Assert.IsTrue(result.Div != null);

            xmlString = @"<testNarrative xmlns='http://hl7.org/fhir' xmlns:xhtml='http://www.w3.org/1999/xhtml'>
                              <status value='generated' />
                              <xhtml:div>Whatever</xhtml:div>
                          </testNarrative>";
            errors.Clear();

            result = (Narrative)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(Narrative.NarrativeStatus.Generated, result.Status.Value);
            Assert.IsTrue(result.Div != null);

            string jsonString = "{ \"testNarrative\" : {" +
                "\"status\" : { \"value\" : \"generated\" }, " +
                "\"div\" : " +
                "\"<div xmlns='http://www.w3.org/1999/xhtml'>Whatever</div>\" } }";

            errors.Clear();
            result = (Narrative)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(Narrative.NarrativeStatus.Generated, result.Status.Value);
            Assert.IsTrue(result.Div != null);
        }
Example #18
0
 protected void btnClose_Click(object sender, EventArgs e)
 {
     if (errorList != null)
     {
         errorList.Clear();
     }
     Show(errorList);
 }
Example #19
0
 private void btnClose_Click(object sender, RoutedEventArgs e)
 {
     if (errorList != null)
     {
         errorList.Clear();
     }
     ((IErrorPresenter)this).Show(errorList);
 }
Example #20
0
        public void CatchTagListParseErrors()
        {
            ErrorList errors = new ErrorList();
            var       tl     = FhirParser.ParseTagListFromXml(xmlTagListE1, errors);

            Assert.IsTrue(errors.Count != 0, errors.ToString());
            errors.Clear();
            tl = FhirParser.ParseTagListFromXml(xmlTagListE2, errors);
            Assert.IsTrue(errors.Count != 0, errors.ToString());
            errors.Clear();

            tl = FhirParser.ParseTagListFromJson(jsonTagListE1, errors);
            Assert.IsTrue(errors.Count != 0, errors.ToString());
            errors.Clear();
            tl = FhirParser.ParseTagListFromJson(jsonTagListE2, errors);
            Assert.IsTrue(errors.Count != 0, errors.ToString());
            errors.Clear();
        }
        public void OnTemplateChanged(string templatePath, bool force = false)
        {
            Log.Debug("{0} queued {1}", GenerationType.Template, templatePath);

            ErrorList.Clear();

            ThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                var projectItem = _dte.Solution.FindProjectItem(templatePath);

                var template = _templateController.GetTemplate(projectItem);

                if (force == false && ExtensionPackage.Instance.RenderOnSave == false)
                {
                    Log.Debug("Render skipped {0}", templatePath);
                    return;
                }

                var filesToRender = template.GetFilesToRender();
                Log.Debug(" Will Check/Render {0} .cs files in referenced projects", filesToRender.Count);


                // Delay to wait for Roslyn to refresh the current Workspace after a change.
                await Task.Delay(1000).ConfigureAwait(true);
                _eventQueue.Enqueue(() =>
                {
                    var stopwatch = Stopwatch.StartNew();

                    foreach (var path in filesToRender)
                    {
                        var metadata = _metadataProvider.GetFile(path, template.Settings, null);
                        if (metadata == null)
                        {
                            // the cs-file was found, but the build-action is not set to compile.
                            continue;
                        }

                        var file = new FileImpl(metadata);

                        template.RenderFile(file);

                        if (template.HasCompileException)
                        {
                            break;
                        }
                    }

                    template.SaveProjectFile();

                    stopwatch.Stop();
                    Log.Debug("{0} processed {1} in {2}ms", GenerationType.Template, templatePath,
                              stopwatch.ElapsedMilliseconds);
                });
            });
        }
 public void ResetErrorList()
 {
     try
     {
         ErrorList.Clear();
     }
     catch (Exception ex)
     {
     }
 }
Example #23
0
        public void HandleCrapInFhirParser()
        {
            var errors = new ErrorList();

            FhirParser.ParseResourceFromJson("Crap!", errors);
            Assert.IsTrue(errors.Count > 0);

            errors.Clear();
            FhirParser.ParseResourceFromJson("{ \" Crap!", errors);
            Assert.IsTrue(errors.Count > 0);

            errors.Clear();
            FhirParser.ParseResourceFromXml("Crap", errors);
            Assert.IsTrue(errors.Count > 0);

            errors.Clear();
            FhirParser.ParseResourceFromXml("<Crap><cra", errors);
            Assert.IsTrue(errors.Count > 0);
        }
Example #24
0
 public void EventHandler_Compile(object sender, System.EventArgs e)
 {
     try
     {
         TreeNode node = gscriptTreeView.SelectedNode;
         if (node != null)
         {
             ScriptTreeNodeProperty prop = (ScriptTreeNodeProperty)node.Tag;
             if (prop != null)
             {
                 if (prop.Type == ScriptTreeNodeType.G ||
                     prop.Type == ScriptTreeNodeType.Simple)
                 {
                     ScriptType type;
                     type = prop.Type == ScriptTreeNodeType.G ? ScriptType.G : ScriptType.Simple;
                     string code = scriptRepository__.GetContent(prop.Name, type);
                     compiler__.ClearCodes();
                     compiler__.AddCode(code);
                     int ret = compiler__.Compile();
                     Output.Clear();
                     ErrorList.Clear();
                     if (ret > 0)
                     {
                         foreach (CompilerError error in compiler__.Errors)
                         {
                             ErrorLevel level = error.IsWarning ? ErrorLevel.elWarning : ErrorLevel.elError;
                             ErrorList.Add(level, error.ErrorNumber, error.ErrorText, error.Line);
                         }
                         Output.Add(Resources.TEXT_ERR_COMPILE);
                         ErrorList.Show();
                     }
                     else if (ret == 0)
                     {
                         Output.Add(Resources.TEXT_COMPILE_OK);
                         Output.Show();
                     }
                     else if (ret == -1)
                     {
                         Output.Add(Resources.TEXT_ERR_NO_CODE);
                         Output.Show();
                     }
                     else
                     {
                         Output.Add(Resources.TEXT_ERR_COMPILE_GENERAL);
                         Output.Show();
                     }
                 }
             }
         }
     }
     catch
     {
         throw;
     }
 }
Example #25
0
        public static Type Compile(ProjectItem projectItem, ShadowClass shadowClass)
        {
            if (Directory.Exists(Constants.TempDirectory) == false)
            {
                Directory.CreateDirectory(Constants.TempDirectory);
            }

            var filname = Path.GetRandomFileName();
            var path    = Path.Combine(Constants.TempDirectory, filname);

            var result = shadowClass.Compile(path);

            ErrorList.Clear();

            var errors = result.Diagnostics.Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error || diagnostic.Severity == DiagnosticSeverity.Warning);

            var hasErrors = false;

            foreach (var error in errors)
            {
                var message = error.GetMessage();

                message = message.Replace("__Typewriter.", string.Empty);
                //message = message.Replace("__Code.", string.Empty);
                message = message.Replace("publicstatic", string.Empty);

                Log.Warn("Template error: {0} {1}", error.Id, message);

                if (error.Severity == DiagnosticSeverity.Error || error.IsWarningAsError)
                {
                    ErrorList.AddError(projectItem, message);
                    hasErrors = true;
                }
                else
                {
                    ErrorList.AddWarning(projectItem, message);
                }
            }

            if (hasErrors)
            {
                ErrorList.Show();
            }

            if (result.Success)
            {
                var assembly = Assembly.LoadFrom(path);
                var type     = assembly.GetType("__Typewriter.Template");

                return(type);
            }

            throw new Exception("Failed to compile template.");
        }
 public void ResetErrorList()
 {
     try
     {
         ErrorList.Clear();
     }
     catch (Exception ex)
     {
         WebErrorLog.ErrorInstence.StartErrorLog(ex);
     }
 }
Example #27
0
        public void ClearErrors()
        {
            List <string> oldErrorProperties = errors.Select(x => x.Key.ToString()).ToList();

            errors.Clear();
            ErrorList.Clear();
            foreach (var p in oldErrorProperties)
            {
                NotifyErrorsChanged(p);
            }
            NotifyErrorsChanged("");
        }
Example #28
0
    public void GetObjectByComponent(string Name)
    {
        ErrorList.Clear();
        List <GameObject> allObject    = GetAllObjectsInScene();
        List <GameObject> componentObj = new List <GameObject>();

        foreach (GameObject nowObj in allObject)
        {
            if (nowObj.GetComponent(Name))
            {
                ErrorList.Add(nowObj);
            }
        }
    }
Example #29
0
        bool Check()
        {
            bool result = true;

            ErrorList.Clear();

            // Номер
            if (string.IsNullOrWhiteSpace(_protocol.Number))
            {
                ErrorList.Add("Не указан номер протокола");
                result = false;
            }

            // Дата
            if (_protocol.Date == null)
            {
                ErrorList.Add("Не указана дата протокола");
                result = false;
            }

            // Конкурсная группа
            if (_protocol.CompetitiveGroup == null)
            {
                ErrorList.Add("Не найдена конкурсная группа по текущим условиям фильтра");
                result = false;
            }

            // Дата окончания образовательной программы
            if (_protocol.TrainingEndDate == null)
            {
                ErrorList.Add("Не указана дата окончания образовательной программы");
                result = false;
            }

            // Срок обучения
            if (_protocol.TrainingTime == null)
            {
                ErrorList.Add("Не указан срок обучения");
                result = false;
            }

            // Факультет
            if (_protocol.Faculty == null)
            {
                ErrorList.Add("Не указан факультет");
                result = false;
            }

            return(result);
        }
Example #30
0
 /// <summary>
 /// Occurs when the script is going to be run.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void EventHandler_Run(object sender, System.EventArgs e)
 {
     try
     {
         compiler__.ClearCodes();
         compiler__.AddCode(syntaxDocument1.Text);
         int ret = compiler__.Compile();
         Output.Clear();
         ErrorList.Clear();
         if (ret > 0)
         {
             foreach (CompilerError error in compiler__.Errors)
             {
                 ErrorLevel level = error.IsWarning ? ErrorLevel.elWarning : ErrorLevel.elError;
                 ErrorList.Add(level, error.ErrorNumber, error.ErrorText, error.Line);
             }
             Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_ERR_COMPILE);
             ErrorList.Show();
         }
         else if (ret == 0)
         {
             Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_COMPILE_OK);
             Output.Show();
             try
             {
                 compiler__.Run("Program", "Main");
             }
             catch (Exception ex)
             {
                 //ExceptionMessageBox.ShowDialog(ex);
                 Exception param = ex.InnerException == null ? ex : ex.InnerException;
                 ExceptionMessageBox.ShowDialog(param, true);
             }
         }
         else if (ret == -1)
         {
             Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_ERR_NO_CODE);
             Output.Show();
         }
         else
         {
             Output.Add(SunnyChen.Gulu.Win.Properties.Resources.TEXT_ERR_COMPILE_GENERAL);
             Output.Show();
         }
     }
     catch
     {
         throw;
     }
 }
Example #31
0
        public void ParseEmptyPrimitive()
        {
            string     xmlString = "<someString xmlns='http://hl7.org/fhir' id='4' />";
            ErrorList  errors    = new ErrorList();
            FhirString result    = (FhirString)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsNotNull(result);
            Assert.IsNull(result.Value);
            Assert.AreEqual("4", result.Id.ToString());

            xmlString = "<someString xmlns='http://hl7.org/fhir' id='4' value='' />";
            errors.Clear();
            result = (FhirString)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsNotNull(result);
            Assert.IsNull(result.Value);
            Assert.AreEqual("4", result.Id.ToString());

            string jsonString = "{ \"someString\" : { \"_id\" : \"4\" } }";

            errors.Clear();
            result = (FhirString)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsNotNull(result);
            Assert.IsNull(result.Value);
            Assert.AreEqual("4", result.Id.ToString());

            jsonString = "{ \"someString\" : { \"_id\" : \"4\", \"value\" : \"\" } }";
            errors.Clear();
            result = (FhirString)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsNotNull(result);
            Assert.IsNull(result.Value);
            Assert.AreEqual("4", result.Id.ToString());
        }
Example #32
0
        public void ParseLargeComposite()
        {
            XmlReader        xr     = XmlReader.Create(new StreamReader(@"..\..\..\..\..\publish\diagnosticreport-example.xml"));
            ErrorList        errors = new ErrorList();
            DiagnosticReport rep    = (DiagnosticReport)FhirParser.ParseResource(xr, errors);

            validateDiagReportAttributes(errors, rep);

            JsonTextReader jr = new JsonTextReader(new StreamReader(@"..\..\..\..\..\publish\diagnosticreport-example.json"));

            errors.Clear();
            rep = (DiagnosticReport)FhirParser.ParseResource(jr, errors);

            validateDiagReportAttributes(errors, rep);
        }
        public void ParsePrimitive()
        {
            string xmlString = "<someBoolean xmlns='http://hl7.org/fhir' value='true' id='3141' />";
            ErrorList errors = new ErrorList();
            FhirBoolean result = (FhirBoolean)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count == 0, errors.ToString());
            Assert.AreEqual(true, result.Value);
            Assert.AreEqual("3141", result.Id.ToString());

            string jsonString = "{\"someBoolean\": { \"value\" : true, \"_id\" : \"3141\" } }";
            errors.Clear();
            result = (FhirBoolean)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count == 0, errors.ToString());
            Assert.AreEqual(true, result.Value);
            Assert.AreEqual("3141", result.Id.ToString());
        }
Example #34
0
        public void ParsePrimitiveWithIllegalAttribute()
        {
            string      xmlString = "<someBoolean xmlns='http://hl7.org/fhir' value='true' unknownattr='yes' />";
            ErrorList   errors    = new ErrorList();
            FhirBoolean result    = (FhirBoolean)FhirParser.ParseElementFromXml(xmlString, errors);

            Assert.IsTrue(errors.Count == 1);
            Assert.IsTrue(errors[0].Message.Contains("unknownattr"));

            string jsonString = "{\"someBoolean\": { \"value\" : true, \"unknownattr\" : \"yes\" } }";

            errors.Clear();
            result = (FhirBoolean)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count == 1);
            Assert.IsTrue(errors[0].Message.Contains("unknownattr"));
        }
Example #35
0
        // Runs after each job is done.
        private void JobsFinished()
        {
            m_threadDone++;
            if ((m_task.m_threadCount == m_threadDone && !Settings.UseLzma2) || Settings.UseLzma2)
            {
                timer.Stop();
                m_stopWatch.Stop();

                m_working = false;
                btnBrowseSteam.Enabled  = true;
                btnFindSteam.Enabled    = true;
                btnBrowseBackup.Enabled = true;
                tbxSteamDir.Enabled     = true;
                tbxBackupDir.Enabled    = true;
                btnBackup.Visible       = true;
                btnRestore.Visible      = true;
                btnCancel.Visible       = false;
                btnPause.Visible        = false;
                btnPause.Text           = Resources.PauseText;
                btnShowLog.Visible      = false;
                btnUpdWiz.Visible       = true;
                SetScreenSize(400, 402);
                lbl0.Text = string.Format(Resources.VersionStr, m_versionNum);

                TimeSpan ts          = m_stopWatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

                if (ErrorList.HasErrors())
                {
                    string str = string.Format(Resources.FinishedWithErrorsText, m_task.m_jobsDone, m_task.m_jobsToDoCount, elapsedTime);
                    MessageBox.Show(str, Resources.FinishedWithErrorsTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    string str = string.Format(Resources.FinishedText, m_task.m_jobsDone, m_task.m_jobsToDoCount, elapsedTime);
                    MessageBox.Show(str, Resources.FinishedTitle);
                }

                ErrorList.Clear();
                lblProgress.Text = m_task.ProgressText();
                m_task           = null;
            }
            else
            {
                lblProgress.Text = m_task.ProgressText();
            }
        }
        public void HandleCrapInFhirParser()
        {
            var errors = new ErrorList();
            FhirParser.ParseResourceFromJson("Crap!", errors);
            Assert.IsTrue(errors.Count > 0);

            errors.Clear();
            FhirParser.ParseResourceFromJson("{ \" Crap!", errors);
            Assert.IsTrue(errors.Count > 0);

            errors.Clear();
            FhirParser.ParseResourceFromXml("Crap", errors);
            Assert.IsTrue(errors.Count > 0);

            errors.Clear();
            FhirParser.ParseResourceFromXml("<Crap><cra", errors);
            Assert.IsTrue(errors.Count > 0);
        }
        public void ParseLargeComposite()
        {
            XmlReader xr = XmlReader.Create(new StreamReader(@"..\..\..\..\..\publish\diagnosticreport-example.xml"));
            ErrorList errors = new ErrorList();
            DiagnosticReport rep = (DiagnosticReport)FhirParser.ParseResource(xr, errors);

            validateDiagReportAttributes(errors, rep);

            JsonTextReader jr = new JsonTextReader(new StreamReader(@"..\..\..\..\..\publish\diagnosticreport-example.json"));
            errors.Clear();
            rep = (DiagnosticReport)FhirParser.ParseResource(jr, errors);

            validateDiagReportAttributes(errors, rep);
        }
        public void ParseJsonNativeTypes()
        {
            string json = "{ testExtension: { url: { value : \"http://bla.com\" }," +
                        "isModifier: { value: true }, valueInteger: { value: 14 } } }";

            var errors = new ErrorList();
            var result = (Extension)FhirParser.ParseElementFromJson(json, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.IsTrue(result.IsModifier.Value);
            Assert.AreEqual(14, ((Integer)result.Value).Value.Value);

            string jsonWrong = "{ testExtension: { url: { value : \"http://bla.com\" }," +
                        "isModifier: { value: \"true\" }, valueInteger: { value: \"14\" } } }";
            errors.Clear();
            result = (Extension)FhirParser.ParseElementFromJson(jsonWrong, errors);
            Assert.IsTrue(errors.Count() > 0);
            Assert.IsTrue(errors.ToString().Contains("Expected") &&
                        errors.ToString().Contains("Boolean"),errors.ToString());
        }
        public void JsonDivZonderNamespace()
        {
            string jsonString = "{ \"testNarrative\" : {" +
                "\"status\" : { \"value\" : \"generated\" }, " +
                "\"div\" : " +
                "\"<div>Whatever</div>\" } }";

            var errors = new ErrorList();
            var result = (Narrative)FhirParser.ParseElementFromJson(jsonString, errors);
            var xml = FhirSerializer.SerializeElementAsXml(result, "testNarrative");
            Assert.IsTrue(xml.Contains("w3.org/1999/xhtml"));

            jsonString = "{ \"testNarrative\" : {" +
             "\"status\" : { \"value\" : \"generated\" }, " +
             "\"div\" : " +
             "\"<div xmlns='http://www.w3.org/1999/xhtml'>Whatever</div>\" } }";

            errors.Clear();
            result = (Narrative)FhirParser.ParseElementFromJson(jsonString, errors);
            xml = FhirSerializer.SerializeElementAsXml(result, "testNarrative");
            Assert.IsTrue(xml.Contains("w3.org/1999/xhtml"));
        }
        public void ParseExtendedPrimitiveWithOtherElements()
        {
            string xmlString =
                @"<birthDate xmlns='http://hl7.org/fhir' value='1972-11-30'>
                    <crap />
                    <extension>
                       <url value='http://hl7.org/fhir/profile/@iso-21090#nullFlavor' />
                       <valueCode value='UNK' />
                    </extension>
                  </birthDate>";

            ErrorList errors = new ErrorList();
            Date result = (Date)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.AreNotEqual(0, errors.Count);
            Assert.IsTrue(errors.ToString().Contains("crap"));

            xmlString =
                @"<birthDate xmlns='http://hl7.org/fhir' value='1972-11-30'>
                    <crap xmlns=""http://furore.com"" />
                    <extension>
                       <url value='http://hl7.org/fhir/profile/@iso-21090#nullFlavor' />
                       <valueCode value='UNK' />
                    </extension>
                  </birthDate>";

            errors.Clear();
            result = (Date)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.AreNotEqual(0, errors.Count);
            Assert.IsTrue(errors.ToString().Contains("crap"));


            string jsonString = @"{ ""birthDate"" : 
                                { 
                                    ""value"" : ""1972-11-30"",
                                    ""crap"" : {},
                                    ""extension"" : [
                                    {
                                        ""url"" : { ""value"" : ""http://hl7.org/fhir/profile/@iso-21090#nullFlavor"" },
                                        ""valueCode"" : { ""value"" : ""UNK"" }
                                    } ]
                                }
                            }";

            errors.Clear();
            result = (Date)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.AreNotEqual(0, errors.Count);
            Assert.IsTrue(errors.ToString().Contains("crap"));
        }
        public void ParseSimpleComposite()
        {
            string xmlString = @"<testCoding id='x4' xmlns='http://hl7.org/fhir'>
                                    <system value='http://hl7.org/fhir/sid/icd-10' />
                                    <code value='G44.1' />
                                 </testCoding>";

            ErrorList errors = new ErrorList();
            Coding result = (Coding)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual("x4", result.LocalId.ToString());
            Assert.AreEqual("G44.1", result.Code);
            Assert.AreEqual("http://hl7.org/fhir/sid/icd-10", result.System.ToString());
            Assert.IsNull(result.Display);

            string jsonString = "{ \"testCoding\" : { \"_id\" : \"x4\", " +
                    "\"system\": { \"value\" : \"http://hl7.org/fhir/sid/icd-10\" }, " +
                    "\"code\": { \"value\" : \"G44.1\" } } }";

            errors.Clear();
            result = (Coding)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual("x4", result.LocalId);
            Assert.AreEqual("G44.1", result.Code);
            Assert.AreEqual("http://hl7.org/fhir/sid/icd-10", result.System.ToString());
            Assert.IsNull(result.Display);
        }
        public void ParsePrimitiveWithIllegalAttribute()
        {
            string xmlString = "<someBoolean xmlns='http://hl7.org/fhir' value='true' unknownattr='yes' />";
            ErrorList errors = new ErrorList();
            FhirBoolean result = (FhirBoolean)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count == 1);
            Assert.IsTrue(errors[0].Message.Contains("unknownattr"));

            string jsonString = "{\"someBoolean\": { \"value\" : true, \"unknownattr\" : \"yes\" } }";
            errors.Clear();
            result = (FhirBoolean)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count == 1);
            Assert.IsTrue(errors[0].Message.Contains("unknownattr"));
        }
        public void CompositeWithRepeatingElement()
        {
            string xmlString = @"
                <testCodeableConcept xmlns='http://hl7.org/fhir'>
                    <coding>
                        <system value=""http://hl7.org/fhir/sid/icd-10"" />
                        <code value=""R51"" />
                    </coding>
                    <coding id='1'>
                        <system value=""http://snomed.info/id"" />
                        <code value=""25064002"" />
                    </coding>
                </testCodeableConcept>";

            ErrorList errors = new ErrorList();
            CodeableConcept result = (CodeableConcept)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(2, result.Coding.Count);
            Assert.AreEqual("R51", result.Coding[0].Code);
            Assert.AreEqual("25064002", result.Coding[1].Code);
            Assert.AreEqual("http://snomed.info/id", result.Coding[1].System.ToString());
            Assert.AreEqual("1", result.Coding[1].LocalId.ToString());

            string jsonString = @"{ ""testCodeableConcept"" :
                    { ""coding"" : [
                        { ""system"" : { ""value"" : ""http://hl7.org/fhir/sid/icd-10"" },
                          ""code"" : { ""value"" : ""R51"" } },
                        { ""_id"" : ""1"",
                          ""system"": { ""value"" : ""http://snomed.info/id"" },
                          ""code"" : { ""value"" : ""25064002"" } } ]
                    } }";

            errors.Clear();
            result = (CodeableConcept)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.IsTrue(errors.Count() == 0, errors.ToString());
            Assert.AreEqual(2, result.Coding.Count);
            Assert.AreEqual("R51", result.Coding[0].Code);
            Assert.AreEqual("25064002", result.Coding[1].Code);
            Assert.AreEqual("http://snomed.info/id", result.Coding[1].System.ToString());
            Assert.AreEqual("1", result.Coding[1].LocalId.ToString());
        }
        public void ParseUnknownMembersAndRecover()
        {
            string xmlString = @"<testCodeableConcept xmlns='http://hl7.org/fhir'>
                    <coding>
                        <system value='http://hl7.org/fhir/sid/icd-10' />
                        <ewout>bla</ewout>
                        <code value='R51' />
                    </coding>
                    <coding id='1'>
                        <system value='http://snomed.info/id' />
                        <code value='25064002' />
                    </coding>
                    <grahame></grahame>
                    </testCodeableConcept>";

            ErrorList errors = new ErrorList();
            CodeableConcept result = (CodeableConcept)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.AreEqual(2,errors.Count);
            Assert.IsTrue(errors[0].ToString().Contains("ewout"));
            Assert.IsTrue(errors[1].ToString().Contains("grahame"));

            string jsonString = @"{ ""testCodeableConcept"" :
                    { ""coding"" : [
                        { ""system"": { ""value"" : ""http://hl7.org/fhir/sid/icd-10"" },
                          ""ewout"" : ""bla"",
                          ""code"" : { ""value"" : ""R51"" }
                        },
                        { ""_id"" : ""1"",
                          ""system"": { ""value"" : ""http://snomed.info/id"" },
                          ""code"" : { ""value"" : ""25064002""  }
                        } ],
                       ""grahame"" : { ""value"" : ""x"" } } }";

            errors.Clear();
            result = (CodeableConcept)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.AreEqual(2, errors.Count);
            Assert.IsTrue(errors[0].ToString().Contains("ewout"));
            Assert.IsTrue(errors[1].ToString().Contains("grahame"));
        }
        public void ParsePerformance()
        {
            //string file = @"..\..\..\loinc.json";
            string file = @"..\..\..\..\..\publish\diagnosticreport-example.xml";

            int repeats = 20;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            ErrorList errors = new ErrorList();

            for (int i = 0; i < repeats; i++)
            {
                errors.Clear();
                var xmlr = XmlReader.Create(file);
                //var jsonr = new JsonTextReader(new System.IO.StreamReader(file));
                //var rep = FhirParser.ParseResource(jsonr, errors);
                var rep = FhirParser.ParseResource(xmlr, errors);
            }

            Assert.IsTrue(errors.Count == 0, errors.ToString());

            sw.Stop();

            FileInfo f = new FileInfo(file);
            long bytesPerMs = f.Length * repeats / sw.ElapsedMilliseconds;

            File.WriteAllText(@"c:\temp\speedtest.txt", bytesPerMs.ToString() + " bytes per ms");
              //  Assert.IsTrue(bytesPerMs > 10*1024);       // > 10k per ms (Speed is of course very dependent on debug/release and machine)
        }
        public void ParseExtendedPrimitive()
        {
            string xmlString =
                @"<birthDate xmlns='http://hl7.org/fhir' value='1972-11-30'>
                    <extension>
                       <url value='http://hl7.org/fhir/profile/@iso-21090#nullFlavor' />
                       <valueCode value='UNK' />
                    </extension>
                  </birthDate>";

            ErrorList errors = new ErrorList();
            Date result = (Date)FhirParser.ParseElementFromXml(xmlString, errors);
            Assert.AreEqual(0, errors.Count, errors.ToString());
            verifyParseExtendedPrimitive(result);

            string jsonString = @"{ ""birthDate"" : 
                                { 
                                    ""value"" : ""1972-11-30"",
                                    ""extension"" : [
                                    {
                                        ""url"" : { ""value"" : ""http://hl7.org/fhir/profile/@iso-21090#nullFlavor"" },
                                        ""valueCode"" : { ""value"" : ""UNK"" }
                                    } ]
                                }
                            }";

            errors.Clear();
            result = (Date)FhirParser.ParseElementFromJson(jsonString, errors);
            Assert.AreEqual(0, errors.Count);
            verifyParseExtendedPrimitive(result);
        }