Пример #1
0
 private async Task InitBox()
 {
     using (var repo = new ReasonRepository())
     {
         importantWords = await repo.GetImportantWordsAsync();
     }
 }
 public void Start()
 {
     Console.WriteLine("KarmaPlugin started");
     _context = new KarmaContext();
     _context.Database.Migrate();
     _karmaRepository  = new KarmaRepository(_context);
     _reasonRepository = new ReasonRepository(_context);
 }
Пример #3
0
        private async Task InitBox()
        {
            msgBox.Document.Blocks.Clear();
            msgBox.IsDocumentEnabled = true;


            using (var repo = new ReasonRepository())
            {
                importantWords = await repo.GetImportantWordsAsync();
            }
        }
Пример #4
0
        public void Save()
        {
            try
            {
                var settings = _settingsStoreSource.GetSettingsStore();
                settings.TimeZoneInfo         = Settings.TimeZoneInfo;
                settings.AdminName            = Settings.AdminName.Replace(" ", string.Empty);
                settings.BansUpdateSeconds    = Settings.BansUpdateSeconds;
                settings.PlayersUpdateSeconds = Settings.PlayersUpdateSeconds;
                settings.Save();

                using (var servierInfoRepository = new ServerInfoRepository())
                {
                    var all = servierInfoRepository.GetServerInfo();

                    var todelete = all.Where(x => Servers.All(s => s.GetDbModel().Id != x.Id));

                    foreach (var serverInfo in todelete)
                    {
                        servierInfoRepository.Remove(serverInfo.Id);
                    }

                    foreach (var s in Servers)
                    {
                        var m = s.GetDbModel();
                        if (m.Id == Guid.Empty)
                        {
                            m.Id = Guid.NewGuid();
                        }
                        servierInfoRepository.AddOrUpdate(m);
                    }
                }

                using (var dc = new ReasonRepository())
                {
                    dc.UpdateBanReasons(BanReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                    dc.UpdateBanTimes(BanTimes.Where(x => string.IsNullOrEmpty(x.Text) == false).Select(x => new BanTime()
                    {
                        TimeInMinutes = x.Minutes, Title = x.Text
                    }).ToArray());
                    dc.UpdateKickReasons(KickReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                }

                _eventAggregator.GetEvent <BEServersChangedEvent>().Publish(null);
                _eventAggregator.GetEvent <SettingsChangedEvent>().Publish(_settingsStoreSource.GetSettingsStore());
            }
            catch (Exception e)
            {
                _log.Error(e);
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #5
0
 public void GetReasonById_WrongId_ReturnsNull()
 {
     // Use a clean instance of the context to run the test
     using (var context = new ReasonContext(_options))
     {
         ReasonRepository reasonRepository = new ReasonRepository(context);
         //act
         var reason = reasonRepository
                      .GetReasonById(5, _userId1);
         //assert
         Assert.Null(reason);
     }
 }
Пример #6
0
        public void GetAllReasons()
        {
            // Use a clean instance of the context to run the test
            using (var context = new ReasonContext(_options))
            {
                ReasonRepository reasonRepository = new ReasonRepository(context);
                //act
                var reasons = reasonRepository.GetAllReasons;

                //assert
                Assert.Equal(15, reasons.Count());
            }
        }
Пример #7
0
 public void GetReasonById_WrongUserId_ReturnsNull()
 {
     // Use a clean instance of the context to run the test
     using (var context = new ReasonContext(_options))
     {
         ReasonRepository reasonRepository = new ReasonRepository(context);
         //act
         var userId = "487f83a4-7e64-4c7f-9330-197b48549ee3";
         var reason = reasonRepository
                      .GetReasonById(1, userId);
         //assert
         Assert.Null(reason);
     }
 }
Пример #8
0
 public void GetReasonById(int id, string userId, string text)
 {
     // Use a clean instance of the context to run the test
     using (var context = new ReasonContext(_options))
     {
         ReasonRepository reasonRepository = new ReasonRepository(context);
         //act
         var reason = reasonRepository
                      .GetReasonById(id, userId);
         var isTrue = reason.Text.Contains(text);
         //assert
         Assert.True(isTrue);
         Assert.Equal(reason.UserId, userId);
     }
 }
Пример #9
0
        async Task <string[]> GetReasons()
        {
            try
            {
                using (var repo = new ReasonRepository())
                {
                    var str = await repo.GetBanReasonsAsync();

                    return(str);
                }
            }
            catch (Exception)
            {
                return(new[] { string.Empty });
            }
        }
Пример #10
0
        private async Task <IEnumerable <string> > GerReasons()
        {
            try
            {
                using (var repo = new ReasonRepository())
                {
                    var str = await repo.GetKickReasonsAsync();

                    return(str);
                }
            }
            catch (Exception)
            {
                return(new[] { string.Empty });
            }
        }
Пример #11
0
        private async void Init()
        {
            Servers = (await _infoRepository.GetServerInfoAsync()).Select(x => new ServerInfoModel(x)).ToList();


            using (var dc = new ReasonRepository())
            {
                BanReasons = (await dc.GetBanReasonsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                KickReasons = (await dc.GetKickReasonsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                BanTimes =
                    (await dc.GetBanTimesAsync()).Select(x => new BanTimeEdit {
                    Text = x.Title, Minutes = x.TimeInMinutes
                }).ToList();

                BadNicknames = (await dc.GetBadNicknamesAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                ImportantWords = (await dc.GetImportantWordsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
            }

            var zones = TimeZoneInfo.GetSystemTimeZones().ToArray();

            for (var i = 0; i < zones.Length; i++)
            {
                if (zones[i].Id == Settings.TimeZoneInfo?.Id)
                {
                    zones[i] = Settings.TimeZoneInfo;
                }
            }

            TimeZones = zones;

            RaisePropertyChanged(nameof(Servers));
            RaisePropertyChanged(nameof(BanReasons));
            RaisePropertyChanged(nameof(KickReasons));
            RaisePropertyChanged(nameof(BanTimes));
            RaisePropertyChanged(nameof(BadNicknames));
            RaisePropertyChanged(nameof(ImportantWords));
            RaisePropertyChanged(nameof(TimeZones));
        }
Пример #12
0
 async Task <IEnumerable <BanFullTime> > GetBanTimes()
 {
     try
     {
         using (var repo = new ReasonRepository())
         {
             var str = (await repo.GetBanTimesAsync()).Select(x => new BanFullTime
             {
                 Text          = x.Title,
                 Period        = System.TimeSpan.FromMinutes(x.TimeInMinutes),
                 PeriodMinutes = x.TimeInMinutes
             }).ToArray();
             return(str);
         }
     }
     catch (Exception)
     {
         return(Enumerable.Empty <BanFullTime>());
     }
 }
        public ActionResult Reason(int id)
        {
            SlippingRequest slippingRequest = Get(id);

            if (slippingRequest != null && !IsSubmitted(slippingRequest))
            {
                var model = new ReasonAndDetails
                {
                    Reasons = ReasonRepository.Get().Where(r => r.ID != 4).ToList(),
                    ID      = slippingRequest.ID,
                    Reason  = slippingRequest.ReasonID.HasValue ? slippingRequest.ReasonID.ToString() : "-1"
                };

                switch (model.Reason)
                {
                case "1":
                    model.Details1 = slippingRequest.Details ?? string.Empty;
                    break;

                case "2":
                    model.Details2 = slippingRequest.Details ?? string.Empty;
                    break;

                case "3":
                    model.Details3 = slippingRequest.Details ?? string.Empty;
                    break;

                case "5":
                    model.Details4 = slippingRequest.Details ?? string.Empty;
                    break;
                }

                return(View(model));
            }
            else
            {
                return(RedirectToAction("NotFound"));
            }
        }
Пример #14
0
        public OptionsModel(IEventAggregator eventAggregator, ISettingsStoreSource settingsStoreSource)
        {
            _eventAggregator     = eventAggregator;
            _settingsStoreSource = settingsStoreSource;
            using (var servierInfoRepository = new ServerInfoRepository())
            {
                Servers = servierInfoRepository.GetServerInfo().Select(x => new ServerInfoModel(x)).ToList();
            }

            using (var dc = new ReasonRepository())
            {
                BanReasons = dc.GetBanReasons().Select(x => new ReasonEdit()
                {
                    Text = x
                }).ToList();
                KickReasons = dc.GetKickReasons().Select(x => new ReasonEdit()
                {
                    Text = x
                }).ToList();
                BanTimes =
                    dc.GetBanTimes().Select(x => new BanTimeEdit()
                {
                    Text = x.Title, Minutes = x.TimeInMinutes
                }).ToList();
            }

            var zones = TimeZoneInfo.GetSystemTimeZones().ToArray();

            for (var i = 0; i < zones.Length; i++)
            {
                if (zones[i].Id == Settings.TimeZoneInfo.Id)
                {
                    zones[i] = Settings.TimeZoneInfo;
                }
            }

            TimeZones = zones;
        }
Пример #15
0
        public ServerMonitorPlayerViewModel(ServerInfoDto serverInfo,
                                            IBanHelper banHelper, IEventAggregator eventAggregator, IPlayerRepository playerRepository,
                                            ReasonRepository reasonRepository,
                                            ISteamService steamService)
            : base(
                new ActionCommand(() => SendCommand(eventAggregator, serverInfo.Id, CommandType.Players)),
                new PlayerViewComparer())
        {
            _serverInfo      = serverInfo;
            _eventAggregator = eventAggregator;
            _playerHelper    = new PlayerHelper(serverInfo.Id, banHelper, playerRepository, reasonRepository, steamService);

            KickUserCommand   = new DelegateCommand(ShowKickDialog, CanShowDialog);
            BanUserCommand    = new DelegateCommand(ShowBanDialog, CanShowDialog);
            PlayerInfoCommand = new DelegateCommand(PlayerInfoDialog, CanShowDialog);


            PropertyChanged += ServerMonitorPlayerViewModel_PropertyChanged;

            _eventAggregator.GetEvent <BEMessageEvent <BEItemsMessage <Player> > >().Subscribe(async e =>
            {
                if (e.ServerId == serverInfo.Id)
                {
                    await SetDataAsync(e.Items);
                    WaitingForEvent = false;
                }
            });

            _eventAggregator.GetEvent <BEMessageEvent <BEItemsMessage <Admin> > >().Subscribe(e =>
            {
                if (e.ServerId == serverInfo.Id)
                {
                    _admins = e.Items ?? new Admin[0];
                }
            });
        }
Пример #16
0
 private async Task Init(ReasonRepository reasonRepository)
 {
     _badNicknames = await reasonRepository.GetBadNicknamesAsync();
 }
Пример #17
0
        public PlayerHelper(Guid serverId, IBanHelper banHelper, IPlayerRepository playerRepository, ReasonRepository reasonRepository, ISteamService steamService)
        {
            _serverId         = serverId;
            _banHelper        = banHelper;
            _playerRepository = playerRepository;
            _steamService     = steamService;

            Init(reasonRepository);
        }
Пример #18
0
        public PlayerHelper(Guid serverId, IBanHelper banHelper, IPlayerRepository playerRepository, ReasonRepository reasonRepository)
        {
            _serverId         = serverId;
            _banHelper        = banHelper;
            _playerRepository = playerRepository;

            Init(reasonRepository);
        }
Пример #19
0
        public async Task Save()
        {
            try
            {
                var customStore = _settingsStoreSource.GetCustomSettingsStore();

                foreach (var serverSetting in ServerSettings)
                {
                    customStore.Save(serverSetting.ServerId.ToString(), new ServerSettings()
                    {
                        ServerId        = serverSetting.ServerId,
                        IdleTimeInMins  = serverSetting.IdleTimeInMins,
                        IdleKickReason  = serverSetting.IdleKickReason,
                        KickIdlePlayers = serverSetting.KickIdlePlayers
                    });
                }

                var settings = _settingsStoreSource.GetSettingsStore();
                settings.TimeZoneInfo = Settings.TimeZoneInfo;

                settings.AdminName = Settings.AdminName.Replace(" ", string.Empty);

                settings.BanMessageTemplate  = Settings.BanMessageTemplate;
                settings.KickMessageTemplate = Settings.KickMessageTemplate;


                settings.BansUpdateSeconds    = Settings.BansUpdateSeconds;
                settings.PlayersUpdateSeconds = Settings.PlayersUpdateSeconds;

                settings.TopMost = Settings.TopMost;

                settings.Save();


                var all = await _infoRepository.GetServerInfoAsync();

                var todelete = all.Where(x => Servers.All(s => s.GetDbModel().Id != x.Id));

                foreach (var serverInfo in todelete)
                {
                    await _infoRepository.RemoveAsync(serverInfo.Id);
                }

                foreach (var s in Servers)
                {
                    var m = s.GetDbModel();
                    if (m.Id == Guid.Empty)
                    {
                        m.Id = Guid.NewGuid();
                    }
                    await _infoRepository.AddOrUpdateAsync(m);
                }


                using (var dc = new ReasonRepository())
                {
                    await dc.UpdateBanReasons(BanReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());

                    await dc.UpdateBanTimes(BanTimes.Where(x => string.IsNullOrEmpty(x.Text) == false).Select(x => new BanTime {
                        TimeInMinutes = x.Minutes, Title = x.Text
                    }).ToArray());

                    await dc.UpdateKickReasons(KickReasons.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());


                    await dc.UpdateBadNicknames(BadNicknames.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());

                    await dc.UpdateImportantWords(ImportantWords.Select(x => x.Text).Where(x => string.IsNullOrEmpty(x) == false).Distinct().ToArray());
                }

                _eventAggregator.GetEvent <BEServersChangedEvent>().Publish(null);
                _eventAggregator.GetEvent <SettingsChangedEvent>().Publish(_settingsStoreSource.GetSettingsStore());


                foreach (Window wnd in Application.Current.Windows)
                {
                    wnd.Topmost = settings.TopMost;
                }
            }
            catch (Exception e)
            {
                _log.Error(e);
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #20
0
        private async void Init()
        {
            var dbServers = (await _infoRepository.GetServerInfoAsync()).ToArray();

            Servers = dbServers.Select(x => new ServerInfoModel(x)).ToList();


            using (var dc = new ReasonRepository())
            {
                BanReasons = (await dc.GetBanReasonsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                KickReasons = (await dc.GetKickReasonsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                BanTimes =
                    (await dc.GetBanTimesAsync()).Select(x => new BanTimeEdit {
                    Text = x.Title, Minutes = x.TimeInMinutes
                }).ToList();

                BadNicknames = (await dc.GetBadNicknamesAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
                ImportantWords = (await dc.GetImportantWordsAsync()).Select(x => new ReasonEdit {
                    Text = x
                }).ToList();
            }

            var zones = TimeZoneInfo.GetSystemTimeZones().ToArray();

            for (var i = 0; i < zones.Length; i++)
            {
                if (zones[i].Id == Settings.TimeZoneInfo?.Id)
                {
                    zones[i] = Settings.TimeZoneInfo;
                }
            }

            TimeZones = zones;

            var customStore = _settingsStoreSource.GetCustomSettingsStore();

            ServerSettings = dbServers.Select(x => new
            {
                ServerSettings =
                    customStore.Load <ServerSettings>(x.Id.ToString()) ?? new ServerSettings()
                {
                    IdleTimeInMins  = 0,
                    KickIdlePlayers = false,
                    IdleKickReason  = "Lobby Idle",
                    ServerId        = x.Id
                },
                ServerName = x.Name
            })
                             .Select(x => new ServerSettingsVM()
            {
                ServerId        = x.ServerSettings.ServerId,
                IdleTimeInMins  = x.ServerSettings.IdleTimeInMins,
                ServerName      = x.ServerName,
                IdleKickReason  = x.ServerSettings.IdleKickReason,
                KickIdlePlayers = x.ServerSettings.KickIdlePlayers
            })
                             .ToList();


            RaisePropertyChanged(nameof(Servers));
            RaisePropertyChanged(nameof(BanReasons));
            RaisePropertyChanged(nameof(KickReasons));
            RaisePropertyChanged(nameof(BanTimes));
            RaisePropertyChanged(nameof(BadNicknames));
            RaisePropertyChanged(nameof(ImportantWords));
            RaisePropertyChanged(nameof(TimeZones));
            RaisePropertyChanged(nameof(ServerSettings));
        }
        public ActionResult Reason(int id, ReasonAndDetails model)
        {
            SlippingRequest slippingRequest = Get(id);

            //mapping correct reason details
            switch (model.Reason)
            {
            case "1":
                if (string.IsNullOrWhiteSpace(model.Details1))
                {
                    ModelState.AddModelError("Details1", "A description of the reason is required");
                }
                break;

            case "2":
                if (string.IsNullOrWhiteSpace(model.Details2))
                {
                    ModelState.AddModelError("Details2", "A description of the reason is required");
                }
                break;

            case "3":
                if (string.IsNullOrWhiteSpace(model.Details3))
                {
                    ModelState.AddModelError("Details3", "A description of the reason is required");
                }
                break;

            case "5":
                if (string.IsNullOrWhiteSpace(model.Details4))
                {
                    ModelState.AddModelError("Details4", "A description of the reason is required");
                }
                break;
            }

            if (slippingRequest != null && !IsSubmitted(slippingRequest))
            {
                if (ModelState.IsValid)
                {
                    slippingRequest.ReasonID = Convert.ToInt32(model.Reason);
                    switch (model.Reason)
                    {
                    case "1":
                        slippingRequest.Details = model.Details1;
                        break;

                    case "2":
                        slippingRequest.Details = model.Details2;
                        break;

                    case "3":
                        slippingRequest.Details = model.Details3;
                        break;

                    case "5":
                        slippingRequest.Details = model.Details4;
                        break;
                    }

                    CreateOrUpdate(slippingRequest);
                    return(RedirectToAction("OppositionMPs"));
                }
                else
                {
                    model.Reasons = ReasonRepository.Get().Where(r => r.ID != 4).ToList();
                    return(View(model));
                }
            }
            else
            {
                return(RedirectToAction("NotFound"));
            }
        }