Ejemplo n.º 1
0
        /// <summary>
        /// Encapsulate the XmlRpc call to standardize security and error handling.
        /// </summary>
        private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param)
        {
            XmlRpcResponse resp     = null;
            string         CacheKey = null;

            // Only bother with the cache if it isn't disabled.
            if (m_cacheTimeout > 0)
            {
                if (!function.StartsWith("groups.get"))
                {
                    // Any and all updates cause the cache to clear
                    m_memoryCache.Clear();
                }
                else
                {
                    StringBuilder sb = new StringBuilder(requestingAgentID + function);
                    foreach (object key in param.Keys)
                    {
                        if (param[key] != null)
                        {
                            sb.AppendFormat(",{0}:{1}", key.ToString(), param[key].ToString());
                        }
                    }

                    CacheKey = sb.ToString();
                    m_memoryCache.TryGetValue(CacheKey, out resp);
                }
            }

            if (resp == null)
            {
                if (m_debugEnabled)
                {
                    m_log.DebugFormat("[XMLRPC-GROUPS-CONNECTOR]: Cache miss for key {0}", CacheKey);
                }

                string UserService;
                UUID   SessionID;
                GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID);

                param.Add("RequestingAgentID", requestingAgentID.ToString());
                param.Add("RequestingAgentUserService", UserService);
                param.Add("RequestingSessionID", SessionID.ToString());
                param.Add("ReadKey", m_groupReadKey);
                param.Add("WriteKey", m_groupWriteKey);

                IList parameters = new ArrayList();
                parameters.Add(param);

                ConfigurableKeepAliveXmlRpcRequest req;
                req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive);

                try
                {
                    resp = req.Send(m_groupsServerURI, 10000);

                    if ((m_cacheTimeout > 0) && (CacheKey != null))
                    {
                        m_memoryCache.AddOrUpdate(CacheKey, resp, TimeSpan.FromSeconds(m_cacheTimeout));
                    }
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat(
                        "[XMLRPC-GROUPS-CONNECTOR]: An error has occured while attempting to access the XmlRpcGroups server method {0} at {1}",
                        function, m_groupsServerURI);

                    m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}{1}", e.Message, e.StackTrace);

                    foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
                    {
                        m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", ResponseLine);
                    }

                    foreach (string key in param.Keys)
                    {
                        m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", key, param[key].ToString());
                    }

                    Hashtable respData = new Hashtable();
                    respData.Add("error", e.ToString());
                    return(respData);
                }
            }

            if (resp.Value is Hashtable)
            {
                Hashtable respData = (Hashtable)resp.Value;
                if (respData.Contains("error") && !respData.Contains("succeed"))
                {
                    LogRespDataToConsoleError(respData);
                }

                return(respData);
            }

            m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString());

            if (resp.Value is ArrayList)
            {
                ArrayList al = (ArrayList)resp.Value;
                m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements", al.Count);

                foreach (object o in al)
                {
                    m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", o.GetType().ToString(), o.ToString());
                }
            }
            else
            {
                m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}", resp.Value.ToString());
            }

            Hashtable error = new Hashtable();

            error.Add("error", "invalid return value");
            return(error);
        }
Ejemplo n.º 2
0
        private void HandleConsoleCommand(string module, string[] cmdparams)
        {
            ICommandConsole con = MainConsole.Instance;

            if (cmdparams.Length >= 2)
            {
                string cmd = cmdparams[1];

                switch (cmd)
                {
                case "status":
                    if (m_MemoryCacheEnabled)
                    {
                        con.OutputFormat("Memory Cache: {0} assets", m_MemoryCache.Count);
                    }
                    else
                    {
                        con.OutputFormat("Memory cache disabled");
                    }

                    if (m_FileCacheEnabled)
                    {
                        int fileCount = GetFileCacheCount(m_CacheDirectory);
                        con.OutputFormat("File Cache: {0} assets", fileCount);
                    }
                    else
                    {
                        con.Output("File cache disabled");
                    }

                    GenerateCacheHitReport().ForEach(l => con.Output(l));

                    if (m_FileCacheEnabled)
                    {
                        con.Output("Deep scans have previously been performed on the following regions:");

                        foreach (string s in Directory.GetFiles(m_CacheDirectory, "*.fac"))
                        {
                            string   RegionID = s.Remove(0, s.IndexOf("_")).Replace(".fac", "");
                            DateTime RegionDeepScanTMStamp = File.GetLastWriteTime(s);
                            con.OutputFormat("Region: {0}, {1}", RegionID, RegionDeepScanTMStamp.ToString("MM/dd/yyyy hh:mm:ss"));
                        }
                    }

                    break;

                case "clear":
                    if (cmdparams.Length < 2)
                    {
                        con.Output("Usage is fcache clear [file] [memory]");
                        break;
                    }

                    bool clearMemory = false, clearFile = false;

                    if (cmdparams.Length == 2)
                    {
                        clearMemory = true;
                        clearFile   = true;
                    }
                    foreach (string s in cmdparams)
                    {
                        if (s.ToLower() == "memory")
                        {
                            clearMemory = true;
                        }
                        else if (s.ToLower() == "file")
                        {
                            clearFile = true;
                        }
                    }

                    if (clearMemory)
                    {
                        if (m_MemoryCacheEnabled)
                        {
                            m_MemoryCache.Clear();
                            con.Output("Memory cache cleared.");
                        }
                        else
                        {
                            con.Output("Memory cache not enabled.");
                        }
                    }

                    if (clearFile)
                    {
                        if (m_FileCacheEnabled)
                        {
                            ClearFileCache();
                            con.Output("File cache cleared.");
                        }
                        else
                        {
                            con.Output("File cache not enabled.");
                        }
                    }

                    break;

                case "assets":
                    lock (timerLock)
                    {
                        if (m_cleanupRunning)
                        {
                            con.OutputFormat("FloatSam assets check already running");
                            return;
                        }
                        m_cleanupRunning = true;
                    }

                    con.Output("FloatSam Ensuring assets are cached for all scenes.");

                    WorkManager.RunInThread(delegate
                    {
                        bool wasRunning = false;
                        lock (timerLock)
                        {
                            if (m_timerRunning)
                            {
                                m_CacheCleanTimer.Stop();
                                m_timerRunning = false;
                                wasRunning     = true;
                                Thread.Sleep(100);
                            }
                        }
                        int assetReferenceTotal = TouchAllSceneAssets(true);
                        GC.Collect();
                        lock (timerLock)
                        {
                            if (wasRunning)
                            {
                                m_CacheCleanTimer.Start();
                                m_timerRunning = true;
                            }
                            m_cleanupRunning = false;
                        }
                        con.OutputFormat("Completed check with {0} assets.", assetReferenceTotal);
                    }, null, "TouchAllSceneAssets");

                    break;

                case "expire":
                    if (cmdparams.Length < 3)
                    {
                        con.OutputFormat("Invalid parameters for Expire, please specify a valid date & time", cmd);
                        break;
                    }

                    string   s_expirationDate = "";
                    DateTime expirationDate;

                    if (cmdparams.Length > 3)
                    {
                        s_expirationDate = string.Join(" ", cmdparams, 2, cmdparams.Length - 2);
                    }
                    else
                    {
                        s_expirationDate = cmdparams[2];
                    }

                    if (!DateTime.TryParse(s_expirationDate, out expirationDate))
                    {
                        con.OutputFormat("{0} is not a valid date & time", cmd);
                        break;
                    }

                    if (m_FileCacheEnabled)
                    {
                        CleanExpiredFiles(m_CacheDirectory, expirationDate);
                    }
                    else
                    {
                        con.OutputFormat("File cache not active, not clearing.");
                    }

                    break;

                default:
                    con.OutputFormat("Unknown command {0}", cmd);
                    break;
                }
            }
            else if (cmdparams.Length == 1)
            {
                con.Output("fcache assets - Attempt a deep cache of all assets in all scenes");
                con.Output("fcache expire <datetime> - Purge assets older then the specified date & time");
                con.Output("fcache clear [file] [memory] - Remove cached assets");
                con.Output("fcache status - Display cache status");
            }
        }