Exemple #1
0
        public void ProcessProductionSchedule()
        {
            // ProcessProductionSchedule request test

            // Creating a message object for testing
            var request = new MsgBiz.ProcessProductionSchedule()
            {
                ProductionSchedules = new System.Collections.Generic.List <MsgBiz.ProductionSchedule>
                {
                    new MsgBiz.ProductionSchedule()
                    {
                        ProductionRequests = new System.Collections.Generic.List <MsgBiz.ProductionRequest>
                        {
                            new MsgBiz.ProductionRequest()
                            {
                                HierarchyScopeObj = new MsgBiz.HierarchyScope(
                                    new MsgBiz.IdentifierType("my-equipment"),
                                    MsgBiz.EquipmentElementLevelType.ProcessCell
                                    )
                            }
                        }
                    }
                }
            };

            var msg = request.ToXmlBytes();

            // Extracting metadata
            var testObject = MetadataExtractor.Build(msg);

            Assert.AreEqual(ContentTypeType.Xml, testObject.ContentType);
            Assert.AreEqual("Production schedule", testObject.Name);
            Assert.AreEqual("Production schedule", testObject.PayloadSummary);
            Assert.AreEqual(PayloadTypeType.ProcessProductionScheduleXml, testObject.PayloadType);
        }
Exemple #2
0
        public void ReadXml(byte[] xmlBytes)
        {
            MsgBiz.ProcessProductionSchedule processRequest;

            // Reading the message
            try
            {
                processRequest = new MsgBiz.ProcessProductionSchedule(xmlBytes);
            }
            catch (MsgBiz.Neutral.InvalidMessageException e)
            {
                throw new InvalidOperationException("Failed to read message: " + e.Message);
            }

            // Now, read message content and realise the schedule if possible
            //processRequest.ProductionSchedules[0].ProductionRequests[0].SegmentRequirements ...
        }
Exemple #3
0
        private void VisualiseProductionSchedule(string filepath)
        {
            MessageTreeView.Items.Clear();

            try
            {
                // Deserialising the document
                var msg        = System.IO.File.ReadAllBytes(filepath);
                var requestMsg = new MsgBiz.ProcessProductionSchedule(msg);

                // Adding metadata
                var root = AddNodeToTreeview(MessageTreeView, "ProcessProductionSchedule");
                AddNodeToTreeview(root, "CreationDateTime", FormatDateTimeForTreeview(requestMsg.CreationDateTime));

                // Adding production schedules
                AddProductionSchedules(root, requestMsg.ProductionSchedules);
            }
            catch (Exception e)
            {
                AddMessageToTreeview("Error: " + e.Message);
                m_appLogic.AddUnexpectedErrorToLog(e);
            }
        }
Exemple #4
0
        // 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());
        }
Exemple #5
0
        private byte[] GetProcessProductionSchedule()
        {
            try
            {
                // Fabricating a message
                var baseDateTime = DateTime.Now.ToUniversalTime().AddMinutes(30);

                var materialReq = new MsgBiz.MaterialRequirement()
                {
                    MaterialDefinitionIdentifiers = new System.Collections.Generic.List <MsgBiz.IdentifierType>
                    {
                        new MsgBiz.IdentifierType("material_x")
                    },
                    MaterialLotIdentifiers = new System.Collections.Generic.List <MsgBiz.IdentifierType>
                    {
                        new MsgBiz.IdentifierType("batch-119")
                    },
                    MaterialUse = new MsgBiz.MaterialUse(MsgBiz.MaterialUseType.Produced),
                    Quantities  = new System.Collections.Generic.List <MsgBiz.QuantityValue>
                    {
                        new MsgBiz.QuantityValue(41.9)
                        {
                            UnitOfMeasure = "t/h"
                        }
                    }
                };

                var messageObj = new MsgBiz.ProcessProductionSchedule()
                {
                    ProductionSchedules = new System.Collections.Generic.List <MsgBiz.ProductionSchedule>
                    {
                        new MsgBiz.ProductionSchedule()
                        {
                            ProductionRequests = new System.Collections.Generic.List <MsgBiz.ProductionRequest>
                            {
                                new MsgBiz.ProductionRequest()
                                {
                                    Identifier        = new MsgBiz.IdentifierType("my-identifier-1"),
                                    HierarchyScopeObj = new MsgBiz.HierarchyScope(
                                        new MsgBiz.IdentifierType("process_a"),
                                        MsgBiz.EquipmentElementLevelType.ProcessCell
                                        ),
                                    SegmentRequirements = new System.Collections.Generic.List <MsgBiz.SegmentRequirement>
                                    {
                                        new MsgBiz.SegmentRequirement()
                                        {
                                            EarliestStartTime    = baseDateTime.AddMinutes(1),
                                            LatestEndTime        = baseDateTime.AddMinutes(30),
                                            MaterialRequirements = new System.Collections.Generic.List <MsgBiz.MaterialRequirement>
                                            {
                                                materialReq
                                            }
                                        },
                                        new MsgBiz.SegmentRequirement()
                                        {
                                            EarliestStartTime = baseDateTime.AddMinutes(31),
                                            LatestEndTime     = baseDateTime.AddMinutes(60)
                                        }
                                    }
                                },
                                new MsgBiz.ProductionRequest()
                                {
                                    Identifier = new MsgBiz.IdentifierType("my-identifier-2")
                                }
                            }
                        }
                    }
                };

                // String to bytes
                return(messageObj.ToXmlBytes());
            }
            catch
            {
                // Fallback: use empty message
                return(new byte[0]);
            }
        }
Exemple #6
0
        private void SendSchedule(Rmq.IModel channel)
        {
            // Creating an imaginary schedule for two tanks, T300 and T400.

            // It helps to create a "base DateTime", because the message API requires all DateTimes in UTC
            var dateTimeBase = DateTime.Now.ToUniversalTime();

            // Creating material requirements for the production requests
            var matReqLoad   = CreateMaterialReqForSchedule(MsgBiz.MaterialUseType.Consumed, "liquid_422", 1.3);
            var matReqUnload = CreateMaterialReqForSchedule(MsgBiz.MaterialUseType.Produced, "liquid_429", 1.1);

            // Creating scheduling parameters
            var schedulingParams = new MsgMeas.Item_DataRecord()
            {
                { "scheduling-method", new MsgMeas.Item_Category("default") },
                { "scheduling-horizon", new MsgMeas.Item_Measurement("min", 120) }
            };

            // Creating production requests
            var prodReqT300 = new MsgBiz.ProductionRequest()
            {
                HierarchyScopeObj = new MsgBiz.HierarchyScope(
                    new MsgBiz.IdentifierType("T300"),
                    MsgBiz.EquipmentElementLevelType.ProcessCell
                    ),

                SegmentRequirements = new SysColl.List <MsgBiz.SegmentRequirement>()
                {
                    CreateSegmentForSchedule(dateTimeBase.AddMinutes(29), dateTimeBase.AddMinutes(49), "load", matReqLoad),
                    CreateSegmentForSchedule(dateTimeBase.AddMinutes(62), dateTimeBase.AddMinutes(82), "unload", matReqUnload),
                },

                SchedulingParameters = schedulingParams.ToDataRecordPropertyProxy()
            };
            var prodReqT400 = new MsgBiz.ProductionRequest()
            {
                HierarchyScopeObj = new MsgBiz.HierarchyScope(
                    new MsgBiz.IdentifierType("T400"),
                    MsgBiz.EquipmentElementLevelType.ProcessCell
                    ),

                SegmentRequirements = new SysColl.List <MsgBiz.SegmentRequirement>()
                {
                    CreateSegmentForSchedule(dateTimeBase.AddMinutes(19), dateTimeBase.AddMinutes(39), "load", matReqLoad),
                    CreateSegmentForSchedule(dateTimeBase.AddMinutes(52), dateTimeBase.AddMinutes(72), "unload", matReqUnload),
                },

                SchedulingParameters = schedulingParams.ToDataRecordPropertyProxy()
            };

            // Creating a request to process the schedule
            var processScheduleRequest = new MsgBiz.ProcessProductionSchedule()
            {
                // This is the current time by default, but setting it explicitly
                CreationDateTime = DateTime.Now.ToUniversalTime(),

                ProductionSchedules = new SysColl.List <MsgBiz.ProductionSchedule>
                {
                    new MsgBiz.ProductionSchedule()
                }
            };

            // Adding the production requests to the message
            processScheduleRequest.ProductionSchedules[0].ProductionRequests.Add(prodReqT300);
            processScheduleRequest.ProductionSchedules[0].ProductionRequests.Add(prodReqT400);

            // Sending the message to the message bus
            SendToMessageBus(channel, TopicNameSchedules, processScheduleRequest.ToXmlBytes());
        }