<commit_before>﻿using System;
using System.Net;
using log4net;
using OpenMetaverse;
using OpenSim.Data;
using InWorldz.Data.Inventory.Cassandra;
using SimpleAPIServer;
using Nini.Config;

namespace AIS
{
    class InventoryAPI
    {
        private static readonly ILog m_log = LogManager.GetLogger(typeof(InventoryAPI));

        static private string _cluster = Properties.Settings.Default.cassandraCluster;
        static private string _connstring = Properties.Settings.Default.coreConnStr;

        private UUID _Id;

        private IInventoryStorage _storage;

        private InventoryStorage _cassandraStorage;
        private CassandraMigrationProviderSelector _selector;
        private LegacyMysqlInventoryStorage _legacy;

        public InventoryAPI()
        {
        }

        public void AddRoutes(APIRouter router)
        {
            APIRoute[] inventoryRoutes =
            {
                new APIRoute("ALL", "/category/{category}",            HandleCategory),
                new APIRoute("ALL", "/category/{category}/children",   HandleCategoryChildren),
                new APIRoute("ALL", "/category/{category}/links",      HandleCategoryLinks),
                new APIRoute("ALL", "/category/{category}/items",      HandleCategoryItems),
                new APIRoute("ALL", "/category/{category}/categories", HandleCategoryCategories),
                new APIRoute("ALL", "/item/{item}",                    HandleItem),
            };

            router.AddRoutes(inventoryRoutes);
        }

        // "GET", "/category/{category}",           HandleGetCategory
        public void HandleGetCategory(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
        {
            APIServer.SetResponse(response, HttpStatusCode.OK, "OK " + request.RawUrl);
        }
        public void HandleCategory(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
        {
            if (string.Compare(request.HttpMethod, "GET", true) == 0)
                HandleGetCategory(request, requestParts, response);
            else
                APIServer.SetResponse(response, HttpStatusCode.MethodNotAllowed, request.RawUrl);<commit_msg>Now loading and connecting to Cassandra and legacy inv.<commit_after>﻿using System;
using System.Net;
using log4net;
using OpenMetaverse;
using OpenSim.Data;
using InWorldz.Data.Inventory.Cassandra;
using SimpleAPIServer;
using Nini.Config;

namespace AIS
{
    class InventoryAPI
    {
        private static readonly ILog m_log = LogManager.GetLogger(typeof(InventoryAPI));

        static private string _cluster = Properties.Settings.Default.cassandraCluster;
        static private string _connstring = Properties.Settings.Default.coreConnStr;

        private UUID _Id;

        private InventoryStorage _cassandraStorage;
        private CassandraMigrationProviderSelector _selector;
        private LegacyMysqlInventoryStorage _legacy;

        private IInventoryStorage _storage; // per-user specific storage reference

        public InventoryAPI()
        {
            try
            {
                _cassandraStorage = new InventoryStorage(_cluster);
                _legacy = new LegacyMysqlInventoryStorage(_connstring);
                _selector = new CassandraMigrationProviderSelector(true, _connstring, _cassandraStorage, _legacy);
                m_log.InfoFormat("Cassandra support on '{0}' enabled and ready.", _cluster);
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("Unable to connect to cassandra cluster: {0}", e);
            }
        }

        public void AddRoutes(APIRouter router)
        {
            APIRoute[] inventoryRoutes =
            {
                new APIRoute("ALL", "/category/{category}",            HandleCategory),
                new APIRoute("ALL", "/category/{category}/children",   HandleCategoryChildren),
                new APIRoute("ALL", "/category/{category}/links",      HandleCategoryLinks),
                new APIRoute("ALL", "/category/{category}/items",      HandleCategoryItems),
                new APIRoute("ALL", "/category/{category}/categories", HandleCategoryCategories),
                new APIRoute("ALL", "/item/{item}",                    HandleItem),
            };

            router.AddRoutes(inventoryRoutes);
        }

        // "GET", "/category/{category}",           HandleGetCategory
        public void HandleGetCategory(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
        {
            APIServer.SetResponse(response, HttpStatusCode.OK, "OK " + request.RawUrl);
        }
        public void HandleCategory(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
        {
            if (string.Compare(request.HttpMethod, "GET", true) == 0)
                HandleGetCategory(request, requestParts, response);
            else
                APIServer.SetResponse(response, HttpStatusCode.MethodNotAllowed, request.RawUrl);
{'fraction_non_alphanumeric': 0.09045922406967538, 'fraction_numerical': 0.0011876484560570072, 'mean_word_length': 2.4800275482093666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '178005', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1208, 'n_words': 281}