aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.CodeGeneration/EnumerationFileJava.cs
blob: 205e528dfb4b31577efa979bf30fa4f10aae2d27 (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
32
33
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.CodeGeneration
{
    /// <summary>
    /// Represents a Java enumeration file.
    /// </summary>
    /// <seealso cref="Tango.CodeGeneration.CodeFile" />
    public class EnumerationFileJava : CodeFile
    {
        /// <summary>
        /// Gets or sets the enum name.
        /// </summary>
        public String Name { get; set; }

        /// <summary>
        /// Gets or sets the collection of enum fields.
        /// </summary>
        public List<EnumerationField> Fields { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="EnumerationFileJava"/> class.
        /// </summary>
        public EnumerationFileJava()
        {
            Fields = new List<EnumerationField>();
        }
    }
}
*/ .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.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()
        {
            
        }
    }
}