tasque r141 - in trunk: . src/Backends/Hiveminder src/Backends/Hiveminder/service
- From: jjohnny svn gnome org
- To: svn-commits-list gnome org
- Subject: tasque r141 - in trunk: . src/Backends/Hiveminder src/Backends/Hiveminder/service
- Date: Tue, 14 Oct 2008 20:54:26 +0000 (UTC)
Author: jjohnny
Date: Tue Oct 14 20:54:25 2008
New Revision: 141
URL: http://svn.gnome.org/viewvc/tasque?rev=141&view=rev
Log:
Hiveminder Backend : Initial code commit.
Added:
trunk/src/Backends/Hiveminder/
trunk/src/Backends/Hiveminder/HmBackend.cs
trunk/src/Backends/Hiveminder/HmCategory.cs
trunk/src/Backends/Hiveminder/HmNote.cs
trunk/src/Backends/Hiveminder/HmPreferencesWidget.cs
trunk/src/Backends/Hiveminder/HmTask.cs
trunk/src/Backends/Hiveminder/service/
trunk/src/Backends/Hiveminder/service/Group.cs
trunk/src/Backends/Hiveminder/service/Hiveminder.cs
trunk/src/Backends/Hiveminder/service/HiveminderException.cs
trunk/src/Backends/Hiveminder/service/Task.cs
Modified:
trunk/ChangeLog
Added: trunk/src/Backends/Hiveminder/HmBackend.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/HmBackend.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,356 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// HMBackend.cs
+//
+// Copyright (c) 2008 Johnny Jacob <johnnyjacob gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+using System.IO;
+
+using Mono.Unix;
+using Hiveminder;
+using Tasque.Backends;
+
+namespace Tasque.Backends.HmBackend
+{
+ public class HmBackend : IBackend
+ {
+
+ private Hiveminder.Hiveminder hm;
+ /// <summary>
+ /// Keep track of the Gtk.TreeIters for the tasks so that they can
+ /// be referenced later.
+ ///
+ /// Key = Task ID
+ /// Value = Gtk.TreeIter in taskStore
+ /// </summary>
+ private Dictionary<int, Gtk.TreeIter> taskIters;
+ private int newTaskId;
+ private Gtk.TreeStore taskStore;
+ private Gtk.TreeModelSort sortedTasksModel;
+
+ private bool initialized;
+ private bool configured;
+
+ private Thread refreshThread;
+ private bool runningRefreshThread;
+ private AutoResetEvent runRefreshEvent;
+
+ private Gtk.ListStore categoryListStore;
+ private Gtk.TreeModelSort sortedCategoriesModel;
+
+ public event BackendInitializedHandler BackendInitialized;
+ public event BackendSyncStartedHandler BackendSyncStarted;
+ public event BackendSyncFinishedHandler BackendSyncFinished;
+
+ private static string credentialFile = System.IO.Path.Combine (
+ Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tasque/hm");
+
+ public HmBackend ()
+ {
+ initialized = false;
+ configured = false;
+
+ newTaskId = 0;
+ taskIters = new Dictionary<int, Gtk.TreeIter> ();
+ taskStore = new Gtk.TreeStore (typeof (ITask));
+
+ sortedTasksModel = new Gtk.TreeModelSort (taskStore);
+ sortedTasksModel.SetSortFunc (0, new Gtk.TreeIterCompareFunc (CompareTasksSortFunc));
+ sortedTasksModel.SetSortColumnId (0, Gtk.SortType.Ascending);
+
+ categoryListStore = new Gtk.ListStore (typeof (ICategory));
+
+ sortedCategoriesModel = new Gtk.TreeModelSort (categoryListStore);
+ sortedCategoriesModel.SetSortFunc (0, new Gtk.TreeIterCompareFunc (CompareCategorySortFunc));
+ sortedCategoriesModel.SetSortColumnId (0, Gtk.SortType.Ascending);
+
+ runRefreshEvent = new AutoResetEvent(false);
+ runningRefreshThread = false;
+ refreshThread = new Thread(RefreshThreadLoop);
+ }
+
+ #region Public Properties
+ public string Name
+ {
+ get { return "Hiveminder"; }
+ }
+
+ /// <value>
+ /// All the tasks .
+ /// </value>
+ public Gtk.TreeModel Tasks
+ {
+ get { return sortedTasksModel; }
+ }
+
+ /// <value>
+ /// This returns all the task lists (categories) that exist.
+ /// </value>
+ public Gtk.TreeModel Categories
+ {
+ get { return sortedCategoriesModel; }
+ }
+
+ /// <value>
+ /// Indication that the backend is configured
+ /// </value>
+ public bool Configured
+ {
+ get { return configured; }
+ }
+
+ /// <value>
+ /// Inidication that the backend is initialized
+ /// </value>
+ public bool Initialized
+ {
+ get { return initialized; }
+ }
+ #endregion // Public Properties
+
+ #region Public Methods
+ public ITask CreateTask (string taskName, ICategory category)
+ {
+ return null;
+ }
+
+ public void DeleteTask(ITask task)
+ {
+ }
+
+ public void Refresh()
+ {
+ Logger.Debug("Refreshing data...");
+
+ runRefreshEvent.Set();
+
+ Logger.Debug("Done refreshing data!");
+ }
+
+ public void Initialize()
+ {
+ Gtk.TreeIter iter;
+ try {
+ string username, password;
+ LoadCredentails (out username,out password);
+ this.hm = new Hiveminder.Hiveminder(username, password);
+ configured = true;
+ } catch (HiveminderAuthException e) {
+ Logger.Debug (e.ToString());
+ Logger.Error ("Hiveminder authentication failed.");
+ } catch (Exception e) {
+ Logger.Debug (e.ToString());
+ Logger.Error ("Unable to connect to Hiveminder");
+ }
+ //
+ // Add in the "All" Category
+ //
+ AllCategory allCategory = new Tasque.AllCategory ();
+ iter = categoryListStore.Append ();
+ categoryListStore.SetValue (iter, 0, allCategory);
+
+ runningRefreshThread = true;
+ Logger.Debug("ThreadState: " + refreshThread.ThreadState);
+ if (refreshThread.ThreadState == ThreadState.Running) {
+ Logger.Debug ("RtmBackend refreshThread already running");
+ } else {
+ if (!refreshThread.IsAlive) {
+ refreshThread = new Thread(RefreshThreadLoop);
+ }
+ refreshThread.Start();
+ }
+ runRefreshEvent.Set();
+ }
+
+ public void RefreshTasks()
+ {
+ Gtk.TreeIter iter;
+
+ Logger.Debug ("Fetching tasks");
+
+ HmTask[] tasks = HmTask.GetTasks (this.hm.DownloadTasks());
+
+ foreach (HmTask task in tasks) {
+ task.Dump();
+ iter = taskStore.AppendNode();
+ taskStore.SetValue (iter, 0, task);
+ }
+
+ Logger.Debug ("Fetching tasks Completed");
+ }
+
+ public void RefreshCategories ()
+ {
+ Gtk.TreeIter iter;
+ HmCategory[] categories = HmCategory.GetCategories (this.hm.DownloadGroups());
+
+ foreach (HmCategory category in categories) {
+ category.Dump();
+ iter = categoryListStore.Append ();
+ categoryListStore.SetValue (iter, 0, category);
+ }
+
+ Logger.Debug ("Fetching Categories");
+ }
+
+ public void Cleanup()
+ {}
+
+ public Gtk.Widget GetPreferencesWidget ()
+ {
+ return new HmPreferencesWidget();
+ }
+
+
+ public static bool LoadCredentails (out string username, out string password)
+ {
+ try {
+ TextReader configFile = new StreamReader (new FileStream(credentialFile, FileMode.OpenOrCreate, FileAccess.Read));
+
+ username = configFile.ReadLine ();
+ password = configFile.ReadLine ();
+
+ if (username == string.Empty || password == string.Empty)
+ return false;
+
+ configFile.Close ();
+
+ } catch (Exception e) {
+ Console.WriteLine (e);
+
+ username = string.Empty;
+ password = string.Empty;
+
+ return false;
+ }
+
+ return true;
+ }
+
+ public static bool PreserveCredentials (string username, string password)
+ {
+ if (username == string.Empty || password == string.Empty)
+ return false;
+
+ try {
+
+ TextWriter configFile = new StreamWriter(new FileStream(credentialFile, FileMode.Create, FileAccess.Write));
+
+ configFile.WriteLine (username);
+ configFile.WriteLine (password);
+
+ configFile.Close();
+
+ } catch (Exception e) {
+ return false;
+ }
+
+ return true;
+ }
+ #endregion // Public Methods
+
+ #region Private Methods
+ static int CompareTasksSortFunc (Gtk.TreeModel model,
+ Gtk.TreeIter a,
+ Gtk.TreeIter b)
+ {
+ ITask taskA = model.GetValue (a, 0) as ITask;
+ ITask taskB = model.GetValue (b, 0) as ITask;
+
+ if (taskA == null || taskB == null)
+ return 0;
+
+ return (taskA.CompareTo (taskB));
+ }
+
+ static int CompareCategorySortFunc (Gtk.TreeModel model,
+ Gtk.TreeIter a,
+ Gtk.TreeIter b)
+ {
+ ICategory categoryA = model.GetValue (a, 0) as ICategory;
+ ICategory categoryB = model.GetValue (b, 0) as ICategory;
+
+ if (categoryA == null || categoryB == null)
+ return 0;
+
+ if (categoryA is Tasque.AllCategory)
+ return -1;
+ else if (categoryB is Tasque.AllCategory)
+ return 1;
+
+ return (categoryA.Name.CompareTo (categoryB.Name));
+ }
+
+ private void RefreshThreadLoop()
+ {
+ while(runningRefreshThread) {
+ runRefreshEvent.WaitOne();
+
+ if(!runningRefreshThread)
+ return;
+
+ // Fire the event on the main thread
+ Gtk.Application.Invoke ( delegate {
+ if(BackendSyncStarted != null)
+ BackendSyncStarted();
+ });
+
+ runRefreshEvent.Reset();
+
+ if(this.hm != null) {
+ RefreshCategories();
+ RefreshTasks();
+ }
+
+ if(!initialized) {
+ initialized = true;
+
+ // Fire the event on the main thread
+ Gtk.Application.Invoke ( delegate {
+ if(BackendInitialized != null)
+ BackendInitialized();
+ });
+ }
+
+ // Fire the event on the main thread
+ Gtk.Application.Invoke ( delegate {
+ if(BackendSyncFinished != null)
+ BackendSyncFinished();
+ });
+ }
+ }
+
+ public void UpdateTask (HmTask task)
+ {
+
+ }
+ #endregion // Private Methods
+
+ #region Event Handlers
+ #endregion // Event Handlers
+ }
+}
Added: trunk/src/Backends/Hiveminder/HmCategory.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/HmCategory.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,87 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// HmCategory.cs
+//
+// Copyright (c) 2008 Johnny Jacob <johnnyjacob gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+
+using System;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+using System.IO;
+
+using Tasque;
+using Hiveminder;
+
+namespace Tasque.Backends.HmBackend
+{
+ public class HmCategory : ICategory
+ {
+ Group group;
+
+ public string Name
+ {
+ get { return group.Name; }
+ }
+
+ public string Id
+ {
+ get { return group.Id; }
+ }
+ public bool ContainsTask(ITask task)
+ {
+ if (task is HmTask) {
+ HmTask hmtask = task as HmTask;
+ return hmtask.GroupId == this.group.Id;
+ }
+
+ return false;
+ }
+
+ public HmCategory ()
+ {
+ this.group = new Group();
+ }
+
+ public HmCategory (Group group)
+ {
+ this.group = group;
+ }
+
+ public static HmCategory[] GetCategories (XmlNodeList list)
+ {
+ uint i = 0;
+ XmlSerializer serializer = new XmlSerializer(typeof(Group));
+ HmCategory[] categories = new HmCategory[list.Count];
+
+ foreach (XmlNode node in list )
+ categories[i++] = new HmCategory ((Group)serializer.Deserialize(new StringReader(node.OuterXml)));
+
+ return categories;
+ }
+
+ public void Dump ()
+ {
+ this.group.Dump();
+ }
+ }
+}
Added: trunk/src/Backends/Hiveminder/HmNote.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/HmNote.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,49 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// HmNote.cs
+//
+// Copyright (c) 2008 Johnny Jacob <johnnyjacob gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+using System;
+using Tasque;
+
+namespace Tasque.Backends.HmBackend
+{
+ public class HmNote : INote
+ {
+ private string text;
+
+ public HmNote (string text)
+ {
+ this.text = text;
+ }
+
+ public string Text
+ {
+ get { return this.text; }
+
+ set {
+ this.text = value;
+ }
+ }
+
+ }
+}
Added: trunk/src/Backends/Hiveminder/HmPreferencesWidget.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/HmPreferencesWidget.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,107 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// HmPreferencesWidget.cs
+//
+// Johnny Jacob <johnnyjacob gmail com>
+//
+// Copyright (c) 2008 Novell Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+using System;
+using System.IO;
+using System.Text;
+using Gtk;
+
+namespace Tasque.Backends.HmBackend
+{
+ public class HmPreferencesWidget : Gtk.EventBox
+ {
+ private LinkButton authButton;
+ private Label statusLabel;
+
+ // NOTE: This is temporary, we need to use OAuth.
+ Gtk.Entry passwordEntry;
+ Gtk.Entry emailEntry;
+
+ private string username;
+ private string password;
+
+ public HmPreferencesWidget () : base()
+ {
+ OAuth.OAuthBase a = new OAuth.OAuthBase();
+
+ HmBackend.LoadCredentails (out this.username, out this.password);
+
+ //Fixme Please ! I look UGLY!
+ VBox mainVBox = new VBox(false, 12);
+ mainVBox.BorderWidth = 10;
+ mainVBox.Show();
+ Add(mainVBox);
+
+ HBox usernameBox = new HBox(false, 12);
+ Gtk.Label emailLabel = new Label ("Email Address");
+ usernameBox.Add (emailLabel);
+ emailEntry = new Entry(username);
+ usernameBox.Add (emailEntry);
+ usernameBox.ShowAll();
+ mainVBox.PackStart (usernameBox, false, false, 0);
+
+ HBox passwordBox = new HBox(false, 12);
+ Gtk.Label passwordLabel = new Label ("Password");
+ passwordBox.Add (passwordLabel);
+ passwordEntry = new Entry(password);
+ passwordBox.Add (passwordEntry);
+ passwordBox.ShowAll();
+ mainVBox.PackStart (passwordBox, false, false, 0);
+
+ // Status message label
+ statusLabel = new Label();
+ statusLabel.Justify = Gtk.Justification.Center;
+ statusLabel.Wrap = true;
+ statusLabel.LineWrap = true;
+ statusLabel.Show();
+ statusLabel.UseMarkup = true;
+ statusLabel.UseUnderline = false;
+
+ mainVBox.PackStart(statusLabel, false, false, 0);
+
+ authButton = new LinkButton("Click Here to Connect");
+ authButton.Show();
+ mainVBox.PackStart(authButton, false, false, 0);
+ mainVBox.ShowAll();
+
+ authButton.Clicked += OnAuthButtonClicked;
+ }
+
+ private void OnAuthButtonClicked (object sender, EventArgs args)
+ {
+ username = this.emailEntry.Text;
+ password = this.passwordEntry.Text;
+ HmBackend.PreserveCredentials(username, password);
+
+ try {
+ Hiveminder.Hiveminder hm = new Hiveminder.Hiveminder(username, password);
+ } catch (Exception e) {
+ authButton.Label = "Try Again";
+ }
+ }
+ }
+}
Added: trunk/src/Backends/Hiveminder/HmTask.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/HmTask.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,363 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// HmTask.cs
+//
+// Copyright (c) 2008 Johnny Jacob <johnnyjacob gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+using System;
+using System.Collections.Generic;
+using System.Xml;
+using System.Xml.Schema;
+using System.Xml.Serialization;
+using System.Text;
+using System.IO;
+using Hiveminder;
+
+namespace Tasque.Backends.HmBackend
+{
+ public class HmTask : AbstractTask
+ {
+ Task task;
+
+ private List <INote> notes;
+
+ #region Properties
+
+ public override string Id
+ {
+ get { return this.task.Id; }
+ }
+
+ public override string Name
+ {
+ get { return this.task.Summary; }
+ set { this.task.Summary = value; }
+ }
+
+ public override DateTime DueDate
+ {
+ get {
+ if (!string.IsNullOrEmpty(this.task.Due)) {
+ return DateTime.Parse (this.task.Due);
+ }
+ return DateTime.MinValue;
+ }
+ set {this.task.Due = value.ToString();}
+ }
+
+ public override DateTime CompletionDate
+ {
+ get {return DateTime.Now;}
+ set {Logger.Info ("Not implemented");}
+ }
+
+ public override bool IsComplete
+ {
+ get {return this.task.IsComplete;}
+ }
+
+ public override TaskPriority Priority
+ {
+ get {
+ switch (this.task.Priority) {
+ case 1 :
+ return TaskPriority.Low;
+ case 3:
+ return TaskPriority.Medium;
+ case 5:
+ return TaskPriority.High;
+ default:
+ return TaskPriority.None;
+ }
+ return TaskPriority.None;
+ }
+
+ set {
+ switch (value) {
+ case TaskPriority.High:
+ this.task.Priority = 1;
+ break;
+ case TaskPriority.Low:
+ this.task.Priority = 3;
+ break;
+ case TaskPriority.Medium:
+ this.task.Priority = 5;
+ break;
+ default:
+ this.task.Priority = 0;
+ break;
+ }
+ }
+ }
+
+ public override bool HasNotes
+ {
+ get {return !string.IsNullOrEmpty(this.task.Description);}
+ }
+
+ public override bool SupportsMultipleNotes
+ {
+ get {return false;}
+ }
+
+ public override TaskState State
+ {
+ get {
+ if (this.task.IsComplete)
+ return TaskState.Completed;
+
+ return TaskState.Active;
+ }
+ }
+
+ public override ICategory Category
+ {
+ get {return null;}
+ set { Logger.Info ("Not implemented");}
+ }
+
+ public override List<INote> Notes
+ {
+ get {
+ return this.notes;
+ }
+ }
+
+ /// <value>
+ /// The ID of the timer used to complete a task after being marked
+ /// inactive.
+ /// </value>
+ public uint TimerID
+ {
+ get { return 0; }
+ set {Logger.Info ("Not implemented"); }
+ }
+
+ public string GroupId
+ {
+ get {return task.GroupId;}
+ }
+
+ #endregion Properties
+
+ public static HmTask[] GetTasks (XmlNodeList list)
+ {
+ uint i = 0;
+ XmlSerializer serializer = new XmlSerializer(typeof(Task));
+ HmTask[] tasks = new HmTask[list.Count];
+
+ foreach (XmlNode node in list )
+ tasks[i++] = new HmTask ((Task)serializer.Deserialize(new StringReader(node.OuterXml)));
+
+ return tasks;
+ }
+
+ #region Constructors
+
+ public HmTask ()
+ {
+ this.task = new Task();
+
+ //Add Description as note.
+ this.notes = null;
+ if (!string.IsNullOrEmpty (this.task.Description)) {
+ this.notes = new List<INote>();
+ HmNote hmnote = new HmNote (this.task.Description);
+ notes.Add (new HmNote (this.task.Description));
+ }
+ }
+
+ public HmTask (Hiveminder.Task task)
+ {
+ this.task = task;
+
+ this.notes = null;
+ if (!string.IsNullOrEmpty (this.task.Description)) {
+ this.notes = new List<INote>();
+ HmNote hmnote = new HmNote (this.task.Description);
+ notes.Add (new HmNote (this.task.Description));
+ }
+ }
+
+ #endregion
+
+ #region Methods
+ public override void Activate ()
+ {
+ Logger.Info ("Not implemented");
+ }
+
+ /// <summary>
+ /// Sets the task to be inactive
+ /// </summary>
+ public override void Inactivate ()
+ {
+ Logger.Info ("Not implemented");
+ }
+
+ /// <summary>
+ /// Completes the task
+ /// </summary>
+ public override void Complete ()
+ {
+ Logger.Info ("Not implemented");
+ }
+
+ /// <summary>
+ /// Deletes the task
+ /// </summary>
+ public override void Delete ()
+ {
+ Logger.Info ("Not implemented");
+ }
+
+ /// <summary>
+ /// Adds a note to a task
+ /// </summary>
+ /// <param name="note">
+ /// A <see cref="INote"/>
+ /// </param>
+ public override INote CreateNote(string text)
+ {
+ Logger.Info ("Not implemented");
+ return null;
+ }
+
+ /// <summary>
+ /// Deletes a note from a task
+ /// </summary>
+ /// <param name="note">
+ /// A <see cref="INote"/>
+ /// </param>
+ public override void DeleteNote(INote note)
+ {
+ Logger.Info ("Not implemented");
+ }
+
+ /// <summary>
+ /// Deletes a note from a task
+ /// </summary>
+ /// <param name="note">
+ /// A <see cref="INote"/>
+ /// </param>
+ public override void SaveNote(INote note)
+ {
+ Logger.Info ("Not implemented");
+ }
+ public int CompareTo (ITask task)
+ {
+ bool isSameDate = true;
+ if (DueDate.Year != task.DueDate.Year
+ || DueDate.DayOfYear != task.DueDate.DayOfYear)
+ isSameDate = false;
+
+ if (isSameDate == false) {
+ if (DueDate == DateTime.MinValue) {
+ // No due date set on this task. Since we already tested to see
+ // if the dates were the same above, we know that the passed-in
+ // task has a due date set and it should be "higher" in a sort.
+ return 1;
+ } else if (task.DueDate == DateTime.MinValue) {
+ // This task has a due date and should be "first" in sort order.
+ return -1;
+ }
+
+ int result = DueDate.CompareTo (task.DueDate);
+
+ if (result != 0) {
+ return result;
+ }
+ }
+
+ // The due dates match, so now sort based on priority and name
+ return CompareByPriorityAndName (task);
+ }
+
+ public int CompareToByCompletionDate (ITask task)
+ {
+ bool isSameDate = true;
+ if (CompletionDate.Year != task.CompletionDate.Year
+ || CompletionDate.DayOfYear != task.CompletionDate.DayOfYear)
+ isSameDate = false;
+
+ if (isSameDate == false) {
+ if (CompletionDate == DateTime.MinValue) {
+ // No completion date set for some reason. Since we already
+ // tested to see if the dates were the same above, we know
+ // that the passed-in task has a CompletionDate set, so the
+ // passed-in task should be "higher" in the sort.
+ return 1;
+ } else if (task.CompletionDate == DateTime.MinValue) {
+ // "this" task has a completion date and should evaluate
+ // higher than the passed-in task which doesn't have a
+ // completion date.
+ return -1;
+ }
+
+ return CompletionDate.CompareTo (task.CompletionDate);
+ }
+
+ // The completion dates are the same, so no sort based on other
+ // things.
+ return CompareByPriorityAndName (task);
+ }
+ #endregion // Methods
+
+ #region Private Methods
+
+ private int CompareByPriorityAndName (ITask task)
+ {
+ // The due dates match, so now sort based on priority
+ if (Priority != task.Priority) {
+ switch (Priority) {
+ case TaskPriority.High:
+ return -1;
+ case TaskPriority.Medium:
+ if (task.Priority == TaskPriority.High) {
+ return 1;
+ } else {
+ return -1;
+ }
+ case TaskPriority.Low:
+ if (task.Priority == TaskPriority.None) {
+ return -1;
+ } else {
+ return 1;
+ }
+ case TaskPriority.None:
+ return 1;
+ }
+ }
+
+ // Due dates and priorities match, now sort by name
+ return Name.CompareTo (task.Name);
+ }
+ #endregion // Private Methods
+
+ #region Debug Methods
+ public void Dump ()
+ {
+ this.task.Dump();
+ }
+ #endregion
+ }
+}
Added: trunk/src/Backends/Hiveminder/service/Group.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/service/Group.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,51 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// Group.cs
+//
+// Copyright (c) 2008 Johnny Jacob <johnnyjacob gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+using System;
+using System.Xml;
+using System.Xml.Serialization;
+using System.Xml.Schema;
+
+namespace Hiveminder
+{
+ [XmlRoot("search", Namespace="", IsNullable=false)]
+ [Serializable]
+ public class Group
+ {
+ [XmlElement("id", Form=XmlSchemaForm.Unqualified)]
+ public string Id;
+
+ [XmlElement("name", Form=XmlSchemaForm.Unqualified)]
+ public string Name;
+
+ [XmlElement("description", Form=XmlSchemaForm.Unqualified)]
+ public string Description;
+
+ public void Dump ()
+ {
+ Console.WriteLine (Id + " : " + Name + " : " + Description);
+ }
+ }
+}
Added: trunk/src/Backends/Hiveminder/service/Hiveminder.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/service/Hiveminder.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,188 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// Hiveminder.cs
+//
+// Copyright (c) 2008 Johnny Jacob <johnnyjacob gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+using System;
+using System.Net;
+using System.IO;
+using System.Xml;
+using System.Collections.Generic;
+using System.Xml.Serialization;
+using System.Text;
+
+namespace Hiveminder
+{
+ class Hiveminder
+ {
+ private const string BaseURL = "http://hiveminder.com";
+ private Cookie COOKIE_HIVEMINDER_SID;
+
+ public Hiveminder (string username, string password)
+ {
+ string cookieValue;
+ cookieValue = this.login(username, password);
+ this.COOKIE_HIVEMINDER_SID = new Cookie ("JIFTY_SID_HIVEMINDER", cookieValue, "/", "hiveminder.com");
+ }
+
+ public string cookieValue
+ {
+ get { return COOKIE_HIVEMINDER_SID.Value; }
+ }
+
+ /// <summary>
+ /// Login to Hiveminder using HTTP Basic Auth
+ /// </summary>
+ /// <param name="username">
+ /// A <see cref="System.String"/>
+ /// </param>
+ /// <param name="password">
+ /// A <see cref="System.String"/>
+ /// </param>
+ public string login (string username, string password)
+ {
+ string postURL = "/__jifty/webservices/xml";
+ //TODO : Fix this.
+ string postData = "J%3AA-fnord=Login&J%3AA%3AF-address-fnord="+username+"&J%3AA%3AF-password-fnord="+password;
+ ASCIIEncoding encoding = new ASCIIEncoding ();
+ byte[] encodedPostData = encoding.GetBytes (postData);
+
+ HttpWebRequest req = (HttpWebRequest)WebRequest.Create (BaseURL + postURL);
+ req.CookieContainer = new CookieContainer();
+ req.Method = "POST";
+ req.ContentType = "application/x-www-form-urlencoded";
+ req.ContentLength = encodedPostData.Length;
+
+ Stream postDataStream = req.GetRequestStream ();
+ postDataStream.Write (encodedPostData, 0, encodedPostData.Length);
+
+ HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
+ Console.WriteLine (resp.StatusCode);
+
+ //Look for JIFTY_SID_HIVEMINDER
+ foreach (Cookie cook in resp.Cookies)
+ {
+ if (cook.Name == "JIFTY_SID_HIVEMINDER") {
+ this.COOKIE_HIVEMINDER_SID = cook;
+ }
+ }
+
+ checkLoginStatus();
+
+ return this.COOKIE_HIVEMINDER_SID.Value;
+ }
+ /// <summary>
+ /// Hack to Check the success of authentication.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.Boolean"/>
+ /// </returns>
+ private bool checkLoginStatus ()
+ {
+ string responseString;
+ responseString = this.command ("/=/version/");
+
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.LoadXml (responseString);
+ XmlNodeList list = xmlDoc.SelectNodes ("//data/REST");
+
+ //Hack :(
+ if (list.Count != 1)
+ throw new HiveminderAuthException ("Authentication Failed");
+
+ return true;
+ }
+
+ public string command (string command, string method)
+ {
+ HttpWebRequest req = (HttpWebRequest)WebRequest.Create (BaseURL + command + ".xml");
+ Console.WriteLine (BaseURL+command);
+ req.CookieContainer = new CookieContainer();
+ req.CookieContainer.Add (this.COOKIE_HIVEMINDER_SID);
+ req.Method = method;
+
+ HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
+
+ string responseString = string.Empty;
+ StreamReader sr = new StreamReader(resp.GetResponseStream());
+ responseString = sr.ReadToEnd();
+
+ return responseString;
+ }
+
+ public string command (string command)
+ {
+ return this.command (command, "GET");
+ }
+
+ /// <summary>
+ /// Get all the Tasks
+ /// </summary>
+ public XmlNodeList DownloadTasks ()
+ {
+ string responseString;
+ uint i =0;
+
+ responseString = this.command ("/=/search/BTDT.Model.Task/");
+
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.LoadXml (responseString);
+ XmlNodeList list = xmlDoc.SelectNodes ("//value");
+ Console.WriteLine (responseString);
+ return list;
+ }
+
+
+ /// <summary>
+ /// Get all the Tasks
+ /// </summary>
+ public XmlNodeList DownloadGroups ()
+ {
+ string responseString;
+ uint i =0;
+
+ responseString = this.command ("/=/action/BTDT.Action.SearchGroup/", "POST");
+
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.LoadXml (responseString);
+ XmlNodeList list = xmlDoc.SelectNodes ("//search");
+ Console.WriteLine (responseString);
+ return list;
+ }
+
+ /// <summary>
+ /// Create a new Task
+ /// </summary>
+ /// <param name="task">
+ /// A <see cref="Task"/>
+ /// </param>
+ /// <returns>
+ /// A <see cref="System.String"/>
+ /// </returns>
+ public string CreateTask (Task task)
+ {
+ //Return TaskID on success or null
+ return null;
+ }
+ }
+}
\ No newline at end of file
Added: trunk/src/Backends/Hiveminder/service/HiveminderException.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/service/HiveminderException.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,36 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// HiveminderException.cs
+//
+// Copyright (c) 2008 Johnny Jacob <johnnyjacob gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+using System;
+
+namespace Hiveminder
+{
+ public class HiveminderAuthException : System.ApplicationException
+ {
+ public HiveminderAuthException(string message) :base (message)
+ {
+ }
+ }
+}
Added: trunk/src/Backends/Hiveminder/service/Task.cs
==============================================================================
--- (empty file)
+++ trunk/src/Backends/Hiveminder/service/Task.cs Tue Oct 14 20:54:25 2008
@@ -0,0 +1,90 @@
+/* -*- Mode: java; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+// Task.cs
+//
+// Copyright (c) 2008 Johnny Jacob <johnnyjacob gmail com>
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+using System;
+using System.Xml;
+using System.Xml.Serialization;
+using System.Xml.Schema;
+
+namespace Hiveminder
+{
+ [XmlRoot("value", Namespace="", IsNullable=false)]
+ [Serializable]
+ public class Task
+ {
+
+ #region PublicProperties
+
+ [XmlElement("id", Form=XmlSchemaForm.Unqualified)]
+ public string Id;
+
+ [XmlElement("priority", Form=XmlSchemaForm.Unqualified)]
+ public int Priority;
+
+ [XmlElement("complete", Form=XmlSchemaForm.Unqualified)]
+ public bool IsComplete;
+
+ [XmlElement("summary", Form=XmlSchemaForm.Unqualified)]
+ public string Summary;
+
+ [XmlElement("created", Form=XmlSchemaForm.Unqualified)]
+ public string Created;
+
+ [XmlElement("started", Form=XmlSchemaForm.Unqualified)]
+ public string Started;
+
+ [XmlElement("due", Form=XmlSchemaForm.Unqualified)]
+ public string Due;
+
+ [XmlElement("description", Form=XmlSchemaForm.Unqualified)]
+ public string Description;
+
+ [XmlElement("group_id", Form=XmlSchemaForm.Unqualified)]
+ public string GroupId;
+
+ #endregion
+
+ public Task()
+ {
+
+ }
+
+ #region Debug Functions
+
+ public void Dump ()
+ {
+ Console.WriteLine ("id : " + this.Id);
+ Console.WriteLine ("priority : " + this.Priority);
+ Console.WriteLine ("summary : " + this.Summary);
+ Console.WriteLine ("started : " + this.Started);
+ Console.WriteLine ("created : " + this.Created);
+ Console.WriteLine ("Due : " + this.Due);
+ Console.WriteLine ("complete : " + this.IsComplete);
+ Console.WriteLine ("Description : " + this.Description);
+ }
+
+ #endregion
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]