public string SetTriggerState()

in certified-connectors/SurveyMonkey/script.csx [100:127]


    public string SetTriggerState(JArray newItems, string triggerState, string date)
    {
        DateTime newTriggerState = DateTime.MinValue;
        string excludeIds = string.Empty;
        var listOfOperations = new List<string>() { "OnNewResponseAddedCollector", "OnNewResponseAddedSurvey" };

        if (listOfOperations.Contains(this.Context.OperationId, StringComparer.OrdinalIgnoreCase) && newItems != null)
        {
            if (newItems.Count > 0)
            {
                newTriggerState = newItems.Max(x => DateTime.Parse(x["date_modified"].ToString()));
                newTriggerState = newTriggerState.AddSeconds(1);
                /* now get the ids of any responses with modified date in the same minute as the next trigger date so we can exclude them from the next run */
                excludeIds = string.Join(",", newItems.Where(x => DateTime.Parse(x["date_modified"].ToString()).ToString("yyyy-MM-ddTHH:mmZ") == newTriggerState.ToString("yyyy-MM-ddTHH:mmZ")).Select(y => y["id"].ToString()));
            }
        }

        if ((newItems == null || newItems.Count == 0) && !String.IsNullOrEmpty(triggerState) && newTriggerState == DateTime.MinValue)
        {
            newTriggerState = DateTime.Parse(triggerState);
        }
        else if (newTriggerState == DateTime.MinValue)
        {
            newTriggerState = DateTime.Parse(date);
        }

        return newTriggerState.ToString("yyyy-MM-ddTHH:mm:ss.fffZ") + "|" + excludeIds;
    }