public ICharInfo GetCharInfo() { try { CharInfo info = new CharInfo(); info.Race = InfoXML.Element("Race").Value; info.Classes = new Dictionary <string, int>(); foreach (XElement element in InfoXML.Element("Classes").Elements()) { info.Classes.Add(key: element.Element("Name").Value, value: int.Parse(element.Element("Level").Value)); } int level = 0; foreach (string key in info.Classes.Keys) { level += info.Classes[key]; } info.LevelMod = (level - 1) / 4 + 2; info.Alignment = InfoXML.Element("Alignment").Value; info.Background = InfoXML.Element("Background").Value; info.Exp = int.Parse(InfoXML.Element("Exp").Value); info.Hp = int.Parse(InfoXML.Element("Hp").Value); info.MaxHp = int.Parse(InfoXML.Element("MaxHP").Value); info.Speed = int.Parse(InfoXML.Element("Speed").Value); info.Traits = InfoXML.Element("Traits").Value; info.Ideals = InfoXML.Element("Ideals").Value; info.Bonds = InfoXML.Element("Bonds").Value; info.Flaws = InfoXML.Element("Flaws").Value; info.Features = new Dictionary <string, string>(); foreach (XElement element in InfoXML.Element("Features").Elements()) { info.Features.Add( key: element.Element("Name").Value, value: element.Element("Description").Value); } return(info); } catch { return(null); } }
public XMLResult GetResultXML(InfoXML info) { var json = JsonConvert.SerializeObject(info); var bodyContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = httpClient.PostAsync(urlApi + "xml/", bodyContent).Result; if (response.IsSuccessStatusCode) { var responContent = response.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <XMLResult>(responContent)); } else { var responContent = response.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <XMLResult>(responContent)); } }
protected void btnValidar_Click(object sender, EventArgs e) { try { lblMessageError.Text = ""; lblMessageSuccess.Text = ""; lblMessageXmlError.Text = ""; AlertXMLError.Visible = false; double docTotal = 0; foreach (Telerik.Web.UI.GridDataItem dataitem in RadGrid1.Items) { if ((dataitem.FindControl("CheckBox1") as CheckBox).Checked == true) { docTotal = Convert.ToDouble(dataitem["DocTotal"].Text); } } if (RadAsyncUpload1.UploadedFiles.Count > 0) { foreach (UploadedFile file in RadAsyncUpload1.UploadedFiles) { if (file.FileName != "") { XMLController xmlController = new XMLController(); UploadResult result = xmlController.UploadFiles(file); if (result.count > 0) { SessionInfoModel session = new SessionInfoModel(); session = (SessionInfoModel)Session["SessionInfo"]; InfoXML info = new InfoXML { cardcode = session.cardcode, docnum = int.Parse(lblDocNum.Text), doctotal = docTotal, typedocument = "PA", xml = result.path }; XMLResult xmlResult = xmlController.GetResultXML(info); if (xmlResult.Status == "Error") { AlertXMLError.Visible = true; lblMessageXmlError.Text = xmlResult.Messages; lblXmlFile.Text = ""; } else { lblHidePathXML.Text = result.path; lblHideUUIDXML.Text = xmlResult.UUID; lblXmlFile.Text = file.FileName; lblMessageSuccess.Text = xmlResult.Messages; btnProcesar.Enabled = true; } } else { lblMessageError.Text = "Debe seleccionar un archivo XML."; lblXmlFile.Text = ""; } } } } else { lblMessageError.Text = "Debe seleccionar un archivo XML."; lblXmlFile.Text = ""; } } catch (Exception ex) { lblMessageError.Text = ex.Message; } }