예제 #1
0
        public ActionResult Friends(string q)
        {
            var token = repository.GetOAuthToken(subdomainid.Value, sessionid.Value.ToString(), OAuthTokenType.FACEBOOK);

            if (token == null)
            {
                return(Json(JavascriptReturnCodes.NOTOKEN.ToJsonOKData(), JsonRequestBehavior.AllowGet));
            }
            var facebook = new FacebookService(token.token_key);

            // see if this is cached
            var cachekey = "friends" + token.token_key;
            var cached   = SimpleCache.Get(cachekey, SimpleCacheType.FACEBOOK) as ResponseCollection <IdName>;

            if (cached == null)
            {
                var response = facebook.People.GetFriends("me");
                SimpleCache.Add(cachekey, response, SimpleCacheType.FACEBOOK);
                cached = response;
            }

            var friends = cached.data.Where(x => x.name.StartsWith(q, true, CultureInfo.InvariantCulture)).Select(x => new { x.id, x.name });

            return(Json(friends.ToList(), JsonRequestBehavior.AllowGet));
        }
예제 #2
0
    /// <summary>
    /// マネージャー取得
    /// </summary>
    /// <typeparam name="T">マネージャータイプ</typeparam>
    /// <returns>マネージャーインスタンス</returns>
    public static T GetManager <T>() where T : MonoBehaviour
    {
        // キャッシュ検索
        if (cache.IsCache <T>())
        {
            // マネージャーの階層を深くしないつくりのため、ダウンキャスト ※ジェネリック解決のためだけの階層は作らない
            return((T)cache.Get <T>());
        }

        // コンポーネント検索用オブジェクト取得 ※マネージャー用ゲームオブジェクトは今のところひとつに絞る想定なので、直接シングルトン化
        GameObject globalGameObject = Singleton <GameObject> .Instance;

        globalGameObject.name = "GlobalManagerObject";

        // マネージャー検索
        T ret = globalGameObject.GetComponent <T>();

        // マネージャーが見つからない場合、新規作成
        if (ret == null)
        {
            ret = GetManager <T>(globalGameObject);
        }

        // キャッシュ対象ならインスタンスをキャッシュ
        if (ret is GlobalManager && ((GlobalManager)(object)ret).IsCacheInstans)
        {
            cache.Add(ret);
        }

        return(ret);
    }
예제 #3
0
 private static void AddToCache(SimpleCache cache, string key, BaseDef def)
 {
     AddToTypeCache(def);
     if (key == null)
     {
         key = "";
     }
     if (!cache.TryGetValue(key, out object data))
     {
         cache.Add(key, def);
         return;
     }
     if (data is BaseDef[] list)
     {
         var len     = list.Length;
         var newList = new BaseDef[len + 1];
         Array.Copy(list, newList, len);
         newList[len] = def;
         cache[key]   = newList;
     }
     else
     {
         cache[key] = new BaseDef[] { data as BaseDef, def }
     };
 }
예제 #4
0
        public void Clearing_cache_should_work_as_expected()
        {
            /* Arrange */
            var c = new SimpleCache<string, string>();

            /* Act */
            c.Add("Val1", "TheValue", 10000, false);
            c.Add("Val2", "TheValue2", 10000, false);

            int countPre = c.Count;
            c.Clear();
            int countPost = c.Count;

            /* Assert */
            countPre.Should().Be(2);
            countPost.Should().Be(0);
        }
예제 #5
0
        public void SetAuthToken(AuthTokenDto token, string key)
        {
            var authToken = _localData.Get(key);

            if (authToken != null)
            {
                _localData.Remove(key);
            }
            _localData.Add(key, token);
        }
예제 #6
0
        public void SetAuthToken(AuthTokenDto token)
        {
            var key       = string.Format("{0}|{1}", token.ServerDto.ServerName, token.Login.TenantName);
            var authToken = _localData.Get(key);

            if (authToken != null)
            {
                _localData.Remove(key);
            }
            _localData.Add(key, token);
        }
예제 #7
0
        /// Operation DownloadMapData
        /// <summary>
        /// Gets the map data with the given ID.
        /// <p><strong>Implementation Notes</strong></p>
        /// <ul type="disc">
        /// <li>If mapDataCache is not null, and if mapDataCache has an entry for this mapId, return the MapData for that ID.</li>
        /// <li>Call retriever.DownloadMapData(mapId) to get the MapData.</li>
        /// <li>If mapDataCache is not null, add the retrieved MapData mapDataCache with the mapId as the key.</li>
        /// </ul>           /// </summary>
        /// <exception>MapIdNotFoundException If there is no MapData with the given ID</exception>
        /// <exception>MapDataSourceException If there were errors during this operation</exception>
        /// <param name='mapId'>The ID of the MapData to be retrieved</param>
        /// <returns>Retrieved MapData</returns>
        public MapData DownloadMapData(long mapId)
        {
            if ((mapDataCache != null) && mapDataCache.ContainsKey(mapId))
            {
                return((MapData)mapDataCache[mapId]);
            }
            MapData mapData = retriever.DownloadMapData(mapId);

            if (mapDataCache != null)
            {
                mapDataCache.Add(mapId, mapData);
            }
            return(mapData);
        }
예제 #8
0
        /// Operation DownloadAttributeTypes
        /// <summary>
        /// Gets all available MapAttributeTypes. Returns an empty list if none found. It will never return null or a list with null elements.
        /// <p><strong>Implementation Notes</strong></p>
        /// <ul type="disc">
        /// <li>If attributeTypeCache is not null, and if attributeTypeCache has an entry for &quot;attributeTypes&quot;, return the IList of MapAttributeType for that key.</li>
        /// <li>Call retriever.DownloadAttributeTypes() to get the IList of MapAttributeType.</li>
        /// <li>If attributeTypeCache is not null, add the retrieved IList of MapAttributeType to attributeTypeCache with &quot;attributeTypes&quot; as the key.</li>
        /// </ul>           /// </summary>
        /// <exception>MapDataSourceException If there were errors during this operation</exception>
        /// <returns>List of available MapAttributeTypes</returns>
        public IList <MapAttributeType> DownloadAttributeTypes()
        {
            if ((attributeTypeCache != null) && attributeTypeCache.ContainsKey("attributeTypes"))
            {
                return((IList <MapAttributeType>)attributeTypeCache["attributeTypes"]);
            }
            IList <MapAttributeType> attributeTypes = retriever.DownloadAttributeTypes();

            if (attributeTypeCache != null)
            {
                attributeTypeCache.Add("attributeTypes", attributeTypes);
            }

            return(attributeTypes);
        }
예제 #9
0
        /// Operation DownloadStyles
        /// <summary>
        /// Gets all styles of the map data with the given ID. Returns an empty list if none found. It will never return null or a list with null elements.
        /// <p><strong>Implementation Notes</strong></p>
        /// <ul type="disc">
        /// <li>If styleCache is not null, and if styleCache has an entry for this mapId, return the IList of MapStyle for that ID.</li>
        /// <li>Call retriever.DownloadStyles(mapId) to get the IList of MapStyle.</li>
        /// <li>If styleCache is not null, add the retrieved IList of MapStyle to styleCache with the mapId as the key.</li>
        /// </ul>           /// </summary>
        /// <exception>MapIdNotFoundException If there is no MapData with the given ID</exception>
        /// <exception>MapDataSourceException If there were errors during this operation</exception>
        /// <param name='mapId'>The ID of the MapData whose styles are to be retrieved</param>
        /// <returns>List of MapStyles of the map data with the given ID</returns>
        public IList <MapStyle> DownloadStyles(long mapId)
        {
            if ((styleCache != null) && styleCache.ContainsKey(mapId))
            {
                return((IList <MapStyle>)styleCache[mapId]);
            }
            IList <MapStyle> styles = retriever.DownloadStyles(mapId);

            if (styleCache != null)
            {
                styleCache.Add(mapId, styles);
            }

            return(styles);
        }
예제 #10
0
        /// Operation DownloadElementTypes
        /// <summary>
        /// Gets all available MapElementTypes. Returns an empty list if none found. It will never return null or a list with null elements.
        /// <p><strong>Implementation Notes</strong></p>
        /// <ul type="disc">
        /// <li>If elementTypeCache is not null, and if elementTypeCache has an entry for &quot;elementTypes&quot;, return the IList of MapElementType for that key.</li>
        /// <li>Call retriever.DownloadElementTypes() to get the IList of MapElementType.</li>
        /// <li>If elementTypeCache is not null, add the retrieved IList of MapElementType to elementTypeCache with &quot;elementTypes&quot; as the key.</li>
        /// </ul>           /// </summary>
        /// <exception>MapDataSourceException If there were errors during this operation</exception>
        /// <returns>List of available MapElementTypes</returns>
        public IList <MapElementType> DownloadElementTypes()
        {
            if ((elementTypeCache != null) && elementTypeCache.ContainsKey("elementTypes"))
            {
                return((IList <MapElementType>)elementTypeCache["elementTypes"]);
            }
            IList <MapElementType> elementTypes = retriever.DownloadElementTypes();

            if (elementTypeCache != null)
            {
                elementTypeCache.Add("elementTypes", elementTypes);
            }

            return(elementTypes);
        }
예제 #11
0
        public void Adding_and_retrieving_an_item_should_work_as_expected()
        {
            /* Arrange */
            var c = new SimpleCache<string, string>();
            string key = "Val1";

            /* Act */
            c.Add(key, "TheValue", 10000, false);

            bool exists = c.Contains(key);
            string val = c[key];

            /* Assert */
            exists.Should().BeTrue();
            val.Should().Be("TheValue");
        }
예제 #12
0
        public void Basic_expiration_should_work_as_expected()
        {
            /* Arrange */
            var c = new SimpleCache<string, string>();
            string key = "Val1";

            /* Act */
            c.Add(key, "TheValue", 10, false);

            Thread.Sleep(11);

            bool exists = c.Contains(key);
            string val = c[key];

            /* Assert */
            exists.Should().BeFalse();
            val.Should().BeNull();
        }
예제 #13
0
파일: Courses.cs 프로젝트: fredwong-it/Mars
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get",
                                                           Route = "courses")] HttpRequestMessage req, TraceWriter log)
        {
            log.Info("Courses Request");

            string course = (string)_cache.Get("GetCourses");

            if (course == null)
            {
                StorageService service = new StorageService();
                course = service.GetCourses();
                int cacheInMinutes = AppSettings.CourseCacheInMinutes;
                _cache.Add("GetCourses", cacheInMinutes, course);
                log.Info("course refresh");
            }

            // Fetching the name from the path parameter in the request URL
            return(req.CreateResponse(HttpStatusCode.OK, course, "application/json"));
        }
예제 #14
0
        public void Auto_cleanup_should_work_as_expected()
        {
            /* Arrange */
            var c = new SimpleCache<string, string>(15);
            string key = "Val1";

            /* Act */
            c.Add(key, "TheValue", 10, true);
            int countPre = c.Count;

            Thread.Sleep(20);
            string val = c[key];
            int countPost = c.Count;

            /* Assert */
            countPre.Should().Be(1);
            countPost.Should().Be(0);
            val.Should().BeNull();
        }
예제 #15
0
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get",
                                                           Route = "Services/{name}")] HttpRequestMessage req, string name, TraceWriter log)
        {
            // if user is authenticated and authorized, otherwise return nothing
            string email = UserManager.GetAuthenticatedEmail();

            log.Info(email);

            string list = (string)_cache.Get(name);

            if (list == null)
            {
                StorageService service = new StorageService();
                list = service.ListFilesOrDirectories(name.Replace("-", "/"));

                int fileCacheInMinutes = AppSettings.FolderCacheInMinutes;
                _cache.Add(name, fileCacheInMinutes, list);
                log.Info("course folder refresh");
            }

            // Fetching the name from the path parameter in the request URL
            return(req.CreateResponse(HttpStatusCode.OK, list, "application/json"));
        }
예제 #16
0
 /// <summary>
 /// クエリキャッシュ追加
 /// </summary>
 /// <param name="key">キー</param>
 /// <param name="query">クエリ</param>
 protected void AddQueryCache(string key, string query)
 {
     queryCache.Add(CreateQueryCacheKey(key));
 }
예제 #17
0
        public void GetVisitorStatistics(string hostname, DateTime startDate, DateTime endDate)
        {
            var query = new DataQuery(BaseUrl)
            {
                Ids         = TableId,
                Dimensions  = "ga:date,ga:referralPath,ga:source,ga:keyword,ga:country",
                Metrics     = "ga:visits,ga:pageviews,ga:timeOnSite",
                Segment     = string.Format("dynamic::ga:hostname=={0}", hostname),
                Sort        = "ga:date",
                GAStartDate = startDate.ToString("yyyy-MM-dd"),
                GAEndDate   = endDate.ToString("yyyy-MM-dd")
            };

            Uri url = query.Uri;

            try
            {
                // try to get from the cache first
                var cachekey = string.Concat(hostname, startDate.ToShortDateString(), endDate.ToShortDateString());
                var data     = SimpleCache.Get(cachekey, SimpleCacheType.GOOGLE_ANALYTICS);
                if (data == null)
                {
                    data = service.Query(query);
                    SimpleCache.Add(cachekey, data, SimpleCacheType.GOOGLE_ANALYTICS, DateTime.UtcNow.AddDays(1));
                }

                feed = (DataFeed)data;

                FeedTitle    = feed.Title.Text;
                FeedID       = feed.Id.Uri.Content;
                TotalResults = feed.TotalResults;
                StartIndex   = feed.StartIndex;
                ItemsPerPage = feed.ItemsPerPage;

                foreach (DataEntry entry in feed.Entries)
                {
                    var stat = new VisitorStat();
                    foreach (var dimension in entry.Dimensions)
                    {
                        switch (dimension.Name)
                        {
                        case "ga:country":
                            stat.country = dimension.Value;
                            break;

                        case "ga:date":
                            stat.visitDate = DateTime.ParseExact(dimension.Value, "yyyyMMdd", CultureInfo.InvariantCulture);
                            break;

                        case "ga:referralPath":
                            stat.referrerPath = dimension.Value;
                            break;

                        case "ga:source":
                            stat.referrerHostname = dimension.Value;
                            break;

                        case "ga:keyword":
                            stat.keyword = dimension.Value;
                            break;
                        }
                    }
                    foreach (var metric in entry.Metrics)
                    {
                        switch (metric.Name)
                        {
                        case "ga:visits":
                            stat.visitCount = metric.IntegerValue;
                            break;

                        case "ga:pageviews":
                            stat.pageViews = metric.IntegerValue;
                            break;

                        case "ga:timeOnSite":
                            stat.timeOnSite = metric.FloatValue;
                            break;
                        }
                    }
                    stats.Add(stat);
                }
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
                Syslog.Write(string.Concat(ex.Message, ":", url.ToString()));
            }
        }
예제 #18
0
        public void Sliding_expiration_should_work_as_expected()
        {
            /* Arrange */
            var c = new SimpleCache<string, string>();
            string key = "Val1";

            /* Act */
            c.Add(key, "TheValue", 10, true);

            Thread.Sleep(5);
            string val1 = c[key];

            Thread.Sleep(5);
            string val2 = c[key];

            Thread.Sleep(11);
            string val3 = c[key];

            /* Assert */
            val1.Should().Be("TheValue");
            val2.Should().Be("TheValue");
            val3.Should().BeNull();
        }