示例#1
0
        public async Task <byte[]> DownloadFileVersion(string projectId, string languageFileId, int version)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    var request = new HttpRequestMessage(HttpMethod.Get, new Uri(ApiUrl.DownloadFileVersion(projectId, languageFileId, version)));
                    ApiUrl.AddRequestHeaders(httpClient, request);

                    var responseMessage = await httpClient.SendAsync(request);

                    var fileResponse = await responseMessage.Content.ReadAsByteArrayAsync();

                    if (responseMessage.StatusCode == HttpStatusCode.OK)
                    {
                        return(fileResponse);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Logger.Error($"DownloadFileVersion service method: {e.Message}\n {e.StackTrace}");
            }
            return(new byte[0]);
        }
示例#2
0
        public async Task <List <GsFileVersion> > GetFileVersion(string languageFileId)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    var request = new HttpRequestMessage(HttpMethod.Get, new Uri(ApiUrl.GetFileVersions(languageFileId)));
                    ApiUrl.AddRequestHeaders(httpClient, request);

                    var responseMessage = await httpClient.SendAsync(request);

                    var filesResponse = await responseMessage.Content.ReadAsStringAsync();

                    if (responseMessage.StatusCode == HttpStatusCode.OK)
                    {
                        return(JsonConvert.DeserializeObject <List <GsFileVersion> >(filesResponse));
                    }
                }
            }
            catch (Exception e)
            {
                Log.Logger.Error($"GetFileVersion service method: {e.Message}\n {e.StackTrace}");
            }
            return(new List <GsFileVersion>());
        }
示例#3
0
        public async Task <ProjectResponse> GetGsProjects(ProjectFilter projectFilter)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    var queryString = ApiUrl.GetQuerryString(projectFilter);
                    var request     = new HttpRequestMessage(HttpMethod.Get, new Uri(queryString));
                    ApiUrl.AddRequestHeaders(httpClient, request);

                    var responseMessage = await httpClient.SendAsync(request);

                    var projectsResponse = await responseMessage.Content.ReadAsStringAsync();

                    if (responseMessage.StatusCode == HttpStatusCode.OK)
                    {
                        return(JsonConvert.DeserializeObject <ProjectResponse>(projectsResponse));
                    }
                }
            }
            catch (Exception e)
            {
                Log.Logger.Error($"GetGsProjects service method: {e.Message}\n {e.StackTrace}");
            }
            return(new ProjectResponse());
        }
示例#4
0
        public async Task <List <GsFile> > GetProjectFiles(string projectId)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    var request = new HttpRequestMessage(HttpMethod.Get, new Uri(ApiUrl.GetProjectFiles(projectId)));
                    ApiUrl.AddRequestHeaders(httpClient, request);

                    var responseMessage = await httpClient.SendAsync(request);

                    var filesResponse = await responseMessage.Content.ReadAsStringAsync();

                    if (responseMessage.StatusCode == HttpStatusCode.OK)
                    {
                        return(JsonConvert.DeserializeObject <List <GsFile> >(filesResponse));
                    }
                }
            }
            catch (Exception e)
            {
                // here we'll add loging
            }
            return(new List <GsFile>());
        }
示例#5
0
        public async Task <byte[]> DownloadFileVersion(string projectId, string languageFileId, int version)
        {
            using (var httpClient = new HttpClient())
            {
                var request = new HttpRequestMessage(HttpMethod.Get, new Uri(ApiUrl.DownloadFileVersion(projectId, languageFileId, version)));
                ApiUrl.AddRequestHeaders(httpClient, request);

                var responseMessage = await httpClient.SendAsync(request);

                var fileResponse = await responseMessage.Content.ReadAsByteArrayAsync();

                if (responseMessage.StatusCode == HttpStatusCode.OK)
                {
                    return(fileResponse);
                }
                throw new Exception(responseMessage.StatusCode.ToString());
            }
        }