Ejemplo n.º 1
0
        private void update(IRhspData data, XDocument document)
        {
            RhspDataAttribute hdca    = GetRuntimeHda(data.GetType());
            XElement          element = getElementUsingHda(document, data.DataID, hdca);

            // Delegate element update to object it's self.
            data.UpdateElement(element, this);

            /* Set the latest schema version (as re-saving automatically
             * updates the object to this version). Versions are only ever
             * opened as earlier versions and never saved as this. */
            updateVersionElement(element, hdca);
        }
Ejemplo n.º 2
0
        private void create(IRhspData data, XDocument document)
        {
            if (data.DataID == null)
            {
                throw new Exception(
                          "Hosting ID cannot be unassigned.");
            }

            RhspDataAttribute hda    = GetRuntimeHda(data.GetType());
            XElement          parent = getParent(document, hda.Parent);
            var uniqueQuery          = find(parent, data.DataID, hda);

            // Ensure that IDs are not duplicated.
            if (uniqueQuery.Count() != 0)
            {
                throw new InvalidOperationException(
                          "An element with name '" + hda.Name + "' in parent " +
                          "'" + hda.Parent + "' already contains unique ID " +
                          "with value of '" + data.DataID + "'.");
            }

            // Get original data without unique ID present.
            XElement element = data.ToXElement(this);

            // Add ID first for better visual diagnosis.
            element.AddFirst(new XElement(hda.ID, data.DataID.Value));

            if (hda.SchemaVersion != 0)
            {
                // Add version before the ID element, but only if neccecary.
                element.AddFirst(new XElement(SchemaVersionElement, hda.SchemaVersion));
            }

            // Add the element with unique ID present.
            parent.Add(element);
        }