summaryrefslogtreecommitdiff
path: root/tomboy/Zeitgeist.cs
blob: eee7a501d2a6a63ad92577a47125cc925a1b6433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using Zeitgeist.Datamodel;
using Zeitgeist;
using System.Collections.Generic;
using Tomboy;

namespace Tomboy.Zeitgeist
{
	public class ZeitgeistHandler
	{
		public static bool SendEvent(Note note, NameUri eventInterpretation)
		{
			NameUri eventManifestation = Manifestation.Instance.EventManifestation.UserActivity;
			
			NameUri subjectInterpretation = Interpretation.Instance.Document.Document;
			NameUri subjectManifestation = Manifestation.Instance.FileDataObject.FileDataObject;
			
			Event ev = EventCreator.CreateEvent(note, eventInterpretation, eventManifestation, subjectInterpretation, subjectManifestation);
			
			
			try
			{
				List<Event> listOfEvents = new List<Event>();
				listOfEvents.Add(ev);
				
				GLib.Idle.Add(delegate()
							{
								SendEvent(listOfEvents);
								return false;
							});
				
				Console.WriteLine(string.Format("Operation {0} successful", ev.Interpretation.Name));
				return true;
			}
			catch(Exception e)
			{
				Console.WriteLine(e.StackTrace);
				
				return false;
			}
		}
		
		private static void SendEvent(List<Event> e)
		{
			LogClient client = new LogClient();
			client.InsertEvents(e);
		}
	}
	
	public class EventCreator
	{
		public static Event CreateEvent(Note note,
		                          NameUri eventInterpretation, 
		                          NameUri eventManifestation, 
		                          NameUri subjectInterpretation, 
		                          NameUri subjectManifestation)
		{
			Event ev = new Event();
			
			
			ev.Id = 0;
			ev.Timestamp = DateTime.Now;
			ev.Interpretation = eventInterpretation;
			ev.Manifestation = eventManifestation;
			ev.Actor = ZeitgeistAddin.TomboyUri;
			
			Subject sub = new Subject();
			
			sub.Uri = note.Uri;
			sub.Interpretation = subjectInterpretation;
			sub.Manifestation = subjectManifestation;
			sub.Origin = string.Empty;
			sub.MimeType = ZeitgeistAddin.NoteMimetype;
			sub.Text = note.Title;
			sub.Storage = string.Empty;
			
			ev.Subjects.Add(sub);
			
			return ev;
		}
	}
}