private void RabbitHoleCopy(ref HistoryGroup parent, StatGroup statGroup) { if (statGroup.Stats != null) { foreach (Stat <double> stat in statGroup.Stats) { parent.Stats.EnsureStatValue(stat.Name, stat.Value); } } if (!statGroup.Children.Any()) { return; } foreach (StatGroup group in statGroup.Children) { HistoryGroup newParent = parent.GetGroup(group.Name); foreach (Stat <double> stat in group.Stats) { newParent.Stats.EnsureStatValue(stat.Name, stat.Value); } this.RabbitHoleCopy(ref newParent, group); } }
private static void RabbitHoleCopy(ref HistoryGroup parent, KeyValuePair <string, JToken> statGroup) { var stats = GetDictionary(statGroup.Value["Stats"]); if (stats != null) { foreach (var stat in stats) { parent.Stats.EnsureStatValue(stat.Key, (double)stat.Value); } } var groups = GetDictionary(statGroup.Value); if (!groups.Any()) { return; } foreach (var group in groups.Where(kvp => kvp.Key != "Stats" && !kvp.Key.StartsWith("Last20"))) { var newParent = parent.GetGroup(group.Key); try { var groupStats = GetDictionary(group.Value["Stats"]); foreach (var stat in groupStats) { newParent.Stats.EnsureStatValue(stat.Key, (double)stat.Value); } } catch (Exception ex) { } RabbitHoleCopy(ref newParent, group); } }
/// <summary> /// 生成之后的操作 /// </summary> /// <param name="sendItems"></param> /// <param name="receiveBoxes"></param> protected override void PreviewItemCreated(List <SendItem> sendItems, List <ReceiveBox> receiveBoxes) { // 生成发送的组 // 获取发件箱 // 判断数据中是否有发件人 var senderIds = new List <string>(); List <SendBox> senders = null; if (senderIds.Count > 0) { // 使用选择发件人发件 senders = LiteDb.Fetch <SendBox>(sd => senderIds.Contains(sd._id)); } else { senders = LiteDb.Database.GetCollection <SendBox>().FindAll().ToList(); } // 添加历史 HistoryGroup historyGroup = new HistoryGroup() { userId = _userId, createDate = DateTime.Now, subject = Subject, data = JsonConvert.SerializeObject(Data), receiverIds = receiveBoxes.ConvertAll(rec => rec._id), templateId = Template._id, templateName = Template.name, senderIds = senders.ConvertAll(s => s._id), sendStatus = SendStatus.Sending, }; LiteDb.Database.GetCollection <HistoryGroup>().Insert(historyGroup); // 反回发件信息 _info.historyId = historyGroup._id; // 如果选择发件人,默认从数据中读取发件人,所以选择的发件人数量为0 if (Receivers == null || Receivers.Count < 1) { _info.selectedReceiverCount = 0; } else { _info.selectedReceiverCount = receiveBoxes.Count; } _info.dataReceiverCount = Data.Count; _info.acctualReceiverCount = sendItems.Count; _info.ok = true; _info.senderCount = senders.Count; // 将所有的待发信息添加到数据库 sendItems.ForEach(item => item.historyId = historyGroup._id); LiteDb.Database.GetCollection <SendItem>().InsertBulk(sendItems); }
public async Task GetHistoryResult(string id) { HistoryGroup historyGroup = LiteDb.SingleById <HistoryGroup>(id); // 获取成功的数量 int successCount = LiteDb.Fetch <SendItem>(s => s.historyId == id && s.isSent).Count; JObject result; if (successCount == historyGroup.receiverIds.Count) { string msg = $"发送成功!共发送:{successCount}/{historyGroup.receiverIds.Count}"; result = new JObject(new JProperty("message", msg), new JProperty("ok", true)); } else { string msg = $"未完全发送,共发送:{successCount}/{historyGroup.receiverIds.Count}。请在发件历史中查询重发"; result = new JObject(new JProperty("message", msg), new JProperty("ok", false)); } await ResponseSuccessAsync(result); }
public HistoryTimeline() { Overall = new HistoryGroup("Overall"); Party = new HistoryGroup("Party"); Monster = new HistoryGroup("Monster"); }
private void InitializeHistory() { var hasDamage = this.ParseControl.Timeline.Overall.Stats.GetStatValue("TotalOverallDamage") > 0; var hasHealing = this.ParseControl.Timeline.Overall.Stats.GetStatValue("TotalOverallHealing") > 0; var hasDamageTaken = this.ParseControl.Timeline.Overall.Stats.GetStatValue("TotalOverallDamageTaken") > 0; if (hasDamage || hasHealing || hasDamageTaken) { StatContainer currentOverallStats = this.ParseControl.Timeline.Overall.Stats; var historyItem = new ParseHistoryItem(); HistoryControl historyController = historyItem.HistoryControl = new HistoryControl(); foreach (Stat <double> stat in currentOverallStats) { historyController.Timeline.Overall.Stats.EnsureStatValue(stat.Name, stat.Value); } historyController.Timeline.Overall.Stats.EnsureStatValue("StaticPlayerDPS", currentOverallStats.GetStatValue("DPS")); historyController.Timeline.Overall.Stats.EnsureStatValue("StaticPlayerDOTPS", currentOverallStats.GetStatValue("DOTPS")); historyController.Timeline.Overall.Stats.EnsureStatValue("StaticPlayerHPS", currentOverallStats.GetStatValue("HPS")); historyController.Timeline.Overall.Stats.EnsureStatValue("StaticPlayerHOHPS", currentOverallStats.GetStatValue("HOHPS")); historyController.Timeline.Overall.Stats.EnsureStatValue("StaticPlayerHOTPS", currentOverallStats.GetStatValue("HOTPS")); historyController.Timeline.Overall.Stats.EnsureStatValue("StaticPlayerHMPS", currentOverallStats.GetStatValue("HMPS")); historyController.Timeline.Overall.Stats.EnsureStatValue("StaticPlayerDTPS", currentOverallStats.GetStatValue("DTPS")); historyController.Timeline.Overall.Stats.EnsureStatValue("StaticPlayerDTOTPS", currentOverallStats.GetStatValue("DTOTPS")); StatGroup[] playerList = this.ParseControl.Timeline.Party.ToArray(); foreach (StatGroup player in playerList) { HistoryGroup playerInstance = historyController.Timeline.GetSetPlayer(player.Name); playerInstance.Last20DamageActions = ((Player)player).Last20DamageActions.ToList(); playerInstance.Last20DamageTakenActions = ((Player)player).Last20DamageTakenActions.ToList(); playerInstance.Last20HealingActions = ((Player)player).Last20HealingActions.ToList(); playerInstance.Last20Items = ((Player)player).Last20Items.ToList(); foreach (Stat <double> stat in player.Stats) { playerInstance.Stats.EnsureStatValue(stat.Name, stat.Value); } this.RabbitHoleCopy(ref playerInstance, player); } StatGroup[] monsterList = this.ParseControl.Timeline.Monster.ToArray(); foreach (StatGroup monster in monsterList) { HistoryGroup monsterInstance = historyController.Timeline.GetSetMonster(monster.Name); monsterInstance.Last20DamageActions = ((Monster)monster).Last20DamageActions.ToList(); monsterInstance.Last20DamageTakenActions = ((Monster)monster).Last20DamageTakenActions.ToList(); monsterInstance.Last20HealingActions = ((Monster)monster).Last20HealingActions.ToList(); monsterInstance.Last20Items = ((Monster)monster).Last20Items.ToList(); foreach (Stat <double> stat in monster.Stats) { monsterInstance.Stats.EnsureStatValue(stat.Name, stat.Value); } this.RabbitHoleCopy(ref monsterInstance, monster); } historyItem.Start = this.ParseControl.StartTime; historyItem.End = DateTime.Now; historyItem.ParseLength = historyItem.End - historyItem.Start; var parseTimeDetails = $"{historyItem.Start} -> {historyItem.End} [{historyItem.ParseLength}]"; var zone = "UNKNOWN"; if (XIVInfoViewModel.Instance.CurrentUser != null) { var mapIndex = XIVInfoViewModel.Instance.CurrentUser.MapIndex; MapItem mapItem = ZoneLookup.GetZoneInfo(mapIndex); switch (Constants.GameLanguage) { case "French": zone = mapItem.Name.French; break; case "Japanese": zone = mapItem.Name.Japanese; break; case "German": zone = mapItem.Name.German; break; case "Chinese": zone = mapItem.Name.Chinese; break; case "Korean": zone = mapItem.Name.Korean; break; default: zone = mapItem.Name.English; break; } } var monsterName = "NULL"; try { StatGroup biggestMonster = null; foreach (StatGroup monster in this.ParseControl.Timeline.Monster) { if (biggestMonster == null) { biggestMonster = monster; } else { if (monster.Stats.GetStatValue("TotalOverallDamage") > biggestMonster.Stats.GetStatValue("TotalOverallDamage")) { biggestMonster = monster; } } } if (biggestMonster != null) { monsterName = biggestMonster.Name; } } catch (Exception ex) { Logging.Log(Logger, new LogItem(ex, true)); } foreach (Stat <double> oStat in currentOverallStats) { historyController.Timeline.Overall.Stats.EnsureStatValue(oStat.Name, oStat.Value); } historyItem.Name = $"{zone} [{monsterName}] {parseTimeDetails}"; DispatcherHelper.Invoke(() => MainViewModel.Instance.ParseHistory.Insert(1, historyItem)); } }
public static void ConvertJson(string fileName, string json) { JObject jsonHistoryItem = JObject.Parse(json); Dictionary <string, JToken> timeline = GetDictionary(jsonHistoryItem["Timeline"]); Dictionary <string, JToken> overall = GetDictionary(timeline["Overall"]); Dictionary <string, JToken> overallStats = GetDictionary(overall["Stats"]); var historyItem = new ParseHistoryItem(); HistoryControl historyController = historyItem.HistoryControl = new HistoryControl(); foreach (KeyValuePair <string, JToken> stat in overallStats) { historyController.Timeline.Overall.Stats.EnsureStatValue(stat.Key, (double)stat.Value); } Dictionary <string, JToken> players = GetDictionary(timeline["Party"]); foreach (KeyValuePair <string, JToken> player in players) { Dictionary <string, JToken> children = GetDictionary(player.Value); HistoryGroup playerInstance = historyController.Timeline.GetSetPlayer(player.Key); playerInstance.Last20DamageActions = children["Last20DamageActions"].ToObject <List <LineHistory> >(); playerInstance.Last20DamageTakenActions = children["Last20DamageTakenActions"].ToObject <List <LineHistory> >(); playerInstance.Last20HealingActions = children["Last20HealingActions"].ToObject <List <LineHistory> >(); playerInstance.Last20Items = children["Last20Items"].ToObject <List <LineHistory> >(); Dictionary <string, JToken> stats = GetDictionary(player.Value["Stats"]); foreach (KeyValuePair <string, JToken> stat in stats) { playerInstance.Stats.EnsureStatValue(stat.Key, (double)stat.Value); } RabbitHoleCopy(ref playerInstance, player); } Dictionary <string, JToken> monsters = GetDictionary(timeline["Monster"]); foreach (KeyValuePair <string, JToken> monster in monsters) { Dictionary <string, JToken> children = GetDictionary(monster.Value); HistoryGroup monsterInstance = historyController.Timeline.GetSetMonster(monster.Key); monsterInstance.Last20DamageActions = children["Last20DamageActions"].ToObject <List <LineHistory> >(); monsterInstance.Last20DamageTakenActions = children["Last20DamageTakenActions"].ToObject <List <LineHistory> >(); monsterInstance.Last20HealingActions = children["Last20HealingActions"].ToObject <List <LineHistory> >(); monsterInstance.Last20Items = children["Last20Items"].ToObject <List <LineHistory> >(); Dictionary <string, JToken> stats = GetDictionary(monster.Value["Stats"]); foreach (KeyValuePair <string, JToken> stat in stats) { monsterInstance.Stats.EnsureStatValue(stat.Key, (double)stat.Value); } RabbitHoleCopy(ref monsterInstance, monster); } Match fileNameParts = FileNameRegEx.Match(Path.GetFileNameWithoutExtension(fileName)); historyItem.Start = DateTime.Now; historyItem.End = DateTime.Now; var zone = "Unknown"; var monsterName = "NULL"; try { historyItem.Start = DateTime.Parse(fileNameParts.Groups["startTime"].ToString().Replace("_", ":")); historyItem.End = DateTime.Parse(fileNameParts.Groups["endTime"].ToString().Replace("_", ":")); } catch (Exception ex) { Logging.Log(Logger, new LogItem(ex, true)); } try { zone = fileNameParts.Groups["zone"].ToString(); monsterName = fileNameParts.Groups["monsterName"].ToString(); } catch (Exception ex) { Logging.Log(Logger, new LogItem(ex, true)); } historyItem.ParseLength = historyItem.End - historyItem.Start; var parseTimeDetails = $"{historyItem.Start} -> {historyItem.End} [{historyItem.ParseLength}]"; historyItem.Name = $"{zone} [{monsterName}] {parseTimeDetails}"; DispatcherHelper.Invoke(() => MainViewModel.Instance.ParseHistory.Insert(1, historyItem)); }
public void We_Can_Relate_User_To_Groups() { // arrange var groupOneId = Guid.NewGuid(); var groupTwoId = Guid.NewGuid(); var groupOne = new Group() { Id = groupOneId, Name = "GroupOne", Users = new List <User>(), IsActive = true }; var groupTwo = new Group() { Id = groupTwoId, Name = "GroupTwo", Users = new List <User>(), IsActive = true }; var area = new Area() { Id = Guid.NewGuid(), Latitude = 10, Longitude = 10, Groups = new List <Group>() { groupOne, groupTwo }, IsActive = true }; groupOne.Areas = new List <Area>() { area }; groupTwo.Areas = new List <Area>() { area }; var userId = Guid.NewGuid(); var user = new User() { Id = userId, FirstName = "Stefcho", LastName = "Stefchev", Email = "*****@*****.**", IdsrvUniqueId = Guid.NewGuid().ToString() }; var firstHistoryGroup = new HistoryGroup() { DateTimeGroupWasSubscribed = DateTime.UtcNow, GroupId = groupOneId, GroupThatWasPreviouslySubscribed = groupOne, UserId = userId, UserWhoSubscribedGroup = user, Id = Guid.NewGuid() }; var secondHistoryGroup = new HistoryGroup() { DateTimeGroupWasSubscribed = DateTime.UtcNow, GroupId = groupTwoId, GroupThatWasPreviouslySubscribed = groupTwo, UserId = userId, UserWhoSubscribedGroup = user, Id = Guid.NewGuid() }; var populatedDatabase = new FakeLikkleDbContext() { Groups = new FakeDbSet <Group>() { groupOne, groupTwo }, Areas = new FakeDbSet <Area>() { area }, Users = new FakeDbSet <User>() { user }, HistoryGroups = new FakeDbSet <HistoryGroup>() { firstHistoryGroup, secondHistoryGroup } } .Seed(); this._mockedLikkleUoW.Setup(uow => uow.AreaRepository).Returns(new AreaRepository(populatedDatabase)); this._mockedLikkleUoW.Setup(uow => uow.GroupRepository).Returns(new GroupRepository(populatedDatabase)); this._mockedLikkleUoW.Setup(uow => uow.UserRepository).Returns(new UserRepository(populatedDatabase)); this._mockedLikkleUoW.Setup(uow => uow.HistoryGroupRepository).Returns(new HistoryGroupRepository(populatedDatabase)); var relateUserToGroupsRequest = new RelateUserToGroupsDto() { UserId = userId, Latitude = 10, Longitude = 10, GroupsUserSubscribes = new List <Guid>() { groupOneId, groupTwoId } }; // act this._subscriptionService.RelateUserToGroups(relateUserToGroupsRequest); var userSubscribtionsAroundCoordintes = this._groupService.GetUserSubscriptions(userId, 10, 10); // assert subscription works Assert.IsNotNull(userSubscribtionsAroundCoordintes); Assert.AreEqual(userSubscribtionsAroundCoordintes.Count(), 2); Assert.IsTrue(userSubscribtionsAroundCoordintes.Contains(groupOneId)); Assert.IsTrue(userSubscribtionsAroundCoordintes.Contains(groupTwoId)); Assert.IsNotNull(user.HistoryGroups); Assert.AreEqual(user.HistoryGroups.Count(), 2); var historyGroupIds = user.HistoryGroups.Select(hgr => hgr.GroupId).ToList(); Assert.IsTrue(historyGroupIds.Contains(groupOneId) && historyGroupIds.Contains(groupTwoId)); // arrange relateUserToGroupsRequest = new RelateUserToGroupsDto() { UserId = userId, Latitude = 10, Longitude = 10, GroupsUserSubscribes = new List <Guid>() { groupTwoId } }; groupOne.Users = new List <User>() { user }; groupTwo.Users = new List <User>() { user }; user.HistoryGroups = new List <HistoryGroup>() { firstHistoryGroup, secondHistoryGroup }; // act this._subscriptionService.RelateUserToGroups(relateUserToGroupsRequest); userSubscribtionsAroundCoordintes = this._groupService.GetUserSubscriptions(userId, 10, 10); // assert unsubscription works Assert.IsNotNull(userSubscribtionsAroundCoordintes); Assert.AreEqual(userSubscribtionsAroundCoordintes.Count(), 1); Assert.IsFalse(userSubscribtionsAroundCoordintes.Contains(groupOneId)); Assert.IsTrue(userSubscribtionsAroundCoordintes.Contains(groupTwoId)); Assert.IsTrue(user.HistoryGroups != null); Assert.IsTrue(user.HistoryGroups.Select(hgr => hgr.GroupId).Contains(groupTwoId)); Assert.IsTrue(this._mockedLikkleUoW.Object.HistoryGroupRepository.AllHistoryGroups().Count() == 2); // arrange var groupThree = new Group() { Id = Guid.NewGuid(), Name = "GroupThree", Users = new List <User>(), IsActive = true }; var groupFour = new Group() { Id = Guid.NewGuid(), Name = "GroupFour", Users = new List <User>(), IsActive = true }; groupThree.Areas = new List <Area>() { area }; groupFour.Areas = new List <Area>() { area }; area.Groups.Clear(); area.Groups.Add(groupThree); area.Groups.Add(groupFour); populatedDatabase.Groups = new FakeDbSet <Group>() { groupThree, groupFour }; relateUserToGroupsRequest = new RelateUserToGroupsDto() { UserId = userId, Latitude = 10, Longitude = 10, GroupsUserSubscribes = new List <Guid>() { groupThree.Id, groupFour.Id } }; // act this._subscriptionService.RelateUserToGroups(relateUserToGroupsRequest); userSubscribtionsAroundCoordintes = this._groupService.GetUserSubscriptions(userId, 10, 10); // assert Assert.IsNotNull(userSubscribtionsAroundCoordintes); Assert.AreEqual(userSubscribtionsAroundCoordintes.Count(), 2); Assert.IsFalse(userSubscribtionsAroundCoordintes.Contains(groupOneId)); Assert.IsFalse(userSubscribtionsAroundCoordintes.Contains(groupTwoId)); Assert.IsTrue(userSubscribtionsAroundCoordintes.Contains(groupThree.Id)); Assert.IsTrue(userSubscribtionsAroundCoordintes.Contains(groupFour.Id)); }
private static void RabbitHoleCopy(ref HistoryGroup parent, KeyValuePair<string, JToken> statGroup) { var stats = GetDictionary(statGroup.Value["Stats"]); if (stats != null) { foreach (var stat in stats) { parent.Stats.EnsureStatValue(stat.Key, (decimal) stat.Value); } } var groups = GetDictionary(statGroup.Value); if (!groups.Any()) { return; } foreach (var group in groups.Where(kvp => kvp.Key != "Stats" && !kvp.Key.StartsWith("Last20"))) { var newParent = parent.GetGroup(group.Key); try { var groupStats = GetDictionary(group.Value["Stats"]); foreach (var stat in groupStats) { newParent.Stats.EnsureStatValue(stat.Key, (decimal) stat.Value); } } catch (Exception ex) { } RabbitHoleCopy(ref newParent, group); } }