Exemplo n.º 1
0
 static void Main()
 {
     int starttick;
      int endtick;
      int i;
      XmlTextReader rdr;
      StringBuilder sb;
      SimpleElement se = new SimpleElement("junk");
      SimpleDOMParser sdp;
      sb = new StringBuilder();
      try
      {
     starttick = System.Environment.TickCount;
     for (i=0; i < 10; i++)
     {
        rdr = new XmlTextReader(@"c:\rjones\temp\employees.xml");
        sdp = new SimpleDOMParser();
        se = sdp.parse(rdr);
        rdr.Close();
     }
     endtick = System.Environment.TickCount;
     sb = new StringBuilder();
     printTree(se, sb, 0);
     System.Diagnostics.Debug.WriteLine(sb.ToString());
     System.Diagnostics.Debug.WriteLine(endtick - starttick);
      }
      catch (Exception ex)
      {
     System.Diagnostics.Debug.WriteLine(ex.Message);
      }
 }
Exemplo n.º 2
0
        private void RegForm_Load(object sender, EventArgs e)
        {
            NickGencomboBox.SelectedIndex = 1;

            try
            {
                ConsoleLog.WriteLine("Downloading List of Countries");
                string sCountryName = "";
                string sCountryId = "";
                string sRegId = "";
                string sRegName = "";
                Hashtable siBufRegions = new Hashtable();
                siCountries = new Hashtable();
                siRegions = new Hashtable();
                siCountriesRegions = new Hashtable();
                SimpleDOMParser dp = new SimpleDOMParser();
                SimpleElement elCountries = dp.parse(new XmlTextReader("http://api.erepublik.com/v2/feeds/countries"));
                foreach (SimpleElement elCountry in elCountries.ChildElements)
                {
                    sCountryName = "";
                    sCountryId = "";
                    siBufRegions = new Hashtable();
                    foreach (SimpleElement elCountryEls in elCountry.ChildElements)
                    {
                        if (elCountryEls.TagName == "name")
                        {
                            sCountryName = elCountryEls.Text;
                        }
                        if (elCountryEls.TagName == "id")
                        {
                            sCountryId = elCountryEls.Text;
                        }

                        if (elCountryEls.TagName == "regions")
                        {
                            foreach (SimpleElement elRegion in elCountryEls.ChildElements)
                            {
                                sRegId = "";
                                sRegName = "";
                                foreach (SimpleElement elRegionEl in elRegion.ChildElements)
                                {
                                    if (elRegionEl.TagName == "name")
                                    {
                                        sRegName = elRegionEl.Text;
                                    }
                                    if (elRegionEl.TagName == "id")
                                    {
                                        sRegId = elRegionEl.Text;
                                    }
                                    if (sRegId != "" && sRegName != "")
                                    {
                                        siRegions.Add(sRegName, sRegId);
                                        siBufRegions.Add(sRegName, sRegId);
                                        break;
                                    }
                                }
                            }
                        }
                        if (sCountryId!=""&&sCountryName!="")
                        {
                            if(!siCountries.Contains(sCountryName))
                                siCountries.Add(sCountryName, sCountryId);
                        }
                        if (siBufRegions.Count!=0&&sCountryName!="")
                        {
                            if (!siCountriesRegions.Contains(sCountryName))
                                siCountriesRegions.Add(sCountryName, siBufRegions);
                        }
                    }
                }
                BindingSource bs = new BindingSource();
                bs.DataSource = siCountries;
                CountrycomboBox.DataSource = bs;
                CountrycomboBox.DisplayMember = "Key";
                CountrycomboBox_SelectedIndexChanged(null, null);
            }
            catch (System.Exception e1)
            {
                ConsoleLog.WriteLine(e1.ToString());
            }
        }
Exemplo n.º 3
0
 private void ParseXMLbutton_Click(object sender, EventArgs e)
 {
     m_ssUsers = new Dictionary<string, string>();
     SimpleDOMParser dp = new SimpleDOMParser();
     SimpleElement elRoot = dp.parse(new XmlTextReader(XMLtextBox.Text));
     foreach (SimpleElement elCh in elRoot.ChildElements)
     {
         string sName = "";
         string sId = "";
         foreach (SimpleElement elSubCh in elCh.ChildElements)
         {
             if (elSubCh.TagName=="name")
             {
                 sName = elSubCh.Text;
             }
             if (elSubCh.TagName=="id")
             {
                 sId = elSubCh.Text;
             }
             if (sId!=""&& sName!="")
             {
                 break;
             }
         }
         m_ssUsers.Add(sId, sName);
     }
     System.IO.File.WriteAllText("ParsedXML.txt", GetLine(m_ssUsers));
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            SimpleDOMParser dp = null;
            SimpleElement elCountries = null;
            while (true)
            {
                try
                {
                    dp = new SimpleDOMParser();
                    elCountries = dp.parse(new XmlTextReader("http://api.erepublik.com/v2/feeds/countries"));
                    Console.WriteLine("Countries");
                    break;
                }
                catch (System.Exception e)
                {
                    Console.WriteLine("Countries again");
                }
            }
            pResnames = new Dictionary<string, string>();
            Dictionary<string, Dictionary<string, string>> ssCountryRegions = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, Dictionary<string, int>> ssRegionsResources = new Dictionary<string, Dictionary<string, int>>();
            Dictionary<string, Dictionary<string, int>> ssCountryResources = new Dictionary<string, Dictionary<string, int>>();
            foreach (SimpleElement elCountry in elCountries.ChildElements)
            {
                string sCountyName = "";
                foreach (SimpleElement elCountryEls in elCountry.ChildElements)
                {
                    if (elCountryEls.TagName == "name")
                    {
                        sCountyName = elCountryEls.Text;
                    }
                    if (elCountryEls.TagName == "regions")
                    {
                        Dictionary<string, string> ssRegions = new Dictionary<string, string>();
                        foreach (SimpleElement elRegion in elCountryEls.ChildElements)
                        {
                            string sRegId = "";
                            string sRegName = "";

                            foreach (SimpleElement elRegionEl in elRegion.ChildElements)
                            {
                                if (elRegionEl.TagName == "name")
                                {
                                    sRegName = elRegionEl.Text;
                                }
                                if (elRegionEl.TagName == "id")
                                {
                                    sRegId = elRegionEl.Text;
                                }
                                if (sRegId != "" && sRegName != "")
                                {
                                    ssRegions.Add(sRegName, sRegId);
                                    break;
                                }
                            }
                        }
                        ssCountryRegions.Add(sCountyName, ssRegions);
                    }
                }
            }
            foreach(var elem in ssCountryRegions)
            {
                Console.WriteLine(elem.Key.ToString());
                Dictionary<string, int> ssRegionsRes1 = new Dictionary<string, int>();
                foreach (var regElem in elem.Value)
                {
                    Dictionary<string, int> ssRegionsRes2 = new Dictionary<string, int>();
                    SimpleDOMParser dp1 = null;
                    SimpleElement elRegions = null;
                    while (true)
                    {
                        try
                        {
                            dp1 = new SimpleDOMParser();
                            Console.WriteLine(regElem.Key.ToString());
                            elRegions = dp1.parse(new XmlTextReader("http://api.erepublik.com/v2/feeds/regions/" + regElem.Value.ToString()));
                            break;
                        }
                        catch (System.Exception e)
                        {
                            Console.WriteLine("Region again");
                        }
                    }
                    foreach (SimpleElement elRegion in elRegions.ChildElements)
                    {
                        if (elRegion.TagName == "raw-materials")
                        {
                            string sVal = "";
                            foreach (SimpleElement elMat in elRegion.ChildElements)
                            {
                                if (elMat.TagName == "name")
                                {
                                    string sBuf;
                                    int iVal = 0;
                                    sVal = elMat.Text;
                                    ssRegionsRes2.Add(sVal, 1);
                                    if (ssRegionsRes1.TryGetValue(sVal, out iVal))
                                        ssRegionsRes1[sVal]++;
                                    else
                                        ssRegionsRes1.Add(sVal, 1);

                                    if (!pResnames.TryGetValue(sVal, out sBuf))
                                        pResnames.Add(sVal,sVal);
                                    break;
                                }
                            }
                            ssRegionsResources.Add(regElem.Key, ssRegionsRes2);
                            break;
                        }
                    }
                }
                ssCountryResources.Add(elem.Key, ssRegionsRes1);
            }
            System.IO.File.WriteAllText("countries.csv", GetRes(ssCountryResources));
            System.IO.File.WriteAllText("regions.csv", GetRes(ssRegionsResources));
            System.IO.File.WriteAllText("countryregions.csv", GetCountriesRegionsRes(ssCountryRegions, ssRegionsResources));
        }
Exemplo n.º 5
0
        private void FlyForm_Load(object sender, EventArgs e)
        {
            DbRows grps = Globals.Database.Select("bots", "`group`");
            BindingSource bs = new BindingSource();
            hsgrps = new Hashtable();
            hsgrps.Add("all", grps.Count);
            for (int i = 0; i < grps.Count; ++i)
            {
                DbRow row = grps[i] as DbRow;
                string str = row["group"] as string;
                if (hsgrps.Contains(str))
                    hsgrps[str] = int.Parse(hsgrps[str].ToString()) + 1;
                else
                    hsgrps.Add(str, 1);

            }
            bs.DataSource = hsgrps;
            GroupcomboBox.DataSource = bs;
            GroupcomboBox.DisplayMember = "Key";
            Globals.Database.Reset();
            GroupcomboBox.Text = "all";

            try
            {
                ConsoleLog.WriteLine("Downloading List of Countries");
                string sCountryName = "";
                string sCountryId = "";
                string sRegId = "";
                string sRegName = "";
                Hashtable siBufRegions = new Hashtable();
                siCountries = new Hashtable();
                siRegions = new Hashtable();
                siCountriesRegions = new Hashtable();
                SimpleDOMParser dp = new SimpleDOMParser();
                SimpleElement elCountries = dp.parse(new XmlTextReader("http://api.erepublik.com/v2/feeds/countries"));
                foreach (SimpleElement elCountry in elCountries.ChildElements)
                {
                    sCountryName = "";
                    sCountryId = "";
                    siBufRegions = new Hashtable();
                    foreach (SimpleElement elCountryEls in elCountry.ChildElements)
                    {
                        if (elCountryEls.TagName == "name")
                        {
                            sCountryName = elCountryEls.Text;
                        }
                        if (elCountryEls.TagName == "id")
                        {
                            sCountryId = elCountryEls.Text;
                        }

                        if (elCountryEls.TagName == "regions")
                        {
                            foreach (SimpleElement elRegion in elCountryEls.ChildElements)
                            {
                                sRegId = "";
                                sRegName = "";
                                foreach (SimpleElement elRegionEl in elRegion.ChildElements)
                                {
                                    if (elRegionEl.TagName == "name")
                                    {
                                        sRegName = elRegionEl.Text;
                                    }
                                    if (elRegionEl.TagName == "id")
                                    {
                                        sRegId = elRegionEl.Text;
                                    }
                                    if (sRegId != "" && sRegName != "")
                                    {
                                        siRegions.Add(sRegName, sRegId);
                                        siBufRegions.Add(sRegName, sRegId);
                                        break;
                                    }
                                }
                            }
                        }
                        if (sCountryId != "" && sCountryName != "")
                        {
                            if (!siCountries.Contains(sCountryName))
                                siCountries.Add(sCountryName, sCountryId);
                        }
                        if (siBufRegions.Count != 0 && sCountryName != "")
                        {
                            if (!siCountriesRegions.Contains(sCountryName))
                                siCountriesRegions.Add(sCountryName, siBufRegions);
                        }
                    }
                }
            }
            catch (System.Exception e1)
            {
                ConsoleLog.WriteLine(e1.ToString());
            }

            bs = new BindingSource();
            bs.DataSource = siCountries;
            CountrycomboBox.DataSource = bs;
            CountrycomboBox.DisplayMember = "Key";
            CountrycomboBox_SelectedIndexChanged(null, null);
        }