コード例 #1
0
        private Translations PrepareLanguages(Geosite data)
        {
            var translations = new Translations();

            // Add all plugin translation files
            foreach (var plugin in data.PluginFolderNames)
            {
                var pluginLocalesPath = HostingEnvironment.MapPath(String.Format("~/{0}/locales", plugin));

                if (Directory.Exists(pluginLocalesPath))
                {
                    var pluginTranslations = Directory
                                             .GetFiles(pluginLocalesPath, "*.json")
                                             .ToDictionary(Path.GetFileNameWithoutExtension, toTranslationDictionary);

                    translations = mergeTranslations(pluginTranslations, translations);
                }
            }

            // Add core translation files
            var coreLocalesPath  = HostingEnvironment.MapPath("~/locales");
            var coreTranslations = Directory
                                   .GetFiles(coreLocalesPath, "*.json")
                                   .ToDictionary(Path.GetFileNameWithoutExtension, toTranslationDictionary);

            translations = mergeTranslations(coreTranslations, translations);

            return(translations);
        }
コード例 #2
0
        public void TestValidRegionData()
        {
            var regionJson        = @"
                {
                    'titleMain': { 'text': 'Geosite Framework Sample', 'url': 'http://www.azavea.com/' },
                    'titleDetail':  { 'text': 'Sample Region', 'url': 'http://www.azavea.com/' },
                    'initialExtent': [ -98.61328125, 17.392579271057766, -79.716796875,31.653381399664 ],
                    'headerLinks': [
                        { 'text': 'Azavea', 'url': 'http://www.azavea.com/' },
                        { 'text': 'GIS', 'url': 'http://en.wikipedia.org/wiki/Geographic_information_system' }
                    ],
                    'basemaps': [
                        {
                            'name': 'Topological',
                            'url': 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer'
                        }
                    ],
                    'pluginOrder': [ 'layer_selector', 'measure' ]
                }";
            var pluginFolderNames = new List <string> {
                "nearshore_waves", "measure", "layer_selector", "explode"
            };
            var pluginModuleNames = new List <string> {
                "nearshore_waves/main", "measure/main", "layer_selector/main", "explode/main"
            };
            var pluginJsonData = new List <JsonData> {
                LoadPluginData(@"{ css: ['main.css'], use: { underscore: { attach: '_' } } }")
            };
            var geosite = new Geosite(LoadRegionData(regionJson), pluginFolderNames, pluginModuleNames, pluginJsonData);

            Expect(geosite.TitleMain.Text, EqualTo("Geosite Framework Sample"));
            Expect(geosite.TitleDetail.Text, EqualTo("Sample Region"));
            Expect(geosite.HeaderLinks.Count, EqualTo(2));
            Expect(geosite.HeaderLinks[0].Url, EqualTo("http://www.azavea.com/"));
            Expect(geosite.HeaderLinks[1].Text, EqualTo("GIS"));
            Expect(geosite.RegionLinks.Count, EqualTo(11));
            Expect(geosite.RegionLinks[10].Text, EqualTo("Washington"));
            Expect(geosite.RegionLinks[3].Url, EqualTo("http://maps.coastalresilience.org/gsvg/"));
            Expect(geosite.PluginModuleIdentifiers, EqualTo("'layer_selector/main', 'measure/main', 'nearshore_waves/main', 'explode/main'"));
            Expect(geosite.PluginVariableNames, EqualTo("p0, p1, p2, p3"));
            Expect(geosite.PluginCssUrls, Contains("main.css"));
            Expect(geosite.ConfigurationForUseJs, Contains("underscore"));

            // Test that "pluginFolderNames" was correctly added to the JSON
            var jsonObj            = JObject.Parse(geosite.RegionDataJson);
            var orderedFolderNames = jsonObj["pluginFolderNames"].Select(t => (string)t).ToList();

            Expect(orderedFolderNames, EqualTo(new List <string> {
                "layer_selector", "measure", "nearshore_waves", "explode"
            }));
        }
コード例 #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            // Configure log4net from the info in Web.config
            log4net.Config.XmlConfigurator.Configure();
            _log.Info("Initializing GeositeFramework, version " + _geositeFrameworkVersion);

            // Load geosite configuration data (which loads and validates all config files)
            GeositeData = LoadGeositeData();

            // Create a logger for each plugin
            foreach (string pluginName in GeositeData.PluginFolderNames)
            {
                CreateLogger(pluginName);
            }
        }
コード例 #4
0
        private Geosite LoadGeositeData()
        {
            // Load geosite data from "region.json" file
            string basePath          = HostingEnvironment.MapPath("~/");
            string configFilePath    = HostingEnvironment.MapPath("~/region.json");
            string appDataFolderPath = HostingEnvironment.MapPath("~/App_Data");

            if (!File.Exists(configFilePath))
            {
                throw new FileNotFoundException("Site configuration file not found: " + configFilePath);
            }
            if (!Directory.Exists(appDataFolderPath))
            {
                throw new FileNotFoundException("App_Data folder not found: " + appDataFolderPath);
            }
            try
            {
                var geositeData = Geosite.LoadSiteData(configFilePath, basePath, appDataFolderPath);
                geositeData.GeositeFrameworkVersion = _geositeFrameworkVersion;
                return(geositeData);
            }
            catch (JsonValidationException ex)
            {
                _log.Error(ex.Message);
                foreach (var message in ex.ParseMessages)
                {
                    _log.Error(message);
                }
                throw;   // Will display /Error.html
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message);
                throw;   // Will display /Error.html
            }
        }