示例#1
0
文件: Xml.cs 项目: rgatkinson/nadir
 string XMLSerialize(object oResult)
 // http://msdn.microsoft.com/en-us/library/58a18dwa(v=VS.100).aspx
     {
     IXmlWritable wResult = oResult as IXmlWritable;
     if (wResult != null)
         {
         XmlSerializer ser = new XmlSerializer(typeof(XmlElement));
         TextWriter writer = new Utf8StringWriter();
         XmlContext context = new XmlContext();
         //
         context.Document = new XmlDocument();
         //
         XmlElement wElement = wResult.ToXml(context);;
         //
         XmlElement rootElement = context.CreateElement("Root");
         rootElement.Attributes.Append(context.CreateAttribute("randSeed", MiscUtil.RandSeed));
         rootElement.AppendChild(wElement);
         //
         context.Document.AppendChild(rootElement);
         //
         ser.Serialize(writer, context.Document);
         writer.Close();
         return writer.ToString();
         }
     return null;
     }
示例#2
0
        public void GivenEmptyContext_WhenSavedState_ThenXmlAsExpected()
        {
            //Given
            var context = GetNewContext();

            //When
            var account = new BankAccount() { Number = "A", Name = "B", Description = "C" };
            var accountsRepository = context.GetRepository<IRepository<BankAccount>>();
            accountsRepository.Add(account);

            var opType = new BankOperationType() { Name = "xx" };
            var opTypeRepository = context.GetRepository<IRepository<BankOperationType>>();
            opTypeRepository.Add(opType);

            var ops = new List<BankOperation>()
            {
                new BankOperation(){Id=1,Description="A",BankAccount=account, Type = opType},
                new BankOperation(){Id=2,Description="C",BankAccount =account, Type = opType}
            };

            var opRepository = context.GetRepository<IRepository<BankOperation>>();
            foreach (var item in ops)
            {
                opRepository.Add(item);
            }

            var statement = new BankStatement()
            {
                FileName = "A",
                LoadTime = new DateTime(),
                Operations = ops
            };
            var statementRepository = context.GetRepository<IRepository<BankStatement>>();
            statementRepository.Add(statement);

            Assert.IsTrue(context.SaveChanges());

            //Then
            _saveMock.Verify(a => a.Save(It.IsAny<XElement>()));
            Assert.IsNotNull(_savedContext.ToString());

            _saveMock.Setup(a => a.Load()).Returns(new XElement(_savedContext));

            var context2 = new XmlContext(_saveMock.Object, GetRepoFactory());
        }
        /// <summary>
        /// Reads information about time unit or variable unit
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        private Unit ReadUnit(XmlReader r)
        {
            Unit unitInfo = Unit.Unknown;

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    string nodeName = r.Name.ToLower();
                    if (nodeName == "unitname")
                    {
                        r.Read();
                        unitInfo.Name = r.Value;
                    }
                    else if (nodeName == "unittype")
                    {
                        r.Read();
                        unitInfo.UnitsType = r.Value;
                    }
                    else if (nodeName == "unitabbreviation")
                    {
                        r.Read();
                        unitInfo.Abbreviation = r.Value;
                    }
                }
                else if (r.NodeType == XmlNodeType.EndElement && r.Name == "unit")
                {
                    return(unitInfo);
                }
            }
            return(unitInfo);
        }
示例#4
0
 public string GetAttributeValue(XmlContext context, string lookupName)
 {
     return(context.CurrentNode.GetAttribute(lookupName, ""));
 }
示例#5
0
 /// <summary>
 /// Internals the serialize.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="ctx">The CTX.</param>
 protected abstract void InternalUnSerialize(XmlReader reader, XmlContext ctx);
示例#6
0
        // This constructor is used when creating XmlTextReaderImpl reader via "XmlReader.Create(..)"
        private XmlTextReaderImpl(XmlResolver resolver, XmlReaderSettings settings, XmlParserContext context)
        {
            _useAsync = settings.Async;
            _v1Compat = false;
            _outerReader = this;

            _xmlContext = new XmlContext();

            // create or get nametable and namespace manager from XmlParserContext
            XmlNameTable nt = settings.NameTable;
            if (context == null)
            {
                if (nt == null)
                {
                    nt = new NameTable();
                    Debug.Assert(_nameTableFromSettings == false);
                }
                else
                {
                    _nameTableFromSettings = true;
                }
                _nameTable = nt;
                _namespaceManager = new XmlNamespaceManager(nt);
            }
            else
            {
                SetupFromParserContext(context, settings);
                nt = _nameTable;
            }

            nt.Add(string.Empty);
            _xml = nt.Add("xml");
            _xmlNs = nt.Add("xmlns");

            _xmlResolver = resolver;

            Debug.Assert(_index == 0);

            _nodes = new NodeData[NodesInitialSize];
            _nodes[0] = new NodeData();
            _curNode = _nodes[0];

            _stringBuilder = new StringBuilder();

            // Needed only for XmlTextReader (reporting of entities)
            _entityHandling = EntityHandling.ExpandEntities;

            _xmlResolverIsSet = settings.IsXmlResolverSet;

            _whitespaceHandling = (settings.IgnoreWhitespace) ? WhitespaceHandling.Significant : WhitespaceHandling.All;
            _normalize = true;
            _ignorePIs = settings.IgnoreProcessingInstructions;
            _ignoreComments = settings.IgnoreComments;
            _checkCharacters = settings.CheckCharacters;
            _lineNumberOffset = settings.LineNumberOffset;
            _linePositionOffset = settings.LinePositionOffset;
            _ps.lineNo = _lineNumberOffset + 1;
            _ps.lineStartPos = -_linePositionOffset - 1;
            _curNode.SetLineInfo(_ps.LineNo - 1, _ps.LinePos - 1);
            _dtdProcessing = settings.DtdProcessing;
            _maxCharactersInDocument = settings.MaxCharactersInDocument;
            _maxCharactersFromEntities = settings.MaxCharactersFromEntities;

            _charactersInDocument = 0;
            _charactersFromEntities = 0;

            _fragmentParserContext = context;

            _parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl;
            _nextParsingFunction = ParsingFunction.DocumentContent;

            switch (settings.ConformanceLevel)
            {
                case ConformanceLevel.Auto:
                    _fragmentType = XmlNodeType.None;
                    _fragment = true;
                    break;
                case ConformanceLevel.Fragment:
                    _fragmentType = XmlNodeType.Element;
                    _fragment = true;
                    break;
                case ConformanceLevel.Document:
                    _fragmentType = XmlNodeType.Document;
                    break;
                default:
                    Debug.Assert(false);
                    goto case ConformanceLevel.Document;
            }
        }
 public FileRepository(XmlContext context) : base(context)
 {
 }
示例#8
0
        protected virtual void ReadSpatialReference(XmlReader r, Site site)
        {
            while (r.Read())
            {
                //lat long datum (srs)
                if (r.NodeType == XmlNodeType.Element && r.Name == "geogLocation")
                {
                    if (r.HasAttributes)
                    {
                        site.SpatialReference = new SpatialReference();
                        string srsName = r.GetAttribute("srs");
                        if (String.IsNullOrEmpty(srsName))
                        {
                            srsName = "unknown";
                        }
                        site.SpatialReference.SRSName = srsName;
                    }
                }

                //local projection
                if (r.NodeType == XmlNodeType.Element && r.Name == "localSiteXY" && r.HasAttributes)
                {
                    site.LocalProjection         = new SpatialReference();
                    site.LocalProjection.SRSName = r.GetAttribute("projectionInformation");
                }

                if (XmlContext.AdvanceReaderPastEmptyElement(r))
                {
                    //Empty element - advance and continue...
                    continue;
                }

                //latitude
                if (r.NodeType == XmlNodeType.Element && r.Name == "latitude")
                {
                    r.Read();
                    site.Latitude = r.ReadContentAsDouble();
                }

                //longitude
                if (r.NodeType == XmlNodeType.Element && r.Name == "longitude")
                {
                    r.Read();
                    site.Longitude = r.ReadContentAsDouble();
                }

                //local projection
                if (r.NodeType == XmlNodeType.Element && r.Name == "localSiteXY" && r.HasAttributes)
                {
                    site.LocalProjection         = new SpatialReference();
                    site.LocalProjection.SRSName = r.GetAttribute("projectionInformation");
                }

                if (r.NodeType == XmlNodeType.Element && r.Name == "X")
                {
                    r.Read();
                    site.LocalX = r.ReadContentAsDouble();
                }

                if (r.NodeType == XmlNodeType.Element && r.Name == "Y")
                {
                    r.Read();
                    site.LocalY = r.ReadContentAsDouble();
                }

                if (r.NodeType == XmlNodeType.EndElement && r.Name == "geoLocation")
                {
                    return;
                }
            }
        }
示例#9
0
 public UnitOfWork()
 {
     _context = new XmlContext();
 }
示例#10
0
 private UnexpectedPreprocessorException(Exception innerEX, string msg, XmlContext context)
     : base(msg, innerEX, context)
 {
     Context = context;
 }
示例#11
0
文件: Xml.cs 项目: rgatkinson/nadir
    public XmlElement ToXml(XmlContext context)
        {
        XmlElement me = context.CreateElement(this.Text);

        switch (this.Type)
            {
        // Text contents
        case NadirParser.MatchClause:
        case NadirParser.NoMatchClause:
        case NadirParser.Adenine:
        case NadirParser.Guanine:
        case NadirParser.Cytosine:
        case NadirParser.Thymine:
            me.AppendChild(context.CreateTextNode(this.GetNadirChild(0)));
            return me;

        // Named thing
        case NadirParser.SeqDesignerDef:
        case NadirParser.ExperimentDef:
        case NadirParser.VariableDef:
        case NadirParser.TypedefDef:
        case NadirParser.AttrDef:
        case NadirParser.FunctionCall:
        case NadirParser.VariableRef:
        case NadirParser.FormalParam:
        case NadirParser.FunctionDef:
            {
            // ^(Name name scope?)
            //
            NadirAST nodeName = this.GetNadirChild(0);
            me.Attributes.Append(context.CreateAttribute("name", nodeName, 0));
            if (nodeName.ChildCount > 1)
                me.Attributes.Append(context.CreateAttribute("scope", nodeName, 1));
            //
            int iChildFirst = 1;
            //
            // Recurse on remaining children
            //
            for(int i=iChildFirst; i < this.ChildCount; i++)
                {
                me.AppendChild(this.GetNadirChild(i).ToXml(context));
                }
            //
            return me;
            }

        case NadirParser.DomainDefRef:
            {
            XmlAttribute attr = context.Document.CreateAttribute("name");
            attr.InnerText = this.GetNadirChild(0).Text;
            me.Attributes.Append(attr);
            return me;
            }

        // Just me and my children
        default:
            //
            for(int i=0; i < this.ChildCount; i++)
                me.AppendChild(this.GetNadirChild(i).ToXml(context));
            //
            return me;        
            }
        }
示例#12
0
文件: Xml.cs 项目: rgatkinson/nadir
 public override XmlElement ToXml(XmlContext context)
     {
     return context.CreateTreedElement(this, "Mixture", this.molecules.ConvertAll<Molecule, IXmlWritable>(child => (IXmlWritable)child));
     }
示例#13
0
文件: Xml.cs 项目: rgatkinson/nadir
 public override XmlElement ToXml(XmlContext context)
     {
     return context.CreateTreedElement(this, "Plex", this.Strands.ConvertAll<IXmlWritable>(child => (IXmlWritable)child));
     }
示例#14
0
文件: Xml.cs 项目: rgatkinson/nadir
 public override XmlElement ToXml(XmlContext context)
     {
     return context.CreateTreedElement(this, "Strand", this.domains.ConvertAll<IXmlWritable>(domain => (IXmlWritable)domain));
     }
示例#15
0
文件: Xml.cs 项目: rgatkinson/nadir
 public override XmlElement ToXml(XmlContext context)
     {
     XmlElement me = context.CreateElement("Domain");
     me.Attributes.Append(context.CreateXmlIdAttribute(this));
     me.Attributes.Append(context.CreateAttribute("domid", this.Id));
     //
     if (this.Symbol != null)
         {
         me.Attributes.Append(context.CreateAttribute("name", this.Symbol.DisplayName));
         }
     //
     if (this.IsConnected)
         {
         me.Attributes.Append(context.CreateAttribute("connection", context.XmlIdOf(this.Connection)));
         }
     //
     if (this.IsComplemented)
         {
         me.Attributes.Append(context.CreateAttribute("complemented", "true"));
         }
     //
     // Deal with extended attributes that we didn't print by the above means.
     // REVIEW: we could do better - try to unify the builtin and non-builtin attrs.
     //
     foreach (KeyValuePair<string,EvaluateAttributeOnce> pair in this.DefinedAttrs)
         {
         XmlElement domattr = context.CreateElement("DomainAttribute");
         domattr.Attributes.Append(context.CreateAttribute("name", pair.Key));
         domattr.Attributes.Append(context.CreateAttribute("value", pair.Value.AttributeValue));
         me.AppendChild(domattr);
         }
     //
     if (this.Nucleotides!=null && this.Nucleotides.Length > 0)
         {
         me.Attributes.Append(context.CreateAttribute("sequence", this.Nucleotides));
         }
     //
     return me;
     }
示例#16
0
文件: Xml.cs 项目: rgatkinson/nadir
 public abstract XmlElement ToXml(XmlContext context);
示例#17
0
        /// <summary>
        /// Reads information about variable
        /// </summary>
        protected override Variable ReadVariable(XmlReader r)
        {
            Variable varInfo = new Variable();

            //Unit timeUnit = Unit.Unknown;
            //Unit valueUnit = Unit.Unknown;
            varInfo.Speciation      = "Not Applicable";
            varInfo.DataType        = "Unknown";
            varInfo.GeneralCategory = "Unknown";
            varInfo.SampleMedium    = "Unknown";
            varInfo.ValueType       = "Unknown";

            while (r.Read())
            {
                string nodeName = r.Name.ToLower();

                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    if (nodeName.IndexOf("variablecode") >= 0)
                    {
                        string prefix = r.GetAttribute("vocabulary");
                        if (string.IsNullOrEmpty(prefix))
                        {
                            prefix = r.GetAttribute("network");
                        }

                        //BCC - 08-Aug-2016 - Retrieve variableID attribute value
                        string variableID = r.GetAttribute("variableID");
                        long   result     = 0;
                        if (long.TryParse(variableID, out result))
                        {
                            varInfo.Id = result;
                        }

                        r.Read();
                        string variableCode = r.Value;
                        if (!String.IsNullOrEmpty(prefix))
                        {
                            variableCode             = prefix + ":" + variableCode;
                            varInfo.VocabularyPrefix = prefix;
                        }
                        varInfo.Code = variableCode;
                    }
                    else if (nodeName == "variablename")
                    {
                        r.Read();
                        varInfo.Name = r.Value;
                    }
                    else if (nodeName.IndexOf("valuetype") >= 0)
                    {
                        r.Read();
                        varInfo.ValueType = r.Value;
                    }
                    else if (nodeName.IndexOf("datatype") >= 0)
                    {
                        r.Read();
                        varInfo.DataType = r.Value;
                    }
                    else if (nodeName == "generalcategory")
                    {
                        r.Read();
                        varInfo.GeneralCategory = r.Value;
                    }
                    else if (nodeName == "samplemedium")
                    {
                        r.Read();
                        varInfo.SampleMedium = r.Value;
                    }
                    else if (nodeName == "speciation")
                    {
                        r.Read();
                        varInfo.Speciation = r.Value;
                    }
                    else if (nodeName == "unit")
                    {
                        Unit u = ReadUnit(r);
                        if (u.UnitsType.ToLower() == "time")
                        {
                            varInfo.TimeUnit = u;
                        }
                        else
                        {
                            varInfo.VariableUnit = u;
                        }
                    }
                    else if (nodeName == "units")
                    {
                        string unitAbbreviation = r.GetAttribute("unitsAbbreviation");
                        if (!String.IsNullOrEmpty(unitAbbreviation))
                        {
                            Unit u = Unit.Unknown;
                            u.Abbreviation       = unitAbbreviation;
                            u.Name               = unitAbbreviation;
                            varInfo.VariableUnit = u;
                            varInfo.TimeUnit     = Unit.UnknownTimeUnit;
                        }
                        else
                        {
                            varInfo.VariableUnit = Unit.Unknown;
                            varInfo.TimeUnit     = Unit.UnknownTimeUnit;
                        }
                    }

                    else if (nodeName == "nodatavalue")
                    {
                        r.Read();
                        varInfo.NoDataValue = Convert.ToDouble(r.Value, CultureInfo.InvariantCulture);
                    }
                    else if (nodeName == "timescale") //some versions of WaterML 1.1 use 'timescale'
                    {
                        string isRegular = r.GetAttribute("isRegular");
                        if (!String.IsNullOrEmpty(isRegular))
                        {
                            varInfo.IsRegular = Convert.ToBoolean(isRegular);
                        }
                    }
                    else if (nodeName == "timesupport") //other versions use 'timesupport'
                    {
                        r.Read();
                        try
                        {
                            varInfo.TimeSupport = Convert.ToSingle(r.Value);
                        }
                        catch
                        { }
                    }
                    else if (nodeName == "timeinterval")
                    {
                        r.Read();
                        varInfo.TimeSupport = Convert.ToSingle(r.Value);
                    }
                }
                else if (r.NodeType == XmlNodeType.EndElement && nodeName == "variable")
                {
                    return(varInfo);
                }
            }
            return(varInfo);
        }
示例#18
0
        /// <summary>
        /// Internals the serialize.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="ctx">xml context</param>
        protected override void InternalUnSerialize(XmlReader reader, XmlContext ctx)
        {
            var val = reader.ReadElementContentAsString();

            this._data = Convert.FromBase64String(val);
        }
示例#19
0
 /// <summary>
 /// Clears out the current context factory
 /// </summary>
 public static void DestroyContextFactory()
 {
     XmlContext = null;
     AlreadyBuilt = false;
     Configuration = null;
 }
示例#20
0
 /// <summary>
 /// Internals the serialize.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="ctx">xmlcontext</param>
 protected override void InternalSerialize(XmlWriter writer, XmlContext ctx)
 {
     writer.WriteValue(Convert.ToBase64String(this.Value));
 }
示例#21
0
        private IList <Series> ReadValues(XmlReader reader)
        {
            Site           site       = null;
            Source         source     = null;
            Variable       varInfo    = null;
            IList <Series> seriesList = null;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(reader))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    string readerName = reader.Name.ToLower();

                    if (readerName == "queryinfo")
                    {
                        //Read the 'Query Info'
                        //var qry = ReadQueryInfo(reader);
                        //xmlFileInfo.QueryInfo = qry;
                    }
                    else if (readerName == "sourceinfo")//sourceinfo does contains site information but does not contain source values. Source is separate tag in response
                    {
                        //Read the site information
                        site = ReadSite(reader);
                    }
                    else if (readerName == "variable")
                    {
                        //Read the variable information
                        varInfo = ReadVariable(reader);
                    }
                    else if (readerName == "values")
                    {
                        //Read the time series and data values information
                        seriesList = ReadDataValues(reader);
                        foreach (var series in seriesList)
                        {
                            if (varInfo != null)
                            {
                                series.Variable = varInfo;
                            }
                            if (source != null)
                            {
                                series.Source = source;
                            }
                            if (site != null)
                            {
                                series.Site = site;
                            }

                            //set the checked and creation date time
                            series.CreationDateTime    = DateTime.Now;
                            series.LastCheckedDateTime = DateTime.Now;
                            series.UpdateDateTime      = series.LastCheckedDateTime;
                        }
                    }
                }
            }

            return(seriesList ?? (new List <Series>(0)));
        }
示例#22
0
 public TechnologyCountAnalysisResultRepository(XmlContext context)
 {
     _context = context;
     _technologyCountAnalysisResults = _context.TechnologyCountAnalysisResults.ToList();
 }
示例#23
0
        /// <summary>
        /// Read the list of series from the XML that is returned by HIS Central
        /// </summary>
        /// <param name="reader">the xml reader</param>
        /// <returns>the list of intermediate 'SeriesDataCart' objects</returns>
        private BusinessObjects.Models.SeriesDataCartModel.SeriesDataCart ReadSeriesFromHISCentral(XmlReader reader)
        {
            var series = new BusinessObjects.Models.SeriesDataCartModel.SeriesDataCart();

            while (reader.Read())
            {
                var nodeName = reader.Name.ToLower();
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(reader))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    switch (nodeName)
                    {
                    case "servcode":
                        reader.Read();
                        series.ServCode = reader.Value;
                        break;

                    case "servurl":
                        reader.Read();
                        series.ServURL = reader.Value;
                        break;

                    case "location":
                        reader.Read();
                        series.SiteCode = reader.Value;
                        break;

                    case "varcode":
                        reader.Read();
                        series.VariableCode = reader.Value;
                        break;

                    case "varname":
                        reader.Read();
                        series.VariableName = reader.Value;
                        break;

                    case "begindate":
                        reader.Read();
                        if (!String.IsNullOrWhiteSpace(reader.Value))
                        {
                            series.BeginDate = Convert.ToDateTime(reader.Value, _invariantCulture);
                        }
                        else
                        {
                            return(null);
                        }
                        break;

                    case "enddate":
                        reader.Read();
                        if (!String.IsNullOrWhiteSpace(reader.Value))
                        {
                            series.EndDate = Convert.ToDateTime(reader.Value, _invariantCulture);
                        }
                        else
                        {
                            return(null);
                        }
                        break;

                    case "valuecount":
                        reader.Read();
                        if (!String.IsNullOrWhiteSpace(reader.Value))
                        {
                            series.ValueCount = Convert.ToInt32(reader.Value);
                        }
                        else
                        {
                            return(null);
                        }
                        break;

                    case "sitename":
                        reader.Read();
                        series.SiteName = reader.Value;
                        break;

                    case "latitude":
                        reader.Read();
                        if (!String.IsNullOrWhiteSpace(reader.Value))
                        {
                            series.Latitude = Convert.ToDouble(reader.Value, CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            return(null);
                        }
                        break;

                    case "longitude":
                        reader.Read();
                        if (!String.IsNullOrWhiteSpace(reader.Value))
                        {
                            series.Longitude = Convert.ToDouble(reader.Value, CultureInfo.InvariantCulture);
                        }
                        else
                        {
                            return(null);
                        }
                        break;

                    case "datatype":
                        reader.Read();
                        series.DataType = reader.Value;
                        break;

                    case "valuetype":
                        reader.Read();
                        series.ValueType = reader.Value;
                        break;

                    case "samplemedium":
                        reader.Read();
                        series.SampleMedium = reader.Value;
                        break;

                    case "timeunits":
                        reader.Read();
                        series.TimeUnit = reader.Value;
                        break;

                    case "conceptkeyword":
                        reader.Read();
                        series.ConceptKeyword = reader.Value;
                        break;

                    case "gencategory":
                        reader.Read();
                        series.GeneralCategory = reader.Value;
                        break;

                    case "timesupport":
                        reader.Read();
                        if (!String.IsNullOrWhiteSpace(reader.Value))
                        {
                            series.TimeSupport = Convert.ToDouble(reader.Value, CultureInfo.InvariantCulture);
                        }
                        break;

                    case "isregular":
                        reader.Read();
                        if (!String.IsNullOrWhiteSpace(reader.Value))
                        {
                            series.IsRegular = Convert.ToBoolean(reader.Value);
                        }
                        break;

                    case "variableunitsabbrev":
                        reader.Read();
                        series.VariableUnits = reader.Value;
                        break;

                    //BCC - 07-Sep-2016 - Added additional reads for use with GetSeriesCatalogForBox3...
                    case "qclid":
                        reader.Read();
                        series.QCLID = reader.Value;
                        break;

                    case "qcldesc":
                        reader.Read();
                        series.QCLDesc = reader.Value;
                        break;

                    case "sourceorg":
                        reader.Read();
                        series.SourceOrg = reader.Value;
                        break;

                    case "sourceid":
                        reader.Read();
                        series.SourceId = reader.Value;
                        break;

                    case "methodid":
                        reader.Read();
                        series.MethodId = reader.Value;
                        break;

                    case "methoddesc":
                        reader.Read();
                        series.MethodDesc = reader.Value;
                        break;
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement && (nodeName == "seriesrecord" || nodeName == "seriesrecordfull"))
                {
                    return(series);
                }
            }

            return(null);
        }
示例#24
0
        /// <summary>
        /// Reads the DataValues section
        /// </summary>
        protected override IList <Series> ReadDataValues(XmlReader r)
        {
            int valueCount;
            var lst = new List <DataValueWrapper>(Int32.TryParse(r.GetAttribute("count"), out valueCount) ? valueCount : 4);

            var qualifiers           = new Dictionary <string, Qualifier>();
            var methods              = new Dictionary <string, Method>();
            var sources              = new Dictionary <string, Source>();
            var qualityControlLevels = new Dictionary <string, QualityControlLevel>();
            var samples              = new Dictionary <string, Sample>();
            var offsets              = new Dictionary <string, OffsetType>();
            var seriesDictionary     = new Dictionary <string, Series>();

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    if (r.Name == "value")
                    {
                        //create a new empty data value and add it to the list
                        var wrapper = new DataValueWrapper();
                        var val     = new DataValue();
                        wrapper.DataValue = val;
                        lst.Add(wrapper);

                        if (r.HasAttributes)
                        {
                            var censorCode = r.GetAttribute("censorCode");
                            if (!string.IsNullOrEmpty(censorCode))
                            {
                                val.CensorCode = censorCode;
                            }
                            //fix by Jiri - sometimes the dateTime attribute is uppercase
                            var localDateTime = r.GetAttribute("dateTime");
                            if (string.IsNullOrEmpty(localDateTime))
                            {
                                localDateTime = r.GetAttribute("DateTime");
                            }
                            val.LocalDateTime = Convert.ToDateTime(localDateTime, CultureInfo.InvariantCulture);
                            val.DateTimeUTC   = val.LocalDateTime;
                            val.UTCOffset     = 0.0;

                            //method
                            var methodID = r.GetAttribute("methodID");
                            if (String.IsNullOrEmpty(methodID))
                            {
                                methodID = "0"; //when a method ID is unspecified
                            }
                            if (!methods.ContainsKey(methodID))
                            {
                                var newMethod = Method.Unknown;
                                methods.Add(methodID, newMethod);
                            }
                            wrapper.MethodID = methodID;

                            //quality control level
                            string qualityCode = r.GetAttribute("qualityControlLevel");
                            if (String.IsNullOrEmpty(qualityCode))
                            {
                                qualityCode = "unknown"; //when the quality control level is unspecified
                            }
                            if (!qualityControlLevels.ContainsKey(qualityCode))
                            {
                                var qualControl = QualityControlLevel.Unknown;
                                qualControl.Code        = qualityCode;
                                qualControl.Definition  = qualityCode;
                                qualControl.Explanation = qualityCode;
                                qualityControlLevels.Add(qualityCode, qualControl);
                            }

                            //source
                            var sourceID = r.GetAttribute("sourceID");
                            if (String.IsNullOrEmpty(sourceID))
                            {
                                sourceID = "0"; //when a source ID is unspecified
                            }
                            if (!sources.ContainsKey(sourceID))
                            {
                                sources.Add(sourceID, Source.Unknown);
                            }
                            wrapper.SourceID   = sourceID;
                            wrapper.SeriesCode = SeriesCodeHelper.CreateSeriesCode(methodID, qualityCode, sourceID); //----method-source-qualityControl combination----

                            //sample
                            var sampleID = r.GetAttribute("sampleID");
                            if (!String.IsNullOrEmpty(sampleID))
                            {
                                if (!samples.ContainsKey(sampleID))
                                {
                                    samples.Add(sampleID, Sample.Unknown);
                                }
                            }
                            wrapper.SampleID = sampleID;

                            //qualifiers
                            string qualifierCodes = r.GetAttribute("qualifiers");
                            if (!String.IsNullOrEmpty(qualifierCodes))
                            {
                                if (!qualifiers.ContainsKey(qualifierCodes))
                                {
                                    var newQualifier = new Qualifier {
                                        Code = qualifierCodes
                                    };
                                    qualifiers.Add(qualifierCodes, newQualifier);
                                    val.Qualifier = newQualifier;
                                }
                                else
                                {
                                    val.Qualifier = qualifiers[qualifierCodes];
                                }
                            }

                            //vertical offset
                            var offsetID = r.GetAttribute("offsetTypeID");
                            if (!String.IsNullOrEmpty(offsetID))
                            {
                                if (!offsets.ContainsKey(offsetID))
                                {
                                    offsets.Add(offsetID, new OffsetType());
                                }
                                var offsetValue = r.GetAttribute("offsetValue");
                                if (!String.IsNullOrEmpty(offsetValue))
                                {
                                    val.OffsetValue = Convert.ToDouble(offsetValue, CultureInfo.InvariantCulture);
                                }
                            }
                            wrapper.OffsetID = offsetID;

                            //data value
                            val.Value = Convert.ToDouble(r.ReadString(), CultureInfo.InvariantCulture);
                        }
                    }
                    else if (r.Name == "method")
                    {
                        var method        = ReadMethod(r);
                        var methodCodeKey = method.Code.ToString(CultureInfo.InvariantCulture);
                        if (methods.ContainsKey(methodCodeKey))
                        {
                            methods[methodCodeKey] = method;
                        }
                    }
                    else if (r.Name == "source")
                    {
                        var source        = ReadSource(r);
                        var sourceCodeKey = source.OriginId.ToString(CultureInfo.InvariantCulture);
                        if (sources.ContainsKey(sourceCodeKey))
                        {
                            sources[sourceCodeKey] = source;
                        }
                    }
                    else if (r.Name == "qualityControlLevel")
                    {
                        //quality control level seems to be included with each value
                    }
                    else if (r.Name == "qualifier")
                    {
                        ReadQualifier(r, qualifiers);
                    }
                    else if (r.Name == "offset")
                    {
                        ReadOffset(r, offsets);
                    }
                }
            }

            //to assign special properties of each data value
            foreach (var wrapper in lst)
            {
                var val = wrapper.DataValue;

                //which series does the data value belong to?
                var seriesCode = wrapper.SeriesCode;
                if (!seriesDictionary.ContainsKey(seriesCode))
                {
                    var newSeries = new Series();
                    seriesDictionary.Add(seriesCode, newSeries);
                    //assign method, source and qual.control level
                    //assign method, source and qual.control level
                    try
                    {
                        newSeries.Method = methods[SeriesCodeHelper.GetMethodCode(seriesCode)];
                        //fix by Jiri: fixes the case when sourceID is unspecified sources
                        //has more than one source entry
                        string sourceCode = SeriesCodeHelper.GetSourceCode(seriesCode);
                        if (sourceCode == "0" && sources.Count > 0)
                        {
                            foreach (string sc in sources.Keys)
                            {
                                if (sc != "0")
                                {
                                    sourceCode = sc;
                                    break;
                                }
                            }
                        }
                        newSeries.Source = sources[sourceCode];
                        newSeries.QualityControlLevel = qualityControlLevels[SeriesCodeHelper.GetQualityCode(seriesCode)];
                    }
                    catch { }
                }

                //add the data value to the correct series
                var series = seriesDictionary[seriesCode];
                series.DataValueList.Add(val);
                val.Series = series;

                Sample sample;
                if (!string.IsNullOrEmpty(wrapper.SampleID) &&
                    samples.TryGetValue(wrapper.SampleID, out sample))
                {
                    val.Sample = sample;
                }
                OffsetType offset;
                if (!string.IsNullOrEmpty(wrapper.OffsetID) &&
                    offsets.TryGetValue(wrapper.OffsetID, out offset))
                {
                    val.OffsetType = offset;
                }
                if (series.Method == null)
                {
                    series.Method = methods[wrapper.MethodID];
                }
                if (series.Source == null)
                {
                    series.Source = sources[wrapper.SourceID];
                }
            }

            //to check the qualifiers
            CheckQualifiers(qualifiers);
            return(seriesDictionary.Values.ToList());
        }
示例#25
0
 private void PushXmlContext() {
     xmlContext = new XmlContext( xmlContext );
     curNode.xmlContextPushed = true;
 }
示例#26
0
 public void CanCreateInstance()
 {
     Assert.DoesNotThrow(() => { var instance = new XmlContext <FakeItem>(new Uri("http://server")); });
 }
示例#27
0
 private void PopXmlContext()
 {
     Debug.Assert(_curNode.xmlContextPushed);
     _xmlContext = _xmlContext.previousContext;
     _curNode.xmlContextPushed = false;
 }
 internal XmlContext() {
     xmlSpace = XmlSpace.None;
     xmlLang = string.Empty;
     defaultNamespace = string.Empty;
     previousContext = null;
 }
        // This constructor is used when creating XmlTextReaderImpl reader via "XmlReader.Create(..)"
        private XmlTextReaderImpl( XmlResolver resolver, XmlReaderSettings settings, XmlParserContext context ) {
            v1Compat = false;
            outerReader = this;

            xmlContext = new XmlContext();        

            // create or get nametable and namespace manager from XmlParserContext
            XmlNameTable nt = settings.NameTable;
            if ( context == null ) {
                if ( nt == null ) {
                    nt = new NameTable();
                    Debug.Assert( nameTableFromSettings == false );
                }
                else {
                    nameTableFromSettings = true;
                }
                nameTable = nt;
                namespaceManager = new XmlNamespaceManager( nt );
            }
            else {
                SetupFromParserContext( context, settings );
                nt = nameTable;
            }

            nt.Add( string.Empty );
            Xml = nt.Add( "xml" );
            XmlNs = nt.Add( "xmlns" );

            xmlResolver = resolver;

            Debug.Assert( index == 0 );

            nodes = new NodeData[ NodesInitialSize ];
            nodes[0] = new NodeData();
            curNode = nodes[0];

            stringBuilder = new BufferBuilder();

            entityHandling = EntityHandling.ExpandEntities;
            whitespaceHandling = ( settings.IgnoreWhitespace ) ? WhitespaceHandling.Significant : WhitespaceHandling.All;
            normalize = true;
            ignorePIs = settings.IgnoreProcessingInstructions;
            ignoreComments = settings.IgnoreComments;
            checkCharacters = settings.CheckCharacters;
            lineNumberOffset = settings.LineNumberOffset;
            linePositionOffset = settings.LinePositionOffset;
            ps.lineNo = lineNumberOffset + 1;
            ps.lineStartPos = - linePositionOffset - 1;
            curNode.SetLineInfo( ps.LineNo - 1, ps.LinePos - 1 );
            prohibitDtd = settings.ProhibitDtd;

            fragmentParserContext = context;

            parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl;
            nextParsingFunction = ParsingFunction.DocumentContent;

            switch ( settings.ConformanceLevel ) { 
                case ConformanceLevel.Auto:
                    fragmentType = XmlNodeType.None;
                    fragment = true;
                    break;
                case ConformanceLevel.Fragment:
                    fragmentType = XmlNodeType.Element;
                    fragment = true;
                    break;
                case ConformanceLevel.Document:
                    fragmentType = XmlNodeType.Document;
                    break;
                default:
                    Debug.Assert( false );
                    goto case ConformanceLevel.Document;
            }
        }
 internal XmlContext( XmlContext previousContext ) {
     this.xmlSpace = previousContext.xmlSpace;
     this.xmlLang = previousContext.xmlLang;
     this.defaultNamespace = previousContext.defaultNamespace;
     this.previousContext = previousContext;
 }
示例#31
0
        /// <summary>
        /// Reads the DataValues section
        /// </summary>
        protected override IList <Series> ReadDataValues(XmlReader r)
        {
            int valueCount;
            var lst = new List <DataValueWrapper>(Int32.TryParse(r.GetAttribute("count"), out valueCount) ? valueCount : 4);

            var qualifiers           = new Dictionary <string, Qualifier>();
            var methods              = new Dictionary <string, Method>();
            var sources              = new Dictionary <string, Source>();
            var qualityControlLevels = new Dictionary <string, QualityControlLevel>();
            var samples              = new Dictionary <string, Sample>();
            var labMethods           = new Dictionary <string, LabMethod>();
            var offsets              = new Dictionary <string, OffsetType>();
            var seriesDictionary     = new Dictionary <string, Series>();

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    if (r.Name == "value")
                    {
                        //create a new empty data value and add it to the list
                        var wrapper = new DataValueWrapper();
                        var val     = new DataValue();
                        wrapper.DataValue = val;
                        lst.Add(wrapper);

                        if (r.HasAttributes)
                        {
                            var censorCode = r.GetAttribute("censorCode");
                            if (!string.IsNullOrEmpty(censorCode))
                            {
                                val.CensorCode = censorCode;
                            }
                            val.LocalDateTime = Convert.ToDateTime(r.GetAttribute("dateTime"), CultureInfo.InvariantCulture);

                            //utcOffset
                            var utcOffset = r.GetAttribute("timeOffset");
                            val.UTCOffset = !String.IsNullOrEmpty(utcOffset) ? ConvertUtcOffset(utcOffset) : 0.0;

                            //dateTimeUtc
                            var dateTimeUTC = r.GetAttribute("dateTimeUTC");
                            val.DateTimeUTC = !String.IsNullOrEmpty(dateTimeUTC) ? Convert.ToDateTime(dateTimeUTC, CultureInfo.InvariantCulture) : val.LocalDateTime;

                            //method
                            var methodID = r.GetAttribute("methodCode");
                            if (String.IsNullOrEmpty(methodID))
                            {
                                //try methodID instead of methodCode
                                methodID = r.GetAttribute("methodID");
                                if (String.IsNullOrEmpty(methodID))
                                {
                                    methodID = "unknown"; //when a method is unspecified
                                }
                            }
                            if (!methods.ContainsKey(methodID))
                            {
                                var newMethod = Method.Unknown;
                                methods.Add(methodID, newMethod);
                            }
                            wrapper.MethodID = methodID;

                            //quality control level
                            var qualityCode = r.GetAttribute("qualityControlLevelCode");
                            if (String.IsNullOrEmpty(qualityCode))
                            {
                                qualityCode = r.GetAttribute("qualityControlLevelID");
                                if (string.IsNullOrEmpty(qualityCode))
                                {
                                    qualityCode = "unknown"; //when the quality control level is unspecified
                                }
                            }

                            //BCC - 24-Aug-2016 - Check for a quality code of space-delimited terms...
                            string[] terms = qualityCode.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                            foreach (var term in terms)
                            {
                                if (!qualityControlLevels.ContainsKey(term))
                                {
                                    var qualControl = QualityControlLevel.Unknown;
                                    qualControl.Code        = term;
                                    qualControl.Definition  = term;
                                    qualControl.Explanation = term;
                                    qualityControlLevels.Add(term, qualControl);
                                }
                            }

                            wrapper.QualityID = qualityCode;

                            //source
                            string sourceID = r.GetAttribute("sourceCode");
                            if (string.IsNullOrEmpty(sourceID))
                            {
                                sourceID = r.GetAttribute("sourceID");
                                if (String.IsNullOrEmpty(sourceID))
                                {
                                    sourceID = "unknown"; //when a source is unspecified
                                }
                            }
                            if (!sources.ContainsKey(sourceID))
                            {
                                sources.Add(sourceID, Source.Unknown);
                            }
                            wrapper.SourceID   = sourceID;
                            wrapper.SeriesCode = SeriesCodeHelper.CreateSeriesCode(methodID, qualityCode, sourceID); //----method-source-qualityControl combination----

                            //sample
                            string sampleCode = r.GetAttribute("labSampleCode");
                            if (!String.IsNullOrEmpty(sampleCode))
                            {
                                if (!samples.ContainsKey(sampleCode))
                                {
                                    samples.Add(sampleCode, Sample.Unknown);
                                }
                            }
                            wrapper.SampleID = sampleCode;

                            //qualifiers
                            string qualifierCodes = r.GetAttribute("qualifiers");
                            if (!String.IsNullOrEmpty(qualifierCodes))
                            {
                                if (!qualifiers.ContainsKey(qualifierCodes))
                                {
                                    var newQualifier = new Qualifier {
                                        Code = qualifierCodes
                                    };
                                    qualifiers.Add(qualifierCodes, newQualifier);
                                    val.Qualifier = newQualifier;
                                }
                                else
                                {
                                    val.Qualifier = qualifiers[qualifierCodes];
                                }
                            }

                            //vertical offset
                            string offsetCode = r.GetAttribute("offsetTypeCode");
                            if (string.IsNullOrEmpty(offsetCode))
                            {
                                offsetCode = r.GetAttribute("offsetTypeID");
                            }
                            if (!String.IsNullOrEmpty(offsetCode))
                            {
                                if (!offsets.ContainsKey(offsetCode))
                                {
                                    offsets.Add(offsetCode, new OffsetType());
                                }
                                string offsetValue = r.GetAttribute("offsetValue");
                                if (!String.IsNullOrEmpty(offsetValue))
                                {
                                    val.OffsetValue = Convert.ToDouble(offsetValue, CultureInfo.InvariantCulture);
                                }
                            }
                            wrapper.OffsetID = offsetCode;
                        }

                        //data value
                        r.Read();
                        val.Value = r.ReadContentAsDouble();
                    }
                    else if (r.Name == "method")
                    {
                        var method        = ReadMethod(r);
                        var methodCodeKey = method.Code.ToString(CultureInfo.InvariantCulture);
                        if (methods.ContainsKey(methodCodeKey))
                        {
                            methods[methodCodeKey] = method;
                        }
                    }
                    else if (r.Name == "source")
                    {
                        var source        = ReadSource(r);
                        var sourceCodeKey = source.OriginId.ToString(CultureInfo.InvariantCulture);
                        if (sources.ContainsKey(sourceCodeKey))
                        {
                            sources[sourceCodeKey] = source;
                        }
                    }
                    else if (r.Name == "qualityControlLevel")
                    {
                        var qcLevel   = ReadQualityControlLevel(r);
                        var qcCodeKey = qcLevel.Code;
                        if (qualityControlLevels.ContainsKey(qcCodeKey))
                        {
                            qualityControlLevels[qcCodeKey] = qcLevel;
                        }
                    }
                    else if (r.Name == "qualifier")
                    {
                        ReadQualifier(r, qualifiers);
                    }
                    else if (r.Name == "sample")
                    {
                        ReadSample(r, samples, labMethods);
                    }
                    else if (r.Name == "offset")
                    {
                        ReadOffset(r, offsets);
                    }
                }
            }

            //to assign special properties of each data value
            foreach (var wrapper in lst)
            {
                var val = wrapper.DataValue;

                //which series does the data value belong to?
                var seriesCode = wrapper.SeriesCode;
                if (!seriesDictionary.ContainsKey(seriesCode))
                {
                    Series newSeries = new Series();
                    seriesDictionary.Add(seriesCode, newSeries);
                    //assign method, source and qual.control level
                    try
                    {
                        newSeries.Method = methods[SeriesCodeHelper.GetMethodCode(seriesCode)];
                        newSeries.Source = sources[SeriesCodeHelper.GetSourceCode(seriesCode)];

                        //BCC - 24-Aug-2016 - Add logic to handle space-delimited quality codes...
                        var      qcCode = SeriesCodeHelper.GetQualityCode(seriesCode);
                        string[] terms  = qcCode.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                        if (1 == terms.Length)
                        {
                            //One quality code found...
                            newSeries.QualityControlLevel = qualityControlLevels[SeriesCodeHelper.GetQualityCode(seriesCode)];
                        }
                        else
                        {
                            //Multiple quality codes found...
                            var    qcl       = new QualityControlLevel();
                            string separator = " | ";

                            qcl.Code        = qcCode;
                            qcl.Definition  = String.Empty;
                            qcl.Explanation = String.Empty;
                            foreach (var term in terms)
                            {
                                var qclTemp = qualityControlLevels[term];

                                qcl.Definition  += qclTemp.Definition + separator;
                                qcl.Explanation += qclTemp.Explanation + separator;
                            }

                            qcl.Definition  = qcl.Definition.Substring(0, qcl.Definition.Length - separator.Length);
                            qcl.Explanation = qcl.Explanation.Substring(0, qcl.Explanation.Length - separator.Length);

                            //Set the OriginId to a minimum value to indicate a 'pseudo' instance...
                            int min = qualityControlLevels.Values.Min(value => value.OriginId);
                            qcl.OriginId = min - 1;

                            newSeries.QualityControlLevel = qcl;

                            //Add compound key to dictionary, if indicated...
                            if (!qualityControlLevels.ContainsKey(qcl.Code))
                            {
                                qualityControlLevels.Add(qcl.Code, qcl);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //Any exception happening here?
                        string msg = ex.Message;

                        int n = 5;

                        ++n;
                    }
                }

                //add the data value to the correct series
                var series = seriesDictionary[seriesCode];
                series.DataValueList.Add(val);
                val.Series = series;

                Sample sample;
                if (!string.IsNullOrEmpty(wrapper.SampleID) &&
                    samples.TryGetValue(wrapper.SampleID, out sample))
                {
                    val.Sample = sample;
                }
                OffsetType offset;
                if (!string.IsNullOrEmpty(wrapper.OffsetID) &&
                    offsets.TryGetValue(wrapper.OffsetID, out offset))
                {
                    val.OffsetType = offset;
                }
                if (series.Method == null)
                {
                    series.Method = methods[wrapper.MethodID];
                }
                if (series.Source == null)
                {
                    series.Source = sources[wrapper.SourceID];
                }
                if (series.QualityControlLevel == null)
                {
                    series.QualityControlLevel = qualityControlLevels[wrapper.QualityID];
                }
            }
            //to check the qualifiers
            CheckQualifiers(qualifiers);

            return(seriesDictionary.Values.ToList());
        }
示例#32
0
 /// <summary>
 /// Internals the serialize.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="ctx">xml context</param>
 protected override void InternalUnSerialize(XmlReader reader, XmlContext ctx)
 {
     this._value = reader.ReadElementContentAsString();
 }
示例#33
0
        /// <summary>
        /// Reads information about a sample
        /// </summary>
        private static void ReadSample(XmlReader r, IDictionary <string, Sample> samples, Dictionary <string, LabMethod> labMethods)
        {
            Sample sample = Sample.Unknown;

            sample.LabMethod = LabMethod.Unknown;

            var newLabMethod = LabMethod.Unknown;

            string labSampleCode = String.Empty;

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    string nodeName = r.Name.ToLower();
                    if (nodeName == "labsamplecode")
                    {
                        r.Read();
                        labSampleCode        = r.Value;
                        sample.LabSampleCode = labSampleCode;
                    }
                    else if (nodeName == "sampletype")
                    {
                        r.Read();
                        sample.SampleType = r.Value;
                    }
                    else if (nodeName == "labname")
                    {
                        r.Read();
                        newLabMethod.LabName = r.Value;
                    }
                    else if (nodeName == "laborganization")
                    {
                        r.Read();
                        newLabMethod.LabOrganization = r.Value;
                    }
                    else if (nodeName == "labmethodname")
                    {
                        r.Read();
                        newLabMethod.LabMethodName = r.Value;
                    }
                }
                else if (r.NodeType == XmlNodeType.EndElement && r.Name.ToLower() == "sample")
                {
                    //assign the lab method
                    string labMethodKey = newLabMethod.LabName + "|" + newLabMethod.LabMethodName;
                    if (!labMethods.ContainsKey(labMethodKey))
                    {
                        labMethods.Add(labMethodKey, newLabMethod);
                        sample.LabMethod = newLabMethod;
                    }
                    else
                    {
                        sample.LabMethod = null;
                        sample.LabMethod = labMethods[labMethodKey];
                    }

                    //check existing sample
                    if (samples.ContainsKey(labSampleCode))
                    {
                        samples[labSampleCode] = null;
                        samples[labSampleCode] = sample;
                    }
                    return;
                }
            }
        }
示例#34
0
 /// <summary>
 /// Internals the serialize.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="ctx">xml context</param>
 protected override void InternalSerialize(XmlWriter writer, XmlContext ctx)
 {
     writer.WriteValue(this.Value);
 }
示例#35
0
 internal PreprocessorException(string msg, Exception innerEX, XmlContext ctx)
     : base(msg, innerEX)
 {
     Context = ctx;
 }
示例#36
0
 public EntityRepository(IContext context)
 {
     _context   = (XmlContext)context ?? throw new NullException(() => context);
     _document  = _context.GetDocument <Entity>();
     _converter = _context.GetConverter();
 }
示例#37
0
        /// <summary>
        /// Build context factory that has already been configured
        /// </summary>
        private static void BuildContextFactory()
        {
            if ( Configuration == null )
            {
                throw new ApplicationException( "Xmlicious has not been configured!" );
            }

            if ( AlreadyBuilt )
            {
                return;
            }

            XmlContext = new XmlContext( Configuration );

            AlreadyBuilt = true;
        }
 public Repository(XmlContext context)
 {
     _context = context;
 }
示例#39
0
 public UnitOfWork(XmlContext context)
 {
     _context = context;
 }
示例#40
0
 internal PreprocessorException(string msg, Exception innerEX, XmlContext ctx)
     : base( msg, innerEX )
 {
     Context = ctx;
 }
示例#41
0
        protected virtual SeriesMetadata ReadSeriesFromSiteInfo(XmlReader r, Site site)
        {
            var series = new SeriesMetadata {
                Site = site
            };

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    string nodeName = r.Name.ToLower();
                    if (nodeName == "variable")
                    {
                        series.Variable = ReadVariable(r);
                    }
                    else if (nodeName == "valuecount")
                    {
                        r.Read();
                        series.ValueCount = Convert.ToInt32(r.Value);
                    }
                    else if (nodeName == "begindatetime")
                    {
                        r.Read();
                        series.BeginDateTime    = Convert.ToDateTime(r.Value, CultureInfo.InvariantCulture);
                        series.BeginDateTimeUTC = series.BeginDateTime;
                    }
                    else if (nodeName == "enddatetime")
                    {
                        r.Read();
                        series.EndDateTime    = Convert.ToDateTime(r.Value, CultureInfo.InvariantCulture);
                        series.EndDateTimeUTC = series.EndDateTime;
                    }
                    else if (nodeName == "begindatetimeutc")
                    {
                        r.Read();
                        series.BeginDateTimeUTC = Convert.ToDateTime(r.Value, CultureInfo.InvariantCulture);
                    }
                    else if (nodeName == "enddatetimeutc")
                    {
                        r.Read();
                        series.EndDateTimeUTC = Convert.ToDateTime(r.Value, CultureInfo.InvariantCulture);
                    }
                    else if (nodeName == "method")
                    {
                        series.Method = ReadMethod(r);
                    }
                    else if (nodeName == "source")
                    {
                        series.Source = ReadSource(r);
                    }
                    else if (nodeName == "qualitycontrollevel")
                    {
                        series.QualityControlLevel = ReadQualityControlLevel(r);
                    }
                }
                else
                {
                    if (r.NodeType == XmlNodeType.EndElement && r.Name == "series")
                    {
                        return(series);
                    }
                }
            }
            return(series);
        }
示例#42
0
 private UnexpectedPreprocessorException(Exception innerEX, string msg, XmlContext context)
     : base( msg, innerEX, context )
 {
     Context = context;
 }
示例#43
0
        protected virtual Site ReadSite(XmlReader r)
        {
            var site = new Site();

            while (r.Read())
            {
                var nodeName = r.Name.ToLower();

                if (r.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(r))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    if (nodeName == "sitename")
                    {
                        r.Read();
                        site.Name = r.Value;
                    }
                    else if (nodeName == "geolocation")
                    {
                        ReadSpatialReference(r, site);
                    }
                    else if (nodeName.IndexOf("sitecode", StringComparison.Ordinal) >= 0)
                    {
                        string networkPrefix = r.GetAttribute("network");

                        //BCC - 08-Aug-2016 - Retrieve siteID attribute value...
                        string siteID = r.GetAttribute("siteID");
                        long   result = 0;
                        if (long.TryParse(siteID, out result))
                        {
                            site.Id = result;
                        }

                        r.Read();
                        string siteCode = r.Value;
                        if (!String.IsNullOrEmpty(networkPrefix))
                        {
                            siteCode = networkPrefix + ":" + siteCode;
                        }
                        site.Code          = siteCode;
                        site.NetworkPrefix = networkPrefix;
                    }
                    else if (nodeName == "verticaldatum")
                    {
                        r.Read();
                        site.VerticalDatum = r.Value;
                    }
                    else if (nodeName == "timezoneinfo")
                    {
                        site.DefaultTimeZone = ReadTimeZoneInfo(r);
                    }
                    else if (nodeName == "elevation_m")
                    {
                        r.Read();
                        site.Elevation_m = Convert.ToDouble(r.Value, CultureInfo.InvariantCulture);
                    }
                    // WaterML 1.0 notes
                    else if (nodeName == "note")
                    {
                        var title = r.GetAttribute("title");
                        if (!String.IsNullOrEmpty(title))
                        {
                            title = title.ToLower();
                            r.Read();
                            var value = r.Value;
                            switch (title)
                            {
                            case "county":
                                site.County = value;
                                break;

                            case "state":
                                site.State = value;
                                break;

                            case "comments":
                                site.Comments = value;
                                break;
                            }
                        }
                    }
                    // WaterML 1.1 site properties
                    else if (nodeName == "siteproperty")
                    {
                        var title = r.GetAttribute("name");
                        if (!String.IsNullOrEmpty(title))
                        {
                            title = title.ToLower();
                            r.Read();
                            var value = r.Value;
                            switch (title)
                            {
                            case "county":
                                site.County = value;
                                break;

                            case "state":
                                site.State = value;
                                break;

                            case "comments":
                                site.Comments = value;
                                break;

                            case "sitetype":
                                site.SiteType = value;
                                break;

                            case "country":
                                site.Country = value;
                                break;

                            case "posaccuracy_m":
                                site.PosAccuracy_m = Convert.ToDouble(value, CultureInfo.InvariantCulture);
                                break;
                            }
                        }
                    }
                }
                else if (r.NodeType == XmlNodeType.EndElement &&
                         (nodeName.StartsWith("source") || nodeName.StartsWith("siteinfo")))
                {
                    //ensure that spatial reference is set
                    if (site.SpatialReference == null)
                    {
                        site.SpatialReference = new SpatialReference {
                            SRSID = 0, SRSName = "unknown"
                        };
                    }

                    return(site);
                }
            }
            return(null);
        }
示例#44
0
 internal static Exception CreateException(Exception innerEX, XmlContext context)
 {
     return
         new UnexpectedPreprocessorException( innerEX,
                                              String.Format(
                                                  CultureInfo.CurrentCulture, "Unexpected exception in {0}\n{1}",
                                                  context, innerEX.Message ), context );
 }
示例#45
0
        protected virtual Source ReadSource(XmlReader reader)
        {
            var source   = Source.Unknown;
            var sourceID = reader.GetAttribute("sourceID");

            if (!String.IsNullOrEmpty(sourceID))
            {
                source.OriginId = Convert.ToInt32(sourceID);
            }

            if (reader.IsEmptyElement)
            {
                return(source);
            }

            while (reader.Read())
            {
                var nodeName = reader.Name.ToLower();
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (XmlContext.AdvanceReaderPastEmptyElement(reader))
                    {
                        //Empty element - advance and continue...
                        continue;
                    }

                    switch (nodeName)
                    {
                    case "organization":     // WML 1.0/1.1
                        reader.Read();
                        source.Organization = reader.Value;
                        break;

                    case "sourcedescription":      // WML 1.0/1.1
                        reader.Read();
                        source.Description = reader.Value;
                        break;

                    case "metadata":     // WML 1.0/1.1
                        source.ISOMetadata = ReadISOMetadata(reader);
                        break;

                    case "contactinformation":     // WML 1.0/1.1. Note: WML 1.1 supports many "ContactInformation" elements
                        var contact = ReadContactInformtaion(reader);

                        source.ContactName = contact.ContactName;
                        source.Email       = contact.Email;
                        source.Phone       = contact.Phone;

                        // Convert WaterML address into HD address
                        if (!String.IsNullOrEmpty(contact.Address))
                        {
                            //Complete address: {Address},{City},{State},{ZipCode}
                            var split = contact.Address.Split(new[] { ',' },
                                                              StringSplitOptions.RemoveEmptyEntries);
                            if (split.Length > 0)
                            {
                                source.Address = split[0].Trim();
                            }
                            if (split.Length > 1)
                            {
                                source.City = split[1].Trim();
                            }
                            if (split.Length > 2)
                            {
                                source.State = split[2].Trim();
                            }
                            if (split.Length > 3)
                            {
                                int zipCode;
                                if (Int32.TryParse(split[3].Trim(), out zipCode))
                                {
                                    source.ZipCode = zipCode;
                                }
                            }
                        }
                        break;

                    case "sourcelink":      // WML 1.0/1.1.  Note: WML 1.1 supports many "SourceLinks" elements
                        reader.Read();
                        source.Link = reader.Value;
                        break;

                    case "sourcecode":     // WML 1.1
                        reader.Read();
                        break;

                    case "citation":     // WML 1.1
                        reader.Read();
                        source.Citation = reader.Value;
                        break;
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement && nodeName == "source")
                {
                    break;
                }
            }

            return(source);
        }
示例#46
0
        // This constructor is used when creating XmlTextReader reader via "XmlReader.Create(..)"
        private XmlTextReader(XmlReaderSettings settings)
        {
            xmlContext = new XmlContext();

            // create nametable
            XmlNameTable nt = settings.NameTable;
            if (nt == null)
            {
                nt = new NameTable();
                Debug.Assert(nameTableFromSettings == false);
            }
            else
            {
                nameTableFromSettings = true;
            }

            nameTable = nt;

            nt.Add("");
            Xml = nt.Add("xml");
            XmlNs = nt.Add("xmlns");

            Debug.Assert(index == 0);

            nodes = new NodeData[NodesInitialSize];
            nodes[0] = new NodeData();
            curNode = nodes[0];

            stringBuilder = new BufferBuilder();

            entityHandling = EntityHandling.ExpandEntities;
            whitespaceHandling = (settings.IgnoreWhitespace) ? WhitespaceHandling.Significant : WhitespaceHandling.All;
            normalize = true;
            ignorePIs = settings.IgnoreProcessingInstructions;
            ignoreComments = settings.IgnoreComments;
            checkCharacters = settings.CheckCharacters;
            lineNumberOffset = settings.LineNumberOffset;
            linePositionOffset = settings.LinePositionOffset;
            ps.lineNo = lineNumberOffset + 1;
            ps.lineStartPos = -linePositionOffset - 1;
            curNode.SetLineInfo(ps.LineNo - 1, ps.LinePos - 1);

            parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl;
            nextParsingFunction = ParsingFunction.DocumentContent;

            switch (settings.ConformanceLevel)
            {
                case ConformanceLevel.Auto:
                    fragmentType = XmlNodeType.None;
                    break;
                case ConformanceLevel.Fragment:
                    fragmentType = XmlNodeType.Element;
                    break;
                case ConformanceLevel.Document:
                    fragmentType = XmlNodeType.Document;
                    break;
                default:
                    Debug.Assert(false);
                    goto case ConformanceLevel.Document;
            }
        }
示例#47
0
 public CompanyRepository(XmlContext context)
 {
     _context   = context;
     _companies = _context.Companies;
 }
示例#48
0
 internal XmlContext()
 {
     xmlSpace = XmlSpace.None;
     xmlLang = "";
     previousContext = null;
     xmlNamespaces = new XmlNamespaces();
 }
示例#49
0
        // Initializes a new instance of the XmlTextReaderImpl class with the specified XmlNameTable.
        // This constructor is used when creating XmlTextReaderImpl for V1 XmlTextReader
        internal XmlTextReaderImpl( XmlNameTable nt ) {
            Debug.Assert( nt != null );

            v1Compat = true;
            outerReader = this;

            nameTable = nt;
            nt.Add( string.Empty );

            xmlResolver = new XmlUrlResolver();

            Xml = nt.Add( "xml" );
            XmlNs = nt.Add( "xmlns" );

            Debug.Assert( index == 0 );
            nodes = new NodeData[ NodesInitialSize ];
            nodes[0] = new NodeData();
            curNode = nodes[0];

            stringBuilder = new BufferBuilder();
            xmlContext = new XmlContext();

            parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl;
            nextParsingFunction = ParsingFunction.DocumentContent;

            entityHandling = EntityHandling.ExpandCharEntities;
            whitespaceHandling = WhitespaceHandling.All;
            closeInput = true;

            maxCharactersInDocument = 0;
            // Breaking change: entity expansion is enabled, but limit it to 10,000,000 chars (like XLinq)
            maxCharactersFromEntities = (long)1e7;
            charactersInDocument = 0;
            charactersFromEntities = 0;

            ps.lineNo = 1;
            ps.lineStartPos = -1;
        }
示例#50
0
 internal XmlContext(XmlContext previousContext)
 {
     this.xmlSpace = previousContext.xmlSpace;
     this.xmlLang = previousContext.xmlLang;
     this.previousContext = previousContext;
     this.xmlNamespaces = previousContext.xmlNamespaces;
 }
示例#51
0
        // Initializes a new instance of the XmlTextReaderImpl class with the specified XmlNameTable.
        // This constructor is used when creating XmlTextReaderImpl for V1 XmlTextReader
        internal XmlTextReaderImpl(XmlNameTable nt)
        {
            Debug.Assert(nt != null);

            _v1Compat = true;
            _outerReader = this;

            _nameTable = nt;
            nt.Add(string.Empty);

            if (!System.Xml.XmlReaderSettings.EnableLegacyXmlSettings())
            {
                _xmlResolver = null;
            }
            else
            {
                _xmlResolver = new XmlUrlResolver();
            }

            _xml = nt.Add("xml");
            _xmlNs = nt.Add("xmlns");

            Debug.Assert(_index == 0);
            _nodes = new NodeData[NodesInitialSize];
            _nodes[0] = new NodeData();
            _curNode = _nodes[0];

            _stringBuilder = new StringBuilder();
            _xmlContext = new XmlContext();

            _parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl;
            _nextParsingFunction = ParsingFunction.DocumentContent;

            _entityHandling = EntityHandling.ExpandCharEntities;
            _whitespaceHandling = WhitespaceHandling.All;
            _closeInput = true;

            _maxCharactersInDocument = 0;
            // Breaking change: entity expansion is enabled, but limit it to 10,000,000 chars (like XLinq)
            _maxCharactersFromEntities = (long)1e7;
            _charactersInDocument = 0;
            _charactersFromEntities = 0;

            _ps.lineNo = 1;
            _ps.lineStartPos = -1;
        }
示例#52
0
        private List <WebServiceNode> getWebserviceNodeList(string xmlData)
        {
            var list = new List <WebServiceNode>();

            var xmlReaderSettings = new XmlReaderSettings
            {
                CloseInput       = true,
                IgnoreComments   = true,
                IgnoreWhitespace = true,
            };

            using (var reader = XmlReader.Create(new StringReader(xmlData), xmlReaderSettings))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (XmlContext.AdvanceReaderPastEmptyElement(reader))
                        {
                            //Empty element - advance and continue...
                            continue;
                        }

                        if (reader.Name == "ServiceInfo")
                        {
                            string desciptionUrl = null;
                            string serviceUrl    = null;
                            string title         = null;
                            int    serviceID     = -1;
                            string serviceCode   = null;
                            string organization  = null;

                            int    variables = -1, values = -1, sites = -1;
                            double xmin = double.NaN, xmax = double.NaN, ymin = double.NaN, ymax = double.NaN;

                            while (reader.Read())
                            {
                                if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "ServiceInfo")
                                {
                                    break;
                                }

                                if (reader.NodeType == XmlNodeType.Element)
                                {
                                    if (XmlContext.AdvanceReaderPastEmptyElement(reader))
                                    {
                                        //Empty element - advance and continue...
                                        continue;
                                    }

                                    switch (reader.Name)
                                    {
                                    case "Title":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        title = reader.Value.Trim();
                                        break;

                                    case "ServiceID":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        serviceID = Convert.ToInt32(reader.Value.Trim());
                                        break;

                                    case "ServiceDescriptionURL":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        desciptionUrl = reader.Value.Trim();
                                        break;

                                    case "organization":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        organization = reader.Value.Trim();
                                        break;

                                    case "servURL":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        serviceUrl = reader.Value.Trim();
                                        break;

                                    case "valuecount":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        values = Convert.ToInt32(reader.Value.Trim());
                                        break;

                                    case "variablecount":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        variables = Convert.ToInt32(reader.Value.Trim());
                                        break;

                                    case "sitecount":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        sites = Convert.ToInt32(reader.Value.Trim());
                                        break;

                                    case "NetworkName":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        serviceCode = reader.Value.Trim();
                                        break;

                                    case "minx":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        double.TryParse(reader.Value.Trim(), NumberStyles.Number, CultureInfo.InvariantCulture,
                                                        out xmin);
                                        break;

                                    case "maxx":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        double.TryParse(reader.Value.Trim(), NumberStyles.Number, CultureInfo.InvariantCulture,
                                                        out xmax);
                                        break;

                                    case "miny":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        double.TryParse(reader.Value.Trim(), NumberStyles.Number, CultureInfo.InvariantCulture,
                                                        out ymin);
                                        break;

                                    case "maxy":
                                        if (!reader.Read())
                                        {
                                            continue;
                                        }
                                        double.TryParse(reader.Value.Trim(), NumberStyles.Number, CultureInfo.InvariantCulture,
                                                        out ymax);
                                        break;
                                    }
                                }
                            }

                            var boundingBox = (Box)null;
                            if (!double.IsNaN(xmin) && !double.IsNaN(xmax) && !double.IsNaN(ymin) && !double.IsNaN(ymax))
                            {
                                boundingBox = new Box(xmin, xmax, ymin, ymax);
                            }

                            var node = new WebServiceNode(title, serviceCode, serviceID, desciptionUrl, serviceUrl, boundingBox, organization, sites, variables, values);
                            list.Add(node);
                        }
                    }
                }
            }

            return(list);
        }
示例#53
0
 private void PushXmlContext()
 {
     _xmlContext = new XmlContext(_xmlContext);
     _curNode.xmlContextPushed = true;
 }
        // Initializes a new instance of the XmlTextReaderImpl class with the specified XmlNameTable.
        // This constructor is used when creating XmlTextReaderImpl for V1 XmlTextReader
        internal XmlTextReaderImpl( XmlNameTable nt ) {
            Debug.Assert( nt != null );

            v1Compat = true;
            outerReader = this;

            nameTable = nt;
            nt.Add( string.Empty );

            xmlResolver = new XmlUrlResolver();

            Xml = nt.Add( "xml" );
            XmlNs = nt.Add( "xmlns" );

            Debug.Assert( index == 0 );
            nodes = new NodeData[ NodesInitialSize ];
            nodes[0] = new NodeData();
            curNode = nodes[0];

            stringBuilder = new BufferBuilder();
            xmlContext = new XmlContext();

            parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl;
            nextParsingFunction = ParsingFunction.DocumentContent;

            entityHandling = EntityHandling.ExpandCharEntities;
            whitespaceHandling = WhitespaceHandling.All;
            closeInput = true;

            ps.lineNo = 1;
            ps.lineStartPos = -1;
        }
 public FileVersionRepository(XmlContext context) : base(context)
 {
 }
示例#56
0
 /// <summary>
 /// Internals the serialize.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="ctx">xml context</param>
 protected abstract void InternalSerialize(XmlWriter writer, XmlContext ctx);