/// <summary> /// 検索処理の実行 /// </summary> /// <returns></returns> private async Task ExecuteSearch() { try { EnableProcessingMode(); // DBが古い場合はアップグレードする if (DatabaseMigration.GetCurrentVersion() < DatabaseContext.Version) { DatabaseMigration.UpgradeDatabase(); } var parameter = new ActivityLogSearchParameter { IsJoinedRoom = joinCheckBox.IsChecked ?? false, IsMetPlayer = meetCheckBox.IsChecked ?? false, IsSendInvite = sendInvCheckBox.IsChecked ?? false, IsSendRequestInvite = sendReqInvCheckBox.IsChecked ?? false, IsReceivedInvite = recvInvCheckBox.IsChecked ?? false, IsReceivedRequestInvite = recvReqInvCheckBox.IsChecked ?? false, IsSendFriendRequest = sendFriendReqCheckBox.IsChecked ?? false, IsReceivedFriendRequest = recvFriendReqCheckBox.IsChecked ?? false, IsAcceptFriendRequest = acptFriendReqCheckBox.IsChecked ?? false, FromDateTime = fromDatePicker.SelectedDate, UntilDateTime = untilDatePicker.SelectedDate?.AddDays(1), IsReceivedInviteResponse = recvInvResCheckBox.IsChecked ?? false, IsReceivedRequestInviteResponse = recvReqInvResCheckBox.IsChecked ?? false, IsPlayedVideo = videoCheckBox.IsChecked ?? false, }; var activityLogs = await VRChatActivityLogModel.SearchActivityLogs(parameter); var keywords = keywordBox.Text.Split(' ').Where(s => s != string.Empty).ToArray(); ActivityLogGridModelCollection.Clear(); foreach (var activityLog in activityLogs) { var gridModel = new ActivityLogGridModel(activityLog); if (keywords.Any()) { var contained = keywords.All(k => gridModel.Content?.Contains(k, StringComparison.CurrentCultureIgnoreCase) ?? false); if (!contained) { continue; } } ActivityLogGridModelCollection.Add(gridModel); } DisableProcessingMode(); } catch (Exception) { MessageBox.Show("エラーが発生しました。プログラムを終了します。", "VRChatActivityLogViewer", MessageBoxButton.OK, MessageBoxImage.Error); Application.Current.Shutdown(); } }
/// <summary> /// アクティビティを検索する /// </summary> /// <param name="parameter"></param> /// <returns></returns> public static async Task <List <ActivityLog> > SearchActivityLogs(ActivityLogSearchParameter parameter) { return(await Task.Run(() => { var searchActivityTypes = new List <ActivityType>(); if (parameter.IsJoinedRoom) { searchActivityTypes.Add(ActivityType.JoinedRoom); } if (parameter.IsMetPlayer) { searchActivityTypes.Add(ActivityType.MetPlayer); } if (parameter.IsSendInvite) { searchActivityTypes.Add(ActivityType.SendInvite); } if (parameter.IsSendRequestInvite) { searchActivityTypes.Add(ActivityType.SendRequestInvite); } if (parameter.IsReceivedInvite) { searchActivityTypes.Add(ActivityType.ReceivedInvite); } if (parameter.IsReceivedRequestInvite) { searchActivityTypes.Add(ActivityType.ReceivedRequestInvite); } if (parameter.IsSendFriendRequest) { searchActivityTypes.Add(ActivityType.SendFriendRequest); } if (parameter.IsReceivedFriendRequest) { searchActivityTypes.Add(ActivityType.ReceivedFriendRequest); } if (parameter.IsAcceptFriendRequest) { searchActivityTypes.Add(ActivityType.AcceptFriendRequest); } List <ActivityLog> activityLogs = new List <ActivityLog>(); using (var db = new DatabaseContext()) { activityLogs = db.ActivityLogs .Where(a => searchActivityTypes.Contains(a.ActivityType)) .Where(a => a.Timestamp >= parameter.FromDateTime) .Where(a => a.Timestamp < parameter.UntilDateTime) .OrderByDescending(a => a.Timestamp) .ToList(); } return activityLogs; })); }
/// <summary> /// Searchボタンクリック時のイベント /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void searchButton_Click(object sender, RoutedEventArgs e) { try { EnableProcessingMode(); var parameter = new ActivityLogSearchParameter { IsJoinedRoom = joinCheckBox.IsChecked ?? false, IsMetPlayer = meetCheckBox.IsChecked ?? false, IsSendInvite = sendInvCheckBox.IsChecked ?? false, IsSendRequestInvite = sendReqInvCheckBox.IsChecked ?? false, IsReceivedInvite = recvInvCheckBox.IsChecked ?? false, IsReceivedRequestInvite = recvReqInvCheckBox.IsChecked ?? false, IsSendFriendRequest = sendFriendReqCheckBox.IsChecked ?? false, IsReceivedFriendRequest = recvFriendReqCheckBox.IsChecked ?? false, IsAcceptFriendRequest = acptFriendReqCheckBox.IsChecked ?? false, FromDateTime = fromDatePicker.SelectedDate, UntilDateTime = untilDatePicker.SelectedDate?.AddDays(1), }; var activityLogs = await VRChatActivityLogModel.SearchActivityLogs(parameter); ActivityLogGridModelCollection.Clear(); foreach (var activityLog in activityLogs) { ActivityLogGridModelCollection.Add(new ActivityLogGridModel(activityLog)); } DisableProcessingMode(); } catch (Exception) { MessageBox.Show("エラーが発生しました。プログラムを終了します。", "VRChatActivityLogViewer"); Application.Current.Shutdown(); } }