aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting/ScriptSessionStateChangedEventArgs.cs
blob: 7ea3b924bd8f7c9fb2717a4fbcad5ff097e3d66a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Scripting
{
    public class ScriptSessionStateChangedEventArgs : EventArgs
    {
        public Object ReturnValue { get; set; }

        public ScriptSessionState State { get; set; }

        public Exception Exception { get; set; }
    }
}
{ color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
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;

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;
        }

        /// <summary>
        /// Called when the application has been started
        /// </summary>
        public override void OnApplicationStarted()
        {
            base.OnApplicationStarted();
            Load();
        }

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

            ThreadsHelper.StartStaThread(() =>
            {
                try
                {
                    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()
        {
            
        }
    }
}