Skip to content

Commit

Permalink
starting to work on the activities
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullin committed Jul 17, 2011
1 parent d022d4e commit 327e0a7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
2 changes: 2 additions & 0 deletions FarleyFile.Abstractions/IEvent.cs
Expand Up @@ -4,4 +4,6 @@ public interface IEvent : IBaseMessage
{

}


}
23 changes: 21 additions & 2 deletions FarleyFile.Abstractions/Messages.cs
Expand Up @@ -44,16 +44,33 @@ public SimpleStoryStarted (Guid storyId, string name)
}
}

[DataContract] public sealed class ActivityReference
{
[DataMember(Order = 1)] public Guid RecordId { get; internal set; }
[DataMember(Order = 2)] public string Text { get; internal set; }
[DataMember(Order = 3)] public string OriginalRef { get; internal set; }

internal ActivityReference () {}
public ActivityReference (Guid recordId, string text, string originalRef)
{
RecordId = recordId;
Text = text;
OriginalRef = originalRef;
}
}

[DataContract] public sealed class AddActivity : ICommand
{
[DataMember(Order = 1)] public Guid StoryId { get; internal set; }
[DataMember(Order = 2)] public string Text { get; internal set; }
[DataMember(Order = 3)] public ICollection<ActivityReference> References { get; internal set; }

internal AddActivity () {}
public AddActivity (Guid storyId, string text)
public AddActivity (Guid storyId, string text, ICollection<ActivityReference> references)
{
StoryId = storyId;
Text = text;
References = references;
}
}

Expand All @@ -63,14 +80,16 @@ public AddActivity (Guid storyId, string text)
[DataMember(Order = 2)] public string Text { get; internal set; }
[DataMember(Order = 3)] public DateTime CreatedUtc { get; internal set; }
[DataMember(Order = 4)] public Guid ActivityId { get; internal set; }
[DataMember(Order = 5)] public ICollection<ActivityReference> References { get; internal set; }

internal ActivityAdded () {}
public ActivityAdded (Guid storyId, string text, DateTime createdUtc, Guid activityId)
public ActivityAdded (Guid storyId, string text, DateTime createdUtc, Guid activityId, ICollection<ActivityReference> references)
{
StoryId = storyId;
Text = text;
CreatedUtc = createdUtc;
ActivityId = activityId;
References = references;
}
}

Expand Down
7 changes: 5 additions & 2 deletions FarleyFile.Abstractions/Messages.tt
Expand Up @@ -23,8 +23,11 @@ PerspectiveCreated! (storyId)
StartSimpleStory? (string name)
SimpleStoryStarted! (storyId, string name)

AddActivity? (storyId, string text)
ActivityAdded! (storyId, string text, DateTime createdUtc, activity)
// Done something witReh [john](7) and [jill](78) and
ActivityReference (Guid recordId, string text, string originalRef)

AddActivity? (storyId, string text, ICollection<ActivityReference> references)
ActivityAdded! (storyId, string text, DateTime createdUtc, activity, ICollection<ActivityReference> references)


AddNote? (string title, string text, storyId)
Expand Down
25 changes: 24 additions & 1 deletion FarleyFile.Desktop/Interactions/Specific/ClearScreen.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using FarleyFile.Views;

namespace FarleyFile.Interactions.Specific
Expand All @@ -25,6 +27,8 @@ protected override string[] Alias
get { return new[] {"aa"}; }
}

static readonly Regex _reference = new Regex(@"\[\]\(\d+\)",RegexOptions.Compiled);

public override InteractionResult Handle(InteractionContext context)
{
var txt = context.Request.Data;
Expand All @@ -33,7 +37,26 @@ public override InteractionResult Handle(InteractionContext context)
{
return Error("Tweet err.. activity can't be longer than 140 chars. Use notes to record data");
}
context.Response.SendToProject(new AddActivity(storyId, txt));

var match = _reference.Match(txt);

var references = new List<ActivityReference>();
while (match.Success)
{
var id = match.Groups["id"].Value;
var name = match.Groups["name"].Value;
Guid guid;
if (!context.Request.TryGetId(id, out guid))
{
return Error("Can't find id for '{0}'", id);
}
references.Add(new ActivityReference(guid, name, id));
match = match.NextMatch();
}



context.Response.SendToProject(new AddActivity(storyId, txt, references));
return Handled();
}
}
Expand Down
14 changes: 6 additions & 8 deletions FarleyFile.Desktop/LifelineViewport.cs
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using FarleyFile.Views;
using Lokad.Cqrs;

namespace FarleyFile
{
Expand All @@ -18,7 +16,7 @@ public class LifelineViewport
public readonly Dictionary<string,Guid> LookupRef = new Dictionary<string, Guid>(StringComparer.InvariantCultureIgnoreCase);


string AddReference(Guid identity, params object[] names)
string AddReference(string type, Guid identity, params object[] names)
{
if (identity == Guid.Empty)
throw new InvalidOperationException("Can't add an empty reference");
Expand Down Expand Up @@ -127,14 +125,14 @@ public void When(StoryListView list)
_rich.AppendLine("=======");
foreach (var item in list.Items.Values.OrderBy(s => s.Name))
{
var reference = AddReference(item.StoryId, item.Name);
var reference = AddReference("story", item.StoryId, item.Name);
_rich.AppendLine("[{1}] {2} .{0}", reference, item.Type, item.Name);
}
}

public void When(StoryView view)
{
var txt = string.Format("Story: {0} .{1}", view.Name, AddReference(view.StoryId, view.Name));
var txt = string.Format("Story: {0} .{1}", view.Name, AddReference("story", view.StoryId, view.Name));
using (_rich.Styled(Solarized.Yellow))
{
_rich.AppendLine(txt);
Expand All @@ -151,7 +149,7 @@ public void When(StoryView view)

foreach (var task in completed)
{
_rich.AppendLine(string.Format(" {1} {2} .{0}", AddReference(task.TaskId), task.Completed ? "x" : "",
_rich.AppendLine(string.Format(" {1} {2} .{0}", AddReference("task", task.TaskId), task.Completed ? "x" : "",
task.Text));
}
_rich.AppendLine();
Expand All @@ -164,7 +162,7 @@ public void When(StoryView view)
_rich.AppendLine(activity.Text);
using (_rich.Styled(Solarized.Base1))
{
var refid = AddReference(activity.ActivityId);
var refid = AddReference("activity", activity.ActivityId);
_rich.AppendLine("{0:yyyy-MM-dd HH:mm} .{1}", activity.CreatedUtc, refid);
}
}
Expand All @@ -181,7 +179,7 @@ public void When(StoryView view)

foreach (var note in view.Notes.OrderBy(s => s.Title))
{
_rich.AppendLine("{0} .{1}", note.Title, AddReference(note.NoteId));
_rich.AppendLine("{0} .{1}", note.Title, AddReference("note", note.NoteId));
}
}
if (view.Notes.Count == 0 && view.Tasks.Count == 0 && view.Activities.Count == 0)
Expand Down
2 changes: 1 addition & 1 deletion FarleyFile.Domain/Aggregates/PerspectiveAggregate.cs
Expand Up @@ -72,7 +72,7 @@ public void When(AddActivity c)
}
var id = _state.GetNextId();
var date = DateTime.UtcNow;
Apply(new ActivityAdded(c.StoryId, c.Text, date, id)) ;
Apply(new ActivityAdded(c.StoryId, c.Text, date, id, c.References)) ;
}

public void When(MergeNotes c)
Expand Down

0 comments on commit 327e0a7

Please sign in to comment.