Пример #1
0
        /// <summary>
        /// Serialises the object to XML.
        /// </summary>
        /// <returns>XML data.</returns>
        public byte[] ToXmlBytes()
        {
            var proxy = new XsdNs.ProcessProductionScheduleType
            {
                // Set release ID (obligatory in the XML schema)
                releaseID = "1",

                // Create application area
                ApplicationArea = new XsdNs.TransApplicationAreaType()
                {
                    // Set creation datetime
                    CreationDateTime = new XsdNs.DateTimeType
                    {
                        Value = XNeut.Helper.DateTimeForSerialisation(m_creationDateTime)
                    }
                },

                // Creating data area
                DataArea = new XsdNs.ProcessProductionScheduleTypeDataArea()
                {
                    Process = new XsdNs.TransProcessType(),

                    // Adding schedules
                    ProductionSchedule = CreateScheduleProxies(out ICollection <Type> extraTypes)
                }
            };

            // Serialising to XML
            return(XNeut.Helper.ToXmlBytes(obj: proxy, extraTypes: extraTypes));
        }
Пример #2
0
        /// <summary>
        /// Constructor. Use this to deserialise from XML.
        /// </summary>
        /// <param name="xmlBytes">XML data.</param>
        /// <exception cref="XNeut.InvalidMessageException">Thrown if an error is encountered.</exception>
        public ProcessProductionSchedule(byte[] xmlBytes)
            : this()
        {
            XsdNs.ProcessProductionScheduleType proxy = null;

            // Generating proxy
            try
            {
                proxy = (XsdNs.ProcessProductionScheduleType)XNeut.Helper.DeserialiseFromXml(typeof(XsdNs.ProcessProductionScheduleType), xmlBytes);

                // Processing the proxy
                ReadFieldValuesFromXmlProxy(proxy); // throws InvalidMessageException
            }
            catch (InvalidOperationException e)
            {
                throw new XNeut.InvalidMessageException("Failed to deserialise ProcessProductionSchedule from XML", e);
            }
        }
Пример #3
0
        private void ReadFieldValuesFromXmlProxy(XsdNs.ProcessProductionScheduleType proxy)
        {
            try
            {
                // Read creation time
                m_creationDateTime = XNeut.Helper.DateTimeToUtcIfPossible(proxy.ApplicationArea.CreationDateTime.Value);

                // The schema requires at least one schedule. Therefore, if
                // ProductionSchedule[] is null, the document is invalid -> no null check here.
                foreach (var scheduleProxy in proxy.DataArea.ProductionSchedule)
                {
                    ProductionSchedules.Add(new ProductionSchedule(scheduleProxy));
                }
            }
            catch (NullReferenceException e)
            {
                throw new XNeut.InvalidMessageException("Failed to read ProcessProductionSchedule - something required is missing", e);
            }
        }