aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Utils/NullSafeCollection.cs
blob: 8a37c54ae16eb0eec168d8eb5300fee40cd510f1 (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
// 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 System;
using System.Collections.ObjectModel;

namespace Tango.Scripting.Editors.Utils
{
	/// <summary>
	/// A collection that cannot contain null values.
	/// </summary>
	[Serializable]
	public class NullSafeCollection<T> : Collection<T> where T : class
	{
		/// <inheritdoc/>
		protected override void InsertItem(int index, T item)
		{
			if (item == null)
				throw new ArgumentNullException("item");
			base.InsertItem(index, item);
		}
		
		/// <inheritdoc/>
		protected override void SetItem(int index, T item)
		{
			if (item == null)
				throw new ArgumentNullException("item");
			base.SetItem(index, item);
		}
	}
}
an>System.Data.Entity; using Tango.BL.Enumerations; using Tango.BL.Builders; namespace Tango.PPC.UI.ViewModels { /// <summary> /// Represents the PPC loading splash screen view model. /// </summary> /// <seealso cref="Tango.PPC.Common.PPCViewModel" /> public class LoadingViewVM : PPCViewModel { /// <summary> /// Gets or sets the module loader. /// </summary> [TangoInject] public IPPCModuleLoader ModuleLoader { get; set; } private bool _isLoading; /// <summary> /// Gets or sets a value indicating whether this instance is loading. /// </summary> public bool IsLoading { get { return _isLoading; } set { _isLoading = value; RaisePropertyChangedAuto(); } } /// <summary> /// Initializes a new instance of the <see cref="LoadingViewVM"/> class. /// </summary> public LoadingViewVM(IPPCApplicationManager applicationManager) { if (!DesignMode) { Task.Delay(1000).ContinueWith((x) => { IsLoading = true; }); } applicationManager.ApplicationInitializationError += ApplicationManager_ApplicationInitializationError; } private void ApplicationManager_ApplicationInitializationError(object sender, Exception ex) { InvokeUI(() => { NavigationManager.NavigateWithObject<Exception>(NavigationView.LoadingErrorView, ex); IsLoading = false; }); } /// <summary> /// Called when the application has been started. /// </summary> public async override void OnApplicationStarted() { using (ObservablesContext db = ObservablesContext.CreateDefault()) { var machine = await db.Machines.FirstAsync(); if (db.Users.Count() == 1 || machine.AutoLogin) { var user = await new UserBuilder(db).SetFirst().WithRolesAndPermissions().BuildAsync(); if (!user.HasRole(Roles.PPCUser)) { var role = db.Roles.Single(x => x.Code == (int)Roles.PPCUser); user.Roles.Add(role); db.UsersRoles.Add(new BL.Entities.UsersRole() { User = user, Role = role, }); await db.SaveChangesAsync(); } LogManager.Log($"Application started. Single user/Auto login detected ({user.Email}). Skipping LoginView..."); await AuthenticationProvider.Login(user.Email, user.Password, false); IsLoading = false; } else { LogManager.Log("Application started. Navigating to LoginView..."); await NavigationManager.NavigateTo(NavigationView.LoginView); IsLoading = false; } } } } }