public void ConfigMapProperties_MapsAllPropertiesToConfiguration()
        {
            //Assign
            FinalStubMap    finalStubMap    = new FinalStubMap();
            PartialStub1Map partialStub1Map = new PartialStub1Map();
            StubBaseMap     stubBaseMap     = new StubBaseMap();
            PartialStub2Map partialStub2Map = new PartialStub2Map();

            UmbracoFluentConfigurationLoader loader = new UmbracoFluentConfigurationLoader();
            ConfigurationMap configMap = new ConfigurationMap(new IGlassMap[] { partialStub1Map, stubBaseMap, partialStub2Map, finalStubMap });

            configMap.Load(loader);

            //Act
            finalStubMap.PerformMap(loader);
            partialStub1Map.PerformMap(loader);
            stubBaseMap.PerformMap(loader);
            partialStub2Map.PerformMap(loader);

            //Assert
            Assert.AreEqual(5, finalStubMap.GlassType.Config.Properties.Count());
            UmbracoPropertyConfiguration fieldNameProperty = finalStubMap.GlassType.Config.Properties.FirstOrDefault(x => x.PropertyInfo.Name == "FieldName") as UmbracoPropertyConfiguration;

            Assert.AreEqual("Field Name", fieldNameProperty.PropertyName);

            UmbracoInfoConfiguration qwertyProperty = finalStubMap.GlassType.Config.Properties.FirstOrDefault(x => x.PropertyInfo.Name == "Qwerty") as UmbracoInfoConfiguration;

            Assert.AreEqual(UmbracoInfoType.Name, qwertyProperty.Type);

            Assert.IsNotNull(finalStubMap.GlassType.Config.IdConfig);
        }
Exemplo n.º 2
0
        public void ConfigMapProperties_ImportMap_CanOverrideExistingPropertyConfig()
        {
            //Assign
            FinalStubMap         finalStubMap         = new FinalStubMap();
            FinalStubSubClassMap finalStubSubClassMap = new FinalStubSubClassMap();
            PartialStub1Map      partialStub1Map      = new PartialStub1Map();
            PartialStub2Map      partialStub2Map      = new PartialStub2Map();
            StubBaseMap          stubBaseMap          = new StubBaseMap();

            SitecoreFluentConfigurationLoader loader = new SitecoreFluentConfigurationLoader();
            ConfigurationMap configMap = new ConfigurationMap(new IGlassMap[] { partialStub1Map, stubBaseMap, partialStub2Map, finalStubMap, finalStubSubClassMap });

            configMap.Load(loader);

            //Act
            finalStubMap.PerformMap(loader);
            finalStubSubClassMap.PerformMap(loader);

            //Assert
            Assert.AreEqual(5, finalStubSubClassMap.GlassType.Config.Properties.Count());
            SitecoreFieldConfiguration fieldNameProperty = finalStubSubClassMap.GlassType.Config.Properties.FirstOrDefault(x => x.PropertyInfo.Name == "FieldName") as SitecoreFieldConfiguration;

            Assert.AreEqual("Field Other Name", fieldNameProperty.FieldName);

            SitecoreInfoConfiguration qwertyProperty = finalStubSubClassMap.GlassType.Config.Properties.FirstOrDefault(x => x.PropertyInfo.Name == "Qwerty") as SitecoreInfoConfiguration;

            Assert.AreEqual(SitecoreInfoType.Name, qwertyProperty.Type);

            Assert.IsNotNull(finalStubSubClassMap.GlassType.Config.IdConfig);
        }
        public void General_RetrieveItemAndFieldsFromSitecore_ReturnPopulatedDerivedClass()
        {
            //Assign
            string fieldValue = "test field value";
            Guid   id         = new Guid("{A544AE18-BC21-457D-8852-438F53AAE7E1}");
            string name       = "Target";

            var db = Sitecore.Configuration.Factory.GetDatabase("master");

            DependencyResolver resolver = Utilities.CreateStandardResolver() as DependencyResolver;

            resolver.Container.Register(Component.For <IDependencyResolver>().Instance(resolver));

            resolver.Container.Register(
                Component.For <IGlassMap, SitecoreGlassMap <SuperStub> >()
                .ImplementedBy <SuperStubMap>()
                .LifestyleCustom <NoTrackLifestyleManager>());
            resolver.Container.Register(
                Component.For <IGlassMap, SitecoreGlassMap <IStub> >()
                .ImplementedBy <StubInterfaceMap>()
                .LifestyleCustom <NoTrackLifestyleManager>());
            resolver.Container.Register(
                Component.For <IGlassMap, SitecoreGlassMap <Stub> >()
                .ImplementedBy <StubMap>()
                .LifestyleCustom <NoTrackLifestyleManager>());

            var context = Context.Create(resolver);

            var loader = new SitecoreFluentConfigurationLoader();

            ConfigurationMap map = new ConfigurationMap(resolver);

            map.Load(loader);
            context.Load(loader);

            var item = db.GetItem(new ID(id));

            using (new ItemEditing(item, true))
            {
                item["Field"] = fieldValue;
            }

            var service = new SitecoreService(db, context);

            //Act
            var result = service.GetItem <SuperStub>(id);

            //Assert
            Assert.AreEqual(fieldValue, result.Field);
            Assert.AreEqual(id, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.AreEqual("/en/sitecore/content/Tests/Configuration/Fluent/Target.aspx", result.Url);
            Assert.AreEqual("Random String", result.DelegatedField);
        }
        public void ConfigMapProperties_MapsSinglePropertyToConfiguration()
        {
            //Assign
            StubBaseMap stubMap = new StubBaseMap();
            SitecoreFluentConfigurationLoader loader = new SitecoreFluentConfigurationLoader();
            ConfigurationMap configMap = new ConfigurationMap(new IGlassMap[] { stubMap });
            configMap.Load(loader);

            //Act
            stubMap.PerformMap(loader);

            //Assert
            Assert.AreEqual(1, stubMap.GlassType.Config.Properties.Count());
            Assert.IsNull(stubMap.GlassType.Config.ItemConfig);            
        }
        public static void LoadConfigurationMaps(IDependencyResolver resolver, Glass.Mapper.Context context)
        {
            var dependencyResolver = resolver as DependencyResolver;
            if (dependencyResolver == null)
            {
                return;
            }

            if (dependencyResolver.ConfigurationMapFactory is ConfigurationMapConfigFactory)
            {
                GlassMapperScCustom.AddMaps(dependencyResolver.ConfigurationMapFactory);
            }

            IConfigurationMap configurationMap = new ConfigurationMap(dependencyResolver);
            SitecoreFluentConfigurationLoader configurationLoader = configurationMap.GetConfigurationLoader<SitecoreFluentConfigurationLoader>();
            context.Load(configurationLoader);
        }
Exemplo n.º 6
0
        public void Issue254_Test()
        {
            MapStubWithChildren mapStubWithChildren = new MapStubWithChildren();
            MapStubInherit1     mapStubInherit1     = new MapStubInherit1();
            MapStubInherit2     mapStubInherit2     = new MapStubInherit2();

            SitecoreFluentConfigurationLoader loader = new SitecoreFluentConfigurationLoader();
            ConfigurationMap configMap = new ConfigurationMap(new IGlassMap[] { mapStubWithChildren, mapStubInherit1, mapStubInherit2 });

            configMap.Load(loader);

            //Assert
            //Assert
            Assert.IsTrue(mapStubWithChildren.GlassType.Config.Properties.Any(x => x is SitecoreChildrenConfiguration));
            Assert.IsTrue(mapStubInherit1.GlassType.Config.Properties.Any(x => x is SitecoreChildrenConfiguration));
            Assert.IsTrue(mapStubInherit2.GlassType.Config.Properties.Any(x => x is SitecoreChildrenConfiguration));
        }
Exemplo n.º 7
0
        public override string SetPropertyValue(string key, string value)
        {
            string oldValue = null;

            ConfigurationMap.AddOrUpdate(key, value, (k, v) => { oldValue = v; return(value); });
            if (OnChange != null && !object.Equals(oldValue, value))
            {
                var changedProperties = new PropertyChangedEventArgs[1];
                changedProperties[0] = new PropertyChangedEventArgs(key, oldValue, value);
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(1000);
                    OnChange(this, new ConfigurationChangedEventArgs(changedProperties));
                });
            }
            return(oldValue);
        }
Exemplo n.º 8
0
        public static void LoadConfigurationMaps(IDependencyResolver resolver, Glass.Mapper.Context context)
        {
            var dependencyResolver = resolver as DependencyResolver;

            if (dependencyResolver == null)
            {
                return;
            }

            if (dependencyResolver.ConfigurationMapFactory is ConfigurationMapConfigFactory)
            {
                GlassMapperScCustom.AddMaps(dependencyResolver.ConfigurationMapFactory);
            }

            IConfigurationMap configurationMap = new ConfigurationMap(dependencyResolver);
            SitecoreFluentConfigurationLoader configurationLoader = configurationMap.GetConfigurationLoader <SitecoreFluentConfigurationLoader>();

            context.Load(configurationLoader);
        }
Exemplo n.º 9
0
        public static ConfigurationMap CreateMap <TSource, TDestination>()
        {
            var conf = ConfigurationMaps.FirstOrDefault(cm => cm.SourceType.Equals(typeof(TSource)) &&
                                                        cm.DestinationType.Equals(typeof(TDestination)));

            if (conf == null)
            {
                conf = new ConfigurationMap()
                {
                    SourceType      = typeof(TSource),
                    DestinationType = typeof(TDestination)
                };

                var destProp  = conf.DestinationType.GetProperties();
                var propNames = destProp.Select(p => p.Name).ToList();

                conf.SourceType.GetProperties().Where(p => propNames.Contains(p.Name))
                .ToList()
                .ForEach(pi => conf.MembersForMap.Add(pi.Name, pi.Name));


                List <MemberInfo> sourceMembers = conf.SourceType
                                                  .GetProperties(BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.IgnoreCase)
                                                  .ToList <MemberInfo>();
                sourceMembers.AddRange(conf.DestinationType
                                       .GetFields(BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic));

                //Находим соответствующие наименования полей и строим карту маппинга
                sourceMembers.ForEach(sm =>
                {
                    var dm = conf.DestinationType.GetMember(sm.Name, BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.IgnoreCase).FirstOrDefault();
                    if (dm != null)
                    {
                        conf.MembersMap.Add(sm, dm);
                    }
                });

                ConfigurationMaps.Add(conf);
            }

            return(conf);
        }
Exemplo n.º 10
0
    private void Awake()
    {
        inst = this;

        // Create the ground and establish the size and position.
        if (groundPrefab == null)
        {
            groundPrefab = Resources.Load("Ground") as GameObject;
            groundPrefab = Instantiate(groundPrefab);
        }
        groundPrefab.transform.position = new Vector3(0, -0.01f, 0);
        groundPrefab.name = "Ground";

        horizontalMapSize = (columns + 1) * nodeDistance;
        verticalMapSize   = ((Mathf.Sqrt(3) * nodeDistance) / 2) * (rows + 1);
        groundPrefab.transform.localScale = new Vector3(verticalMapSize, horizontalMapSize, 1);
        groundOffset = new Vector3(-verticalMapSize / 2f, 0, -horizontalMapSize / 2f);

        nodeOffset = new Vector3(-(verticalMapSize - (2 * (Mathf.Sqrt(3) * nodeDistance) / 2f)) / 2f, 0, -(horizontalMapSize - (2 * nodeDistance)) / 2f);

        // Create the tower prefab and establish the tower positioning information.
        if (towerPrefab == null)
        {
            towerPrefab = Resources.Load("Tower") as GameObject;
            towerPrefab = Instantiate(towerPrefab);
        }
        towerPrefab.name = "Tower";

        Vector3 towerPosition = groundOffset + new Vector3(towerPosX * verticalMapSize, 2 * uavHeight, towerPosZ * horizontalMapSize);

        towerPrefab.transform.localScale = new Vector3(1, towerPosition.y, 1);
        towerPrefab.transform.position   = new Vector3(towerPosition.x, towerPosition.y / 2, towerPosition.z);

        // Adjust the main camera to fit the size of the map.
        Camera.main.orthographicSize = Mathf.Max(horizontalMapSize, verticalMapSize) / 2f;

        visualsFolder = new GameObject();
        visualsFolder.transform.parent = transform;
        visualsFolder.name             = "VisualsFolder";
    }
Exemplo n.º 11
0
        public Solution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver) {
            Regex reProjects = new Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""(?<all>[\s\S]*?)EndProject", RegexOptions.Multiline);
            MatchCollection projectMatches = reProjects.Matches(solutionContent);

            Hashtable explicitProjectDependencies = CollectionsUtil.CreateCaseInsensitiveHashtable();

            foreach (Match projectMatch in projectMatches) {
                string project = projectMatch.Groups["project"].Value;
                string guid = projectMatch.Groups["guid"].Value;

                // translate partial project path or URL to absolute path
                string fullProjectPath = TranslateProjectPath(solutionTask.SolutionFile.DirectoryName,
                    project);

                // check if project file actually exists
                if (!System.IO.File.Exists(fullProjectPath)) {
                    throw CreateProjectDoesNotExistException(fullProjectPath);
                }

                if (ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath)) {
                    RecursiveLoadTemplateProject(fullProjectPath);
                } else {
                    // add project path to collection
                    ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath));
                }

                // set-up project dependencies
                Regex reDependencies = new Regex(@"^\s+" + guid + @"\.[0-9]+ = (?<dep>\{\S*\}?)\s*$", RegexOptions.Multiline);
                MatchCollection dependencyMatches = reDependencies.Matches(solutionContent);

                foreach (Match dependencyMatch in dependencyMatches) {
                    string dependency = dependencyMatch.Groups["dep"].Value;

                    if (!explicitProjectDependencies.ContainsKey(guid)) {
                        explicitProjectDependencies[guid] = CollectionsUtil.CreateCaseInsensitiveHashtable();
                    }
                    ((Hashtable) explicitProjectDependencies[guid])[dependency] = null;
                }

                // set-up project configuration 
                Regex reProjectBuildConfig = new Regex(@"^\s+" + guid + @"\.(?<solutionConfiguration>[^|]+)\|?(?<solutionPlatform>[^\.]?)\.Build\.0\s*=\s*(?<projectConfiguration>[^|]+)\|(?<projectPlatform>[\.\w ]+)\s*", RegexOptions.Multiline);
                MatchCollection projectBuildMatches = reProjectBuildConfig.Matches(solutionContent);

                ProjectEntry projectEntry = ProjectEntries [guid];
                if (projectEntry == null) {
                    // TODO: determine if we should report an error if a build
                    // configuration is defined for a project that does not
                    // exist in the solution
                    continue;
                }

                // holds mapping between project configuration(s) and solution(s)
                ConfigurationMap buildConfigurations = new ConfigurationMap(
                    projectBuildMatches.Count);

                for (int i = 0; i < projectBuildMatches.Count; i++) {
                    Match projectBuildMatch = projectBuildMatches [i];
                    string solutionConfigName = projectBuildMatch.Groups["solutionConfiguration"].Value;
                    string solutionPlatform = projectBuildMatch.Groups["solutionPlatform"].Value;
                    string projectConfigName = projectBuildMatch.Groups["projectConfiguration"].Value;
                    string projectPlatform = projectBuildMatch.Groups["projectPlatform"].Value;
                    Configuration solutionConfig = new Configuration(
                        solutionConfigName, solutionPlatform);
                    Configuration projectConfig = new Configuration(
                        projectConfigName, projectPlatform);
                    buildConfigurations [solutionConfig] = projectConfig;
                }

                // add map to corresponding project entry
                projectEntry.BuildConfigurations = buildConfigurations;
            }

            LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false);
            LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true);
            LoadProjects(gacCache, refResolver, explicitProjectDependencies);
        }
Exemplo n.º 12
0
        public Solution(string solutionContent, SolutionTask solutionTask, TempFileCollection tfc, GacCache gacCache, ReferencesResolver refResolver) : base(solutionTask, tfc, gacCache, refResolver)
        {
            Regex           reProjects     = new Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""(?<all>[\s\S]*?)EndProject", RegexOptions.Multiline);
            MatchCollection projectMatches = reProjects.Matches(solutionContent);

            Hashtable explicitProjectDependencies = CollectionsUtil.CreateCaseInsensitiveHashtable();

            foreach (Match projectMatch in projectMatches)
            {
                string project = projectMatch.Groups["project"].Value;
                string guid    = projectMatch.Groups["guid"].Value;

                // translate partial project path or URL to absolute path
                string fullProjectPath = TranslateProjectPath(solutionTask.SolutionFile.DirectoryName,
                                                              project);

                // check if project file actually exists
                if (!System.IO.File.Exists(fullProjectPath))
                {
                    throw CreateProjectDoesNotExistException(fullProjectPath);
                }

                bool isEnterpriseTemplateProject = ManagedProjectBase.IsEnterpriseTemplateProject(fullProjectPath);
                if (isEnterpriseTemplateProject)
                {
                    RecursiveLoadTemplateProject(fullProjectPath);
                }
                else
                {
                    // add project entry to collection
                    ProjectEntries.Add(new ProjectEntry(guid, fullProjectPath));
                }

                // set-up project dependencies
                Regex           reDependencies    = new Regex(@"^\s+(?<guid>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})\s+=\s+(?<dep>\{[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}\})", RegexOptions.Multiline);
                MatchCollection dependencyMatches = reDependencies.Matches(projectMatch.Value);

                foreach (Match dependencyMatch in dependencyMatches)
                {
                    string dependency = dependencyMatch.Groups["dep"].Value;
                    // bug #1534864: an Enterprise Template project actually
                    // defines dependencies for the projects it contains, and
                    // is not added as a project itself
                    //
                    // Note: for non-ET projects both the "guid" and "dep" group
                    // have the same value, which is the guid of the project
                    // that the project containing the dependencies section
                    // depends upon
                    string projectGuid = isEnterpriseTemplateProject ?
                                         dependencyMatch.Groups["guid"].Value : guid;

                    if (!explicitProjectDependencies.ContainsKey(projectGuid))
                    {
                        explicitProjectDependencies[projectGuid] = CollectionsUtil.CreateCaseInsensitiveHashtable();
                    }
                    ((Hashtable)explicitProjectDependencies[projectGuid])[dependency] = null;
                }

                // set-up project configuration
                Regex           reProjectBuildConfig = new Regex(@"^\s+" + guid + @"\.(?<solutionConfiguration>[^|]+)\|?(?<solutionPlatform>[^\.]?)\.Build\.0\s*=\s* (?<projectConfiguration>[^|]+)\|(?<projectPlatform>[\.\w ]+)\s*", RegexOptions.Multiline);
                MatchCollection projectBuildMatches  = reProjectBuildConfig.Matches(solutionContent);

                ProjectEntry projectEntry = ProjectEntries [guid];
                if (projectEntry == null)
                {
                    // TODO: determine if we should report an error if a build
                    // configuration is defined for a project that does not
                    // exist in the solution
                    continue;
                }

                // holds mapping between project configuration(s) and solution(s)
                ConfigurationMap buildConfigurations = new ConfigurationMap(
                    projectBuildMatches.Count);

                for (int i = 0; i < projectBuildMatches.Count; i++)
                {
                    Match         projectBuildMatch  = projectBuildMatches [i];
                    string        solutionConfigName = projectBuildMatch.Groups["solutionConfiguration"].Value;
                    string        solutionPlatform   = projectBuildMatch.Groups["solutionPlatform"].Value;
                    string        projectConfigName  = projectBuildMatch.Groups["projectConfiguration"].Value;
                    string        projectPlatform    = projectBuildMatch.Groups["projectPlatform"].Value;
                    Configuration solutionConfig     = new Configuration(
                        solutionConfigName, solutionPlatform);
                    Configuration projectConfig = new Configuration(
                        projectConfigName, projectPlatform);
                    buildConfigurations [solutionConfig] = projectConfig;
                }

                // add map to corresponding project entry
                projectEntry.BuildConfigurations = buildConfigurations;
            }

            LoadProjectGuids(new ArrayList(solutionTask.Projects.FileNames), false);
            LoadProjectGuids(new ArrayList(solutionTask.ReferenceProjects.FileNames), true);
            LoadProjects(gacCache, refResolver, explicitProjectDependencies);
        }