-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskUpdateStatus.cs
More file actions
89 lines (82 loc) · 3.85 KB
/
Copy pathTaskUpdateStatus.cs
File metadata and controls
89 lines (82 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TaskScheduler
{
public class TaskUpdateStatus: TaskBase
{
private int _specialIndex = 0;
private long _counter = 0;
public class GeocacheInfo
{
public long ID { get; set; }
public string Code { get; set; }
}
public TaskUpdateStatus(Manager taskManager) :
base(taskManager, typeof(TaskUpdateStatus), "Update status", 0, 1, 0)
{
}
protected override void ServiceMethod()
{
try
{
string token = GeocachingAPI.Instance.GetServiceToken(ref _specialIndex);
if (token.Length > 0)
{
using (var db = new PetaPoco.Database(Manager.SchedulerConnectionString, "System.Data.SqlClient"))
{
List<long> gcidList = db.Fetch<long>("SELECT LastGeocacheID FROM TaskUpdateStatus");
long lastId = 0;
if (gcidList.Count > 0)
{
lastId = gcidList[0];
}
List<GeocacheInfo> gil = db.SkipTake<GeocacheInfo>(0, 100, string.Format("select ID, Code from [{0}].[dbo].[GCComGeocache] where ID>@0 order by ID", GCComDataSupport.GeocachingDatabaseName), lastId);
if (gil.Count < 100)
{
lastId = 0;
}
else
{
lastId = gil[gil.Count - 1].ID;
}
if (gcidList.Count > 0)
{
db.Execute("update TaskUpdateStatus set LastGeocacheID=@0", lastId);
}
else
{
db.Execute("insert into TaskUpdateStatus (LastGeocacheID) values (@0)", lastId);
}
if (gil.Count > 0)
{
Tucson.Geocaching.WCF.API.Geocaching1.Types.GeocacheStatus[] gstats = GeocachingAPI.GetGeocacheStatus(token, (from a in gil select a.Code).ToArray());
if (gstats != null)
{
foreach (Tucson.Geocaching.WCF.API.Geocaching1.Types.GeocacheStatus stats in gstats)
{
db.Execute(string.Format("update [{0}].[dbo].[GCComGeocache] set Archived=@0, Available=@1 where Code=@2", GCComDataSupport.GeocachingDatabaseName), stats.Archived, stats.Available, stats.CacheCode);
db.Execute(string.Format("update [{0}].[dbo].GCEuGeocache set StatusUpdateDate = @0 where ID=@1", GCEuDataSupport.GlobalcachingDatabaseName), DateTime.Now, Helper.GetCacheIDFromCacheCode(stats.CacheCode));
}
_counter++;
Details = string.Format("{0}, total counter={1}, this batch={2}, lastWP={3}", DateTime.Now.ToString(), _counter.ToString(), gstats.Length, lastId);
}
else
{
Details = string.Format("{0}, total counter={1}, this batch=ERROR, lastWP={2}", DateTime.Now.ToString(), _counter.ToString(), lastId);
}
}
}
}
ServiceInfo.ErrorInLastRun = false;
}
catch (Exception e)
{
Details = e.Message;
ServiceInfo.ErrorInLastRun = true;
}
}
}
}