summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManish Sinha <manishsinha.tech@gmail.com>2010-09-05 21:56:51 +0530
committerManish Sinha <manishsinha.tech@gmail.com>2010-09-05 21:56:51 +0530
commit81624542f0f33d1e54b26bd916df8038e01c1a3d (patch)
tree1c76a14eb5b873d1dc2bacd065d59f83e825952f
parent3cea3b64c89e4e0a1d6764e7d8967a0601abe62b (diff)
Implemented IBlacklist and also finished RawEvent and Event with converting from one type to other
-rw-r--r--Zeitgeist.Cli/Main.cs11
-rw-r--r--Zeitgeist/Client/IBlacklist.cs14
-rw-r--r--Zeitgeist/Client/IDataSource.cs2
-rw-r--r--Zeitgeist/Datamodel/Event.cs143
-rw-r--r--Zeitgeist/Zeitgeist.csproj6
5 files changed, 151 insertions, 25 deletions
diff --git a/Zeitgeist.Cli/Main.cs b/Zeitgeist.Cli/Main.cs
index 6d6efba..8c2c9d3 100644
--- a/Zeitgeist.Cli/Main.cs
+++ b/Zeitgeist.Cli/Main.cs
@@ -11,10 +11,13 @@ namespace Zeitgeist.ZeitgeistSharp.Cli
{
BusG.Init();
- NDesk.DBus.ObjectPath objPath = new NDesk.DBus.ObjectPath("/org/gnome/zeitgeist/data_source_registry");
- IDataSource zeitgeist = Bus.Session.GetObject<IDataSource>("org.gnome.zeitgeist.Engine", objPath);
- DataSource[] sources = zeitgeist.GetDataSources();
- Console.WriteLine(sources.Length);
+ NDesk.DBus.ObjectPath objPath = new NDesk.DBus.ObjectPath("/org/gnome/zeitgeist/blacklist");
+ IBlacklist zeitgeist = Bus.Session.GetObject<IBlacklist>("org.gnome.zeitgeist.Engine", objPath);
+ RawEvent[] sources = zeitgeist.GetBlacklist();
+
+ RawEvent evnt = sources[0];
+ Event ev = Event.FromRaw(evnt);
+ RawEvent rw = ev.GetRawEvent();
}
}
}
diff --git a/Zeitgeist/Client/IBlacklist.cs b/Zeitgeist/Client/IBlacklist.cs
new file mode 100644
index 0000000..b75be4e
--- /dev/null
+++ b/Zeitgeist/Client/IBlacklist.cs
@@ -0,0 +1,14 @@
+using System;
+using Zeitgeist.Datamodel;
+using Zeitgeist;
+
+namespace Zeitgeist.Client
+{
+ [NDesk.DBus.Interface ("org.gnome.zeitgeist.Blacklist")]
+ public interface IBlacklist
+ {
+ RawEvent[] GetBlacklist();
+ void SetBlacklist(RawEvent[] event_templates);
+ }
+}
+
diff --git a/Zeitgeist/Client/IDataSource.cs b/Zeitgeist/Client/IDataSource.cs
index 7bcc5fd..65f12db 100644
--- a/Zeitgeist/Client/IDataSource.cs
+++ b/Zeitgeist/Client/IDataSource.cs
@@ -1,5 +1,5 @@
using System;
-using Zeitgeist.Datamodel;
+using Zeitgeist.Datamodel;
using Zeitgeist;
namespace Zeitgeist.Client
diff --git a/Zeitgeist/Datamodel/Event.cs b/Zeitgeist/Datamodel/Event.cs
index 0cd1ad2..b5bee7c 100644
--- a/Zeitgeist/Datamodel/Event.cs
+++ b/Zeitgeist/Datamodel/Event.cs
@@ -1,22 +1,63 @@
using System;
+using System.Collections.Generic;
+using System.Collections;
+using System.Linq;
namespace Zeitgeist.Datamodel
{
public class Event
{
- private int Timestamp { get; set; }
- private string Actor { get; set; }
- private string Interpretation { get; set; }
- private string Manifestation { get; set; }
- private Subject[] Subjects { get; set; }
+ public UInt64 Id;
+ public UInt64 Timestamp;
+ public string Actor;
+ public string Interpretation;
+ public string Manifestation;
+ public List<Subject> Subjects;
+ public byte[] Payload;
public Event(){}
public static Event FromRaw(RawEvent raw)
{
Event e = new Event();
- /*
- * assign e properties here
- */
+
+ #region Metadata
+
+ UInt64.TryParse(raw.metadata[(int)EventMetadataPosition.Id], out e.Id);
+ UInt64.TryParse(raw.metadata[(int)EventMetadataPosition.Timestamp], out e.Timestamp);
+ e.Actor = raw.metadata[(int)EventMetadataPosition.Actor];
+ e.Interpretation = raw.metadata[(int)EventMetadataPosition.Interpretation];
+ e.Manifestation = raw.metadata[(int)EventMetadataPosition.Manifestation];
+
+ #endregion
+
+ #region Subjects
+
+ e.Subjects= new List<Subject>();
+
+ for(int i = 0; i < raw.subjects.Length; i ++)
+ {
+ Subject sub = new Subject();
+ string[] subjArr = raw.subjects[i];
+
+ sub.Uri = subjArr[(int)EventSubjectPosition.Uri];
+ sub.Origin = subjArr[(int)EventSubjectPosition.Origin];
+ sub.MimeType = subjArr[(int)EventSubjectPosition.MimeType];
+ sub.Text = subjArr[(int)EventSubjectPosition.Text];
+ sub.Storage = subjArr[(int)EventSubjectPosition.Storage];
+ sub.Interpretation = subjArr[(int)EventSubjectPosition.Interpretation];
+ sub.Manifestation = subjArr[(int)EventSubjectPosition.Manifestation];
+
+ e.Subjects.Add(sub);
+ }
+
+ #endregion
+
+ #region Payload
+
+ e.Payload = raw.payload;
+
+ #endregion
+
return e;
}
public RawEvent GetRawEvent()
@@ -27,9 +68,9 @@ namespace Zeitgeist.Datamodel
public struct RawEvent
{
- public string[] metadata { get; set; }
- public string[][] subjects { get; set; }
- public byte[] payload { get; set; }
+ public string[] metadata;
+ public string[][] subjects;
+ public byte[] payload;
public RawEvent(string[] metadata, string[][] subjects, byte[] payload)
{
@@ -41,12 +82,84 @@ namespace Zeitgeist.Datamodel
public static RawEvent FromEvent(Event ev)
{
RawEvent raw = new RawEvent();
- /*
- * assign rae properties here
- */
+
+ #region MetaData
+
+ int metaDataLength = Enum.GetNames(typeof(EventMetadataPosition)).Length;
+ List<string> metaDataList = new List<string>(metaDataLength);
+
+ for(int i=0; i< metaDataList.Capacity; i++)
+ metaDataList.Add(null);
+
+ metaDataList[(int)EventMetadataPosition.Id] = ev.Id.ToString();
+ metaDataList[(int)EventMetadataPosition.Timestamp] = ev.Timestamp.ToString();
+ metaDataList[(int)EventMetadataPosition.Actor] = ev.Actor;
+ metaDataList[(int)EventMetadataPosition.Interpretation] = ev.Interpretation;
+ metaDataList[(int)EventMetadataPosition.Manifestation] = ev.Manifestation;
+
+ raw.metadata = metaDataList.ToArray();
+
+ #endregion
+
+ #region Subject
+
+ List<string[]> subList= new List<string[]>();
+ foreach(Subject sub in ev.Subjects)
+ {
+ #region Individual Subject
+
+ int subLength = Enum.GetNames(typeof(EventSubjectPosition)).Length;
+ List<string> subCont = new List<string>(subLength);
+
+ for(int i=0; i< subCont.Capacity; i++)
+ subCont.Add(null);
+
+ subCont[(int)EventSubjectPosition.Uri] = sub.Uri;
+ subCont[(int)EventSubjectPosition.Origin] = sub.Origin;
+ subCont[(int)EventSubjectPosition.MimeType] = sub.MimeType;
+ subCont[(int)EventSubjectPosition.Text] = sub.Text;
+ subCont[(int)EventSubjectPosition.Storage] = sub.Storage;
+ subCont[(int)EventSubjectPosition.Interpretation] = sub.Interpretation;
+ subCont[(int)EventSubjectPosition.Manifestation] = sub.Manifestation;
+
+ subList.Add(subCont.ToArray());
+
+ #endregion
+ }
+
+ raw.subjects = subList.ToArray();
+
+ #endregion
+
+ #region Payload
+
+ raw.payload = ev.Payload;
+
+ #endregion
+
return raw;
}
- }
+ }
+
+ enum EventMetadataPosition
+ {
+ Id = 0,
+ Timestamp = 1,
+ Interpretation = 2,
+ Manifestation = 3,
+ Actor = 4
+ }
+
+ enum EventSubjectPosition
+ {
+ Uri = 0,
+ Origin = 1,
+ MimeType = 2,
+ Text = 3,
+ Storage = 4,
+ Interpretation = 5,
+ Manifestation = 6
+ }
}
diff --git a/Zeitgeist/Zeitgeist.csproj b/Zeitgeist/Zeitgeist.csproj
index a58823c..d6609a6 100644
--- a/Zeitgeist/Zeitgeist.csproj
+++ b/Zeitgeist/Zeitgeist.csproj
@@ -47,15 +47,11 @@
<Compile Include="Datamodel\DataSource.cs" />
<Compile Include="Delegates.cs" />
<Compile Include="Client\IDataSource.cs" />
+ <Compile Include="Client\IBlacklist.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Datamodel\" />
<Folder Include="Client\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
- <ProjectExtensions>
- <MonoDevelop>
- <Properties InternalTargetFrameworkVersion="3.5" />
- </MonoDevelop>
- </ProjectExtensions>
</Project> \ No newline at end of file