public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSpaStaticFiles(config => config.RootPath = "wwwroot/build"); var cfg = new RelayConfiguration(); _config.Bind(cfg); const string dbConnectionString = "Data Source = Config/relay.db"; services .Configure <RelayConfiguration>(_config) .AddDbContext <LineupContext>(options => options.UseSqlite(dbConnectionString)) .AddSingleton <LineupUpdater>() .AddSingleton <UdpDiscovery>(); switch (cfg.Provider) { case LineupProvider.Tvheadend: services.AddSingleton <ILineupProvider, TvheadendLineupProvider>(); break; } }
public DeviceController( IOptionsSnapshot <RelayConfiguration> config, ILineupProvider provider) { _config = config.Value; _provider = provider; }
public UdpDiscovery( ILogger <UdpDiscovery> log, IOptionsSnapshot <RelayConfiguration> config) { _log = log; _config = config.Value; _client = new UdpClient(Constants.UdpDiscoveryPort); }
public static void ReloadConfiguration() { ChatServers.Clear(); ChannelMappings.Clear(); if (!File.Exists(ConfigFileName)) { throw new RelayConfigurationException( $"Could not locate the configuration file '{ConfigFileName}' in the executing directory."); } string jsonText = File.ReadAllText(ConfigFileName); RelayConfiguration relayConfig = JsonConvert.DeserializeObject <RelayConfiguration>(jsonText); foreach (ChatServer chatServer in relayConfig.ChatServers) { if (ChatServers.ContainsKey(chatServer.ServerId)) { throw new RelayConfigurationException( $"Relay configuration contains duplicate server id '{chatServer.ServerId}'."); } ChatServers.Add(chatServer.ServerId, chatServer); } foreach (ChannelMapping channelMapping in relayConfig.ChannelMappings) { bool mappingExists = ChannelMappings.Exists(x => x.SourceServerId == channelMapping.SourceServerId && x.SourceChannel == channelMapping.SourceChannel && x.TargetServerId == channelMapping.TargetServerId && x.TargetChannel == channelMapping.TargetChannel); if (mappingExists) { throw new RelayConfigurationException( "Relay configuration contains a duplicate channel mapping."); } bool selfMap = channelMapping.SourceServerId == channelMapping.TargetServerId && channelMapping.SourceChannel == channelMapping.TargetChannel; if (selfMap) { throw new RelayConfigurationException( "Relay configuration contains a mapping where the source and target are the same."); } ChannelMappings.Add(channelMapping); } }
public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { tracer.Trace("Parsing Input"); Entity entity = (Entity)context.InputParameters["Target"]; tracer.Trace("Parsing Relay Configuration"); RelayConfiguration config = GetConfig(); tracer.Trace("Creating HttpClient"); using (var client = new HttpClient(new HybridRelayHandler(config))) { tracer.Trace("Executing Request"); var response = client.GetStringAsync($"{config.Url}/api/values").Result; tracer.Trace("Updating Target"); entity["tickersymbol"] = response; } } }
public HybridRelayHandler(RelayConfiguration relayConfig) : base() { _config = relayConfig; _tokenProvider = new SharedAccessSignatureTokenProvider(_config.SasKeyName, _config.SasKey); InnerHandler = new HttpClientHandler(); }
public async Task RegisterRelayCommandAsync( [Description("Discord channel to link to.")] DiscordChannel discordChannel, [Description("IRC channel to link to.")] string ircChannel) { ircChannel = GetIrcChannelName(ircChannel); if (Context.Channel.GuildId == null) { await RespondBasicError("Can only use relay command in a guild channel"); return; } var cfg = _database.Find <RelayConfiguration>(Context.Channel.GuildId); if (cfg is null) { cfg = new RelayConfiguration() { DiscordServer = Context.Channel.GuildId.Value }; await _database.AddAsync(cfg); await _database.SaveChangesAsync(); } // TODO: Some check to see if the IRC channel is available. if (cfg.DiscordToIRCLinks.ContainsKey(discordChannel.Id)) { await RespondBasicError("A relay already exists for this Discord channel."); } var activeHooks = await discordChannel.GetWebhooksAsync(); if (cfg.Webhooks.TryGetValue(ircChannel, out var hook)) { if (activeHooks.Any(x => x.Id == hook.Id)) { await RespondBasicError("A relay for this IRC channel is already in that Discord channel!"); } else { _database.Update(cfg); var discordHook = await Context.Client.GetWebhookAsync(hook.Id); await discordHook.ModifyAsync(channelId : discordChannel.Id); await _database.SaveChangesAsync(); await RespondBasicSuccess($"Moved the relay for IRC channel `{ircChannel}` to {discordChannel.Name}"); } return; } var newHook = await discordChannel.CreateWebhookAsync($"Dostya-{ircChannel}", reason : "Dostya Relay Creation"); if (await _relay.AddRelayAsync(Context.Channel.GuildId.Value, newHook, ircChannel)) { await RespondBasicSuccess($"Relay bridge added ({discordChannel.Name} <-> {ircChannel})"); } else { await RespondBasicError("Failed to add new relay."); } }