Renamed existing methods to *Asynch and added synchronous methods.
This commit is contained in:
Родитель
dc03179b3a
Коммит
79ad69be7b
|
@ -41,7 +41,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="JobType.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ScheduledTask.cs" />
|
||||
<Compile Include="TaskModel.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Aditi.Scheduler.Models
|
||||
{
|
||||
public class ScheduledTask
|
||||
public class TaskModel
|
||||
{
|
||||
public ScheduledTask()
|
||||
public TaskModel()
|
||||
{
|
||||
Enabled = true;
|
||||
TimeZoneId = TimeZoneInfo.Utc.Id;
|
||||
|
@ -15,7 +15,7 @@ namespace Aditi.Scheduler.Models
|
|||
public JobType JobType { get; set; }
|
||||
public DateTime? Start { get; set; }
|
||||
public DateTime? End { get; set; }
|
||||
public int RepeatEveryMins { get; set; }
|
||||
public int? RepeatEveryMins { get; set; }
|
||||
public string CronExpression { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public string TimeZoneId { get; set; }
|
|
@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{07522B
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aditi.Scheduler.Models", "Aditi.Scheduler.Models\Aditi.Scheduler.Models.csproj", "{21444757-3D70-45FC-A948-279AD079E470}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tester_Synch", "Tester_Synch\Tester_Synch.csproj", "{CE3B1238-6080-49CF-8D7C-C2B650A92F0E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -26,6 +28,10 @@ Global
|
|||
{21444757-3D70-45FC-A948-279AD079E470}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{21444757-3D70-45FC-A948-279AD079E470}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{21444757-3D70-45FC-A948-279AD079E470}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CE3B1238-6080-49CF-8D7C-C2B650A92F0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CE3B1238-6080-49CF-8D7C-C2B650A92F0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CE3B1238-6080-49CF-8D7C-C2B650A92F0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CE3B1238-6080-49CF-8D7C-C2B650A92F0E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aditi.Scheduler.Models;
|
||||
using Aditi.SignatureAuth;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Aditi.Scheduler
|
||||
{
|
||||
|
@ -22,14 +29,34 @@ namespace Aditi.Scheduler
|
|||
this._secretKey = secretKey;
|
||||
}
|
||||
|
||||
public ScheduledTasks( string tenantId, string secretKey)
|
||||
public ScheduledTasks(string tenantId, string secretKey)
|
||||
{
|
||||
this._uri = new Uri("http://scheduler.aditicloud.com/api/task/");
|
||||
this._tenantId = tenantId;
|
||||
this._secretKey = secretKey;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ScheduledTask>> GetTasks()
|
||||
public IEnumerable<TaskModel> GetTasks()
|
||||
{
|
||||
var request = (HttpWebRequest)WebRequest.Create(_uri);
|
||||
|
||||
request.Method = "GET";
|
||||
request.ContentType = "application/json";
|
||||
request.Headers.Add("Authorization",
|
||||
new Signature(this._tenantId, this._secretKey).ToString());
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
string jsonResponse;
|
||||
using (var sr = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
jsonResponse = sr.ReadToEnd();
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<List<TaskModel>>(jsonResponse);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TaskModel>> GetTasksAsync()
|
||||
{
|
||||
var client = new HttpClient();
|
||||
|
||||
|
@ -41,10 +68,30 @@ namespace Aditi.Scheduler
|
|||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
return await response.Content.ReadAsAsync<IEnumerable<ScheduledTask>>();
|
||||
return await response.Content.ReadAsAsync<IEnumerable<TaskModel>>();
|
||||
}
|
||||
|
||||
public async Task<ScheduledTask> GetTask(Guid taskId)
|
||||
public TaskModel GetTask(Guid taskId)
|
||||
{
|
||||
var request = (HttpWebRequest)WebRequest.Create(_uri + taskId.ToString());
|
||||
|
||||
request.Method = "GET";
|
||||
request.ContentType = "application/json";
|
||||
request.Headers.Add("Authorization",
|
||||
new Signature(this._tenantId, this._secretKey).ToString());
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
string jsonResponse;
|
||||
using (var sr = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
jsonResponse = sr.ReadToEnd();
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<TaskModel>(jsonResponse);
|
||||
}
|
||||
|
||||
public async Task<TaskModel> GetTaskAsync(Guid taskId)
|
||||
{
|
||||
var client = new HttpClient();
|
||||
|
||||
|
@ -56,10 +103,39 @@ namespace Aditi.Scheduler
|
|||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
return await response.Content.ReadAsAsync<ScheduledTask>();
|
||||
return await response.Content.ReadAsAsync<TaskModel>();
|
||||
}
|
||||
|
||||
public async Task<ScheduledTask> CreateTask(ScheduledTask task)
|
||||
public TaskModel CreateTask(TaskModel task)
|
||||
{
|
||||
var request = (HttpWebRequest)WebRequest.Create(_uri);
|
||||
request.Method = "POST";
|
||||
|
||||
request.ContentType = "application/json";
|
||||
request.Headers.Add("Authorization",
|
||||
new Signature(this._tenantId, this._secretKey).ToString());
|
||||
|
||||
string json = JsonConvert.SerializeObject(task);
|
||||
|
||||
string jsonResponse;
|
||||
|
||||
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
|
||||
{
|
||||
streamWriter.Write(json);
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
using (var streamReader = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
jsonResponse = streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<TaskModel>(jsonResponse);
|
||||
}
|
||||
|
||||
public async Task<TaskModel> CreateTaskAsync(TaskModel task)
|
||||
{
|
||||
var client = new HttpClient();
|
||||
|
||||
|
@ -71,13 +147,42 @@ namespace Aditi.Scheduler
|
|||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
var jsonFormatter = new JsonMediaTypeFormatter();
|
||||
var content = new ObjectContent<ScheduledTask>(task, jsonFormatter);
|
||||
var content = new ObjectContent<TaskModel>(task, jsonFormatter);
|
||||
var response = client.PostAsync(_uri, content).Result;
|
||||
|
||||
return await response.Content.ReadAsAsync<ScheduledTask>();
|
||||
return await response.Content.ReadAsAsync<TaskModel>();
|
||||
}
|
||||
|
||||
public async Task<ScheduledTask> UpdateTask(ScheduledTask updated)
|
||||
public TaskModel UpdateTask(TaskModel task)
|
||||
{
|
||||
var request = (HttpWebRequest)WebRequest.Create(_uri.ToString() + task.Id.ToString());
|
||||
request.Method = "PUT";
|
||||
|
||||
request.ContentType = "application/json";
|
||||
request.Headers.Add("Authorization",
|
||||
new Signature(this._tenantId, this._secretKey).ToString());
|
||||
|
||||
string json = JsonConvert.SerializeObject(task);
|
||||
|
||||
string jsonResponse;
|
||||
|
||||
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
|
||||
{
|
||||
streamWriter.Write(json);
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
using (var streamReader = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
jsonResponse = streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
return JsonConvert.DeserializeObject<TaskModel>(jsonResponse);
|
||||
}
|
||||
|
||||
public async Task<TaskModel> UpdateTaskAsync(TaskModel task)
|
||||
{
|
||||
var client = new HttpClient();
|
||||
|
||||
|
@ -89,13 +194,32 @@ namespace Aditi.Scheduler
|
|||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
var jsonFormatter = new JsonMediaTypeFormatter();
|
||||
var content = new ObjectContent<ScheduledTask>(updated, jsonFormatter);
|
||||
var response = client.PutAsync(_uri.ToString() + updated.Id.ToString(), content).Result;
|
||||
var content = new ObjectContent<TaskModel>(task, jsonFormatter);
|
||||
var response = client.PutAsync(_uri.ToString() + task.Id.ToString(), content).Result;
|
||||
|
||||
return await response.Content.ReadAsAsync<ScheduledTask>();
|
||||
return await response.Content.ReadAsAsync<TaskModel>();
|
||||
}
|
||||
|
||||
public async Task<string> DeleteTask(Guid taskId)
|
||||
public string DeleteTask(Guid taskId)
|
||||
{
|
||||
var request = (HttpWebRequest)WebRequest.Create(_uri + taskId.ToString());
|
||||
|
||||
request.Method = "DELETE";
|
||||
request.Headers.Add("Authorization",
|
||||
new Signature(this._tenantId, this._secretKey).ToString());
|
||||
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
string result;
|
||||
using (var sr = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
result = sr.ReadToEnd();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<string> DeleteTaskAsync(Guid taskId)
|
||||
{
|
||||
var client = new HttpClient();
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aditi.Scheduler;
|
||||
using Aditi.Scheduler.Models;
|
||||
|
||||
namespace Tester_Synch
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static string tenantId = "0007057b-0d06-4825-a812-42b1d896cc95";
|
||||
private static string secretKey = "nQOSFjqiEwIrymp5g+iaDRx1UmUgM+UMeOP9MkTaw0k=";
|
||||
private static Uri uri = new Uri("http://schedulerdev.aditicloud.com/api/task/");
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var scheduledTasks = new ScheduledTasks(uri, tenantId, secretKey);
|
||||
|
||||
// create a task
|
||||
var task = new TaskModel
|
||||
{
|
||||
Name = "My first Scheduler job",
|
||||
JobType = JobType.Webhook,
|
||||
CronExpression = "0 0/5 * 1/1 * ? *", // run every 5 minutes
|
||||
Params = new Dictionary<string, object>
|
||||
{
|
||||
{"url", "http://www.microsoft.com"}
|
||||
}
|
||||
};
|
||||
|
||||
var newTask = scheduledTasks.CreateTask(task);
|
||||
|
||||
var tasks = scheduledTasks.GetTasks();
|
||||
|
||||
var getTask = scheduledTasks.GetTask(newTask.Id);
|
||||
|
||||
newTask.Name = "new name";
|
||||
|
||||
var updTask = scheduledTasks.UpdateTask(newTask);
|
||||
|
||||
getTask = scheduledTasks.GetTask(updTask.Id);
|
||||
|
||||
var delTask = scheduledTasks.DeleteTask(newTask.Id);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Tester_Synch")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Tester_Synch")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("fdefbf8c-2a0e-47ee-871f-974ad172531b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,68 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{CE3B1238-6080-49CF-8D7C-C2B650A92F0E}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Tester_Synch</RootNamespace>
|
||||
<AssemblyName>Tester_Synch</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Aditi.Scheduler.Models\Aditi.Scheduler.Models.csproj">
|
||||
<Project>{21444757-3d70-45fc-a948-279ad079e470}</Project>
|
||||
<Name>Aditi.Scheduler.Models</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Aditi.Scheduler\Aditi.Scheduler.csproj">
|
||||
<Project>{2730a987-bd8d-435b-a7ed-03db7f54cea4}</Project>
|
||||
<Name>Aditi.Scheduler</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Загрузка…
Ссылка в новой задаче