Example #1
0
 public override string ToString()
 {
     return(string.Format("���{0}���ؼ���{1}������{2}��ҳ��ͷ����{3}��ҳ��β����{4}��������ɫ{5}����Ȩ��Ϣ{6}", Id, SiteKeyWord, SiteDescription, HeaderLinks.Join(",", item => item.ToString()), FooterLinks.Join(",", item => item.ToString()), BGColor, CopyrightInfo));
 }
Example #2
0
        /// <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)
            {
                var pluginOrder = GetPluginOrder(jsonObj);
                Func <string, int> byPluginOrder = x => pluginOrder.IndexOf(PluginLoader.StripPluginModule(x));
                PluginLoader.SortPluginNames(existingPluginFolderNames, byPluginOrder);
                PluginLoader.SortPluginNames(pluginModuleNames, byPluginOrder);
            }

            PluginFolderNames = existingPluginFolderNames;

            // If single plugin mode is active, remove every plugin besides the specified plugin
            // from the plugin lists.
            if (jsonObj["singlePluginMode"] != null && (bool)jsonObj["singlePluginMode"]["active"])
            {
                SinglePluginMode = true;
                var singlePlugin = (string)jsonObj["singlePluginMode"]["pluginFolderName"];

                if (String.IsNullOrEmpty(singlePlugin))
                {
                    const string msg = "Single plugin mode is active but no plugin is defined.";
                    throw new Exception(msg);
                }

                var singlePluginFolderName = PluginFolderNames.Where(p => p.Contains(singlePlugin)).ToList();
                var singlePluginModuleName = pluginModuleNames.Where(p => p.Contains(singlePlugin)).ToList();

                if (String.IsNullOrEmpty(singlePluginFolderName.FirstOrDefault()))
                {
                    const string msg = "The specified plugin for single plugin mode was not found.";
                    throw new Exception(msg);
                }
                else
                {
                    PluginFolderNames = singlePluginFolderName;
                    pluginModuleNames = singlePluginModuleName;
                }
            }
            else
            {
                SinglePluginMode = false;
            }

            // 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 = colorConfig.SelectToken("primary") != null?
                               ExtractColorFromJson(colorConfig, "primary") : ColorTranslator.ToHtml(_defaultPrimary);

                SecondaryColor = colorConfig.SelectToken("secondary") != null?
                                 ExtractColorFromJson(colorConfig, "secondary") : ColorTranslator.ToHtml(_defaultSecondary);

                ActiveAppColor = colorConfig.SelectToken("active") != null?
                                 ExtractColorFromJson(colorConfig, "active") : ColorTranslator.ToHtml(_defaultActiveApp);

                TertiaryColor = colorConfig.SelectToken("tertiary") != null?
                                ExtractColorFromJson(colorConfig, "tertiary") : ColorTranslator.ToHtml(_defaultTertiary);
            }

            var printConfig = jsonObj["print"];

            if (printConfig != null)
            {
                PrintHeaderLogo = (string)printConfig["headerLogoPath"];
            }

            if (jsonObj["googleAnalyticsPropertyId"] != null)
            {
                GoogleAnalyticsPropertyId = (string)jsonObj["googleAnalyticsPropertyId"];
            }

            if (jsonObj["headerLinks"] != null)
            {
                HeaderLinks = jsonObj["headerLinks"]
                              .Select(ExtractLinkFromJson).ToList();

                if (jsonObj["regionLinks"] != null)
                {
                    HeaderLinks.Add(AddRegionLinksToHeaderLinks(jsonObj["regionLinks"]));
                }
            }

            // 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);
            }
        }