tasque r202 - in branches/new_cache: . src
- From: bgmerrell svn gnome org
- To: svn-commits-list gnome org
- Subject: tasque r202 - in branches/new_cache: . src
- Date: Wed, 31 Dec 2008 23:37:20 +0000 (UTC)
Author: bgmerrell
Date: Wed Dec 31 23:37:20 2008
New Revision: 202
URL: http://svn.gnome.org/viewvc/tasque?rev=202&view=rev
Log:
* src/SyncManager.cs: Add external tasks to the local database, and only do so if the task hasn't
been previously added (this is done by checking the local database for a task with the external
tasks externalID).
* src/Task.cs: Add constructor for an external task. We're not yet handling the category
correctly.
* src/Database.cs: Add boolean method to determine if an external task id already exists in the
local database. Also hastily fixed some indentation.
Modified:
branches/new_cache/ChangeLog
branches/new_cache/src/Database.cs
branches/new_cache/src/SyncManager.cs
branches/new_cache/src/Task.cs
Modified: branches/new_cache/src/Database.cs
==============================================================================
--- branches/new_cache/src/Database.cs (original)
+++ branches/new_cache/src/Database.cs Wed Dec 31 23:37:20 2008
@@ -83,99 +83,106 @@
public object ExecuteScalar(string command)
- {
- object resultset;
-
- SqliteCommand cmd = connection.CreateCommand();
- cmd.CommandText = command;
- resultset = cmd.ExecuteScalar();
- return resultset;
- }
-
- public int ExecuteNonQuery(string command)
- {
- int resultCode;
- SqliteCommand cmd = connection.CreateCommand();
- cmd.CommandText = command;
- resultCode = cmd.ExecuteNonQuery();
- cmd.Dispose();
- return resultCode;
- }
-
- public string GetSingleString(string command)
- {
- string readString = String.Empty;
- try {
- SqliteCommand cmd = connection.CreateCommand();
- cmd.CommandText = command;
- SqliteDataReader dataReader = cmd.ExecuteReader();
- if(dataReader.Read())
- readString = dataReader.GetString(0);
- else
- readString = string.Empty;
- dataReader.Close();
- cmd.Dispose();
- } catch (Exception e) {
- Logger.Debug("Exception Thrown {0}", e);
- }
- return readString;
- }
-
- public DateTime GetDateTime(string command)
- {
- long longValue;
- DateTime dtValue;
- try{
- longValue = GetSingleLong(command);
- if(longValue == 0)
- dtValue = DateTime.MinValue;
- else
- dtValue = Database.ToDateTime(longValue);
- } catch (Exception e) {
- Logger.Debug("Exception Thrown {0}", e);
- dtValue = DateTime.MinValue;
- }
- return dtValue;
- }
-
- public int GetSingleInt(string command)
- {
- int dtVal = 0;
- try {
- SqliteCommand cmd = connection.CreateCommand();
- cmd.CommandText = command;
- SqliteDataReader dataReader = cmd.ExecuteReader();
- if(dataReader.Read())
- dtVal = dataReader.GetInt32(0);
- else
- dtVal = 0;
- dataReader.Close();
- cmd.Dispose();
- } catch (Exception e) {
- Logger.Debug("Exception Thrown {0}", e);
- }
- return dtVal;
- }
-
- public long GetSingleLong(string command)
- {
- long dtVal = 0;
- try {
- SqliteCommand cmd = connection.CreateCommand();
- cmd.CommandText = command;
- SqliteDataReader dataReader = cmd.ExecuteReader();
- if(dataReader.Read())
- dtVal = dataReader.GetInt64(0);
- else
- dtVal = 0;
- dataReader.Close();
- cmd.Dispose();
- } catch (Exception e) {
- Logger.Debug("Exception Thrown {0}", e);
- }
- return dtVal;
- }
+ {
+ object resultset;
+
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ resultset = cmd.ExecuteScalar();
+ return resultset;
+ }
+
+ public int ExecuteNonQuery(string command)
+ {
+ int resultCode;
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ resultCode = cmd.ExecuteNonQuery();
+ cmd.Dispose();
+ return resultCode;
+ }
+
+ public string GetSingleString(string command)
+ {
+ string readString = String.Empty;
+ try {
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ SqliteDataReader dataReader = cmd.ExecuteReader();
+ if(dataReader.Read())
+ readString = dataReader.GetString(0);
+ else
+ readString = string.Empty;
+ dataReader.Close();
+ cmd.Dispose();
+ } catch (Exception e) {
+ Logger.Debug("Exception Thrown {0}", e);
+ }
+ return readString;
+ }
+
+ public DateTime GetDateTime(string command)
+ {
+ long longValue;
+ DateTime dtValue;
+ try{
+ longValue = GetSingleLong(command);
+ if(longValue == 0)
+ dtValue = DateTime.MinValue;
+ else
+ dtValue = Database.ToDateTime(longValue);
+ } catch (Exception e) {
+ Logger.Debug("Exception Thrown {0}", e);
+ dtValue = DateTime.MinValue;
+ }
+ return dtValue;
+ }
+
+ public int GetSingleInt(string command)
+ {
+ int dtVal = 0;
+ try {
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ SqliteDataReader dataReader = cmd.ExecuteReader();
+ if(dataReader.Read())
+ dtVal = dataReader.GetInt32(0);
+ else
+ dtVal = 0;
+ dataReader.Close();
+ cmd.Dispose();
+ } catch (Exception e) {
+ Logger.Debug("Exception Thrown {0}", e);
+ }
+ return dtVal;
+ }
+ public long GetSingleLong(string command)
+ {
+ long dtVal = 0;
+ try {
+ SqliteCommand cmd = connection.CreateCommand();
+ cmd.CommandText = command;
+ SqliteDataReader dataReader = cmd.ExecuteReader();
+ if(dataReader.Read())
+ dtVal = dataReader.GetInt64(0);
+ else
+ dtVal = 0;
+ dataReader.Close();
+ cmd.Dispose();
+ } catch (Exception e) {
+ Logger.Debug("Exception Thrown {0}", e);
+ }
+ return dtVal;
+ }
+
+ public bool ExternalTaskExists(string externalID)
+ {
+ return Convert.ToInt32(ExecuteScalar(String.Format(@"
+ SELECT COUNT (*)
+ FROM Tasks
+ WHERE ExternalID='{0}'", externalID))) > 0;
+ }
public bool TableExists(string table)
{
Modified: branches/new_cache/src/SyncManager.cs
==============================================================================
--- branches/new_cache/src/SyncManager.cs (original)
+++ branches/new_cache/src/SyncManager.cs Wed Dec 31 23:37:20 2008
@@ -81,13 +81,32 @@
Logger.Debug("Populating local cache with tasks.");
foreach(ITask task in tasks.Values)
{
- Logger.Debug("Task: {0}", task.Name);
+ CreateLocalTask(task);
}
}
Logger.Debug("SyncThreadLoop done!");
}
}
-
+
+ private void CreateLocalTask(ITask task)
+ {
+ Logger.Debug("Creating Local Task:");
+ Logger.Debug("Name: {0}", task.Name);
+ Logger.Debug("DueDate: {0}", task.DueDate);
+ Logger.Debug("CompletionDate: {0}", task.CompletionDate);
+ Logger.Debug("Priority: {0}", task.Priority);
+ Logger.Debug("State: {0}", task.State);
+ Logger.Debug("Category: {0}", task.Category);
+ Logger.Debug("External ID: {0}", task.Id);
+ if (Application.LocalCache.Database.ExternalTaskExists(task.Id)) {
+ Logger.Debug("Task not added.");
+ Logger.Debug("External ID {0} already exists", task.Id);
+ return;
+ }
+ Task local_task = new Task (Application.LocalCache, task.Name, task.DueDate,
+ task.CompletionDate, task.Priority, task.State,
+ task.Category as Category, task.Id);
+ }
}
}
Modified: branches/new_cache/src/Task.cs
==============================================================================
--- branches/new_cache/src/Task.cs (original)
+++ branches/new_cache/src/Task.cs Wed Dec 31 23:37:20 2008
@@ -22,6 +22,17 @@
cache.Database.ExecuteScalar(command);
this.id = cache.Database.Connection.LastInsertRowId;
}
+
+ // The constructor for external tasks
+ public Task(LocalCache cache, string name, DateTime dueDate, DateTime completionDate, TaskPriority priority, TaskState state, Category category, string externalID)
+ {
+ this.cache = cache;
+ // XXX: Handle the category correctly
+ string command = String.Format("INSERT INTO Tasks (Name, DueDate, CompletionDate, Priority, State, Category, ExternalID) values ('{0}','{1}', '{2}','{3}', '{4}', '{5}', '{6}')",
+ name, Database.FromDateTime(dueDate), Database.FromDateTime(completionDate), ((int)(TaskPriority)priority), ((int)(TaskState)state), 0, externalID);
+ cache.Database.ExecuteScalar(command);
+ this.id = cache.Database.Connection.LastInsertRowId;
+ }
public Task (LocalCache cache, int id)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]