Skip to content

Commit cec71e7

Browse files
committed
#8095 Support for environment variables in squiggle settings
1 parent 352eb43 commit cec71e7

17 files changed

+115
-41
lines changed

Shared/AssemblyInfo.Version.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

5-
[assembly: AssemblyVersion("3.2.4.0")]
6-
[assembly: AssemblyFileVersion("3.2.4.0")]
5+
[assembly: AssemblyVersion("3.3.0.0")]
6+
[assembly: AssemblyFileVersion("3.3.0.0")]

Squiggle.Client/Chat.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ class Chat: IChat
2424
IChatSession session;
2525
ChatBuddies buddies;
2626
IBuddy self;
27+
HistoryManager history;
2728

28-
public Chat(IChatSession session, IBuddy self, IBuddy buddy, BuddyResolver buddyResolver) : this(session, self, Enumerable.Repeat(buddy, 1), buddyResolver) { }
29-
30-
public Chat(IChatSession session, IBuddy self, IEnumerable<IBuddy> buddies, BuddyResolver buddyResolver)
29+
public Chat(IChatSession session, IBuddy self, IEnumerable<IBuddy> buddies, BuddyResolver buddyResolver, HistoryManager history)
3130
{
3231
this.self = self;
3332

@@ -42,6 +41,8 @@ public Chat(IChatSession session, IBuddy self, IEnumerable<IBuddy> buddies, Budd
4241
session.UserTyping += session_UserTyping;
4342
session.BuzzReceived += session_BuzzReceived;
4443
session.ActivityInviteReceived += session_ActivityInviteReceived;
44+
45+
this.history = history;
4546
}
4647

4748
#region IChat Members
@@ -273,7 +274,7 @@ void LogSessionStart()
273274
void DoHistoryAction(Action<HistoryManager> action)
274275
{
275276
if (EnableLogging)
276-
ExceptionMonster.EatTheException(() => action(new HistoryManager()), "logging history.");
277+
ExceptionMonster.EatTheException(() => action(history), "logging history.");
277278
}
278279
}
279280
}

Squiggle.Client/ChatClient.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class ChatClient: IChatClient
1616
IPresenceService presenceService;
1717
SquiggleEndPoint chatEndPoint;
1818
BuddyList buddies;
19+
HistoryManager history;
1920

2021
public event EventHandler<ChatStartedEventArgs> ChatStarted = delegate { };
2122
public event EventHandler<BuddyOnlineEventArgs> BuddyOnline = delegate { };
@@ -47,8 +48,9 @@ public bool IsLoggedIn
4748

4849
public bool EnableLogging { get; set; }
4950

50-
public ChatClient(string clientId)
51+
public ChatClient(string clientId, HistoryManager history)
5152
{
53+
this.history = history;
5254
buddies = new BuddyList();
5355
CurrentUser = new SelfBuddy(this, clientId, String.Empty, UserStatus.Offline, new BuddyProperties());
5456
}
@@ -59,7 +61,7 @@ public IChat StartChat(IBuddy buddy)
5961
throw new InvalidOperationException("Not logged in.");
6062

6163
IChatSession session = chatService.CreateSession(new SquiggleEndPoint(buddy.Id, ((Buddy)buddy).ChatEndPoint));
62-
var chat = new Chat(session, CurrentUser, buddy, id=>buddies[id]);
64+
var chat = new Chat(session, CurrentUser, new[]{ buddy }, id=>buddies[id], history);
6365
return chat;
6466
}
6567

@@ -121,7 +123,7 @@ void chatService_ChatStarted(object sender, Squiggle.Core.Chat.ChatStartedEventA
121123

122124
if (buddyList.Any())
123125
{
124-
var chat = new Chat(e.Session, CurrentUser, buddyList, id=>buddies[id]);
126+
var chat = new Chat(e.Session, CurrentUser, buddyList, id=>buddies[id], history);
125127
ChatStarted(this, new ChatStartedEventArgs() { Chat = chat, Buddies = buddyList });
126128
}
127129
}
@@ -196,8 +198,7 @@ void LogStatus(IBuddy buddy)
196198
if (EnableLogging)
197199
ExceptionMonster.EatTheException(() =>
198200
{
199-
var manager = new HistoryManager();
200-
manager.AddStatusUpdate(new Guid(buddy.Id), buddy.DisplayName, (int)buddy.Status);
201+
history.AddStatusUpdate(new Guid(buddy.Id), buddy.DisplayName, (int)buddy.Status);
201202
}, "logging history.");
202203
}
203204

Squiggle.History/DAL/Entities/HistoryContext.cs

+4
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ class HistoryContext : DbContext
1212
public DbSet<Session> Sessions { get; set; }
1313
public DbSet<Event> Events { get; set; }
1414
public DbSet<StatusUpdate> StatusUpdates { get; set; }
15+
16+
public HistoryContext(string nameOrConnectionString): base(nameOrConnectionString)
17+
{
18+
}
1519
}
1620
}

Squiggle.History/DAL/HistoryRepository.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ namespace Squiggle.History.DAL
1111
{
1212
class HistoryRepository : IDisposable
1313
{
14-
HistoryContext context = new HistoryContext();
14+
HistoryContext context;
15+
16+
public HistoryRepository(string nameOrConnectionString)
17+
{
18+
this.context = new HistoryContext(nameOrConnectionString);
19+
}
1520

1621
public void AddSessionEvent(Guid sessionId, DateTime stamp, EventType type, Guid sender, string senderName, IEnumerable<Guid> recipients, string data)
1722
{

Squiggle.History/HistoryManager.cs

+16-9
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ namespace Squiggle.History
99
{
1010
public class HistoryManager
1111
{
12+
string connectionString;
13+
14+
public HistoryManager(string connectionString)
15+
{
16+
this.connectionString = connectionString;
17+
}
18+
1219
public void AddSessionEvent(Guid sessionId, EventType type, Guid senderId, string senderName, IEnumerable<Guid> recipients, string data)
1320
{
14-
using (var repository = new HistoryRepository())
21+
using (var repository = new HistoryRepository(connectionString))
1522
{
1623
repository.AddSessionEvent(sessionId, DateTime.UtcNow, type, senderId, senderName, recipients, data);
1724
if (type == EventType.Joined)
@@ -29,50 +36,50 @@ public void AddSessionEvent(Guid sessionId, EventType type, Guid senderId, strin
2936

3037
public void AddStatusUpdate(Guid contactId, string contactName, int status)
3138
{
32-
using (var repository = new HistoryRepository())
39+
using (var repository = new HistoryRepository(connectionString))
3340
repository.AddStatusUpdate(DateTime.UtcNow, contactId, contactName, status);
3441
}
3542

3643
public IEnumerable<Session> GetSessions(SessionCriteria criteria)
3744
{
38-
using (var repository = new HistoryRepository())
45+
using (var repository = new HistoryRepository(connectionString))
3946
return repository.GetSessions(criteria);
4047
}
4148

4249
public Session GetSession(Guid sessionId)
4350
{
44-
using (var repository = new HistoryRepository())
51+
using (var repository = new HistoryRepository(connectionString))
4552
return repository.GetSession(sessionId);
4653
}
4754

4855

4956
public IEnumerable<StatusUpdate> GetStatusUpdates(StatusCriteria criteria)
5057
{
51-
using (var repository = new HistoryRepository())
58+
using (var repository = new HistoryRepository(connectionString))
5259
return repository.GetStatusUpdates(criteria);
5360
}
5461

5562
public void ClearChatHistory()
5663
{
57-
using (var repository = new HistoryRepository())
64+
using (var repository = new HistoryRepository(connectionString))
5865
repository.ClearChatHistory();
5966
}
6067

6168
public void ClearStatusHistory()
6269
{
63-
using (var repository = new HistoryRepository())
70+
using (var repository = new HistoryRepository(connectionString))
6471
repository.ClearStatusHistory();
6572
}
6673

6774
public void AddSession(Session newSession, IEnumerable<Participant> participants)
6875
{
69-
using (var repository = new HistoryRepository())
76+
using (var repository = new HistoryRepository(connectionString))
7077
repository.AddSession(newSession, participants);
7178
}
7279

7380
public void DeleteSessions(IEnumerable<Guid> sessionIds)
7481
{
75-
using (var repository = new HistoryRepository())
82+
using (var repository = new HistoryRepository(connectionString))
7683
repository.DeleteSessions(sessionIds);
7784
}
7885
}

Squiggle.UI/Controls/ChatHistoryViewer.xaml.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Squiggle.History.DAL;
99
using Squiggle.History.DAL.Entities;
1010
using Squiggle.Plugins;
11+
using Squiggle.UI.Factories;
1112
using Squiggle.UI.Helpers;
1213
using Squiggle.UI.Resources;
1314
using Squiggle.UI.Windows;
@@ -61,7 +62,7 @@ private void results_MouseDoubleClick(object sender, MouseButtonEventArgs e)
6162

6263
void SearchSessions(DateTime? from, DateTime? to, string message)
6364
{
64-
var historyManager = new HistoryManager();
65+
var historyManager = new HistoryManagerFactory().CreateInstance();
6566
var sessions = historyManager.GetSessions(new SessionCriteria()
6667
{
6768
From = from.HasValue ? from.Value.ToUniversalTime() : from,
@@ -85,7 +86,7 @@ private void Delete_Click(object sender, RoutedEventArgs e)
8586
IEnumerable<Guid> sessionIds = results.SelectedItems.Cast<Result>().Select(r => r.Id).ToList();
8687
AsyncInvoke(() =>
8788
{
88-
var historyManager = new HistoryManager();
89+
var historyManager = new HistoryManagerFactory().CreateInstance();
8990
historyManager.DeleteSessions(sessionIds);
9091
},
9192
lastSearch);
@@ -98,7 +99,7 @@ private void Clear_Click(object sender, RoutedEventArgs e)
9899
{
99100
AsyncInvoke(() =>
100101
{
101-
var historyManager = new HistoryManager();
102+
var historyManager = new HistoryManagerFactory().CreateInstance();
102103
historyManager.ClearChatHistory();
103104
}, () => results.ItemsSource = null);
104105
}

Squiggle.UI/Controls/StatusHistoryViewer.xaml.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Squiggle.History;
1717
using Squiggle.History.DAL;
1818
using Squiggle.History.DAL.Entities;
19+
using Squiggle.UI.Factories;
1920
using Squiggle.UI.Resources;
2021
using Squiggle.Utilities;
2122
using Squiggle.Utilities.Threading;
@@ -44,7 +45,7 @@ void Search_Click(object sender, RoutedEventArgs e)
4445

4546
void SearchUpdates(DateTime? from, DateTime? to)
4647
{
47-
var historyManager = new HistoryManager();
48+
var historyManager = new HistoryManagerFactory().CreateInstance();
4849
var updates = historyManager.GetStatusUpdates(new StatusCriteria()
4950
{
5051
From = from.HasValue ? from.Value.ToUniversalTime() : from,
@@ -65,7 +66,7 @@ private void Clear_Click(object sender, RoutedEventArgs e)
6566
{
6667
AsyncInvoke(() =>
6768
{
68-
var historyManager = new HistoryManager();
69+
var historyManager = new HistoryManagerFactory().CreateInstance();
6970
historyManager.ClearStatusHistory();
7071
}, () => results.ItemsSource = null);
7172
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Linq;
5+
using System.Text;
6+
using Squiggle.History;
7+
8+
namespace Squiggle.UI.Factories
9+
{
10+
class HistoryManagerFactory: IInstanceFactory<HistoryManager>
11+
{
12+
public HistoryManager CreateInstance()
13+
{
14+
ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["HistoryContext"];
15+
if (setting == null)
16+
return null;
17+
18+
string connectionString = Environment.ExpandEnvironmentVariables(setting.ConnectionString);
19+
return new HistoryManager(connectionString);
20+
}
21+
}
22+
}

Squiggle.UI/Factories/LoginOptionsFactory.cs

+15-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public LoginOptions CreateInstance()
4848

4949
string clientID = settings.ConnectionSettings.ClientID;
5050

51+
string displayName = Environment.ExpandEnvironmentVariables(userInfo.DisplayName.NullIfEmpty() ??
52+
signInOptions.DisplayName.NullIfEmpty() ??
53+
settings.PersonalSettings.DisplayName);
5154
var options = new LoginOptions()
5255
{
5356
ChatEndPoint = chatEndPoint,
@@ -56,19 +59,27 @@ public LoginOptions CreateInstance()
5659
PresenceServiceEndPoint = presenceServiceEndPoint,
5760
KeepAliveTime = keepAliveTimeout,
5861
UserProperties = CreateProperties(),
59-
DisplayName = userInfo.DisplayName.NullIfEmpty() ?? signInOptions.DisplayName.NullIfEmpty() ?? settings.PersonalSettings.DisplayName
62+
DisplayName = displayName
6063
};
6164

6265
return options;
6366
}
6467

6568
IBuddyProperties CreateProperties()
6669
{
70+
string groupName = Environment.ExpandEnvironmentVariables(userInfo.GroupName.NullIfEmpty() ??
71+
signInOptions.GroupName.NullIfEmpty() ??
72+
settings.PersonalSettings.GroupName);
73+
74+
string email = Environment.ExpandEnvironmentVariables(userInfo.Email.NullIfEmpty() ?? settings.PersonalSettings.EmailAddress);
75+
76+
string displayMessage = Environment.ExpandEnvironmentVariables(settings.PersonalSettings.DisplayMessage);
77+
6778
var properties = new BuddyProperties();
68-
properties.GroupName = userInfo.GroupName.NullIfEmpty() ?? signInOptions.GroupName.NullIfEmpty() ?? settings.PersonalSettings.GroupName;
69-
properties.EmailAddress = userInfo.Email.NullIfEmpty() ?? settings.PersonalSettings.EmailAddress;
79+
properties.GroupName = groupName;
80+
properties.EmailAddress = email;
7081
properties.DisplayImage = userInfo.Image ?? settings.PersonalSettings.DisplayImage;
71-
properties.DisplayMessage = settings.PersonalSettings.DisplayMessage;
82+
properties.DisplayMessage = displayMessage;
7283
properties.MachineName = Environment.MachineName;
7384

7485
return properties;

Squiggle.UI/Factories/SquiggleContextFactory.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using Squiggle.Client;
6+
using Squiggle.History;
67
using Squiggle.UI.Components;
78
using Squiggle.UI.Windows;
89

@@ -11,12 +12,17 @@ namespace Squiggle.UI.Factories
1112
class SquiggleContextFactory: IInstanceFactory<SquiggleContext>
1213
{
1314
IInstanceFactory<PluginLoader> pluginLoaderFactory;
15+
HistoryManager history;
1416
MainWindow window;
1517
string clientId;
1618

17-
public SquiggleContextFactory(IInstanceFactory<PluginLoader> pluginLoaderFactory, MainWindow window, string clientId)
19+
public SquiggleContextFactory(IInstanceFactory<PluginLoader> pluginLoaderFactory,
20+
HistoryManager history,
21+
MainWindow window,
22+
string clientId)
1823
{
1924
this.pluginLoaderFactory = pluginLoaderFactory;
25+
this.history = history;
2026
this.window = window;
2127
this.clientId = clientId;
2228
}
@@ -29,7 +35,7 @@ public SquiggleContext CreateInstance()
2935
SquiggleContext context = new SquiggleContext();
3036
context.MainWindow = window;
3137
context.PluginLoader = pluginLoader;
32-
context.ChatClient = new ChatClient(clientId);
38+
context.ChatClient = new ChatClient(clientId, history);
3339
SquiggleContext.Current = context;
3440
}
3541
return SquiggleContext.Current;

Squiggle.UI/Helpers/SquiggleUtility.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4-
using System.IO;
54
using System.Linq;
6-
using System.Reflection;
75
using System.Threading;
86
using System.Windows;
97
using Squiggle.Client;
108
using Squiggle.Core.Presence;
9+
using Squiggle.UI.Components;
1110
using Squiggle.UI.Controls;
1211
using Squiggle.UI.Settings;
1312
using Squiggle.UI.ViewModel;
13+
using Squiggle.UI.Windows;
1414
using Squiggle.Utilities;
1515
using Squiggle.Utilities.Application;
16-
using Squiggle.UI.Windows;
17-
using Squiggle.UI.Components;
1816

1917
namespace Squiggle.UI.Helpers
2018
{
@@ -34,9 +32,16 @@ public static IEnumerable<UserStatus> GetChangableStatuses()
3432
return statuses;
3533
}
3634

37-
public static void OpenDownloadsFolder()
35+
public static string GetDownloadsFolderPath()
3836
{
3937
string downloadsFolder = SettingsProvider.Current.Settings.GeneralSettings.DownloadsFolder;
38+
downloadsFolder = Environment.ExpandEnvironmentVariables(downloadsFolder);
39+
return downloadsFolder;
40+
}
41+
42+
public static void OpenDownloadsFolder()
43+
{
44+
string downloadsFolder = GetDownloadsFolderPath();
4045
if (Shell.CreateDirectoryIfNotExists(downloadsFolder))
4146
ExceptionMonster.EatTheException(() => Process.Start(downloadsFolder), "opening downloads folder");
4247
}

0 commit comments

Comments
 (0)