public async Task <IActionResult> CompleteCode([FromBody] TimeDevice timeDevice) //TODO: Complete & Fix. { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Code latest = await GetLatestCode(timeDevice.deviceId, false); if (latest == null) { return(NotFound()); } await _repository.CompleteAsync(latest, timeDevice.dateTime); await _hubContext.Clients.Group(GetUserName()).InvokeAsync("codeDone", latest.Device.Name, string.IsNullOrWhiteSpace(latest.ActionName) ? latest.Action.ToString() : latest.ActionName); return(Ok()); }
/// <summary> /// Добавление элемента в коллекцию доступных устройств. /// При этом устройству назначается новый идентификатор. /// </summary> /// <param name="Item">Устройство.</param> public void Add(TimeDevice Item) { items.Add((TimeDevice)Item.Clone()); }
private void button3_Click(object sender, EventArgs e) { string FailMessage = ""; string Name = textBox1.Text; if (Name.Length == 0) { FailMessage = "Необходимо указать название станка!"; goto fail_exit; } if (itemId == -1) { if (devType == BaseDeviceType.Saw ? conf.Saws.GetIndexByText(Name) != -1 : conf.Grinders.GetIndexByText(Name) != -1) { FailMessage = "Станок с таким названием уже существует!"; goto fail_exit; } } if (textBox4.Text.Length == 0) { FailMessage = "Необходимо задать переодичность технического обслуживания!"; goto fail_exit; } int ServiceTimePeriod = -1; try { ServiceTimePeriod = Convert.ToInt32(textBox4.Text); } catch (Exception ex) { FailMessage = "Период обслуживания: " + ex.Message; goto fail_exit; } if (textBox4.Text.Length == 0) { FailMessage = "Необходимо задать время технического обслуживания!"; goto fail_exit; } int ServiceTime = -1; try { ServiceTime = Convert.ToInt32(textBox5.Text); } catch (Exception ex) { FailMessage = "Время технического обслуживания: " + ex.Message; goto fail_exit; } if (itemId == -1) { DeviceList GoalList = devType == BaseDeviceType.Saw ? conf.Saws : conf.Grinders; TimeDevice NewDevice = new TimeDevice(GoalList.GetFreeId(), Name, textBox2.Text); NewDevice.SupportedMaterials = mpl; NewDevice.ServiceTimePeriod = ServiceTimePeriod; NewDevice.ServiceTime = ServiceTime; NewDevice.DefaultMaterialId = DefaultMaterialId; GoalList.Add(NewDevice); } else { DeviceList GoalList = devType == BaseDeviceType.Saw ? conf.Saws : conf.Grinders; int DeviceIndex = GoalList.GetIndexById(itemId); GoalList[DeviceIndex].Text = Name; GoalList[DeviceIndex].Responsible = textBox2.Text; GoalList[DeviceIndex].SupportedMaterials = mpl; GoalList[DeviceIndex].ServiceTimePeriod = ServiceTimePeriod; GoalList[DeviceIndex].ServiceTime = ServiceTime; GoalList[DeviceIndex].DefaultMaterialId = DefaultMaterialId; } this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); return; fail_exit: MessageBox.Show(this, FailMessage, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }
/// <summary> /// Считывает доступные устройства. /// </summary> /// <param name="XMLDeviceLists">Список узлов, соответствующих тегу "Devices", содержащих информацию о доступных устройствах.</param> private void LoadDevices(XmlNodeList XMLDeviceLists) { // // Да. Конечно, наблюдательный программист заметит, // что информация по пилам и станкам однинакова и дублировать // код бессмысленно. Для этого я хочу оставить своё замечание. // В перспективе, программа может здорово расшириться и учитывать гораздо больше // ньюансов, чем в данный момент, поэтому и код чтения может измениться как в общем // так и отдельно. Если Вы всё же решите изменить код, то меняйте на здоровье, но // учитывайте мой посыл. // // очищаем списки saws.Clear(); grinders.Clear(); foreach (XmlNode Dev in XMLDeviceLists) { XmlNodeList DeviceDescription = Dev.ChildNodes; foreach (XmlNode item in DeviceDescription) { // проверяем узел на возможность обработки if (item.Name == "Saw") { // получаем идентификатор XmlNode XMLItemAttribute = item.Attributes["id"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Saw\" не содержит обязательный атрибут \"id\""); int ItemId = -1; try { ItemId = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"id\": " + ex.Message); } // считываем имя пилы XMLItemAttribute = item.Attributes["Name"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Saw\" не содержит обязательный атрибут \"Name\""); string DeviceName = XMLItemAttribute.Value; // считываем ответственного человека XMLItemAttribute = item.Attributes["Responsible"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Saw\" не содержит обязательный атрибут \"Responsible\""); string Responsible = XMLItemAttribute.Value; // считываем период технического обслуживания XMLItemAttribute = item.Attributes["ServicePeriod"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Saw\" не содержит обязательный атрибут \"ServicePeriod\""); int ServiceTimePeriod = -1; try { ServiceTimePeriod = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"ServicePeriod\": " + ex.Message); } // считываем время технического обслуживания XMLItemAttribute = item.Attributes["ServiceTime"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Saw\" не содержит обязательный атрибут \"ServiceTime\""); int ServiceTime = -1; try { ServiceTime = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"ServiceTime\": " + ex.Message); } // считываем настройку пилы по умолчанию XMLItemAttribute = item.Attributes["DefaultMaterialId"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Saw\" не содержит обязательный атрибут \"DefaultMaterialId\""); int DefaultMaterialId = -1; try { DefaultMaterialId = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"DefaultMaterialId\": " + ex.Message); } TimeDevice NewTimeDevice = new TimeDevice(ItemId, DeviceName, Responsible); NewTimeDevice.ServiceTimePeriod = ServiceTimePeriod; NewTimeDevice.ServiceTime = ServiceTime; // считываем материалы, которые способна обрабатывать пила XmlNodeList SupportedMaterials = item.ChildNodes; if (SupportedMaterials != null) { foreach (XmlNode SupportedMaterial in SupportedMaterials) { if (SupportedMaterial.Name != "SupportedMaterial") throw new Exception("Не поддерживаемый дочерний узел: \"" + item.Name + "\" для узла Saw. Единственный допустимый тег: \"SupportedMaterial\""); XMLItemAttribute = SupportedMaterial.Attributes["MaterialId"]; if (XMLItemAttribute == null) throw new Exception("Узел \"SupportedMaterial\" не содержит обязательный атрибут \"MaterialId\""); int MaterialId = -1; try { MaterialId = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"MaterialId\": " + ex.Message); } // уникальный идентификатор материала int MaterialIndex = materials.GetIndexById(MaterialId); if (MaterialIndex == -1) throw new Exception("\"" + XMLItemAttribute.Value + "\": описание материала не найдено!"); XmlNode XMLMaterialConfTime = SupportedMaterial.Attributes["ConfTime"]; if (XMLMaterialConfTime == null) throw new Exception("Узел \"SupportedMaterial\" не содержит обязательный атрибут \"ConfTime\""); // время на настройку пилы под этот материал int ConfTime = 0; try { ConfTime = Convert.ToInt32(XMLMaterialConfTime.Value); } catch (Exception ex) { throw new Exception("Атрибут \"ConfTime\": " + ex.Message); } NewTimeDevice.AddMaterial(new MaterialPair(MaterialId, ConfTime)); } } NewTimeDevice.DefaultMaterialId = DefaultMaterialId; saws.Add(NewTimeDevice); } else if (item.Name == "Grinder") { // получаем идентификатор XmlNode XMLItemAttribute = item.Attributes["id"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Grinder\" не содержит обязательный атрибут \"id\""); int ItemId = -1; try { ItemId = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"id\": " + ex.Message); } // добавление шлифовального станка XMLItemAttribute = item.Attributes["Name"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Grinder\" не содержит обязательный атрибут \"Name\""); string DeviceName = XMLItemAttribute.Value; // считываем ответственного человека XMLItemAttribute = item.Attributes["Responsible"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Grinder\" не содержит обязательный атрибут \"Responsible\""); string Responsible = XMLItemAttribute.Value; // считываем период технического обслуживания XMLItemAttribute = item.Attributes["ServicePeriod"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Grinder\" не содержит обязательный атрибут \"ServicePeriod\""); int ServiceTimePeriod = -1; try { ServiceTimePeriod = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"ServicePeriod\": " + ex.Message); } // считываем время технического обслуживания XMLItemAttribute = item.Attributes["ServiceTime"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Grinder\" не содержит обязательный атрибут \"ServiceTime\""); int ServiceTime = -1; try { ServiceTime = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"ServiceTime\": " + ex.Message); } // считываем настройку пилы по умолчанию XMLItemAttribute = item.Attributes["DefaultMaterialId"]; if (XMLItemAttribute == null) throw new Exception("Узел \"Grinder\" не содержит обязательный атрибут \"DefaultMaterialId\""); int DefaultMaterialId = -1; try { DefaultMaterialId = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"DefaultMaterialId\": " + ex.Message); } TimeDevice NewTimeDevice = new TimeDevice(ItemId, DeviceName, Responsible); NewTimeDevice.ServiceTimePeriod = ServiceTimePeriod; NewTimeDevice.ServiceTime = ServiceTime; // считываем материалы, которые способна обрабатывать пила XmlNodeList SupportedMaterials = item.ChildNodes; if (SupportedMaterials != null) { foreach (XmlNode SupportedMaterial in SupportedMaterials) { if (SupportedMaterial.Name != "SupportedMaterial") throw new Exception("Не поддерживаемый дочерний узел: \"" + item.Name + "\" для узла Saw. Единственный допустимый тег: \"SupportedMaterial\""); XMLItemAttribute = SupportedMaterial.Attributes["MaterialId"]; if (XMLItemAttribute == null) throw new Exception("Узел \"SupportedMaterial\" не содержит обязательный атрибут \"MaterialId\""); int MaterialId = -1; try { MaterialId = Convert.ToInt32(XMLItemAttribute.Value); } catch (Exception ex) { throw new Exception("\"MaterialId\": " + ex.Message); } // уникальный идентификатор материала int MaterialIndex = materials.GetIndexById(MaterialId); if (MaterialIndex == -1) throw new Exception("\"" + XMLItemAttribute.Value + "\": описание материала не найдено!"); XmlNode XMLMaterialConfTime = SupportedMaterial.Attributes["ConfTime"]; if (XMLMaterialConfTime == null) throw new Exception("Узел \"SupportedMaterial\" не содержит обязательный атрибут \"ConfTime\""); // время на настройку пилы под этот материал int ConfTime = 0; try { ConfTime = Convert.ToInt32(XMLMaterialConfTime.Value); } catch (Exception ex) { throw new Exception("Атрибут \"ConfTime\": " + ex.Message); } NewTimeDevice.AddMaterial(new MaterialPair(MaterialId, ConfTime)); } } NewTimeDevice.DefaultMaterialId = DefaultMaterialId; grinders.Add(NewTimeDevice); } else throw new Exception("Не поддерживаемый дочерний узел: \"" + item.Name + "\" для узла Devices. Допустимые узлы: \"Saw\", \"Grinder\"."); } } }