Linq extraction fichier XML - récupération champ

Résolu
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 11 juil. 2015 à 12:16
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 - 13 juil. 2015 à 08:54
Bonjour,

Extrait fichier xml
    <JobApplicationServer name="PRD_M3" comment="Connexion M3 au serveur AS400 de Production" type="M3">
<Properties>
<Property key="VTM3_PASSWORD" value="Klj32+vV"/>
<Property key="VTM3_PORT" value="6800"/>
<Property key="VTM3_SERVER" value="AMO102P"/>
<Property key="VTM3_USER" value="SVA-ZA-VHO"/>
</Properties>
</JobApplicationServer>
Je souhaite extraire la value de la 3 troisième clé de "Property".
Actuellement, j'ai écrit
    Private Function returnHostJob(ByVal e As String) As String
If Not IsNothing(e) Then
Dim myLinkJob = From items In MyDoc.Root.Elements("JobApplicationServers").Elements("JobApplicationServer") _
Where items.Attribute("name").Value = e _
Select items

For Each xEle As XElement In myLinkJob
For i As Integer = 2 To xEle.Elements("Properties").Elements("Property").Attributes("value").Count - 1
Return xEle.Elements("Properties").Elements("Property").Attributes("value")(i).Value & " (" & e & ")"
Exit Function
Next
Next
End If
Return e
End Function
où "e" pour cet exemple correspond à "PRD_M3".
La fonction me retourne correctement "AMO102P".

Question:
Est-ce la bonne méthode pour extraire cette donnée ?
J'en doute !!!


jean-marc

6 réponses

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
11 juil. 2015 à 12:25
Suite à re-lecture, j'ai testé
Private Function returnHostJob(ByVal e As String) As String
If Not IsNothing(e) Then
Dim myLinkJob = From items In MyDoc.Root.Elements("JobApplicationServers").Elements("JobApplicationServer") _
Where items.Attribute("name").Value = e _
Select items

Return myLinkJob.Elements("Properties").Elements("Property").Attributes("value")(2).Value & " (" & e & ")"
Exit Function
End If
Return e
End Function
qui me renvoie bien la donnée.
Est-ce la solution ???
0
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
11 juil. 2015 à 14:27
Salut, tu en as plusieurs des JobApplicationServer?
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
11 juil. 2015 à 15:16
bonjour Whismeril,

Oui, il y en a plusieurs.

Pour les repérer dans le xml
    </JobApplicationServer>
<JobApplicationServer name="PRD_M3" comment="Connexion M3 au serveur AS400 de Production" type="M3">
<Properties>
<Property key="VTM3_PASSWORD" value="Klj32+gG"/>
<Property key="VTM3_PORT" value="6800"/>
<Property key="VTM3_SERVER" value="AMO102P"/>
<Property key="VTM3_USER" value="SVC-ZZ-VT"/>
</Properties>
</JobApplicationServer>
<JobApplicationServer name="REC_M3" comment="Connexion M3 au serveur AS400 de Developpement" type="M3">
<Properties>
<Property ke

et
                        .Jobs = (
From j In a.Descendants("Job")
Select New JOB With {
.EnvironnementApplicationJob = d.@name & "_" & a.@name & "_" & j.@name,
.DDO = returnDDO(d.@name, a.@name, a.@comment), _
.Job = j.@name, _
.RessourcesJobs = (
From l In j.Descendants("ExpectedResource")
Select New RessourceJob With {
.Name = l.@resource,
.Type = l.@operator,
.Valeur = l.Element("Value").Value
}).ToList(),
.JobAppServeur = returnHostJob(If(j.Attributes("jobApplicationServer").Count() > 0,
j.@jobApplicationServer, Nothing)), _
.Serveur = returnHost(If(j.Attributes("host").Count() > 0,
j.@host, Nothing)), _
.TypeJob = returnTypeJob(If(j.Attributes("jobType").Count() > 0, j.@jobType, Nothing)), _
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
11 juil. 2015 à 18:50
J'ai oublié de préciser que je me sers de
<Job name="TEST_CX_M3DEV" retained="0" family="TR2" ... queue="queue_vt2m3" jobType="M3" jobApplicationServer="DEV_M3" mepType="E">
pour repérer si un job dépend d'un jobApplicationServer
0
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
11 juil. 2015 à 22:47
Bonsoir, je ne suis pas sur de bien comprendre, la liste de jobApplicationServer, est indépendante de ton arborescence (environnement, application, job) dans le fichier xml, mais tu veux renseigner dans les jobs la 3eme valeur de property, c'est bien ça?

Et c'est systématiquement la 3eme, ou celle dont la clé est "VTM3_SERVER" qui pourrait avoir une autre place?
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
12 juil. 2015 à 08:02
Bonjour Whismeril,

Oui, la liste JobApllicationServer est indépendante.
  </Icons>
<JobApplicationServers>
<JobApplicationServer name="SMTP_CLIENT" comment="" type="MAIL">
<Properties>
<Property key="VTMAIL_ENCRYPTION" value="none"/>
<Property key="VTMAIL_PASSWORD" value=""/>
<Property key="VTMAIL_PORT" value="25"/>
<Property key="VTMAIL_SERVER" value="172.22.1.50"/>
<Property key="VTMAIL_USE_AUTH" value="false"/>
</Properties>
</JobApplicationServer>
<JobApplicationServer name="PRD_M3" comment="Connexion M3 au serveur AS400 de Production" type="M3">
<Properties>
<Property key="VTM3_PASSWORD" value="Klj32+gG"/>
<Property key="VTM3_PORT" value="6800"/>
<Property key="VTM3_SERVER" value="AMO102P"/>
<Property key="VTM3_USER" value="SVC-ZZ-VT"/>
</Properties>
</JobApplicationServer>
<JobApplicationServer name="REC_M3" comment="Connexion M3 au serveur AS400 de Developpement" type="M3">
<Properties>
<Property key="VTM3_PASSWORD" value="Klj32+gG"/>
<Property key="VTM3_PORT" value="56800"/>
<Property key="VTM3_SERVER" value="AMO303R"/>
<Property key="VTM3_USER" value="SVC-ZZ-VT"/>
</Properties>
</JobApplicationServer>
<JobApplicationServer name="DEV_M3" comment="Connexion M3 au serveur AS400 de Developpement" type="M3">
<Properties>
<Property key="VTM3_PASSWORD" value="Klj32+gG"/>
<Property key="VTM3_PORT" value="36800"/>
<Property key="VTM3_SERVER" value="AMO303R"/>
<Property key="VTM3_USER" value="SVC-ZZ-VT"/>
</Properties>
</JobApplicationServer>
</JobApplicationServers>
</Domain>


Dans l'arborescence, Environnement \ Application \ Job, il y a deux possibilités:
1)
<Job name="P0007J0109" retained="0" family="TR2" comment="BPW : Extraction des donnees PivotLink et envoi sur le FTP"  frequency="D" onDemand="0" isAsked="0" cycleEnabled="0" cycle="00:00:00"  mepType="E">
<Script><![CDATA#c:\VTOM5\SCRIPTS\ROS_Start_Sqlagent_Job.bat]></Script>
<Parameters>
<Parameter><![CDATA[SMO-BI101P\BPW]]></Parameter>
<Parameter><![CDATA[BPW_Send_PivotLink]]></Parameter>
</Parameters>
<Node objectType="job" x="547" y="690"/>
</Job>
Ici, c'est un job classique, sur la ligne "<Job name=", il n'y a pas de " type="M3" ". Le host du serveur est hérité de l'application.

2)
<Job name="P0113H0106" retained="0" family="TR6" comment="ARTICLE HEBDO - Available to Promise. Re-creat" frequency="D" cycleEnabled="0" cycle="00:00:00" queue="queue_vt2m3" jobType="M3" jobApplicationServer="PRD_M3" mepType="E">

Ici, sur la ligne "<Job name=", il y a type="M3" et jobApplicationServer="PRD_M3". Le nom du serveur est donc à aller chercher dans le <JobApplicationServer> correspondant.


Pour l'instant, j'"ai aussi modifié la classe JOB
    Public Property JobAppServeur() As String

Private privateServeur As String
Public Property Serveur() As String
Get
' Si le champ est vide, on retourne celui de son parent
If String.IsNullOrWhiteSpace(privateServeur) Then
Return parent.Serveur
Else
Return privateServeur
End If
End Get
Set(ByVal value As String)
privateServeur = value & JobAppServeur
End Set
End Property
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
12 juil. 2015 à 08:03
Capture du formulaire

0
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
Modifié par Whismeril le 12/07/2015 à 08:51
Bonjour,
comme souvent il y a moultes façons de faire, et tu en as trouvé par toi même.
Ce que je ferais, c'est extraire une liste de JobApplicationServer, contant un dictionnaire de Propriete.
Le dictionnaire est une collection qui associe deux données: une clé et une valeur, et dont tu peux retourner une valeur en entrant la clé, je pense que ça colle bien.
Cette extraction serait à faire avant la requête qui crée mesJobs.
Il faudrait modifier la méthode AffecteParent en ajoutant la liste de JobApplicationServer en paramètre et affecterait le host si nécessaire à ce moment là.

Modérer m'amène à intervenir dans de nombreux posts, mais les seuls langages que je connaisses sont le C# et un peu de VB. Pour vos codes pensez à la coloration.
Réponse trouvée ->Question Résolue
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
12 juil. 2015 à 09:02
Merci de tes conseils.
Je m'en vais donc tester la collection dictionary, que j'utilisais à outrance en vbs.

Bon dimanche,
jean-marc
0
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
12 juil. 2015 à 09:26
Remarque je n'ai jamais essayé d'en faire un depuis linq (xml ou pas) et là je n'ai pas le temps
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27 > Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024
12 juil. 2015 à 10:11
Pour le dictionnaire
Private DicoServersM3 As New Dictionary(Of String, String)

Private Sub CreateDicoServersM3()
Dim myServersM3 = From items In MyDoc.Root.Elements("JobApplicationServers").Elements("JobApplicationServer") _
Where items.@type = "M3"
Select items

For Each xEle As XElement In myServersM3
DicoServersM3.Add(xEle.@name, xEle.Elements("Properties").Elements("Property").Attributes("value")(2).Value)
Next xEle
End Sub
        Call CreateDicoServersM3()

For Each kvp As KeyValuePair(Of String, String) In DicoServersM3
TextBox2.Text = TextBox2.Text & kvp.Key & " (" & kvp.Value & ")" & Environment.NewLine
Next kvp

me retourne
PRD_M3 (AMO102P)
REC_M3 (AMO303R)
DEV_M3 (AMO303R)
0
Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656 > cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018
12 juil. 2015 à 14:11
Super, ça y est t'es lâché Linq
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27 > Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024
13 juil. 2015 à 07:31
Bonjour le Forum,

bonjour Whismeril,

Je suis passé par deux dictionnaires
Private Sub CreateDicoServersM3()
Dim myServersM3 = From items In MyDoc.Root.Elements("JobApplicationServers").Elements("JobApplicationServer") _
Where items.@type = "M3"
Select items

For Each xEle As XElement In myServersM3
DicoServersM3.Add(xEle.@name, xEle.Elements("Properties").Elements("Property").Attributes("value")(2).Value)
Next xEle
End Sub

Private Sub CreateDicoJobsM3()
Dim myJobsM3 = From items In MyDoc.Descendants("Environment").Descendants("Application").Descendants("Job") _
Where items.@jobType = "M3"
Select items

For Each xEle As XElement In myJobsM3
If DicoServersM3.ContainsKey(xEle.@jobApplicationServer) Then
DicoJobsM3.Add(xEle.@name, DicoServersM3(xEle.@jobApplicationServer))
End If
Next xEle
End Sub

.Serveur = returnHost(If(j.Attributes("host").Count() > 0, j.@host, Nothing), j.@name), _
pour la ListOf JOB
et une fonction pour retourner le nom du serveur
Private Function returnHost(ByVal e As String, ByVal name As String) As String
If DicoJobsM3.ContainsKey(name) Then
Return DicoJobsM3(name)
Else
Return e
End If
End Function

Les dictionnaires en VB.Net offrent davantage de possibilité qu'en vbs !!!
Bonne journée,
Je valide ce post.

jean-marc
0
Rejoignez-nous