Skip to content

Commit bb55159

Browse files
committed
Validate TimeZoneId
1 parent 7041fb3 commit bb55159

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed

IntegrationEngine/Api/Controllers/CronTriggerController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public IHttpActionResult PutCronTrigger(string id, CronTrigger trigger)
4848
return BadRequest("Job type is invalid: " + trigger.JobType);
4949
if (!trigger.CronExpressionString.IsValidCronExpression())
5050
return BadRequest("Cron expression is not valid: " + trigger.CronExpressionString);
51+
if (!trigger.TimeZoneId.IsValidTimeZone())
52+
return BadRequest("Time zone id is invalid: " + trigger.TimeZoneId);
5153
Repository.Update(trigger);
5254
EngineScheduler.ScheduleJobWithCronTrigger(trigger);
5355
return StatusCode(HttpStatusCode.NoContent);
@@ -61,6 +63,8 @@ public IHttpActionResult PostCronTrigger(CronTrigger trigger)
6163
return BadRequest("Job type is invalid: " + trigger.JobType);
6264
if (!trigger.CronExpressionString.IsValidCronExpression())
6365
return BadRequest("Cron expression is not valid: " + trigger.CronExpressionString);
66+
if (!trigger.TimeZoneId.IsValidTimeZone())
67+
return BadRequest("Time zone id is invalid: " + trigger.TimeZoneId);
6468
var triggerWithId = Repository.Insert(trigger);
6569
EngineScheduler.ScheduleJobWithCronTrigger(triggerWithId);
6670
return CreatedAtRoute("DefaultApi", new { id = triggerWithId.Id }, triggerWithId);

IntegrationEngine/IntegrationEngine.csproj

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@
5353
<WarningLevel>4</WarningLevel>
5454
</PropertyGroup>
5555
<ItemGroup>
56-
<Reference Include="Common.Logging, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e, processorArchitecture=MSIL">
57-
<SpecificVersion>False</SpecificVersion>
58-
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
59-
</Reference>
6056
<Reference Include="Common.Logging.Core">
6157
<HintPath>..\packages\Common.Logging.Core.3.0.0\lib\net40\Common.Logging.Core.dll</HintPath>
6258
</Reference>
@@ -78,21 +74,9 @@
7874
<Reference Include="Microsoft.Owin.Hosting">
7975
<HintPath>..\packages\Microsoft.Owin.Hosting.3.0.0\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
8076
</Reference>
81-
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
82-
<SpecificVersion>False</SpecificVersion>
83-
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
84-
</Reference>
8577
<Reference Include="NLog">
8678
<HintPath>..\packages\NLog.3.2.0.0\lib\net45\NLog.dll</HintPath>
8779
</Reference>
88-
<Reference Include="Quartz, Version=2.3.1.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
89-
<SpecificVersion>False</SpecificVersion>
90-
<HintPath>..\packages\Quartz.2.3.1\lib\net40\Quartz.dll</HintPath>
91-
</Reference>
92-
<Reference Include="RabbitMQ.Client, Version=3.4.3.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce, processorArchitecture=MSIL">
93-
<SpecificVersion>False</SpecificVersion>
94-
<HintPath>..\packages\RabbitMQ.Client.3.4.3\lib\net35\RabbitMQ.Client.dll</HintPath>
95-
</Reference>
9680
<Reference Include="System" />
9781
<Reference Include="Elasticsearch.Net">
9882
<HintPath>..\packages\Elasticsearch.Net.1.3.1\lib\Elasticsearch.Net.dll</HintPath>
@@ -140,6 +124,18 @@
140124
<Reference Include="Microsoft.Practices.Unity.RegistrationByConvention">
141125
<HintPath>..\packages\Unity.3.5.1404.0\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll</HintPath>
142126
</Reference>
127+
<Reference Include="Common.Logging">
128+
<HintPath>..\packages\Common.Logging.3.0.0\lib\net40\Common.Logging.dll</HintPath>
129+
</Reference>
130+
<Reference Include="Newtonsoft.Json">
131+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
132+
</Reference>
133+
<Reference Include="Quartz">
134+
<HintPath>..\packages\Quartz.2.3.1\lib\net40\Quartz.dll</HintPath>
135+
</Reference>
136+
<Reference Include="RabbitMQ.Client">
137+
<HintPath>..\packages\RabbitMQ.Client.3.4.3\lib\net35\RabbitMQ.Client.dll</HintPath>
138+
</Reference>
143139
</ItemGroup>
144140
<ItemGroup>
145141
<Compile Include="..\configuration\SharedAssemblyInfo.cs">
@@ -175,8 +171,7 @@
175171
<Compile Include="Scheduler\ITimeZone.cs" />
176172
<Compile Include="Scheduler\SimpleTrigger.cs" />
177173
<Compile Include="Scheduler\TimeZone.cs" />
178-
<Compile Include="Scheduler\TriggerCronExpressionExtension.cs" />
179-
<Compile Include="Scheduler\TriggerStateIdExtension.cs" />
174+
<Compile Include="Scheduler\TriggerPropertyExtension.cs" />
180175
</ItemGroup>
181176
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
182177
<ItemGroup>

IntegrationEngine/Scheduler/TriggerCronExpressionExtension.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
3+
namespace IntegrationEngine.Scheduler
4+
{
5+
public static class TriggerPropertyExtension
6+
{
7+
public static bool IsValidCronExpression(this string value)
8+
{
9+
return Quartz.CronExpression.IsValidExpression(value);
10+
}
11+
12+
public static bool IsValidTimeZone(this string value)
13+
{
14+
try
15+
{
16+
TimeZoneInfo.FindSystemTimeZoneById(value);
17+
return true;
18+
}
19+
catch
20+
{
21+
return false;
22+
}
23+
}
24+
25+
public static string GetStateDescription(this int value)
26+
{
27+
return ((Quartz.TriggerState)value).ToString();
28+
}
29+
}
30+
}

IntegrationEngine/Scheduler/TriggerStateIdExtension.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)