Ejemplo n.º 1
0
        public void PreserveNullIDsTest()
        {
            Guid testId = Guid.NewGuid();

            GuidMap map = new GuidMap();

            Assert.AreEqual(null, map.MapId(null));
        }
Ejemplo n.º 2
0
        public void EnsureIDRelationshipTest()
        {
            Guid testId = Guid.NewGuid();

            GuidMap map = new GuidMap();

            Assert.AreEqual(map.MapId(testId), map.MapId(testId));
            Assert.AreNotEqual(map.MapId(testId), map.MapId(Guid.NewGuid()));
        }
Ejemplo n.º 3
0
        public Guid MapujGuid(Guid zrodlo, string tabela)
        {
            GuidMap guidMap = ContextManager.WebContext.GuidMaps.Where(m => m.Zrodlo == zrodlo && m.Tabela == tabela).FirstOrDefault();

            if (guidMap != null)
            {
                return((Guid)guidMap.Cel);
            }
            return(zrodlo);
        }
Ejemplo n.º 4
0
        Nullable <Guid> GetParentId(string child)
        {
            string strParent = this.GetStringParent(child);

            if (!GuidMap.ContainsKey(strParent))
            {
                Guid newGuid = Guid.NewGuid();
                GuidMap.Add(strParent, newGuid);
                return(newGuid);
            }
            Nullable <Guid> nullGuid = null;

            return((!strParent.Equals("ROOT")) ? GuidMap[strParent] : nullGuid);
        }
Ejemplo n.º 5
0
        private void UpdateProjectReferences(Project project, IList <MksProjectFile> mksProjectFiles, ProjectItem[] sysRefs)
        {
            var projectGuidMap = new GuidMap();

            foreach (var mksProjectFile in mksProjectFiles)
            {
                var originalNameSpace = mksProjectFile.NameSpace.Replace(nameSpacePrefix, originalNameSpacePrefix);
                var projectRefs       = mksProjectFile.ProjectItems
                                        .SelectMany(c => c.References)
                                        .Where(d => d.StartsWith("MKS") && d.StartsWith(originalNameSpace) == false)
                                        .Distinct();

                var projectNames = projectRefs

                                   .Select(c => c.Remove(0, 4).Split('.'))
                                   .Select(c => c.Take(2).ConcatToString(""));

                var ItemGroup = new XElement("ItemGroup");
                foreach (var projectRef in projectNames)
                {
                    var listOfProjects = new List <XElement>();
                    if (projectGuidMap.ProjectGuidMap.ContainsKey(projectRef))
                    {
                        var guid           = projectGuidMap.ProjectGuidMap[projectRef];
                        var foo            = mksProjectFiles.FirstOrDefault(c => c.AssemblyName == projectRef);
                        var IncludePath    = mksProjectFile.AbsoluteTargetUri.MakeRelativeUri(foo.AbsoluteTargetUri).ToString().Replace('/', '\\');
                        var projectElement = new XElement(
                            new XElement("ProjectReference"
                                         , new XAttribute("Include", IncludePath)
                                         , new XElement("Project", guid)
                                         , new XElement("Name", projectRef)
                                         ));
                        listOfProjects.Add(projectElement);
                    }

                    if (listOfProjects.Count > 0)
                    {
                        foreach (var element in listOfProjects)
                        {
                            ItemGroup.Add(element);
                        }
                    }
                }

                mksProjectFile.XML = mksProjectFile.XML.Replace(@"  <BeginInsertion />",
                                                                @"  <BeginInsertion />" + "\r\n" + ItemGroup.ToString());
            }
        }
Ejemplo n.º 6
0
        private void UpdateSystemReferences(Project project, List <MksProjectFile> mksProjectFiles, ProjectItem[] allReferences)
        {
            var projectGuidMap = new GuidMap();


            var projectRefsWithoutHint = project.Items.Where(c =>
                                                             c.ItemType == "Reference" &&
                                                             c.DirectMetadata.Any(d => d.Name == "HintPath") == false).ToArray();

            foreach (var mksProject in mksProjectFiles)
            {
                var itemGroup = new XElement("ItemGroup");
                foreach (var sysRef in projectRefsWithoutHint)
                {
                    itemGroup.Add(new XElement("Reference"
                                               , new  XAttribute("Include", sysRef.EvaluatedInclude)

                                               ));
                }

                mksProject.XML = mksProject.XML.Replace(@"  <BeginInsertion />",
                                                        @"  <BeginInsertion />" + "\r\n" + itemGroup.ToString());
            }
        }
Ejemplo n.º 7
0
 void InitRoot()
 {
     GuidMap.Add("ROOT", Guid.NewGuid());
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new map entry for the oldGuid. This generates a new Guid and
        /// stores a reference between the two.
        /// </summary>
        /// <param name="oldGuid">The original Guid value to be mapped from.</param>
        /// <returns>A new Guid value that should be used in place of oldGuid.</returns>
        protected Guid MapNewGuid(Guid oldGuid)
        {
            GuidMap.Add(oldGuid, Guid.NewGuid());

            return(GuidMap[oldGuid]);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a new entity in the database from the encoded information. The entity
        /// is saved before being returned.
        /// </summary>
        /// <param name="encodedEntity">The encoded entity information to create the new entity from.</param>
        /// <returns>A reference to the new entity.</returns>
        protected IEntity CreateNewEntity(EncodedEntity encodedEntity)
        {
            Type entityType = Reflection.FindType(typeof(IEntity), encodedEntity.EntityType);
            var  service    = Reflection.GetServiceForEntityType(entityType, RockContext);

            if (service != null)
            {
                var addMethod = service.GetType().GetMethod("Add", new Type[] { entityType });

                if (addMethod != null)
                {
                    IEntity entity = ( IEntity )Activator.CreateInstance(entityType);

                    RestoreEntityProperties(entity, encodedEntity);
                    entity.Guid = FindMappedGuid(encodedEntity.Guid);

                    //
                    // Do custom pre-save processing.
                    //
                    foreach (var processor in FindEntityProcessors(entityType))
                    {
                        processor.ProcessImportedEntity(entity, encodedEntity, encodedEntity.GetTransformData(processor.Identifier.ToString()), this);
                    }

                    //
                    // Special handling of AttributeQualifier because Guids may not be the same
                    // across installations and the AttributeId+Key columns make up a unique key.
                    //
                    if (encodedEntity.EntityType == "Rock.Model.AttributeQualifier")
                    {
                        var    reference = encodedEntity.References.Where(r => r.Property == "AttributeId").First();
                        var    attribute = GetExistingEntity("Rock.Model.Attribute", FindMappedGuid(new Guid(( string )reference.Data)));
                        string key       = ( string )encodedEntity.Properties["Key"];

                        var existingEntity = new AttributeQualifierService(RockContext)
                                             .GetByAttributeId(attribute.Id)
                                             .Where(a => a.Key == key)
                                             .FirstOrDefault();

                        if (existingEntity != null)
                        {
                            if (entity.Guid != encodedEntity.Guid)
                            {
                                throw new Exception("AttributeQualifier marked for new Guid but conflicting value already exists.");
                            }

                            GuidMap.AddOrReplace(encodedEntity.Guid, existingEntity.Guid);

                            return(existingEntity);
                        }
                    }

                    //
                    // Special handling of Attribute's. The guid's might be different but if the entity type,
                    // entity qualifiers and key are the same, assume it's the same.
                    //
                    else if (encodedEntity.EntityType == "Rock.Model.Attribute")
                    {
                        var attribute      = (Rock.Model.Attribute)entity;
                        var existingEntity = new AttributeService(RockContext)
                                             .GetByEntityTypeId(attribute.EntityTypeId)
                                             .Where(a => a.EntityTypeQualifierColumn == attribute.EntityTypeQualifierColumn && a.EntityTypeQualifierValue == attribute.EntityTypeQualifierValue && a.Key == attribute.Key)
                                             .FirstOrDefault();

                        if (existingEntity != null)
                        {
                            if (entity.Guid != encodedEntity.Guid)
                            {
                                throw new Exception("Attribute marked for new Guid but conflicting value already exists.");
                            }

                            GuidMap.AddOrReplace(encodedEntity.Guid, existingEntity.Guid);

                            return(existingEntity);
                        }
                    }

                    //
                    // Special handling of AttributeValue's. The guid's might be different but if the attribute Id
                    // and entity Id are the same, assume it's the same.
                    //
                    else if (encodedEntity.EntityType == "Rock.Model.AttributeValue")
                    {
                        var attributeReference = encodedEntity.References.Where(r => r.Property == "AttributeId").First();
                        var attribute          = GetExistingEntity("Rock.Model.Attribute", FindMappedGuid(new Guid(( string )attributeReference.Data)));
                        var entityReference    = encodedEntity.References.Where(r => r.Property == "EntityId").First();
                        var entityRef          = GetExistingEntity(entityReference.EntityType, FindMappedGuid(new Guid(( string )entityReference.Data)));

                        var existingEntity = new AttributeValueService(RockContext)
                                             .Queryable().Where(a => a.AttributeId == attribute.Id && a.EntityId == entityRef.Id)
                                             .FirstOrDefault();

                        if (existingEntity != null)
                        {
                            if (entity.Guid != encodedEntity.Guid)
                            {
                                throw new Exception("AttributeValue marked for new Guid but conflicting value already exists.");
                            }

                            GuidMap.AddOrReplace(encodedEntity.Guid, existingEntity.Guid);

                            return(existingEntity);
                        }
                    }

                    addMethod.Invoke(service, new object[] { entity });
                    RockContext.SaveChanges(true);

                    return(entity);
                }
            }

            throw new Exception(string.Format("Failed to create new database entity for {0}_{1}", encodedEntity.EntityType, encodedEntity.Guid));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Finds and returns a Guid from the mapping dictionary. If no mapping
 /// exists then the original Guid is returned.
 /// </summary>
 /// <param name="oldGuid">The original Guid value to map from.</param>
 /// <returns>The Guid value that should be used, may be the same as oldGuid.</returns>
 public Guid FindMappedGuid(Guid oldGuid)
 {
     return(GuidMap.ContainsKey(oldGuid) ? GuidMap[oldGuid] : oldGuid);
 }