Exemplo n.º 1
0
        private void AddOneProductionRequest(ItemsControl parent, MsgBiz.ProductionRequest req, int nr)
        {
            var prodReqNode = AddNodeToTreeview(parent, "ProductionRequest " + nr);

            // Add hierarchy scope and identifier
            var hierarchyScope = req.HierarchyScopeObj ?? null;

            AddHierarchyScopeIfNotNull(prodReqNode, req.HierarchyScopeObj);
            AddIdentifierIfNotNull(prodReqNode, "ID", req.Identifier);

            // Add segment requirements
            for (int a = 0; a < req.SegmentRequirements.Count; ++a)
            {
                AddSegmentRequirement(prodReqNode, req.SegmentRequirements[a], a + 1);
            }

            // Add scheduling params
            if (req.SchedulingParameters != null)
            {
                try
                {
                    // Expecting a data record
                    var paramsDataRec = new MsgMeas.Item_DataRecord((System.Xml.XmlNode[])req.SchedulingParameters);
                    AddNodeToTreeview(prodReqNode, "SchedulingParameters", paramsDataRec);
                }
                catch (Exception e)
                {
                    AddNodeToTreeview(prodReqNode, "SchedulingParameters failed to show: " + e.Message);
                    HandleBug(e);
                }
            }
        }
Exemplo n.º 2
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());
        }
Exemplo n.º 3
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());
        }