private void JSInterface_CurrentRaidReport(object sender, RaidReport e) { //uaktualniam dane które już mam, scalam if (SelectedReport != null && SelectedReport.ReportId == e.ReportId) { e.CavernType = SelectedReport.CavernType; e.AttackCity = SelectedReport.AttackCity; e.CarryCapacity = SelectedReport.CarryCapacity; e.ReportDT = SelectedReport.ReportDT; e.CavernCoords = SelectedReport.CavernCoords; e.Progress = SelectedReport.Progress; //resztę przekopiuję z automatu AutoMapper.Mapper.Map <RaidReport, RaidReport>(e, SelectedReport); //domyślnie ustawiam wagi dla jednostek biorących udział w ataku foreach (var ct in CalcTroops) { ct.Weight = 0; } foreach (var attackT in SelectedReport.AttackTrops) { var ct = CalcTroops.FirstOrDefault(x => x.TropType == attackT.TropType); if (ct != null) { ct.Weight = 1; } } CalcOptimalSquad(); } }
private void DoCurrentRaidReport(RaidReport rep) { var h = CurrentRaidReport; if (h != null) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { try { h(this, rep); } catch (Exception e) { log.Error(e.Message, e); } }), DispatcherPriority.Normal); } }
/// <summary> /// Dane na liście /// </summary> /// <param name="jsonData"></param> /// <returns></returns> public List <RaidReport> GetRaidReports(string jsonData) { var res = new List <RaidReport>(); var allTokens = JsonConvert.DeserializeObject(jsonData) as Newtonsoft.Json.Linq.JObject; if (allTokens != null) { var repArray = allTokens["b"] as Newtonsoft.Json.Linq.JArray; if (repArray != null) { foreach (Newtonsoft.Json.Linq.JArray jRep in repArray) { var rep = new RaidReport(); rep.CavernType = (jRep[0] as Newtonsoft.Json.Linq.JValue).Value as string; rep.AttackCity = (jRep[1] as Newtonsoft.Json.Linq.JValue).Value as string; rep.CarryCapacity = double.Parse((jRep[3] as Newtonsoft.Json.Linq.JValue).Value.ToString()); var strDT = ((jRep[4] as Newtonsoft.Json.Linq.JValue).Value as string).Split(' '); var time = TimeSpan.Parse(strDT[0]); DateTime date = new DateTime(DateTime.Now.Year, int.Parse(strDT[1].Split(new string[] { "/" }, StringSplitOptions.None)[1]), int.Parse(strDT[1].Split(new string[] { "/" }, StringSplitOptions.None)[0]), 0, 0, 0); rep.ReportDT = date.Add(time); rep.CavernCoords = (jRep[5] as Newtonsoft.Json.Linq.JValue).Value as string; rep.ReportId = (jRep[6] as Newtonsoft.Json.Linq.JValue).Value.ToString(); rep.IsNew = (jRep[7] as Newtonsoft.Json.Linq.JValue).Value.ToString() == "0"; rep.Progress = double.Parse((jRep[8] as Newtonsoft.Json.Linq.JValue).Value.ToString()); res.Add(rep); } } } return(res); }
/// <summary> /// Detale /// </summary> /// <param name="jsonData"></param> /// <returns></returns> public RaidReport GetRaidReport(string jsonData) { RaidReport res = null; var allTokens = JsonConvert.DeserializeObject(jsonData) as Newtonsoft.Json.Linq.JObject; if (allTokens != null) { res = new RaidReport(); foreach (var token in allTokens) { switch (token.Key) { case "rid": res.ReportId = token.Value.ToString(); break; case "tn": res.Title = token.Value.ToString(); break; case "tcont": res.TargetCont = token.Value.ToString(); break; case "apn": res.AttackPlayer = token.Value.ToString(); break; case "acont": res.AttackCont = token.Value.ToString(); break; case "acoord": res.AttackCoords = token.Value.ToString(); break; case "anal": res.AnalRes = new Resources(token.Value as JObject); break; case "tc": res.CarryCapacityPcs = (int)token.Value; break; case "rt": res.RtRes = new Resources(token.Value as JObject); break; case "r": res.RRes = new Resources(token.Value as JObject); break; case "rl": res.RlRes = new Resources(token.Value as JObject); break; case "at": res.AttackTrops = new ObservableCollection <ReportTrops>(); foreach (var trop in token.Value) { res.AttackTrops.Add(new ReportTrops(trop as JObject)); } break; case "dt": res.DefTrops = new ObservableCollection <ReportTrops>(); foreach (var trop in token.Value) { res.DefTrops.Add(new ReportTrops(trop as JObject)); } break; default: break; } } } res.RefreshCalcFields(); return(res); }