public bool CreateUser(User user)
        {
            m_log.Info("Creating user account for " + user.Name + " (" + user.ID + ")");

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "AddUser" },
                { "UserID", user.ID.ToString() },
                { "Name", user.Name },
                { "Email", user.Email },
                { "AccessLevel", user.AccessLevel.ToString() }
            };

            OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);

            if (response["Success"].AsBoolean())
            {
                // Cache the user account info
                m_userCache.AddOrUpdate(user.ID, user, CACHE_TIMEOUT);
                return(true);
            }
            else
            {
                m_log.Warn("Failed to store user account for " + user.Name + ": " + response["Message"].AsString());
            }

            return(false);
        }
Exemple #2
0
        public InventoryItemBase GetItem(InventoryItemBase item)
        {
            InventoryItemBase retrieved = null;

            if (m_ItemCache.TryGetValue(item.ID, out retrieved))
            {
                return(retrieved);
            }

            try
            {
                Dictionary <string, object> ret = MakeRequest("GETITEM",
                                                              new Dictionary <string, object> {
                    { "ID", item.ID.ToString() }
                });

                if (!CheckReturn(ret))
                {
                    return(null);
                }

                retrieved = BuildItem((Dictionary <string, object>)ret["item"]);
            }
            catch (Exception e)
            {
                m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e);
            }

            m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS);

            return(retrieved);
        }
        public UserAccount GetUserAccount(UUID scopeID, UUID userID)
        {
            // Cache check
            UserAccount account;

            if (m_accountCache.TryGetValue(userID, out account))
            {
                return(account);
            }

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetUser" },
                { "UserID", userID.ToString() }
            };

            account = GetUser(requestArgs);

            if (account == null)
            {
                // Store null responses too, to avoid repeated lookups for missing accounts
                m_accountCache.AddOrUpdate(userID, null, CACHE_EXPIRATION_SECONDS);
            }

            return(account);
        }
Exemple #4
0
        public bool TryGetScene(UUID sceneID, out SceneInfo sceneInfo)
        {
            // Cache check
            if (m_sceneCache.TryGetValue(sceneID, out sceneInfo))
            {
                return(true);
            }

            // Remote fetch
            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetScene" },
                { "SceneID", sceneID.ToString() },
                { "Enabled", "1" }
            };

            OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);

            if (response["Success"].AsBoolean())
            {
                sceneInfo = ResponseToSceneInfo(response);
                m_sceneCache.AddOrUpdate(sceneID, sceneInfo, CACHE_TIMEOUT);
                return(true);
            }
            else
            {
                m_log.Warn("Grid service did not find a match for region " + sceneID);
                sceneInfo = null;
                return(false);
            }
        }
Exemple #5
0
        public bool StoreUserAccount(UserAccount data)
        {
            m_log.InfoFormat("[SIMIAN ACCOUNT CONNECTOR]: Storing user account for " + data.Name);

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "AddUser" },
                { "UserID", data.PrincipalID.ToString() },
                { "Name", data.Name },
                { "Email", data.Email },
                { "AccessLevel", data.UserLevel.ToString() }
            };

            OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);

            if (response["Success"].AsBoolean())
            {
                m_log.InfoFormat("[SIMIAN ACCOUNT CONNECTOR]: Storing user account data for " + data.Name);

                requestArgs = new NameValueCollection
                {
                    { "RequestMethod", "AddUserData" },
                    { "UserID", data.PrincipalID.ToString() },
                    { "CreationDate", data.Created.ToString() },
                    { "UserFlags", data.UserFlags.ToString() },
                    { "UserTitle", data.UserTitle }
                };

                response = WebUtil.PostToService(m_serverUrl, requestArgs);
                bool success = response["Success"].AsBoolean();

                if (success)
                {
                    // Cache the user account info
                    m_accountCache.AddOrUpdate(data.PrincipalID, data, DateTime.Now + TimeSpan.FromMinutes(2.0d));
                }
                else
                {
                    m_log.Warn("[SIMIAN ACCOUNT CONNECTOR]: Failed to store user account data for " + data.Name + ": " + response["Message"].AsString());
                }

                return(success);
            }
            else
            {
                m_log.Warn("[SIMIAN ACCOUNT CONNECTOR]: Failed to store user account for " + data.Name + ": " + response["Message"].AsString());
            }

            return(false);
        }
        ////////////////////////////////////////////////////////////
        // IImprovedAssetCache
        //

        private void UpdateMemoryCache(string key, AssetBase asset)
        {
            if (m_MemoryCacheEnabled)
            {
                if (m_MemoryExpiration > TimeSpan.Zero)
                {
                    m_MemoryCache.AddOrUpdate(key, asset, m_MemoryExpiration);
                }
                else
                {
                    m_MemoryCache.AddOrUpdate(key, asset, DateTime.MaxValue);
                }
            }
        }
Exemple #7
0
 private void UpdateMemoryCache(string key, AssetBase asset, bool forceMemCache)
 {
     if (m_MemoryCacheEnabled || forceMemCache)
     {
         if (m_MemoryExpiration > TimeSpan.Zero)
         {
             m_MemoryCache.AddOrUpdate(key, asset, m_MemoryExpiration);
         }
         else
         {
             m_MemoryCache.AddOrUpdate(key, asset, m_DefaultMemoryExpiration);
         }
     }
 }
Exemple #8
0
 public void CacheNegative(string id)
 {
     if (m_negativeCacheEnabled)
     {
         if (m_negativeCacheSliding)
         {
             m_negativeCache.AddOrUpdate(id, null, TimeSpan.FromSeconds(m_negativeExpiration));
         }
         else
         {
             m_negativeCache.AddOrUpdate(id, null, m_negativeExpiration);
         }
     }
 }
Exemple #9
0
        private void SaveFileCacheForAsset(UUID AssetId, OpenJPEG.J2KLayerInfo[] Layers)
        {
            m_decodedCache.AddOrUpdate(AssetId, Layers, TimeSpan.FromMinutes(10));

            if (Cache != null)
            {
                string assetID = "j2kCache_" + AssetId.ToString();

                AssetBase layerDecodeAsset = new AssetBase(assetID, assetID, (sbyte)AssetType.Notecard, m_CreatorID.ToString());
                layerDecodeAsset.Local     = true;
                layerDecodeAsset.Temporary = true;

                #region Serialize Layer Data

                StringBuilder stringResult = new StringBuilder();
                string        strEnd       = "\n";
                for (int i = 0; i < Layers.Length; i++)
                {
                    if (i == Layers.Length - 1)
                    {
                        strEnd = String.Empty;
                    }

                    stringResult.AppendFormat("{0}|{1}|{2}{3}", Layers[i].Start, Layers[i].End, Layers[i].End - Layers[i].Start, strEnd);
                }

                layerDecodeAsset.Data = Util.UTF8.GetBytes(stringResult.ToString());

                #endregion Serialize Layer Data

                Cache.Cache(layerDecodeAsset);
            }
        }
Exemple #10
0
        ////////////////////////////////////////////////////////////
        // IImprovedAssetCache
        //

        private void UpdateMemoryCache(string key, AssetBase asset)
        {
            if (m_MemoryCacheEnabled)
            {
                m_MemoryCache.AddOrUpdate(key, asset, m_MemoryExpiration);
            }
        }
        /// <summary>
        /// Save Layers to Disk Cache
        /// </summary>
        /// <param name="AssetId">Asset to Save the layers. Used int he file name by default</param>
        /// <param name="Layers">The Layer Data from OpenJpeg</param>
        /// <returns></returns>
        public bool SaveCacheForAsset(UUID AssetId, OpenJPEG.J2KLayerInfo[] Layers)
        {
            if (Layers.Length > 0)
            {
                m_decodedCache.AddOrUpdate(AssetId, Layers, TimeSpan.FromMinutes(10));

                if (enabled == true)
                {
                    using (FileStream fsCache =
                               new FileStream(String.Format("{0}/{1}", m_cacheDecodeFolder, FileNameFromAssetId(AssetId)),
                                              FileMode.Create))
                    {
                        using (StreamWriter fsSWCache = new StreamWriter(fsCache))
                        {
                            StringBuilder stringResult = new StringBuilder();
                            string        strEnd       = "\n";
                            for (int i = 0; i < Layers.Length; i++)
                            {
                                if (i == (Layers.Length - 1))
                                {
                                    strEnd = "";
                                }

                                stringResult.AppendFormat("{0}|{1}|{2}{3}", Layers[i].Start, Layers[i].End, Layers[i].End - Layers[i].Start, strEnd);
                            }
                            fsSWCache.Write(stringResult.ToString());
                            fsSWCache.Close();
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemple #12
0
        public void Cache(UUID userID, UserAccount account)
        {
            // Cache even null accounts
            m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);

            //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
        }
        public void Cache(UUID userID, T account)
        {
            if (!m_allowNullCaching && account == null)
            {
                return;
            }
            if (account == null)
            {
                if (!m_nullCacheTimes.ContainsKey(userID))
                {
                    m_nullCacheTimes[userID] = 0;
                }
                else
                {
                    m_nullCacheTimes[userID]++;
                }
                if (m_nullCacheTimes[userID] < 5)
                {
                    return;
                }
            }
            else if (m_nullCacheTimes.ContainsKey(userID))
            {
                m_nullCacheTimes.Remove(userID);
            }
            // Cache even null accounts
            m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
            if (account != null && !string.IsNullOrEmpty(account.Name))
            {
                m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
            }

            //MainConsole.Instance.DebugFormat("[USER CACHE]: cached user {0}", userID);
        }
        private List<XInventoryFolder> GetFolderTree(UUID principalID, UUID folder)
        {
            List<XInventoryFolder> t = null;
            if (m_SuitcaseTrees.TryGetValue(principalID, out t))
                return t;

            t = GetFolderTreeRecursive(folder);
            m_SuitcaseTrees.AddOrUpdate(principalID, t, 5*60); // 5minutes
            return t;
        }
        private AvatarAppearance GetAppearance(UUID principalID)
        {
            AvatarAppearance a = null;
            if (m_Appearances.TryGetValue(principalID, out a))
                return a;

            a = m_AvatarService.GetAppearance(principalID);
            m_Appearances.AddOrUpdate(principalID, a, 5 * 60); // 5minutes
            return a;
        }
        private void EventManager_OnAvatarLeavingRegion(ScenePresence presence, SimpleRegionInfo newRegion)
        {
            //Add them to the cache
            LeavingRegionInfo info = new LeavingRegionInfo()
            {
                RegionServerURI = newRegion.InsecurePublicHTTPServerURI, SessionID = presence.ControllingClient.SessionId
            };

            _avatarRegionCache.AddOrUpdate(presence.UUID, info, CACHE_EXPIRATION_TIME);
        }
        public Hashtable OnGetSnapshot(Hashtable keysvals)
        {
            Hashtable reply = new Hashtable();
            string    reqtag;
            string    snapObj = (string)keysvals["region"];

            if (string.IsNullOrWhiteSpace(snapObj))
            {
                reqtag = GetClientString(keysvals);
            }
            else
            {
                reqtag = snapObj + GetClientString(keysvals);
            }


            if (!string.IsNullOrWhiteSpace(reqtag))
            {
                if (throotleGen.Contains(reqtag))
                {
                    reply["str_response_string"] = "Please try your request again later";
                    reply["int_response_code"]   = 503;
                    reply["content_type"]        = "text/plain";
                    m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
                    return(reply);
                }

                throotleGen.AddOrUpdate(reqtag, 0, 60);
            }

            if (string.IsNullOrWhiteSpace(snapObj))
            {
                m_log.DebugFormat("[DATASNAPSHOT] Received collection request for all");
            }
            else
            {
                m_log.DebugFormat("[DATASNAPSHOT] Received collection request for {0}", snapObj);
            }

            XmlDocument response = m_externalData.GetSnapshot(snapObj);

            if (response == null)
            {
                reply["str_response_string"] = "Please try your request again later";
                reply["int_response_code"]   = 503;
                reply["content_type"]        = "text/plain";
                m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
                return(reply);
            }

            reply["str_response_string"] = response.OuterXml;
            reply["int_response_code"]   = 200;
            reply["content_type"]        = "text/xml";
            return(reply);
        }
Exemple #18
0
        public void Cache(UUID userID, UserAccount account)
        {
            // Cache even null accounts
            m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
            if (account != null)
            {
                m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
            }

            //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
        }
Exemple #19
0
        public void Cache(UUID userID, UserAccount account)
        {
            // Cache even null accounts
            m_UUIDCache.AddOrUpdate(userID, account, DateTime.Now + TimeSpan.FromMinutes(2.0d));
            if (account != null)
            {
                m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, DateTime.Now + TimeSpan.FromMinutes(2.0d));
            }

            m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
        }
        public bool UpdateItem(InventoryItemBase item)
        {
            if (item.CreatorData == null)
            {
                item.CreatorData = String.Empty;
            }
            Dictionary <string, object> ret = MakeRequest(
                new Dictionary <string, object> {
                { "METHOD", "UPDATEITEM" },
                { "AssetID", item.AssetID.ToString() },
                { "AssetType", item.AssetType.ToString() },
                { "Name", item.Name.ToString() },
                { "Owner", item.Owner.ToString() },
                { "ID", item.ID.ToString() },
                { "InvType", item.InvType.ToString() },
                { "Folder", item.Folder.ToString() },
                { "CreatorId", item.CreatorId.ToString() },
                { "CreatorData", item.CreatorData.ToString() },
                { "Description", item.Description.ToString() },
                { "NextPermissions", item.NextPermissions.ToString() },
                { "CurrentPermissions", item.CurrentPermissions.ToString() },
                { "BasePermissions", item.BasePermissions.ToString() },
                { "EveryOnePermissions", item.EveryOnePermissions.ToString() },
                { "GroupPermissions", item.GroupPermissions.ToString() },
                { "GroupID", item.GroupID.ToString() },
                { "GroupOwned", item.GroupOwned.ToString() },
                { "SalePrice", item.SalePrice.ToString() },
                { "SaleType", item.SaleType.ToString() },
                { "Flags", item.Flags.ToString() },
                { "CreationDate", item.CreationDate.ToString() }
            });

            bool result = CheckReturn(ret);

            if (result)
            {
                m_ItemCache.AddOrUpdate(item.ID, item, CACHE_EXPIRATION_SECONDS);
            }

            return(result);
        }
        bool SendIMToRegion(PresenceInfo upd, GridInstantMessage im, UUID toAgentID, bool foreigner)
        {
            bool       imresult = false;
            GridRegion reginfo  = null;

            if (!m_RegionCache.TryGetValue(upd.RegionID, out reginfo))
            {
                reginfo = m_GridService.GetRegionByUUID(UUID.Zero /*!!!*/, upd.RegionID);
                if (reginfo != null)
                {
                    m_RegionCache.AddOrUpdate(upd.RegionID, reginfo, CACHE_EXPIRATION_SECONDS);
                }
            }

            if (reginfo != null)
            {
                imresult = InstantMessageServiceConnector.SendInstantMessage(reginfo.ServerURI, im, m_messageKey);
            }
            else
            {
                m_log.DebugFormat("[HG IM SERVICE]: Failed to deliver message to {0}", reginfo.ServerURI);
                return(false);
            }

            if (imresult)
            {
                // IM delivery successful, so store the Agent's location in our local cache.
                lock (m_UserLocationMap)
                {
                    if (m_UserLocationMap.ContainsKey(toAgentID))
                    {
                        m_UserLocationMap[toAgentID] = upd;
                    }
                    else
                    {
                        m_UserLocationMap.Add(toAgentID, upd);
                    }
                }
                return(true);
            }
            else
            {
                // try again, but lookup user this time.
                // Warning, this must call the Async version
                // of this method or we'll be making thousands of threads
                // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
                // The version that spawns the thread is SendGridInstantMessageViaXMLRPC

                // This is recursive!!!!!
                return(TrySendInstantMessage(im, upd, false, foreigner));
            }
        }
Exemple #22
0
 public void Cache(UUID userID, UserAccount account)
 {
     // Cache even null accounts
     lock (accessLock)
     {
         if (account == null)
         {
             m_UUIDCache.AddOrUpdate(userID, null, CACHE_NULL_EXPIRATION_SECONDS);
         }
         else if (account.LocalToGrid)
         {
             m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
             m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
         }
         else
         {
             m_UUIDCache.AddOrUpdate(userID, account, CACHE_ALIEN_EXPIRATION_SECONDS);
             m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_ALIEN_EXPIRATION_SECONDS);
         }
         //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
     }
 }
Exemple #23
0
        public void OnGetSnapshot(IOSHttpRequest req, IOSHttpResponse resp)
        {
            Hashtable reply = new Hashtable();
            string    reqtag;

            if (req.QueryAsDictionary.TryGetValue("region", out string snapObj) && !string.IsNullOrWhiteSpace(snapObj))
            {
                reqtag = snapObj + req.RemoteIPEndPoint.Address.ToString();
            }
            else
            {
                reqtag = req.RemoteIPEndPoint.Address.ToString();
            }

            if (!string.IsNullOrWhiteSpace(reqtag))
            {
                if (throotleGen.Contains(reqtag))
                {
                    resp.StatusCode        = (int)HttpStatusCode.ServiceUnavailable;
                    resp.StatusDescription = "Please try again later";
                    resp.ContentType       = "text/plain";
                    m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
                    return;
                }

                throotleGen.AddOrUpdate(reqtag, 0, 60);
            }

            if (string.IsNullOrWhiteSpace(snapObj))
            {
                m_log.DebugFormat("[DATASNAPSHOT] Received collection request for all");
            }
            else
            {
                m_log.DebugFormat("[DATASNAPSHOT] Received collection request for {0}", snapObj);
            }

            XmlDocument response = m_externalData.GetSnapshot(snapObj);

            if (response == null)
            {
                resp.StatusCode  = (int)HttpStatusCode.ServiceUnavailable;
                resp.ContentType = "text/plain";
                m_log.Debug("[DATASNAPSHOT] Collection request spam. reply try later");
                return;
            }

            resp.RawBuffer   = Util.UTF8NBGetbytes(response.OuterXml);
            resp.ContentType = "text/xml";
            resp.StatusCode  = (int)HttpStatusCode.OK;
        }
Exemple #24
0
        private List <XInventoryFolder> GetFolderTree(UUID principalID, UUID folder)
        {
            List <XInventoryFolder> t;

            if (m_SuitcaseTrees.TryGetValue(principalID, out t))
            {
                return(t);
            }

            // Get the tree of the suitcase folder
            t = GetFolderTreeRecursive(folder);
            m_SuitcaseTrees.AddOrUpdate(principalID, t, 5 * 60); // 5 minutes
            return(t);
        }
        public GridUserInfo GetGridUserInfo(string userID)
        {
            GridUserInfo info = null;

            if (m_Infos.TryGetValue(userID, out info))
            {
                return(info);
            }

            info = m_RemoteConnector.GetGridUserInfo(userID);

            m_Infos.AddOrUpdate(userID, info, KEEPTIME);

            return(info);
        }
Exemple #26
0
        private void GetMapItems()
        {
            itemRequesterIsRunning = true;
            while (true)
            {
                MapItemRequester item = null;
                if (m_itemsToRequest.Count > 0)
                {
                    item = m_itemsToRequest.Dequeue();
                }
                if (item == null)
                {
                    break; //Nothing in the queue
                }
                List <mapItemReply> mapitems;
                if (!m_mapItemCache.TryGetValue(item.regionhandle, out mapitems)) //try again, might have gotten picked up by this already
                {
                    multipleMapItemReply allmapitems = m_scene.GridService.GetMapItems(item.regionhandle, (GridItemType)item.itemtype);

                    if (allmapitems == null)
                    {
                        continue;
                    }
                    //Send out the update
                    if (allmapitems.items.ContainsKey(item.regionhandle))
                    {
                        mapitems = allmapitems.items[item.regionhandle];

                        //Update the cache
                        foreach (KeyValuePair <ulong, List <mapItemReply> > kvp in allmapitems.items)
                        {
                            m_mapItemCache.AddOrUpdate(kvp.Key, kvp.Value, 3 * 60); //5 mins
                        }
                    }
                }

                if (mapitems != null)
                {
                    item.remoteClient.SendMapItemReply(mapitems.ToArray(), item.itemtype, item.flags);
                }
                Thread.Sleep(5);
            }
            itemRequesterIsRunning = false;
        }
        /// <summary>
        /// Get an item, given by its UUID
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public InventoryItemBase GetItem(InventoryItemBase item)
        {
            InventoryItemBase retrieved = null;

            if (m_ItemCache.TryGetValue(item.ID, out retrieved))
            {
                return(retrieved);
            }

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetInventoryNode" },
                { "ItemID", item.ID.ToString() },
                { "OwnerID", item.Owner.ToString() },
                { "IncludeFolders", "1" },
                { "IncludeItems", "1" },
                { "ChildrenOnly", "1" }
            };

            OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);

            if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
            {
                List <InventoryItemBase> items = GetItemsFromResponse((OSDArray)response["Items"]);
                if (items.Count > 0)
                {
                    // The requested item should be the first in this list, but loop through
                    // and sanity check just in case
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i].ID == item.ID)
                        {
                            retrieved = items[i];
                            m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS);
                            return(retrieved);
                        }
                    }
                }
            }

            m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Item " + item.ID + " owned by " + item.Owner + " not found");
            return(null);
        }
Exemple #28
0
        public void Cache(UUID scopeID, UUID regionID, GridRegion rinfo)
        {
            // for now, do not cache negative results; this is because
            // we need to figure out how to handle regions coming online
            // in a timely way
            if (rinfo == null)
            {
                return;
            }

            ScopedRegionUUID id = new ScopedRegionUUID(scopeID, regionID);

            // Cache even null accounts
            m_UUIDCache.AddOrUpdate(id, rinfo, CACHE_EXPIRATION_SECONDS);
            if (rinfo != null)
            {
                ScopedRegionName name = new ScopedRegionName(scopeID, rinfo.RegionName);
                m_NameCache.AddOrUpdate(name, id, CACHE_EXPIRATION_SECONDS);
            }
        }
Exemple #29
0
        void SaveFileCacheForAsset(UUID assetId, OpenJPEG.J2KLayerInfo [] layers)
        {
            if (m_useCache)
            {
                m_decodedCache.AddOrUpdate(assetId, layers, TimeSpan.FromMinutes(10));
            }

            if (m_cache != null)
            {
                string assetID = "j2kCache_" + assetId;

                var layerDecodeAsset = new AssetBase(assetID, assetID, AssetType.Notecard,
                                                     UUID.Zero)
                {
                    Flags = AssetFlags.Local | AssetFlags.Temporary
                };

                #region Serialize Layer Data

                var    stringResult = new StringBuilder();
                string strEnd       = "\n";
                for (int i = 0; i < layers.Length; i++)
                {
                    if (i == layers.Length - 1)
                    {
                        strEnd = string.Empty;
                    }

                    stringResult.AppendFormat("{0}|{1}|{2}{3}", layers [i].Start, layers [i].End,
                                              layers [i].End - layers [i].Start, strEnd);
                }

                layerDecodeAsset.Data = Util.UTF8.GetBytes(stringResult.ToString());

                #endregion Serialize Layer Data

                m_cache.Cache(assetID, layerDecodeAsset);
            }
        }
Exemple #30
0
        static OSDMap CachedPostRequest(NameValueCollection requestArgs, string m_ServerURI)
        {
            // Immediately forward the request if the cache is disabled.
            if (m_cacheTimeout == 0)
            {
                return(WebUtils.PostToService(m_ServerURI, requestArgs));
            }

            // Check if this is an update or a request
            if (requestArgs["RequestMethod"] == "RemoveGeneric" ||
                requestArgs["RequestMethod"] == "AddGeneric"
                )
            {
                // Any and all updates cause the cache to clear
                m_memoryCache.Clear();

                // Send update to server, return the response without caching it
                return(WebUtils.PostToService(m_ServerURI, requestArgs));
            }

            // If we're not doing an update, we must be requesting data

            // Create the cache key for the request and see if we have it cached
            string CacheKey = WebUtils.BuildQueryString(requestArgs);
            OSDMap response = null;

            if (!m_memoryCache.TryGetValue(CacheKey, out response))
            {
                // if it wasn't in the cache, pass the request to the Simian Grid Services
                response = WebUtils.PostToService(m_ServerURI, requestArgs);

                // and cache the response
                m_memoryCache.AddOrUpdate(CacheKey, response, TimeSpan.FromSeconds(m_cacheTimeout));
            }

            // return cached response
            return(response);
        }