static async Task Main() { // Sets up Miki.Logging for internal library logging. Can be removed if you do not want to // see internal logs. ExampleHelper.InitLog(LogLevel.Information); // Fetches your token from environment values. var token = ExampleHelper.GetTokenFromEnv(); var memCache = new InMemoryCacheClient(new ProtobufSerializer()); var apiClient = new DiscordApiClient(token, memCache); // Discord direct gateway implementation. var gateway = new GatewayCluster( new GatewayProperties { ShardCount = 1, ShardId = 0, Token = token.ToString(), }); var discordClient = new DiscordClient(apiClient, gateway, memCache); // Subscribe to ready event. discordClient.Events.MessageCreate.SubscribeTask(OnMessageReceived); // Start the connection to the gateway. await gateway.StartAsync(); // Wait, else the application will close. await Task.Delay(-1); }
static async Task MainAsync(string[] args) { // Enables library wide logging for all Miki libraries. Consider using this logging for debugging or general information. new LogBuilder().SetLogHeader(x => $"[{DateTime.UtcNow.ToLongTimeString()}]") .AddLogEvent((msg, level) => { if (level >= logLevel) { Console.WriteLine($"{msg}"); } }).Apply(); // A cache client is needed to store ratelimits and entities. // This is an in-memory cache, and will be used as a local storage repository. IExtendedCacheClient cache = new InMemoryCacheClient( new ProtobufSerializer() ); // Discord REST API implementation gets set up. IApiClient api = new DiscordApiClient(Token, cache); // Discord direct gateway implementation. IGateway gateway = new GatewayCluster(new GatewayProperties { ShardCount = 1, ShardId = 0, Token = Token, Compressed = true, WebSocketClientFactory = () => new BasicWebSocketClient() }); // This function adds additional utility, caching systems and more. DiscordClient bot = new DiscordClient(new DiscordClientConfigurations { ApiClient = api, Gateway = gateway, CacheClient = cache }); // Add caching events for the gateway. new BasicCacheStage().Initialize(gateway, cache); // Hook up on the MessageCreate event. This will send every message through this flow. bot.MessageCreate += async(msg) => { if (msg.Content == "ping") { IDiscordTextChannel channel = await msg.GetChannelAsync(); await channel.SendMessageAsync("pong!"); } }; // Start the connection to the gateway. await gateway.StartAsync(); // Wait, else the application will close. await Task.Delay(-1); }
public async Task GetOnPremisesDataGatewayClustersCanBeSerializedAndDeSerialized() { // Arrange var clusterId = Guid.NewGuid(); var gatewayClusterObject = new GatewayCluster { Id = clusterId, Name = "the cluster name", Description = "the cluster description", Status = "the status", Region = "the region", Permissions = new Permission[] { new Permission { Id = Guid.NewGuid().ToString(), PrincipalType = "User", TenantId = Guid.NewGuid().ToString(), Role = "Admin", AllowedDataSources = new string[] { Guid.NewGuid().ToString() }, ClusterId = clusterId.ToString() } }, DataSourceIds = new Guid[] { Guid.NewGuid() }, Type = "the type", MemberGateways = new MemberGateway[] { new MemberGateway { Id = clusterId, Name = "the member name", Description = "the member description", Status = "the member status", Region = "the member region", Type = "the member type", Version = "the version", Annotation = "the annotation", ClusterId = clusterId } } }; var oDataResponse = new ODataResponseList <GatewayCluster> { ODataContext = "http://example.net/v2.0/myorg/me/$metadata#gatewayClusters", Value = new GatewayCluster[] { gatewayClusterObject } }; var serializedODataRepsonse = JsonConvert.SerializeObject(oDataResponse); var client = Utilities.GetTestClient(serializedODataRepsonse); // Act var result = await client.GetGatewayClusters(true); // Assert gatewayClusterObject.Should().BeEquivalentTo(result.ToArray()[0]); }
public void GetOnPremisesDataGatewayClusterReturnsExpectedResults() { // Arrange var clusterId = Guid.NewGuid(); var expectedResponse = new GatewayCluster { Id = clusterId, Name = "the cluster name", Description = "the cluster description", Status = "the status", Region = "the region", Permissions = new Permission[] { new Permission { Id = Guid.NewGuid().ToString(), PrincipalType = "User", TenantId = Guid.NewGuid().ToString(), Role = "Admin", AllowedDataSources = new string[] { Guid.NewGuid().ToString() }, ClusterId = clusterId.ToString() } }, DataSourceIds = new Guid[] { Guid.NewGuid() }, Type = "the type", MemberGateways = new MemberGateway[] { new MemberGateway { Id = clusterId, Name = "the member name", Description = "the member description", Status = "the member status", Region = "the member region", Type = "the member type", Version = "the version", Annotation = "the annotation", ClusterId = clusterId } } }; var client = new Mock <IPowerBIApiClient>(); client.Setup(x => x.Gateways .GetGatewayClusters(clusterId, true)) .ReturnsAsync(expectedResponse); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new GetOnPremisesDataGatewayCluster(initFactory) { GatewayClusterId = clusterId }; // Act cmdlet.InvokePowerBICmdlet(); // Assert TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory); }