public static void fGetTagDataAPI(ParamHttp _oData) { // Debug.fTrace("sInfo" + _oData.sInfo); string _sLimit = ""; if (_oData.oHeader != null) //C# http method { _sLimit = _oData.oHeader["X-RateLimit-Remaining"]; } else { _sLimit = fBetween(_oData.sInfo, "X-RateLimit-Remaining:", "\n"); } if (_sLimit != "") { int _nLimit = -1; int.TryParse(_sLimit, out _nLimit); if (_nLimit == 0) { Debug.fTrace("No API access remain, try alt method... for " + _oData.sURL); if (_oData.sCustom != "") { Debug.fTrace("Try the alternative method with recommend ver :" + _oData.sAltURL + "?after=" + _oData.sCustom); _oData.nCustom = 1; //Try the alternative method with recommend ver Http.fGetHttp(_oData.sAltURL + "?after=" + _oData.sCustom, _oData); } else { Debug.fTrace("Try the alternative method & Just get last version: " + _oData.sAltURL); _oData.nCustom = 4; //Try the alternative method & Just get last version Http.fGetHttp(_oData.sAltURL, _oData); } return; } } /* * if(_oData.bFail) { * Debug.fTrace("Fail: " + _oData.sFailMsg + " " + _oData.sURL ); * if(_oData.oHeader != null) { * int _nLimit = -1; * int.TryParse( _oData.oHeader["X-RateLimit-Remaining"], out _nLimit); * if(_nLimit == 0) { * Debug.fTrace("No API access remain, try alt method..." ); * } * } * if(_oData.sCustom != "") { * _oData.nCustom = 1; //Try the alternative method with recommend ver * Http.fGetHttp( _oData.sAltURL + "?after=" + _oData.sCustom, _oData); * }else { * _oData.nCustom = 4; //Try the alternative method & Just get last version * Http.fGetHttp( _oData.sAltURL, _oData); * } * * return; * }*/ Tags _aTags = (Tags)_oData.oContainer; Tags _aNewTags; // Debug.fTrace("fGetTagData " + _oData.sResult); //_aNewTags = fExtractTags_API(_oData.sResult) ; _aNewTags = fExtractTags_API(fBetween(_oData.sResult, "[", "]", 0, true, true)); if (_aNewTags != null) { _aTags.AddRange(_aNewTags); } else { Debug.fTrace("No new TAG "); } //Console.WriteLine("assssssssssss"); // Debug.fTrace("--Count: " + _aNewTags.Count.ToString()); // Debug.fTrace("--last: " + _aNewTags[_aNewTags.Count-1].name); // string _sNext = oPa oHeader string _sAllLink = ""; if (_oData.oHeader != null) //C# http method { _sAllLink = _oData.oHeader["Link"]; } else { _sAllLink = fBetween(_oData.sInfo, "Link:", "\n"); } // string _sModified = _oData.oHeader["Last-Modified"]; // int _nRemain = _oData.oHeader["X-RateLimit-Limit"]; string _sNextLink = ""; if (!FileUtils.IsEmpty(_sAllLink)) { string[] _aLink = _sAllLink.Split(','); foreach (string _sLink in _aLink) { //Debug.fTrace("Link: " + _sLink); string[] _aLinkData = _sLink.Split(';'); if (_aLinkData[1].Trim() == "rel=\"next\"") { _sNextLink = fBetween(_aLinkData[0], "<", ">"); if (_sNextLink == "") //If fail { _sNextLink = _aLinkData[0].Trim(); } } } } if (_sNextLink != "") { Http.fGetHttp(_sNextLink, _oData); } else { _oData.dCustom(_oData); //Finish(); } /* * //?after=v4.4.3 * if(_aNewTags.Count == 10) { ///Have more -> get other * string _sNewURL = _oData.sAltURL + "?after=" + _aNewTags[_aNewTags.Count-1].name; * Debug.fTrace("_sNewURL" + _sNewURL); * JSON.fGetHttp( _sNewURL, _oData); * }else { * _oData.dCustom(_oData); //Finish(); * }*/ ///_oData.dCustom(_oData); //Finish(); }
public static void fGetTagDataALT(ParamHttp _oData) { Tags _aTags = (Tags)_oData.oContainer; Tags _aNewTags; _aNewTags = fExtractTags_STD(_oData.sResult); switch (_oData.nCustom) { case 1: { //1 = Ver after recommended version -> then get recommended string _sPreviousLink = fBetween(_oData.sResult, "\"pagination\"><a href=\"", "\""); _oData.nCustom = 2; _aTags.AddRange(_aNewTags); //Debug.fTrace("!_sPreviousLink!! " + _sPreviousLink); Http.fGetHttp(_sPreviousLink, _oData); } break; case 2: { //2 = Ver with recommended version -> then get most recent _oData.nCustom = 3; //_aTags.InsertRange(0,_aNewTags); string _sFistTag = _aTags[0].name; int i = 0; foreach (Tag _oTag in _aNewTags) { if (_oTag.name != _sFistTag) { _aTags.Insert(i, _oTag); i++; } else { break; } } //Debug.fTrace("---Test1: " + _oData.sAltURL ); //Debug.fTrace("---Test2: " + _oData.sURL ); if (_oData.sURL != _oData.sAltURL) { Http.fGetHttp(_oData.sAltURL, _oData); //Get most recent ver } else { //Already got, stop here _oData.dCustom(_oData); //Finish(); } } break; case 3: { //3 = Get most recent date add but don't double it //_aTags.Insert(); string _sFistTag = _aTags[0].name; int i = 0; foreach (Tag _oTag in _aNewTags) { if (_oTag.name != _sFistTag) { _aTags.Insert(i, _oTag); i++; } else { break; } } _oData.dCustom(_oData); //Finish(); } break; default: _aTags.AddRange(_aNewTags); _oData.dCustom(_oData); //Finish(); break; } }