Esempio n. 1
0
        private async Task <List <T> > ReadTextAsync <T>(string filePath) where T : class
        {
            try
            {
                JsonEngine jengine = new JsonEngine();

                using (FileStream sourceStream = new FileStream(filePath,
                                                                FileMode.Open, FileAccess.Read, FileShare.Read,
                                                                bufferSize: 4096, useAsync: true))
                {
                    StringBuilder sb = new StringBuilder();

                    byte[] buffer = new byte[0x1000];
                    int    numRead;
                    while ((numRead = await sourceStream.ReadAsync(buffer, 0, buffer.Length)) != 0)
                    {
                        string text = Encoding.ASCII.GetString(buffer, 0, numRead);
                        sb.Append(text);
                    }

                    var listback = jengine.ConvertFromJson <T>(sb.ToString());

                    return(listback);
                }
            }
            catch (Exception ex) {
                throw ex;
            }
        }
        public List <EmployeeDTO> GetEmployeeById(int?Id)
        {
            JsonEngine         objEngine       = new JsonEngine("http://masglobaltestapi.azurewebsites.net/api/Employees", 60000);
            List <EmployeeDTO> objEmployeeList = objEngine.ExecuteGetOperation <List <EmployeeDTO> >();

            return(objEmployeeList.Where(employee => Id == null || employee.Id == Id).ToList());
        }
Esempio n. 3
0
 public static TagCompound FromJson(string json, JsonEngine jsonEngine = JsonEngine.Accurate)
 {
     if (jsonEngine == JsonEngine.Fuzzy)
     {
         return(NBTJsonSerializerFizzy.FromJson(json) as TagCompound);
     }
     return(NBTJsonSerializer.FromJson(json) as TagCompound);
 }
        public IEnumerable <Employee> GetEmployeeInfo(Employee emp)
        {
            JsonEngine objEngine = new JsonEngine("https://wscalculatedannualsalary.azurewebsites.net/api/Employee/GetEmployees/", 60000);

            List <Employee> objEmployeeList = objEngine.ExecutePostOperation <List <Employee> >(emp);

            if (objEmployeeList.Count() == 0)
            {
                ModelState.AddModelError(string.Empty, "No data found.");
            }

            return(objEmployeeList);
        }
Esempio n. 5
0
        private void Button2_Click(object sender, EventArgs e)
        {
            JsonEngine jengine = new JsonEngine();

            var str = jengine.ConvertFromList <BussinessTypesJson>(
                new List <BussinessTypesJson>()
            {
                new BussinessTypesJson()
                {
                    Id = 1, Name = "Business - 1-19 Employees", Description = "Business - 1-19 Employees"
                },
                new BussinessTypesJson()
                {
                    Id = 1, Name = "Business - 20-249 Employees", Description = "Business - 20-249 Employees"
                },
                new BussinessTypesJson()
                {
                    Id = 1, Name = "Business - 250-499 Employees", Description = "Business - 250-499 Employees"
                }
            });

            File.WriteAllText("BussinessTypesJson.json", str);

            var str2 = jengine.ConvertFromList <DistrictJson>(
                new List <DistrictJson>()
            {
                new DistrictJson()
                {
                    Id = 1, DName = "Ampara"
                },
                new DistrictJson()
                {
                    Id = 2, DName = "Anuradhapura"
                },
                new DistrictJson()
                {
                    Id = 3, DName = "Badulla"
                },
                new DistrictJson()
                {
                    Id = 4, DName = "Batticaloa"
                },
                new DistrictJson()
                {
                    Id = 5, DName = "Colombo"
                },
                new DistrictJson()
                {
                    Id = 6, DName = "Galle"
                },
                new DistrictJson()
                {
                    Id = 7, DName = "Gampaha"
                },
                new DistrictJson()
                {
                    Id = 8, DName = "Hambantota"
                },
                new DistrictJson()
                {
                    Id = 9, DName = "Jaffna"
                },
                new DistrictJson()
                {
                    Id = 10, DName = "Kalutara"
                },
                new DistrictJson()
                {
                    Id = 11, DName = "Kandy"
                },
                new DistrictJson()
                {
                    Id = 12, DName = "Kegalle"
                },
                new DistrictJson()
                {
                    Id = 13, DName = "Kilinochchi"
                },
                new DistrictJson()
                {
                    Id = 14, DName = "Kurunegala"
                },
                new DistrictJson()
                {
                    Id = 15, DName = "Mannar"
                },
                new DistrictJson()
                {
                    Id = 16, DName = "Matara"
                },
                new DistrictJson()
                {
                    Id = 17, DName = "Moneragala"
                },
                new DistrictJson()
                {
                    Id = 18, DName = "Nuwara Eliya"
                },
                new DistrictJson()
                {
                    Id = 19, DName = "Polonnaruwa"
                },
                new DistrictJson()
                {
                    Id = 20, DName = "Puttalam"
                },
                new DistrictJson()
                {
                    Id = 21, DName = "Ratnapura"
                },
                new DistrictJson()
                {
                    Id = 22, DName = "Trincomalee"
                },
                new DistrictJson()
                {
                    Id = 23, DName = "Vavuniya"
                }
            });

            File.WriteAllText("DistrictJson.json", str2);
        }
 public RaceImportWorker(JsonEngine jsonEngine, XmlEngine xmlEngine, IOutputService outputService)
 {
     _jsonEngine    = jsonEngine;
     _xmlEngine     = xmlEngine;
     _outputService = outputService;
 }