Today I will elucidate about undertaking scheduler in c# and how to booked on particular time in window.Today i will make an errand scheduler utilizing c# reassure application to call or expend rest web programming interface with intermediary to get information from sharepoint .This illustration use to devour web programming interface to call sharepoint to download report on neighborhood application catalog.
How to make Task scheduler in c# application?
Step 1:- Create a reassure application in c#
Step 2:- You have to include Microsoft.SharePoint.Client library from chunk bundle in you application.
utilizing System;
utilizing System.IO;
utilizing System.Net;
utilizing System.Net.Http;
utilizing System.Net.Http.Headers;
utilizing System.Threading.Tasks;
utilizing System.Configuration;
utilizing System.Security;
utilizing Microsoft.SharePoint.Client;
namespace InsightTaskSchedular{
class Program {
static void Main()
{
attempt {
/to validate from sharepoint server.
string UserName = ConfigurationSettings.AppSettings["UserName"].ToString();
string Password = ConfigurationSettings.AppSettings["Password"].ToString();
string userName = UserName;
string secret key = Password;
string baseurl = "***********Sharepoint URL";
Uri = new Uri(baseurl);
var securePassword = new SecureString();
foreach (var c in secret key) { securePassword.AppendChar(c); }
var certifications = new SharePointOnlineCredentials(userName, securePassword);
/get authCookie from sharepoint utilizing username and secret word.
var authCookie = credentials.GetAuthenticationCookie(uri);
string fedAuthString = authCookie.TrimStart("SPOIDCRL=".ToCharArray());
in the case of (fedAuthString != invalid)
{
/call capacity to devour web programming interface utilizing fedAuthString as token for programming interface.
RunAsync(fedAuthString).Wait();
/Console.WriteLine(fedAuthString);
/Console.Read();
}
else {
Console.WriteLine("Invalid User!!");
}
}
get (TaskCanceledException ex)
{
Console.WriteLine(ex);
Console.Read();
}
}
static async Task RunAsync(string fedAuthString)
{
attempt {
utilizing (HttpClient _client = new HttpClient())
{
/By default httpclient timeout=100 second.
_client.Timeout = TimeSpan.FromHours(1);
string BaseApiUrl = ConfigurationSettings.AppSettings["BaseApiUrl"].ToString();
_client.BaseAddress = new Uri(BaseApiUrl);
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_client.DefaultRequestHeaders.Add("SPOIDCRL", fedAuthString);
HttpResponseMessage reaction = anticipate _client.GetAsync("/programming interface/Insight/DownloadDocument");
on the off chance that (response.IsSuccessStatusCode)
{
Console.WriteLine("Sucess!!");
}
}
}
get (TaskCanceledException ex)
{
Console.WriteLine(ex);
Console.Read();
}
}
}
}
Step 3:- Set intermediary and userName and watchword in app.config document.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy>
<proxy proxyaddress="proxy IP:port" usesystemdefault="true" bypassonlocal="true"/>
</defaultProxy>
</system.net>
<appSettings>
<add key="UserName" value="***********"/>
<add key="Password" value="************"/>
<add key="BaseApiUrl" value="***********:Port"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Step 3:- You can change this code concurring your requirment and run support application.
from that point check container envelope your application index to execute .exe on anyplace.
How to utilize errand scheduler in window working framework?
Step 1:- Open Task scheduler utilizing these means.
Open laud prompt=> sort "Taskschd.msc" from there on open window like this
Principle window
Step 2:- Create new errand in undertaking scheduler utilizing these progression given underneath.
Assignment Scheduler Library=>right click=>Create Task from that point open window like this and set errand Name and depiction and other design concurring your requirment .
General window
Step 3:- Now you will make trigger to plan your assignment agreeing your requirment like this.
trigger window
Step 4:- Now you will make activities for .exe. tap on Browse and set way of exe document .
e.g. ...\InsightTaskSchedular\bin\Debug\InsightTaskSchedular.exe
Activity window
Step 5:- Now you can set other setting agreeing your requirment and also other.
also, tap on "OK".Thereafter you can check your undertaking in errand board
Your errand will keep running at planned time precisely.
How to make Task scheduler in c# application?
Step 1:- Create a reassure application in c#
Step 2:- You have to include Microsoft.SharePoint.Client library from chunk bundle in you application.
utilizing System;
utilizing System.IO;
utilizing System.Net;
utilizing System.Net.Http;
utilizing System.Net.Http.Headers;
utilizing System.Threading.Tasks;
utilizing System.Configuration;
utilizing System.Security;
utilizing Microsoft.SharePoint.Client;
namespace InsightTaskSchedular{
class Program {
static void Main()
{
attempt {
/to validate from sharepoint server.
string UserName = ConfigurationSettings.AppSettings["UserName"].ToString();
string Password = ConfigurationSettings.AppSettings["Password"].ToString();
string userName = UserName;
string secret key = Password;
string baseurl = "***********Sharepoint URL";
Uri = new Uri(baseurl);
var securePassword = new SecureString();
foreach (var c in secret key) { securePassword.AppendChar(c); }
var certifications = new SharePointOnlineCredentials(userName, securePassword);
/get authCookie from sharepoint utilizing username and secret word.
var authCookie = credentials.GetAuthenticationCookie(uri);
string fedAuthString = authCookie.TrimStart("SPOIDCRL=".ToCharArray());
in the case of (fedAuthString != invalid)
{
/call capacity to devour web programming interface utilizing fedAuthString as token for programming interface.
RunAsync(fedAuthString).Wait();
/Console.WriteLine(fedAuthString);
/Console.Read();
}
else {
Console.WriteLine("Invalid User!!");
}
}
get (TaskCanceledException ex)
{
Console.WriteLine(ex);
Console.Read();
}
}
static async Task RunAsync(string fedAuthString)
{
attempt {
utilizing (HttpClient _client = new HttpClient())
{
/By default httpclient timeout=100 second.
_client.Timeout = TimeSpan.FromHours(1);
string BaseApiUrl = ConfigurationSettings.AppSettings["BaseApiUrl"].ToString();
_client.BaseAddress = new Uri(BaseApiUrl);
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_client.DefaultRequestHeaders.Add("SPOIDCRL", fedAuthString);
HttpResponseMessage reaction = anticipate _client.GetAsync("/programming interface/Insight/DownloadDocument");
on the off chance that (response.IsSuccessStatusCode)
{
Console.WriteLine("Sucess!!");
}
}
}
get (TaskCanceledException ex)
{
Console.WriteLine(ex);
Console.Read();
}
}
}
}
Step 3:- Set intermediary and userName and watchword in app.config document.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy>
<proxy proxyaddress="proxy IP:port" usesystemdefault="true" bypassonlocal="true"/>
</defaultProxy>
</system.net>
<appSettings>
<add key="UserName" value="***********"/>
<add key="Password" value="************"/>
<add key="BaseApiUrl" value="***********:Port"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Step 3:- You can change this code concurring your requirment and run support application.
from that point check container envelope your application index to execute .exe on anyplace.
How to utilize errand scheduler in window working framework?
Step 1:- Open Task scheduler utilizing these means.
Open laud prompt=> sort "Taskschd.msc" from there on open window like this
Principle window
Step 2:- Create new errand in undertaking scheduler utilizing these progression given underneath.
Assignment Scheduler Library=>right click=>Create Task from that point open window like this and set errand Name and depiction and other design concurring your requirment .
General window
Step 3:- Now you will make trigger to plan your assignment agreeing your requirment like this.
trigger window
Step 4:- Now you will make activities for .exe. tap on Browse and set way of exe document .
e.g. ...\InsightTaskSchedular\bin\Debug\InsightTaskSchedular.exe
Activity window
Step 5:- Now you can set other setting agreeing your requirment and also other.
also, tap on "OK".Thereafter you can check your undertaking in errand board
Your errand will keep running at planned time precisely.
Comments
Post a Comment