Fix stringsource parsing to that apostrophes don't count as quotes.
[schedulator.git] / resultsource.cs
blob387e02e8f4c99999352bf2a9551c0d4689f46736
1 using System;
2 using System.Data;
3 using Wv;
4 using Wv.Schedulator;
6 namespace Wv.Schedulator
8 public class ResultSource : Source, IDisposable
10 string user; // get the bugs for this username
11 WvLog log;
12 public WvDbi db;
14 public ResultSource(Schedulator s, string name,
15 string odbcstring, string user)
16 : base(s, name)
18 if (!wv.isempty(user))
19 this.user = user;
20 else
21 this.user = s.name;
22 log = new WvLog(String.Format("Result:{0}", name));
23 log.print("Initializing result plugin '{0}'.\n", name);
24 log.print("Connecting to: '{0}'\n", odbcstring);
25 db = WvDbi.create(odbcstring);
27 // db.try_execute("drop table Schedule");
28 db.try_execute("create table Schedule ("
29 + "sUser varchar(40) not null, "
30 + "sProject varchar(40) not null, "
31 + "sFixFor varchar(40) not null, "
32 + "sTaskId varchar(40) not null, "
33 + "sTask varchar(80) not null, "
34 + "ixPriority int not null, "
35 + "fDone boolean not null, "
36 + "fHalfDone boolean not null, "
37 + "fEstimated boolean not null, "
38 + "dtStart datetime not null, "
39 + "dtEnd datetime not null "
40 + ")");
43 public void Dispose()
45 if (db != null)
47 db.Dispose();
48 db = null;
52 public static Source create(Schedulator s, string name,
53 string prefix, string suffix)
55 string[] points = suffix.Split(':');
56 string dsn = points[0];
57 string user = points.Length>1 ? points[1] : null;
58 return new ResultSource(s, name, dsn, user);
61 public override void post_schedule()
63 db.execute("delete from Schedule where sUser=?", user);
65 string q =
66 "insert into Schedule "
67 + "(sUser,sProject,sFixFor,sTaskId,sTask,"
68 + " ixPriority,fDone,fHalfDone,fEstimated,dtStart,dtEnd) "
69 + "values (?,?,?,?,?,?,?,?,?,?,?) ";
71 foreach (TimeSlot _ts in s.schedule)
73 if (_ts is TaskTimeSlot)
75 TaskTimeSlot ts = (TaskTimeSlot)_ts;
76 log.print("Adding {0} - {1}\n", ts.start, ts.end);
77 FixFor ff = ts.task.fixfor;
78 if (ff == null)
79 ff = s.fixfors.Add(s.projects.Add("UNKNOWN"),
80 "-Undecided-");
81 db.execute(q, user, ff.project.name, ff.name,
82 ts.task.moniker, ts.name, ts.task.priority,
83 ts.done ? 1 : 0,
84 ts.task.halfdone ? 1 : 0,
85 ts.task.is_estimated() ? 1 : 0,
86 ts.start, ts.end);