Newtonsoft.Json.JsonTextReader.ReadAsInt32 C# (CSharp) Method

ReadAsInt32() public method

Reads the next JSON token from the stream as a Nullable{T} of Int32.
public ReadAsInt32 ( ) : int?
return int?
        public override int? ReadAsInt32()
        {
            return (int?)ReadNumberValue(ReadType.ReadAsInt32);
        }

Usage Example

Exemplo n.º 1
0
        protected override async Task ProcessRequestCoreAsync(HttpContext ctx, string viewer, string world, long startTime)
        {
            var req = ctx.Request;
            var resp = ctx.Response;

            if(!req.IsAuthenticated) {
                resp.StatusCode = 403;
                return;
            }
            
            var currentTs = Utils.UnixTimestamp.CurrentMillisecondTimestamp;
            var start2Ts = start2Timestamp;
            if((currentTs - startTime < Start2ValidityPeriod) && (currentTs - start2Ts > Start2ValidityPeriod)) {
                string referer = null;
                if(req.Headers["Referer"] != null) {
                    var hdrLine = req.Headers["Referer"];
                    var schema = hdrLine.IndexOf("//") + 2;
                    var kcsUrl = hdrLine.IndexOf("/kcs", schema);
                    if(kcsUrl > 0) {
                        referer = world + hdrLine.Substring(kcsUrl + 1);
                    }
                }

                var proxyResponse = await Utils.Forwarder.ForwardRequest(req, world + "kcsapi/api_start2", referer);
                if(proxyResponse != null) {
                    using(proxyResponse) {
                        if(proxyResponse.StatusCode == HttpStatusCode.OK) {
                            string newStart2;
                            using(StreamReader rdr = new StreamReader(proxyResponse.GetResponseStream())) {
                                newStart2 = (await rdr.ReadToEndAsync());
                            }
                            JsonReader json = new JsonTextReader(new StringReader(newStart2.Substring(7)));
                            while(json.Read()) {
                                if(json.TokenType == JsonToken.PropertyName && json.Value.ToString() == "api_result") {
                                    if(json.ReadAsInt32() == 1) {
                                        if(System.Threading.Interlocked.CompareExchange(ref start2Timestamp, currentTs, start2Ts) == start2Ts) {
                                            start2Content = newStart2;
                                            File.WriteAllText(ctx.Server.MapPath("~/App_Data/api_start2.json"), start2Content);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if(start2Content == null) {
                ctx.Response.StatusCode = 503;
                return;
            }

            ctx.Response.ContentType = "text/plain";
            ctx.Response.Write(start2Content);
            return;
        }
All Usage Examples Of Newtonsoft.Json.JsonTextReader::ReadAsInt32