Esempio n. 1
0
 private object createFromElement(XElement element, Type dataType)
 {
     try
     {
         RhspDataAttribute hda  = GetRuntimeHda(dataType);
         object            data = Activator.CreateInstance(dataType);
         if (data is IRhspData)
         {
             IRhspData hd = (IRhspData)data;
             hd.DataID = new RhspDataID(element.Element(hda.ID).Value);
             hd.FromElement(element, this);
         }
         else
         {
             throw new NotSupportedException(
                       "The data type must implement interface " +
                       typeof(IRhspData).Name + " for an instance " +
                       "to be created from an XML element.");
         }
         return(data);
     }
     catch (TargetInvocationException ex)
     {
         // Rethrow the target invocation exception, but pull the message to the top.
         throw new TargetInvocationException(ex.InnerException.Message, ex.InnerException);
     }
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void delete(RhspDataID dataID, Type dataType)
        {
            IRhspData data = (IRhspData)getSingleOfType(dataID, dataType);

            deleteWithoutSave(dataID, dataType, ConfigDocument);

            if (data is IRhspDataParent)
            {
                // Set each child to deleted, then process.
                IRhspDataParent       dataParent = (IRhspDataParent)data;
                List <IRhspDataChild> childList  = dataParent.GetDataChildren().ToList();

                // Process all the marked deletions.
                childList.ForEach(c => c.PendingAction = ChildPendingAction.Delete);
            }
        }
Esempio n. 4
0
        private void updateChildDataParent(IRhspData data)
        {
            if (data is IRhspDataParent)
            {
                IRhspDataParent parent = (IRhspDataParent)data;

                // Apply parent ID to all child data.
                parent.GetDataChildren().ToList().ForEach(
                    c =>
                {
                    c.ParentID = data.DataID;
                    c.Parent   = parent;
                }
                    );
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
 public void Update(IRhspData data)
 {
     updateChildDataParent(data);
     update(data, ConfigDocument);
 }