private async Task UpdateRequest()

in certified-connectors/SurveyMonkey/script.csx [129:183]


    private async Task<bool> UpdateRequest()
    {
        var uriBuilder = new UriBuilder(this.Context.Request.RequestUri);
        var query = HttpUtility.ParseQueryString(this.Context.Request.RequestUri.Query);
        string triggerState = query.Get("triggerstate");
        if (!string.IsNullOrEmpty(triggerState))
        {
            // initial trigger state to get existing items
            triggerState = DateTime.Parse(triggerState).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
        }

        if ("OnSurveyCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) ||
            "OnNewResponseAddedCollector".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) ||
            "OnNewResponseAddedSurvey".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) ||
            "OnSurveyCollectorCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
        {
            var segments = this.Context.Request.RequestUri.Segments.ToList();
            var removeTrigger = segments.Find(x => x.StartsWith("trigger"));
            uriBuilder.Path = uriBuilder.Path.Replace(removeTrigger, string.Empty);
            if (!string.IsNullOrEmpty(triggerState))
            {
                if ("OnSurveyCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) ||
                "OnNewResponseAddedCollector".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase) ||
                "OnNewResponseAddedSurvey".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
                {
                    query["start_modified_at"] = triggerState;
                }
                else if ("OnSurveyCollectorCreated".Equals(this.Context.OperationId, StringComparison.OrdinalIgnoreCase))
                {
                    query["start_date"] = triggerState;
                }
                else
                {
                    query["since"] = triggerState;
                }
            }
            else
            {
                return false;
            }
            query.Remove("triggerstate");
            query.Remove("triggerstate_exclude_ids");
        }
        else
        {
            var content = await this.Context.Request.Content.ReadAsStringAsync().ConfigureAwait(false);
            string body = SetBody(content);
            this.Context.Request.Content = new StringContent(body, Encoding.UTF8, "application/json");
        }
        query.Remove("surveyId");
        uriBuilder.Query = query.ToString();
        this.Context.Request.RequestUri = uriBuilder.Uri;

        return true;
    }