コード例 #1
0
        public HttpResponseMessage GetSettings()
        {
            var settings = new SettingsViewModel();

            var ctl = new HostController();
            var searchTargetsRaw = ctl.GetString(Utility.SettingNameSearchTargets);

            if (string.IsNullOrEmpty(searchTargetsRaw))
            {
                // Load default configuration
                settings.SearchTargts = new List <SearchItem>
                {
                    new SearchItem(SqlDataProvider.FullDbObjectName("HtmlText"),
                                   SqlDataProvider.QuoteName("Content")),
                    new SearchItem(SqlDataProvider.FullDbObjectName("ModuleSettings"),
                                   SqlDataProvider.QuoteName("SettingValue")),
                    new SearchItem(SqlDataProvider.FullDbObjectName("TabModuleSettings"),
                                   SqlDataProvider.QuoteName("SettingValue")),
                    new SearchItem(SqlDataProvider.FullDbObjectName("Tabs"),
                                   SqlDataProvider.QuoteName("Url")),
                    new SearchItem(SqlDataProvider.FullDbObjectName("Urls"),
                                   SqlDataProvider.QuoteName("Url")),
                    new SearchItem(SqlDataProvider.FullDbObjectName("UrlTracking"),
                                   SqlDataProvider.QuoteName("Url")),
                    new SearchItem(SqlDataProvider.FullDbObjectName("Links"),
                                   SqlDataProvider.QuoteName("Url")),
                };
            }
            else
            {
                // Load saved configuration
                settings.SearchTargts = searchTargetsRaw.FromJson <List <SearchItem> >();
            }

            // Filter out non-existing targets
            settings.SearchTargts = settings.SearchTargts.Where(SqlDataProvider.SearchTargetExists);

            // Return Settings
            var res = Request.CreateResponse(HttpStatusCode.OK);

            res.Content = new StringContent(JsonConvert.SerializeObject(settings), Encoding.UTF8, "application/json");
            return(res);
        }