Пример #1
0
 /// <summary>
 /// Clones all the members of <paramref name="sourceCollection"/>, calls FillCopy for each cloned member and
 /// </summary>
 public static void CopyCollection <T>(this IExolutioCloneable cloneable, UndirectCollection <T> sourceCollection, UndirectCollection <T> targetCollection, ProjectVersion projectVersion, ElementCopiesMap createdCopies)
     where T : ExolutioObject
 {
     foreach (T collectionItem in sourceCollection)
     {
         T itemCopy = (T)collectionItem.Clone(projectVersion, createdCopies);
         collectionItem.FillCopy(itemCopy, projectVersion, createdCopies);
         targetCollection.Add(itemCopy);
     }
 }
Пример #2
0
 /// <summary>
 /// Registers (already existing) copies of the members of <paramref name="sourceCollection"/> into <paramref name="targetCollection"/>.
 /// </summary>
 public static void CopyRefCollection <T>(this IExolutioCloneable cloneable, IEnumerable <T> sourceCollection, UndirectCollection <T> targetCollection,
                                          ProjectVersion projectVersion, ElementCopiesMap createdCopies, bool asGuid = false)
     where T : ExolutioObject
 {
     foreach (T collectionItem in sourceCollection)
     {
         Guid guid = createdCopies.GetGuidForCopyOf(collectionItem);
         if (!asGuid)
         {
             targetCollection.Add(targetCollection.Project.TranslateComponent <T>(guid));
         }
         else
         {
             targetCollection.AddAsGuidSilent(guid);
         }
     }
 }
Пример #3
0
        public static void DeserializeWrappedCollection <T>(this IExolutioSerializable component, [NotNull] string collectionNodeName, UndirectCollection <T> collection, CreateComponentDelegate <T> createAction, XElement parentNode, SerializationContext context, bool missingAsEmpty = false)
            where T : ExolutioObject
        {
            XElement collectionNode = parentNode.Element(context.ExolutioNS + collectionNodeName);

            if (collectionNode == null && missingAsEmpty)
            {
                return;
            }

            if (collectionNode == null)
            {
                context.Log.AddErrorFormat(SerializationLogMessages.Collection_node__0__not_found_in_node__1__,
                                           collectionNodeName, parentNode);
                return;
            }

            int?count = null;

            if (collectionNode.Attribute("Count") == null)
            {
                context.Log.AddWarningFormat(SerializationLogMessages.Collection_node__0__missing_attribute__Count__,
                                             collectionNode);
            }
            else
            {
                count = int.Parse(collectionNode.Attribute("Count").Value);
            }

            int subelementsCount = 0;

            foreach (XElement xmlElement in collectionNode.Elements())
            {
                T member = createAction(component.Project);
                member.Deserialize(xmlElement, context);
                collection.Add(member);
                subelementsCount++;
            }

            if (count.HasValue && count != subelementsCount)
            {
                context.Log.AddWarningFormat(SerializationLogMessages.InconsistentCount, count, collectionNode, subelementsCount);
            }
        }