Ejemplo n.º 1
0
        public async Task <ServerApiClient> Open()
        {
            _apiClient = await CreateApiClient();

            _reporter = CreateReporter(ApplicationId);
            return(_apiClient);
        }
Ejemplo n.º 2
0
        public static async Task <bool> CheckIfReportExists(this ServerApiClient client, int applicationId,
                                                            string genericMessage, string reportDetails)
        {
            var report = await client.FindReport(applicationId, reportDetails);

            return(report != null);
        }
Ejemplo n.º 3
0
        public static async Task <GetReportResult> FindReport(this ServerApiClient client, int incidentId,
                                                              string partOfErrorMessage, Func <GetReportResult, bool> filter = null)
        {
            var reportListItem = await client.GetReportListItem(incidentId, partOfErrorMessage);

            if (reportListItem == null)
            {
                throw new InvalidOperationException("Failed to find our uploaded report");
            }

            GetReportResult result = null;

            await Repeat(async() =>
            {
                var query3 = new GetReport(reportListItem.Id);
                result     = await client.QueryAsync(query3);
                if (result == null)
                {
                    return(false);
                }

                if (filter != null && filter(result))
                {
                    return(true);
                }

                return(result.ContextCollections.Any());
            });

            if (result != null)
            {
                Console.WriteLine($"Got report {result.CreatedAtUtc:yyyyMMdd hh:mm:ss.fff}");
            }
            return(result);
        }
Ejemplo n.º 4
0
        private static async Task <int?> GetIncidentId(this ServerApiClient client, int applicationId,
                                                       string incidentMessage, string reportMessage = null)
        {
            int?returnValue = null;

            await Repeat(async() =>
            {
                var query = new FindIncidents
                {
                    ApplicationIds = new[] { applicationId },
                    FreeText       = incidentMessage,
                    SortType       = IncidentOrder.Newest
                };
                var result = await client.QueryAsync(query);
                if (result.Items.Count <= 0)
                {
                    return(false);
                }

                if (reportMessage == null)
                {
                    returnValue = result.Items[0].Id;
                    return(true);
                }

                var item = result.Items.FirstOrDefault(x => x.Name.Contains(reportMessage));
                if (item != null)
                {
                    var query2  = new GetReportList(item.Id);
                    var result2 = await client.QueryAsync(query2);
                    var report  = result2.Items.FirstOrDefault(x => x.Message.Contains(reportMessage));
                    if (report != null)
                    {
                        returnValue = item.Id;
                        return(true);
                    }
                }

                foreach (var resultItem in result.Items)
                {
                    var query2  = new GetReportList(resultItem.Id);
                    var result2 = await client.QueryAsync(query2);
                    var report  = result2.Items.FirstOrDefault(x => x.Message.Contains(reportMessage));
                    if (report != null)
                    {
                        returnValue = resultItem.Id;
                        return(true);
                    }
                }

                return(false);
            });

            return(returnValue);
        }
Ejemplo n.º 5
0
        private async Task <ServerApiClient> CreateApiClient()
        {
            SqlTools.GetApiKey(_dbName, out var apiKey, out var apiSecret);
            var apiClient = new ServerApiClient();

            apiClient.Open(new Uri(_serverAddress), apiKey, apiSecret);
            ApplicationId = await apiClient.EnsureApplication("ForTests");

            await apiClient.Reset(ApplicationId, "IntegrationTests");

            return(apiClient);
        }
Ejemplo n.º 6
0
        private void CheckUpdate()
        {
            var version = Assembly.GetExecutingAssembly().GetName().Version;
            var api     = new ServerApiClient(new CommonRequestParams());

            var updateInfo = api.App.CheckUpdate(version);

            if (updateInfo == null)
            {
                return;
            }
            string link = updateInfo.Link;

            DownloadAndUnrarUpdate(link);
        }
Ejemplo n.º 7
0
        public static async Task <int> Reset(this ServerApiClient client, int applicationId, string environmentName)
        {
            var envs   = new GetEnvironments();
            var result = await client.QueryAsync(envs);

            var id = result.Items.FirstOrDefault(x => x.Name == environmentName)?.Id;

            // haven't reported for that environment yet
            if (id == null)
            {
                return(id ?? 0);
            }

            var cmd = new ResetEnvironment(applicationId, id.Value);
            await client.SendAsync(cmd);

            return(id ?? 0);
        }
Ejemplo n.º 8
0
        //[Fact]
        public async Task Test()
        {
            var client = new ServerApiClient();

            client.Open(new Uri("http://localhost/coderr/"), "", "");
            FindAccountByUserNameResult result = null;

            try
            {
                result = await client.QueryAsync(new FindAccountByUserName("admin"));
            }
            catch (WebException)
            {
            }


            result.Should().NotBeNull();
        }
Ejemplo n.º 9
0
        public static async Task <GetIncidentResult> GetIncident(this ServerApiClient client, int applicationId,
                                                                 string incidentMessage, string reportMessage = null)
        {
            var id = await client.GetIncidentId(applicationId, incidentMessage, reportMessage);

            if (id == null)
            {
                throw new InvalidOperationException("Failed to find our uploaded report");
            }


            var query  = new GetIncident(id.Value);
            var result = await client.QueryAsync(query);

            if (result != null)
            {
                Console.WriteLine($"Got incident {result.CreatedAtUtc:yyyyMMdd hh:mm:ss.fff}");
            }

            return(result);
        }
Ejemplo n.º 10
0
        public static async Task <GetReportListResultItem> GetReportListItem(this ServerApiClient client, int incidentId,
                                                                             string partOfErrorMessage)
        {
            var attempt = 0;

            while (attempt++ < 6)
            {
                var query2  = new GetReportList(incidentId);
                var result2 = await client.QueryAsync(query2);

                var report = result2.Items.FirstOrDefault(x => x.Message.Contains(partOfErrorMessage));
                if (report != null)
                {
                    return(report);
                }


                await Task.Delay(attempt * 150);
            }

            return(null);
        }
Ejemplo n.º 11
0
        private static async Task <TResult> TryQuery <TQuery, TResult>(this ServerApiClient client, TQuery query)
            where TQuery : Query <TResult>
        {
            var attempt = 0;

            while (attempt++ < 6)
            {
                var result = await client.QueryAsync(query);

                if (result != null)
                {
                    var collection = (IList)result.GetType().GetProperty("Items")?.GetValue(result);
                    if (collection != null)
                    {
                        if (collection.Count > 0)
                        {
                            return(result);
                        }
                    }

                    var prop = result.GetType().GetProperties()
                               .FirstOrDefault(x => x.PropertyType.GetProperty("Count") != null);
                    if (prop != null)
                    {
                        var collection2 = prop.GetValue(result);
                        var value       = (int)collection2.GetType().GetProperty("Count").GetValue(collection2);
                        if (value > 0)
                        {
                            return(result);
                        }
                    }
                }

                await Task.Delay(attempt * 150);
            }

            return(default);
Ejemplo n.º 12
0
        public static async Task <int> EnsureApplication(this ServerApiClient client, string name)
        {
            var query  = new GetApplicationList();
            var result = await client.QueryAsync(query);

            var app = result.FirstOrDefault(x => x.Name == name);

            if (app != null)
            {
                return(app.Id);
            }

            var cmd = new CreateApplication(name, TypeOfApplication.DesktopApplication)
            {
                ApplicationKey = Guid.NewGuid().ToString("N"),
                UserId         = 1
            };
            await client.SendAsync(cmd);

            var query2      = new GetApplicationIdByKey(cmd.ApplicationKey);
            var retriesLeft = 3;

            while (retriesLeft-- > 0)
            {
                var app2 = await client.QueryAsync(query2);

                if (app2 != null)
                {
                    return(app2.Id);
                }

                await Task.Delay(500);
            }

            throw new TestFailedException("Could not create application.");
        }
Ejemplo n.º 13
0
 public EnvironmentTests(ApplicationClient applicationClient, ServerApiClient apiClient)
 {
     _applicationClient = applicationClient;
     _apiClient         = apiClient;
 }
Ejemplo n.º 14
0
 public UserReportTests(ApplicationClient applicationClient, ServerApiClient apiClient)
 {
     _applicationClient = applicationClient;
     _apiClient         = apiClient;
 }
Ejemplo n.º 15
0
 public NoticeCategory(ServerApiClient apiClient)
 {
     _apiClient = apiClient;
 }
Ejemplo n.º 16
0
 public AuthCategory(ServerApiClient serverApi)
 {
     _serverApi = serverApi;
 }
Ejemplo n.º 17
0
 public DataCategory(ServerApiClient apiClient)
 {
     _apiClient = apiClient;
 }
Ejemplo n.º 18
0
 public async Task Prepare()
 {
     _apiClient = await _client.Open();
 }
Ejemplo n.º 19
0
 public AppCategory(ServerApiClient apiClient)
 {
     _apiClient = apiClient;
 }
Ejemplo n.º 20
0
 public WhitelistTests(ApplicationClient applicationClient, ServerApiClient apiClient)
 {
     _applicationClient = applicationClient;
     _apiClient         = apiClient;
 }
Ejemplo n.º 21
0
 public IncidentWrapper(ServerApiClient apiClient, Reporter reporter, int applicationId)
 {
     _apiClient     = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
     _reporter      = reporter ?? throw new ArgumentNullException(nameof(reporter));
     _applicationId = applicationId;
 }