Exemplo n.º 1
0
        private XsdNs.SegmentRequirementType[] BuildSegmentReqsForProxy()
        {
            var retval = new XsdNs.SegmentRequirementType[SegmentRequirements.Count];

            for (int a = 0; a < SegmentRequirements.Count; ++a)
            {
                retval[a] = SegmentRequirements[a].ToXmlProxy();
            }

            return(retval);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="proxy">XML proxy.</param>
        /// <exception cref="XNeut.InvalidMessageException">Thrown if an error is encountered.</exception>
        internal SegmentRequirement(XsdNs.SegmentRequirementType proxy)
            : this() // Call the default constructor
        {
            try
            {
                if (proxy.ProcessSegmentID != null)
                {
                    ProcessSegmentIdentifier = new IdentifierType(proxy.ProcessSegmentID);
                }

                m_earliestStartTime = TryGetTime(proxy.EarliestStartTime);
                m_latestEndTime     = TryGetTime(proxy.LatestEndTime);

                // Check if end is before start
                if (m_earliestStartTime.HasValue && m_latestEndTime.HasValue &&
                    m_earliestStartTime.Value > m_latestEndTime.Value)
                {
                    var msg = string.Format("Segment end must not be before start; start at {0} UTC",
                                            m_earliestStartTime.Value.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    throw new XNeut.InvalidMessageException(msg);
                }

                if (proxy.EquipmentRequirement != null)
                {
                    foreach (var req in proxy.EquipmentRequirement)
                    {
                        EquipmentRequirements.Add(new EquipmentRequirement(req)); // throws InvalidMessageException
                    }
                }

                if (proxy.MaterialRequirement != null)
                {
                    foreach (var req in proxy.MaterialRequirement)
                    {
                        MaterialRequirements.Add(new MaterialRequirement(req)); // throws InvalidMessageException
                    }
                }

                if (proxy.SegmentRequirement != null)
                {
                    foreach (var req in proxy.SegmentRequirement)
                    {
                        SegmentRequirements.Add(new SegmentRequirement(req)); // throws InvalidMessageException
                    }
                }
            }
            catch (NullReferenceException e)
            {
                throw new XNeut.InvalidMessageException("Failed to read SegmentRequirement - something required is missing", e);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates an XML proxy from the object.
        /// </summary>
        /// <returns>XML proxy.</returns>
        /// <exception cref="XNeut.DateTimeException">Thrown if there is a segment that has EarliestStartTime
        /// after LatestEndTime.</exception>
        internal XsdNs.SegmentRequirementType ToXmlProxy()
        {
            XsdNs.ProcessSegmentIDType segmentIdProxy = null;

            // Process segment ID specified?
            if (ProcessSegmentIdentifier != null)
            {
                // Creating segment ID proxy
                segmentIdProxy = new XsdNs.ProcessSegmentIDType();
                ProcessSegmentIdentifier.PopulateXmlProxy(segmentIdProxy);
            }

            var retval = new XsdNs.SegmentRequirementType()
            {
                ProcessSegmentID = segmentIdProxy,

                EquipmentRequirement = BuildEquipmentReqsForProxy(),
                MaterialRequirement  = BuildMaterialReqsForProxy(),
                SegmentRequirement   = BuildSegmentReqsForProxy()
            };

            // Making sure start is not after end
            if (m_earliestStartTime.HasValue && m_latestEndTime.HasValue &&
                m_earliestStartTime > m_latestEndTime)
            {
                var msg = string.Format("Start of segment must not be after end (starting at {0} UTC)",
                                        m_earliestStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                throw new XNeut.DateTimeException(msg);
            }

            // Add time values
            if (m_earliestStartTime.HasValue)
            {
                retval.EarliestStartTime = new XsdNs.EarliestStartTimeType()
                {
                    Value = XNeut.Helper.DateTimeForSerialisation(m_earliestStartTime.Value)
                };
            }
            if (m_latestEndTime.HasValue)
            {
                retval.LatestEndTime = new XsdNs.LatestEndTimeType()
                {
                    Value = XNeut.Helper.DateTimeForSerialisation(m_latestEndTime.Value)
                };
            }

            return(retval);
        }