From d932ea6c69bd5dbbd35f2de4139458d98500d6d8 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Fri, 4 Apr 2008 18:17:59 -0400 Subject: [PATCH] Beginnings of a switch to use latest wvdotnet library. All compiles, but I get errors running unit tests or the main app. --- .gitignore | 1 + .gitmodules | 3 + Makefile | 79 +++---- dateslider.cs | 18 +- dateslider.t.cs | 8 +- fixfor.cs | 3 +- fogbugz.cs | 126 +++++------ googlecode.cs | 16 +- logsource.cs | 2 +- mantis.cs | 133 ++++++------ person.cs | 3 +- project.cs | 3 +- resultsource.cs | 25 ++- schedulator.cs | 45 ++-- schedulator.t.cs | 13 +- source.cs | 9 +- stringsource.cs | 14 +- task.cs | 3 +- testsource.cs | 2 +- versaplex | 1 + webtest.cs | 22 +- webui.cs | 114 +++++----- wvdbi.cs | 100 --------- wvdotnet | 1 + wvini.cs | 59 ----- wvtest.cs | 123 ----------- wvtest.cs.h | 8 - wvtest.t.cs | 58 ----- wvutils.cs | 284 ------------------------ wvutils.t.cs | 36 ---- wvweb.cs | 645 ------------------------------------------------------- 31 files changed, 302 insertions(+), 1655 deletions(-) create mode 100644 .gitmodules rewrite Makefile (77%) create mode 160000 versaplex delete mode 100644 wvdbi.cs create mode 120000 wvdotnet delete mode 100644 wvini.cs delete mode 100644 wvtest.cs delete mode 100644 wvtest.cs.h delete mode 100644 wvtest.t.cs delete mode 100644 wvutils.cs delete mode 100644 wvutils.t.cs delete mode 100644 wvweb.cs diff --git a/.gitignore b/.gitignore index 6546ed6..6b65bec 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.exe *.mdb *~ +*.dll diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e38682f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "versaplex"] + path = versaplex + url = ../versaplex.git diff --git a/Makefile b/Makefile dissimilarity index 77% index ad0c544..b8e4b3a 100644 --- a/Makefile +++ b/Makefile @@ -1,50 +1,29 @@ - -CSFLAGS=-warn:4 -debug -#CSFLAGS += -warnaserror -PKGS=-pkg:nunit -r:System.Data -r:System.Web - -all: schedulator.exe webtest.exe - -LIBFILES= \ - wvutils.cs wvtest.cs wvweb.cs wvdbi.cs wvini.cs \ - wvtest.t.cs.E wvutils.t.cs.E \ - -webtest.exe: webtest.cs $(LIBFILES) - -schedulator.exe: schedulator.cs webui.cs $(LIBFILES) \ - source.cs person.cs project.cs fixfor.cs task.cs dateslider.cs \ - testsource.cs stringsource.cs logsource.cs fogbugz.cs mantis.cs \ - resultsource.cs googlecode.cs \ - $(addsuffix .E,$(wildcard *.t.cs)) - -test: schedulator.exe - nunit-console /nologo /labels $^ - -# you're supposed to use addsuffix() here, but it doesn't really -# matter: if the .E file doesn't exist, we don't care that it -# depends on a .h file. -$(wildcard *.cs.E): $(wildcard *.h) - -%: %.exe - rm -f $@ && ln -sf $< $@ - -%.cs.E: %.cs - @rm -f $@ - cpp -C -dI $< \ - | expand -8 \ - | sed -e 's,^#include,//#include,' \ - | grep -v '^# [0-9]' \ - >$@ - -define mcs_go - gmcs $(PKGS) $(CSFLAGS) -out:$@ $(filter %.E %.cs,$^) -endef - -%.exe: %.cs.E - $(mcs_go) - -%.exe: %.cs - $(mcs_go) - -clean: - rm -f *~ *.E *.exe *.dll TestResult.xml *.mdb +include wvdotnet/rules.mk +include wvdotnet/monorules.mk + +PKGS=-r:System.Data -r:System.Web +CPPFLAGS=-Iwvdotnet +DOTDIR=../$(shell basename "$$PWD") + +all: schedulator.exe webtest.exe + +webtest.exe: webtest.cs $(DOTDIR)/wvdotnet/wv.dll + +SRC=schedulator.cs \ + source.cs person.cs project.cs fixfor.cs task.cs dateslider.cs \ + testsource.cs stringsource.cs logsource.cs fogbugz.cs mantis.cs \ + resultsource.cs googlecode.cs \ + $(DOTDIR)/wvdotnet/wv.dll + +schedulator.exe: webui.cs $(SRC) + +schedulator.t.exe: $(SRC) \ + $(addsuffix .E,$(wildcard *.t.cs)) \ + +tests: schedulator.t.exe + +test: tests + mono --debug ./schedulator.t.exe + +clean:: + rm -f *~ *.E *.exe *.dll TestResult.xml *.mdb diff --git a/dateslider.cs b/dateslider.cs index 87b7dff..04655f9 100644 --- a/dateslider.cs +++ b/dateslider.cs @@ -1,5 +1,5 @@ using System; -using Wv.Utils; +using Wv; namespace Wv.Schedulator { @@ -92,8 +92,8 @@ namespace Wv.Schedulator public DateTime add(DateTime point, TimeSpan span) { - Log log = new SilentLog("slider"); - log.log("* {0} + {1}", point, span.TotalHours); + WvLog log = new WvLog("slider", WvLog.L.Debug5); + log.print("* {0} + {1}", point, span.TotalHours); int sign = (span.Ticks < 0) ? -1 : 1; bool less_one = false; @@ -102,7 +102,7 @@ namespace Wv.Schedulator double hpw = hours_per_week / loadfactor; while (Math.Abs(span.TotalHours) >= hpw) { - log.log("W {0} + {1} ({2})", point, span.TotalHours, hpw); + log.print("W {0} + {1} ({2})", point, span.TotalHours, hpw); point = point.AddDays(7*sign); span = span.Add(TimeSpan.FromHours(-hpw*sign)); } @@ -140,7 +140,7 @@ namespace Wv.Schedulator double hpd = hours_per_day[day] * dayfraction / loadfactor; - log.log("D {0} + {1} ({2})", point, span.TotalHours, hpd); + log.print("D {0} + {1} ({2})", point, span.TotalHours, hpd); if (Math.Abs(span.TotalHours) >= hpd) { // avoid rounding errors by forcing the date @@ -158,7 +158,7 @@ namespace Wv.Schedulator } } - log.log(": {0} + {1}", point, span.TotalHours); + log.print(": {0} + {1}", point, span.TotalHours); // ah, rounding errors. The above should make things work out // to within the nearest minute or so, which is close enough(tm). @@ -166,7 +166,7 @@ namespace Wv.Schedulator point = point.AddHours(Math.Round(th, 1) - th + 0.5/60.0/60.0); point = new DateTime(point.Year, point.Month, point.Day, point.Hour, point.Minute, 0, 0); - log.log(". {0} + {1} ({2})", + log.print(". {0} + {1} ({2})", point, span.TotalHours, Math.Round(th, 1)); return point; } @@ -177,7 +177,7 @@ namespace Wv.Schedulator // to, but not including, x. public TimeSpan diff(DateTime x, DateTime y) { - Log log = new SilentLog("slider"); + WvLog log = new WvLog("slider", WvLog.L.Debug5); wv.assert(x > y); DateTime point = y, end = x; @@ -209,7 +209,7 @@ namespace Wv.Schedulator } } - log.log("result: {0} hours", result.TotalHours); + log.print("result: {0} hours", result.TotalHours); return result; } } diff --git a/dateslider.t.cs b/dateslider.t.cs index f30b979..80689f5 100644 --- a/dateslider.t.cs +++ b/dateslider.t.cs @@ -1,15 +1,13 @@ #include "wvtest.cs.h" - using System; -using NUnit.Framework; using Wv.Test; -using Wv.Utils; +using Wv; using Wv.Schedulator; [TestFixture] public class DateSliderTests { - Log log = new Log("log"); + WvLog log = new WvLog("log"); static DateTime date(string s) { @@ -82,7 +80,7 @@ public class DateSliderTests DateTime dt2 = date("1997-01-29").AddHours(0.75*24); DateTime odt1 = slider.add(dt1, TimeSpan.FromHours(4)); DateTime odt2 = slider.add(dt2, TimeSpan.FromHours(-4)); - log.log("Start: {0} - {1}", dt1, dt2); + log.print("Start: {0} - {1}", dt1, dt2); WVPASSEQ(dt2.ToString(), odt1.ToString()); WVPASSEQ(dt1.ToString(), odt2.ToString()); } diff --git a/fixfor.cs b/fixfor.cs index 7554a81..56807e1 100644 --- a/fixfor.cs +++ b/fixfor.cs @@ -1,6 +1,7 @@ using System; using System.Collections; -using Wv.Utils; +using Wv; +using Wv.Obsolete; namespace Wv.Schedulator { diff --git a/fogbugz.cs b/fogbugz.cs index 5693807..7770828 100644 --- a/fogbugz.cs +++ b/fogbugz.cs @@ -1,7 +1,6 @@ using System; using System.Collections; -using Wv.Dbi; -using Wv.Utils; +using Wv; using Wv.Schedulator; using System.Data; using System.Data.Odbc; @@ -11,9 +10,9 @@ namespace Wv.Schedulator public class FogBugzSource : Source { string user; // get the bugs for this username - Log log; + WvLog log; - Db db; + WvDbi db; public FogBugzSource(Schedulator s, string name, string odbcstring, string user) @@ -23,10 +22,10 @@ namespace Wv.Schedulator this.user = user; else this.user = s.name; - log = new Log(String.Format("FogBugz:{0}", name)); - log.log("Initializing FogBugz source '{0}'.", name); - log.log("Connecting to: '{0}'", odbcstring); - db = new Db(odbcstring); + log = new WvLog(String.Format("FogBugz:{0}", name)); + log.print("Initializing FogBugz source '{0}'.", name); + log.print("Connecting to: '{0}'", odbcstring); + db = new WvDbi(odbcstring); } public static Source create(Schedulator s, string name, @@ -53,17 +52,14 @@ namespace Wv.Schedulator public override void make_basic() { - IDataReader r; - - log.log("Reading Person table."); - r = db.select("select ixPerson, sFullName, sEmail " + log.print("Reading Person table."); + foreach (var r in db.select("select ixPerson, sFullName, sEmail " + "from Person " - + "order by fDeleted, ixPerson "); - while (r.Read()) + + "order by fDeleted, ixPerson ")) { - int ix = r.GetInt32(0); - string fullname = r.IsDBNull(1) ? null : r.GetString(1); - string email = r.IsDBNull(2) ? "--" : r.GetString(2); + int ix = r[0]; + string fullname = r[1]; + string email = r[2].IsNull ? "--" : r[2]; string name = email; if (name.IndexOf('@') >= 0) @@ -77,27 +73,25 @@ namespace Wv.Schedulator fogpersons_byname.Add(fullname, ix); } - log.log("Reading Project table."); - r = db.select("select ixProject, sProject from Project"); - while (r.Read()) + log.print("Reading Project table."); + foreach (var r in db.select("select ixProject, sProject " + + " from Project")) { - int ix = r.GetInt32(0); - string name = r.IsDBNull(1) ? null : r.GetString(1); + int ix = r[0]; + string name = r[1]; Project p = s.projects.Add(name); fogprojects.Add(ix, p); } - log.log("Reading FixFor table."); - r = db.select("select ixFixFor, ixProject, sFixFor, dt " - + " from FixFor "); - while (r.Read()) + log.print("Reading FixFor table."); + foreach (var r in db.select("select ixFixFor, ixProject, sFixFor, dt " + + " from FixFor ")) { - int ix = r.GetInt32(0); - int projix = r.GetInt32(1); - string name = r.IsDBNull(2) ? null : r.GetString(2); - DateTime date = - r.IsDBNull(3) ? DateTime.MinValue : r.GetDateTime(3); + int ix = r[0]; + int projix = r[1]; + string name = r[2]; + DateTime date = r[3]; Project project = (Project)fogprojects[projix]; if (project == null) @@ -145,7 +139,6 @@ namespace Wv.Schedulator public override Task[] make_tasks() { - IDataReader r; Hashtable abugs = new Hashtable(); // active Hashtable vbugs = new Hashtable(); // needs-verify Hashtable rbugs = new Hashtable(); // resolved-by-me @@ -153,56 +146,53 @@ namespace Wv.Schedulator if (!fogpersons_byname.Contains(user)) { - log.log("No user '{0}' exists!", user); + log.print("No user '{0}' exists!", user); return null; } int userix = (int)fogpersons_byname[user]; - log.log("Listing active bugs."); - r = db.select(String.Format + log.print("Listing active bugs."); + foreach (var r in db.select(String.Format ("select ixBug, ixStatus " + "from Bug " + "where ixPersonAssignedTo={0} " - + " and fOpen=1 ", userix)); - while (r.Read()) + + " and fOpen=1 ", userix))) { - int ix = r.GetInt32(0); - int status = r.GetInt32(1); + int ix = r[0]; + int status = r[1]; if (status > 1) vbugs.Add(ix, ix.ToString()); else abugs.Add(ix, ix.ToString()); } - log.log("Reading BugEvent table (1)."); - r = db.select(String.Format + log.print("Reading BugEvent table (1)."); + foreach (var r in db.select(String.Format ("select distinct ixBug " + " from BugEvent " + " where ixPerson={0} " - + " and sVerb like 'Resolved %' ", userix)); - while (r.Read()) - rbugs.Add(r.GetInt32(0), r.GetInt32(0).ToString()); - log.log(" {0} bugs to check.", rbugs.Count); + + " and sVerb like 'Resolved %' ", userix))) + rbugs.Add(r[0], r[0]); + log.print(" {0} bugs to check.", rbugs.Count); string rbugs_str = bug_str(rbugs.Values); - //log.log("rbugs: {0}", rbugs_str); + //log.print("rbugs: {0}", rbugs_str); - log.log("Reading BugEvent table (2)."); + log.print("Reading BugEvent table (2)."); rbugs.Clear(); - r = db.select(String.Format + int last_bug = -1; + bool resolved_by_me_once = false, resolved_away = false; + foreach (var r in db.select(String.Format ("select ixBug, ixPerson, sVerb " + " from BugEvent " + " where sVerb like 'Resolved %' " + " and ixBug in ({1}) " + " order by ixBug, ixBugEvent ", - userix, rbugs_str)); - int last_bug = -1; - bool resolved_by_me_once = false, resolved_away = false; - while (r.Read()) + userix, rbugs_str))) { - int bug = r.GetInt32(0); - int ixperson = r.GetInt32(1); - string verb = r.GetString(2); + int bug = r[0]; + int ixperson = r[1]; + string verb = r[2]; if (last_bug != bug) { @@ -241,33 +231,31 @@ namespace Wv.Schedulator else if (resolved_by_me_once) rbugs.Add(last_bug, last_bug.ToString()); - log.log("{0} rbugs and {1} sbugs.", rbugs.Count, sbugs.Count); + log.print("{0} rbugs and {1} sbugs.", rbugs.Count, sbugs.Count); - log.log("Reading Bug details."); + log.print("Reading Bug details."); ArrayList all_bugs = new ArrayList(); add_list(all_bugs, abugs.Values); add_list(all_bugs, vbugs.Values); add_list(all_bugs, rbugs.Values); add_list(all_bugs, sbugs.Values); string all_str = bug_str(all_bugs); - r = db.select(String.Format + foreach (var r in db.select(String.Format ("select ixBug, sTitle, ixFixFor, ixPriority, " + " dtResolved, " + " hrsOrigEst, hrsCurrEst, hrsElapsed " + "from Bug " - + "where ixBug in ({0})", all_str)); - while (r.Read()) + + "where ixBug in ({0})", all_str))) { - int ix = r.GetInt32(0); + int ix = r[0]; string ixstr = ix.ToString(); - string title = r.IsDBNull(1) ? "--" : r.GetString(1); - int ixfixfor = r.GetInt32(2); - int pri = r.GetInt32(3); - DateTime resolvedate = - r.IsDBNull(4) ? DateTime.MinValue : r.GetDateTime(4); - double origest = r.GetFloat(5); - double currest = r.GetFloat(6); - double elapsed = r.GetFloat(7); + string title = r[1].IsNull ? "--" : r[1]; + int ixfixfor = r[2]; + int pri = r[3]; + DateTime resolvedate = r[4]; + double origest = r[5]; + double currest = r[6]; + double elapsed = r[7]; FixFor fixfor = (FixFor)fogfixfors[ixfixfor]; diff --git a/googlecode.cs b/googlecode.cs index 2d4196f..61a44ce 100644 --- a/googlecode.cs +++ b/googlecode.cs @@ -4,7 +4,7 @@ using System.Net; using System.Web; using System.Collections; using System.Text.RegularExpressions; -using Wv.Utils; +using Wv; using Wv.Schedulator; namespace Wv.Schedulator @@ -13,7 +13,7 @@ namespace Wv.Schedulator { string project; // get the bugs from this googlecode project string user; // get the bugs for this username - Log log; + WvLog log; class Row { @@ -32,8 +32,8 @@ namespace Wv.Schedulator else this.user = s.name; - log = new Log(wv.fmt("GoogleCode:{0}", name)); - log.log("Initializing GoogleCode source '{0}'.", name); + log = new WvLog(wv.fmt("GoogleCode:{0}", name)); + log.print("Initializing GoogleCode source '{0}'.", name); } public static Source create(Schedulator s, string name, @@ -66,13 +66,13 @@ namespace Wv.Schedulator project, user, start); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); - log.log("Created request (start={0}).", start); + log.print("Created request (start={0}).", start); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); - log.log("Created response."); + log.print("Created response."); StreamReader rr = new StreamReader(resp.GetResponseStream()); - log.log("Created reader."); + log.print("Created reader."); string s = rr.ReadToEnd(); @@ -89,7 +89,7 @@ namespace Wv.Schedulator if (content == " ") continue; content = HttpUtility.HtmlDecode(content); - // log.log("Match: {0}: [{1}]", colid, content); + // log.print("Match: {0}: [{1}]", colid, content); switch (wv.atoi(colid)) { diff --git a/logsource.cs b/logsource.cs index 77de10d..5d59a76 100644 --- a/logsource.cs +++ b/logsource.cs @@ -2,7 +2,7 @@ using System; using System.IO; using System.Web; using System.Collections; -using Wv.Utils; +using Wv; using Wv.Schedulator; namespace Wv.Schedulator diff --git a/mantis.cs b/mantis.cs index 0005e1f..ba8340d 100644 --- a/mantis.cs +++ b/mantis.cs @@ -2,8 +2,7 @@ using System; using System.Data; using System.Data.Odbc; using System.Collections; -using Wv.Dbi; -using Wv.Utils; +using Wv; using Wv.Schedulator; namespace Wv.Schedulator @@ -11,9 +10,9 @@ namespace Wv.Schedulator public class MantisSource : Source { string user; // get the bugs for this username - Log log; + WvLog log; - Db db; + WvDbi db; public MantisSource(Schedulator s, string name, string odbcstring, string user) @@ -26,10 +25,10 @@ namespace Wv.Schedulator else this.user = s.name; - log = new Log(wv.fmt("Mantis:{0}", name)); - log.log("Initializing Mantis source '{0}'.", name); - log.log("Connecting to: '{0}'", odbcstring); - db = new Db(odbcstring); + log = new WvLog(wv.fmt("Mantis:{0}", name)); + log.print("Initializing Mantis source '{0}'.", name); + log.print("Connecting to: '{0}'", odbcstring); + db = new WvDbi(odbcstring); } public static Source create(Schedulator s, string name, @@ -56,17 +55,14 @@ namespace Wv.Schedulator public override void make_basic() { - IDataReader r; - - log.log("Reading mantis_user_table."); - r = db.select("select id, username, realname " + log.print("Reading mantis_user_table."); + foreach (var r in db.select("select id, username, realname " + "from mantis_user_table " - + "order by enabled desc, id "); - while (r.Read()) + + "order by enabled desc, id ")) { - int ix = r.GetInt32(0); - string name = r.IsDBNull(1) ? "--" : r.GetString(1); - string fullname = r.IsDBNull(2) ? null : r.GetString(2); + int ix = r[0]; + string name = r[1].IsNull ? "--" : r[1]; + string fullname = r[2]; if (wv.isempty(fullname)) fullname = name; name = name.ToLower(); @@ -82,28 +78,26 @@ namespace Wv.Schedulator mantispersons_byname.Remove(""); mantispersons_byname.Add("", 0); - log.log("Reading mantis_project_table."); - r = db.select("select id, name from mantis_project_table"); - while (r.Read()) + log.print("Reading mantis_project_table."); + foreach (var r in db.select("select id, name from mantis_project_table")) { - int ix = r.GetInt32(0); - string name = r.IsDBNull(1) ? null : r.GetString(1); + int ix = r[0]; + string name = r[1]; Project p = s.projects.Add(name); mantisprojects.Add(ix, p); } - log.log("Reading list of versions."); + log.print("Reading list of versions."); string[] cols = {"fixed_in_version", "version"}; foreach (string col in cols) { - r = db.select(wv.fmt("select distinct project_id, {0} " + foreach (var r in db.select(wv.fmt("select distinct project_id, {0} " + "from mantis_bug_table " - + "order by project_id, {0} ", col)); - while (r.Read()) + + "order by project_id, {0} ", col))) { - int projix = r.GetInt32(0); - string name = r.GetString(1); + int projix = r[0]; + string name = r[1]; if (wv.isempty(name)) name = "-Undecided-"; string ix = projix.ToString() + "." + name; @@ -117,14 +111,13 @@ namespace Wv.Schedulator } } - log.log("Reading mantis_project_version_table."); - r = db.select("select project_id, version, date_order " - + " from mantis_project_version_table "); - while (r.Read()) + log.print("Reading mantis_project_version_table."); + foreach (var r in db.select("select project_id, version, date_order " + + " from mantis_project_version_table ")) { - int projix = r.GetInt32(0); - string name = r.GetString(1); - DateTime date = r.GetDateTime(2); + int projix = r[0]; + string name = r[1]; + DateTime date = r[2]; string ix = projix.ToString() + "." + name; Project project = (Project)mantisprojects[projix]; @@ -206,7 +199,6 @@ namespace Wv.Schedulator public override Task[] make_tasks() { - IDataReader r; Hashtable abugs = new Hashtable(); // active Hashtable vbugs = new Hashtable(); // needs-verify Hashtable rbugs = new Hashtable(); // resolved-by-me @@ -214,57 +206,54 @@ namespace Wv.Schedulator if (!mantispersons_byname.Contains(user)) { - log.log("No user '{0}' exists!", user); + log.print("No user '{0}' exists!", user); return null; } int userix = (int)mantispersons_byname[user]; - log.log("Listing active bugs."); - r = db.select(wv.fmt("select id, status " + log.print("Listing active bugs."); + foreach (var r in db.select(wv.fmt("select id, status " + "from mantis_bug_table " + "where handler_id={0} " + " and status != {1} ", - userix, (int)Status.Closed)); - while (r.Read()) + userix, (int)Status.Closed))) { - int ix = r.GetInt32(0); - int status = r.GetInt32(1); + int ix = r[0]; + int status = r[1]; if (status >= (int)Status.Resolved) vbugs.Add(ix, ix.ToString()); else abugs.Add(ix, ix.ToString()); } - log.log("Reading mantis_bug_history_table (1)."); - r = db.select(wv.fmt("select distinct bug_id " + log.print("Reading mantis_bug_history_table (1)."); + foreach (var r in db.select(wv.fmt("select distinct bug_id " + " from mantis_bug_history_table " + " where user_id={0} " + " and field_name='resolution' ", - userix)); - while (r.Read()) - rbugs.Add(r.GetInt32(0), r.GetInt32(0).ToString()); - log.log(" {0} bugs to check.", rbugs.Count); + userix))) + rbugs.Add(r[0], r[0]); + log.print(" {0} bugs to check.", rbugs.Count); string rbugs_str = bug_str(rbugs.Values); - // log.log("rbugs: {0}", rbugs_str); + // log.print("rbugs: {0}", rbugs_str); - log.log("Reading mantis_bug_history_table (2)."); + log.print("Reading mantis_bug_history_table (2)."); rbugs.Clear(); - r = db.select(wv.fmt + int last_bug = -1; + bool resolved_by_me_once = false, resolved_away = false; + foreach (var r in db.select(wv.fmt ("select bug_id, user_id, new_value " + " from mantis_bug_history_table " + " where field_name='resolution' " + " and new_value is not null " + " and bug_id in ({1}) " + " order by bug_id, id ", - userix, rbugs_str)); - int last_bug = -1; - bool resolved_by_me_once = false, resolved_away = false; - while (r.Read()) + userix, rbugs_str))) { - int bug = r.GetInt32(0); - int ixperson = r.GetInt32(1); - int newval = wv.atoi(r.GetString(2)); + int bug = r[0]; + int ixperson = r[1]; + int newval = r[2]; if (last_bug != bug) { @@ -296,37 +285,35 @@ namespace Wv.Schedulator else if (resolved_by_me_once) rbugs.Add(last_bug, last_bug.ToString()); - log.log("{0} abugs, {1} vbugs, {2} rbugs and {3} sbugs.", + log.print("{0} abugs, {1} vbugs, {2} rbugs and {3} sbugs.", abugs.Count, vbugs.Count, rbugs.Count, sbugs.Count); - log.log("Reading bug details."); + log.print("Reading bug details."); ArrayList all_bugs = new ArrayList(); add_list(all_bugs, abugs.Values); add_list(all_bugs, vbugs.Values); add_list(all_bugs, rbugs.Values); add_list(all_bugs, sbugs.Values); string all_str = bug_str(all_bugs); - r = db.select(wv.fmt + foreach (var r in db.select(wv.fmt ("select id, summary, project_id, " + " fixed_in_version, version, " + " priority, last_updated " + "from mantis_bug_table " - + "where id in ({0})", all_str)); - while (r.Read()) + + "where id in ({0})", all_str))) { - int ix = r.GetInt32(0); + int ix = r[0]; string ixstr = ix.ToString(); - string title = r.IsDBNull(1) ? "--" : r.GetString(1); - int ixproject = r.GetInt32(2); + string title = r[1].IsNull ? "--" : r[1]; + int ixproject = r[2]; string ffname - = (r.IsDBNull(3) - ? (r.IsDBNull(4) ? "" : r.GetString(4)) - : r.GetString(3)); + = (r[3].IsNull + ? (r[4].IsNull ? "" : r[4]) + : r[3]); if (wv.isempty(ffname)) ffname = "-Undecided-"; - int pri = priority_map(r.GetInt32(5)); + int pri = priority_map(r[5]); string ixfixfor = ixproject.ToString() + "." + ffname; - DateTime resolvedate - = r.IsDBNull(6) ? DateTime.MinValue : r.GetDateTime(6); + DateTime resolvedate = r[6]; FixFor fixfor = (FixFor)mantisfixfors[ixfixfor]; diff --git a/person.cs b/person.cs index 16962e0..244fc25 100644 --- a/person.cs +++ b/person.cs @@ -1,6 +1,7 @@ using System; using System.Collections; -using Wv.Utils; +using Wv; +using Wv.Obsolete; namespace Wv.Schedulator { diff --git a/project.cs b/project.cs index b5ae6db..12559a8 100644 --- a/project.cs +++ b/project.cs @@ -1,6 +1,7 @@ using System; using System.Collections; -using Wv.Utils; +using Wv; +using Wv.Obsolete; namespace Wv.Schedulator { diff --git a/resultsource.cs b/resultsource.cs index 3339a72..97176d1 100644 --- a/resultsource.cs +++ b/resultsource.cs @@ -1,7 +1,6 @@ using System; using System.Data; -using Wv.Dbi; -using Wv.Utils; +using Wv; using Wv.Schedulator; namespace Wv.Schedulator @@ -9,8 +8,8 @@ namespace Wv.Schedulator public class ResultSource : Source { string user; // get the bugs for this username - Log log; - public Db db; + WvLog log; + public WvDbi db; public ResultSource(Schedulator s, string name, string odbcstring, string user) @@ -20,10 +19,10 @@ namespace Wv.Schedulator this.user = user; else this.user = s.name; - log = new Log(String.Format("Result:{0}", name)); - log.log("Initializing result plugin '{0}'.", name); - log.log("Connecting to: '{0}'", odbcstring); - db = new Db(odbcstring); + log = new WvLog(String.Format("Result:{0}", name)); + log.print("Initializing result plugin '{0}'.", name); + log.print("Connecting to: '{0}'", odbcstring); + db = new WvDbi(odbcstring); // db.try_execute("drop table Schedule"); db.try_execute("create table Schedule (" @@ -54,23 +53,23 @@ namespace Wv.Schedulator { db.execute("delete from Schedule where sUser=?", user); - IDbCommand cmd = db.prepare - ("insert into Schedule " + string q = + "insert into Schedule " + "(sUser,sProject,sFixFor,sTaskId,sTask," + " ixPriority,fDone,fHalfDone,fEstimated,dtStart,dtEnd) " - + "values (?,?,?,?,?,?,?,?,?,?,?) ", 11); + + "values (?,?,?,?,?,?,?,?,?,?,?) "; foreach (TimeSlot _ts in s.schedule) { if (_ts is TaskTimeSlot) { TaskTimeSlot ts = (TaskTimeSlot)_ts; - log.log("Adding {0} - {1}", ts.start, ts.end); + log.print("Adding {0} - {1}", ts.start, ts.end); FixFor ff = ts.task.fixfor; if (ff == null) ff = s.fixfors.Add(s.projects.Add("UNKNOWN"), "-Undecided-"); - db.execute(cmd, user, ff.project.name, ff.name, + db.execute(q, user, ff.project.name, ff.name, ts.task.moniker, ts.name, ts.task.priority, ts.done ? 1 : 0, ts.task.halfdone ? 1 : 0, diff --git a/schedulator.cs b/schedulator.cs index 173f35b..c7116fc 100644 --- a/schedulator.cs +++ b/schedulator.cs @@ -1,7 +1,6 @@ using System; using System.Collections; -using Wv.Utils; -using Wv.Web; +using Wv; namespace Wv.Schedulator { @@ -233,50 +232,50 @@ namespace Wv.Schedulator } } - public void dump(Log log) + public void dump(WvLog log) { - log.log("\nPERSONS"); + log.print("\nPERSONS"); foreach (Person p in persons) - log.log(" {0,-20} {1}", p.name, p.fullname); + log.print(" {0,-20} {1}", p.name, p.fullname); - log.log("\nPROJECTS"); + log.print("\nPROJECTS"); foreach (Project p in projects) - log.log(" '{0}'", p.name); + log.print(" '{0}'", p.name); - log.log("\nFIXFORS"); + log.print("\nFIXFORS"); foreach (FixFor f in fixfors) { - log.log("'{0}'.'{1}' has {2} release date(s). (final={3})", + log.print("'{0}'.'{1}' has {2} release date(s). (final={3})", f.project.name, f.name, f.releases.Count, FixFor.date_string(f.final_release)); foreach (DateTime d in f.releases) - log.log(" {0,-30} {1}", + log.print(" {0,-30} {1}", String.Format("'{0}'.'{1}'", f.project.name, f.name), FixFor.date_string(d)); } - log.log("\nTASKS"); + log.print("\nTASKS"); FixFor last_ff = null; bool was_done = true; foreach (Task t in tasks) { if (was_done && !t.done) { - log.log("END FINISHED TASKS --"); - log.log(""); + log.print("END FINISHED TASKS --"); + log.print(""); } else if (!was_done && last_ff != t.fixfor) { if (last_ff == null) - log.log("END UNDECIDED TASKS --"); + log.print("END UNDECIDED TASKS --"); else - log.log("END MILESTONE '{0}.{1}' --", + log.print("END MILESTONE '{0}.{1}' --", last_ff.project.name, last_ff.name); - log.log(""); + log.print(""); } - log.log(" {0} [P{1}/{8}] {2}:{3} '{4}' ({5}/{6}/{7})", + log.print(" {0} [P{1}/{8}] {2}:{3} '{4}' ({5}/{6}/{7})", t.done ? "X" : ".", t.priority, t.source.name, t.id, @@ -289,13 +288,13 @@ namespace Wv.Schedulator } if (last_ff != null) - log.log("END MILESTONE '{0}.{1}' --", + log.print("END MILESTONE '{0}.{1}' --", last_ff.project.name, last_ff.name); } - public void dump_schedule(Log log) + public void dump_schedule(WvLog log) { - log.log("\nSCHEDULE"); + log.print("\nSCHEDULE"); FixFor last_fixfor = null; foreach (TimeSlot _ts in schedule) @@ -303,7 +302,7 @@ namespace Wv.Schedulator if (_ts is CommentTimeSlot) { CommentTimeSlot ts = (CommentTimeSlot)_ts; - log.log("{0}", ts.name); + log.print("{0}", ts.name); } if (_ts is TaskTimeSlot) @@ -312,7 +311,7 @@ namespace Wv.Schedulator if (!ts.done && ts.fixfor != last_fixfor) { - log.log("Release {0}:{1}:", + log.print("Release {0}:{1}:", ts.fixfor.project.name, ts.fixfor.name); last_fixfor = ts.fixfor; } @@ -329,7 +328,7 @@ namespace Wv.Schedulator = (daypercent==0 ? "" : "." + daypercent.ToString("d2")); - log.log(" {0} {1}{2,3} {3,4} {4} ({5})", + log.print(" {0} {1}{2,3} {3,4} {4} ({5})", ts.done ? "X" : ".", FixFor.date_string(ts.end), dayadd, diff --git a/schedulator.t.cs b/schedulator.t.cs index 655ad4b..2a42570 100644 --- a/schedulator.t.cs +++ b/schedulator.t.cs @@ -1,23 +1,21 @@ #include "wvtest.cs.h" - using System; using System.IO; using System.Collections; -using NUnit.Framework; +using Wv; using Wv.Test; -using Wv.Utils; using Wv.Schedulator; [TestFixture] public class SchedTests { - Log log = new Log("Tests"); + WvLog log = new WvLog("Tests"); Schedulator s; SourceRegistry reg; [SetUp] public void Init() { - log.log("Creating schedulator."); + log.print("Creating schedulator."); reg = new SourceRegistry(); s = new Schedulator("test"); } @@ -382,4 +380,9 @@ public class SchedTests // not much of a test, but oh well, it proves *something* :) WVPASS(s.tasks.Count > 0); } + + public static void Main() + { + WvTest.DoMain(); + } } diff --git a/source.cs b/source.cs index fffc262..79332ef 100644 --- a/source.cs +++ b/source.cs @@ -1,7 +1,6 @@ using System; using System.Collections; -using Wv.Utils; -using Wv.Web; +using Wv; namespace Wv.Schedulator { @@ -69,7 +68,7 @@ namespace Wv.Schedulator public class SourceRegistry { - Log log = new Log("SourceRegistry"); + WvLog log = new WvLog("SourceRegistry"); Hashtable sources = new Hashtable(); public delegate Source Creator(Schedulator s, string name, @@ -91,7 +90,7 @@ namespace Wv.Schedulator public void register(string prefix, Creator create) { - log.log("registering {0}", prefix); + log.print("registering {0}", prefix); sources.Add(prefix, create); } @@ -102,7 +101,7 @@ namespace Wv.Schedulator string prefix = list[0]; string suffix = list.Length>1 ? list[1] : ""; - log.log("create: prefix='{0}', suffix='{1}'", prefix, suffix); + log.print("create: prefix='{0}', suffix='{1}'", prefix, suffix); if (!sources.Contains(prefix)) return null; diff --git a/stringsource.cs b/stringsource.cs index f241c34..ed35160 100644 --- a/stringsource.cs +++ b/stringsource.cs @@ -2,7 +2,7 @@ using System; using System.IO; using System.Collections; using System.Text.RegularExpressions; -using Wv.Utils; +using Wv; using Wv.Schedulator; namespace Wv.Schedulator @@ -10,12 +10,12 @@ namespace Wv.Schedulator public class StringSource : Source { protected string[] lines; - Log log; + WvLog log; public StringSource(Schedulator s, string name, string[] lines) : base(s, name) { - log = new Log(name); + log = new WvLog(name); this.lines = lines; // process "import" lines right away, to create additional @@ -27,7 +27,7 @@ namespace Wv.Schedulator if (cmd == "import" || cmd == "plugin") { - log.log("Creating plugin from line: '{0}'", line); + log.print("Creating plugin from line: '{0}'", line); if (args.Length < 2) err(0, "Not enough parameters to '{0}'", cmd); else @@ -116,7 +116,7 @@ namespace Wv.Schedulator void err(int lineno, string fmt, params object[] args) { - log.log(lineno.ToString() + ": " + fmt, args); + log.print(lineno.ToString() + ": " + fmt, args); } static string dequote(string s, string bra, string ket) @@ -417,7 +417,7 @@ namespace Wv.Schedulator d.done = true; d.habits = habits; - //log.log("Parent of '{0}' is '{1}'", + //log.print("Parent of '{0}' is '{1}'", // d.name, d.dtparent==null ? "(none)" : d.dtparent.name); parents.Add(d); @@ -470,7 +470,7 @@ namespace Wv.Schedulator if (args.Length > 1) last_fixfor.add_release(wv.date(args[1])); - log.log("New milestone: {0}", last_fixfor.name); + log.print("New milestone: {0}", last_fixfor.name); break; case "bounce": diff --git a/task.cs b/task.cs index 1f175bc..c15d3c8 100644 --- a/task.cs +++ b/task.cs @@ -1,6 +1,7 @@ using System; using System.Collections; -using Wv.Utils; +using Wv; +using Wv.Obsolete; namespace Wv.Schedulator { diff --git a/testsource.cs b/testsource.cs index ed1727d..7abe14d 100644 --- a/testsource.cs +++ b/testsource.cs @@ -1,5 +1,5 @@ using System; -using Wv.Utils; +using Wv; using Wv.Schedulator; namespace Wv.Schedulator diff --git a/versaplex b/versaplex new file mode 160000 index 0000000..55bde96 --- /dev/null +++ b/versaplex @@ -0,0 +1 @@ +Subproject commit 55bde9609e8238bfa70b042a71faa95cc90c253b diff --git a/webtest.cs b/webtest.cs index 2ab4108..4902efa 100644 --- a/webtest.cs +++ b/webtest.cs @@ -1,7 +1,7 @@ using System; using System.IO; using System.Collections; -using Wv.Utils; +using Wv; using Wv.Web; public class WebTest @@ -16,7 +16,7 @@ public class WebTest // g.use_tablesort() // incompatible with editinplace... ); - g.send(g.start_form(new Attr("action", "", + g.send(g.form_start(new Attr("action", "", "name", "sillyform", "method", "post"))); @@ -27,11 +27,11 @@ public class WebTest g.send(g.h1("Query variables:")); Cgi cgi = new Cgi(); - g.send(g.start_table()); + g.send(g.table_start()); g.send(g.tr(g.th("Key"), g.th("Value"))); foreach (string key in cgi.request.Keys) g.send(g.tr(g.td(key), g.td(g.pre(cgi.request[key])))); - g.send(g.end_table()); + g.send(g.table_end()); g.send(g.p(), g.editinplace("bigtext", "textarea", @@ -48,7 +48,7 @@ public class WebTest g.text("this is the content")), g.p()); - g.send(g.start_table(new Attr("id", "foo1", + g.send(g.table_start(new Attr("id", "foo1", "tablesort", "1", "border", "0")), g.tr(g.td("hello"), @@ -69,9 +69,9 @@ public class WebTest new Attr("autovalidate", "integer"), g.text("7")))), - g.end_table()); + g.table_end()); - g.send(g.start_ul(new Attr("id", "foo2", + g.send(g.ul_start(new Attr("id", "foo2", "tablesort", "1", "border", "1")), g.li(g.text("title"), @@ -87,18 +87,18 @@ public class WebTest g.li(g.ul(g.li("9"), g.li("8"), g.li("7 "))), - g.end_ul()); + g.ul_end()); g.send(g.h1("Environment variables:")); - g.send(g.start_table()); + g.send(g.table_start()); g.send(g.tr(g.th("Key"), g.th("Value"))); IDictionary env = Environment.GetEnvironmentVariables(); foreach (string key in env.Keys) g.send(g.tr(g.td(key), g.td((string)env[key]))); - g.send(g.end_table()); + g.send(g.table_end()); g.send(g.submit("Subm\"it!"), - g.end_form()); + g.form_end()); g.send(g.done()); } } diff --git a/webui.cs b/webui.cs index 35eb6b2..1a96d64 100644 --- a/webui.cs +++ b/webui.cs @@ -5,9 +5,9 @@ using System.Data; using System.Text; using System.Collections; using System.Diagnostics; -using Wv.Utils; -using Wv.Dbi; +using Wv; using Wv.Web; +using Wv.Obsolete; namespace Wv.Schedulator { @@ -191,7 +191,7 @@ namespace Wv.Schedulator } } - void append_file(string filename, string content) + void appfile_end(string filename, string content) { if (filename == null || content == null || content == "") return; @@ -260,7 +260,7 @@ namespace Wv.Schedulator } } if (schedname() != null) - append_file(schedfile() + ".log", appendwhat); + appfile_end(schedfile() + ".log", appendwhat); } void http_redirect(string url) @@ -286,74 +286,73 @@ namespace Wv.Schedulator void page_list_schedules() { g.send(g.title("Available Schedules - Schedulator")); - g.send(g.start_form(new Attr("action", base_url(), + g.send(g.form_start(new Attr("action", base_url(), "method", "GET"))); g.send(g.h1("Schedulator: Available Schedules")); - g.send(g.start_ul()); + g.send(g.ul_start()); foreach (string name in all_schedules()) g.send(g.li(g.ahref(person_url(name), name))); g.send(g.li(g.input("sid"), g.submit("Create New"))); - g.send(g.end_ul()); + g.send(g.ul_end()); - g.send(g.end_form()); + g.send(g.form_end()); - g.send(g.start_form(new Attr("action", base_url(), + g.send(g.form_start(new Attr("action", base_url(), "method", "POST"))); g.send(g.submit("Update All")); - g.send(g.end_form()); + g.send(g.form_end()); ResultSource results = find_result_source(); if (results != null) { - Db db = results.db; + WvDbi db = results.db; g.send(g.h1("Schedulator: Available Summaries")); - g.send(g.start_ul()); - IDataReader r = db.select + g.send(g.ul_start()); + string last_proj = ""; + foreach (var r in db.select ("select distinct sProject, sFixfor " + " from Schedule " + " where fDone=0 " - + " order by sProject, sFixFor "); - string last_proj = ""; - while (r.Read()) + + " order by sProject, sFixFor ")) { - string proj = r.GetString(0); - string fixfor = r.GetString(1); + string proj = r[0]; + string fixfor = r[1]; if (last_proj != proj) { if (last_proj != null) - g.send(g.end_li()); - g.send(g.start_li(), g.text(wv.fmt("{0}: ", proj))); + g.send(g.li_end()); + g.send(g.li_start(), g.text(wv.fmt("{0}: ", proj))); last_proj = proj; } else g.send(g.text(", ")); g.send(g.ahref(summary_url(proj, fixfor), fixfor)); } - g.send(g.end_ul()); + g.send(g.ul_end()); } } void page_update_all() { g.send(g.title("Update All - Schedulator")); - g.send(g.start_form(new Attr("action", base_url(), + g.send(g.form_start(new Attr("action", base_url(), "method", "GET"))); g.send(g.h1("Schedulator: Updating All Schedules")); - g.send(g.start_ul()); + g.send(g.ul_start()); foreach (string name in all_schedules()) { g.send(g.li(g.text(name))); Schedulator s = new_web_schedulator(name); s.run(); } - g.send(g.end_ul()); + g.send(g.ul_end()); g.send(g.h2("Done.")); g.send(g.ahref(base_url(), "< 0) - { - StringDictionary sect = settings[odbcstr]; - - string s = wv.fmt("driver={0};server={1};database={2};" - + "uid={3};pwd={4};", - sect["driver"], sect["server"], - sect["database"], - sect["user"], sect["password"]); - real = s; - } - else if (String.Compare(odbcstr, 0, "dsn=", 0, 4, true) == 0) - real = odbcstr; - else if (String.Compare(odbcstr, 0, "driver=", 0, 7, true) == 0) - real = odbcstr; - else - throw new ArgumentException - ("unrecognized odbc string '" + odbcstr + "'"); - db = new OdbcConnection(real); - db.Open(); - } - - public IDbCommand prepare(string sql, int nparams) - { - IDbCommand cmd = db.CreateCommand(); - cmd.CommandText = sql; - for (int i = 0; i < nparams; i++) - cmd.Parameters.Add(cmd.CreateParameter()); - cmd.Prepare(); - return cmd; - } - - void bind(IDbCommand cmd, params object[] args) - { - int i = 0; - foreach (IDataParameter param in cmd.Parameters) - { - object o = args[i++]; - if (o is DateTime) - param.DbType = DbType.DateTime; - else - param.DbType = DbType.String; // I sure hope so... - param.Value = o; - } - } - - public IDataReader select(string sql, params object[] args) - { - return select(prepare(sql, args.Length), args); - } - - public IDataReader select(IDbCommand cmd, params object[] args) - { - bind(cmd, args); - return cmd.ExecuteReader(); - } - - public int execute(string sql, params object[] args) - { - return execute(prepare(sql, args.Length), args); - } - - public int execute(IDbCommand cmd, params object[] args) - { - bind(cmd, args); - return cmd.ExecuteNonQuery(); - } - - public int try_execute(string sql, params object[] args) - { - try - { - return execute(sql, args); - } - catch (OdbcException) - { - // well, I guess no rows were affected... - return 0; - } - } - } -} - diff --git a/wvdotnet b/wvdotnet new file mode 120000 index 0000000..95b22cd --- /dev/null +++ b/wvdotnet @@ -0,0 +1 @@ +versaplex/wvdotnet \ No newline at end of file diff --git a/wvini.cs b/wvini.cs deleted file mode 100644 index 7b44a67..0000000 --- a/wvini.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.IO; -using System.Collections; -using System.Collections.Specialized; - -namespace Wv.Utils -{ - /// Well, it's not exactly UniConf, but... - public class Ini - { - Hashtable sections - = new Hashtable(10, new CaseInsensitiveHashCodeProvider(), - new CaseInsensitiveComparer()); - - public Ini(string filename) - { - StreamReader r; - - try - { - r = File.OpenText(filename); - } - catch (IOException) - { - return; // I guess there's no file! - } - - string section = ""; - string s; - while ((s = r.ReadLine()) != null) - { - s = s.Trim(); - if (s.Length == 0) continue; // blank line - if (s[0] == '#') continue; // comment - if (s[0] == '[' && s[s.Length-1]==']') // section - { - section = s.Substring(1, s.Length-2); - } - else if (s.IndexOf('=') >= 0) - { - string[] a = s.Split(new char[] {'='}, 2); - this[section][a[0].Trim()] = a[1].Trim(); - } - else - continue; // whatever - } - } - - public StringDictionary this[string sectname] - { - get - { - if (!sections.Contains(sectname)) - sections.Add(sectname, new StringDictionary()); - return (StringDictionary)sections[sectname]; - } - } - } -} diff --git a/wvtest.cs b/wvtest.cs deleted file mode 100644 index 4e369b2..0000000 --- a/wvtest.cs +++ /dev/null @@ -1,123 +0,0 @@ -using System; -using NUnit.Framework; - -namespace Wv.Test -{ - public class WvTest - { - public static bool booleanize(long x) - { - return x != 0; - } - - public static bool booleanize(string s) - { - return s != null && s != ""; - } - - public static bool booleanize(object o) - { - return o != null; - } - - public static bool test(bool cond, string file, int line, string s) - { - System.Console.Out.WriteLine("! {0}:{1,-5} {2,-40} {3}", - file, line, s, - cond ? "ok" : "FAIL"); - System.Console.Out.Flush(); - Assert.IsTrue(cond, String.Format("{0}:{1} {2}", file, line, s)); - return cond; - } - - public static bool test_eq(long cond1, long cond2, - string file, int line, - string s1, string s2) - { - return test(cond1 == cond2, file, line, - String.Format("[{0}] == [{1}] ({{{2}}} == {{{3}}})", - cond1, cond2, s1, s2)); - } - - public static bool test_eq(double cond1, double cond2, - string file, int line, - string s1, string s2) - { - return test(cond1 == cond2, file, line, - String.Format("[{0}] == [{1}] ({{{2}}} == {{{3}}})", - cond1, cond2, s1, s2)); - } - - public static bool test_eq(string cond1, string cond2, - string file, int line, - string s1, string s2) - { - return test(cond1 == cond2, file, line, - String.Format("[{0}] == [{1}] ({{{2}}} == {{{3}}})", - cond1, cond2, s1, s2)); - } - - // some objects can compare themselves to 'null', which is helpful. - // for example, DateTime.MinValue == null, but only through - // IComparable, not through IObject. - public static bool test_eq(IComparable cond1, IComparable cond2, - string file, int line, - string s1, string s2) - { - return test(cond1.CompareTo(cond2) == 0, file, line, - String.Format("[{0}] == [{1}]", s1, s2)); - } - - public static bool test_eq(object cond1, object cond2, - string file, int line, - string s1, string s2) - { - return test(cond1 == cond2, file, line, - String.Format("[{0}] == [{1}]", s1, s2)); - } - - public static bool test_ne(long cond1, long cond2, - string file, int line, - string s1, string s2) - { - return test(cond1 != cond2, file, line, - String.Format("[{0}] != [{1}] ({{{2}}} != {{{3}}})", - cond1, cond2, s1, s2)); - } - - public static bool test_ne(double cond1, double cond2, - string file, int line, - string s1, string s2) - { - return test(cond1 != cond2, file, line, - String.Format("[{0}] != [{1}] ({{{2}}} != {{{3}}})", - cond1, cond2, s1, s2)); - } - - public static bool test_ne(string cond1, string cond2, - string file, int line, - string s1, string s2) - { - return test(cond1 != cond2, file, line, - String.Format("[{0}] != [{1}] ({{{2}}} != {{{3}}})", - cond1, cond2, s1, s2)); - } - - // See notes for test_eq(IComparable,IComparable) - public static bool test_ne(IComparable cond1, IComparable cond2, - string file, int line, - string s1, string s2) - { - return test(cond1.CompareTo(cond2) != 0, file, line, - String.Format("[{0}] != [{1}]", s1, s2)); - } - - public static bool test_ne(object cond1, object cond2, - string file, int line, - string s1, string s2) - { - return test(cond1 != cond2, file, line, - String.Format("[{0}] != [{1}]", s1, s2)); - } - } -} diff --git a/wvtest.cs.h b/wvtest.cs.h deleted file mode 100644 index 372cbe8..0000000 --- a/wvtest.cs.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __WVTEST_CS_H // Blank lines in this file mess up line numbering! -#define __WVTEST_CS_H -#define WVASSERT(x) WvTest.test(WvTest.booleanize(x), __FILE__, __LINE__, #x) -#define WVPASS(x) WVASSERT(x) -#define WVFAIL(x) WvTest.test(!WvTest.booleanize(x), __FILE__, __LINE__, "NOT(" + #x + ")") -#define WVPASSEQ(x, y) WvTest.test_eq((x), (y), __FILE__, __LINE__, #x, #y) -#define WVPASSNE(x, y) WvTest.test_ne((x), (y), __FILE__, __LINE__, #x, #y) -#endif // __WVTEST_CS_H diff --git a/wvtest.t.cs b/wvtest.t.cs deleted file mode 100644 index 371da80..0000000 --- a/wvtest.t.cs +++ /dev/null @@ -1,58 +0,0 @@ -#include "wvtest.cs.h" - -using System; -using NUnit.Framework; -using Wv.Test; - -[TestFixture] -public class WvTestTest -{ - [Test] public void test_wvtest() - { - WVPASS(1); - WVPASS("hello"); - WVPASS(new Object()); - WVPASS(0 != 1); - - WVFAIL(0); - WVFAIL(""); - WVFAIL(null); - - WVPASSEQ(7, 7); - WVPASSEQ("foo", "foo"); - WVPASSEQ("", ""); - Object obj = new Object(); - WVPASSEQ(obj, obj); - WVPASSEQ(null, null); - - WVPASSNE(7, 8); - WVPASSNE("foo", "blue"); - WVPASSNE("", "notempty"); - WVPASSNE(null, ""); - WVPASSNE(obj, null); - WVPASSNE(obj, new Object()); - WVPASSNE(new Object(), new Object()); - } - - // these are only public to get rid of the "not assigned to" warnings. - // we don't assign to them because that's the whole point of the test. - public DateTime null_date; - public TimeSpan null_span; - - [Test] public void test_dates_and_spans() - { - WVPASS(null_date == DateTime.MinValue); - WVPASSEQ(null_date, DateTime.MinValue); - WVPASS(null_span == TimeSpan.Zero); - WVPASSEQ(null_span, TimeSpan.Zero); - - TimeSpan t = TimeSpan.FromMinutes(60*24*7); - WVPASSEQ(t.ToString(), "7.00:00:00"); - WVPASSEQ(t.Ticks, 7*24*60*60*10000000L); - WVPASS(t.TotalMinutes == 7*24*60); - WVPASSEQ(t.TotalMinutes, 7*24*60); - WVPASSEQ(t.TotalSeconds, 7*24*60*60); - WVPASSEQ(t.Minutes, 0); - } - -} diff --git a/wvutils.cs b/wvutils.cs deleted file mode 100644 index d5fcace..0000000 --- a/wvutils.cs +++ /dev/null @@ -1,284 +0,0 @@ -#define DEBUG -#define TRACE - -using System; -using System.Collections; -using System.Diagnostics; - -namespace Wv.Utils -{ - public class wv - { - public static string shift(ref string[] array, int index) - { - string s = array[index]; - string[] outa = new string[array.Length-1]; - Array.Copy(array, 0, outa, 0, index); - Array.Copy(array, index+1, outa, index, array.Length-index-1); - array = outa; - return s; - } - - public static string shift(ref string[] array) - { - return shift(ref array, 0); - } - - public static void assert(bool b) - { - if (!b) - throw new System.ArgumentException("assertion failure"); - } - - public static void assert() - { - assert(false); - } - - public static DateTime date(string s) - { - try - { - return DateTime.Parse(s); - } - catch (FormatException) - { - return DateTime.MinValue; - } - } - - public static double atod(string s) - { - try - { - return Double.Parse(s); - } - catch (FormatException) - { - return 0.0; - } - } - - public static int atoi(string s) - { - try - { - return Int32.Parse(s); - } - catch (FormatException) - { - return 0; - } - } - - public static long atol(string s) - { - try - { - return Int64.Parse(s); - } - catch (FormatException) - { - return 0; - } - } - - public static bool isempty(string s) - { - return s == null || s == ""; - } - - public static bool isempty(DateTime d) - { - return d == DateTime.MinValue; - } - - public static bool isempty(TimeSpan t) - { - return t == TimeSpan.Zero; - } - - public static string fmt(string format, params object[] args) - { - return String.Format(format, args); - } - - public static Array sort(ICollection keys, IComparer comparer) - { - object[] sorted = new object[keys.Count]; - keys.CopyTo(sorted, 0); - Array.Sort(sorted, comparer); - return sorted; - } - - public static Array sort(ICollection keys) - { - return sort(keys, Comparer.Default); - } - - public static string[] stringify(ICollection keys) - { - string[] a = new string[keys.Count]; - int i = 0; - foreach (object o in keys) - a[i++] = o.ToString(); - return a; - } - } - - public class Log - { - protected string logname; - - static int refs = 0; - static TraceListener mytrace = null; - static bool disable_mytrace = false; - - public Log(string logname) - { - refs++; - if (mytrace == null && !disable_mytrace - && Trace.Listeners.Count < 2) - { - mytrace = new TextWriterTraceListener(Console.Error); - Trace.Listeners.Add(mytrace); - } - - //Trace.WriteLine(String.Format("Log constructor for '{0}'.", - // logname)); - Trace.Flush(); - this.logname = logname; - } - - ~Log() - { - refs--; - if (refs == 0) - { - if (mytrace != null) - Trace.Listeners.Remove(mytrace); - mytrace = null; - } - } - - public static void no_default_listener() - { - disable_mytrace = true; - if (mytrace != null) - { - Trace.Listeners.Remove(mytrace); - mytrace = null; - } - } - - public virtual void log(string format, params object [] arg) - { - // Console.Error.WriteLine("<" + logname + "> " + format, arg); - Trace.WriteLine(String.Format - ("[" + logname + "] " + format, arg)); - Trace.Flush(); - } - - public void log(string s) - { - log("{0}", s); - } - } - - public class SilentLog : Log - { - public SilentLog(string logname) : base(logname) - { - } - - public override void log(string format, params object [] arg) - { - } - } - - // This is intended to work sort of like PHP arrays, which are a mix of - // hash tables and lists. Looking up an entry in the hash is O(1), but - // when you iterate through all the entries, the ordering is well-defined. - // - // So far, this implementation is pretty limited and lacks a bunch of the - // things PHP can do, such as assigning to a particular array index. - public class SortedHash : IEnumerable - { - ArrayList array = new ArrayList(); - Hashtable hash = new Hashtable(); - - public IEnumerator GetEnumerator() - { - return array.GetEnumerator(); - } - - public void Add(string key, object value) - { - array.Add(value); - if (!hash.Contains(key)) - hash.Add(key, value); - } - - public int Count - { - get { return hash.Count; } - } - - public bool Contains(object key) - { - return hash.Contains(key); - } - - public object Find(string key) - { - return hash[key]; - } - - public virtual object this[int index] - { - get { return array[index]; } - } - - public virtual void Sort() - { - array.Sort(); - } - - public virtual void Sort(IComparer comparer) - { - array.Sort(comparer); - } - - public void Clear() - { - array.Clear(); - hash.Clear(); - } - - public static explicit operator ArrayList(SortedHash x) - { - return ArrayList.ReadOnly(x.array); - } - } - - public class ObjectCounter : Hashtable - { - public new virtual int this [object key] - { - get - { - if (!Contains(key)) - Add(key, 0); - return (int)base[key]; - } - - set - { - if (Contains(key)) - Remove(key); - Add(key, (int)value); - } - } - } -} - diff --git a/wvutils.t.cs b/wvutils.t.cs deleted file mode 100644 index f3eb0b1..0000000 --- a/wvutils.t.cs +++ /dev/null @@ -1,36 +0,0 @@ -#include "wvtest.cs.h" - -using System; -using System.Collections; -using NUnit.Framework; -using Wv.Test; -using Wv.Utils; - -[TestFixture] -public class WvTests -{ - [Test] [Category("shift")] public void shift_test() - { - string[] x = {"a", null, "c", "", "e", "f"}; - - WVPASSEQ(wv.shift(ref x, 0), "a"); - WVPASSEQ(wv.shift(ref x, 0), null); - WVPASSEQ(wv.shift(ref x, 1), ""); - WVPASSEQ(wv.shift(ref x, 2), "f"); - WVPASSEQ(x.Length, 2); - WVPASSEQ(wv.shift(ref x, 0), "c"); - WVPASSEQ(wv.shift(ref x, 0), "e"); - WVPASSEQ(x.Length, 0); - } - - [Test] [Category("ini")] public void ini_test() - { - Ini ini = new Ini("test.ini"); - WVPASSEQ(ini[""].Count, 2); - WVPASSEQ(ini[""]["global item"], "i"); - WVPASSEQ(ini[""]["global 2"], "i2"); - WVPASSEQ(ini["subsEction"].Count, 3); - WVPASSEQ(ini["subseCtion"]["2"], "3"); - WVPASSEQ(ini["nonexistent"].Count, 0); - } -} diff --git a/wvweb.cs b/wvweb.cs deleted file mode 100644 index b0a9a1c..0000000 --- a/wvweb.cs +++ /dev/null @@ -1,645 +0,0 @@ -using System; -using System.IO; -using System.Collections; -using System.Collections.Specialized; -using System.Web; -using Wv.Utils; - -namespace Wv.Web -{ - public class Cgi - { - public NameValueCollection cgivars = new NameValueCollection(); - public NameValueCollection request = new NameValueCollection(); - - public string query_string - { - get { return cgivars["QUERY_STRING"]; } - } - - public string script_name - { - get { return cgivars["SCRIPT_NAME"]; } - } - - public enum Method { Unknown, Get, Post }; - public Method method - { - get - { - switch (cgivars["REQUEST_METHOD"]) - { - case "GET": return Method.Get; - case "POST": return Method.Post; - default: return Method.Unknown; - } - } - } - - public Cgi() - { - string[] wanted = { - "REQUEST_URI", - "SCRIPT_NAME", - "QUERY_STRING", - "HTTP_HOST", - - "REQUEST_METHOD", - "CONTENT_LENGTH", - - "SCRIPT_FILENAME", - "DOCUMENT_ROOT", - - "HTTP_USER_AGENT", - "HTTP_REFERER", - "HTTP_CACHE_CONTROL", - "HTTP_CONNECTION", - "HTTP_ACCEPT", - "HTTP_ACCEPT_LANGUAGE", - "HTTP_ACCEPT_ENCODING", - "HTTP_ACCEPT_CHARSET", - - "REMOTE_ADDR", - "REMOTE_PORT", - - "SERVER_NAME", - "SERVER_ADDR", - "SERVER_PORT", - "SERVER_SOFTWARE", - "SERVER_PROTOCOL", - "GATEWAY_INTERFACE", - "SERVER_ADMIN", - }; - - IDictionary env = Environment.GetEnvironmentVariables(); - foreach (string key in wanted) - { - if (env.Contains(key)) - cgivars.Add(key, (string)env[key]); - else - cgivars.Add(key, ""); - } - - // GET variables - split_settings(query_string); - - // POST variables - if (cgivars["REQUEST_METHOD"] == "POST") - { -#if false - string postdata = Console.In.ReadToEnd(); -#else - string postdata = ""; - string line; - while ((line = Console.In.ReadLine()) != null) - postdata += line; -#endif - split_settings(postdata); - } - } - - void split_settings(string query) - { - if (query == "") return; - - string[] settings = query.Split("&".ToCharArray()); - foreach (string setting in settings) - { - string[] a = setting.Split("=".ToCharArray(), 2); - //Console.Write("queryk:" + a[0] + "\n"); - string key = HttpUtility.UrlDecode(a[0]); - //Console.Write("queryv:" + a[1] + "\n"); - string value - = a.Length > 1 ? HttpUtility.UrlDecode(a[1]) : "1"; - request.Add(key, value); - } - } - } - - - public enum Context { Headers, Head, Body, Done }; - - public class Html - { - public Context context; - string s; - - public Html(Context context, string s) - { - this.context = context; - this.s = s; - } - - public Html(Context context, params object[] ha) - { - this.context = context; - this.s = merge(context, ha); - } - - string merge(Context context, object[] ha) - { - string s = ""; - - foreach (object o in ha) - { - if (o is object[]) - s += merge(context, (object[])o); - else - { - Html h = (Html)o; - wv.assert(h.context == context); - s += h.ToString(); - } - } - return s; - } - - public override string ToString() - { - return s; - } - } - - public class Attr - { - string s = ""; - - public Attr(params object[] sa) - { - wv.assert((sa.Length % 2) == 0); - - for (int i = 0; i < sa.Length; i += 2) - s += String.Format(" {0}=\"{1}\"", - HttpUtility.HtmlAttributeEncode(sa[i].ToString()), - HttpUtility.HtmlAttributeEncode(sa[i+1].ToString())); - } - - public override string ToString() - { - return s; - } - - public static Attr none = new Attr(); - } - - public class HtmlGen - { - TextWriter stream = Console.Out; - - Context context = Context.Headers; - NameValueCollection headers = new NameValueCollection(); - - public HtmlGen() - { - header("Content-Type", "text/html"); - } - - ~HtmlGen() - { - done(); - } - - public void header(string key, string value) - { - wv.assert(context <= Context.Headers); - headers.Add(key, value); - } - - void go(Context newcontext) - { - wv.assert(newcontext >= context); - while (context < newcontext) - { - context++; - switch (context) - { - case Context.Headers: - wv.assert(); // it was the first one! - break; - - case Context.Head: - foreach (string k in headers.Keys) - _send(fmt("{0}: {1}\n", k, headers[k])); - _send("\n"); - _send(""); - break; - - case Context.Body: - _send("\n"); - break; - - case Context.Done: - _send("\n\n"); - break; - } - } - } - - public Html done() - { - return new Html(Context.Done, ""); - } - - public void _send(string s) - { - stream.Write(s); - } - - public void send(params Html[] ha) - { - foreach (Html h in ha) - { - go(h.context); - _send(h.ToString()); - } - } - - public Html[] htmlarray(ICollection keys) - { - Html[] a = new Html[keys.Count]; - int i = 0; - foreach (object o in keys) - a[i++] = (Html)o; - return a; - } - - public string fmt(string fmt, params object[] args) - { - return String.Format(fmt, args); - } - - Html head_v(string s) - { - return new Html(Context.Head, s); - } - - Html head_v(params object[] ha) - { - return new Html(Context.Head, ha); - } - - Html head_vfmt(string format, params object[] args) - { - return head_v(fmt(format, args)); - } - - Html v(string s) - { - return new Html(Context.Body, s); - } - - public Html v(params object[] ha) - { - return new Html(Context.Body, ha); - } - - Html vfmt(string format, params object[] args) - { - return v(fmt(format, args)); - } - - public Html head_text(string s) - { - return head_v(HttpUtility.HtmlEncode(s)); - } - - public Html text(string fmt, params object[] args) - { - return v(HttpUtility.HtmlEncode(String.Format(fmt, args))); - } - - public Html text(string s) - { - return v(HttpUtility.HtmlEncode(s)); - } - - public Html pre(string s) - { - return vfmt("
{0}
", text(s)); - } - - public Html title(string s) - { - return head_vfmt("{0}", head_text(s)); - } - - public Html include_js(string name) - { - return head_vfmt("", - new Attr("src", name, - "type", "text/javascript")); - } - - public Html include_css(string name) - { - return head_vfmt("", - new Attr("rel", "stylesheet", - "href", name, - "type", "text/css")); - } - - public Html use_tablesort() - { - return head_v(include_js("mesh/shared.js"), - include_css("mesh/tablesort/tablesort.css"), - include_js("mesh/tablesort/tablesort.js")); - } - - public Html use_editinplace() - { - return head_v(include_js("mesh/shared.js"), - include_js("config.js"), - - include_css("mesh/tooltip/tooltip.css"), - include_js("mesh/tooltip/tooltip.js"), - - include_css("mesh/editinplace/editinplace.css"), - include_js("mesh/editinplace/editinplace.js"), - - include_css("mesh/autovalidate/autovalidate.css"), - include_js("mesh/autovalidate/autovalidate.js"), - - include_css("mesh/powersearch/powersearch.css"), - include_js("mesh/powersearch/powersearch.js") - ); - } - - public Html h1(string s) - { - return vfmt("

{0}

\n", text(s)); - } - - public Html h2(string s) - { - return vfmt("

{0}

\n", text(s)); - } - - public Html h3(string s) - { - return vfmt("

{0}

\n", text(s)); - } - - public Html start_ul(Attr at) - { - return vfmt("", at); - } - - public Html start_ul() - { - return start_ul(Attr.none); - } - - public Html end_ul() - { - return v(""); - } - - public Html ul(params Html[] ha) - { - return v(start_ul(), ha, end_ul()); - } - - public Html start_li() - { - return v("
  • "); - } - - public Html end_li() - { - return v("
  • \n"); - } - - public Html li(params Html[] ha) - { - return v(start_li(), - ha, - end_li()); - } - - public Html li(string s) - { - return li(text(s)); - } - - public Html start_table(Attr at) - { - return vfmt("", at); - } - - public Html start_table() - { - return start_table(Attr.none); - } - - public Html end_table() - { - return v(""); - } - - public Html table(params Html[] ha) - { - return v(start_table(), - ha, - end_table()); - } - - public Html tr(Attr at, params Html[] ha) - { - return new Html(Context.Body, - start_tr(at), - ha, - end_tr()); - } - - public Html tr(params Html[] ha) - { - return tr(Attr.none, ha); - } - - public Html start_tr(Attr at) - { - return new Html(Context.Body, vfmt("", at)); - } - - public Html start_tr() - { - return start_tr(Attr.none); - } - - public Html end_tr() - { - return new Html(Context.Body, vfmt("\n")); - } - - public Html td(Attr at, string s) - { - return td(at, text(s)); - } - - public Html td(string s) - { - return td(Attr.none, s); - } - - public Html td(Attr at, params Html[] ha) - { - return v(start_td(at), - ha, - end_td()); - } - - public Html td(params Html[] ha) - { - return td(Attr.none, ha); - } - - public Html start_td(Attr at) - { - return vfmt("", at); - } - - public Html start_td() - { - return start_td(Attr.none); - } - - public Html end_td() - { - return v(""); - } - - public Html th(Attr at, string s) - { - return vfmt("{1}", at, text(s)); - } - - public Html th(string s) - { - return th(Attr.none, s); - } - - public Html th(Attr at, params Html[] ha) - { - return v(vfmt("", at), ha, v("")); - } - - public Html th(params Html[] ha) - { - return th(Attr.none, ha); - } - - public Html start_form(Attr at, params Html[] ha) - { - return vfmt("", at); - } - - public Html start_form(params Html[] ha) - { - return start_form(Attr.none, ha); - } - - public Html end_form() - { - return v(""); - } - - public Html submit(string id) - { - return vfmt("", - new Attr("id", id, - "name", id, - "value", id)); - } - - public Html input(string id) - { - return vfmt("", new Attr("name", id)); - } - - public Html editinplace(string id, string type, - Attr at, params Html[] ha) - { - if (type == "textarea") - { - return v(vfmt("", - new Attr("name", id, - "editinplace", "textarea"), - at), - ha, - v("")); - } - else - { - return v(vfmt("", - new Attr("id", id, - "editinplace", type), - at), - ha, - v("")); - } - } - - public Html a(Attr at, params Html[] ha) - { - return v(vfmt("", at), - ha, - v("")); - } - - public Html ahref(Attr at, string url, params Html[] ha) - { - return v(vfmt("", new Attr("href", url), at), - ha, - v("")); - } - - public Html ahref(string url, params Html[] ha) - { - return ahref(Attr.none, url, ha); - } - - public Html ahref(string url, string s) - { - return ahref(Attr.none, url, text(s)); - } - - public Html span(Attr at, params Html[] ha) - { - return v(vfmt("", at), - ha, - v("")); - } - - public Html p(Attr at, params Html[] ha) - { - return v(vfmt("", at), - ha, - v("

    ")); - } - - public Html p(string s) - { - return p(Attr.none, text(s)); - } - - public Html p() - { - return p(Attr.none); - } - - public Html sup(string s) - { - return vfmt("{0}", text(s)); - } - - public Html nbsp() - { - return v(" "); - } - - public Html img(string src) - { - return vfmt("", new Attr("src", src)); - } - } -} -- 2.11.4.GIT