using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Tango.Core.Helpers; using Tango.BL.Entities; using Tango.Logging; using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; using Tango.SharedUI; using Tango.BL; using Tango.MachineStudio.Common.EventLogging; using Tango.BL.Enumerations; using Tango.MachineStudio.UI.TFS; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Web; using Tango.Core.DI; using Tango.Settings; using Tango.Core; using Tango.MachineStudio.Common.Buid; namespace Tango.MachineStudio.UI.ViewModels { /// /// Represents the Machine Studio loading view, view model. /// /// public class LoadingViewVM : StudioViewModel { private INotificationProvider _notificationProvider; private TeamFoundationServiceExtendedClient _tfs; private INavigationManager _navigationManager; private IStudioModuleLoader _studioModuleLoader; private IEventLogger _eventLogger; private IBuildProvider _buildProvider; private LogManager logManager = LogManager.Default; public IStudioApplicationManager ApplicationManager { get; set; } private bool _isLoading; public bool IsLoading { get { return _isLoading; } set { _isLoading = value; RaisePropertyChangedAuto(); } } private String _status; public String Status { get { return _status; } set { _status = value; RaisePropertyChangedAuto(); } } /// /// Initializes a new instance of the class. /// /// The navigation manager. /// The studio module loader. /// The notification provider. public LoadingViewVM(IBuildProvider buildProvider, IStudioApplicationManager applicationManager, INavigationManager navigationManager, IStudioModuleLoader studioModuleLoader, INotificationProvider notificationProvider, IEventLogger eventLogger, TeamFoundationServiceExtendedClient teamFoundationClient) { Status = "Loading, please wait..."; _tfs = teamFoundationClient; _eventLogger = eventLogger; ApplicationManager = applicationManager; _navigationManager = navigationManager; _studioModuleLoader = studioModuleLoader; _notificationProvider = notificationProvider; _buildProvider = buildProvider; } /// /// Called when the application has been started /// public override void OnApplicationStarted() { base.OnApplicationStarted(); Load(); } /// /// Load application modules. /// private void Load() { IsLoading = true; ThreadsHelper.StartStaThread(() => { try { if (_buildProvider.BuildType == MSBuildType.Default) { try { Status = "Connecting to Team Foundation Services..."; _tfs.Initialize(); Thread.Sleep(500); } catch (Exception ex) { LogManager.Log(ex, "Could not initialize Team Foundation Service client."); } } Status = "Loading, please wait..."; //ObservablesStaticCollections.Instance.Initialize(); //_eventLogger.Log(EventTypes.ApplicationStarted, "Application Started!"); Status = "Starting application..."; InvokeUI(() => { //_studioModuleLoader.LoadModules(); _navigationManager.NavigateTo(NavigationView.LoginView); IsLoading = false; }); } catch (Exception ex) { logManager.Log(ex); InvokeUINow(() => { if (_notificationProvider.ShowQuestion("An error occurred while trying to connect to Twine database." + Environment.NewLine + "Would you like to try again?")) { Load(); } else { ApplicationManager.ShutDown(); } }); } }); } public override void OnApplicationReady() { } } }