public ApiResponse AddContainer(AddContainerRequest request) { ApiResponse response = new ApiResponse(); if (inventoryManager.InventoryNameIsNotUnique(request.Inventory.InventoryName)) { response.AddMessage("InventoryName", new List <string>() { "This inventory name is in use. Please choose another." }); } else if (inventoryManager.ContainerNameIsNotUnique(request.Container.ContainerName)) { response.AddMessage("ContainerName", new List <string>() { "This container name is in use. Please choose another." }); } else { response.Id = inventoryManager.AddContainer(request); if (response.Id == 0) { response.AddMessage("DbError", new List <string>() { "There was an error saving this container." }); } } return(response); }
protected override void HandleCanHaveContainerResponce(CanHaveContainerResponce message) { if (message.Bid.AuctionId != inOrderProping.InstanceId) { throw new NotImplementedException("How come"); } if (message.Bid.Valid) { AddContainerRequest request = new AddContainerRequest(message.SenderId, 0, CurrentContainer); CommunicationModule.SendMessage(request); CurrentContainer = null; inOrderProping = null; } else { if (inOrderProping.OpenSession) { TestHostForAContainer(); } else { FailedScheduling(); } } }
private void HanleAddContainerRequest(AddContainerRequest addContainerRequest) { Task t = new Task(async() => { var table = ContainerTable as DockerContainerTable; var dockerCon = addContainerRequest.NewContainer as DockerContainer; await table.LoadImage(dockerCon.ImageId); ContainerTable.AddContainer(addContainerRequest.NewContainer.ContainerId, addContainerRequest.NewContainer); }); t.Start(); }
protected override void HandleCanHaveContainerResponce(CanHaveContainerResponce message) { if (message.Bid.AuctionId != auction.InstanceId) { throw new NotImplementedException("How come"); } auction.AddBid(message.Bid); if (!auction.OpenSession) { var winner = auction.GetWinnerBid(); if (winner == null) { FailedScheduling(); } else { AddContainerRequest request = new AddContainerRequest(message.SenderId, 0, CurrentContainer); CommunicationModule.SendMessage(request); CurrentContainer = null; auction = null; } } }
public async Task AddContainerAsync(AddContainerRequest container) { if (container is null) { throw new Exception(); } try { var result = await _context.Containers.AddAsync(new ContainerEntity { ContainerId = container.ContainerId, Size = container.Size }); if (result.State == EntityState.Added) { _context.SaveChanges(); } } catch (Exception e) { throw; } }
public long AddContainer(AddContainerRequest containerRequest) { return(persistence.AddContainer(containerRequest)); }
public void AddContainer() { long image_id = 0; string jsonData = String.Empty; try { AddContainerRequest addContainerRequest = new AddContainerRequest(); //save image if the user has selected one if (fileStreamContent != null) { var url = "http://localhost:9000/api/Login/UploadPlantImage"; fileStreamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") { Name = "file", FileName = fileName }; fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"); using (var client1 = new HttpClient()) { using (var formData = new MultipartFormDataContent()) { client1.DefaultRequestHeaders.Add("EO-Header", wnd.User + " : " + wnd.Pwd); formData.Add(fileStreamContent); var response = client1.PostAsync(url, formData).Result; string strImageId = response.Content.ReadAsStringAsync().Result; Int64.TryParse(strImageId, out image_id); } } } KeyValuePair <long, string> containerName = (KeyValuePair <long, string>) this.ContainerNames.SelectedValue; KeyValuePair <long, string> containerType = (KeyValuePair <long, string>) this.ContainerTypes.SelectedValue; //KeyValuePair<long, string> serviceCode = (KeyValuePair<long, string>)this.ServiceCodes.SelectedValue; ContainerDTO cDTO = new ContainerDTO(); cDTO.ContainerName = containerName.Value; cDTO.ContainerTypeId = containerType.Key; cDTO.ContainerTypeName = containerType.Value; addContainerRequest.Container = cDTO; InventoryDTO iDTO = new InventoryDTO(); iDTO.InventoryName = containerName.Value; iDTO.InventoryTypeId = 2; //"Containers" //iDTO.ServiceCodeId = serviceCode.Key; addContainerRequest.Container = cDTO; addContainerRequest.Inventory = iDTO; if (image_id > 0) { addContainerRequest.ImageId = image_id; } HttpClient client = new HttpClient(); client.BaseAddress = new Uri(((App)App.Current).LAN_Address); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Add("EO-Header", wnd.User + " : " + wnd.Pwd); jsonData = JsonConvert.SerializeObject(addContainerRequest); var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpResponseMessage httpResponse = client.PostAsync("api/Login/AddContainer", content).Result; if (httpResponse.IsSuccessStatusCode) { Stream streamData = httpResponse.Content.ReadAsStreamAsync().Result; StreamReader strReader = new StreamReader(streamData); string strData = strReader.ReadToEnd(); strReader.Close(); GetContainerResponse apiResponse = JsonConvert.DeserializeObject <GetContainerResponse>(strData); if (apiResponse.Messages.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, List <string> > messages in apiResponse.Messages) { foreach (string msg in messages.Value) { sb.AppendLine(msg); } } MessageBox.Show(sb.ToString()); } else { foreach (ContainerInventoryDTO c in apiResponse.ContainerInventoryList) { list3.Add(c); } this.ContainerListView.ItemsSource = null; this.ContainerListView.ItemsSource = list3; } } else { MessageBox.Show(Application.Current.MainWindow, "Error adding container", "Error", MessageBoxButton.OK); } } catch (Exception ex) { Exception ex2 = new Exception("Admin - AddContainer", ex); ((App)App.Current).LogError(ex2.Message, jsonData); } }