Beispiel #1
0
        public void CanSetServiceTimeout_Mocked()
        {
            string   preferHeader    = null;
            TimeSpan?networkOverride = default;

            var mockTransport = MockTransport.FromMessageCallback(message =>
            {
                Assert.True(message.Request.Headers.TryGetValue("prefer", out preferHeader));
                networkOverride = message.NetworkTimeout;

                return(new MockResponse(500));
            });

            var client = new LogsClient(new MockCredential(), new LogsClientOptions()
            {
                Transport = mockTransport
            });

            Assert.ThrowsAsync <RequestFailedException>(() => client.QueryAsync("wid", "tid", options: new LogsQueryOptions()
            {
                Timeout = TimeSpan.FromMinutes(10)
            }));

            Assert.AreEqual("wait=600", preferHeader);
            Assert.AreEqual(TimeSpan.FromMinutes(10), networkOverride);
        }
Beispiel #2
0
        public async Task BatchQuery()
        {
            #region Snippet:BatchQuery

#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());

            // Query TOP 10 resource groups by event count
            // And total event count
            LogsBatchQuery batch        = new LogsBatchQuery();
            string         countQueryId = batch.AddQuery(workspaceId, "AzureActivity | count", TimeSpan.FromDays(1));
            string         topQueryId   = batch.AddQuery(workspaceId, "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count", TimeSpan.FromDays(1));

            Response <LogsBatchQueryResult> response = await client.QueryBatchAsync(batch);

            var count      = response.Value.GetResult <int>(countQueryId).Single();
            var topEntries = response.Value.GetResult <MyLogEntryModel>(topQueryId);

            Console.WriteLine($"AzureActivity has total {count} events");
            foreach (var logEntryModel in topEntries)
            {
                Console.WriteLine($"{logEntryModel.ResourceGroup} had {logEntryModel.Count} events");
            }

            #endregion
        }
Beispiel #3
0
        protected virtual void InitRestClients()
        {
            RestClient = new RestClient(RootUrl + "api/v1/");
            RestClient.AddDefaultHeader("Authentication", ApiKey);
            RestClient.AddDefaultHeader("X-Api-Key", ApiKey);

            Blacklist         = new ClientBase <BlacklistResource>(RestClient, ApiKey);
            Commands          = new CommandClient(RestClient, ApiKey);
            DownloadClients   = new DownloadClientClient(RestClient, ApiKey);
            Albums            = new AlbumClient(RestClient, ApiKey);
            Tracks            = new TrackClient(RestClient, ApiKey);
            History           = new ClientBase <HistoryResource>(RestClient, ApiKey);
            HostConfig        = new ClientBase <HostConfigResource>(RestClient, ApiKey, "config/host");
            Indexers          = new IndexerClient(RestClient, ApiKey);
            Logs              = new LogsClient(RestClient, ApiKey);
            NamingConfig      = new ClientBase <NamingConfigResource>(RestClient, ApiKey, "config/naming");
            Notifications     = new NotificationClient(RestClient, ApiKey);
            Profiles          = new ClientBase <QualityProfileResource>(RestClient, ApiKey);
            Releases          = new ReleaseClient(RestClient, ApiKey);
            ReleasePush       = new ReleasePushClient(RestClient, ApiKey);
            RootFolders       = new ClientBase <RootFolderResource>(RestClient, ApiKey);
            Artist            = new ArtistClient(RestClient, ApiKey);
            Tags              = new ClientBase <TagResource>(RestClient, ApiKey);
            WantedMissing     = new ClientBase <AlbumResource>(RestClient, ApiKey, "wanted/missing");
            WantedCutoffUnmet = new ClientBase <AlbumResource>(RestClient, ApiKey, "wanted/cutoff");
        }
Beispiel #4
0
        public async Task QueryLogsAsPrimitive()
        {
            #region Snippet:QueryLogsAsPrimitive

#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());

            // Query TOP 10 resource groups by event count
            Response <IReadOnlyList <string> > response = await client.QueryAsync <string>(workspaceId,
                                                                                           "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count | project ResourceGroup",
                                                                                           TimeSpan.FromDays(1));

            foreach (var resourceGroup in response.Value)
            {
                Console.WriteLine(resourceGroup);
            }

            #endregion
        }
Beispiel #5
0
        public async Task BatchQuery()
        {
            #region Snippet:BatchQuery

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";

            // Query TOP 10 resource groups by event count
            // And total event count
            LogsBatchQuery batch        = client.CreateBatchQuery();
            string         countQueryId = batch.AddQuery(workspaceId, "AzureActivity | count");
            string         topQueryId   = batch.AddQuery(workspaceId, "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count");

            Response <LogsBatchQueryResult> response = await batch.SubmitAsync();

            var count      = response.Value.GetResult <int>(countQueryId).Single();
            var topEntries = response.Value.GetResult <MyLogEntryModel>(topQueryId);

            Console.WriteLine($"AzureActivity has total {count} events");
            foreach (var logEntryModel in topEntries)
            {
                Console.WriteLine($"{logEntryModel.ResourceGroup} had {logEntryModel.Count} events");
            }

            #endregion
        }
Beispiel #6
0
        protected virtual void InitRestClients()
        {
            RestClient = new RestClient(RootUrl + "api/");
            RestClient.AddDefaultHeader("Authentication", ApiKey);
            RestClient.AddDefaultHeader("X-Api-Key", ApiKey);

            RestClientv3 = new RestClient(RootUrl + "api/v3/");
            RestClientv3.AddDefaultHeader("Authentication", ApiKey);
            RestClientv3.AddDefaultHeader("X-Api-Key", ApiKey);

            Blocklist         = new ClientBase <BlocklistResource>(RestClient, ApiKey);
            Commands          = new CommandClient(RestClient, ApiKey);
            DownloadClients   = new DownloadClientClient(RestClient, ApiKey);
            Episodes          = new EpisodeClient(RestClient, ApiKey);
            History           = new ClientBase <HistoryResource>(RestClient, ApiKey);
            HostConfig        = new ClientBase <HostConfigResource>(RestClient, ApiKey, "config/host");
            Indexers          = new IndexerClient(RestClient, ApiKey);
            Indexersv3        = new IndexerClient(RestClientv3, ApiKey);
            Logs              = new LogsClient(RestClient, ApiKey);
            NamingConfig      = new ClientBase <NamingConfigResource>(RestClient, ApiKey, "config/naming");
            Notifications     = new NotificationClient(RestClient, ApiKey);
            Profiles          = new ClientBase <ProfileResource>(RestClient, ApiKey);
            Releases          = new ReleaseClient(RestClient, ApiKey);
            ReleasePush       = new ReleasePushClient(RestClient, ApiKey);
            RootFolders       = new ClientBase <RootFolderResource>(RestClient, ApiKey);
            Series            = new SeriesClient(RestClient, ApiKey);
            Tags              = new ClientBase <TagResource>(RestClient, ApiKey);
            WantedMissing     = new ClientBase <EpisodeResource>(RestClient, ApiKey, "wanted/missing");
            WantedCutoffUnmet = new ClientBase <EpisodeResource>(RestClient, ApiKey, "wanted/cutoff");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ManagementApiClient"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="baseUri">The base URI.</param>
        /// <param name="diagnostics">The diagnostics.</param>
        /// <param name="handler">The <see cref="HttpMessageHandler"/> which is used for HTTP requests</param>
        public ManagementApiClient(string token, Uri baseUri, DiagnosticsHeader diagnostics, HttpMessageHandler handler)
        {
            // If no diagnostics header structure was specified, then revert to the default one
            if (diagnostics == null)
            {
                diagnostics = DiagnosticsHeader.Default;
            }

            apiConnection = new ApiConnection(token, baseUri.AbsoluteUri, diagnostics, handler);

            BlacklistedTokens = new BlacklistedTokensClient(apiConnection);
            ClientGrants      = new ClientGrantsClient(apiConnection);
            Clients           = new ClientsClient(apiConnection);
            Connections       = new ConnectionsClient(apiConnection);
            DeviceCredentials = new DeviceCredentialsClient(apiConnection);
            EmailProvider     = new EmailProviderClient(apiConnection);
            Jobs            = new JobsClient(apiConnection);
            Logs            = new LogsClient(apiConnection);
            ResourceServers = new ResourceServersClient(apiConnection);
            Rules           = new RulesClient(apiConnection);
            Stats           = new StatsClient(apiConnection);
            TenantSettings  = new TentantSettingsClient(apiConnection);
            Tickets         = new TicketsClient(apiConnection);
            UserBlocks      = new UserBlocksClient(apiConnection);
            Users           = new UsersClient(apiConnection);
        }
Beispiel #8
0
        public void CanSetServiceTimeout_Mocked()
        {
            string preferHeader = null;
            // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
            // TimeSpan? networkOverride = default;

            var mockTransport = MockTransport.FromMessageCallback(message =>
            {
                Assert.True(message.Request.Headers.TryGetValue("prefer", out preferHeader));
                // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
                //networkOverride = message.NetworkTimeout;

                return(new MockResponse(500));
            });

            var client = new LogsClient(new Uri("https://api.loganalytics.io"), new MockCredential(), new LogsClientOptions()
            {
                Transport = mockTransport
            });

            Assert.ThrowsAsync <RequestFailedException>(() => client.QueryAsync("wid", "tid", TimeSpan.FromDays(1), options: new LogsQueryOptions()
            {
                Timeout = TimeSpan.FromMinutes(10)
            }));

            Assert.AreEqual("wait=600", preferHeader);
            // TODO: https://github.com/Azure/azure-sdk-for-net/issues/20859
            //Assert.AreEqual(TimeSpan.FromMinutes(10), networkOverride);
        }
Beispiel #9
0
        public async Task QueryLogsAsTablePrintAll()
        {
            #region Snippet:QueryLogsPrintTable

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";
            Response <LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated");

            LogsQueryResultTable table = response.Value.PrimaryTable;

            foreach (var column in table.Columns)
            {
                Console.Write(column.Name + ";");
            }

            Console.WriteLine();

            var columnCount = table.Columns.Count;
            foreach (var row in table.Rows)
            {
                for (int i = 0; i < columnCount; i++)
                {
                    Console.Write(row[i] + ";");
                }

                Console.WriteLine();
            }

            #endregion
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ManagementApiClient"/> class.
        /// </summary>
        /// <param name="token">A valid Auth0 Management API v2 token.</param>
        /// <param name="baseUri"><see cref="Uri"/> of the tenant to manage.</param>
        /// <param name="managementConnection"><see cref="IManagementConnection"/> to facilitate communication with server.</param>
        public ManagementApiClient(string token, Uri baseUri, IManagementConnection managementConnection = null)
        {
            if (managementConnection == null)
            {
                var ownedManagementConnection = new HttpClientManagementConnection();
                managementConnection = ownedManagementConnection;
                connectionToDispose  = ownedManagementConnection;
            }

            var defaultHeaders = CreateDefaultHeaders(token);

            BlacklistedTokens = new BlacklistedTokensClient(managementConnection, baseUri, defaultHeaders);
            ClientGrants      = new ClientGrantsClient(managementConnection, baseUri, defaultHeaders);
            Clients           = new ClientsClient(managementConnection, baseUri, defaultHeaders);
            Connections       = new ConnectionsClient(managementConnection, baseUri, defaultHeaders);
            CustomDomains     = new CustomDomainsClient(managementConnection, baseUri, defaultHeaders);
            DeviceCredentials = new DeviceCredentialsClient(managementConnection, baseUri, defaultHeaders);
            EmailProvider     = new EmailProviderClient(managementConnection, baseUri, defaultHeaders);
            EmailTemplates    = new EmailTemplatesClient(managementConnection, baseUri, defaultHeaders);
            Guardian          = new GuardianClient(managementConnection, baseUri, defaultHeaders);
            Jobs            = new JobsClient(managementConnection, baseUri, defaultHeaders);
            Logs            = new LogsClient(managementConnection, baseUri, defaultHeaders);
            ResourceServers = new ResourceServersClient(managementConnection, baseUri, defaultHeaders);
            Roles           = new RolesClient(managementConnection, baseUri, defaultHeaders);
            Rules           = new RulesClient(managementConnection, baseUri, defaultHeaders);
            Stats           = new StatsClient(managementConnection, baseUri, defaultHeaders);
            TenantSettings  = new TenantSettingsClient(managementConnection, baseUri, defaultHeaders);
            Tickets         = new TicketsClient(managementConnection, baseUri, defaultHeaders);
            UserBlocks      = new UserBlocksClient(managementConnection, baseUri, defaultHeaders);
            Users           = new UsersClient(managementConnection, baseUri, defaultHeaders);
        }
Beispiel #11
0
        public async Task QueryLogsWithTimeout()
        {
            #region Snippet:QueryLogsWithTimeout
#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());

            // Query TOP 10 resource groups by event count
            Response <IReadOnlyList <int> > response = await client.QueryAsync <int>(workspaceId,
                                                                                     "AzureActivity | summarize count()",
                                                                                     TimeSpan.FromDays(1),
                                                                                     options : new LogsQueryOptions()
            {
                Timeout = TimeSpan.FromMinutes(10)
            });

            foreach (var resourceGroup in response.Value)
            {
                Console.WriteLine(resourceGroup);
            }

            #endregion
        }
        protected virtual void InitRestClients()
        {
            RestClient = new RestClient(RootUrl + "api/v1/");
            RestClient.AddDefaultHeader("Authentication", ApiKey);
            RestClient.AddDefaultHeader("X-Api-Key", ApiKey);
            RestClient.UseSystemTextJson();

            Commands      = new CommandClient(RestClient, ApiKey);
            Tasks         = new ClientBase <TaskResource>(RestClient, ApiKey, "system/task");
            History       = new ClientBase <HistoryResource>(RestClient, ApiKey);
            HostConfig    = new ClientBase <HostConfigResource>(RestClient, ApiKey, "config/host");
            Indexers      = new IndexerClient(RestClient, ApiKey);
            Logs          = new LogsClient(RestClient, ApiKey);
            Notifications = new NotificationClient(RestClient, ApiKey);

            //Releases = new ReleaseClient(RestClient, ApiKey);
            Tags = new ClientBase <TagResource>(RestClient, ApiKey);
        }
Beispiel #13
0
        public async Task QueryLogsAsTable()
        {
            #region Snippet:QueryLogsAsTable

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";
            Response <LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated");

            LogsQueryResultTable table = response.Value.PrimaryTable;

            foreach (var row in table.Rows)
            {
                Console.WriteLine(row["OperationName"] + " " + row["ResourceGroup"]);
            }

            #endregion
        }
Beispiel #14
0
        public async Task QueryLogsAsModels()
        {
            #region Snippet:QueryLogsAsModels

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";

            // Query TOP 10 resource groups by event count
            Response <IReadOnlyList <MyLogEntryModel> > response = await client.QueryAsync <MyLogEntryModel>(workspaceId,
                                                                                                             "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count");

            foreach (var logEntryModel in response.Value)
            {
                Console.WriteLine($"{logEntryModel.ResourceGroup} had {logEntryModel.Count} events");
            }

            #endregion
        }
Beispiel #15
0
        public async Task QueryLogsAsPrimitive()
        {
            #region Snippet:QueryLogsAsPrimitive

            LogsClient    client      = new LogsClient(new DefaultAzureCredential());
            /*@@*/ string workspaceId = TestEnvironment.WorkspaceId;
            //@@string workspaceId = "<workspace_id>";

            // Query TOP 10 resource groups by event count
            Response <IReadOnlyList <string> > response = await client.QueryAsync <string>(workspaceId,
                                                                                           "AzureActivity | summarize Count = count() by ResourceGroup | top 10 by Count | project ResourceGroup");

            foreach (var resourceGroup in response.Value)
            {
                Console.WriteLine(resourceGroup);
            }

            #endregion
        }
Beispiel #16
0
        public async Task BadRequest()
        {
            #region Snippet:BadRequest
#if SNIPPET
            string workspaceId = "<workspace_id>";
#else
            string workspaceId = TestEnvironment.WorkspaceId;
#endif
            LogsClient client = new LogsClient(new DefaultAzureCredential());
            try
            {
                await client.QueryAsync(workspaceId, "My Not So Valid Query", TimeSpan.FromDays(1));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            #endregion
        }
Beispiel #17
0
        private ManagementApiClient(string token, Uri baseUri, DiagnosticsHeader diagnostics,
                                    ApiConnection apiConnection)
        {
            _apiConnection = apiConnection;

            BlacklistedTokens = new BlacklistedTokensClient(_apiConnection);
            ClientGrants      = new ClientGrantsClient(_apiConnection);
            Clients           = new ClientsClient(_apiConnection);
            Connections       = new ConnectionsClient(_apiConnection);
            DeviceCredentials = new DeviceCredentialsClient(_apiConnection);
            EmailProvider     = new EmailProviderClient(_apiConnection);
            EmailTemplates    = new EmailTemplatesClient(_apiConnection);
            Jobs            = new JobsClient(_apiConnection);
            Logs            = new LogsClient(_apiConnection);
            ResourceServers = new ResourceServersClient(_apiConnection);
            Rules           = new RulesClient(_apiConnection);
            Stats           = new StatsClient(_apiConnection);
            TenantSettings  = new TenantSettingsClient(_apiConnection);
            Tickets         = new TicketsClient(_apiConnection);
            UserBlocks      = new UserBlocksClient(_apiConnection);
            Users           = new UsersClient(_apiConnection);
        }
Beispiel #18
0
        public async Task QueryLogsAsTable()
        {
            #region Snippet:QueryLogsAsTable
#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());
            Response <LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated", TimeSpan.FromDays(1));

            LogsQueryResultTable table = response.Value.PrimaryTable;

            foreach (var row in table.Rows)
            {
                Console.WriteLine(row["OperationName"] + " " + row["ResourceGroup"]);
            }

            #endregion
        }
Beispiel #19
0
        public async Task QueryLogsAsTablePrintAll()
        {
            #region Snippet:QueryLogsPrintTable

#if SNIPPET
            Uri    endpoint    = new Uri("https://api.loganalytics.io");
            string workspaceId = "<workspace_id>";
#else
            Uri    endpoint    = TestEnvironment.LogsEndpoint;
            string workspaceId = TestEnvironment.WorkspaceId;
#endif

            LogsClient client = new LogsClient(endpoint, new DefaultAzureCredential());
            Response <LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated", TimeSpan.FromDays(1));

            LogsQueryResultTable table = response.Value.PrimaryTable;

            foreach (var column in table.Columns)
            {
                Console.Write(column.Name + ";");
            }

            Console.WriteLine();

            var columnCount = table.Columns.Count;
            foreach (var row in table.Rows)
            {
                for (int i = 0; i < columnCount; i++)
                {
                    Console.Write(row[i] + ";");
                }

                Console.WriteLine();
            }

            #endregion
        }
        private ManagementApiClient(ApiConnection apiConnection)
        {
            _apiConnection = apiConnection;

            BlacklistedTokens = new BlacklistedTokensClient(_apiConnection);
            ClientGrants      = new ClientGrantsClient(_apiConnection);
            Clients           = new ClientsClient(_apiConnection);
            Connections       = new ConnectionsClient(_apiConnection);
            CustomDomains     = new CustomDomainsClient(_apiConnection);
            DeviceCredentials = new DeviceCredentialsClient(_apiConnection);
            EmailProvider     = new EmailProviderClient(_apiConnection);
            EmailTemplates    = new EmailTemplatesClient(_apiConnection);
            Guardian          = new GuardianClient(_apiConnection);
            Jobs            = new JobsClient(_apiConnection);
            Logs            = new LogsClient(_apiConnection);
            ResourceServers = new ResourceServersClient(_apiConnection);
            Roles           = new RolesClient(_apiConnection);
            Rules           = new RulesClient(_apiConnection);
            Stats           = new StatsClient(_apiConnection);
            TenantSettings  = new TenantSettingsClient(_apiConnection);
            Tickets         = new TicketsClient(_apiConnection);
            UserBlocks      = new UserBlocksClient(_apiConnection);
            Users           = new UsersClient(_apiConnection);
        }
Beispiel #21
0
 private void Awake()
 {
     PhotonNetwork.AutomaticallySyncScene = true;
     client = new LogsClient("http://localhost:60047/api/");
 }