示例#1
0
        public static async Task Converts_raw_data_to_configuration()
        {
            var mockDatabaseProvider = new Mock <IDatabaseProvider>(MockBehavior.Strict);

            var rawData = new Dictionary <string, string>
            {
                { "nearbyDistance", "3.5" },
                { "shortLeadTimeSpaces", "2" },
                { "totalSpaces", "9" }
            };

            mockDatabaseProvider
            .Setup(p => p.GetConfiguration())
            .ReturnsAsync(RawItem.CreateConfiguration(rawData));

            var configurationRepository = new ConfigurationRepository(mockDatabaseProvider.Object);

            var result = await configurationRepository.GetConfiguration();

            Assert.NotNull(result);

            Assert.Equal(3.5m, result.NearbyDistance);
            Assert.Equal(2, result.ShortLeadTimeSpaces);
            Assert.Equal(9, result.TotalSpaces);
        }
示例#2
0
        public HomeViewModel()
        {
            var configuration = ConfigurationRepository.GetConfiguration();
            var listMCR       = MotorizedCardReaderRepository.GetAll();
            var selectedMCR   = listMCR.Where(m => m.IdMotorizedCardReader == configuration?.IdMotorizedCardReader).FirstOrDefault();

            SelectedMotorizedCardReader = new ReactiveProperty <MotorizedCardReaderModel>(selectedMCR);
            SelectedMotorizedCardReader.PropertyChanged += (_, e) => Save();

            Name = new ReactiveProperty <string>().SetValidateAttribute(() => Name);
            MotorizedCardReaderCollection = listMCR.ToObservable().ToReadOnlyReactiveCollection();
            BautRateCollection            = new ReactiveCollection <int>()
            {
                9600, 19200, 38400, 115200
            };
            PortCollection = Observable.Range(1, 30)
                             .Select(i => $"COM{i}")
                             .ToReadOnlyReactiveCollection();

            SaveCommand = new[]
            {
                Name.ObserveHasErrors
            }
            .CombineLatestValuesAreAllFalse()
            .ToReactiveCommand(false)
            .WithSubscribe(Save);
        }
示例#3
0
        public JsonResult GetConfig(string sortBy)
        {
            var repo   = new ConfigurationRepository(_appSettings);
            var config = repo.GetConfiguration();

            return(Json(config.ToString()));
        }
示例#4
0
        public List <OrganizationalUnit> FindAll()
        {
            ConfigurationRepository config     = new ConfigurationRepository(_mySQLContext);
            CredentialRepository    credential = new CredentialRepository(_mySQLContext);

            credential.DN = config.GetConfiguration("DefaultDN");
            return(FindAll(credential));
        }
示例#5
0
        private async Task MessageReceived(SocketMessage messageParam)
        {
            if (messageParam as SocketUserMessage == null)
            {
                return;
            }
            // Create a number to track where the prefix ends and the command begins
            int argPos = 0;
            // Determine if the message is a command, based on if it starts with '!' or a mention prefix
            // Create a Command Context
            var context = new CommandContext(_client, messageParam as SocketUserMessage);

            if ((messageParam as SocketUserMessage).HasCharPrefix('!', ref argPos) || (messageParam as SocketUserMessage).HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                // Execute the command. (result does not indicate a return value,
                // rather an object stating if the command executed successfully)
                var input = context.Message.Content.Substring(argPos);

                var command = _commands.Search(input);

                bool exec = true;

                if (command.Commands.Any(x => x.Command.Module.Name == "MiscCommands"))
                {
                    var conf = await _configurationRepository.GetConfiguration(context.Guild.Id, "MiscCommandsEnabled");

                    if (conf != null)
                    {
                        var enabled = JsonConvert.DeserializeObject <bool>(conf?.Value);
                        if (!enabled)
                        {
                            exec = false;
                        }
                    }

                    if (conf is null)
                    {
                        exec = false;
                    }
                }

                if (exec)
                {
                    var result = await _commands.ExecuteAsync(context, input, _serviceProvider);

                    if (!result.IsSuccess)
                    {
                        var response = await _errorHandler.SendErrorAsync(context, result);
                    }
                }
            }
            else
            {
                await _statistics.AddPoints(context);
            }

            await _responseRemover.DeleteMessageFromBotOnlyChannels(context);
        }
        public ActionResult Index()
        {
            var viewModel = new ConfigurationViewModel();
            var conf      = _conf.GetConfiguration();

            viewModel.MemoryStrategy = (bool)conf.MemoryStrategy;
            viewModel.LastUpdate     = conf.MameryStrategyDateChaged.ToString();

            return(View("Index", viewModel));
        }
示例#7
0
        public JsonResult UpdateForm(string conf)
        {
            var tempConf = conf.Split(",");
            var repo     = new ConfigurationRepository(_appSettings);

            repo.UpdateConfiguration(new ConfigurationModel()
            {
                Date     = tempConf[0],
                Time     = tempConf[1],
                Assessor = tempConf[2]
            });

            var config = repo.GetConfiguration();

            return(Json(config.ToString()));
        }
        public async Task DeleteMessageFromBotOnlyChannels(CommandContext context)
        {
            if (context.User.IsBot)
            {
                return;
            }
            var guildId = context.Guild.Id;

            var conf = await _configurationRepository.GetConfiguration(guildId, "PlayerViewConfiguration");

            var playerConf = JsonConvert.DeserializeObject <PlayerConfiguration>(conf.Value);

            var playerChat = playerConf?.TextChatId;

            var channel = context.Channel;

            if (playerChat == channel.Id)
            {
                await channel.DeleteMessageAsync(context.Message);
            }
        }
示例#9
0
        public IHttpActionResult Get()
        {
            #region Preconditions

            if (configurationRepository == null)
            {
                throw new InvalidOperationException();
            }

            #endregion

            try
            {
                var configuration = configurationRepository.GetConfiguration();

                var dtoConfiguration = ConfigurationMapper.TranslateModelConfigurationToDTOConfiguration(configuration);

                return(Ok(dtoConfiguration));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
示例#10
0
        private async void UpdatePlayerView(ulong guildId)
        {
            try
            {
                var playerBag = GetPlayerBag(guildId);
                var player    = playerBag.Player;

                var configuration = await _configurationRepository.GetConfiguration <PlayerConfiguration>(guildId, "PlayerViewConfiguration");

                if (configuration is null)
                {
                    return;
                }

                var channel = (IMessageChannel)_discordSocketClient.GetChannel(configuration.TextChatId);

                var viewMsg = (IUserMessage)await channel.GetMessageAsync(configuration.MessageView);

                var queueMsg = (IUserMessage)await channel.GetMessageAsync(configuration.QueueView);

                var title = player?.CurrentTrack?.Title ?? "Pusta kolejka oddtwarzania";
                var icon  = player?.State == PlayerState.Playing ? "https://cdn.discordapp.com/attachments/536616972159549458/650767033339871255/playpause.png" : "https://cdn.discordapp.com/attachments/650687674356727838/650743303549091851/stop.png";

                var ratings = await _audioRatingRepository.GetAudioRatingForSong(guildId, player.CurrentTrack.Identifier);

                var likes    = ratings.Where(x => x.LikeType == LikeType.Like);
                var dislikes = ratings.Where(x => x.LikeType == LikeType.Dislike);

                var embed = new EmbedBuilder
                {
                    ImageUrl = "https://cdn.discordapp.com/attachments/650308145972903940/653310455653072914/pobrany_plik_1.gif",
                    Author   = new EmbedAuthorBuilder
                    {
                        Name    = $"{title} [⭐ {likes.Count()} ❌ {dislikes.Count()} ]",
                        IconUrl = icon
                    },
                    Color = Color.Teal
                };

                await viewMsg.ModifyAsync(x => x.Embed = embed.Build());

                string queuetext = string.Empty;

                var repeatEmoji = playerBag.Repeat switch
                {
                    RepeatType.NormalQueue => "🚫",
                    RepeatType.Repeat => "🔁",
                    RepeatType.RepeatOne => "🔂",
                    _ => ""
                };

                queuetext += $"**Powtarzanie:** {repeatEmoji}\n";

                queuetext += playerBag.Playlist.Count > 0 ?
                             "**Lista odtwarzania**\n" :
                             "**Lista odtwarzania jest pusta**";

                var next  = playerBag.NextSongPointer;
                var plist = playerBag.Playlist;

                queuetext += @$ "{string.Join(" \ n ",
                    playerBag.Playlist
                    .Where(x => plist.IndexOf(x) + 1 >= next - 5)
                    .Select(
                        x => x.Format4Player(plist.IndexOf(x) + 1 >= next, (plist.IndexOf(x) + 1 == next))
                        ))}";

                await queueMsg.ModifyAsync(x => x.Content = queuetext);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#11
0
 public Configuration Get()
 {
     var repository = new ConfigurationRepository();
     return repository.GetConfiguration();
 }
示例#12
0
 /// <summary>
 /// Gets the current OpenMTS configuration.
 /// </summary>
 /// <returns>Returns the current configuration.</returns>
 public Configuration GetConfiguration()
 {
     return(ConfigurationRepository.GetConfiguration());
 }