aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Images
ModeNameSize
-rw-r--r--capture-device.png1812logstatsplain
-rw-r--r--data-capture.jpg121309logstatsplain
-rw-r--r--recordings.png858logstatsplain
-rw-r--r--tape.png713logstatsplain
-rw-r--r--video-frame.png97254logstatsplain
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.Update;
using Tango.Core.DI;
using Tango.Settings;
using Tango.Core;

namespace Tango.MachineStudio.UI.ViewModels
{
    /// <summary>
    /// Represents the Machine Studio loading view, view model.
    /// </summary>
    /// <seealso cref="Tango.SharedUI.ViewModel" />
    public class LoadingViewVM : StudioViewModel
    {
        private INotificationProvider _notificationProvider;
        private TeamFoundationServiceExtendedClient _tfs;
        private INavigationManager _navigationManager;
        private IStudioModuleLoader _studioModuleLoader;
        private IEventLogger _eventLogger;
        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(); }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LoadingViewVM"/> class.
        /// </summary>
        /// <param name="navigationManager">The navigation manager.</param>
        /// <param name="studioModuleLoader">The studio module loader.</param>
        /// <param name="notificationProvider">The notification provider.</param>
        public LoadingViewVM(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;
        }

        public override void OnApplicationStarted()
        {
            base.OnApplicationStarted();
            Load();
        }

        /// <summary>
        /// Load application modules.
        /// </summary>
        private void Load()
        {
            IsLoading = true;

            ThreadsHelper.StartStaThread(() =>
            {
                try
                {
                    try
                    {
                        Status = "Checking for critical updates...";

                        LogManager.Log("Checking for forced update...");
                        var service = UpdateServiceHelper.GetUpdateServiceChannel();
                        var client = service.CreateChannel();

                        CheckForUpdatesResponse response = client.CheckForUpdates(new CheckForUpdatesRequest()
                        {
                            Email = "ForceUpdate",
                            Password = "ForceUpdate",
                            Version = ApplicationManager.Version.ToString(),
                        });

                        if (response.IsUpdateAvailable && response.ForcedUpdate)
                        {
                            LogManager.Log("Forced update found, Navigating to update view!");

                            InvokeUI(() =>
                            {
                                if (_notificationProvider.ShowQuestion("Machine Studio has detected a critical update which must be installed in order for the application to run properly. Do you wish to download and install this update?"))
                                {
                                    TangoMessenger.Default.Send(new Messages.ForcedUpdateMessage() { UpdateResponse = response });
                                    _navigationManager.NavigateTo(NavigationView.UpdateView);
                                }
                                else
                                {
                                    ApplicationManager.ShutDown();
                                }

                                IsLoading = false;
                            });

                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManager.Log(ex, "Error checking for forced update!");
                    }

                    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()
        {
            
        }
    }
}