private void AddSegmentRequirement(ItemsControl parent, MsgBiz.SegmentRequirement segm, int nr) { // Add segment requirement and its children var segmNode = AddNodeToTreeview(parent, "SegmentRequirement " + nr); AddIdentifierIfNotNull(segmNode, "ProcessSegmentID", segm.ProcessSegmentIdentifier); AddDateTimeIfNotNull(segmNode, "EarliestStartTime", segm.EarliestStartTime); AddDateTimeIfNotNull(segmNode, "LatestEndTime", segm.LatestEndTime); if (segm.EquipmentRequirements != null) { for (int a = 0; a < segm.EquipmentRequirements.Count; ++a) { AddEquipmentRequirement(segmNode, segm.EquipmentRequirements[a], a + 1); } } if (segm.MaterialRequirements != null) { for (int a = 0; a < segm.MaterialRequirements.Count; ++a) { AddMaterialRequirement(segmNode, "MaterialRequirement", segm.MaterialRequirements[a], a + 1); } } // Any nested segment requirements? if (segm.SegmentRequirements != null) { for (int a = 0; a < segm.SegmentRequirements.Count; ++a) { AddSegmentRequirement(segmNode, segm.SegmentRequirements[a], a + 1); } } }
// This example shows how to create and read a ProcessProductionSchedule // message in XML (based on the XML schemata of B2MML). // // Please note that this example does not use all fields available in the API. // On the other hand, the API only implements are fraction of B2MML. // "ProcessProductionSchedule" is only one of the message types of B2MML. // Please see the ANSI/ISA-95 standard or B2MML documentation to learn more // about message types and messaging patterns. public byte[] CreateXml() { // This function procudes a schedule for an imaginary batch process, // where materials are cooked in a "cooker". // There are 3 segments: "charge", "cook" and "discharge". // Charge takes raw material in, whereas discharge takes the end product out. var processStart = DateTime.Now.AddMinutes(40).ToUniversalTime(); // Creating segment requirements. The segments are "charge", "cook" and "discharge". var segmentCharge = new MsgBiz.SegmentRequirement { ProcessSegmentIdentifier = new MsgBiz.IdentifierType("charge"), EarliestStartTime = processStart, LatestEndTime = processStart.AddMinutes(15) }; var segmentCook = new MsgBiz.SegmentRequirement { ProcessSegmentIdentifier = new MsgBiz.IdentifierType("cook"), EarliestStartTime = processStart.AddMinutes(15), LatestEndTime = processStart.AddMinutes(75) }; var segmentDischarge = new MsgBiz.SegmentRequirement { ProcessSegmentIdentifier = new MsgBiz.IdentifierType("discharge"), EarliestStartTime = processStart.AddMinutes(75), LatestEndTime = processStart.AddMinutes(90) }; // Specifying the required equipment var equipmentReq = new MsgBiz.EquipmentRequirement() { Quantities = new SysColl.List <MsgBiz.QuantityValue>() { // One cooker is required for the process new MsgBiz.QuantityValue(1) { Key = new MsgBiz.IdentifierType("cooker") } } }; segmentCharge.EquipmentRequirements.Add(equipmentReq); segmentCook.EquipmentRequirements.Add(equipmentReq); segmentDischarge.EquipmentRequirements.Add(equipmentReq); // Specifying the required raw materials var materialWater = CreateMaterialReq( use: MsgBiz.MaterialUseType.Consumed, id: "water", // This could be more specific quantity: 3.2, uom: "m3"); var materialConcentrate = CreateMaterialReq( use: MsgBiz.MaterialUseType.Consumed, id: "concentrate-A2", quantity: 220, uom: "kg"); segmentCharge.MaterialRequirements.Add(materialWater); segmentCharge.MaterialRequirements.Add(materialConcentrate); // Specifying the expected material output var materialEndProduct = CreateMaterialReq( use: MsgBiz.MaterialUseType.Produced, id: "product-A2", quantity: 3.1, uom: "t"); // Specify a lot ID for the output materialEndProduct.MaterialLotIdentifiers.Add( new MsgBiz.IdentifierType("lot-A2-3101") ); segmentDischarge.MaterialRequirements.Add(materialEndProduct); // Creating a production request. The schedule could contain multiple of these. // You could add multiple requests, one for each production unit, for instance. var productionRequest = new MsgBiz.ProductionRequest { // Set hierarchy scope HierarchyScopeObj = new MsgBiz.HierarchyScope( new MsgBiz.IdentifierType("cooker-3"), MsgBiz.EquipmentElementLevelType.ProcessCell ), // Set segments SegmentRequirements = new SysColl.List <MsgBiz.SegmentRequirement>() { segmentCharge, segmentCook, segmentDischarge } }; // Creating a schedule object var schedule = new MsgBiz.ProductionSchedule() { ProductionRequests = new SysColl.List <MsgBiz.ProductionRequest>() { productionRequest } }; var processScheduleRequest = new MsgBiz.ProcessProductionSchedule() { CreationDateTime = DateTime.Now.ToUniversalTime(), ProductionSchedules = new SysColl.List <MsgBiz.ProductionSchedule>() { schedule } }; // Serialising to XML return(processScheduleRequest.ToXmlBytes()); }