| ofs | hex dump | ascii |
|---|
| 0000 | 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 40 00 00 00 40 08 06 00 00 00 aa 69 71 | .PNG........IHDR...@...@......iq |
| 0020 | de 00 00 00 04 73 42 49 54 08 08 08 08 7c 08 64 88 00 00 00 09 70 48 59 73 00 00 01 bb 00 00 01 | .....sBIT....|.d.....pHYs....... |
| 0040 | bb 01 3a ec e3 e2 00 00 00 19 74 45 58 74 53 6f 66 74 77 61 72 65 00 77 77 77 2e 69 6e 6b 73 63 | ..:.......tEXtSoftware.www.inksc |
| 0060 | 61 70 65 2e 6f 72 67 9b ee 3c 1a 00 00 05 a9 49 44 41 54 78 da ed 99 6b 4c 53 67 18 c7 d9 34 3a | ape.org..<.....IDATx...kLSg...4: |
| 0080 | 97 25 5b b6 cc 25 bb 7c 5a e6 5c 40 28 97 0d 5a dc e6 3e 8c 02 72 b1 ed 0e 78 49 b8 c4 95 cb 92 | .%[..%.|Z.\@(..Z..>..r...xI..... |
| 00a0 | c5 00 5b a2 c9 4c 48 74 71 ce dd 02 73 46 13 07 72 35 e5 32 44 28 17 03 3a cb dd 16 a4 50 4a ef | ..[..LHtq...sF..r5.2D(..:....PJ. |
| 00c0 | 5c da d3 72 15 81 0d 9d c2 b3 f7 10 20 a5 40 5b e9 e9 81 9c f2 e1 97 7e ec fb ff 9d e7 9c f7 79 | \..r..........@[.......~.......y |
| 00e0 | 9f d7 0d 00 dc a8 40 86 b9 ef 30 46 31 bf c1 31 a6 d0 f0 45 c0 a8 32 64 df 13 f5 41 2f bd 2e 9c | ......@...0F1..1...E..2d...A/... |
| 0100 | 71 99 aa 35 ac 06 25 7f 62 3c 12 e8 8e 47 b1 ee 23 80 c0 80 31 41 c1 76 5f 42 1d ea 35 d2 17 e1 | q..5..%.b<...G..#...1A.v_B..5... |
| 0120 | e7 4d 4b 01 e3 98 ef cb 28 f4 c0 62 f8 d5 04 10 a8 42 f6 4d 01 aa 12 da 09 30 44 b3 b2 cc c3 af | .MK.....(..b.....B.M.....0D..... |
| 0140 | 25 80 40 13 c6 10 d2 4b c0 81 03 db 51 e0 19 f3 f0 83 69 f1 a0 ac a9 87 d6 a6 5e e8 f9 ea a8 65 | %.@....K....Q.....i.......^....e |
| 0160 | 15 3c a2 95 00 3d c6 62 2c 7b fa d1 81 a0 90 eb 41 36 0c 50 a7 05 68 92 0e af a8 02 35 87 b5 9b | .<...=.b,{......A6.P..h.....5... |
| 0180 | 36 02 f0 28 26 7b 59 e9 c7 87 80 7c e8 e9 92 80 3b 9a a7 2b 04 f4 1d 64 b0 68 23 c0 84 9e a6 e5 | 6..(&{Y....|....;..+...d.h#..... |
| 01a0 | fb af 29 bb b1 24 40 5c 56 bb 2c bc 32 d8 63 8e 76 1f 41 14 5a 6d 29 61 20 35 0e 7a 92 0f af 2c | ..)..$@\V.,.2.c.v.A.Zm)a.5.z..., |
| 01c0 | ff 50 cf 21 da 09 30 45 33 c3 ec dd 05 74 e1 7e 91 b4 6c 84 f0 68 d6 1f b6 04 a0 2d b0 94 b6 9d | .P.!..0E3....t.~..l..h.....-.... |
| 01e0 | e0 7c 37 18 cd 8c 31 44 05 4e 59 0a 20 5a e2 be 08 ef 34 5a b7 c2 8b 5c 88 e1 30 7f 8d 89 84 eb | .|7...1D.NY..Z....4Z...\..0..... |
| 0200 | 47 83 a1 22 92 09 19 9c 4f 01 9d 11 5e a2 fd 59 60 91 6f e3 30 46 5a 5c 14 a4 c6 62 90 c0 65 cf | G.."....O...^..Y`.o.0FZ\...b..e. |
| 0220 | b3 91 e1 b7 04 6c 09 70 82 00 ff 1b 43 6f 30 8b 71 36 e2 90 25 a1 17 6f a5 c4 9f 3c 03 b1 27 cf | .....l.p....Co0.q6..%..o...<..'. |
| 0240 | 42 e8 e9 4b f3 78 e7 69 ce ad 86 4f be 2e c5 a3 d0 f0 ce a6 17 80 09 60 1b ab d8 98 8c 02 96 b0 | B..K.x.i...O...........`........ |
| 0260 | 8a f1 01 04 d8 82 59 64 00 f7 2c 85 5d ec bb a6 7a ec 95 a3 d1 fa e4 6a 7f dc 74 02 02 4a f1 0f | ......Yd..,.]...z......j..t..J.. |
| 0280 | 58 25 78 ab 3d a1 d7 2b c0 1c af 1c b5 de b7 40 b7 77 53 08 40 41 52 11 33 cf 1a de 11 01 04 1e | X%x.=..+.......@.wS.@AR.3....... |
| 02a0 | d9 aa 59 9f 3c ed d9 0d 15 10 58 84 73 d7 13 9c 0c 01 8b f8 14 68 c3 37 44 c0 c7 02 e3 eb 28 c4 | ..Y.<.....X.s........h.7D.....(. |
| 02c0 | f0 46 0b f0 cc 51 4d 1f c8 d2 bd 40 b9 00 f4 f4 4b 1d 09 4f 96 00 02 46 9e a6 9e 52 01 fb 4b f5 | .F...QM....@....K..O...F...R..K. |
| 02e0 | 7b 1c 0d 4f a6 00 8f 6c e5 9c 5b 3a 6c a7 4c 00 b3 d8 70 64 33 09 98 af 82 c2 be 83 94 09 60 15 | {..O...l..[:l.L...pd3.........`. |
| 0300 | e1 3f d9 0a 77 b1 63 14 54 43 0f c1 34 3e b9 26 c6 b1 87 a0 ec c7 ad a2 e8 37 42 b6 44 6f 53 00 | .?..w.c.TC..4>.&.........7B.DoS. |
| 0320 | 6a 9a 2e 51 27 a0 04 bf 63 2d 7c 72 fd 10 8c 4d 4c da 64 e4 81 6d 01 8b 1c 2a d5 58 af 80 5c 4d | j..Q'...c-|r...ML.d..m...*.X..\M |
| 0340 | 07 75 02 8a 71 9d 35 01 97 ef 8f 92 2e 20 a3 65 d0 56 73 84 53 29 a0 8f 6a 01 99 36 04 78 e6 a8 | .u..q.5........e.Vs.S)..j..6.x.. |
| 0360 | 8d 2e 2d c0 2f 4f 3d 51 23 92 f8 0a 64 b2 1d 2e 29 60 7f be 0a aa 1a c4 04 93 c2 46 09 df 95 05 | ..-./O=Q#...d...)`.........F.... |
| 0380 | cc 53 dd 20 11 d6 36 b4 bf e9 b2 02 16 18 af 6a b8 f7 be 2b 0b 40 95 20 6e 11 08 04 db 5c 56 c0 | .S....6........j...+.@..n....\V. |
| 03a0 | 02 a7 28 15 f0 8b 98 7c 01 df df 1d 70 44 c0 63 61 a3 f8 5d ca 04 44 54 18 51 38 12 05 0c 18 c1 | ..(....|....pD.ca..]..DT.Q8..... |
| 03c0 | 27 47 e1 88 00 a8 12 49 12 28 13 40 c0 ab 34 41 66 fb 28 64 49 c7 d6 24 a7 6b 14 ea 7b 71 ab 08 | 'G.....I.(.@..4Af.(dI..$.k..{q.. |
| 03e0 | 3a 0d 10 5a a4 b6 79 16 b0 25 a0 bc 4e 94 4f a9 00 aa 4f 83 b6 04 14 96 dc 80 04 0e 5b c6 e7 06 | :..Z..y..%..N.O...O.........[... |
| 0400 | 7f e8 92 02 2a ff 6e 81 04 6e 30 71 07 f1 24 91 1b 7c dc e5 04 94 54 de 5a ba 84 49 e0 06 fd 9b | ....*.n..n0q..$..|....T.Z..I.... |
| 0420 | c8 fb fc 3d a7 0b 38 56 63 82 c4 ba a1 35 49 ae 33 c1 77 b7 fb ad 72 ac 5c 4b 8a 80 ab 59 d7 cc | ...=..8Vc....5I.3.w...r.\K...Y.. |
| 0440 | 04 b0 21 91 c7 be e9 34 01 9f fd 85 c3 bd c1 09 d2 76 01 89 d6 e8 b0 80 73 e9 a7 2b cc 05 20 26 | ..!....4.........v......s..+...& |
| 0460 | dc dc dc 9e 73 8a 80 f4 e6 11 d2 fb 80 13 b5 7d eb 16 50 2d 12 5f 49 c2 c2 de 42 a1 e7 cc 25 f0 | ....s..........}..P-._I...B...%. |
| 0480 | 39 a1 7b e8 de 09 ce 22 2e 08 85 aa 9d c4 ba 51 e8 47 e6 02 be e4 86 04 d0 46 00 2b 5f 35 2b 6c | 9.{....".......Q.G.......F.+_5+l |
| 04a0 | 10 9b 50 60 1using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Authentication;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.BL.Entities;
using Tango.MachineStudio.Common.Authentication;
using Tango.BL;
using Tango.BL.Enumerations;
using System.Data.Entity;
using Tango.Transport.Web;
using Tango.Settings;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.Common.StudioApplication;
using Tango.Core.Helpers;
using Tango.MachineStudio.Common.Web;
using Tango.BL.Builders;
using System.Data.Entity.Core;
using System.Windows.Threading;
namespace Tango.MachineStudio.UI.Authentication
{
/// <summary>
/// Represents the default Machine Studio <see cref="IAuthenticationProvider">Authentication provider</see>
/// </summary>
/// <seealso cref="Tango.Core.ExtendedObject" />
/// <seealso cref="Tango.MachineStudio.Common.Authentication.IAuthenticationProvider" />
public class DefaultAuthenticationProvider : ExtendedObject, IAuthenticationProvider
{
private MachineStudioWebClient _client;
private DispatcherTimer _refreshTokenTimer;
private User _currentUser;
/// <summary>
/// Gets the current logged-in user.
/// </summary>
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;
_refreshTokenTimer = new DispatcherTimer();
_refreshTokenTimer.Interval = TimeSpan.FromMinutes(30);
_refreshTokenTimer.Tick += _refreshTokenTimer_Tick;
_refreshTokenTimer.Stop();
}
private async void _refreshTokenTimer_Tick(object sender, EventArgs e)
{
if (ObservablesContext.GetActualDataSource().Type == DataSourceType.AccessToken)
{
try
{
LogManager.Log("Refreshing database access token...");
var response = await _client.RefreshToken(new RefreshTokenRequest());
ObservablesContext.UpdateAccessToken(response.AccessToken, response.Expiration);
}
catch (Exception ex)
{
LogManager.Log(ex, "Error occurred while trying to refresh the database access token.");
}
}
}
/// <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, LoginMethod method, bool bypassVersionCheck = false, Action<String> logAction = null)
{
_refreshTokenTimer.Stop();
var settings = SettingsManager.Default.GetOrCreate<MachineStudioSettings>();
if (!App.StartupArgs.Contains("-webDebug"))
{
_client.Environment = settings.DeploymentSlot;
}
var appVersion = AssemblyHelper.GetCurrentAssemblyVersion().ToString();
if (settings.ForceVersionUpdate)
{
appVersion = "1.0.0.0";
}
LoginResponse response = null;
try
{
logAction?.Invoke("Logging in to machine service...");
response = _client.Login(new LoginRequest()
{
Email = email,
Password = password,
Version = appVersion,
Method = method,
}).Result;
}
catch (Exception ex)
{
throw new AggregateException(new AuthenticationException("Error logging in to machine service."), ex);
}
if (bypassVersionCheck)
{
response.VersionChangeRequired = false;
}
if (settings.Environment == MachineStudioSettings.WorkingEnvironment.Remote)
{
ObservablesContext.OverrideSettingsDataSource(response.DataSource);
}
if (response.VersionChangeRequired && !bypassVersionCheck)
{
return new AuthenticationLoginResult()
{
Response = response
};
}
if (response.PasswordChangeRequired)
{
return new AuthenticationLoginResult()
{
Response = response
};
}
try
{
ObservablesStaticCollections.Instance.Initialize((x) =>
{
logAction.Invoke(x);
});
}
catch (Exception ex)
{
throw new AggregateException(new MetadataException("Error initializing database connection."), ex);
}
using (ObservablesContext db = ObservablesContext.CreateDefault())
{
logAction.Invoke("Loading user permissions...");
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);
}
CurrentUser = user;
_refreshTokenTimer.Start();
logAction.Invoke("Starting application...");
return new AuthenticationLoginResult()
{
User = user,
Response = response
};
}
}
/// <summary>
/// Logs-out the current logged-in user.
/// </summary>
public void Logout()
{
CurrentUser = null;
_refreshTokenTimer.Stop();
}
}
}
|