Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify comments #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions LogicAppTriggers/Controllers/PollTriggerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ namespace LogicAppTriggers.Controllers
public class PollTriggerController : ApiController
{
/// <summary>
/// Sample polling trigger that will fire whenever the last time it fired was more than 2 minutes ago.
/// Create a sample polling trigger that fires whenever the last time the trigger fired was more than 2 minutes ago.
/// </summary>
/// <param name="triggerState"></param>
/// <returns></returns>
public HttpResponseMessage Get(string triggerState = "")
{
//If there is no triggerState - meaning this is the first poll.
// If "triggerState" doesn't exist, then this iteration is the first poll.
if(String.IsNullOrEmpty(triggerState))
{
///
/// Generate the triggerState. This will be the identifier you will use to know which items you have triggered off of.
/// This is commonly a "timestamp", and you would check on each poll if there are any items available after the timestamp.
///
/// Generate the "triggerState" value, commonly a "timestamp",
/// to identify which items caused the trigger to fire.
/// On each poll, check for any new items became available after the timestamp.
triggerState = DateTime.UtcNow.ToString();
return GenerateAsyncResponse(HttpStatusCode.Accepted, triggerState, "15");
}
//If there is a triggerState - meaning we have polled before and returned a location header in the if branch above.
// If "triggerState" exists, then the trigger was fired before
// and returned a "location" header from the previous "if" branch.
else
{
//Do some work to check if a trigger is available
// Check whether "triggerState" exists.
if(DateTime.Parse(triggerState) < DateTime.UtcNow)
{
//If available, return a 200 - can update the triggerState as well.
//In this case I'm going to update the triggerState so that it will fire again in 2 minutes based on this fake logic.
// If "triggerState exists, return a "200 OK" status. You can also update "triggerState".
// This example updates "triggerState" so that the trigger fires again in 2 minutes based on this fake logic.
triggerState = DateTime.UtcNow.AddMinutes(2).ToString();
return GenerateAsyncResponse(HttpStatusCode.OK, triggerState, "15");
}
Expand All @@ -41,14 +41,13 @@ public HttpResponseMessage Get(string triggerState = "")
return GenerateAsyncResponse(HttpStatusCode.Accepted, triggerState, "15");
}
}

}

private HttpResponseMessage GenerateAsyncResponse(HttpStatusCode code, string triggerState, string retryAfter)
{
HttpResponseMessage responseMessage = Request.CreateResponse(code); //Return a 200 to tell it to fire.
responseMessage.Headers.Add("location", String.Format("{0}://{1}/api/polltrigger?triggerState={2}", Request.RequestUri.Scheme, Request.RequestUri.Host, HttpUtility.UrlEncode(triggerState))); //Where the engine will poll to check status
responseMessage.Headers.Add("retry-after", retryAfter); //How many seconds it should wait. If multiple files are available you can return a 0 here and the engine will immediately come back and grab other triggers.
HttpResponseMessage responseMessage = Request.CreateResponse(code); // Return a "200 OK" status to fire the trigger.
responseMessage.Headers.Add("location", String.Format("{0}://{1}/api/polltrigger?triggerState={2}", Request.RequestUri.Scheme, Request.RequestUri.Host, HttpUtility.UrlEncode(triggerState))); // The URL that the engine polls to check status
responseMessage.Headers.Add("retry-after", retryAfter); // The number of seconds the engine should wait before polling again. If multiple files are found, you can return "0" seconds so that the engine immediately returns for more items.
return responseMessage;
}
}
Expand Down
10 changes: 5 additions & 5 deletions LogicAppTriggers/Controllers/WebhookTriggerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ namespace LogicAppTriggers.Controllers
public class WebhookTriggerController : ApiController
{
public static List<string> subscriptions = new List<string>();

/// <summary>
/// Recieve a subscription to a webhook.
/// Receive subscription to webhook.
/// </summary>
/// <param name="callbackUrl">URL to get from Logic Apps - @listCallbackUrl()</param>
/// <param name="callbackUrl">The callback URL to get from the Logic Apps engine - @listCallbackUrl()</param>
/// <returns></returns>
[HttpPost, Route("api/webhooktrigger/subscribe")]
public HttpResponseMessage Subscribe([FromBody] string callbackUrl)
Expand All @@ -25,9 +26,8 @@ public HttpResponseMessage Subscribe([FromBody] string callbackUrl)
return Request.CreateResponse();
}


/// <summary>
/// Fire all triggers - do a GET to this API to fire all triggers subscribed
/// Fire all triggers. To fire all subscribed triggers, perform a GET to this API.
/// </summary>
/// <returns></returns>
[HttpGet, Route("api/webhooktrigger/trigger")]
Expand All @@ -41,7 +41,7 @@ public async Task<HttpResponseMessage> Get()
return Request.CreateResponse(HttpStatusCode.Accepted, String.Format("There are {0} subscriptions fired", subscriptions.Count));
}
/// <summary>
/// Unsubscribe
/// Unsubscribe from webhook.
/// </summary>
/// <param name="callbackUrl"></param>
/// <returns></returns>
Expand Down