aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/TextEditorWeakEventManager.cs
blob: 87057ead40fe66c849d272779f312dfdcaf0d80a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using Tango.Scripting.Editors.Utils;
using System;

namespace Tango.Scripting.Editors
{
	/// <summary>
	/// Contains weak event managers for <see cref="ITextEditorComponent"/>.
	/// </summary>
	public static class TextEditorWeakEventManager
	{
		/// <summary>
		/// Weak event manager for the <see cref="ITextEditorComponent.DocumentChanged"/> event.
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
		public sealed class DocumentChanged : WeakEventManagerBase<DocumentChanged, ITextEditorComponent>
		{
			/// <inheritdoc/>
			protected override void StartListening(ITextEditorComponent source)
			{
				source.DocumentChanged += DeliverEvent;
			}
			
			/// <inheritdoc/>
			protected override void StopListening(ITextEditorComponent source)
			{
				source.DocumentChanged -= DeliverEvent;
			}
		}
		
		/// <summary>
		/// Weak event manager for the <see cref="ITextEditorComponent.OptionChanged"/> event.
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
		public sealed class OptionChanged : WeakEventManagerBase<OptionChanged, ITextEditorComponent>
		{
			/// <inheritdoc/>
			protected override void StartListening(ITextEditorComponent source)
			{
				source.OptionChanged += DeliverEvent;
			}
			
			/// <inheritdoc/>
			protected override void StopListening(ITextEditorComponent source)
			{
				source.OptionChanged -= DeliverEvent;
			}
		}
	}
}
class="w"> public User CurrentUser { get { return _currentUser; } set { _currentUser = value; CurrentUserChanged?.Invoke(this, _currentUser); RaisePropertyChangedAuto(); } } /// <summary> /// Occurs when the current logged-in user has changed. /// </summary> public event EventHandler<User> CurrentUserChanged; /// <summary> /// Initializes a new instance of the <see cref="DefaultAuthenticationProvider"/> class. /// </summary> /// <param name="machineStudioWebClient">The machine studio web client.</param> public DefaultAuthenticationProvider(MachineStudioWebClient machineStudioWebClient) { _client = machineStudioWebClient; } /// <summary> /// Performs a user login by the specified email and password. /// </summary> /// <param name="email">The email.</param> /// <param name="password">The password.</param> /// <returns></returns> /// <exception cref="AuthenticationException">Login failed for user " + email</exception> public AuthenticationLoginResult Login(string email, string password) { var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>(); _client.Environment = settings.DeploymentSlot; var response = _client.Login(new LoginRequest() { Email = email, Password = password, Version = AssemblyHelper.GetCurrentAssemblyVersion().ToString(), }).Result; if (settings.Environment == MachineStudioSettings.WorkingEnvironment.Remote) { ObservablesContext.OverrideSettingsDataSource(response.DataSource); } try { ObservablesStaticCollections.Instance.Initialize(); } catch (System.Data.Entity.Core.MetadataException) { ObservablesContext.ClearModelStore(); ObservablesStaticCollections.Instance.Initialize(); } using (ObservablesContext db = ObservablesContext.CreateDefault()) { User user = new UserBuilder(db).Set(x => x.Email.ToLower() == email.ToLower()).WithRolesAndPermissions().WithOrganization().Build(); if (user == null) { throw new AuthenticationException("Invalid credentials for " + email); } if (!response.VersionChangeRequired) { CurrentUser = user; } return new AuthenticationLoginResult() { User = user, Response = response }; } } /// <summary> /// Logs-out the current logged-in user. /// </summary> public void Logout() { CurrentUser = null; } } }