Example #1
0
        //private static void CheckPsmClassParent(PSMDiagram diagram)
        //{
        //    foreach (PSMClass psmClass in diagram.DiagramElements.Keys.OfType<PSMClass>())
        //    {
        //        if (psmClass.ParentAssociation != null)
        //        {
        //            if (psmClass.ParentAssociation.ChildEnd != psmClass)
        //            {
        //                throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass));
        //            }
        //            if (psmClass.ParentUnion != null)
        //            {
        //                throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass));
        //            }
        //        }
        //        else if (psmClass.ParentUnion != null)
        //        {
        //            if (!psmClass.ParentUnion.Components.Contains(psmClass))
        //            {
        //                throw new ModelConsistencyException(string.Format("Bad class parent union component {0}", psmClass));
        //            }
        //            if (psmClass.ParentAssociation != null)
        //            {
        //                throw new ModelConsistencyException(string.Format("Bad class parent association component {0}", psmClass));
        //            }
        //        }
        //        else
        //        {
        //            if (!diagram.Roots.Contains(psmClass) && psmClass.Generalizations.Count == 0)
        //            {
        //                throw new ModelConsistencyException(string.Format("Bad class {0}", psmClass));
        //            }
        //        }
        //    }
        //}

        //public static void CheckPsmParentsAndRoots(PSMDiagram diagram)
        //{
        //    foreach (Element element in diagram.DiagramElements.Keys)
        //    {
        //        PSMSubordinateComponent subordinateComponent = (element as PSMSubordinateComponent);
        //        if (subordinateComponent != null)
        //        {
        //            if (subordinateComponent.ParentEnd == null && !diagram.Roots.Contains((PSMClass)subordinateComponent))
        //            {
        //                throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent));
        //            }
        //            if (subordinateComponent.ParentEnd != null)
        //            {
        //                if (!subordinateComponent.ParentEnd.Components.Contains(subordinateComponent))
        //                {
        //                    throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent));
        //                }
        //            }
        //        }

        //        PSMSuperordinateComponent superordinateComponent = element as PSMSuperordinateComponent;

        //        if (superordinateComponent != null)
        //        {
        //            foreach (PSMSubordinateComponent component in superordinateComponent.Components)
        //            {
        //                if (component.ParentEnd != superordinateComponent)
        //                {
        //                    throw new ModelConsistencyException(string.Format("Bad superordinateComponent component {0}", superordinateComponent));
        //                }
        //            }
        //        }
        //    }
        //}

        //public static void CheckPsmElementsDiagram(PSMDiagram diagram)
        //{
        //    foreach (Element element in diagram.DiagramElements.Keys)
        //    {
        //        PSMElement psmElement = element as PSMElement;
        //        if (psmElement != null)
        //        {
        //            if (psmElement.Diagram != diagram)
        //            {
        //                throw new ModelConsistencyException(string.Format("Element {0}  has wrong diagram.", psmElement));
        //            }
        //        }
        //    }
        //}

        //public static void CheckViewHelpersDiagram(Diagram diagram)
        //{
        //    foreach (KeyValuePair<Element, ViewHelper> kvp in diagram.DiagramElements)
        //    {
        //        if (kvp.Value.Diagram != diagram)
        //        {
        //            throw new ModelConsistencyException(string.Format("ViewHelper {0} for element {1} has wrong diagram.", kvp.Key,
        //                                                              kvp.Value));
        //        }
        //    }
        //}

        //public static void CheckElementSchema(IEnumerable<Element> elements, Schema schema, List<Element> checkedAlready)
        //{
        //    if (checkedAlready == null)
        //        checkedAlready = new List<Element>();
        //    foreach (Element element in elements)
        //    {
        //        CheckElementSchema(element, schema, checkedAlready);
        //    }
        //}

        //public static void CheckElementSchema(Element element, Schema schema, List<Element> checkedAlready)
        //{
        //    if (element == null)
        //    {
        //        return;
        //    }

        //    if (checkedAlready != null)
        //    {
        //        if (checkedAlready.Contains(element))
        //            return;
        //        else
        //            checkedAlready.Add(element);
        //    }

        //    if (element.Schema != schema)
        //    {
        //        throw new ModelConsistencyException(string.Format("Schema of element {0} differs.", element));
        //    }

        //    // reiterate through properties
        //    Type type = element.GetType();
        //    Type elementInterfaceType = typeof(Element);
        //    Type elementCollectionType = typeof(IEnumerable);

        //    foreach (PropertyInfo propertyInfo in type.GetProperties())
        //    {
        //        if (elementInterfaceType.IsAssignableFrom(propertyInfo.PropertyType))
        //        {
        //            //System.Diagnostics.Debug.WriteLine(String.Format("Checking property {0}.{1}.", type.Name, propertyInfo.Name));
        //            Element value = propertyInfo.GetValue(element, null) as Element;
        //            if (value != null)
        //            {
        //                CheckElementSchema(value, schema, checkedAlready);
        //            }
        //        }

        //        if (elementCollectionType.IsAssignableFrom(propertyInfo.PropertyType))
        //        {
        //            IEnumerable theCollection = propertyInfo.GetValue(element, null) as IEnumerable;
        //            if (theCollection != null)
        //            {
        //                foreach (object item in theCollection)
        //                {
        //                    if (item is Element)
        //                    {
        //                        CheckElementSchema(element, schema, checkedAlready);
        //                    }
        //                }

        //            }
        //        }
        //    }

        //}

        #endregion

        #region Versioning

        private static void CheckVersioningConsistency(Project project)
        {
            VersionManager versionManager = project.VersionManager;

            Assert.AreEqual(versionManager.Versions.Count, project.ProjectVersions.Count);
            foreach (ProjectVersion projectVersion in project.ProjectVersions)
            {
                Assert.AreEqual(projectVersion, project.GetProjectVersion(projectVersion.Version));
            }

            foreach (ProjectVersion projectVersion in project.ProjectVersions)
            {
                foreach (ExolutioObject o in ModelIterator.GetAllModelItems(projectVersion))
                {
                    IVersionedItem versionedItem = (o as IVersionedItem);
                    if (versionedItem != null)
                    {
                        Assert.AreEqual(versionedItem.Version, projectVersion.Version);
                        Assert.IsTrue(projectVersion.Version.Items.Contains(versionedItem));
                    }
                }
            }

            foreach (Exolutio.Model.Versioning.Version version in project.VersionManager.Versions)
            {
                Exolutio.Model.Versioning.Version _v = version;
                Assert.IsTrue(version.Items.All(i => i.Version == _v));
            }

#if DEBUG
            versionManager.VerifyConsistency();
#endif
        }
Example #2
0
        private static void ReferenceCheck <TOwner, TMember>(TOwner owner, IVersionedItem other, GetReferredItemHandler <TOwner, TMember> getReferredItem)
            where TOwner : class, IVersionedItem
            where TMember : ExolutioObject, IVersionedItem
        {
            Assert.IsTrue(other is TOwner);
            TOwner  otherT  = (TOwner)other;
            TMember member1 = getReferredItem(owner);

            if (member1 == null)
            {
                TMember member2 = getReferredItem(otherT);
                Assert.IsNull(member2);
            }
            else
            {
                if (member1.ProjectVersion == null)
                {
                    Assert.IsNull(getReferredItem(otherT).ProjectVersion);
                    return;
                }

                TMember member2 = member1.GetInVersion(other.Version) as TMember;
                Assert.IsNotNull(member2);
                Assert.AreEqual(member2.GetInVersion(owner.Version), member1);
                Assert.AreEqual(getReferredItem(otherT), member2);
            }
        }
Example #3
0
        public void DeserializeVersionLinks(XElement parentNode, SerializationContext context)
        {
            foreach (XElement linkedItemsElement in parentNode.Elements(context.ExolutioNS + "LinkedItems"))
            {
                VersionedItemPivot pivot = new VersionedItemPivot();
                PivotList.Add(pivot);

                Dictionary <Version, Guid> linkedItemsIds = new Dictionary <Version, Guid>();
                foreach (XElement linkedItemElement in linkedItemsElement.Elements(context.ExolutioNS + "LinkedItem"))
                {
                    Guid    id        = SerializationContext.DecodeGuid(linkedItemElement.Attribute("itemID").Value);
                    Guid    versionId = SerializationContext.DecodeGuid(linkedItemElement.Attribute("versionNumber").Value);
                    Version version   = (Version)Project.TranslateComponent(versionId);
                    linkedItemsIds[version] = id;
                }

                if (linkedItemsIds.Count > 0)
                {
                    foreach (KeyValuePair <Version, Guid> kvp in linkedItemsIds)
                    {
                        IVersionedItem exolutioObject = (IVersionedItem)Project.TranslateComponent(kvp.Value);
                        pivotLookupDictionary[exolutioObject.ID] = pivot;
                        pivot.PivotMapping.Add(kvp.Key, exolutioObject.ID);
                    }
                }
            }
        }
        /// <summary>
        /// Initializes a new <see cref="TfsSolutionProject"/>.
        /// </summary>
        /// <param name="projectItem">The source controlled project file</param>
        /// <param name="versionControl">TFS source control</param>
        public TfsSolutionProject(IVersionedItem projectItem, IVersionControl versionControl)
            : base(projectItem, versionControl)
        {
            _projectDocument = new Lazy<XDocument>(() =>
                XDocument.Load(new StreamReader(Download())));

            _projectTypeGuids = new Lazy<IEnumerable<Guid>>(() =>
                new HashSet<Guid>(_projectDocument.Value
                    .Descendants(XName.Get("ProjectTypeGuids", ProjectNamespace))
                    .SelectMany(e => e.Value.Split(';'))
                    .Select(Guid.Parse)));
        }
Example #5
0
        /// <summary>
        /// Initializes a new <see cref="TfsSolutionProject"/>.
        /// </summary>
        /// <param name="projectItem">The source controlled project file</param>
        /// <param name="versionControl">TFS source control</param>
        public TfsSolutionProject(IVersionedItem projectItem, IVersionControl versionControl)
            : base(projectItem, versionControl)
        {
            _projectDocument = new Lazy <XDocument>(() =>
                                                    XDocument.Load(new StreamReader(Download())));

            _projectTypeGuids = new Lazy <IEnumerable <Guid> >(() =>
                                                               new HashSet <Guid>(_projectDocument.Value
                                                                                  .Descendants(XName.Get("ProjectTypeGuids", ProjectNamespace))
                                                                                  .SelectMany(e => e.Value.Split(';'))
                                                                                  .Select(Guid.Parse)));
        }
Example #6
0
 public void NotifyItemRemoved(IVersionedItem item)
 {
     if (item.Version != this)
     {
         throw new ExolutioModelException();
     }
     if (!this.Items.Contains(item))
     {
         throw new ExolutioModelException();
     }
     Items.Remove(item);
     Project.VersionManager.RemoveVersionedItem(item);
 }
Example #7
0
 public void NotifyItemAdded(IVersionedItem item)
 {
     if (item.Version != this)
     {
         throw new ExolutioModelException();
     }
     if (Items.Contains(item))
     {
         throw new ExolutioModelException();
     }
     Items.Add(item);
     Project.VersionManager.AddVersionedItem(item);
 }
Example #8
0
 private static void CheckVersionedItem(IVersionedItem component)
 {
     if (component.ProjectVersion.Project.UsesVersioning)
     {
         Assert.IsNotNull(component.Version);
         Assert.IsTrue(component.ProjectVersion.Project.VersionManager.Versions.Contains(component.Version));
         Assert.AreEqual(component.Version, component.ProjectVersion.Version);
     }
     else
     {
         Assert.IsNull(component.Version);
     }
 }
Example #9
0
        public IVersionedItem GetItemInVersion(IVersionedItem item, Version version)
        {
            VersionedItemPivot pivot = PivotLookupDictionary[item.ID];
            Guid result;

            if (pivot.PivotMapping.TryGetValue(version, out result))
            {
                return((IVersionedItem)Project.TranslateComponent(result));
            }
            else
            {
                return(null);
            }
        }
Example #10
0
        /// <summary>
        /// Adds new item to versioning infrastracture (item must not be linked to any other existing item).
        /// </summary>
        public void AddVersionedItem(IVersionedItem item, bool addWhenBranchingOrLoading = false)
        {
            if ((!Loading && !branching) || addWhenBranchingOrLoading)
            {
                if (pivotLookupDictionary.ContainsKey(item.ID))
                {
                    throw new ExolutioModelException("Item already added into versioning infrastracture. ");
                }

                VersionedItemPivot pivot = new VersionedItemPivot();
                PivotList.Add(pivot);
                pivotLookupDictionary[item.ID] = pivot;
                pivot.PivotMapping.Add(item.Version, item.ID);
            }
        }
Example #11
0
        private static void SubcollectionCheck <TOwner, TMember>(TOwner owner, IVersionedItem other, GetSubcollectionHandler <TOwner, TMember> getSubcollection)
            where TOwner : class, IVersionedItem
            where TMember : ExolutioObject, IVersionedItem
        {
            Assert.IsTrue(other is TOwner);
            TOwner otherT = (TOwner)other;

            foreach (TMember member1 in getSubcollection(owner))
            {
                TMember member2 = member1.GetInVersion(other.Version) as TMember;
                Assert.IsNotNull(member2);
                Assert.AreEqual(member2.Version, other.Version);
                Assert.IsTrue(getSubcollection(otherT).Contains(member2));
            }
        }
Example #12
0
 public void SerializeVersionLinks(XElement versionLinksElement, SerializationContext context)
 {
     foreach (VersionedItemPivot pivot in PivotList)
     {
         XElement linkedItemsElement = new XElement(context.ExolutioNS + "LinkedItems");
         foreach (Guid versionedItemID in pivot.PivotMapping.Values)
         {
             IVersionedItem versionedItem     = (IVersionedItem)Project.TranslateComponent(versionedItemID);
             XElement       linkedItemElement = new XElement(context.ExolutioNS + "LinkedItem");
             Project.SerializeIDRef((IExolutioSerializable)versionedItem, "itemID", linkedItemElement, context);
             Project.SerializeSimpleValueToAttribute("versionNumber", versionedItem.Version.ID, linkedItemElement, context);
             linkedItemsElement.Add(linkedItemElement);
         }
         versionLinksElement.Add(linkedItemsElement);
     }
 }
Example #13
0
        public static void VersionsEquivalent(ProjectVersion version1, ProjectVersion version2)
        {
            Assert.AreEqual(version1.Version.Items.Count, version2.Version.Items.Count);
            VersionItemComparer c = new VersionItemComparer();

            c.Project = version1.Project;
            CollectionAssert.AreEqual(version1.Version.Items, version2.Version.Items, c);

            foreach (IVersionedItem versionedItem in version1.Version.Items)
            {
                IVersionedItem other = versionedItem.GetInVersion(version2.Version);
                Assert.IsNotNull(other);

                RelationsCorrespond(versionedItem, other);
            }
        }
Example #14
0
        /// <summary>
        /// Removes item from versioning infrastructure
        /// </summary>
        public void RemoveVersionedItem(IVersionedItem removedItem)
        {
            if (!PivotLookupDictionary.ContainsKey(removedItem.ID) && branching)
            {
                return;
            }

            VersionedItemPivot pivot          = PivotLookupDictionary[removedItem.ID];
            Version            deletedVersion = removedItem.Version;

            // versioned item is going to be removed, thus it is removed from pivot lookup
            pivotLookupDictionary.Remove(removedItem.ID);
            pivot.PivotMapping.Remove(removedItem.Version.ID);

            if (pivot.PivotMapping.IsEmpty())
            {
                PivotList.Remove(pivot);
            }
        }
Example #15
0
        public void VerifyConsistency()
        {
            foreach (KeyValuePair <Guid, VersionedItemPivot> kvp in PivotLookupDictionary)
            {
                VersionedItemPivot pivot         = kvp.Value;
                IVersionedItem     versionedItem = (IVersionedItem)Project.TranslateComponent(kvp.Key);

                Debug.Assert(pivot.PivotMapping.ContainsKey(versionedItem.Version));
                Debug.Assert(pivot.PivotMapping[versionedItem.Version.ID] == versionedItem.ID);
            }

            foreach (VersionedItemPivot pivot in PivotList)
            {
                foreach (KeyValuePair <Guid, Guid> itemID in pivot.PivotMapping)
                {
                    Version        version    = Project.TranslateComponent <Version>(itemID.Key);
                    IVersionedItem linkedItem = (IVersionedItem)Project.TranslateComponent(itemID.Value);
                    Debug.Assert(PivotLookupDictionary[linkedItem.ID] == pivot);
                }
            }
        }
Example #16
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);
                        }
                    }
                }
            }
        }
Example #17
0
        private static List <LinkedPairInfo> FindLinkedComponents(DiagramView dv2, DiagramView dv1)
        {
            List <LinkedPairInfo> linkedComponents = new List <LinkedPairInfo>();

            foreach (Component component in dv1.Diagram.Schema.SchemaComponents)
            {
                IVersionedItem itemV2 = Current.Project.VersionManager.GetItemInVersion(component, dv2.Diagram.Version);
                if (itemV2 != null)
                {
                    var lpi = new LinkedPairInfo
                    {
                        Element1 = component,
                        Element2 = (Component)itemV2
                    };
                    if (dv1.RepresentantsCollection.ContainsKey(component))
                    {
                        lpi.View1 = dv1.RepresentantsCollection[component];
                        lpi.View2 = dv2.RepresentantsCollection[(Component)itemV2];
                    }
                    linkedComponents.Add(lpi);
                }
            }
            return(linkedComponents);
        }
Example #18
0
        private static void RelationsCorrespond(IVersionedItem versionedItem, IVersionedItem other)
        {
            #region PIMSchema
            {
                PIMSchema PIMSchema1 = versionedItem as PIMSchema;
                if (PIMSchema1 != null)
                {
                    SubcollectionCheck(PIMSchema1, other, owner => owner.PIMAttributes);
                    SubcollectionCheck(PIMSchema1, other, owner => owner.PIMAssociationEnds);
                    SubcollectionCheck(PIMSchema1, other, owner => owner.PIMClasses);
                    SubcollectionCheck(PIMSchema1, other, owner => owner.PIMAssociations);
                }
            }
            #endregion

            #region PIMClass
            {
                PIMClass pimClass1 = versionedItem as PIMClass;
                if (pimClass1 != null)
                {
                    SubcollectionCheck(pimClass1, other, owner => owner.PIMAttributes);
                    SubcollectionCheck(pimClass1, other, owner => owner.PIMAssociationEnds);
                }
            }
            #endregion

            #region PIMAttribute
            {
                PIMAttribute PIMAttribute1 = versionedItem as PIMAttribute;
                if (PIMAttribute1 != null)
                {
                    ReferenceCheck(PIMAttribute1, other, owner => owner.PIMClass);
                    ReferenceCheck(PIMAttribute1, other, owner => owner.AttributeType);
                }
            }
            #endregion

            #region PIMAssociation
            {
                PIMAssociation PIMAssociation1 = versionedItem as PIMAssociation;
                if (PIMAssociation1 != null)
                {
                    SubcollectionCheck(PIMAssociation1, other, owner => owner.PIMClasses);
                    SubcollectionCheck(PIMAssociation1, other, owner => owner.PIMAssociationEnds);
                }
            }
            #endregion

            #region PSMClass
            {
                PSMClass PSMClass1 = versionedItem as PSMClass;
                if (PSMClass1 != null)
                {
                    SubcollectionCheck(PSMClass1, other, owner => owner.PSMAttributes);
                    SubcollectionCheck(PSMClass1, other, owner => owner.ChildPSMAssociations);
                    ReferenceCheck(PSMClass1, other, owner => owner.RepresentedClass);
                    ReferenceCheck(PSMClass1, other, owner => owner.ParentAssociation);
                }
            }
            #endregion

            #region PSMAttribute
            {
                PSMAttribute PSMAttribute1 = versionedItem as PSMAttribute;
                if (PSMAttribute1 != null)
                {
                    ReferenceCheck(PSMAttribute1, other, owner => owner.PSMClass);
                    ReferenceCheck(PSMAttribute1, other, owner => owner.AttributeType);
                }
            }
            #endregion

            #region PSMAssociation
            {
                PSMAssociation PSMAssociation1 = versionedItem as PSMAssociation;
                if (PSMAssociation1 != null)
                {
                    ReferenceCheck(PSMAssociation1, other, owner => owner.Parent);
                    ReferenceCheck(PSMAssociation1, other, owner => owner.Child);
                }
            }
            #endregion

            #region PSMContentModel
            {
                PSMContentModel PSMContentModel1 = versionedItem as PSMContentModel;
                if (PSMContentModel1 != null)
                {
                    SubcollectionCheck(PSMContentModel1, other, owner => owner.ChildPSMAssociations);
                    ReferenceCheck(PSMContentModel1, other, owner => owner.ParentAssociation);
                }
            }
            #endregion

            #region PSMSchema
            {
                PSMSchema PSMSchema1 = versionedItem as PSMSchema;
                if (PSMSchema1 != null)
                {
                    SubcollectionCheck(PSMSchema1, other, owner => owner.PSMAttributes);
                    SubcollectionCheck(PSMSchema1, other, owner => owner.PSMContentModels);
                    SubcollectionCheck(PSMSchema1, other, owner => owner.PSMClasses);
                    SubcollectionCheck(PSMSchema1, other, owner => owner.PSMAssociations);
                    SubcollectionCheck(PSMSchema1, other, owner => owner.PSMSchemaReferences);
                    SubcollectionCheck(PSMSchema1, other, owner => owner.Roots);

                    ReferenceCheck(PSMSchema1, other, owner => owner.PSMSchemaClass);
                }
            }
            #endregion
        }
Example #19
0
 public void Set(IVersionedItem item1, IVersionedItem item2)
 {
     Item1ID = item1.ID;
     Item2ID = item2.ID;
 }
Example #20
0
 public static IVersionedItem GetInVersion(this IVersionedItem item, Version version)
 {
     return(item.ProjectVersion.Project.VersionManager.GetItemInVersion(item, version));
 }
Example #21
0
 /// <summary>
 /// Initializes a new <see cref="TfsSourceControlledItem"/>.
 /// </summary>
 /// <param name="item">The source controlled item.</param>
 /// <param name="versionControl">The item's associated TFS source control</param>
 protected TfsSourceControlledItem(IVersionedItem item, IVersionControl versionControl)
 {
     Item           = item;
     VersionControl = versionControl;
 }
 /// <summary>
 /// Initializes a new <see cref="TfsDirectory"/>.
 /// </summary>
 /// <param name="item">The source controlled file</param>
 /// <param name="versionControl">TFS source control</param>
 public TfsDirectory(IVersionedItem item, IVersionControl versionControl)
     : base(item, versionControl)
 {
 }
Example #23
0
 public static bool ExistsInVersion(this IVersionedItem item, Version version)
 {
     return(item.ProjectVersion.Project.VersionManager.GetItemInVersion(item, version) != null);
 }
Example #24
0
 public bool AreItemsLinked(IVersionedItem item1, IVersionedItem item2)
 {
     return(pivotLookupDictionary[item1.ID] == pivotLookupDictionary[item2.ID]);
 }
 /// <summary>
 /// Initializes a new <see cref="TfsSourceControlledItem"/>.
 /// </summary>
 /// <param name="item">The source controlled item.</param>
 /// <param name="versionControl">The item's associated TFS source control</param>
 protected TfsSourceControlledItem(IVersionedItem item, IVersionControl versionControl)
 {
     Item = item;
     VersionControl = versionControl;
 }
 /// <summary>
 /// Initializes a new <see cref="TfsSolution"/>.
 /// </summary>
 /// <param name="solutionItem">The source contorlled solution file</param>
 /// <param name="versionControl">TFS source control</param>
 public TfsSolution(IVersionedItem solutionItem, IVersionControl versionControl)
     : base(solutionItem, versionControl)
 {
 }
Example #27
0
 /// <summary>
 /// Initializes a new <see cref="TfsFile"/>.
 /// </summary>
 /// <param name="fileItem">The source controlled file</param>
 /// <param name="versionControl">TFS source control</param>
 public TfsFile(IVersionedItem fileItem, IVersionControl versionControl)
     : base(fileItem, versionControl)
 {
 }
Example #28
0
        public void UnregisterVersionLink(IVersionedItem item1, IVersionedItem item2, IEnumerable <IVersionedItem> group1 = null, IEnumerable <IVersionedItem> group2 = null)
        {
            if (!AreItemsLinked(item1, item2))
            {
                throw new ExolutioModelException();
            }

            VersionedItemPivot pivot;

            if (!pivotLookupDictionary.TryGetValue(item1.ID, out pivot))
            {
                throw new ExolutioModelException();
            }

            if (group1 == null && group2 == null)
            {
                group1 = new List <IVersionedItem>(pivot.PivotMapping.Where(kvp => kvp.Key != item2.Version.ID).
                                                   Select(kvp => (IVersionedItem)Project.TranslateComponent(kvp.Value)));
                group2 = new IVersionedItem[] { item2 };
            }

            if (group1 == null)
            {
                group1 = new List <IVersionedItem>(pivot.PivotMapping.Where(kvp => !group2.Contains((IVersionedItem)Project.TranslateComponent(kvp.Value))).
                                                   Select(kvp => (IVersionedItem)Project.TranslateComponent(kvp.Value)));
            }
            if (group2 == null)
            {
                group2 = new List <IVersionedItem>(pivot.PivotMapping.Where(kvp => !group1.Contains((IVersionedItem)Project.TranslateComponent(kvp.Value))).
                                                   Select(kvp => (IVersionedItem)Project.TranslateComponent(kvp.Value)));
            }

            {
                VersionedItemPivot pivot1 = new VersionedItemPivot();
                PivotList.Add(pivot1);
                foreach (IVersionedItem versionedItem in group1)
                {
                    pivot1.PivotMapping[versionedItem.Version.ID] = versionedItem.ID;
                    pivotLookupDictionary[versionedItem.ID]       = pivot1;
                }
            }

            {
                VersionedItemPivot pivot2 = new VersionedItemPivot();
                PivotList.Add(pivot2);
                foreach (IVersionedItem versionedItem in group2)
                {
                    pivot2.PivotMapping[versionedItem.Version.ID] = versionedItem.ID;
                    pivotLookupDictionary[versionedItem.ID]       = pivot2;
                }
            }

            foreach (KeyValuePair <Guid, Guid> keyValuePair in pivot.PivotMapping)
            {
                IVersionedItem item = (IVersionedItem)Project.TranslateComponent(keyValuePair.Value);
                if (!group1.Contains(item) && !group2.Contains(item))
                {
                    throw new ExolutioModelException();
                }
            }

            PivotList.Remove(pivot);

#if DEBUG
            VerifyConsistency();
#endif
        }
Example #29
0
        public void RegisterVersionLink(Version version1, Version version2, IVersionedItem itemVersion1, IVersionedItem itemVersion2)
        {
            if (version1 != itemVersion1.Version)
            {
                throw new ExolutioModelException(Exceptions.VersionManager_RegisterVersionLink_itemOldVersion_Version_must_point_to_the_same_object_as_oldVersion);
            }

            if (itemVersion1.GetType() != itemVersion2.GetType())
            {
                throw new ExolutioModelException();
            }

            VersionedItemPivot pivot1;
            VersionedItemPivot pivot2;

            VersionedItemPivot pivot;

            pivotLookupDictionary.TryGetValue(itemVersion1.ID, out pivot1);
            pivotLookupDictionary.TryGetValue(itemVersion2.ID, out pivot2);

            if (pivot1 == null && pivot2 == null) // new pivot is created
            {
                AddVersionedItem(itemVersion1, true);
                pivot = pivotLookupDictionary[itemVersion1.ID];
                pivotLookupDictionary[itemVersion2.ID] = pivot;
                pivot.PivotMapping[version2]           = itemVersion2.ID;
            }
            else if (pivot1 == null) //existing pivot is used
            {
                pivot = pivot2;
                pivotLookupDictionary[itemVersion1.ID] = pivot;
                pivot.PivotMapping[version1]           = itemVersion1.ID;
            }
            else if (pivot2 == null) //existing pivot is used
            {
                pivot = pivot1;
                pivotLookupDictionary[itemVersion2.ID] = pivot;
                pivot.PivotMapping[version2]           = itemVersion2.ID;
            }
            else // in this case the two existing pivots are merged
            {
                pivot = new VersionedItemPivot();
                PivotList.Add(pivot);
                PivotList.Remove(pivot1);
                PivotList.Remove(pivot2);
                foreach (KeyValuePair <Guid, Guid> keyValuePair in pivot1.PivotMapping)
                {
                    Guid versionGuid = keyValuePair.Key;
                    Guid itemGuid    = keyValuePair.Value;
                    pivotLookupDictionary[itemGuid] = pivot;
                    pivot.PivotMapping[versionGuid] = itemGuid;
                }
                foreach (KeyValuePair <Guid, Guid> keyValuePair in pivot2.PivotMapping)
                {
                    Guid versionGuid = keyValuePair.Key;
                    Guid itemGuid    = keyValuePair.Value;
                    pivotLookupDictionary[itemGuid] = pivot;
                    pivot.PivotMapping[versionGuid] = itemGuid;
                }
            }
#if DEBUG
            VerifyConsistency();
#endif
        }
Example #30
0
 /// <summary>
 /// Initializes a new <see cref="TfsSolution"/>.
 /// </summary>
 /// <param name="solutionItem">The source contorlled solution file</param>
 /// <param name="versionControl">TFS source control</param>
 public TfsSolution(IVersionedItem solutionItem, IVersionControl versionControl)
     : base(solutionItem, versionControl)
 {
 }
Example #31
0
        public IEnumerable <IVersionedItem> GetAllVersionsOfItem(IVersionedItem item)
        {
            VersionedItemPivot pivot = PivotLookupDictionary[item.ID];

            return(pivot.PivotMapping.Values.Select(ID => (IVersionedItem)Project.TranslateComponent(ID)));
        }
Example #32
0
 /// <summary>
 /// Initializes a new <see cref="TfsFile"/>.
 /// </summary>
 /// <param name="fileItem">The source controlled file</param>
 /// <param name="versionControl">TFS source control</param>
 public TfsFile(IVersionedItem fileItem, IVersionControl versionControl)
     : base(fileItem, versionControl)
 {
 }