public string Invoke(string methodName, IDictionary<string, string> parameters, bool skipAuthorization = false)
{
if (!skipAuthorization && !IsAuthorized)
{
throw new AccessTokenInvalidException($@"Метод '{methodName}' нельзя вызывать без авторизации");
}
var url = "";
var answer = "";
// Защита от превышения количества запросов в секунду
if (RequestsPerSecond > 0 && LastInvokeTime.HasValue)
{
if (_expireTimer == null)
{
SetTimer(0);
}
lock (_expireTimer)
{
var span = LastInvokeTimeSpan?.TotalMilliseconds;
if (span < _minInterval)
{
var timeout = (int) _minInterval - (int) span;
#if UWP
Task.Delay(timeout).Wait();
#else
Thread.Sleep(timeout);
#endif
}
url = GetApiUrl(methodName, parameters, skipAuthorization);
LastInvokeTime = DateTimeOffset.Now;
answer = Browser.GetJson(url.Replace("\'", "%27"));
}
} else if (skipAuthorization)
{
url = GetApiUrl(methodName, parameters, skipAuthorization: true);
LastInvokeTime = DateTimeOffset.Now;
answer = Browser.GetJson(url.Replace("\'", "%27"));
}
#if DEBUG && !UNIT_TEST
#if UWP
Debug.WriteLine(Utilities.PreetyPrintApiUrl(url));
Debug.WriteLine(Utilities.PreetyPrintJson(answer));
#else
Trace.WriteLine(Utilities.PreetyPrintApiUrl(url));
Trace.WriteLine(Utilities.PreetyPrintJson(answer));
#endif
#endif
VkErrors.IfErrorThrowException(answer);
return answer;
}