diff --git a/Shared/AssemblyInfo.Version.cs b/Shared/AssemblyInfo.Version.cs index 0c57ac7..565d305 100644 --- a/Shared/AssemblyInfo.Version.cs +++ b/Shared/AssemblyInfo.Version.cs @@ -2,5 +2,5 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -[assembly: AssemblyVersion("3.2.4.0")] -[assembly: AssemblyFileVersion("3.2.4.0")] \ No newline at end of file +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")] \ No newline at end of file diff --git a/Squiggle.Client/Chat.cs b/Squiggle.Client/Chat.cs index 726acb1..6245176 100644 --- a/Squiggle.Client/Chat.cs +++ b/Squiggle.Client/Chat.cs @@ -24,10 +24,9 @@ class Chat: IChat IChatSession session; ChatBuddies buddies; IBuddy self; + HistoryManager history; - public Chat(IChatSession session, IBuddy self, IBuddy buddy, BuddyResolver buddyResolver) : this(session, self, Enumerable.Repeat(buddy, 1), buddyResolver) { } - - public Chat(IChatSession session, IBuddy self, IEnumerable buddies, BuddyResolver buddyResolver) + public Chat(IChatSession session, IBuddy self, IEnumerable buddies, BuddyResolver buddyResolver, HistoryManager history) { this.self = self; @@ -42,6 +41,8 @@ public Chat(IChatSession session, IBuddy self, IEnumerable buddies, Budd session.UserTyping += session_UserTyping; session.BuzzReceived += session_BuzzReceived; session.ActivityInviteReceived += session_ActivityInviteReceived; + + this.history = history; } #region IChat Members @@ -273,7 +274,7 @@ void LogSessionStart() void DoHistoryAction(Action action) { if (EnableLogging) - ExceptionMonster.EatTheException(() => action(new HistoryManager()), "logging history."); + ExceptionMonster.EatTheException(() => action(history), "logging history."); } } } diff --git a/Squiggle.Client/ChatClient.cs b/Squiggle.Client/ChatClient.cs index 8c6005c..c353117 100644 --- a/Squiggle.Client/ChatClient.cs +++ b/Squiggle.Client/ChatClient.cs @@ -16,6 +16,7 @@ public class ChatClient: IChatClient IPresenceService presenceService; SquiggleEndPoint chatEndPoint; BuddyList buddies; + HistoryManager history; public event EventHandler ChatStarted = delegate { }; public event EventHandler BuddyOnline = delegate { }; @@ -47,8 +48,9 @@ public bool IsLoggedIn public bool EnableLogging { get; set; } - public ChatClient(string clientId) + public ChatClient(string clientId, HistoryManager history) { + this.history = history; buddies = new BuddyList(); CurrentUser = new SelfBuddy(this, clientId, String.Empty, UserStatus.Offline, new BuddyProperties()); } @@ -59,7 +61,7 @@ public IChat StartChat(IBuddy buddy) throw new InvalidOperationException("Not logged in."); IChatSession session = chatService.CreateSession(new SquiggleEndPoint(buddy.Id, ((Buddy)buddy).ChatEndPoint)); - var chat = new Chat(session, CurrentUser, buddy, id=>buddies[id]); + var chat = new Chat(session, CurrentUser, new[]{ buddy }, id=>buddies[id], history); return chat; } @@ -121,7 +123,7 @@ void chatService_ChatStarted(object sender, Squiggle.Core.Chat.ChatStartedEventA if (buddyList.Any()) { - var chat = new Chat(e.Session, CurrentUser, buddyList, id=>buddies[id]); + var chat = new Chat(e.Session, CurrentUser, buddyList, id=>buddies[id], history); ChatStarted(this, new ChatStartedEventArgs() { Chat = chat, Buddies = buddyList }); } } @@ -196,8 +198,7 @@ void LogStatus(IBuddy buddy) if (EnableLogging) ExceptionMonster.EatTheException(() => { - var manager = new HistoryManager(); - manager.AddStatusUpdate(new Guid(buddy.Id), buddy.DisplayName, (int)buddy.Status); + history.AddStatusUpdate(new Guid(buddy.Id), buddy.DisplayName, (int)buddy.Status); }, "logging history."); } diff --git a/Squiggle.History/DAL/Entities/HistoryContext.cs b/Squiggle.History/DAL/Entities/HistoryContext.cs index e4004a1..a78a2b6 100644 --- a/Squiggle.History/DAL/Entities/HistoryContext.cs +++ b/Squiggle.History/DAL/Entities/HistoryContext.cs @@ -12,5 +12,9 @@ class HistoryContext : DbContext public DbSet Sessions { get; set; } public DbSet Events { get; set; } public DbSet StatusUpdates { get; set; } + + public HistoryContext(string nameOrConnectionString): base(nameOrConnectionString) + { + } } } diff --git a/Squiggle.History/DAL/HistoryRepository.cs b/Squiggle.History/DAL/HistoryRepository.cs index df23f96..5aa8a6c 100644 --- a/Squiggle.History/DAL/HistoryRepository.cs +++ b/Squiggle.History/DAL/HistoryRepository.cs @@ -11,7 +11,12 @@ namespace Squiggle.History.DAL { class HistoryRepository : IDisposable { - HistoryContext context = new HistoryContext(); + HistoryContext context; + + public HistoryRepository(string nameOrConnectionString) + { + this.context = new HistoryContext(nameOrConnectionString); + } public void AddSessionEvent(Guid sessionId, DateTime stamp, EventType type, Guid sender, string senderName, IEnumerable recipients, string data) { diff --git a/Squiggle.History/HistoryManager.cs b/Squiggle.History/HistoryManager.cs index 7b86a60..f4d05aa 100644 --- a/Squiggle.History/HistoryManager.cs +++ b/Squiggle.History/HistoryManager.cs @@ -9,9 +9,16 @@ namespace Squiggle.History { public class HistoryManager { + string connectionString; + + public HistoryManager(string connectionString) + { + this.connectionString = connectionString; + } + public void AddSessionEvent(Guid sessionId, EventType type, Guid senderId, string senderName, IEnumerable recipients, string data) { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) { repository.AddSessionEvent(sessionId, DateTime.UtcNow, type, senderId, senderName, recipients, data); if (type == EventType.Joined) @@ -29,50 +36,50 @@ public void AddSessionEvent(Guid sessionId, EventType type, Guid senderId, strin public void AddStatusUpdate(Guid contactId, string contactName, int status) { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) repository.AddStatusUpdate(DateTime.UtcNow, contactId, contactName, status); } public IEnumerable GetSessions(SessionCriteria criteria) { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) return repository.GetSessions(criteria); } public Session GetSession(Guid sessionId) { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) return repository.GetSession(sessionId); } public IEnumerable GetStatusUpdates(StatusCriteria criteria) { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) return repository.GetStatusUpdates(criteria); } public void ClearChatHistory() { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) repository.ClearChatHistory(); } public void ClearStatusHistory() { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) repository.ClearStatusHistory(); } public void AddSession(Session newSession, IEnumerable participants) { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) repository.AddSession(newSession, participants); } public void DeleteSessions(IEnumerable sessionIds) { - using (var repository = new HistoryRepository()) + using (var repository = new HistoryRepository(connectionString)) repository.DeleteSessions(sessionIds); } } diff --git a/Squiggle.UI/Controls/ChatHistoryViewer.xaml.cs b/Squiggle.UI/Controls/ChatHistoryViewer.xaml.cs index 2424769..f6a191c 100644 --- a/Squiggle.UI/Controls/ChatHistoryViewer.xaml.cs +++ b/Squiggle.UI/Controls/ChatHistoryViewer.xaml.cs @@ -8,6 +8,7 @@ using Squiggle.History.DAL; using Squiggle.History.DAL.Entities; using Squiggle.Plugins; +using Squiggle.UI.Factories; using Squiggle.UI.Helpers; using Squiggle.UI.Resources; using Squiggle.UI.Windows; @@ -61,7 +62,7 @@ private void results_MouseDoubleClick(object sender, MouseButtonEventArgs e) void SearchSessions(DateTime? from, DateTime? to, string message) { - var historyManager = new HistoryManager(); + var historyManager = new HistoryManagerFactory().CreateInstance(); var sessions = historyManager.GetSessions(new SessionCriteria() { From = from.HasValue ? from.Value.ToUniversalTime() : from, @@ -85,7 +86,7 @@ private void Delete_Click(object sender, RoutedEventArgs e) IEnumerable sessionIds = results.SelectedItems.Cast().Select(r => r.Id).ToList(); AsyncInvoke(() => { - var historyManager = new HistoryManager(); + var historyManager = new HistoryManagerFactory().CreateInstance(); historyManager.DeleteSessions(sessionIds); }, lastSearch); @@ -98,7 +99,7 @@ private void Clear_Click(object sender, RoutedEventArgs e) { AsyncInvoke(() => { - var historyManager = new HistoryManager(); + var historyManager = new HistoryManagerFactory().CreateInstance(); historyManager.ClearChatHistory(); }, () => results.ItemsSource = null); } diff --git a/Squiggle.UI/Controls/StatusHistoryViewer.xaml.cs b/Squiggle.UI/Controls/StatusHistoryViewer.xaml.cs index d9a193f..001601e 100644 --- a/Squiggle.UI/Controls/StatusHistoryViewer.xaml.cs +++ b/Squiggle.UI/Controls/StatusHistoryViewer.xaml.cs @@ -16,6 +16,7 @@ using Squiggle.History; using Squiggle.History.DAL; using Squiggle.History.DAL.Entities; +using Squiggle.UI.Factories; using Squiggle.UI.Resources; using Squiggle.Utilities; using Squiggle.Utilities.Threading; @@ -44,7 +45,7 @@ void Search_Click(object sender, RoutedEventArgs e) void SearchUpdates(DateTime? from, DateTime? to) { - var historyManager = new HistoryManager(); + var historyManager = new HistoryManagerFactory().CreateInstance(); var updates = historyManager.GetStatusUpdates(new StatusCriteria() { From = from.HasValue ? from.Value.ToUniversalTime() : from, @@ -65,7 +66,7 @@ private void Clear_Click(object sender, RoutedEventArgs e) { AsyncInvoke(() => { - var historyManager = new HistoryManager(); + var historyManager = new HistoryManagerFactory().CreateInstance(); historyManager.ClearStatusHistory(); }, () => results.ItemsSource = null); } diff --git a/Squiggle.UI/Factories/HistoryManagerFactory.cs b/Squiggle.UI/Factories/HistoryManagerFactory.cs new file mode 100644 index 0000000..55517a5 --- /dev/null +++ b/Squiggle.UI/Factories/HistoryManagerFactory.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using Squiggle.History; + +namespace Squiggle.UI.Factories +{ + class HistoryManagerFactory: IInstanceFactory + { + public HistoryManager CreateInstance() + { + ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["HistoryContext"]; + if (setting == null) + return null; + + string connectionString = Environment.ExpandEnvironmentVariables(setting.ConnectionString); + return new HistoryManager(connectionString); + } + } +} diff --git a/Squiggle.UI/Factories/LoginOptionsFactory.cs b/Squiggle.UI/Factories/LoginOptionsFactory.cs index 9dc3728..d0ff036 100644 --- a/Squiggle.UI/Factories/LoginOptionsFactory.cs +++ b/Squiggle.UI/Factories/LoginOptionsFactory.cs @@ -48,6 +48,9 @@ public LoginOptions CreateInstance() string clientID = settings.ConnectionSettings.ClientID; + string displayName = Environment.ExpandEnvironmentVariables(userInfo.DisplayName.NullIfEmpty() ?? + signInOptions.DisplayName.NullIfEmpty() ?? + settings.PersonalSettings.DisplayName); var options = new LoginOptions() { ChatEndPoint = chatEndPoint, @@ -56,7 +59,7 @@ public LoginOptions CreateInstance() PresenceServiceEndPoint = presenceServiceEndPoint, KeepAliveTime = keepAliveTimeout, UserProperties = CreateProperties(), - DisplayName = userInfo.DisplayName.NullIfEmpty() ?? signInOptions.DisplayName.NullIfEmpty() ?? settings.PersonalSettings.DisplayName + DisplayName = displayName }; return options; @@ -64,11 +67,19 @@ public LoginOptions CreateInstance() IBuddyProperties CreateProperties() { + string groupName = Environment.ExpandEnvironmentVariables(userInfo.GroupName.NullIfEmpty() ?? + signInOptions.GroupName.NullIfEmpty() ?? + settings.PersonalSettings.GroupName); + + string email = Environment.ExpandEnvironmentVariables(userInfo.Email.NullIfEmpty() ?? settings.PersonalSettings.EmailAddress); + + string displayMessage = Environment.ExpandEnvironmentVariables(settings.PersonalSettings.DisplayMessage); + var properties = new BuddyProperties(); - properties.GroupName = userInfo.GroupName.NullIfEmpty() ?? signInOptions.GroupName.NullIfEmpty() ?? settings.PersonalSettings.GroupName; - properties.EmailAddress = userInfo.Email.NullIfEmpty() ?? settings.PersonalSettings.EmailAddress; + properties.GroupName = groupName; + properties.EmailAddress = email; properties.DisplayImage = userInfo.Image ?? settings.PersonalSettings.DisplayImage; - properties.DisplayMessage = settings.PersonalSettings.DisplayMessage; + properties.DisplayMessage = displayMessage; properties.MachineName = Environment.MachineName; return properties; diff --git a/Squiggle.UI/Factories/SquiggleContextFactory.cs b/Squiggle.UI/Factories/SquiggleContextFactory.cs index 01c2924..2b74662 100644 --- a/Squiggle.UI/Factories/SquiggleContextFactory.cs +++ b/Squiggle.UI/Factories/SquiggleContextFactory.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using Squiggle.Client; +using Squiggle.History; using Squiggle.UI.Components; using Squiggle.UI.Windows; @@ -11,12 +12,17 @@ namespace Squiggle.UI.Factories class SquiggleContextFactory: IInstanceFactory { IInstanceFactory pluginLoaderFactory; + HistoryManager history; MainWindow window; string clientId; - public SquiggleContextFactory(IInstanceFactory pluginLoaderFactory, MainWindow window, string clientId) + public SquiggleContextFactory(IInstanceFactory pluginLoaderFactory, + HistoryManager history, + MainWindow window, + string clientId) { this.pluginLoaderFactory = pluginLoaderFactory; + this.history = history; this.window = window; this.clientId = clientId; } @@ -29,7 +35,7 @@ public SquiggleContext CreateInstance() SquiggleContext context = new SquiggleContext(); context.MainWindow = window; context.PluginLoader = pluginLoader; - context.ChatClient = new ChatClient(clientId); + context.ChatClient = new ChatClient(clientId, history); SquiggleContext.Current = context; } return SquiggleContext.Current; diff --git a/Squiggle.UI/Helpers/SquiggleUtility.cs b/Squiggle.UI/Helpers/SquiggleUtility.cs index 96fd16f..4db576d 100644 --- a/Squiggle.UI/Helpers/SquiggleUtility.cs +++ b/Squiggle.UI/Helpers/SquiggleUtility.cs @@ -1,20 +1,18 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; -using System.Reflection; using System.Threading; using System.Windows; using Squiggle.Client; using Squiggle.Core.Presence; +using Squiggle.UI.Components; using Squiggle.UI.Controls; using Squiggle.UI.Settings; using Squiggle.UI.ViewModel; +using Squiggle.UI.Windows; using Squiggle.Utilities; using Squiggle.Utilities.Application; -using Squiggle.UI.Windows; -using Squiggle.UI.Components; namespace Squiggle.UI.Helpers { @@ -34,9 +32,16 @@ public static IEnumerable GetChangableStatuses() return statuses; } - public static void OpenDownloadsFolder() + public static string GetDownloadsFolderPath() { string downloadsFolder = SettingsProvider.Current.Settings.GeneralSettings.DownloadsFolder; + downloadsFolder = Environment.ExpandEnvironmentVariables(downloadsFolder); + return downloadsFolder; + } + + public static void OpenDownloadsFolder() + { + string downloadsFolder = GetDownloadsFolderPath(); if (Shell.CreateDirectoryIfNotExists(downloadsFolder)) ExceptionMonster.EatTheException(() => Process.Start(downloadsFolder), "opening downloads folder"); } diff --git a/Squiggle.UI/Settings/GeneralSettings.cs b/Squiggle.UI/Settings/GeneralSettings.cs index 2e2f711..ca37bcd 100644 --- a/Squiggle.UI/Settings/GeneralSettings.cs +++ b/Squiggle.UI/Settings/GeneralSettings.cs @@ -33,7 +33,8 @@ public void ReadFrom(Properties.Settings settings, ConfigReader reader) CheckForUpdates = reader.GetSetting(SettingKey.CheckForUpdates, true); GitHash = reader.GetSetting(SettingKey.GitHash, String.Empty); - if (String.IsNullOrEmpty(settings.DownloadsFolder) || !Shell.CreateDirectoryIfNotExists(settings.DownloadsFolder)) + string downloadsFolder = Environment.ExpandEnvironmentVariables(settings.DownloadsFolder ?? String.Empty); + if (String.IsNullOrEmpty(downloadsFolder) || !Shell.CreateDirectoryIfNotExists(downloadsFolder)) DownloadsFolder = Path.Combine(AppInfo.Location, "Downloads"); else DownloadsFolder = settings.DownloadsFolder; diff --git a/Squiggle.UI/Squiggle.UI.csproj b/Squiggle.UI/Squiggle.UI.csproj index 7dbd812..f0a9496 100644 --- a/Squiggle.UI/Squiggle.UI.csproj +++ b/Squiggle.UI/Squiggle.UI.csproj @@ -124,6 +124,7 @@ + diff --git a/Squiggle.UI/Windows/ChatWindow.xaml.cs b/Squiggle.UI/Windows/ChatWindow.xaml.cs index 111f10d..de013df 100644 --- a/Squiggle.UI/Windows/ChatWindow.xaml.cs +++ b/Squiggle.UI/Windows/ChatWindow.xaml.cs @@ -513,7 +513,7 @@ void OnTransferInvite(IFileTransferHandler invitation) chatTextBox.AddInfo(Translation.Instance.ChatWindow_FileTransferInviteNotSupported); return; } - string downloadsFolder = SettingsProvider.Current.Settings.GeneralSettings.DownloadsFolder; + string downloadsFolder = SquiggleUtility.GetDownloadsFolderPath(); downloadsFolder = Path.Combine(downloadsFolder, PrimaryBuddy.DisplayName); chatTextBox.AddFileReceiveRequest(invitation, downloadsFolder); fileTransfers.Add(invitation); diff --git a/Squiggle.UI/Windows/ConversationViewer.xaml.cs b/Squiggle.UI/Windows/ConversationViewer.xaml.cs index 186a4c2..f39cfbd 100644 --- a/Squiggle.UI/Windows/ConversationViewer.xaml.cs +++ b/Squiggle.UI/Windows/ConversationViewer.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Linq; using System.Text; using System.Windows; @@ -12,6 +13,7 @@ using System.Windows.Shapes; using Squiggle.History; using Squiggle.History.DAL.Entities; +using Squiggle.UI.Factories; using Squiggle.UI.StickyWindow; namespace Squiggle.UI.Windows @@ -31,7 +33,8 @@ public ConversationViewer() public ConversationViewer(Guid sessionId): this() { this.SessionId = sessionId; - var historyManager = new HistoryManager(); + + var historyManager = new HistoryManagerFactory().CreateInstance(); Session session = historyManager.GetSession(sessionId); messages.ItemsSource = session.Events .OrderBy(e => e.Stamp) diff --git a/Squiggle.UI/Windows/MainWindow.xaml.cs b/Squiggle.UI/Windows/MainWindow.xaml.cs index 66a8bba..145e7a9 100644 --- a/Squiggle.UI/Windows/MainWindow.xaml.cs +++ b/Squiggle.UI/Windows/MainWindow.xaml.cs @@ -18,6 +18,7 @@ using Squiggle.Utilities; using Squiggle.Utilities.Threading; using Squiggle.Plugins; +using Squiggle.History; namespace Squiggle.UI.Windows { @@ -54,7 +55,11 @@ private void Window_Loaded(object sender, RoutedEventArgs e) settings.ContactSettings.ContactGroups.FlushItems(); settingsProvider.Save(); - context = new SquiggleContextFactory(new PluginLoaderFactory(), this, settings.ConnectionSettings.ClientID).CreateInstance(); + HistoryManager history = new HistoryManagerFactory().CreateInstance(); + context = new SquiggleContextFactory(new PluginLoaderFactory(), + history, + this, + settings.ConnectionSettings.ClientID).CreateInstance(); context.PluginLoader.LoadAll(context); SetupControls();