示例#1
0
文件: TestCache.cs 项目: Daoting/dt
        public async Task <long> CacheLong(string p_key, long p_val)
        {
            var cache = new StringCache("Test:Long");
            await cache.Set(p_key, p_val);

            return(await cache.Get <long>(p_key));
        }
示例#2
0
文件: TestCache.cs 项目: Daoting/dt
        public async Task <string> CacheStr(string p_key, string p_val)
        {
            var cache = new StringCache("Test:Str");
            await cache.Set(p_key, p_val);

            return(await cache.Get <string>(p_key));
        }
 public void Adds_and_retrieves_short_content_safely()
 {
     const string input = "This will not compress";
     var cache = new StringCache();
     var added = cache.Add("short", input);
     Assert.IsTrue(added);
     var retrieved = cache.Get("short");
     Assert.AreEqual(input, retrieved);
 }
示例#4
0
        public void StringCacheEnforcesAgeLimit()
        {
            // Test correct normal behavior with large limit
            StringCache cache = new StringCache(2000000, 10);

            cache.Add(key0, value0);
            Assert.AreEqual(value0, cache.Get(key0));

            // Test that an expiration time of 0 minutes immediately expires everything.
            cache = new StringCache(2000000, 0);
            cache.Add(key0, value0);
            Assert.IsNull(cache.Get(key0));
            cache.Add(key1, value1);
            Assert.IsNull(cache.Get(key1));
            cache.Add(key2, value2);
            cache.Add(key3, value3);
            Assert.IsNull(cache.Get(key2));
            Assert.IsNull(cache.Get(key3));
        }
示例#5
0
        public void Adds_and_retrieves_short_content_safely()
        {
            const string input = "This will not compress";
            var          cache = new StringCache();
            var          added = cache.Add("short", input);

            Assert.IsTrue(added);
            var retrieved = cache.Get("short");

            Assert.AreEqual(input, retrieved);
        }
        public XamarinEntry(XamarinTraceCode code, string description, StringCache stringCache)
            : base(stringCache)
        {
            this.Code = code;

            this.BindingPath        = string.Empty;
            this.DataItemType       = string.Empty;
            this.TargetElementType  = string.Empty;
            this.TargetProperty     = string.Empty;
            this.TargetPropertyType = string.Empty;
            this.Description        = stringCache.Get(description);
        }
示例#7
0
文件: TestCache.cs 项目: Daoting/dt
        public async Task CacheStrObj(string p_key, string p_name, int p_age)
        {
            var cache = new StringCache("Test:StrObj");
            await cache.Set(p_key, new TestCacheObject { Name = p_name, Age = p_age });

            var obj = await cache.Get <TestCacheObject>(p_key);

            if (obj != null && !string.IsNullOrEmpty(obj.Name))
            {
                _log.Information(obj.Name);
            }
        }
示例#8
0
文件: MsgKit.cs 项目: Daoting/dt
        /// <summary>
        /// 若用户在线则推送消息,不在线返回false
        /// </summary>
        /// <param name="p_userID"></param>
        /// <param name="p_msg"></param>
        /// <returns>true 已在线推送,false不在线</returns>
        public static async Task <bool> PushIfOnline(long p_userID, MsgInfo p_msg)
        {
            if (Online.All.TryGetValue(p_userID, out var ls) &&
                ls != null &&
                ls.Count > 0)
            {
                // 本地在线推送
                ls[0].AddMsg(p_msg.GetOnlineMsg());
                return(true);
            }

            // 查询所有其他副本
            int cnt = await Kit.GetSvcReplicaCount();

            if (cnt > 1)
            {
                string key = $"msg:PushIfOnline:{p_userID}:{Guid.NewGuid().ToString().Substring(0, 6)}";
                Kit.RemoteMulticast(new OnlinePushEvent
                {
                    PrefixKey = key,
                    Receivers = new List <long> {
                        p_userID
                    },
                    Msg = p_msg.GetOnlineMsg(),
                    PushFirstSession = true
                });

                // 等待收集
                int total, retry = 0;
                var sc = new StringCache(key);
                do
                {
                    await Task.Delay(_delayMilli);

                    total = await sc.Get <int>("cnt");

                    retry++;
                }while (total < cnt && retry < _maxRetry);

                // 删除统计总数
                await sc.Delete("cnt");

                // 存在键值表示在线
                if (await sc.Delete(null))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#9
0
        public UwpEntry(UwpTraceCode code, Match descriptionMatch, Match bindingExpressionMatch, StringCache stringCache)
            : base(stringCache)
        {
            this.Code = code;

            this.BindingPath        = stringCache.Get(bindingExpressionMatch.Groups[nameof(this.BindingPath)].Value);
            this.DataItemType       = stringCache.Get(bindingExpressionMatch.Groups[nameof(this.DataItemType)].Value);
            this.TargetElementType  = stringCache.Get(bindingExpressionMatch.Groups[nameof(this.TargetElementType)].Value);
            this.TargetElementName  = stringCache.Get(bindingExpressionMatch.Groups[nameof(this.TargetElementName)].Value);
            this.TargetProperty     = stringCache.Get(bindingExpressionMatch.Groups[nameof(this.TargetProperty)].Value);
            this.TargetPropertyType = stringCache.Get(bindingExpressionMatch.Groups[nameof(this.TargetPropertyType)].Value);
            this.Description        = stringCache.Get(this.CreateDescription(descriptionMatch));
        }
示例#10
0
        public void Adds_and_retrieves_long_content_safely()
        {
            var sb = new StringBuilder();
            for(var i = 0; i < 1000; i++)
            {
                sb.Append("I will not write loops in unit tests.");
            }
            var input = sb.ToString();

            var cache = new StringCache();
            var added = cache.Add("long", input);
            Assert.IsTrue(added);
            var retrieved = cache.Get("long");
            Assert.AreEqual(input, retrieved);
        }
示例#11
0
文件: Pusher.cs 项目: Daoting/dt
        /// <summary>
        /// 实时获取所有副本的在线用户总数
        /// </summary>
        /// <returns>Dict结构:key为副本id,value为副本会话总数</returns>
        public async Task <Dict> GetOnlineCount()
        {
            Dict result = null;
            int  cnt    = await Kit.GetSvcReplicaCount();

            if (cnt > 1)
            {
                // 所有副本
                string key = "msg:OnlineCount:" + Guid.NewGuid().ToString().Substring(0, 6);
                Kit.RemoteMulticast(new OnlineCountEvent {
                    CacheKey = key
                });

                // 等待收集
                int total, retry = 0;
                var sc = new StringCache(key);
                do
                {
                    await Task.Delay(_delayMilli);

                    total = await sc.Get <int>("cnt");

                    retry++;
                }while (total < cnt && retry < _maxRetry);

                // 删除统计总数
                await sc.Delete("cnt");

                var hc   = new HashCache(key);
                var hash = await hc.GetAll(null);

                if (hash != null && hash.Length > 0)
                {
                    await hc.Delete(null);

                    result = hash.ToDict();
                }
            }
            else
            {
                // 当前单副本
                result = new Dict {
                    { Kit.SvcID, Online.TotalCount }
                };
            }
            return(result);
        }
示例#12
0
文件: MsgKit.cs 项目: Daoting/dt
        /// <summary>
        /// 多副本推送
        /// </summary>
        /// <param name="p_userIDs">用户列表</param>
        /// <param name="p_msg">待推送信息</param>
        /// <param name="p_onlines"></param>
        /// <param name="p_offlines"></param>
        /// <param name="p_cnt"></param>
        static async Task PushMultipleReplicas(List <long> p_userIDs, string p_msg, List <long> p_onlines, List <long> p_offlines, int p_cnt)
        {
            /*
             * Msg服务多副本运行时,有以下两种处理方案:
             * 1. 由当前副本通知所有副本,每个副本都检查会话是否存在,存在时推送并做已推送标志,再由当前副本汇总离线列表
             * 2. 将所有副本的会话信息缓存在redis,当前副本查询缓存获取会话所在的副本,再通过事件总线推送到指定副本
             * 当前采用方案1,因方案2在某个副本非正常退出时,缓存的会话未能与实际同步,造成冗余的推送!
             * 方案1的缺点是所有副本都需要检查会话是否存在
             */

            // 推送结果的前缀键
            string prefixKey = "msg:Push:" + Guid.NewGuid().ToString().Substring(0, 6);

            // 通知所有副本推送
            Kit.RemoteMulticast(new OnlinePushEvent {
                PrefixKey = prefixKey, Receivers = p_userIDs, Msg = p_msg
            });

            // 等待收集
            int total, retry = 0;
            var sc = new StringCache(prefixKey);

            do
            {
                await Task.Delay(_delayMilli);

                total = await sc.Get <int>("cnt");

                retry++;
            }while (total < p_cnt && retry < _maxRetry);

            // 删除统计总数
            await sc.Delete("cnt");

            foreach (long id in p_userIDs)
            {
                // 有记录的表示在线推送成功
                if (await sc.Delete(id))
                {
                    p_onlines.Add(id);
                }
                else
                {
                    p_offlines.Add(id);
                }
            }
        }
示例#13
0
        public XamarinEntry(XamarinTraceCode code, Match match, StringCache stringCache)
            : base(stringCache)
        {
            this.Code = code;

            this.BindingPath        = stringCache.Get(match.Groups[nameof(this.BindingPath)].Value);
            this.DataItemType       = stringCache.Get(match.Groups[nameof(this.DataItemType)].Value);
            this.TargetElementType  = stringCache.Get(match.Groups[nameof(this.TargetElementType)].Value);
            this.TargetProperty     = stringCache.Get(match.Groups[nameof(this.TargetProperty)].Value);
            this.TargetPropertyType = stringCache.Get(match.Groups[nameof(this.TargetPropertyType)].Value);
            this.Description        = stringCache.Get(this.CreateDescription(match));
        }
示例#14
0
        public BindingEntry(int errorCode, string description, StringCache stringCache)
        {
            this.stringCache = stringCache;
            this.ErrorCode   = errorCode;
            this.Count       = 1;

            this.Description        = stringCache.Get(description);
            this.SourceProperty     = string.Empty;
            this.SourcePropertyType = string.Empty;
            this.SourcePropertyName = string.Empty;
            this.BindingPath        = string.Empty;
            this.DataItemType       = string.Empty;
            this.DataItemName       = string.Empty;
            this.TargetElementType  = string.Empty;
            this.TargetElementName  = string.Empty;
            this.TargetProperty     = string.Empty;
            this.TargetPropertyType = string.Empty;
        }
示例#15
0
        public void Adds_and_retrieves_long_content_safely()
        {
            var sb = new StringBuilder();

            for (var i = 0; i < 1000; i++)
            {
                sb.Append("I will not write loops in unit tests.");
            }
            var input = sb.ToString();

            var cache = new StringCache();
            var added = cache.Add("long", input);

            Assert.IsTrue(added);
            var retrieved = cache.Get("long");

            Assert.AreEqual(input, retrieved);
        }
示例#16
0
        public WpfEntry(WpfTraceInfo info, string description, StringCache stringCache)
            : base(stringCache)
        {
            this.Info = info;

            this.SourceProperty     = string.Empty;
            this.SourcePropertyType = string.Empty;
            this.SourcePropertyName = string.Empty;
            this.BindingPath        = string.Empty;
            this.DataItemType       = string.Empty;
            this.DataItemName       = string.Empty;
            this.DataValue          = string.Empty;
            this.TargetElementType  = string.Empty;
            this.TargetElementName  = string.Empty;
            this.TargetProperty     = string.Empty;
            this.TargetPropertyType = string.Empty;
            this.Description        = stringCache.Get(description);
        }
示例#17
0
文件: Pusher.cs 项目: Daoting/dt
        /// <summary>
        /// 注销客户端
        /// 1. 早期版本在客户端关闭时会造成多个无关的ClientInfo收到Abort,只能从服务端Abort,升级到.net 5.0后不再出现该现象!!!
        /// 2. 使用客户端 response.Dispose() 主动关闭时,不同平台现象不同,服务端能同步收到uwp关闭消息,但android ios上不行,
        ///    直到再次推送时才发现客户端已关闭,为了保证客户端在线状态实时更新,客户端只能调用该方法!!!
        /// </summary>
        /// <param name="p_userID"></param>
        /// <param name="p_sessionID">会话标识,区分同一账号多个登录的情况</param>
        /// <returns></returns>
        public async Task <bool> Unregister(long p_userID, string p_sessionID)
        {
            var ci = Online.GetSession(p_userID, p_sessionID);

            if (ci != null)
            {
                await ci.Close();

                return(true);
            }

            // 查询所有其他副本
            int cnt = await Kit.GetSvcReplicaCount();

            if (cnt > 1)
            {
                string key = $"msg:Unregister:{p_userID}:{Guid.NewGuid().ToString().Substring(0, 6)}";
                Kit.RemoteMulticast(new UnregisterEvent {
                    CacheKey = key, UserID = p_userID, SessionID = p_sessionID
                });

                // 等待收集
                int total, retry = 0;
                var sc = new StringCache(key);
                do
                {
                    await Task.Delay(_delayMilli);

                    total = await sc.Get <int>("cnt");

                    retry++;
                }while (total < cnt && retry < _maxRetry);

                // 删除统计总数
                await sc.Delete("cnt");

                // 存在键值表示在线
                if (await sc.Delete(null))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#18
0
        void OnGUI()
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            var fpsString = _stringCache.Get(CurrentFps);

#if UNITY_EDITOR
            CalculateRect();
#endif
            if (_drawShadow)
            {
                GUI.color = Color.black;
                GUI.Label(_rectShadow, fpsString, _style);
            }
            GUI.color = _color;
            GUI.Label(_rect, fpsString, _style);
        }
示例#19
0
 public string GetUtf8String()
 {
     if (Position == 0)
     {
         return(string.Empty);
     }
     else if (Position < 256)
     {
         for (var i = 0; i < Position; i++)
         {
             var ch = Buffer[i];
             if (ch > 126)
             {
                 return(UTF8.GetString(Buffer, 0, Position));
             }
             Chars[i] = (char)ch;
         }
         return(Cache.Get(Chars, Position));
     }
     return(UTF8.GetString(Buffer, 0, Position));
 }
示例#20
0
        private string Good(int fieldEnd, bool inQuotes, bool hasQuotes, bool bySeparator)
        {
            // NOTE: this method not only unquotes field, but it also updates state machine
            int pos = position + (inQuotes ? 1 : 0);
            int end = fieldEnd - (inQuotes ? 1 : 0);

            position = fieldEnd + (bySeparator ? 1 : 0);
            eol      = !bySeparator;
            if (hasQuotes)
            {
                int n = pos;
                for (int i = pos; i < end; i++)
                {
                    if ((buf[n++] = buf[i]) == quote)
                    {
                        i++;
                    }
                }
                end = n;
            }
            return(strings.Get(buf, pos, end - pos));
        }
示例#21
0
        public void StringCacheEnforcesSizeLimit()
        {
            // Test correct normal behavior with large limit
            StringCache cache = new StringCache(2000000, 10);

            cache.Add(key2, value2);
            Assert.AreEqual(value2, cache.Get(key2));

            // Edge case: cache size limit is exactly the calculated size of the cached item (requires knowledge of the implementation details of the cache).
            // In this case, we are using a reference type for key and value, which means 3 references will be counted.
            // We also have one reference for the CacheItem used to wrap around the Value, and 8 bytes for the DateTime used to calculate its age.
            int overhead     = (ObjectSize.ReferenceSize * 4) + 8;
            int requiredSize = overhead + (int)ObjectSize.SizeOf(key2) + (int)ObjectSize.SizeOf(value2);

            cache = new StringCache(requiredSize, 10);
            cache.Add(key2, value2);
            Assert.AreEqual(value2, cache.Get(key2));

            // Edge case: cache size limit one byte smaller than required
            cache = new StringCache(requiredSize - 1, 10);
            cache.Add(key2, value2);
            Assert.IsNull(cache.Get(key2));      // Value should fail to load from the cache, because it should have been removed for being over the limit.

            cache.Add(key0, value0);             // Adding a shorter value should work
            Assert.AreEqual(value0, cache.Get(key0));

            cache.Add(key0, value0);             // Adding the same key again with the same value should change nothing
            Assert.AreEqual(value0, cache.Get(key0));

            cache.Add(key0, value1);             // Adding the same key again with a DIFFERENT but equal length value should work
            Assert.AreEqual(value1, cache.Get(key0));

            cache.Add(key2, value2);             // Adding the oversized value again should cause the cache to be empty.
            Assert.IsNull(cache.Get(key0));      // Value should fail to load from the cache, because it should have been removed for being over the limit.
            Assert.IsNull(cache.Get(key2));      // Value should fail to load from the cache, because it should have been removed for being over the limit.
        }
示例#22
0
文件: Pusher.cs 项目: Daoting/dt
        /// <summary>
        /// 查询所有副本,获取某账号的所有会话信息
        /// </summary>
        /// <param name="p_userID"></param>
        /// <returns>会话信息列表</returns>
        public async Task <List <Dict> > GetAllSessions(long p_userID)
        {
            List <Dict> result = new List <Dict>();
            int         cnt    = await Kit.GetSvcReplicaCount();

            if (cnt > 1)
            {
                // 查询所有副本
                string key = $"msg:Sessions:{p_userID}:{Guid.NewGuid().ToString().Substring(0, 6)}";
                Kit.RemoteMulticast(new UserSessionsEvent {
                    CacheKey = key, UserID = p_userID
                });

                // 等待收集
                int total, retry = 0;
                var sc = new StringCache(key);
                do
                {
                    await Task.Delay(_delayMilli);

                    total = await sc.Get <int>("cnt");

                    retry++;
                }while (total < cnt && retry < _maxRetry);

                // 删除统计总数
                await sc.Delete("cnt");

                var hc   = new HashCache(key);
                var hash = await hc.GetAll(null);

                if (hash != null && hash.Length > 0)
                {
                    await hc.Delete(null);

                    var dt = hash.ToDict();
                    foreach (var item in dt)
                    {
                        var ss = Kit.Deserialize <List <Dict> >((string)item.Value);
                        if (ss != null && ss.Count > 0)
                        {
                            result.AddRange(ss);
                        }
                    }
                }
            }
            else
            {
                // 当前单副本
                var ls = Online.GetSessions(p_userID);
                if (ls != null && ls.Count > 0)
                {
                    foreach (var ci in ls)
                    {
                        result.Add(new Dict
                        {
                            { "userid", ci.UserID },
                            { "svcid", Kit.SvcID },
                            { "starttime", ci.StartTime.ToString() },
                            { "platform", ci.Platform },
                            { "version", ci.Version },
                            { "devicename", ci.DeviceName },
                            { "devicemodel", ci.DeviceModel },
                        });
                    }
                }
            }
            return(result);
        }
示例#23
0
        public void StringCacheRemembersItemsUniquely()
        {
            StringCache cache = new StringCache(2000000, 10);

            cache.Add(key0, value0);
            cache.Add(key1, value1);
            cache.Add(key2, value2);
            cache.Add(key3, value3);
            Assert.AreEqual(value0, cache.Get(key0));
            Assert.AreEqual(value1, cache.Get(key1));
            Assert.AreEqual(value2, cache.Get(key2));
            Assert.AreEqual(value3, cache.Get(key3));

            // Test unmapped inputs
            Assert.IsNull(cache.Get(null));
            Assert.IsNull(cache.Get(""));
            Assert.IsNull(cache.Get("I Do Not Exist as a Key"));

            // Test that null can be used as a key or as a value
            cache.Add(null, "I'm with null");
            cache.Add("I have a null value", null);
            Assert.AreEqual("I'm with null", cache.Get(null));
            Assert.IsNull(cache.Get("I have a null value"));

            // Test that null can be used as a key and as a value
            cache.Add(null, null);
            Assert.IsNull(cache.Get(null));

            // Test that adding a key after failing to retrieve it causes correct behavior
            cache.Add("", "I am a new value");
            Assert.AreEqual("I am a new value", cache.Get(""));
        }
示例#24
0
        public WpfEntry(WpfTraceInfo info, Match match, StringCache stringCache)
        {
            this.stringCache = stringCache;
            this.Info        = info;
            this.Count       = 1;

            this.SourceProperty     = stringCache.Get(match.Groups[nameof(this.SourceProperty)].Value);
            this.SourcePropertyType = stringCache.Get(match.Groups[nameof(this.SourcePropertyType)].Value);
            this.SourcePropertyName = stringCache.Get(match.Groups[nameof(this.SourcePropertyName)].Value);
            this.BindingPath        = stringCache.Get(match.Groups[nameof(this.BindingPath)].Value);
            this.DataItemType       = stringCache.Get(match.Groups[nameof(this.DataItemType)].Value);
            this.DataItemName       = stringCache.Get(match.Groups[nameof(this.DataItemName)].Value);
            this.DataValue          = stringCache.Get(match.Groups[nameof(this.DataValue)].Value);
            this.TargetElementType  = stringCache.Get(match.Groups[nameof(this.TargetElementType)].Value);
            this.TargetElementName  = stringCache.Get(match.Groups[nameof(this.TargetElementName)].Value);
            this.TargetProperty     = stringCache.Get(match.Groups[nameof(this.TargetProperty)].Value);
            this.TargetPropertyType = stringCache.Get(match.Groups[nameof(this.TargetPropertyType)].Value);
            this.Description        = stringCache.Get(this.CreateDescription(match));
        }
示例#25
0
    public void LoadConfigs()
    {
        StringCache instance = PersistentSingleton <StringCache> .Instance;

        Biomes = BiomeParser.ParseBiomes(instance.Get("biomes"));
        BossChunkGeneratings = ChunkGeneratingParser.ParseChunkGeneratings(instance.Get("boss_chunk_generating"));
        ChunkMaps            = new List <ChunkMapConfig>();
        for (int i = 0; i <= 4; i++)
        {
            ChunkMaps.Add(ChunkMapParser.ParseChunkMap(instance.Get("ChunkMaps/chunk_map_" + i)));
        }
        ChunkGeneratings = ChunkGeneratingParser.ParseChunkGeneratings(instance.Get("chunk_generating"));
        Skills           = SkillParser.ParseSkills(instance.Get("skills"));
        Heroes           = HeroParser.ParseHeros(instance.Get("heros"));
        Boosters         = BoosterParser.ParseBoosters(instance.Get("boosters"));
        string text = instance.Get("perk_milestones");

        PerkMilestones          = PerkMilestoneParser.ParsePerkMilestonesLevels(text);
        PerkMilestoneConfigs    = PerkMilestoneParser.ParsePerkMilestones(text);
        CompanionMiniMilestones = PerkMilestoneParser.ParseMiniMilestones(instance.Get("companion_mini_milestones"));
        HeroMiniMilestones      = PerkMilestoneParser.ParseMiniMilestones(instance.Get("hero_mini_milestones"));
        Tiers             = TierParser.ParseTiers(instance.Get("tiers"));
        Ranks             = TierParser.ParseRanks(instance.Get("ranks"));
        Gears             = GearParser.ParseGears(instance.Get("gears"));
        TutorialGoals     = PlayerGoalParser.ParsePlayerGoals(instance.Get("tutorial_goals"), tutorial: true);
        PlayerGoals       = PlayerGoalParser.ParsePlayerGoals(instance.Get("player_goals"), tutorial: false);
        PlayerGoalRewards = PlayerGoalParser.ParseRewards(instance.Get("goal_rewards"));
        GearSets          = GearParser.ParseGearSets(instance.Get("gear_set"));
        KeyChest          = ChestParser.ParseChests(instance.Get("chests"), ChestEnum.KeyChest);
        BronzeChest       = ChestParser.ParseChests(instance.Get("chests"), ChestEnum.BronzeChest);
        SilverChest       = ChestParser.ParseChests(instance.Get("chests"), ChestEnum.SilverChest);
        GoldChest         = ChestParser.ParseChests(instance.Get("chests"), ChestEnum.GoldChest);
        Crafting          = CraftingParser.ParseCrafting(instance.Get("crafting"));
        CraftingMaterial  = CraftingMaterialParser.ParseCraftingMaterial(instance.Get("crafting_materials"));
        IAPs                 = IAPParser.ParseIAPs(instance.Get("iaps"));
        BundleTiers          = BundleTierParser.ParseBundleTiers(instance.Get("bundle_tiers"));
        AdFrequencies        = AdFrequencyParser.ParseAdFrequencies(instance.Get("Ads/frequencies"));
        Drills               = DrillParser.ParseDrills(instance.Get("drills"));
        Gifts                = GiftParser.ParseGiftRewards(instance.Get("gifts"));
        GpuPerf              = GpuPerfParser.ParseGpuPerf(instance.Get("gpuperf"));
        XPromo               = XPromoParser.ParseXpromo(instance.Get("xpromo"));
        Gamblings            = GamblingParser.ParseGamblings(instance.Get("gambling"));
        Tournaments          = TournamentParser.ParseTournaments(instance.Get("tournaments"));
        TournamentTiers      = TournamentParser.ParseTournamentTiers(instance.Get("tournamentTiers"));
        AdMobZoneData        = NetworkConfigParser.ParseAdMobZoneData();
        UnityZoneData        = NetworkConfigParser.ParseUnityZoneData();
        FacebookFloors       = NetworkConfigParser.ParseFacebookFloors();
        AdColonyFloors       = NetworkConfigParser.ParseAdColonyFloors();
        AdMobZoneMappings    = NetworkConfigParser.ParseAdMobZoneMappings();
        FacebookZoneMappings = NetworkConfigParser.ParseFacebookZoneMappings();
        UnityZoneMappings    = NetworkConfigParser.ParseUnityZoneMappings();
    }
示例#26
0
 // inherit javadocs
 public virtual System.String[] GetStrings(IndexReader reader, System.String field, IState state)
 {
     return(_stringCache.Get(reader, new Entry(field, (Parser)null), state));
 }
示例#27
0
        public bool Parse(Socket socket, out RouteMatch?match, out RouteHandler route)
        {
            positionInTmp = 0;
            Pipeline      = false;
            var methodEnd = ReadUntil(socket, Space, 0);

            if (methodEnd == -1)
            {
                match = null;
                route = null;
                if (!socket.Connected)
                {
                    offsetInOutput = 0;
                    return(false);
                }
                else if (positionInTmp == 0)
                {
                    if (offsetInOutput != 0)
                    {
                        socket.Send(OutputTemp, offsetInOutput, SocketFlags.None);
                        offsetInOutput = 0;
                        socket.Close();
                        return(false);
                    }
                    else
                    {
                        return(ReturnError(socket, 408));
                    }
                }
                else
                {
                    return(ReturnError(socket, 505));
                }
            }
            HttpMethod = ReadMethod(methodEnd, InputTemp);
            var rowEnd = ReadUntil(socket, LF, methodEnd + 1);

            if (rowEnd == -1 || rowEnd < 12)
            {
                match = null;
                route = null;
                return(ReturnError(socket, 505));
            }
            RequestHeadersLength  = 0;
            ResponseHeadersLength = 0;
            HttpProtocolVersion   = ReadProtocol(rowEnd - 2);
            if (HttpProtocolVersion == null)
            {
                match = null;
                route = null;
                ReturnError(socket, 505, "Only HTTP/1.1 and HTTP/1.0 supported (partially)", false);
                return(false);
            }
            match = ReadUrl(rowEnd, out route);
            if (route == null)
            {
                var unknownRoute = "Unknown route " + RawUrl + " on method " + HttpMethod;
                ReturnError(socket, 404, unknownRoute, false);
                return(false);
            }
            ResponseStatus           = HttpStatusCode.OK;
            ResponseLength           = null;
            ResponseContentType      = null;
            TemplateMatch            = null;
            ResponseIsJson           = false;
            ContentTypeResponseIndex = -1;
            do
            {
                var start = rowEnd + 1;
                rowEnd = ReadUntil(socket, CR, start);
                if (rowEnd == start)
                {
                    break;
                }
                else if (rowEnd == -1)
                {
                    return(ReturnError(socket, 414));
                }
                else
                {
                    int i = start;
                    for (; i < rowEnd; i++)
                    {
                        if (InputTemp[i] == ':')
                        {
                            break;
                        }
                    }
                    if (i == rowEnd)
                    {
                        return(ReturnError(socket, 414));
                    }
                    var nameBuf = TmpCharBuf;
                    for (int x = start; x < i; x++)
                    {
                        nameBuf[x - start] = Lower[InputTemp[x]];
                    }
                    var name = KeyCache.Get(nameBuf, i - start);
                    if (InputTemp[i + 1] == 32)
                    {
                        i++;
                    }
                    for (int x = i + 1; x < rowEnd; x++)
                    {
                        nameBuf[x - i - 1] = (char)InputTemp[x];
                    }
                    var value = ValueCache.Get(nameBuf, rowEnd - i - 1);
                    if (RequestHeadersLength == RequestHeaders.Length)
                    {
                        var newHeaders = new HeaderPair[RequestHeaders.Length * 2];
                        Array.Copy(RequestHeaders, newHeaders, RequestHeaders.Length);
                        RequestHeaders = newHeaders;
                    }
                    RequestHeaders[RequestHeadersLength++] = new HeaderPair(name, value);
                }
                rowEnd++;
            } while (positionInTmp <= InputTemp.Length);
            rowEnd += 2;
            if (HttpMethod == "POST" || HttpMethod == "PUT")
            {
                int len = 0;
                var ct  = GetRequestHeader("content-length");
                if (ct != null)
                {
                    if (!int.TryParse(ct, out len))
                    {
                        return(ReturnError(socket, 411));
                    }
                    if (len > Limit)
                    {
                        return(ReturnError(socket, 413));
                    }
                }
                else
                {
                    return(ReturnError(socket, 411));
                }
                InputStream.Reset();
                var size = totalBytes - rowEnd;
                InputStream.Write(InputTemp, rowEnd, size);
                len -= size;
                var oldTimeout = socket.ReceiveTimeout;
                socket.ReceiveTimeout = 10000;
                while (len > 0)
                {
                    size = socket.Receive(InputTemp, Math.Min(len, InputTemp.Length), SocketFlags.None);
                    if (size < 1)
                    {
                        return(ReturnError(socket, 408));
                    }
                    InputStream.Write(InputTemp, 0, size);
                    len -= size;
                }
                socket.ReceiveTimeout = oldTimeout;
                InputStream.Position  = 0;
                rowEnd     = totalBytes;
                totalBytes = 0;
            }
            else
            {
                Pipeline = rowEnd < totalBytes;
                if (Pipeline)
                {
                    Buffer.BlockCopy(InputTemp, rowEnd, InputTemp, 0, totalBytes - rowEnd);
                    totalBytes -= rowEnd;
                }
                else
                {
                    totalBytes = 0;
                }
            }
            return(true);
        }
示例#28
0
        public BindingEntry(int errorCode, Match match, StringCache stringCache)
        {
            this.stringCache = stringCache;
            this.ErrorCode   = errorCode;
            this.Count       = 1;

            if (Constants.IsXamlDesigner)
            {
                this.Description        = nameof(this.Description);
                this.SourceProperty     = nameof(this.SourceProperty);
                this.SourcePropertyType = nameof(this.SourcePropertyType);
                this.SourcePropertyName = nameof(this.SourcePropertyName);
                this.BindingPath        = nameof(this.BindingPath);
                this.DataItemType       = nameof(this.DataItemType);
                this.DataItemName       = nameof(this.DataItemName);
                this.TargetElementType  = nameof(this.TargetElementType);
                this.TargetElementName  = nameof(this.TargetElementName);
                this.TargetProperty     = nameof(this.TargetProperty);
                this.TargetPropertyType = nameof(this.TargetPropertyType);
            }
            else
            {
                this.Description        = stringCache.Get(match.Value);
                this.SourceProperty     = stringCache.Get(match.Groups[nameof(this.SourceProperty)].Value);
                this.SourcePropertyType = stringCache.Get(match.Groups[nameof(this.SourcePropertyType)].Value);
                this.SourcePropertyName = stringCache.Get(match.Groups[nameof(this.SourcePropertyName)].Value);
                this.BindingPath        = stringCache.Get(match.Groups[nameof(this.BindingPath)].Value);
                this.DataItemType       = stringCache.Get(match.Groups[nameof(this.DataItemType)].Value);
                this.DataItemName       = stringCache.Get(match.Groups[nameof(this.DataItemName)].Value);
                this.TargetElementType  = stringCache.Get(match.Groups[nameof(this.TargetElementType)].Value);
                this.TargetElementName  = stringCache.Get(match.Groups[nameof(this.TargetElementName)].Value);
                this.TargetProperty     = stringCache.Get(match.Groups[nameof(this.TargetProperty)].Value);
                this.TargetPropertyType = stringCache.Get(match.Groups[nameof(this.TargetPropertyType)].Value);
            }
        }