Ejemplo n.º 1
0
        /// <summary>
        /// Gets the step by Id.
        /// </summary>
        /// <param name="id">The id of the targeted Step.</param>
        /// <returns></returns>
        public static Etape GetById(int id)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            Etape step = new Etape();

            try
            {
                string rslt = Helper.service.LoadFile("etape.xml").ToString();

                StreamWriter sw = new StreamWriter(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                sw.Write(rslt);
                sw.Close();


                //XPathDocument XPathDocu = new XPathDocument((Stream)Helper.service.LoadFile("Experts.xml"));
                XPathDocument     XPathDocu = new XPathDocument(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                XPathNavigator    Navigator;
                XPathNodeIterator Nodes;

                /* On affecte false à  la
                 * /* On crée un navigateur */
                Navigator = XPathDocu.CreateNavigator();

                string ExpXPath = "//etape[@id='" + id + "']";
                /* On lance la recherche */
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                /* On vérifie si la recherche a été fructueuse */
                if (Nodes.Count != 0)
                {
                    Nodes.MoveNext(); // NOTE: Necéssaire pour se placer sur le noeud recherché
                    /* Encodage des données dans la classe Etape */
                    step.setId(id);
                    Nodes.Current.MoveToFirstChild(); /* On se déplace sur le premier noeud
                                                       * enfant "Libelle" */
                    step.setName(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();       // On se déplace sur le noeud suivant "Description"
                    step.setDescription(Nodes.Current.Value);
                    Nodes.Current.MoveToNext();
                    //
                    //Get all the objects
                    //
                    step.setObjectList(XML3dObject.GetStepObjects(id));
                    Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Procedure"
                    step.setprocedure(XMLProcedure.GetById(Convert.ToInt32(Nodes.Current.Value)));
                }
                /* Si aucun expert n'a été trouvé */
                else
                {
                    step = null;
                }
            }
            catch (System.IO.FileNotFoundException x) { }
            catch (Exception x)
            {
                System.Windows.Forms.MessageBox.Show(x.ToString());
            }
            /* Renvoi de toutes les données dans une instance de la classe "etape" */
            return(step);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the list of steps for a specified procedure.
        /// </summary>
        /// <param name="Id">The id of the procedure</param>
        /// <returns></returns>
        public static List <Etape> GetByProcedure(int Id)
        {
            /* On déclare et on crée une instance des variables nécéssaires pour la recherche */
            List <Etape> steps = new List <Etape>();

            try
            {
                string rslt = Helper.service.LoadFile("etape.xml").ToString();

                StreamWriter sw = new StreamWriter(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                sw.Write(rslt);
                sw.Close();


                //XPathDocument XPathDocu = new XPathDocument((Stream)Helper.service.LoadFile("Experts.xml"));
                XPathDocument     XPathDocu = new XPathDocument(System.Windows.Forms.Application.StartupPath + "\\temp.xml");
                XPathNavigator    Navigator;
                XPathNodeIterator Nodes;

                /* On crée un navigateur */
                Navigator = XPathDocu.CreateNavigator();
                /* On crée ici l'expression XPath de recherche d'expert à  partir de l'id */

                //To eleminate the case sensetive in XPath we use the methode translate().
                string ExpXPath = "//etape[procedure='" + Id + "']";

                /* On lance la recherche */
                Nodes = Navigator.Select(Navigator.Compile(ExpXPath));
                /* On vérifie si la recherche a été fructueuse */
                if (Nodes.Count != 0)
                {
                    while (Nodes.MoveNext()) // NOTE: Necéssaire pour se placer sur le noeud recherché
                    {
                        Etape step = new Etape();
                        /* Encodage des données dans la classe Expert */
                        step.setId(Convert.ToInt32(Nodes.Current.GetAttribute("id", ""))); /* Pas besoin de chercher cette donnée vu que c'est notre
                                                                                            * critère de recherche, on peut donc directement
                                                                                            * l'encoder. */
                        Nodes.Current.MoveToFirstChild();                                  /* On se déplace sur le premier noeud
                                                                                            * enfant "Libelle" */
                        step.setName(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();                                        // On se déplace sur le noeud suivant "Description"
                        step.setDescription(Nodes.Current.Value);
                        Nodes.Current.MoveToNext();                                        // On se déplace sur le noeud suivant "Objets"
                        //
                        //Get all the objects of the current step.
                        //
                        foreach (Object3d obj in XML3dObject.GetStepObjects(step.getId()))
                        {
                            step.addObject3d(obj);
                            //System.Windows.Forms.MessageBox.Show("obj.Id: " + obj.getId() + "\nPosX: " + obj.getPosition().X
                            //    + "\nPosY: " + obj.getPosition().Y + "\nPosZ: " + obj.getPosition().Z, "XMLStep.GetByProcedure");
                        }
                        Nodes.Current.MoveToNext(); // On se déplace sur le noeud suivant "Procedure"
                        //step.setprocedure(Convert.ToInt32(Nodes.Current.Value));
                        steps.Add(step);
                    }
                }
            }
            catch (System.IO.FileNotFoundException x) { }
            catch (Exception x)
            {
                System.Windows.Forms.MessageBox.Show(x.ToString());
                return(null);
            }
            /* Renvoi de toutes les données dans une instance de la classe "Client" */
            return(steps);
        }