示例#1
0
        public async Task <Employee> Get(int id)
        {
            // Set the Accept header.
            _httpClient.DefaultRequestHeaders.Clear();
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_dataFormat));
            string url = @"http://localhost:{_dataWarehousePortNumber}/api/employees/{id}";
            // Make a remote request.
            HttpResponseMessage response = await _httpClient.GetAsync(url);

            // Read response body and deserialize it.
            string body = await response.Content.ReadAsStringAsync();

            if (_dataFormat == "application/xml")
            {
                // Validate XML document.
                ValidateXmlSchema(body);
                // Deserialize XML document.
                Employee employee = await UtilityXml.DeserializeXmlAsync <Employee>(body);

                return(employee);
            }

            if (_dataFormat == "application/json")
            {
                Employee employee = await UtilityJson.DeserializeJsonAsync <Employee>(body);

                return(employee);
            }

            return(null);
        }
示例#2
0
        public static AuthBitflyer createAuthBitflyer(string filePath)
        {
            AuthBitflyer result = null;

            try
            {
                if (filePath == null || filePath.Length <= 0)
                {
                    result = null;
                    return(result);
                }

                AuthBitflyer auth = null;
                if (UtilityJson.loadFromJson <AuthBitflyer>(out auth, filePath) != 0)
                {
                    result = null;
                    return(result);
                }

                result = auth;
            }
            catch (Exception ex)
            {
                Console.WriteLine("exception: {0}", ex.Message);
                result = null;
            }
            finally
            {
            }
            return(result);
        }
        public async Task <List <Employee> > Get(int offset, int limit)
        {
            // Set the Accept header.
            _httpClient.DefaultRequestHeaders.Clear();
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_dataFormat));
            string url = @"http://localhost:" + _dataWarehousePortNumber + "/api/employees/?offset= " + offset + "&limit= " + limit;
            // Make a remote request.
            HttpResponseMessage response = await _httpClient.GetAsync(url);

            // Read response body and deserialize it.
            string body = await response.Content.ReadAsStringAsync();

            if (_dataFormat == "application/xml")
            {
                // Validate XML document.
                ValidateXmlSchema(body);
                // Deserialize XML document.
                Employee[] employees = await UtilityXml.DeserializeXmlAsync <Employee[]>(body);

                return(employees.ToList());
            }

            if (_dataFormat == "application/json")
            {
                Employee[] employees = await UtilityJson.DeserializeJsonAsync <Employee[]>(body);

                return(employees.ToList());
            }

            // Return empty list.
            return(new List <Employee>());
        }
示例#4
0
        public static int saveBoxerConfig(BoxerConfig config, string dirPath, string fileName)
        {
            int result = 0;

            try
            {
                if (dirPath == null || dirPath.Length <= 0)
                {
                    result = -1;
                    return(result);
                }

                if (fileName == null || fileName.Length <= 0)
                {
                    result = -1;
                    return(result);
                }

                if (UtilityJson.saveToJson <BoxerConfig>(config, dirPath, fileName) != 0)
                {
                    result = -1;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("exception: {0}", ex.Message);
                result = -1;
            }
            finally
            {
            }
            return(result);
        }
示例#5
0
        public static BoxerConfig loadBoxerConfig(string filePath)
        {
            BoxerConfig result = null;

            try
            {
                if (filePath == null || filePath.Length <= 0)
                {
                    result = null;
                    return(result);
                }

                BoxerConfig config = null;
                if (UtilityJson.loadFromJson <BoxerConfig>(out config, filePath) != 0)
                {
                    result = null;
                    return(result);
                }

                result = config;
            }
            catch (Exception ex)
            {
                Console.WriteLine("exception: {0}", ex.Message);
                result = null;
            }
            finally
            {
            }
            return(result);
        }
示例#6
0
        private void UpdateEmployee(HttpListenerRequest request, HttpListenerResponse response)
        {
            // Deserialize Employee object.
            string body = String.Empty;

            using (StreamReader reader = new StreamReader(request.InputStream))
            {
                body = reader.ReadToEnd();
            }

            Employee employee = null;

            try
            {
                if (_dataFormat == "application/xml")
                {
                    employee = UtilityXml.DeserializeXml <Employee>(body);
                }
                else if (_dataFormat == "application/json")
                {
                    employee = UtilityJson.DeserializeJson <Employee>(body);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(@"ERROR: Failed to deserialize the Employee object - {ex.Message}");
            }

            if (employee == null)
            {
                response.StatusCode = 400;
                response.Close();
                return;
            }

            // Perform the actual update.
            _repository.Update(employee);

            // Construct and send the response.
            response.StatusCode = 200;
            response.Close();

            Console.WriteLine(@"POST: Updated employee with ID {employee.EmployeeId}");
        }