public static void PostCharacterSheetXML(XmlDocument sheet, string server, string name)
        {
            /*try
            {*/
                //Request the new character sheet xml
                BaseStats baseStats = null;
                int MaxHP;

                XmlNodeList xList, xList2;
                #region BaseStats
                xList = sheet.GetElementsByTagName("health");
                if (xList.Count > 0)
                {
                    MaxHP = Convert.ToInt32(sheet.GetElementsByTagName("health")[0].Attributes["effective"].Value);
                }
                else MaxHP = 0;
                xList = sheet.GetElementsByTagName("baseStats");
                xList2 = sheet.GetElementsByTagName("secondBar");
                if (xList.Count > 0 && xList2.Count >0)
                {
                    baseStats = new BaseStats(xList[0], MaxHP, xList2[0]);
                }
                #endregion
                if (baseStats != null)
                    RequestData.SaveBaseStats(name, server, baseStats);
            /*}
            catch { }*/
        }
        //Character Sheet related functions
        public static void SaveBaseStats(string name, string server, BaseStats stats)
        {
            if (stats == null) return;
            bool exists = false;

            checkSqlConnections();
            #region See if we already have a DB entry
            lock (cReaderLock)
            {
                using (SqlCommand cmd = cSqlReader.CreateCommand())
                {
                    cmd.Parameters.Add("@NAME", SqlDbType.VarChar, 512).Value = name;
                    cmd.Parameters.Add("@SERVER", SqlDbType.VarChar, 128).Value = server;

                    cmd.CommandText = "Select * From armory_CharacterBaseStats Where name = @NAME and server = @SERVER";

                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        if (rd.HasRows)
                            exists = true;
                    }
                }
            }
            #endregion
            #region Insert or update this record
            lock (cWriterLock)
            {
                using (SqlCommand cmd = cSqlWriter.CreateCommand())
                {
                    //Set our paramaters
                    #region Paramaters
                    cmd.Parameters.Add("@NAME", SqlDbType.VarChar, 512).Value = name;
                    cmd.Parameters.Add("@SERVER", SqlDbType.VarChar, 128).Value = server;
                    //HP
                    cmd.Parameters.Add("@HP", SqlDbType.Int).Value = stats.maxHP;
                    //STR
                    cmd.Parameters.Add("@BSTR", SqlDbType.Int).Value = stats.str.baseStr;
                    cmd.Parameters.Add("@ESTR", SqlDbType.Int).Value = stats.str.effectiveStr;
                    cmd.Parameters.Add("@ATKSTR", SqlDbType.Int).Value = stats.str.atkFromStr;
                    cmd.Parameters.Add("@BLSTR", SqlDbType.Int).Value = stats.str.blockFromStr;
                    //AGI
                    cmd.Parameters.Add("@BAGI", SqlDbType.Int).Value = stats.agi.baseAgi;
                    cmd.Parameters.Add("@EAGI", SqlDbType.Int).Value = stats.agi.effectiveAgi;
                    cmd.Parameters.Add("@ARAGI", SqlDbType.Int).Value = stats.agi.armorFromAgi;
                    cmd.Parameters.Add("@ATKAGI", SqlDbType.Int).Value = stats.agi.atkFromAgi;
                    cmd.Parameters.Add("@CRITAGI", SqlDbType.Float).Value = stats.agi.critFromAgi;
                    //STA
                    cmd.Parameters.Add("@BSTA", SqlDbType.Int).Value = stats.sta.baseSta;
                    cmd.Parameters.Add("@ESTA", SqlDbType.Int).Value = stats.sta.effectiveSta;
                    cmd.Parameters.Add("@HPSTA", SqlDbType.Int).Value = stats.sta.hpFromSta;
                    cmd.Parameters.Add("@PETSTA", SqlDbType.Int).Value = stats.sta.petBonusStam;
                    //Int
                    cmd.Parameters.Add("@BINT", SqlDbType.Int).Value = stats.intel.baseInt;
                    cmd.Parameters.Add("@EINT", SqlDbType.Int).Value = stats.intel.effectiveInt;
                    cmd.Parameters.Add("@CRITINT", SqlDbType.Float).Value = stats.intel.critFromInt;
                    cmd.Parameters.Add("@MPINT", SqlDbType.Int).Value = stats.intel.mpFromInt;
                    cmd.Parameters.Add("@PETINT", SqlDbType.Int).Value = stats.intel.petBonusInt;
                    //Spir
                    cmd.Parameters.Add("@BSPIR", SqlDbType.Int).Value = stats.spir.baseSpir;
                    cmd.Parameters.Add("@ESPIR", SqlDbType.Int).Value = stats.spir.effectiveSpir;
                    cmd.Parameters.Add("@HPSPIR", SqlDbType.Int).Value = stats.spir.hpRegenFromSpir;
                    cmd.Parameters.Add("@MPSPIR", SqlDbType.Int).Value = stats.spir.mpRegenFromSpir;
                    //Armor
                    cmd.Parameters.Add("@BARMOR", SqlDbType.Int).Value = stats.armor.baseArmor;
                    cmd.Parameters.Add("@EARMOR", SqlDbType.Int).Value = stats.armor.effectiveArmor;
                    cmd.Parameters.Add("@MITARMOR", SqlDbType.Float).Value = stats.armor.armorMitigation;
                    cmd.Parameters.Add("@PETARMOR", SqlDbType.Int).Value = stats.armor.petArmorBonus;
                    //Second Bar
                    cmd.Parameters.Add("@ESECOND", SqlDbType.Int).Value = stats._2ndBar.effective;
                    cmd.Parameters.Add("@SECONDCASTING", SqlDbType.Int).Value = stats._2ndBar.casting;
                    cmd.Parameters.Add("@SECONDNOTCASTING", SqlDbType.Int).Value = stats._2ndBar.notCasting;
                    cmd.Parameters.Add("@SECONDPERFIVE", SqlDbType.Int).Value = stats._2ndBar.perFive;
                    cmd.Parameters.Add("@SECONDTYPE", SqlDbType.Char).Value = stats._2ndBar.type;

                    #endregion
                    if (exists)
                    {
                        cmd.CommandText = "UPDATE armory_CharacterBaseStats "
                            + "SET maxHP = @HP, baseStr = @BSTR, effectiveStr = @ESTR, atkFromStr = @ATKSTR, blockFromStr = @BLSTR, "
                            + "baseAgi = @BAGI, effectiveAgi = @EAGI, armorFromAgi = @ARAGI, atkFromAgi = @ATKAGI, critFromAgi = @CRITAGI, "
                            + "baseSta = @BSTA, effectiveSta = @ESTA, hpFromSta = @HPSTA, petBonusStam = @PETSTA, "
                            + "baseInt = @BINT, effectiveInt = @EINT, critFromInt = @CRITINT, mpFromInt = @MPINT, petBonusInt = @PETINT, "
                            + "baseSpir = @BSPIR, effectiveSpir = @ESPIR, hpRegenFromSpir = @HPSPIR, mpRegenFromSpir = @MPSPIR, "
                            + "baseArmor = @BARMOR, effectiveArmor = @EARMOR, armorMitigation = @MITARMOR, petArmorBonus = @PETARMOR, "
                            + "lastUpdate = getDate(), "
                            + "effectiveSecondBar = @ESECOND, secondBarCasting = @SECONDCASTING, secondBarNotCasting = @SECONDNOTCASTING, "
                            + "secondBarPerFive = @SECONDPERFIVE, secondBarType = @SECONDTYPE "
                            + " WHERE name = @NAME and server = @SERVER";
                    }
                    else
                    {
                        cmd.CommandText = "INSERT INTO armory_CharacterBaseStats "
                            + "(name, server, maxHP, baseStr, effectiveStr, atkFromStr, blockFromStr, "
                            + "baseAgi, effectiveAgi, armorFromAgi, atkFromAgi, critFromAgi, "
                            + "baseSta, effectiveSta, hpFromSta, petBonusStam, "
                            + "baseInt, effectiveInt, critFromInt, mpFromInt, petBonusInt, "
                            + "baseSpir, effectiveSpir, hpRegenFromSpir, mpRegenFromSpir, "
                            + "baseArmor, effectiveArmor, armorMitigation, petArmorBonus, lastUpdate, "
                            + "effectiveSecondBar, secondBarCasting, secondBarNotCasting, secondBarPerFive, "
                            + " secondBarType) "
                            + "VALUES (@NAME, @SERVER, @HP, @BSTR, @ESTR, @ATKSTR, @BLSTR, "
                            + "@BAGI, @EAGI, @ARAGI, @ATKAGI, @CRITAGI, "
                            + "@BSTA, @ESTA, @HPSTA, @PETSTA, "
                            + "@BINT, @EINT, @CRITINT, @MPINT, @PETINT, "
                            + "@BSPIR, @ESPIR, @HPSPIR, @MPSPIR, "
                            + "@BARMOR, @EARMOR, @MITARMOR, @PETARMOR, getDate(), "
                            + "@ESECOND,@SECONDCASTING,@SECONDNOTCASTING,@SECONDPERFIVE,@SECONDTYPE)";
                    }

                    //try
                    //{
                        cmd.ExecuteNonQuery();
                    //}//If there is some error inserting this in to the DB d/w about it
                    //catch { }

                    //Delete this record from the request queue if it exists
                    PurgeRequestQueue(ReqType.CHARACTER_SHEET,"r=" + server + "&cn=" + name);
                }
            }
            #endregion
        }
        public static ArmoryCharacterSheet getFreshCharacterSheet(string name, string server, string url, out XmlDocument rawSheet)
        {
            ArmoryCharacterSheet output = null;
            //Request the new character sheet xml
            XmlDocument sheet = RequestXml.RequestCharacterSheetXML(url);
            BaseStats baseStats = null;
            Spell spellData = null;
            int MaxHP;

            XmlNodeList xList, xList2;
            #region BaseStats
            xList = sheet.GetElementsByTagName("health");
            if (xList.Count > 0)
            {
                MaxHP = Convert.ToInt32(sheet.GetElementsByTagName("health")[0].Attributes["effective"].Value);
            }
            else MaxHP = 0;
            xList = sheet.GetElementsByTagName("baseStats");
            xList2 = sheet.GetElementsByTagName("secondBar");
            if (xList.Count > 0 && xList2.Count > 0)
            {
                baseStats = new BaseStats(xList[0], MaxHP, xList2[0]);
            }
            #endregion
            if (baseStats != null)
            {
                output = new ArmoryCharacterSheet(baseStats, name, server, url);
                //We got new data, so save it to the DB.
                SaveBaseStats(name, server, baseStats);
            }

            #region Spell data
            xList = sheet.GetElementsByTagName("spell");
            if (xList.Count > 0)
            {
                spellData = new Spell(xList[0]);
            }
            #endregion
            if (spellData != null)
            {
                SaveSpellData(name,server,spellData);
                if (output != null)
                    output.SetSpell(spellData);
            }

            //For their records
            rawSheet = sheet;
            return output;
        }
 public ArmoryCharacterSheet(BaseStats stats, string name, string server, string Url)
 {
     this.name = name;
     this.server = server;
     this.sheetUrl = Url;
     this.baseStats = stats;
 }