Esempio n. 1
0
        private void onDashboardLoad(object sender, EventArgs e)
        {
            // Read from XML
            string        workingDirectory = Directory.GetCurrentDirectory();
            XmlTextReader textReader       = new XmlTextReader(workingDirectory + @"\myDataFile.xml");

            if (textReader.HasLineInfo())
            {
                textReader.Read();

                List <string> list = new List <string>();

                while (textReader.Read())
                {
                    textReader.MoveToElement();
                    if (textReader.Name == "Transaction")
                    {
                        // The desired node has been found
                        XmlNodeType nType = textReader.NodeType;
                        if (nType == XmlNodeType.Text)
                        {
                            list.Add(textReader.Value.ToString());
                        }
                    }
                }
                textReader.Close();
            }

            // Read from Database and populate data
        }
Esempio n. 2
0
        private LocalizedString AddReference(LocalizedString localizedString, XmlTextReader reader, string xamlPath)
        {
            if (reader.HasLineInfo())
            {
                localizedString.AddReference(RelativeDocumentUrl(xamlPath), reader.LineNumber);
            }

            return(localizedString);
        }
Esempio n. 3
0
        /// <summary>
        ///     Throws an XML exception.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="xmlReader">The XML text reader.</param>
        /// <exception cref="XmlException">null</exception>
        private static void ThrowXmlException(string message, XmlReader xmlReader)
        {
            XmlTextReader xmlTextReader = xmlReader as XmlTextReader;

            if (xmlTextReader?.HasLineInfo( ) == true)
            {
                throw new XmlException(message, null, xmlTextReader.LineNumber, xmlTextReader.LinePosition);
            }

            throw new XmlException(message);
        }
Esempio n. 4
0
        private IEnumerable <LocalizedString> Parse(string xamlPath)
        {
            using (var reader = new XmlTextReader(xamlPath)) {
                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Element || !reader.HasAttributes)
                    {
                        continue;
                    }

                    var in_app_bar = false;

                    if (reader.NamespaceURI.Contains("clr-namespace:Microsoft.Phone.Shell"))
                    {
                        var name = reader.Name.Substring(reader.Prefix.Length + 1);
                        in_app_bar = name == "ApplicationBarIconButton" || name == "ApplicationBarMenuItem";
                    }

                    var localized_string = new LocalizedString();

                    while (reader.MoveToNextAttribute())
                    {
                        if (!in_app_bar && !reader.NamespaceURI.Contains("clr-namespace:Vernacular.Xaml"))
                        {
                            continue;
                        }

                        var name = String.IsNullOrEmpty(reader.Prefix)
                            ? reader.Name
                            : reader.Name.Substring(reader.Prefix.Length + 1);

                        switch (name)
                        {
                        case "Text":     // only valid when in_app_bar is true
                        case "Catalog.Message":
                            localized_string.UntranslatedSingularValue = reader.Value;
                            if (reader.HasLineInfo())
                            {
                                localized_string.AddReference(RelativeDocumentUrl(xamlPath), reader.LineNumber);
                            }
                            break;

                        case "Catalog.PluralMessage":
                            localized_string.UntranslatedPluralValue = reader.Value;
                            break;

                        case "Catalog.Comment":
                            localized_string.DeveloperComments = reader.Value;
                            break;
                        }
                    }

                    if (localized_string.IsDefined)
                    {
                        yield return(localized_string);
                    }

                    reader.MoveToElement();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Start parsing the resource XML file.
        /// </summary>
        /// <param name="theResFile">The file with the resource definitions.</param>
        /// <returns>False in case of any error, otherwise true.</returns>
        public bool ParseResource(String theResFile)
        {
            if (theResFile == "")
            {
                mErrorString = "Please specify a XML Resource File!";
                return(false);
            }

            try
            {
                if (File.Exists(theResFile))
                {
                    aXMLReader = new XmlTextReader(ResourceGeneratorForm.OpenStreamReaderWithEncoding(theResFile));

                    // find ResourceManifest tag
                    while (aXMLReader.Read())
                    {
                        if (aXMLReader.NodeType == XmlNodeType.Element)
                        {
                            if (aXMLReader.Name.ToLower() == "resourcemanifest")
                            {
                                mOutputForm.WriteLine("Found ResourceManifest");
                                Application.DoEvents();
                                break;
                            }
                        }
                    }

                    if (aXMLReader.EOF == true)
                    {
                        aXMLReader.Close();
                        mErrorString = "Expecting tag ResourceManifest";

                        return(false);
                    }

                    // start parsing the nodes
                    while (aXMLReader.Read())
                    {
                        switch (aXMLReader.NodeType)
                        {
                        case XmlNodeType.Element:     // The node is an element.

                            // each resource group is an element
                            if (aXMLReader.Name.ToLower() == "resources")
                            {
                                String aResGroup = aXMLReader.GetAttribute("id");
                                if (aResGroup == null)
                                {
                                    mErrorString = "No id for resources specified";
                                    if (aXMLReader.HasLineInfo() == true)
                                    {
                                        mErrorString += " - Line: " + aXMLReader.LineNumber + " Position: " + aXMLReader.LinePosition;
                                    }

                                    return(false);
                                }

                                // create a new dictionary for the resource group
                                mCurrentResGroup = new SortedDictionary <String, BaseRes>();
                                mResGroups.Add(aResGroup, mCurrentResGroup);

                                mOutputForm.WriteLine("Parsing Group " + aResGroup);
                                Application.DoEvents();

                                // start parsing the group
                                if (ParseResources() == false)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                mErrorString = "Invalid Section '" + aXMLReader.Name + "'";
                                break;
                            }
                            break;
                        }

                        if (mErrorString != "")
                        {
                            // an error occured, try to get line information from xml parser
                            if (aXMLReader.HasLineInfo() == true)
                            {
                                mErrorString += " - Line: " + aXMLReader.LineNumber + " Position: " + aXMLReader.LinePosition;
                            }
                            break;
                        }
                    }

                    mOutputForm.WriteLine("Closing Reader");
                    Application.DoEvents();

                    aXMLReader.Close();
                }
                else
                {
                    mErrorString = "File not found: " + theResFile;

                    return(false);
                }
            }
            catch (Exception aException)
            {
                mErrorString += aException.Message;

                return(false);
            }

            return(mErrorString == "");
        }