public void InitiateAPI() { List <JsonFileModel> modelOfJson = new List <JsonFileModel>(); var employeeList = getEmployees(); var deviceList = getDeviceModels(); foreach (var employeeValue in employeeList) { foreach (var deviceModelValue in deviceList) { if (employeeValue.Username == deviceModelValue.AssignedTo && deviceModelValue.Type == "Mobile Phone") { JsonFileModel newEntry = new JsonFileModel(); newEntry.Name = employeeValue.DisplayName; newEntry.UserName = employeeValue.Username; newEntry.MacAddr = deviceModelValue.MacAddrWiFi; newEntry.PhoneNumber = employeeValue.WorkMobile; modelOfJson.Add(newEntry); } } } string jsonModelString = JsonConvert.SerializeObject(modelOfJson.ToArray()); System.IO.File.Delete(@"JSON_structure/employees.txt"); System.IO.File.WriteAllText(@"JSON_structure/employees.txt", jsonModelString); }
private void AssertAttachment(JsonFileModel model, MemberMessageAttachment attachment) { Assert.AreEqual(model.Id, attachment.Id); var fileReference = _filesQuery.GetFileReference(attachment.FileReferenceId); Assert.IsNotNull(fileReference); Assert.AreEqual(model.Name, fileReference.FileName); Assert.AreEqual(model.Size, fileReference.FileData.ContentLength); }
/// <summary> /// データを取得できるか確認する /// </summary> /// <returns></returns> public bool ConfirmGetData() { Users = JsonFileModel.GetUsers(); Departments = JsonFileModel.GetDepartments(); if (Users.Count == EmptyListCount || Departments.Count == EmptyListCount) { ShowErrorDialog(ErrorType.FileNotFound); return(true); } return(false); }
public IActionResult Index(JsonFileModel jsonModel) { _memoryCache.TryGetValue("bookings", out bookings); if (bookings == null) { bookings = new List <Booking>(); } if (ModelState.IsValid) { var file = jsonModel.file; if (file == null || file.Length == 0) { ViewBag.ErrorMessage = "File not found"; return(View(bookings)); } var import = new StringBuilder(); using (var reader = new StreamReader(file.OpenReadStream())) { while (reader.Peek() >= 0) { import.AppendLine(reader.ReadLine()); } } var jsonOption = new JsonSerializerOptions(); jsonOption.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); List <Booking> newBookings = JsonSerializer.Deserialize <List <Booking> >(import.ToString(), jsonOption); foreach (Booking booking in newBookings) { bookings.Add(booking); } _memoryCache.Set("bookings", bookings); ViewBag.Message = "File successfully uploaded"; return(View(newBookings)); } else { ViewBag.ErrorMessage = "ERROR: Es wurde eine falsche Datei ausgewählt."; return(View(bookings)); } }
/// <summary> /// データの保存を始める /// </summary> public void BeginSaveData() { //バックアップ var usersForBackup = JsonFileModel.GetUsers(); if (usersForBackup.Count == EmptyListCount) { ShowErrorDialog(ErrorType.DataCanNotSaveToFile); } //ユーザー情報の保存 if (!JsonFileModel.TrySaveData(Users, JsonFileModel.UsersJsonFilePath)) { ShowErrorDialog(ErrorType.DataCanNotSaveToFile); } //部門情報の保存 if (!JsonFileModel.TrySaveData(Departments, JsonFileModel.DepartmentsJsonFilePath)) { //ユーザー情報を戻す JsonFileModel.TrySaveData(usersForBackup, JsonFileModel.UsersJsonFilePath); ShowErrorDialog(ErrorType.DataCanNotSaveToFile); } }
private static void AssertModel(string expectedFileName, JsonFileModel model) { AssertJsonSuccess(model); Assert.AreEqual(expectedFileName, model.Name); }