Exemplo n.º 1
0
        //Saves the project to the specified filepath
        //filepath - Directory, name and file extension (Example: './My Project.xml')
        //Returns a flag indicating whether the project saved successfully
        public bool Save(string filepath)
        {
            try
            {
                //Create XML serializer
                XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <Task>));

                //Create stream writer
                using (StreamWriter streamWriter = new StreamWriter(filepath))
                {
                    //Serialize project tasks and write to the filepath
                    xmlSerializer.Serialize(streamWriter, Tasks);
                }

                //If at least one subscription to the on project saved event exists
                if (OnProjectSaved != null)
                {
                    //Invoke the on project saved event
                    OnProjectSaved.Invoke(this);
                }

                //Successfully saved
                return(true);
            }
            catch (Exception exception)
            {
                //Display exception message
                MessageBox.Show(exception.Message);

                //Failed to save
                return(false);
            }
        }
Exemplo n.º 2
0
 internal void ProjectSaved()
 {
     ProjectChanged = false;
     OnProjectSaved?.Invoke(this, EventArgs.Empty);
 }