Пример #1
0
        private void StartProject(ConsoleProjectViewModel argProject)
        {
            try
            {
                SimpleFileLogger.Instance.LogMessage("Starting project {0}", argProject.Name);
                ConsoleViewModel tmpVM = new ConsoleViewModel(this.Dispatcher, argProject);
                tmpVM.Closing += OnProject_Closing;

                this.RunActionOnUIThread(() =>
                {
                    this.Projects.Add(tmpVM);
                });
                this.ActiveConsole = tmpVM;

                SimpleFileLogger.Instance.LogMessage("Successfullyl started project {0}", argProject.Name);
            }
            catch (Exception ex)
            {
                string tmpError = "Unable to stat the process.";
                if (ex is UnauthorizedAccessException)
                {
                    tmpError += " You have no enough permissions for this operation.";
                }
                SimpleFileLogger.Instance.LogError(tmpError, ex);
                this.ErrorMessage = tmpError;
            }
        }
Пример #2
0
 internal void PersistProjectDetails(ConsoleProjectViewModel argProject)
 {
     this.RunActionWithErrorHandling(() =>
     {
         StorageManager.UpdateProject(argProject.Name, argProject.Model);
     });
 }
Пример #3
0
        private void ImportProject_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog tmpDialog = new OpenFileDialog();

            tmpDialog.Multiselect = false;
            tmpDialog.Filter      = "Shortcuts|*.lnk";
            DialogResult tmpDialogResult = tmpDialog.ShowDialog();

            if (tmpDialogResult == System.Windows.Forms.DialogResult.OK)
            {
                string tmpLink = tmpDialog.FileName;
                try
                {
                    ConsoleProjectViewModel tmpProject;
                    using (WindowsShortcut tmpShellLink = new WindowsShortcut(tmpLink))
                    {
                        tmpProject            = new ConsoleProjectViewModel();
                        tmpProject.Arguments  = tmpShellLink.Arguments;
                        tmpProject.Executable = tmpShellLink.Target;
                        tmpProject.Name       = System.IO.Path.GetFileNameWithoutExtension(tmpShellLink.ShortCutFile);
                        tmpProject.WorkingDir = tmpShellLink.WorkingDirectory;
                    }

                    this.CreateNewProject(tmpProject);
                }
                catch (Exception ex)
                {
                    SimpleFileLogger.Instance.LogError("Unable to import the project", ex);
                    System.Windows.MessageBox.Show("Unable to import the project. You can find more details about this in the application log.");
                }
            }
        }
Пример #4
0
        private void AddProject(ConsoleProjectViewModel argProject)
        {
            ObservableCollection <ConsoleProjectViewModel> tmpProjects = new ObservableCollection <ConsoleProjectViewModel>(this.AvailableProjects);

            tmpProjects.Add(argProject);
            this.AvailableProjects = new ObservableCollection <ConsoleProjectViewModel>(tmpProjects.OrderBy(item => item.Name));
        }
Пример #5
0
        private void DuplicateProject_Click(object sender, RoutedEventArgs e)
        {
            ConsoleProjectViewModel tmpProjectVM = this.ViewModel.ActiveConsole.Project.GetCopy();

            SimpleFileLogger.Instance.LogMessage("Duplicating project {0}", tmpProjectVM.Name);
            tmpProjectVM.Name = String.Format("Duplicate {0}", tmpProjectVM.Name);
            this.CreateNewProject(tmpProjectVM);
        }
Пример #6
0
 internal void UpdateActiveConsoleProject(ConsoleProjectViewModel argProject)
 {
     this.RunActionWithErrorHandling(() =>
     {
         ConsoleProjectViewModel tmpOldProject = this.AvailableProjects.Where(item => item.Name == argProject.Name).Single();
         this.AvailableProjects[this.AvailableProjects.IndexOf(tmpOldProject)] = argProject;
         this.ActiveConsole.Project = argProject;
         this.OnAvailableCommandsChanged();
     });
 }
Пример #7
0
        private void EditProject(ConsoleProjectViewModel argProject)
        {
            this.projectView = new ProjectView(new ProjectDetailsViewModel(this.ViewModel, argProject.GetCopy(), false));
            bool?tmpResult = this.projectView.ShowDialog();

            if (tmpResult.HasValue && tmpResult.Value)
            {
                this.ViewModel.PersistProjectDetails(this.projectView.ViewModel.Project);
                this.ViewModel.UpdateActiveConsoleProject(this.projectView.ViewModel.Project);
            }
        }
Пример #8
0
        public ProjectDetailsViewModel(ConsoleHostViewModel argHostVM, ConsoleProjectViewModel argProject, bool argIsNew)
        {
            if (argHostVM == null)
            {
                throw new ArgumentNullException("argHostVM", "Host VM cannot be null");
            }

            this.hostVM       = argHostVM;
            this.IsNewProject = argIsNew;
            this.Project      = argProject;
        }
Пример #9
0
 internal void RemoveProject(string argProjectName)
 {
     this.RunActionWithErrorHandling(() =>
     {
         ConsoleProjectViewModel tmpCurrentProject = this.AvailableProjects.Where(item => item.Name.Equals(argProjectName, StringComparison.InvariantCultureIgnoreCase)).SingleOrDefault();
         if (tmpCurrentProject == null)
         {
             throw new ApplicationException("No such project");
         }
         this.AvailableProjects.Remove(tmpCurrentProject);
         StorageManager.DeleteProject(tmpCurrentProject.Name);
     });
 }
Пример #10
0
        private void CreateNewProject(ConsoleProjectViewModel argProject)
        {
            ProjectDetailsViewModel tmpVM = new ProjectDetailsViewModel(this.ViewModel, argProject, true);

            this.projectView = new ProjectView(tmpVM);
            bool?tmpResult = this.projectView.ShowDialog();

            if (tmpResult.HasValue && tmpResult.Value)
            {
                this.ViewModel.AddNewProject(this.projectView.ViewModel.Project);
            }
            this.projectView = null;
        }
Пример #11
0
        internal void AddNewProject(ConsoleProjectViewModel argProject)
        {
            this.RunActionWithErrorHandling(() =>
            {
                if (argProject == null)
                {
                    throw new ArgumentNullException("argProject");
                }

                SimpleFileLogger.Instance.LogMessage("Adding new project {0}", argProject.Name);
                StorageManager.SaveProject(argProject.Model);
                this.AddProject(argProject);
            });
        }
Пример #12
0
        public ConsoleViewModel(Dispatcher argDispatcher, ConsoleProjectViewModel argProject)
            : base(argDispatcher)
        {
            if (argProject == null)
            {
                throw new ArgumentNullException();
            }

            this.Project = argProject;
            if (!this.IsInDesignMode)
            {
                this.StartBackgroundConsole();
            }
        }
Пример #13
0
        protected override void InitializeDesignMode()
        {
            base.InitializeDesignMode();

            ConsoleProjectViewModel tmpProject = new ConsoleProjectViewModel
            {
                Name = "Project 1"
            };

            this.AddProject(tmpProject);

            CommandDataViewModel tmpCommand = new CommandDataViewModel()
            {
                Name        = "Level Up",
                CommandText = "cd..",
                IsFinal     = true
            };

            this.AvailableCommands["Global commands"] = new List <CommandDataViewModel>();
            this.AvailableCommands["Global commands"].Add(tmpCommand);

            this.ErrorMessage = "Design mode error";
        }