private void BtnSaveProject(object sender, EventArgs e)
        {
            if (!ValidateComponents())
            {
                Toast.MakeText(this, "Por favor, revise sus campos", ToastLength.Short).Show();
                return;
            }
            Project project = new Project();

            project.id              = 0;
            project.name            = this.et_title.Text;
            project.description     = this.et_description.Text;
            project.estimated_hours = Convert.ToInt16(this.et_estimated_hours.Text);
            project.enabled         = "True";
            //prepare assignemtes
            project.assignment = lstAssignments;
            SaveProjectTask saveProjectTask = new SaveProjectTask(this, this, project);

            saveProjectTask.Execute();
        }
Пример #2
0
        public static Project LoadProject(string path)
        {
            try
            {
                Project project = JsonConvert.DeserializeObject <Project>(File.ReadAllText(path));
                // when the project has been moved
                if (project.Path != path)
                {
                    project.Path = path;
                }

                if (!Directory.Exists(project.OutputFolder))
                {
                    WarningAlert.Show("Output folder not found.\nPlease specify an output folder.");
                    System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
                    DialogResult result = dialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        project.OutputFolder = dialog.SelectedPath;
                        SaveProjectTask   task       = new SaveProjectTask(project);
                        ProcessTaskDialog saveDialog = new ProcessTaskDialog(task, "Saving...");
                        saveDialog.ShowDialog();
                        if (saveDialog.TaskToExecute.IsCanceled)
                        {
                            throw new Exception("Could not save the project.");
                        }
                    }
                    else
                    {
                        throw new Exception("Invalid path.");
                    }
                }


                if (!Directory.Exists(project.OutputFolder))
                {
                    WarningAlert.Show("Project folder not found.\nPlease specify an output folder.");
                    System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
                    DialogResult result = dialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        project.ProjectFolder = dialog.SelectedPath;
                        SaveProjectTask   task       = new SaveProjectTask(project);
                        ProcessTaskDialog saveDialog = new ProcessTaskDialog(task, "Saving...");
                        saveDialog.ShowDialog();
                        if (saveDialog.TaskToExecute.IsCanceled)
                        {
                            throw new Exception("Could not save the project.");
                        }
                    }
                    else
                    {
                        throw new Exception("Invalid path.");
                    }
                }
                return(JsonConvert.DeserializeObject <Project>(File.ReadAllText(path)));
            }
            catch (Exception ex)
            {
                ErrorAlert.Show("Could not load project:\n" + ex.Message);
            }
            return(null);
        }