Skip to content

Commit

Permalink
Replaced HistoryEntities (DB First) with HistoryContext (EF Code first)
Browse files Browse the repository at this point in the history
Status Logging should be toggleable with settings window option (Instead of only before logging in)
Deleted History.sdf because EF code first generates it automatically the first time.
  • Loading branch information
hasankhan committed Nov 3, 2012
1 parent 0c2eb25 commit 54f8b42
Show file tree
Hide file tree
Showing 47 changed files with 37,512 additions and 1,250 deletions.
2 changes: 1 addition & 1 deletion Squiggle.Client/Buddy.cs
Expand Up @@ -15,7 +15,7 @@ public class Buddy: INotifyPropertyChanged, Squiggle.Client.IBuddy
IBuddyProperties properties;
bool initialized;

public string Id { get; private set; }
public string Id { get; protected set; }
public IPEndPoint ChatEndPoint { get; private set; }
public DateTime LastUpdated { get; private set; }

Expand Down
16 changes: 14 additions & 2 deletions Squiggle.Client/Chat.cs
Expand Up @@ -15,6 +15,7 @@
using BuddyResolver = System.Func<string, Squiggle.Client.Buddy>;
using Squiggle.Core.Chat.Activity;
using Squiggle.Utilities.Threading;
using Squiggle.History.DAL.Entities;

namespace Squiggle.Client
{
Expand Down Expand Up @@ -249,8 +250,19 @@ void LogSessionStart()
{
sessionLogged = true;
IBuddy primaryBuddy = Buddies.FirstOrDefault();
var newSession = Session.CreateSession(session.Id, new Guid(primaryBuddy.Id), primaryBuddy.DisplayName, DateTime.Now);
manager.AddSession(newSession, Buddies.Select(b => Participant.CreateParticipant(Guid.NewGuid(), new Guid(b.Id), b.DisplayName)));
var newSession = new Session()
{
Id = session.Id,
ContactId = new Guid(primaryBuddy.Id),
ContactName = primaryBuddy.DisplayName,
Start = DateTime.Now
};
manager.AddSession(newSession, Buddies.Select(b => new Participant()
{
Id = Guid.NewGuid(),
ContactId = new Guid(b.Id),
ContactName = b.DisplayName,
}).ToList());
});
}

Expand Down
8 changes: 7 additions & 1 deletion Squiggle.Client/ChatClient.cs
Expand Up @@ -85,7 +85,7 @@ public void Login(ChatClientOptions options)
StartPresenceService(username, options.UserProperties, presenceOptions);

var self = (SelfBuddy)CurrentUser;
self.Update(UserStatus.Online, options.DisplayName, chatEndPoint.Address, options.UserProperties.ToDictionary());
self.Update(chatEndPoint.ClientID, UserStatus.Online, options.DisplayName, chatEndPoint.Address, options.UserProperties.ToDictionary());
self.EnableUpdates = true;
LogStatus(CurrentUser);

Expand Down Expand Up @@ -257,6 +257,12 @@ public new UserStatus Status
}
}

internal void Update(string id, UserStatus status, string displayName, IPEndPoint chatEndPoint, IDictionary<string, string> properties)
{
this.Id = id;
base.Update(status, displayName, chatEndPoint, properties);
}

protected override void OnBuddyPropertiesChanged()
{
base.OnBuddyPropertiesChanged();
Expand Down
24 changes: 19 additions & 5 deletions Squiggle.History/App.Config
@@ -1,12 +1,26 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="HistoryEntities" connectionString="metadata=res://*/DAL.HistoryEntities.csdl|res://*/DAL.HistoryEntities.ssdl|res://*/DAL.HistoryEntities.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;Data Source=|DataDirectory|\History.sdf&quot;" providerName="System.Data.EntityClient"/>
<add name="HistoryContext" connectionString="Data Source=|DataDirectory|\History.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0"/>
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
28 changes: 28 additions & 0 deletions Squiggle.History/DAL/Entities/Event.cs
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;

namespace Squiggle.History.DAL.Entities
{
public class Event
{
public Guid Id { get; set; }
public Guid SessionId { get; set; }
public int TypeCode { get; set; }
public Guid SenderId { get; set; }
public string SenderName { get; set; }
public string Data { get; set; }
public DateTime Stamp { get; set; }

[NotMapped]
public EventType Type
{
get { return (EventType)TypeCode; }
set { TypeCode = (int)value; }
}

public Session Session { get; set; }
}
}
16 changes: 16 additions & 0 deletions Squiggle.History/DAL/Entities/EventType.cs
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Squiggle.History.DAL.Entities
{
public enum EventType: int
{
Message = 0,
Buzz = 1,
Joined = 2,
Left = 3,
Activity = 4
}
}
16 changes: 16 additions & 0 deletions Squiggle.History/DAL/Entities/HistoryContext.cs
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace Squiggle.History.DAL.Entities
{
class HistoryContext : DbContext
{
public DbSet<Participant> Participants { get; set; }
public DbSet<Session> Sessions { get; set; }
public DbSet<Event> Events { get; set; }
public DbSet<StatusUpdate> StatusUpdates { get; set; }
}
}
17 changes: 17 additions & 0 deletions Squiggle.History/DAL/Entities/Participant.cs
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Squiggle.History.DAL.Entities
{
public class Participant
{
public Guid Id {get; set;}
public Guid SessionId { get; set; }
public Guid ContactId { get; set; }
public string ContactName { get; set; }

public Session Session {get; set;}
}
}
26 changes: 26 additions & 0 deletions Squiggle.History/DAL/Entities/Session.cs
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace Squiggle.History.DAL.Entities
{
public class Session
{
public Guid Id { get; set; }
public Guid ContactId { get; set; }
public string ContactName { get; set; }
public DateTime Start { get; set; }
public DateTime? End { get; set; }

public ICollection<Event> Events { get; set; }
public ICollection<Participant> Participants { get; set; }

public Session()
{
Events = new Collection<Event>();
Participants = new Collection<Participant>();
}
}
}
16 changes: 16 additions & 0 deletions Squiggle.History/DAL/Entities/StatusUpdate.cs
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Squiggle.History.DAL.Entities
{
public class StatusUpdate
{
public Guid Id { get; set; }
public Guid ContactId { get; set; }
public string ContactName { get; set; }
public int StatusCode { get; set; }
public DateTime Stamp { get; set; }
}
}
16 changes: 0 additions & 16 deletions Squiggle.History/DAL/Event.cs

This file was deleted.

16 changes: 0 additions & 16 deletions Squiggle.History/DAL/EventType.cs

This file was deleted.

Binary file removed Squiggle.History/DAL/History.sdf
Binary file not shown.

0 comments on commit 54f8b42

Please sign in to comment.