Example #1
0
        protected EditorViewModel(IViewModelServiceProvider serviceProvider, MostRecentlyUsedFileCollection mru, string editorName)
            : base(serviceProvider)
        {
            AssetsPlugin.RegisterPlugin(typeof(AssetsEditorPlugin));
            serviceProvider.Get <IEditorDialogService>();

            ClearMRUCommand           = new AnonymousCommand(serviceProvider, () => MRU.Clear());
            OpenSettingsWindowCommand = new AnonymousCommand(serviceProvider, OpenSettingsWindow);
            OpenWebPageCommand        = new AnonymousTaskCommand <string>(serviceProvider, OpenWebPage);
#if DEBUG
            DebugCommand = new AnonymousCommand(serviceProvider, DebugFunction);
#endif

            MRU = mru;
            MRU.MostRecentlyUsedFiles.CollectionChanged += MostRecentlyUsedFiles_CollectionChanged;
            UpdateRecentFiles();

            serviceProvider.Get <IEditorDialogService>().RegisterDefaultTemplateProviders();

            EditorName = editorName;
            if (Instance != null)
            {
                throw new InvalidOperationException("The EditorViewModel class can be instanced only once.");
            }

            Status = new StatusViewModel(ServiceProvider);
            Status.PushStatus("Ready");

            Instance = this;
        }
Example #2
0
        /// <summary>
        /// Method is called upon application start-up to retrieve session
        /// relevant information from persistance and restore them (or defaults)
        /// into their target objects properties.
        /// </summary>
        /// <param name="sessionData"></param>
        /// <param name="window"></param>
        public void SetSessionData(IProfile sessionData, IViewSize window)
        {
            ViewPosSizeModel winModel = null;

            sessionData.WindowPosSz.TryGetValue(sessionData.MainWindowName, out winModel);

            window.Height = winModel.Height;
            window.Width  = winModel.Width;
            window.Left   = winModel.X;
            window.Top    = winModel.Y;

            if (winModel.IsMaximized == true)
            {
                window.WindowState = WindowState.Maximized;
            }
            else
            {
                window.WindowState = WindowState.Normal;
            }

            MRU.ReadMruFromSession(sessionData);

            if (SizeUnitLabel.ScreenPoints >= 6 && SizeUnitLabel.ScreenPoints <= 200)
            {
                SizeUnitLabel.ScreenPoints = sessionData.FontSizeScreenPoints;
            }
            else
            {
                SizeUnitLabel.ScreenPoints = 12;
            }
        }
Example #3
0
        /// <summary>
        /// Attempts to load the session corresponding to the given path.
        /// </summary>
        /// <param name="filePath">The path to a solution or package file.</param>
        /// <returns><c>True</c> if the session was successfully loaded, <c>False</c> if an error occurred, <c>Null</c> if the operation was cancelled by user.</returns>
        public async Task <bool?> OpenSession(UFile filePath)
        {
            if (Session != null)
            {
                throw new InvalidOperationException("A session is already open in this instance.");
            }

            if (filePath != null && !File.Exists(filePath))
            {
                MRU.RemoveFile(filePath);
                await ServiceProvider.Get <IDialogService>().MessageBox(string.Format(Tr._p("Message", @"The file '{0}' does not exist."), filePath), MessageBoxButton.OK, MessageBoxImage.Information);

                return(false);
            }

            var sessionResult = new PackageSessionResult();
            var loadedSession = await SessionViewModel.OpenSession(filePath, ServiceProvider, this, sessionResult);

            // Loading has failed
            if (loadedSession == null)
            {
                // Null means the user has cancelled the loading operation.
                return(sessionResult.OperationCancelled ? (bool?)null : false);
            }

            MRU.AddFile(filePath);
            Session = loadedSession;

            InternalSettings.FileDialogLastOpenSessionDirectory.SetValue(new UFile(filePath).GetFullDirectory());
            InternalSettings.Save();
            return(true);
        }
Example #4
0
        /// <summary>
        /// Method is called upon application exit to store session
        /// relevant information in persistance and restore on next start-up.
        /// </summary>
        /// <param name="sessionData"></param>
        /// <param name="window"></param>
        public void GetSessionData(IProfile sessionData, IViewSize window)
        {
            // Store session data from actual objects
            ViewPosSizeModel winModel = null;

            sessionData.WindowPosSz.TryGetValue(sessionData.MainWindowName, out winModel);

            winModel.Height = window.Height;
            winModel.Width  = window.Width;
            winModel.X      = window.Left;
            winModel.Y      = window.Top;

            if (window.WindowState == WindowState.Maximized)
            {
                winModel.IsMaximized = true;
            }
            else
            {
                winModel.IsMaximized = false;
            }

            MRU.WriteMruToSession(sessionData);

            sessionData.FontSizeScreenPoints = SizeUnitLabel.ScreenPoints;
        }
Example #5
0
        private void ClearRecentFiles()
        {
            //Clear considering old projects that have been deleted or upgraded from older versions
            var xenkoVersions = RecentFiles?.Select(x => x.Version).ToList();

            if (xenkoVersions != null)
            {
                foreach (var item in xenkoVersions)
                {
                    MRU.Clear(item);
                }
            }
        }
Example #6
0
        public void RemoveRecentFile(UFile filePath)
        {
            //Get all versions of showing on recent files
            var xenkoVersions = RecentFiles?.Select(x => x.Version).Distinct().ToList();

            if (xenkoVersions != null)
            {
                foreach (var item in xenkoVersions)
                {
                    MRU.RemoveFile(filePath, item);
                }
            }
        }
Example #7
0
        public async Task <bool> NewSession(NewSessionParameters newSessionParameters)
        {
            if (Session != null)
            {
                throw new InvalidOperationException("A session is already open in this instance.");
            }

            var newSession = await SessionViewModel.CreateNewSession(this, ServiceProvider, newSessionParameters);

            if (newSession != null)
            {
                Session = newSession;
                MRU.AddFile(Session.SolutionPath);
            }

            return(Session != null);
        }
Example #8
0
        public static string[] Load(FrmScripter frmScp, MRU mru, string path)
        {
            if (!File.Exists(path))
            {
                UtilSys.MessageBox("File '" + path + "' does not exist.");
                mru.Remove(path);
                mru.Save();
                return(null);
            }

            frmScp.Output("Loading file: " + path);

            string[] buffer = UtilIO.ReadFile2Array(path);

            mru.Add(path);
            mru.Save();

            return(buffer);
        }
Example #9
0
        public void RemoveRecentFile(UFile filePath)
        {
            var packageVersion = PackageSessionHelper.GetPackageVersion(filePath);

            //Remove considering old projects that have been deleted or upgraded from older versions
            if (packageVersion == null || string.Compare(packageVersion.ToString(), "3.0", StringComparison.Ordinal) <= 0)
            {
                //Get all versions of showing on recent files
                var xenkoVersions = RecentFiles?.Select(x => x.Version).ToList();
                if (xenkoVersions != null)
                {
                    foreach (var item in xenkoVersions)
                    {
                        MRU.RemoveFile(filePath, item);
                    }
                }
            }
            else
            {
                MRU.RemoveFile(filePath, packageVersion.ToString());
            }
        }
        private void DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
            {
                string[] droppedFilePaths = e.Data.GetData(DataFormats.FileDrop, true) as string[];

                foreach (var file in droppedFilePaths)
                {
                    var mru = new MRU(file);

                    if (mru.IsValid)
                    {
                        try
                        {
                            VM.ClearAll();

                            this.Title = mru.Name;

                            ShowJSON(File.ReadAllText(mru.Address));

                            VM.AddMRUToUserSettings(mru);
                        }
                        catch (Exception ex)
                        {
                            VM.Error = ex.Demystify().ToString();
                        }
                    }
                    else
                    {
                        VM.Error = $"File {file} is not a valid JSON file";
                    }

                    break; // Only one file for now.
                }
            }
        }
Example #11
0
        static void Main()
        {
            //  Instantiate a log that maintains a running record of the recognised voice commands.  This log
            //  will be displayed within a ListBox in the main form, frmGAVPI.  We specify a callback method so
            //  that we may inform an already open frmGAVPI to update the ListBox with the log content.

            try {
                Log = new Logging <string>(GAVPI.OnLogMessage);
            } catch (Exception) { throw; }

            Settings = new Settings();
            Profile  = new Profile(null);

            vi = new InputEngine();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //
            //  To ensure that only a single instance of the application can be executed at a time, we'll use
            //  Mutex ownership to determine if we're already running.  I used http://www.guidgenerator.com/
            //  to create a Globally Unique ID (GUID) as the name of a Mutex, which the application will attempt
            //  to secure before running proper.  If the Mutex can't be secured it means our application is
            //  already running.
            //

            Mutex LockApplicationInstance;
            bool  OnlyApplicationInstance = false;

            //
            //  We'll do something useful if the application is already running by sending it a message asking
            //  it to show itself.  This may be achieved through the native Win32 API PostMessage (an asynchronous
            //  call).  But regardless of whether another instance of the application is running or now, we should
            //  request a message that is unique to our application.
            //

            if ((WM_OPEN_EXISTING_INSTANCE = Win32_APIs.RegisterWindowMessage("WM_OPEN_EXISTING_INSTANCE")) == 0)
            {
                throw new Win32Exception();
            }

            //  Now we can check to see if our application already running...

            if (((LockApplicationInstance = new Mutex(true, APPLICATION_ID, out OnlyApplicationInstance)) != null) &&
                !OnlyApplicationInstance)
            {
                //
                //  It is already running.  Now assuming the user wants to do something productive, let's bring the
                //  existing instance to the front.  PostMessage is non-blocking native Win32 call, so will return
                //  immediately, whose intent is picked up in the frmGAVPI.WndProc() method of the existing instance.
                //

                Win32_APIs.PostMessage((IntPtr)Win32_APIs.HWND_BROADCAST,
                                       WM_OPEN_EXISTING_INSTANCE,
                                       IntPtr.Zero,
                                       IntPtr.Zero);

                //  We can happily quit now.

                return;
            }  //  if()

            //
            //  A system tray icon and associated menu offers an alternative UI, providing the key functionality
            //  of the application in a convenient menu.
            //
            //  So, let's set the Tray Icon's tooltip name, use an instance of the application's icon (from the
            //  project's resources, and provide a handler for when a user double-clicks the system tray icon.

            sysTrayIcon = new NotifyIcon();

            sysTrayIcon.Icon         = Properties.Resources.gavpi;
            sysTrayIcon.Visible      = true;
            sysTrayIcon.DoubleClick += new System.EventHandler(OnDoubleClickIcon);
            sysTrayIcon.Text         = APPLICATION_TITLE;

            //  Our system tray icon's context menu consists of items that may be enabled or disabled depending
            //  on the available workflow.  By default, however, their initial states should be as declared.

            sysTrayMenu = new ContextMenu();

            //  Our MRU menu.  We'll add it to the top of the system tray icon's context menu.

            ProfileMRU = new MRU("Recent", OnMRUListItem);

            sysTrayMenu.MenuItems.Add(ProfileMRU.GetMenu());
            sysTrayMenu.MenuItems.Add("Open Profile", LoadProfile);
            sysTrayMenu.MenuItems.Add("Modify", OpenProfileEditor).Enabled = false;
            sysTrayMenu.MenuItems.Add("-");
            sysTrayMenu.MenuItems.Add("Show Log", OpenMainWindow);
            sysTrayMenu.MenuItems.Add("-");
            sysTrayMenu.MenuItems.Add("Listen", StartListening).Enabled = false;
            sysTrayMenu.MenuItems.Add("Stop", StopListening).Enabled    = false;
            sysTrayMenu.MenuItems.Add("-");
            sysTrayMenu.MenuItems.Add("Settings", OpenSettings);
            sysTrayMenu.MenuItems.Add("-");
            sysTrayMenu.MenuItems.Add("Exit", Exit);

            //  And now we can attach the menu to the system tray icon.

            sysTrayIcon.ContextMenu = sysTrayMenu;

            //  Now let's load the MRU items before running the application propper.

            ProfileMRU.Deserialize();

            //  Let's commence monitoring process startup and automatically open Profiles if any have been
            //  associated with an executable and the option to do so has been set.

            if (Properties.Settings.Default.EnableAutoOpenProfile)
            {
                EnableAutoOpenProfile(null, null);
            }

            //  And display the main window upon start if specified in the configuration.

            if (Properties.Settings.Default.ShowGAVPI)
            {
                OpenMainWindow(null, null);
            }

            Application.Run();

            //  We don't want the garbage collector to think our Mutex is up for grabs before we close the program,
            //  so let's protect it.

            GC.KeepAlive(LockApplicationInstance);

            LockApplicationInstance.ReleaseMutex();
        }  //  static void Main()
 /// <summary>
 /// Store settings in the settings model space.
 /// This method should be called before destroying a page for good.
 /// </summary>
 /// <param name="settings"></param>
 void ISaveSettings.SavePageSettings(Settings.Interfaces.ISettingsManager settings)
 {
     // Store the current list of MRU model items in the settings manager space
     settings.SessionData.ResetMRUModel(MRU.GetModelList());
 }
Example #13
0
        /// <summary>
        /// Given a MRU, convert it to a meeting.
        /// </summary>
        /// <param name="mru">The MRU.</param>
        /// <returns></returns>
        private IMeetingRef ConvertToIMeeting(MRU mru)
        {
            var ag = AgendaInfo.FromShortString(mru.IDRef);

            return(new IndicoMeetingRef(ag));
        }
        private void UpdateMru(MRU mru)
        {
            mnuFileRecent.DropDownItems.Clear();

            List<ToolStripMenuItem> items = new List<ToolStripMenuItem>();

            if (mru.Count == 0)
            {
                items.Add(mnuFileRecentNone);
            }
            else
            {
                int n = 0;
                foreach (string file in mru)
                {
                    n++;
                    string name = ShortPath(file, 60, 75);
                    if (n < 10)
                    {
                        name = String.Format("&{0} {1}", n, name);
                    }
                    else if (n == 10)
                    {
                        name = String.Format("1&0 {1}", n, name);
                    }

                    ToolStripMenuItem item = new ToolStripMenuItem(name)
                    {
                        Tag = file
                    };

                    item.Click += new EventHandler(MRU_Click);
                    items.Add(item);
                }
            }

            mnuFileRecent.DropDownItems.AddRange(items.ToArray());
        }
Example #15
0
        static void Main(string[] args)
        {
            LeArquivo();
            CriaProcessos();
            //MostraProcessos();

            var fifo    = new FIFO();
            var mru     = new MRU();
            var nuf     = new NUF();
            var optimum = new OPTIMUM();

            int[]         trocas = new int[3];
            int           min;
            int           melhor;
            StringBuilder algoritmos = new StringBuilder();

            foreach (var processo in processos)
            {
                trocas[0] = fifo.Run(processo);
                processo.Molduras.Clear();
                trocas[1] = mru.Run(processo);
                processo.Molduras.Clear();
                trocas[2] = nuf.Run(processo);
                processo.Molduras.Clear();
                melhor = optimum.Run(processo);
                processo.Molduras.Clear();

                min = trocas.Min();

                for (int i = 0; i < trocas.Length; i++)
                {
                    if (trocas[i] == min)
                    {
                        if (i == 0)
                        {
                            algoritmos.Append("FIFO ");
                        }
                        else if (i == 1)
                        {
                            algoritmos.Append("MRU ");
                        }
                        else
                        {
                            algoritmos.Append("NUF");
                        }
                    }
                }

                // Console.WriteLine($"FIFO: {trocas[0]} | MRU: {trocas[1]} | NUF: {trocas[2]} | Ótimo: {melhor} | Melhor(es): {algoritmos}");

                // Console.WriteLine($"{trocas[0]}|{trocas[1]}|{trocas[2]}|{melhor}|{algoritmos}");

                // correção para a saída ficar a igual a proposta sem alterar o resto
                // 5 caracteres do 'FIFO ' que é o maior
                if (algoritmos.Length > 5)
                {
                    algoritmos.Clear();
                    algoritmos.Append("empate");
                }

                Console.WriteLine($"{trocas[0]}|{trocas[1]}|{trocas[2]}|{melhor}|{algoritmos}");

                algoritmos.Clear();
            }
        }