VkNet.VkApi.Invoke C# (CSharp) Method

Invoke() private method

private Invoke ( string methodName, string>.IDictionary parameters, bool skipAuthorization = false ) : string
methodName string
parameters string>.IDictionary
skipAuthorization bool
return string
        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;
        }

Usage Example

Beispiel #1
0
        public MusicLoader(string syncDir, string token, long userId)
        {
            DependencyUtility.BuildUp(this);

            syncDirectory = syncDir;
            this.userId = userId;

            api = new VkApi();
            api.Authorize(token, userId);
            api.Invoke("stats.trackVisitor", new Dictionary<string, string>(), true); // статистика посещаемости приложения

            remoteAudioSizeHelper = new RemoteAudioSizeHelper(Path.Combine(AppPaths.SettingsPath, "sizes.dat"));

            tracks = new ConcurrentSortedList<int, Track>();

            int key = 0;
            foreach (var track in TrackRepository.GetTracks())
                tracks.Add(key++, track);
        }
All Usage Examples Of VkNet.VkApi::Invoke