Ejemplo n.º 1
0
            /// <summary>
            /// This is the worker thread.
            /// </summary>
            /// <param name="stateInfo">Not used.</param>
            void ProcessFiles(object stateInfo)
            {
                System.Text.StringBuilder stb = null;

                while (_filesToProcess.Count > 0)
                {
                    string fullfilename = _filesToProcess.Dequeue();
                    try
                    {
                        string   category     = null;
                        string   name         = null;
                        DateTime creationTime = DateTime.MinValue;
                        string   description  = string.Empty;

                        System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(fullfilename);
                        xmlReader.MoveToContent();
                        while (xmlReader.Read())
                        {
                            if (xmlReader.NodeType == System.Xml.XmlNodeType.Element && xmlReader.LocalName == "Category")
                            {
                                category     = xmlReader.ReadElementString();
                                name         = xmlReader.ReadElementString("Name");
                                creationTime = System.Xml.XmlConvert.ToDateTime(xmlReader.ReadElementString("CreationTime"), System.Xml.XmlDateTimeSerializationMode.Local);
                                if (xmlReader.LocalName == "Description")
                                {
                                    description = xmlReader.ReadElementString("Description");
                                }
                                break;
                            }
                        }
                        xmlReader.Close();

                        AddFitFunctionEntry(category, name, creationTime, description, fullfilename);
                    }
                    catch (Exception ex)
                    {
                        if (stb == null)
                        {
                            stb = new StringBuilder();
                        }

                        stb.AppendLine(ex.ToString());
                    }
                }

                if (stb != null)
                {
                    Current.Console.WriteLine("Exception(s) thrown in " + this.GetType().ToString() + " during parsing of fit functions, details will follow:");
                    Current.Console.WriteLine(stb.ToString());
                }
                _threadIsWorking = false;
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// Parses the XML and fills the list with the hints
        /// </summary>
        public Hints()
        {
            System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(Properties.Settings.Default.HintsFile);

            Hint hint = new Hint();

            // Read an node of the XML
            while (reader.Read())
            {
                reader.MoveToContent();

                // Check if the node is an element
                if (reader.NodeType == System.Xml.XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "id":
                        // create an new Hint-instance
                        hint = new Hint();
                        reader.Read();
                        if (reader.NodeType == System.Xml.XmlNodeType.Text)
                        {
                            hint.ID = Convert.ToInt32(reader.Value);
                        }
                        break;

                    case "title":
                        reader.Read();
                        if (reader.NodeType == System.Xml.XmlNodeType.Text)
                        {
                            hint.Title = reader.Value;
                        }
                        break;

                    case "text":
                        reader.Read();
                        if (reader.NodeType == System.Xml.XmlNodeType.Text)
                        {
                            hint.Text = reader.Value;
                        }

                        // Add the hint to the list
                        hintsList.Add(hint);
                        break;

                    default:
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public bool LoadFromFile(string FileName)
 {
     try {
         Reader = new System.Xml.XmlTextReader(FileName);
         Reader.MoveToContent();
         base.Load(Reader);
         Reader.Close();
         Reader = null;
     } catch (System.Exception Excpt) {
         Err.Add(Excpt);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 4
0
    public static List<ReturnsEval.DataSeriesEvaluator> GetEvalListFromArgs(string[] argsList_)
    {
      List<ReturnsEval.DataSeriesEvaluator> list = new List<ReturnsEval.DataSeriesEvaluator>();

      foreach (string s in argsList_)
      {
        if (System.IO.Directory.Exists(s))
        {
          foreach (string path in System.IO.Directory.GetFiles(s))
          {
            ReturnsEval.DataSeriesEvaluator ev = ReturnsEval.DataSeriesEvaluator.ReadFromDisk(path);
            if (ev != null) list.Add(ev);
            KeyValuePair<ConstructGen<double>, ReturnsEval.DataSeriesEvaluator> kvp = ExtensionMethods.ReadFromDisk<KeyValuePair<ConstructGen<double>, ReturnsEval.DataSeriesEvaluator>>(path);
            if (kvp.Value != null) list.Add(kvp.Value);
          }
        }
        else if (System.IO.File.Exists(s))
        {
          if (s.EndsWith(".xml"))
          {
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(string.Format(@"file://{0}", s.Replace(@"\", "/")));
            reader.MoveToContent();
            doc.Load(reader);
            reader.Close();
            foreach (System.Xml.XmlNode node in doc.DocumentElement.SelectNodes("BloombergTicker"))
            {
              DatedDataCollectionGen<double> hist = BbgTalk.HistoryRequester.GetHistory(new DateTime(2000, 1, 1), node.InnerText, "PX_LAST", true);
              DatedDataCollectionGen<double> genHist = new DatedDataCollectionGen<double>(hist.Dates, hist.Data).ToReturns();
              BbgTalk.RDResult nameData = BbgTalk.HistoryRequester.GetReferenceData(node.InnerText, "SHORT_NAME", null);
              ReturnsEval.DataSeriesEvaluator eval = new ReturnsEval.DataSeriesEvaluator(genHist.Dates, genHist.Data, nameData["SHORT_NAME"].GetValue<string>(), ReturnsEval.DataSeriesType.Returns);
              list.Add(eval);
            }
          }
          else
          {
            ReturnsEval.DataSeriesEvaluator ev = ReturnsEval.DataSeriesEvaluator.ReadFromDisk(s);
            if (ev != null) list.Add(ev);
            KeyValuePair<ConstructGen<double>, ReturnsEval.DataSeriesEvaluator> kvp = SI.ExtensionMethods.ReadFromDisk<KeyValuePair<ConstructGen<double>, ReturnsEval.DataSeriesEvaluator>>(s);
            if (kvp.Value != null) list.Add(kvp.Value);
          }
        }
      }

      return list;
    }
Ejemplo n.º 5
0
 public static int LoadTemplate(ref string err, ref DataSet rmdb, string file)
 {
     DataTable rmdb_set = new DataTable("fields");
     rmdb_set.Columns.Add("id");
     rmdb_set.Columns.Add("type");
     rmdb_set.Columns.Add("value");
     try {
         System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader( file );
         string contents = "";
         while (xmlReader.Read()) {
             xmlReader.MoveToContent();
             string xmlId = null;
             string xmlType = null;
             string xmlValue = null;
             if (xmlReader.NodeType == System.Xml.XmlNodeType.Element) {
                 // contents += "ELEMENT <"+xmlReader.Name + ">\n";
                 if (xmlReader.HasAttributes) {
                     // contents += "Attributes of <" + xmlReader.Name + ">\n";
                     for (int i = 0; i < xmlReader.AttributeCount; i++) {
                         // contents += xmlReader[i];
                         if (i == 0)
                             xmlId = xmlReader[i];
                         if (i == 1)
                             xmlType = xmlReader[i];
                     }
                 }
             }
             if (xmlReader.NodeType == System.Xml.XmlNodeType.Text) {
                 //contents += "TEXT " + xmlReader.Value + "\n";
                 xmlValue = xmlReader.Value;
             }
             // populate internal database
             if (xmlId != null && xmlType != null) {
                 rmdb_set.Rows.Add(xmlId, xmlType, xmlValue);
                 Console.Write(xmlId, xmlType, xmlValue);
             }
         }
         Console.Write(contents);
         rmdb.Tables.Add(rmdb_set);
         return 0;
     }
     catch (Exception e) {
         err = e.Source.ToString() + ": " + e.Message.ToString();
         return 1;
     }
 }
Ejemplo n.º 6
0
        private static void FromXml(System.Xml.XmlTextReader reader, PackageMatchDelegate callback)
        {
            reader.MoveToContent();

            while (reader.Read())
            {
                if (reader.NodeType == System.Xml.XmlNodeType.Element && reader.LocalName == "match")
                {
                    PackageMatch match = ParseMatch(reader);

                    if (!callback(match))
                    {
                        break;
                    }
                }
            }

            reader.Close();
        }
Ejemplo n.º 7
0
 public static int LoadConfig(ref string err, ref Hashtable settings, string file)
 {
     try {
         System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader( file );
         string contents = "";
         while (reader.Read()) {
             reader.MoveToContent();
             if (reader.NodeType == System.Xml.XmlNodeType.Element)
                 contents += "<"+reader.Name + ">\n";
             if (reader.NodeType == System.Xml.XmlNodeType.Text)
                 contents += reader.Value + "\n";
         }
         Console.Write(contents);
         return 0;
     }
     catch (Exception e) {
         err = e.Source.ToString() + ": " + e.Message.ToString();
         return 1;
     }
 }
Ejemplo n.º 8
0
        internal static IEnumerable <ScopedPolicy> RawDeserializeXml(System.IO.StreamReader reader)
        {
            var xr = new System.Xml.XmlTextReader(reader);
            XmlConfigurationReader configReader = XmlConfigurationReader.DefaultReader;

            while (!xr.EOF && xr.MoveToContent() != System.Xml.XmlNodeType.None)
            {
                DataNode node = configReader.Read(xr);
                if (node.Name == "PolicySet" && node is DataItem)
                {
                    foreach (DataNode child in ((DataItem)node).ItemData)
                    {
                        yield return(RawDeserialize(child));
                    }
                }
                else
                {
                    yield return(RawDeserialize(node));
                }
            }
        }
Ejemplo n.º 9
0
        private void WriteXhtmlList(Mvc5RQ.Models.RQItemModel rqItemModel, Stream writeStream)
        {
            if (rqItemModel != null)
            {
                System.Xml.XmlTextReader r = rqItemModel.RQItems.ConvertTo("rqi", 1, 0);

                try
                {
                    var xTrf = new System.Xml.Xsl.XslCompiledTransform(true);
                    var xSet = new System.Xml.Xsl.XsltSettings(enableDocumentFunction: true, enableScript: true);

                    r.MoveToContent();
                    xTrf.Load(rqItemModel.RQItems.FormatPreprocessor.XmlTransformPath, xSet, new System.Xml.XmlUrlResolver());
                    xTrf.Transform(new System.Xml.XPath.XPathDocument(r), rqItemModel.RQItems.FormatPreprocessor.XslTransformArg, writeStream);
                }
                catch (Exception ex)
                {
                    //throw new NotImplementedException("Could not find a RiQuest item with requested document number.");
                    throw new HttpResponseException(JsonErrorResponse.Create(ex, "Add operation failed."));
                }
            }
        }
Ejemplo n.º 10
0
        private TreeNode loadXmlResultsFile(string filename)
        {
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(filename);
            reader.MoveToContent();
            doc.Load(reader);

            System.Xml.XmlElement validatorDataElement =
                doc.FirstChild as System.Xml.XmlElement;
            System.Xml.XmlElement target =
                validatorDataElement.GetElementsByTagName("Target").Item(0)
                as System.Xml.XmlElement;
            statusLabel1.Text =
                "Results from validating target: " +
                target.GetAttribute("friendlyName") + " / " +
                target.GetAttribute("uniqueDeviceName");

            return extractRootFromXmlElement(doc.DocumentElement.FirstChild as System.Xml.XmlElement);
        }
        public ActionResult ImportaIntrebari(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("~/FisiereXML"), Path.GetFileName(file.FileName));
                    file.SaveAs(path);

                    /////////citim fisierul xml
                    System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(path);

                    Disciplina disCiplina  = null;
                    Capitole   capItol     = null;
                    Intrebari  intreBare   = null;
                    Raspunsuri rasPunsuri  = null;
                    int        idIntrebare = 0;

                    while (reader.Read())
                    {
                        reader.MoveToContent();
                        if (reader.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            if (reader.Name == "Disciplina")
                            {
                                string s = reader.GetAttribute(0); // numele disciplinei


                                var v_dis = serviciu.GetDisciplinaByNume_Capitole(s);
                                disCiplina = v_dis;

                                if (disCiplina == null)
                                {
                                    // inseamna ca nu exista elemente
                                    // vom crea o noua disciplina

                                    disCiplina = new Disciplina
                                    {
                                        NumeDisciplina = s
                                    };

                                    disCiplina.State = State.Added;
                                    serviciu.DisciplinaUDI(disCiplina);
                                    disCiplina = serviciu.GetDisciplinaByNume_Capitole(s);
                                }
                            } // if disciplina

                            if (reader.Name == "capitol")
                            {
                                string numeCapitol = reader.GetAttribute(0); // numele capitolului

                                var var_cap = serviciu.GetCapitolByName(numeCapitol);
                                capItol = var_cap;
                                if (capItol == null)
                                {
                                    // inseamana ca nu exista elemente
                                    // vom crea un nou capitol
                                    capItol = new Capitole
                                    {
                                        NumeCapitol            = numeCapitol,
                                        DisciplinaIdDisciplina = disCiplina.IdDisciplina
                                    };

                                    capItol.State = State.Added;
                                    serviciu.CapitoleUDI(capItol);
                                    capItol = serviciu.GetCapitolByName(numeCapitol);
                                }
                            }
                        }

                        if (reader.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            if (reader.Name == "intrebare")
                            {
                                reader.Read();
                                intreBare = new Intrebari
                                {
                                    CapitoleIdCapitol = capItol.IdCapitol,
                                    Intrebarea        = reader.Value
                                };

                                intreBare.State = State.Added;
                                serviciu.IntrebariUDI(intreBare);

                                idIntrebare = serviciu.GetMaxId();
                            }

                            //vom completa cu informatiile pentru raspuns
                            if (reader.Name == "raspunsMotivate")
                            {
                                rasPunsuri = new Raspunsuri();
                                rasPunsuri.IntrebariIdIntrebare = idIntrebare;
                            }

                            if (reader.Name == "raspuns")
                            {
                                reader.Read();
                                rasPunsuri.Raspuns = reader.Value;
                            }
                            if (reader.Name == "motivare")
                            {
                                reader.Read();
                                rasPunsuri.MotivareRaspuns = reader.Value;
                            }
                            if (reader.Name == "corect")
                            {
                                reader.Read();
                                rasPunsuri.RaspunsCorect = reader.Value == "f" ? 0 : 1;
                                rasPunsuri.State         = State.Added;
                                serviciu.RaspunsuriUDI(rasPunsuri);
                            }
                        }
                    }

                    ViewBag.Message = "Fisierul a fost incarcat cu succes";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Exceptie:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "Nu ai ales nici un fisier";
            }
            return(View());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Load options.
        /// </summary>
        /// <param name="filePath">File name to load options from.</param>
        private void DoDeserialize(string filePath)
        {
            if (System.IO.File.Exists(filePath))
            {
                global::System.IO.FileStream fileStream = null;
                try
                {
                    fileStream = global::System.IO.File.OpenRead(filePath);
                    if (fileStream.Length > 5)
                    {
                        using (global::System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(fileStream))
                        {
                            try
                            {
                                reader.MoveToContent();

                                // read attributes
                                string valueE = reader.GetAttribute("errorCategoryVisible");
                                if (valueE != null)
                                {
                                    this.ErrorCategoryVisible = Boolean.Parse(valueE);
                                }

                                string valueW = reader.GetAttribute("warningCategoryVisible");
                                if (valueW != null)
                                {
                                    this.WarningCategoryVisible = Boolean.Parse(valueW);
                                }

                                string valueI = reader.GetAttribute("infoCategoryVisible");
                                if (valueI != null)
                                {
                                    this.InfoCategoryVisible = Boolean.Parse(valueI);
                                }

                                string valueF = reader.GetAttribute("filteredCategoryVisible");
                                if (valueF != null)
                                {
                                    this.FilteredCategoryVisible = Boolean.Parse(valueF);
                                }

                                while (reader.Read())
                                {
                                    switch (reader.NodeType)
                                    {
                                    case System.Xml.XmlNodeType.Element:
                                    {
                                        DeserializeElement(reader, reader.Name);
                                        break;
                                    }
                                    }
                                }
                            }
                            finally
                            {
                                fileStream = null;
                            }
                        }
                    }
                }
                finally
                {
                    if (fileStream != null)
                    {
                        fileStream.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 13
0
      /// <summary>
      /// This is the worker thread.
      /// </summary>
      /// <param name="stateInfo">Not used.</param>
      void ProcessFiles(object stateInfo)
      {

        System.Text.StringBuilder stb = null;

        while (_filesToProcess.Count > 0)
        {
          string fullfilename = _filesToProcess.Dequeue();
          try
          {
            string category = null;
            string name = null;
            DateTime creationTime = DateTime.MinValue;
            string description = string.Empty;

            System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(fullfilename);
            xmlReader.MoveToContent();
            while (xmlReader.Read())
            {
              if (xmlReader.NodeType == System.Xml.XmlNodeType.Element && xmlReader.LocalName == "Category")
              {
                category = xmlReader.ReadElementString();
                name = xmlReader.ReadElementString("Name");
                creationTime = System.Xml.XmlConvert.ToDateTime(xmlReader.ReadElementString("CreationTime"), System.Xml.XmlDateTimeSerializationMode.Local);
                if (xmlReader.LocalName == "Description")
                  description = xmlReader.ReadElementString("Description");
                break;
              }
            }
            xmlReader.Close();

            AddFitFunctionEntry(category, name, creationTime, description, fullfilename);

          }
          catch (Exception ex)
          {
            if (stb == null)
              stb = new StringBuilder();

            stb.AppendLine(ex.ToString());
          }
        }

        if (stb != null)
        {
          Current.Console.WriteLine("Exception(s) thrown in " + this.GetType().ToString() + " during parsing of fit functions, details will follow:");
          Current.Console.WriteLine(stb.ToString());
        }
        _threadIsWorking = false;
      }
Ejemplo n.º 14
0
        private string GetBuildStage()
        {
            if (!controller.SelectedProject.Detail.IsConnected)
            { return string.Empty; }




            if (controller.SelectedProject.ProjectState != ProjectState.Building &&
                controller.SelectedProject.ProjectState != ProjectState.BrokenAndBuilding)
            { return controller.SelectedProject.Detail.ProjectDescription; }

            String currentBuildStage = controller.SelectedProject.Detail.CurrentBuildStage;
            if (currentBuildStage == null || currentBuildStage.Length == 0)
            { return string.Empty; }

            System.Text.StringBuilder SB = new System.Text.StringBuilder();
            System.IO.StringWriter BuildStage = new System.IO.StringWriter(SB);

            try
            {
                System.Xml.XmlTextReader XReader;
                System.Xml.XmlDocument XDoc = new System.Xml.XmlDocument();

                XDoc.LoadXml(controller.SelectedProject.Detail.CurrentBuildStage);
                XReader = new System.Xml.XmlTextReader(XDoc.OuterXml, System.Xml.XmlNodeType.Document, null);
                XReader.WhitespaceHandling = System.Xml.WhitespaceHandling.None;

                while (XReader.Read())
                {
                    XReader.MoveToContent();

                    if (XReader.AttributeCount > 0)
                    {
                        BuildStage.WriteLine("{0}  {1}", XReader.GetAttribute("Time"), XReader.GetAttribute("Data"));
                    }
                }
            }
            catch
            {
                BuildStage = new System.IO.StringWriter();
            }
            return BuildStage.ToString();
        }
Ejemplo n.º 15
0
        private static int FromXml(System.Xml.XmlTextReader reader, ChannelDelegate callback)
        {
            reader.MoveToContent();
            reader.ReadStartElement("channellist");

            int counter = 0;

            while (reader.Read())
            {
                if (reader.LocalName != "channel")
                {
                    continue;
                }

                if (!reader.HasAttributes)
                {
                    Console.WriteLine("channel doesn't have attributes, skipping");
                    continue;
                }

                Channel c = new Channel(reader["bid"],
                                        reader["name"],
                                        reader["alias"],
                                        reader["description"]);
                c.LegacyId = reader["id"];

                string distros = reader["distro_target"];
                if (distros != null)
                {
                    foreach (string d in distros.Split(new Char[] { ':' }))
                    {
                        c.AddDistroTarget(d);
                    }
                }

                ChannelType type     = ChannelType.Unknown;
                string      type_str = reader["type"];
                if (type_str != null)
                {
                    switch (type_str)
                    {
                    case "helix":
                        type = ChannelType.Helix;
                        break;

                    case "debian":
                        type = ChannelType.Debian;
                        break;

                    case "aptrpm":
                        type = ChannelType.Aptrpm;
                        break;

                    case "yum":
                        type = ChannelType.Yum;
                        break;

                    default:
                        break;
                    }
                }

                c.SetType(type);

                int    subd_priority   = 0;
                int    unsubd_priority = 0;
                string priority        = reader["priority"];
                if (priority != null)
                {
                    subd_priority = Channel.PriorityParse(priority);
                }

                priority = reader["priority_when_unsubscribed"];
                if (priority != null)
                {
                    unsubd_priority = Channel.PriorityParse(priority);
                }

                c.SetPriorities(subd_priority, unsubd_priority);

                c.Path        = reader["path"];
                c.FilePath    = reader["file_path"];
                c.IconFile    = reader["icon"];
                c.PkginfoFile = reader["pkginfo_file"];

                string compressed = reader["pkginfo_compressed"];
                if (compressed != null && compressed == "1")
                {
                    c.PkginfoFileCompressed = true;
                }

                counter++;

                if (!callback(c))
                {
                    break;
                }
            }

            return(counter);
        }
Ejemplo n.º 16
0
Archivo: Trigger.cs Proyecto: hpie/hpie
 /// <summary>
 /// Gets basic event information.
 /// </summary>
 /// <param name="log">The event's log.</param>
 /// <param name="source">The event's source. Can be <c>null</c>.</param>
 /// <param name="eventId">The event's id. Can be <c>null</c>.</param>
 /// <returns><c>true</c> if subscription represents a basic event, <c>false</c> if not.</returns>
 public bool GetBasic(out string log, out string source, out int? eventId)
 {
     log = source = null;
     eventId = null;
     if (!string.IsNullOrEmpty(this.Subscription))
     {
         using (System.IO.MemoryStream str = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(this.Subscription)))
         {
             using (System.Xml.XmlTextReader rdr = new System.Xml.XmlTextReader(str))
             {
                 rdr.MoveToContent();
                 rdr.ReadStartElement("QueryList");
                 if (rdr.Name == "Query" && rdr.MoveToAttribute("Path"))
                 {
                     string path = rdr.Value;
                     if (rdr.MoveToElement() && rdr.ReadToDescendant("Select") && path.Equals(rdr["Path"], StringComparison.InvariantCultureIgnoreCase))
                     {
                         string content = rdr.ReadString();
                         System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(content,
                             @"\*(?:\[System\[(?:Provider\[\@Name='(?<s>[^']+)'\])?(?:\s+and\s+)?(?:EventID=(?<e>\d+))?\]\])",
                             System.Text.RegularExpressions.RegexOptions.IgnoreCase |
                             System.Text.RegularExpressions.RegexOptions.Compiled |
                             System.Text.RegularExpressions.RegexOptions.Singleline |
                             System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
                         if (m.Success)
                         {
                             log = path;
                             if (m.Groups["s"].Success)
                                 source = m.Groups["s"].Value;
                             if (m.Groups["e"].Success)
                                 eventId = Convert.ToInt32(m.Groups["e"].Value);
                             return true;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 17
0
 public void openFile()
 {
     xtr = new System.Xml.XmlTextReader(this.fn);
     xtr.MoveToContent();
 }
Ejemplo n.º 18
0
        /// <summary>
        /// This event occurs when the output to print for the current page is needed, and
        /// contains the logic to handle the content and layout of the printed page.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A PrintPageEventArgs that contains the event data.</param>
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            // Determine the height of the header, based on the selected font.
            float headerHeight = headerFont.GetHeight(e.Graphics);

            // Determine the number of lines of body text that can be printed per page, taking
            // into account the presence of the header and the size of the selected body font.
            float linesPerPage = (e.MarginBounds.Height - headerHeight) / bodyFont.GetHeight(e.Graphics);

            // Used to store the position at which the next body line
            // should be printed.
            float yPosition = 0;

            // Used to store the number of lines printed so far on the
            // current page.
            int count = 0;

            // User to store the text of the current line.
            string line = null;

            // Print the page header, as specified by the user in the form.
            // Use the header font for this line only.
            e.Graphics.DrawString(companyName.Text.Trim(), headerFont, Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top, new StringFormat());

            // Print each line of the data file, but don't exceed the maximum allowable
            // number of lines per page.  Also, stop when the end of the data file is
            // reached.  This event is called once per page, so if the data exceeds a single
            // page, the XmlTextReader will pick up where it left off on the previous page.
            while (count < linesPerPage && !xmlReader.EOF)
            {
                // Move the pointer to the next "context" line in the Xml data file.
                // If the line is not an XML element, then it can be skipped.
                // Because the initial Read() call made when the xmlReader was opened
                // positioned the file to the first element (<Customers>) the following
                // call actually moves to the first <Customer> tag the first time through.
                if (xmlReader.MoveToContent() == System.Xml.XmlNodeType.Element)
                {
                    // Based on the element, determine what to print and where to print it.
                    switch (xmlReader.Name)
                    {
                    case "Customers":
                    {
                        // This is not really required, since the initial Read() call
                        // when the xmlReader is loaded effectively bypasses the opening element
                        // as described in the comments above.  Included here for explanation only.

                        // If a <Customers> tag is encountered, just print a blank line.
                        line = "";

                        // Tell the XmlTextReader to move on to the next element.
                        xmlReader.Read();

                        break;
                    }

                    case "Customer":
                    {
                        // Hitting a new <Customer> tag indicates the beginning of a
                        // new customer record.  Take this opportunity to print a blank line,
                        // adding spacing between customer records in the report.
                        line = "";

                        // Tell the XmlTextReader to move on to the next element.
                        xmlReader.Read();

                        break;
                    }

                    default:
                    {
                        // All other elements in the sample XML file are actual data
                        // fields pertaining to a customer record.  Print the field name
                        // and value.  The ReadElementString retrieves the value and
                        // automatically forces the XmlTextReader to move on to the
                        // next element.  Because this is handled generically, any additional
                        // customer fields added inside the <Customer> tag in the xml file will
                        // automatically be shown in the printed report.
                        line = xmlReader.Name + ": " + xmlReader.ReadElementString();
                        break;
                    }
                    }

                    // Determine the position at which to print.  Since this report prints one line
                    // at a time, only the height (or Y coordinate) needs to be calculated, because
                    // every line will begin at the far left.  The Y coordinate must take into
                    // consideration the header, the height of each line of body text, and the
                    // number of body lines printed so far on this page.
                    yPosition = e.MarginBounds.Top + headerHeight + (count * bodyFont.GetHeight(e.Graphics));

                    // Draw the line of text on the page using the body font specified by the user.
                    e.Graphics.DrawString(line, bodyFont, Brushes.Black, e.MarginBounds.Left, yPosition, new StringFormat());

                    // Increment the counter to show that another line has been printed.
                    // This is used in the positioning of future lines of text on the current page.
                    count++;
                }
                else
                {
                    // If the XmlTextReader is positioned on a line that is NOT an
                    // Element, then just go on to the next line.
                    xmlReader.Read();
                }
            }

            // If more data exists, print another page.  If not stop this event from firing
            // again by setting the HasMorePages property to false.
            if (xmlReader.EOF)
            {
                e.HasMorePages = false;
            }
            else
            {
                e.HasMorePages = true;
            }
        }
Ejemplo n.º 19
0
        //-----------------------------------
        // 最新バージョンのチェック
        // "Check for Update"
        //-----------------------------------
        private void mnuCheckForUpdate_Click(object sender, EventArgs e)
        {
            string MsgText = "";
            Version newVersion = null;
            string url = "";
            string dt = "";
            System.Xml.XmlTextReader reader;

            /*
             *	<?xml version="1.0" encoding="utf-8"?>
             *		<markdownsharpeditor>
             *		<version>1.2.1.0</version>
             *		<date>2013/06/18</date>
             *		<url>http://hibara.org/software/markdownsharpeditor/</url>
             *	</markdownsharpeditor>
             */
            string xmlURL = "http://hibara.org/software/markdownsharpeditor/app_version.xml";
            using (reader = new System.Xml.XmlTextReader(xmlURL))
            {
                reader.MoveToContent();
                string elementName = "";
                if ((reader.NodeType == System.Xml.XmlNodeType.Element) && (reader.Name == "markdownsharpeditor"))
                {
                    while (reader.Read())
                    {
                        if (reader.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            elementName = reader.Name;
                        }
                        else
                        {
                            if ((reader.NodeType == System.Xml.XmlNodeType.Text) && (reader.HasValue))
                            {
                                switch (elementName)
                                {
                                    case "version":
                                        newVersion = new Version(reader.Value);
                                        break;
                                    case "url":
                                        url = reader.Value;
                                        break;
                                    case "date":
                                        dt = reader.Value;
                                        break;
                                }
                            }
                        }
                    }
                }
            }

            if (newVersion == null)
            {
                //Failed to get the latest version information.
                MsgText = Resources.ErrorGetNewVersion;
                MessageBox.Show(MsgText, Resources.DialogTitleError, MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }

            // get current version
            Version curVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            if (curVersion.CompareTo(newVersion) < 0)
            {	//"New version was found! Do you open the download site?";
                MsgText = "Update info: ver." + newVersion + " (" + dt + " ) \n" + Resources.NewVersionFound;
                if (DialogResult.Yes == MessageBox.Show(this, MsgText, Resources.DialogTitleQuestion, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    System.Diagnostics.Process.Start(url);
                }
            }
            else
            {	// You already have the latest version of this application.
                MsgText = Resources.AlreadyLatestVersion + "\nver." + newVersion + " ( " + dt + " ) ";
                MessageBox.Show(MsgText, Resources.DialogTitleInfo, MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
        }
        /// <summary>
        /// Load options.
        /// </summary>
        /// <param name="filePath">File name to load options from.</param>
        private void DoDeserialize(string filePath)
        {
            if (System.IO.File.Exists(filePath))
            {
                global::System.IO.FileStream fileStream = null;
                try
                {
                    fileStream = global::System.IO.File.OpenRead(filePath);
                    if (fileStream.Length > 5)
                    {
                        using (global::System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(fileStream))
                        {
                            try
                            {
                                reader.MoveToContent();

                                // read attributes
                                string valueE = reader.GetAttribute("errorCategoryVisible");
                                if (valueE != null)
                                    this.ErrorCategoryVisible = Boolean.Parse(valueE);

                                string valueW = reader.GetAttribute("warningCategoryVisible");
                                if (valueW != null)
                                    this.WarningCategoryVisible = Boolean.Parse(valueW);

                                string valueI = reader.GetAttribute("infoCategoryVisible");
                                if (valueI != null)
                                    this.InfoCategoryVisible = Boolean.Parse(valueI);

                                string valueF = reader.GetAttribute("filteredCategoryVisible");
                                if (valueF != null)
                                    this.FilteredCategoryVisible = Boolean.Parse(valueF);

                                while (reader.Read())
                                {
                                    switch (reader.NodeType)
                                    {
                                        case System.Xml.XmlNodeType.Element:
                                            {
                                                DeserializeElement(reader, reader.Name);
                                                break;
                                            }
                                    }
                                }
                            }
                            finally
                            {
                                fileStream = null;
                            }
                        }
                    }
                }
                finally
                {
                    if (fileStream != null)
                        fileStream.Dispose();
                }
            }
        }