Not logged in - Login
View History

Library: .Net

We have made a library for .Net to help you start using A Trigger in a minute. This .Net library is made to avoid possible errors in your application. Even if ATrigger.com API server become unavailable, your application will work without any problem. On the other hand, all requests are Async by default and no slowness will happen.


Prerequisites

  1. First you need to follow Quick Start Guide.
  2. You have this personal details from your Account Setup page:
    1. API Key
    2. API Secret
  3. .Net 2.0+


Step 1: Initialize

Use NuGet to install the library. From the Visual Studio Tools menu, select Library Package Manager and then click Package Manager Console. Run:

Install-Package ATrigger

Add dependency on first line of the code:

using ATriggerLib;

You only need to initialize once at the start of your program. You can then keep using the ATrigger singleton anywhere in your code.

ATrigger.Initialize("YOUR_APIKey", "YOUR_APISecret");
//Debug-friendly: ATrigger.Initialize("YOUR_APIKey", "YOUR_APISecret", false, true);

In development you might want to use development settings above to start debugging.


Step 2: Start Using, Functions

Create

//Tags: Tags are required to identify tasks. 
//read more at: http://atrigger.com/docs/wiki/9/rest-api-v10-parameter-tag_
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("type", "test");
            
//Create
ATrigger.Client.doCreate(TimeQuantity.Day(), "1", "http://www.example.com/myTask?something", tags);


  1. Required _timeQuantity: Minute, Hour, Day, Month, Year - more info
  2. Required _timeValue: According to the chosen timeQuantity, set the amount of time. "_timeValue + _timeQuantity" will become timeSlice. In the above example: 1day
  3. Required url: The target url that A Trigger will call it at defined TimeSlice. The library will automatically encode this url. Don't use Server.URLEncode()
  4. Required tags: You need tag your tasks for future identification and to control them using API in the future. read more at tags_* parameters.
  5. [Optional] retries: How many times should try if your server failed(or it was down)? default value: 3
  6. [Optional] count: How many cycles should be repeated? read more at count parameter.
  7. [Optional] first: When should be the first call? You are not required to set time value by default. read more at first parameter.
  8. [Optional] postData: The dictionary object for the content you want to HTTP POST to your URL when your task has been triggered.


More advanced example: This code will call your task URL at 1/1/2015. No repeats, no cycles. It will retries 5 times if your server be down.

//Tags:
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("type", "test");

//postData:
Dictionary<string, string> postData = new Dictionary<string, string>();
postData.Add("key1", "value1");
postData.Add("key2", "value2");

//Set the first date - more: http://atrigger.com/docs/wiki/10/rest-api-v10-parameter-first
DateTime firstDate = DateTime.SpecifyKind(new DateTime(2015,1,1), DateTimeKind.Utc);

ATrigger.Client.doCreate(TimeQuantity.Minute(), "0", "http://www.example.com/task?etc", tags, Convert.ToString(firstDate), 1, 5, postData);


Delete

//Tags:
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("type", "test");
            
//Delete
ATrigger.Client.doDelete(tags);

Attention: This line will remove the task you've created in the last function(That is tagged "type=test").


  1. Required tags: All tasks with this tags will be removed. read more at tags_* parameters.


Pause

//Tags:
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("type", "test");
            
//Pause
ATrigger.Client.doPause(tags);


  1. Required tags: All tasks with this tags will be paused. read more at tags_* parameters.


Resume

//Tags:
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("type", "test");
            
//Resume
ATrigger.Client.doResume(tags);


  1. Required tags: All tasks with this tags will be resumed. read more at tags_* parameters.


Verify Request

All previous functions was for controlling tasks. but verifyRequest will be used to verify URL calls when you want to make sure the request is made from ATrigger servers, using the request IP and verifyRequest function:

if (!ATrigger.Client.verifyRequest(Request.UserHostAddress))
{
     //Invalid request: 
     //The request is not called from ATrigger servers.
}
else
{
     //Valid request:
     //Do the task here
}

//If you are using Google Pagespeed, you can access the visitor IP
//using this parameter: Request.ServerVariables("HTTP_X_FORWARDED_FOR");
//Thanks to Nicholas Psarras for sharing the experience.


  1. Required ip: The request IP that you want to validate if it is an IP of ATrigger.


More

How Pause and Resume works?