protected override void PerformAction(IList<string> ackIds, string subscriptionName)
 {
     AcknowledgeRequest requestBody = new AcknowledgeRequest() { AckIds = ackIds };
     try
     {
         ProjectsResource.SubscriptionsResource.AcknowledgeRequest request =
             Service.Projects.Subscriptions.Acknowledge(requestBody, subscriptionName);
         request.Execute();
     }
     catch (GoogleApiException ex) when (ex.HttpStatusCode == HttpStatusCode.NotFound)
     {
         WriteResourceMissingError(
             exceptionMessage: $"Subscription '{subscriptionName}' does not exist in project '{Project}'.",
             errorId: "SubscriptionNotFound",
             targetObject: subscriptionName);
         return;
     }
 }
        protected override void ProcessRecord()
        {
            Name = GetProjectPrefixForSubscription(Name, Project);
            PullRequest requestBody = new PullRequest();
            requestBody.ReturnImmediately = ReturnImmediately.IsPresent;
            requestBody.MaxMessages = MaxMessages.HasValue ? MaxMessages : DefaultMaxMessages;
            if (requestBody.MaxMessages <= 0)
            {
                throw new PSArgumentException("MaxMessages parameter should have a value greater than 0.");
            }

            // Send the pull request. Raise error if subscription is not found.
            ProjectsResource.SubscriptionsResource.PullRequest request = Service.Projects.Subscriptions.Pull(requestBody, Name);
            PullResponse response = null;
            try
            {
                response = request.Execute();
            }
            catch (GoogleApiException ex) when (ex.HttpStatusCode == HttpStatusCode.NotFound)
            {
                WriteResourceMissingError(
                    exceptionMessage: $"Subscription '{Name}' does not exist in project '{Project}'.",
                    errorId: "SubscriptionNotFound",
                    targetObject: Name);
                return;
            }

            IList<ReceivedMessage> receivedMessages = response?.ReceivedMessages;
            if (receivedMessages == null || receivedMessages.Count == 0)
            {
                return;
            }

            // Send acknowledgement for all the messages if -AutoAck is present.
            if (AutoAck.IsPresent)
            {
                AcknowledgeRequest ackRequestBody = new AcknowledgeRequest()
                {
                    AckIds = receivedMessages.Select(message => message.AckId).ToList()
                };
                ProjectsResource.SubscriptionsResource.AcknowledgeRequest ackRequest =
                    Service.Projects.Subscriptions.Acknowledge(ackRequestBody, Name);
                ackRequest.Execute();
            }

            foreach (ReceivedMessage receivedMessage in receivedMessages)
            {
                PubSubMessageWithAckIdAndSubscription messageWithAck = new PubSubMessageWithAckIdAndSubscription(receivedMessage, Name);
                // Convert the base 64 encoded message data.
                if (!string.IsNullOrWhiteSpace(messageWithAck.Data))
                {
                    byte[] base64Bytes = Convert.FromBase64String(messageWithAck.Data);
                    messageWithAck.Data = Encoding.UTF8.GetString(base64Bytes);
                }
                if (AutoAck.IsPresent)
                {
                    // Remove the AckId 
                    messageWithAck.AckId = null;
                }
                WriteObject(messageWithAck);
            }
        }