Exemple #1
0
        public static void SendIndexingRequest(List <string> linksToIndex, string action)
        {
            try
            {
                var indexRequest          = new BatchRequest(_googleIndexingApiClientService);
                var notificationResponses = new List <PublishUrlNotificationResponse>();
                foreach (var url in linksToIndex)
                {
                    var urlNotification = new UrlNotification {
                        Url = url, Type = action
                    };
                    indexRequest.Queue <PublishUrlNotificationResponse>(
                        new UrlNotificationsResource.PublishRequest(_googleIndexingApiClientService, urlNotification), (response, error, i, message) =>
                    {
                        notificationResponses.Add(response);
                    });
                }

                indexRequest.ExecuteAsync().ConfigureAwait(false);
                Log.Info($"{action} request to Google Indexing API for '{string.Join(",", linksToIndex)}' succeeded", linksToIndex);
            }
            catch (Exception ex)
            {
                Log.Error($"{action} request to Google Indexing API for '{string.Join(",", linksToIndex)}' failed: {ex.Message}", ex, linksToIndex);
            }
        }
Exemple #2
0
        public static void SendIndexingRequest(string linkToIndex, string action)
        {
            try
            {
                var publishRequestBody = new UrlNotification {
                    Url = linkToIndex, Type = action
                };
                var publishIndexRequest = new UrlNotificationsResource.PublishRequest(_googleIndexingApiClientService, publishRequestBody);

                publishIndexRequest.ExecuteAsync().ConfigureAwait(false);
                Log.Info($"{action} request to Google Indexing API for '{linkToIndex}' succeeded", linkToIndex);
            }
            catch (Exception ex)
            {
                Log.Error($"{action} request to Google Indexing API for '{linkToIndex}' failed: {ex.Message}", ex, linkToIndex);
            }
        }