public void addActivityTest()
 {
     string CategoryName = string.Empty; // TODO: initialisez à une valeur appropriée
     Category target = new Category(CategoryName); // TODO: initialisez à une valeur appropriée
     Activity activity = null; // TODO: initialisez à une valeur appropriée
     target.addActivity(activity);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Va lire un fichier Xml décrivant la mission (Activité, Map...)
        /// </summary>
        /// <param name="Path">Le chemin vers un fichier Xml</param>
        /// <returns>Un booléen indiquant si le chargement c'est bien passé</returns>
        private bool LoadMissionXml(string Path)
        {
            XmlDocument file = new XmlDocument();

            try
            {
                file.Load(Path);
                XmlNode     noeud      = file.DocumentElement;
                XmlNodeList nomMission = noeud.SelectNodes("Name");
                this.Text = nomMission[0].InnerText;


                XmlNodeList MapMars = noeud.SelectNodes("Map");
                this.Map = MapMars[0].InnerText;

                try
                {
                    Image.FromFile(this.Map);
                }
                catch (Exception)
                {
                    MessageBox.Show("Unable to find Map picture : " + this.Map);
                    return(false);
                }

                XmlNodeList XMap = noeud.SelectNodes("X");
                this.xOrigin = int.Parse(XMap[0].InnerText);

                XmlNodeList YMap = noeud.SelectNodes("Y");
                this.yOrigin = int.Parse(YMap[0].InnerText);


                XmlNode     AstronautXml  = noeud.SelectSingleNode("Astronauts");
                XmlNodeList AstronautsXml = AstronautXml.SelectNodes("Astronaut");

                foreach (XmlNode nodeAstro in AstronautsXml)
                {
                    Astronaut A = new Astronaut(nodeAstro.InnerText);
                    Astronauts.Add(A);
                }


                XmlNode     ActivityXml   = noeud.SelectSingleNode("Activities");
                XmlNodeList ActivitiesXml = ActivityXml.ChildNodes;

                foreach (XmlNode category in ActivitiesXml)
                {
                    Category c = new Category(category.LocalName);
                    Categories.Add(c);
                    XmlNodeList Activities = category.ChildNodes;

                    foreach (XmlNode activity in Activities)
                    {
                        if (activity.LocalName == "Activity")
                        {
                            Activity a = new Activity(activity.InnerText);
                            c.addActivity(a);
                        }
                        else
                        {
                            Category c2 = new Category(activity.Name);
                            c.addActivity(c2);
                            XmlNodeList SecondaryActivity = activity.ChildNodes;

                            foreach (XmlNode SubActivity in SecondaryActivity)
                            {
                                Activity a2 = new Activity(SubActivity.InnerText);
                                c2.addActivity(a2);
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Va lire le fichier Xml lancé par l'utilisateur pour une nouvelle mission
        /// </summary>
        /// <returns>Un booléen indiquant si le chargement c'est bien passé</returns>
        private bool NewMission()
        {
            this.Astronauts.Clear();
            this.Categories.Clear();
            this.AstronautList.Items.Clear();
            saveToolStripMenuItem.Enabled = true;
            XmlDocument    file            = new XmlDocument();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog1.Filter      = "Text Files (.xml)|*.xml|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Multiselect = false;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    this.StartMission = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                    file.Load(openFileDialog1.OpenFile());
                    XmlNode     noeud      = file.DocumentElement;
                    XmlNodeList nomMission = noeud.SelectNodes("Name");
                    this.Text = nomMission[0].InnerText;


                    XmlNodeList MapMars = noeud.SelectNodes("Map");
                    this.Map = MapMars[0].InnerText;

                    try
                    {
                        Image.FromFile(this.Map);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unable to find Map picture : " + this.Map);
                        return(false);
                    }


                    XmlNodeList XMap = noeud.SelectNodes("X");
                    this.xOrigin = int.Parse(XMap[0].InnerText);

                    XmlNodeList YMap = noeud.SelectNodes("Y");
                    this.yOrigin = int.Parse(YMap[0].InnerText);


                    XmlNode     AstronautXml  = noeud.SelectSingleNode("Astronauts");
                    XmlNodeList AstronautsXml = AstronautXml.SelectNodes("Astronaut");

                    foreach (XmlNode nodeAstro in AstronautsXml)
                    {
                        Astronaut A = new Astronaut(nodeAstro.InnerText);
                        Astronauts.Add(A);
                    }


                    XmlNode     ActivityXml   = noeud.SelectSingleNode("Activities");
                    XmlNodeList ActivitiesXml = ActivityXml.ChildNodes;

                    foreach (XmlNode category in ActivitiesXml)
                    {
                        Category c = new Category(category.LocalName);
                        Categories.Add(c);
                        XmlNodeList Activities = category.ChildNodes;

                        foreach (XmlNode activity in Activities)
                        {
                            if (activity.LocalName == "Activity")
                            {
                                Activity a = new Activity(activity.InnerText);
                                c.addActivity(a);
                            }
                            else
                            {
                                Category c2 = new Category(activity.Name);
                                c.addActivity(c2);
                                XmlNodeList SecondaryActivity = activity.ChildNodes;

                                foreach (XmlNode SubActivity in SecondaryActivity)
                                {
                                    Activity a2 = new Activity(SubActivity.InnerText);
                                    c2.addActivity(a2);
                                }
                            }
                        }
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Va lire le fichier Xml lancé par l'utilisateur pour une nouvelle mission
        /// </summary>
        /// <returns>Un booléen indiquant si le chargement c'est bien passé</returns>
        private bool NewMission()
        {
            this.Astronauts.Clear();
            this.Categories.Clear();
            this.AstronautList.Items.Clear();
            saveToolStripMenuItem.Enabled = true;
            XmlDocument file = new XmlDocument();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            // Set filter options and filter index.
            openFileDialog1.Filter = "Text Files (.xml)|*.xml|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.Multiselect = false;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {

                    this.StartMission = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                    file.Load(openFileDialog1.OpenFile());
                    XmlNode noeud = file.DocumentElement;
                    XmlNodeList nomMission = noeud.SelectNodes("Name");
                    this.Text = nomMission[0].InnerText;

                    XmlNodeList MapMars = noeud.SelectNodes("Map");
                    this.Map = MapMars[0].InnerText;

                    try
                    {
                        Image.FromFile(this.Map);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unable to find Map picture : " + this.Map);
                        return false;
                    }

                    XmlNodeList XMap = noeud.SelectNodes("X");
                    this.xOrigin = int.Parse(XMap[0].InnerText);

                    XmlNodeList YMap = noeud.SelectNodes("Y");
                    this.yOrigin = int.Parse(YMap[0].InnerText);

                    XmlNode AstronautXml = noeud.SelectSingleNode("Astronauts");
                    XmlNodeList AstronautsXml = AstronautXml.SelectNodes("Astronaut");

                    foreach (XmlNode nodeAstro in AstronautsXml)
                    {
                        Astronaut A = new Astronaut(nodeAstro.InnerText);
                        Astronauts.Add(A);
                    }

                    XmlNode ActivityXml = noeud.SelectSingleNode("Activities");
                    XmlNodeList ActivitiesXml = ActivityXml.ChildNodes;

                    foreach (XmlNode category in ActivitiesXml)
                    {
                        Category c = new Category(category.LocalName);
                        Categories.Add(c);
                        XmlNodeList Activities = category.ChildNodes;

                        foreach (XmlNode activity in Activities)
                        {
                            if (activity.LocalName == "Activity")
                            {
                                Activity a = new Activity(activity.InnerText);
                                c.addActivity(a);
                            }
                            else
                            {
                                Category c2 = new Category(activity.Name);
                                c.addActivity(c2);
                                XmlNodeList SecondaryActivity = activity.ChildNodes;

                                foreach (XmlNode SubActivity in SecondaryActivity)
                                {
                                    Activity a2 = new Activity(SubActivity.InnerText);
                                    c2.addActivity(a2);
                                }
                            }
                        }
                    }

                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    return false;
                }
            }
            else
                return false;
        }
        /// <summary>
        /// Va lire un fichier Xml décrivant la mission (Activité, Map...)
        /// </summary>
        /// <param name="Path">Le chemin vers un fichier Xml</param>
        /// <returns>Un booléen indiquant si le chargement c'est bien passé</returns>
        private bool LoadMissionXml(string Path)
        {
            XmlDocument file = new XmlDocument();

                try
                {
                    file.Load(Path);
                    XmlNode noeud = file.DocumentElement;
                    XmlNodeList nomMission = noeud.SelectNodes("Name");
                    this.Text = nomMission[0].InnerText;

                    XmlNodeList MapMars = noeud.SelectNodes("Map");
                    this.Map = MapMars[0].InnerText;

                    try
                    {
                        Image.FromFile(this.Map);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unable to find Map picture : " + this.Map);
                        return false;
                    }

                XmlNodeList XMap = noeud.SelectNodes("X");
                    this.xOrigin = int.Parse(XMap[0].InnerText);

                    XmlNodeList YMap = noeud.SelectNodes("Y");
                    this.yOrigin = int.Parse(YMap[0].InnerText);

                    XmlNode AstronautXml = noeud.SelectSingleNode("Astronauts");
                    XmlNodeList AstronautsXml = AstronautXml.SelectNodes("Astronaut");

                    foreach (XmlNode nodeAstro in AstronautsXml)
                    {
                        Astronaut A = new Astronaut(nodeAstro.InnerText);
                        Astronauts.Add(A);
                    }

                    XmlNode ActivityXml = noeud.SelectSingleNode("Activities");
                    XmlNodeList ActivitiesXml = ActivityXml.ChildNodes;

                    foreach (XmlNode category in ActivitiesXml)
                    {
                        Category c = new Category(category.LocalName);
                        Categories.Add(c);
                        XmlNodeList Activities = category.ChildNodes;

                        foreach (XmlNode activity in Activities)
                        {
                            if (activity.LocalName == "Activity")
                            {
                                Activity a = new Activity(activity.InnerText);
                                c.addActivity(a);
                            }
                            else
                            {
                                Category c2 = new Category(activity.Name);
                                c.addActivity(c2);
                                XmlNodeList SecondaryActivity = activity.ChildNodes;

                                foreach (XmlNode SubActivity in SecondaryActivity)
                                {
                                    Activity a2 = new Activity(SubActivity.InnerText);
                                    c2.addActivity(a2);
                                }
                            }
                        }
                    }
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    return false;
                }
        }