Beispiel #1
0
        /// <summary>
        /// Creates new verion of the project from the existing version <param name="branchedVersion" />.
        /// The created version is fully integrated into versioning system
        /// (dictionaries <see cref="Exolutio.Model.Project" />.<see cref="Exolutio.Model.Project.ProjectVersions" /> and version links
        /// among <see cref="IVersionedItem"/>s).
        /// </summary>
        /// <param name="branchedVersion">Existing version in the project</param>
        /// <param name="newVersion">New version marker. Created, but "emtpy", must not be member of Project.Versions collection</param>
        public ProjectVersion BranchProject(ProjectVersion branchedVersion, Version newVersion)
        {
            branching = true;
            newVersion.BranchedFrom = branchedVersion.Version;
            Versions.Add(newVersion);

            ProjectVersion newProjectVersion = new ProjectVersion(Project);

            newProjectVersion.Version = newVersion;

            ElementCopiesMap             elementCopiesMap = new ElementCopiesMap(Project, Project);
            IEnumerable <ExolutioObject> allModelItems    = ModelIterator.GetAllModelItems(branchedVersion);
            List <ExolutioObject>        exolutioObjects  = allModelItems.ToList();

            elementCopiesMap.PrepareGuids(exolutioObjects);
            elementCopiesMap.PrepareGuid(branchedVersion);

            branchedVersion.FillCopy(newProjectVersion, newProjectVersion, elementCopiesMap);

            Project.ProjectVersions.Add(newProjectVersion);

            foreach (KeyValuePair <IVersionedItem, IVersionedItem> keyValuePair in elementCopiesMap)
            {
                RegisterVersionLink(branchedVersion.Version, newVersion, keyValuePair.Key, keyValuePair.Value);
            }

            branching = false;
            return(newProjectVersion);
        }
Beispiel #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);
         }
     }
 }
Beispiel #3
0
        public Project SeparateVersion(ProjectVersion projectVersion, bool keepGuids)
        {
            Project separatedProject = new Project();

            separatedProject.InitNewEmptyProject(false);

            ElementCopiesMap elementCopiesMap = new ElementCopiesMap(Project, separatedProject);

            elementCopiesMap.KeepGuids = keepGuids;
            IEnumerable <ExolutioObject> allModelItems   = ModelIterator.GetAllModelItems(projectVersion);
            List <ExolutioObject>        exolutioObjects = allModelItems.ToList();

            elementCopiesMap.PrepareGuids(exolutioObjects);
            elementCopiesMap.PrepareGuid(projectVersion);

            projectVersion.FillCopy(separatedProject.SingleVersion, separatedProject.SingleVersion, elementCopiesMap);

            return(separatedProject);
        }
Beispiel #4
0
        public void EmbedVersion(ProjectVersion embededVersion, Version newVersion, Version branchedFrom, bool keepGuids, bool createVersionLinks)
        {
            newVersion.BranchedFrom = branchedFrom;
            Versions.Add(newVersion);
            ProjectVersion newProjectVersion = new ProjectVersion(Project);

            newProjectVersion.Version = newVersion;

            ElementCopiesMap elementCopiesMap = new ElementCopiesMap(embededVersion.Project, Project);

            elementCopiesMap.KeepGuids = keepGuids;
            IEnumerable <ExolutioObject> allModelItems   = ModelIterator.GetAllModelItems(embededVersion);
            List <ExolutioObject>        exolutioObjects = allModelItems.ToList();

            elementCopiesMap.PrepareGuids(exolutioObjects);
            elementCopiesMap.PrepareGuid(embededVersion);

            Project.ProjectVersions.Add(newProjectVersion);
            embededVersion.FillCopy(newProjectVersion, newProjectVersion, elementCopiesMap);

            if (createVersionLinks)
            {
                foreach (KeyValuePair <IVersionedItem, IVersionedItem> kvp in elementCopiesMap)
                {
                    IVersionedItem fromEmbedded = kvp.Key;
                    IVersionedItem newlyCreated = kvp.Value;
                    ExolutioObject previousObject;
                    if (Project.TryTranslateObject(fromEmbedded.ID, out previousObject) && previousObject is IVersionedItem)
                    {
                        if (Project.mappingDictionary.ContainsKey(previousObject.ID) &&
                            Project.mappingDictionary.ContainsKey(newlyCreated.ID))
                        {
                            RegisterVersionLink(((IVersionedItem)previousObject).Version, newVersion, (IVersionedItem)previousObject, newlyCreated);
                        }
                    }
                }
            }
        }
Beispiel #5
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);
     }
 }
Beispiel #6
0
 public static T CreateTypedCopy <T>(this T ownedObject, ProjectVersion projectVersion, ElementCopiesMap createdCopies)
     where T : IExolutioCloneable
 {
     return((T)ownedObject.CreateCopy(projectVersion, createdCopies));
 }
Beispiel #7
0
 /// <summary>
 /// Clones all the members of <paramref name="sourceCollection"/>, calls FillCopy for each cloned member and
 /// </summary>
 public static void CopyDictionary <TKey, TValue>(this IExolutioCloneable cloneable, Dictionary <TKey, TValue> sourceDictionary,
                                                  Dictionary <TKey, TValue> targetDictionary, ProjectVersion projectVersion, ElementCopiesMap createdCopies)
     where TKey : ExolutioObject
     where TValue : IExolutioCloneable
 {
     foreach (KeyValuePair <TKey, TValue> collectionItem in sourceDictionary)
     {
         TValue itemCopy = (TValue)collectionItem.Value.Clone(projectVersion, createdCopies);
         collectionItem.Value.FillCopy(itemCopy, projectVersion, createdCopies);
         Guid keyGuid = createdCopies.GetGuidForCopyOf(collectionItem.Key);
         targetDictionary.Add(projectVersion.Project.TranslateComponent <TKey>(keyGuid), itemCopy);
     }
 }