Exemple #1
0
        public ProjectModel CreateNewProject(NewProjectInfoModel projectInfo)
        {
            if (!projectInfo.CreateProject)
            {
                throw new Exception("Can not create a project that is flagged as do not create.");
            }

            var newProject = this.ProjectWriter.CreateNewProject(projectInfo);

            CurrentProject = newProject;

            return(newProject);
        }
        private void CreateNewProject()
        {
            NewProjectInfoModel info = ProjectManager.GetNewProjectInfo();

            if (!info.CreateProject)
            {
                return;
            }

            var projectModel = ProjectManager.CreateNewProject(info);

            this.ProjectViewModel = new ProjectViewModel(projectModel);
        }
Exemple #3
0
        public NewProjectInfoModel GetNewProjectInfo()
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.CreatePrompt = false;
            dlg.Title        = "Select New Project File";
            dlg.Filter       = string.Format("{0} (*.{1})|*.{1}", ProjectWriter.ExtensionDescription, ProjectWriter.FileExtension);

            bool keepGoing = dlg.ShowDialog(Application.Current.MainWindow) == true;

            NewProjectInfoModel info = new NewProjectInfoModel();

            info.CreateProject = keepGoing;
            info.FilePath      = dlg.FileName;

            return(info);
        }
Exemple #4
0
        public ProjectModel CreateNewProject(NewProjectInfoModel projectInformation)
        {
            string filePath     = projectInformation.FilePath;
            bool   canCreateNew = !File.Exists(filePath);
            string projectName  = Path.GetFileNameWithoutExtension(filePath);

            if (!canCreateNew)
            {
                var userInput =
                    MessageBox.Show(
                        string.Format("Project: {0} already exists in selected location. Do you wish to replace it?", projectName),
                        "Problem with Project Creation",
                        MessageBoxButton.YesNo,
                        MessageBoxImage.Question);

                if (userInput == MessageBoxResult.Yes)
                {
                    while (File.Exists(filePath))
                    {
                        bool forgetIt = false;
                        try
                        {
                            File.Delete(filePath);

                            // Give the system some time to get rid of the file
                            // Side Note: On a slow system or a system underload,
                            //			  this might not be enough time.
                            Thread.Sleep(5);
                        }
                        catch (Exception ex)
                        {
                            userInput =
                                MessageBox.Show(
                                    "There was a problem getting rid of the old project file. Do you wish to try again?",
                                    "Deletion Problem",
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Error);

                            forgetIt = userInput == MessageBoxResult.No;
                        }

                        if (forgetIt)
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }


            var defaultLayer = new ObstacleLayerModel()
            {
                LayerName = "Layer 1"
            };

            var obstacleData = new ObstacleDataModel();

            obstacleData.AddLayer(defaultLayer);

            var raceTrackModel = new RaceTrackModel()
            {
                RaceTrackImage = null,
                Obstacles      = obstacleData
            };

            var projectModel = new ProjectModelZip(m_projectManager)
            {
                ProjectFilePath = filePath,
                RaceTrackModel  = raceTrackModel
            };

            SaveProject(projectModel);

            return(projectModel);
        }