/// <summary> /// Return pluginFolders array from region.json. /// Default value is ["plugins"] /// </summary> public static IEnumerable<string> GetPluginDirectories(JsonData jsonDataRegion, string basePath) { JObject regionData = jsonDataRegion.Validate(); JToken token; if (regionData.TryGetValue("pluginFolders", out token)) { return (token as JArray).Select(folderPath => Path.Combine(basePath, folderPath.ToString())); } return new string[] { Path.Combine(basePath, "plugins") }; }
/// <summary> /// Make a Geosite object given the specified configuration info. /// Note this is public only for testing purposes. /// </summary> /// <param name="jsonDataRegion">JSON configuration data (e.g. from a "region.json" configuration file)</param> /// <param name="existingPluginFolderNames">A list of plugin folder names (not full paths -- relative to the site "plugins" folder)</param> public Geosite(JsonData jsonDataRegion, List<string> existingPluginFolderNames, List<JsonData> pluginConfigJsonData) { // Validate the region configuration JSON var jsonObj = jsonDataRegion.Validate(); // Get plugin folder names, in the specified order if (jsonObj["pluginOrder"] == null) { PluginFolderNames = existingPluginFolderNames; } else { var specifiedFolderNames = jsonObj["pluginOrder"].Select(t => (string)t).ToList(); PluginFolderNames = GetOrderedPluginFolderNames(existingPluginFolderNames, specifiedFolderNames); } // Augment the JSON so the client will have the full list of folder names jsonObj.Add("pluginFolderNames", new JArray(PluginFolderNames.ToArray())); // Set public properties needed for View rendering TitleMain = ExtractLinkFromJson(jsonObj["titleMain"]); TitleDetail = ExtractLinkFromJson(jsonObj["titleDetail"]); if (jsonObj["googleAnalyticsPropertyId"] != null) { GoogleAnalyticsPropertyId = (string)jsonObj["googleAnalyticsPropertyId"]; } if (jsonObj["headerLinks"] != null) { HeaderLinks = jsonObj["headerLinks"] .Select(ExtractLinkFromJson).ToList(); } // JSON to be inserted in generated JavaScript code RegionDataJson = jsonObj.ToString(); // Create plugin module identifiers, to be inserted in generated JavaScript code. Example: // "'plugins/layer_selector/main', 'plugins/measure/main'" PluginModuleIdentifiers = string.Join(", ", PluginFolderNames.Select(name => string.Format("'plugins/{0}/main'", name))); // Create plugin variable names, to be inserted in generated JavaScript code. Example: // "p0, p1" PluginVariableNames = string.Join(", ", PluginFolderNames.Select((name, i) => string.Format("p{0}", i))); if (pluginConfigJsonData != null) { MergePluginConfigurationData(this, pluginConfigJsonData); } }
/// <summary> /// Make a Geosite object given the specified configuration info. /// Note this is public only for testing purposes. /// </summary> /// <param name="jsonDataRegion">JSON configuration data (e.g. from a "region.json" configuration file)</param> /// <param name="existingPluginFolderNames">A list of plugin folder names (not full paths -- relative to the site "plugins" folder)</param> public Geosite(JsonData jsonDataRegion, List<string> existingPluginFolderNames, List<string> pluginModuleNames, List<JsonData> pluginConfigJsonData) { // Validate the region configuration JSON var jsonObj = jsonDataRegion.Validate(); // Get plugin folder names, in the specified order if (jsonObj["pluginOrder"] != null) { List<string> pluginOrder = jsonObj["pluginOrder"].Select(t => (string)t).ToList(); Func<string, int> byPluginOrder = x => pluginOrder.IndexOf(PluginLoader.StripPluginModule(x)); PluginLoader.SortPluginNames(existingPluginFolderNames, byPluginOrder); PluginLoader.SortPluginNames(pluginModuleNames, byPluginOrder); } PluginFolderNames = existingPluginFolderNames; // Augment the JSON so the client will have the full list of folder names jsonObj.Add("pluginFolderNames", new JArray(PluginFolderNames.ToArray())); // Set public properties needed for View rendering TitleMain = ExtractLinkFromJson(jsonObj["titleMain"]); TitleDetail = ExtractLinkFromJson(jsonObj["titleDetail"]); var colorConfig = jsonObj["colors"]; if (colorConfig != null) { PrimaryColor = ExtractColorFromJson(colorConfig, "primary"); SecondaryColor = ExtractColorFromJson(colorConfig, "secondary"); } else { PrimaryColor = ColorTranslator.ToHtml(_defaultPrimary); SecondaryColor = ColorTranslator.ToHtml(_defaultSecondary); } if (jsonObj["googleAnalyticsPropertyId"] != null) { GoogleAnalyticsPropertyId = (string)jsonObj["googleAnalyticsPropertyId"]; } if (jsonObj["headerLinks"] != null) { HeaderLinks = jsonObj["headerLinks"] .Select(ExtractLinkFromJson).ToList(); } // JSON to be inserted in generated JavaScript code RegionDataJson = jsonObj.ToString(); // Create plugin module identifiers, to be inserted in generated JavaScript code. Example: // "'plugins/layer_selector/main', 'plugins/measure/main'" PluginModuleIdentifiers = "'" + string.Join("', '", pluginModuleNames) + "'"; // Create plugin variable names, to be inserted in generated JavaScript code. Example: // "p0, p1" PluginVariableNames = string.Join(", ", PluginFolderNames.Select((name, i) => string.Format("p{0}", i))); if (pluginConfigJsonData != null) { MergePluginConfigurationData(this, pluginConfigJsonData); } }