コード例 #1
0
        public static RaiserInfo GetValueFromJson(TextReader jsonStream, string language)
        {
            RaiserInfo result = null;

            using (Newtonsoft.Json.JsonTextReader jtr = new Newtonsoft.Json.JsonTextReader(jsonStream))
            {
                bool?  enable = true;
                int?   count = 0;
                string md5 = string.Empty, url = string.Empty, tmp;
                while (jtr.Read())
                {
                    if (jtr.TokenType == Newtonsoft.Json.JsonToken.PropertyName)
                    {
                        if (((string)jtr.Value).ToLower() == language.ToLower())
                        {
                            while (jtr.Read())
                            {
                                if (jtr.TokenType == Newtonsoft.Json.JsonToken.PropertyName)
                                {
                                    tmp = ((string)jtr.Value).ToLower();
                                    if (tmp == "enabled")
                                    {
                                        enable = jtr.ReadAsBoolean();
                                    }
                                    else if (tmp == "filecount")
                                    {
                                        count = jtr.ReadAsInt32();
                                    }
                                    else if (tmp == "patchmd5")
                                    {
                                        md5 = jtr.ReadAsString();
                                    }
                                    else if (tmp == "patchurl")
                                    {
                                        url = jtr.ReadAsString();
                                    }
                                    else
                                    {
                                        jtr.Skip();
                                    }
                                }
                            }
                        }
                        else
                        {
                            jtr.Skip();
                        }
                    }
                }
                if (enable.HasValue && !enable.Value)
                {
                    result = new RaiserInfo(false, count.HasValue ? count.Value : 0, md5, url);
                }
                else
                {
                    result = new RaiserInfo(true, count.HasValue ? count.Value : 0, md5, url);
                }
            }
            return(result);
        }