<?xml version="1.0" encoding="UTF-8"?> <Domain name="Test jean-marc"> <Environments> <Environment name="exploitation"> <Applications> <Application name="Appli1"> <Jobs> <Job name="appli1_exploitation_Job1"> </Job> <Job name="appli1_exploitation_Job2"> </Job> <Job name="appli1_exploitation_Job3"> </Job> <Job name="appli1_exploitation_Job4"> </Job> </Jobs> </Application> <Application name="Appli2"> <Jobs> <Job name="appli2_exploitation_Job5"> </Job> </Jobs> </Application> </Applications> </Environment> <Environment name="production"> <Applications> <Application name="Appli3"> <Jobs> <Job name="appli3_production_Job1"> </Job> <Job name="appli3_production_Job2"> </Job> </Jobs> </Application> <Application name="Appli4"> <Jobs> <Job name="appli4_production_Job3"> </Job> </Jobs> </Application> </Applications> </Environment> </Environments> </Domain>
<?xml version="1.0" encoding="UTF-8"?> <Customers> <Customer name="SAVEMUTU" product="VTOM" axone="JA888" infocgn="Non"> <Alias name="exploitation" contrat="TOTO" codebien="I25 Incident Ordonnancement"></Alias> <Alias name="production" contrat="TATA" codebien="I24 Storage Incident"></Alias> <Parameters> <Parameter>Environnement</Parameter> <Parameter>Job</Parameter> </Parameters> </Customer> <Customer name="CLIENT1" product="VTOM" axone="JA4567" infocgn="Oui"> <Alias name="CLIENT1" contrat="TITI" codebien="I22 Server Incident"></Alias> <Parameters> <Parameter>Application</Parameter> </Parameters> </Customer> </Customers>
Public Class ItemsConfig Public Property Name() As String Public Property Contract() As String Public Property Category() As String End Class Public Class ConfigCustomer Public Property Name() As String Public Property NameAlias() As List(Of ItemsConfig) Public Property Parameters() As List(Of String) Public Property Infocgn() As String Public Property Axone_Contract() As String Public Property Product() As String Public Shared Function LoadFileConfig(ByVal Path As String) As List(Of ConfigCustomer) Dim xdoc As XDocument = XDocument.Load(Path) Return ( From c In xdoc.Descendants("Customer") Select New ConfigCustomer With {.Name = c.Attribute("name").Value, _ .Product = c.Attribute("product").Value, _ .Infocgn = c.Attribute("infocgn").Value, _ .Axone_Contract = c.Attribute("axone").Value, _ .Parameters = (From p In c.Descendants("Parameter") Select p.Value).ToList(), _ .NameAlias = (From a In c.Descendants("Alias") Select New ItemsConfig With {.Name = a.Attribute("name").Value, _ .Contract = a.Attribute("contrat").Value, _ .Category = a.Attribute("codebien").Value }).ToList()}).ToList() End Function End Class
<?xml version="1.0" encoding="UTF-8"?>
<Customers>
<Customer name="SAVEMUTU" product="VTOM" axone="JA109119" infocgn="Non">
<Alias name="exploitation" contrat="INTERNE" codebien="I25 Incident Ordonnancement"></Alias>
<Alias name="SV_CLIENT4" contrat="CLIENT4" codebien="I20 Incident Sauvegarde"></Alias>
<Alias name="SV_CLIENT5" contrat="CLIENT5" codebien="I20 Incident Sauvegarde"></Alias>
<Alias name="SV_CLIENT6" contrat="CLIENT6" codebien="I20 Incident Sauvegarde"></Alias>
<Parameters>
<Parameter>Environnement</Parameter>
<Parameter>Application</Parameter>
<Parameter>Job</Parameter>
<Parameter>DDO</Parameter>
<Parameter>Serveur</Parameter>
<Parameter>TypeJob</Parameter>
<Parameter>Script</Parameter>
<Parameter>ParametresScript</Parameter>
<Parameter>CycleJob</Parameter>
<Parameter>CommentaireJob</Parameter>
</Parameters>
</Customer>
Dim listofenv As List(Of Env) = (
From d In xdoc.Descendants("Environment")
Select New Env With {
.Name = d.@name, _
.Serveur = d.@host, _
.DateBascule = New String(" "c, 2) & d.@date, _
.Formule = returnFieldEmpty(If(d.Elements("Planning").Count() > 0, d.Elements("Planning").Value, Nothing)), _
.Planning = String.Empty, _
.Queue = d.@queue, _
.Profil = d.@user, _
.Applications = (
From a In d.Descendants("Application")
Select New App With {
.Name = a.@name, _
.Serveur = If(a.Attributes("host").Count() > 0, a.@host, Nothing), _
.RessourcesApp = (
From r In a.Descendants("ExpectedResource")
Select New Ressourcesapplication With {
.Name = r.@resource,
.Type = r.@operator,
.Valeur = r.@Value
}).ToList(),
.DateBascule = New String(" "c, 2) & If(a.Attributes("date").Count() > 0, a.@date, Nothing), _
.Formule = returnFieldEmpty(If(a.Elements("Planning").Count() > 0, a.Elements("Planning").Value, Nothing)), _
.Planning = If(a.Elements("Planning").Count() > 0,
"[" & a.Element("Planning").@daysInWeek & "],[" & _
a.Element("Planning").@daysInMonth & "],[" & _
a.Element("Planning").@weeksInMonth & "],[" & _
a.Element("Planning").@monthsInYear & "]", Nothing), _
.Queue = If(a.Attributes("queue").Count() > 0, a.@queue, Nothing), _
.Profil = If(a.Attributes("user").Count() > 0, a.@user, Nothing), _
.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(),
.Serveur = returnHost(If(j.Attributes("host").Count() > 0, j.@host, String.Empty), j.@name), _
.CommentaireApp = If(a.Attributes("comment").Count() > 0, a.@comment, Nothing), _
.CommentaireJob = returnFieldEmpty(If(j.Attributes("comment").Count() > 0, j.@comment, Nothing)), _
.Script = returnFieldEmpty(If(j.Element("Script").Value().ToString = "#M3#",
j.Element("Script").Value().ToUpper,
j.Element("Script").Value().ToLower)), _
.Parametres = If(j.Elements("Parameters").Count() = 0, Nothing, (
From p In j.Descendants("Parameter")
Select p.Value).ToList()), _
.Trame = returnTrame(If(j.Attributes("family").Count() > 0, j.@family, String.Empty)), _
.ModeExecEnv = New String(" "c, 2) & returnGeneric(d.@enginePid), _
.ModeExecApp = New String(" "c, 2) & returnGeneric(a.@mode), _
.ModeExecJob = New String(" "c, 2) & returnGeneric(j.@mode), _
.TypeJob = returnTypeJob(If(j.Attributes("jobType").Count() > 0, j.@jobType, Nothing), j.Element("Script").Value.ToString), _
.TypeFrequence = New String(" "c, 2) & returnTypeFrequency(j.@onDemand), _
.Frequence = New String(" "c, 1) & returnGeneric(j.@frequency), _
.Cyclique = New String(" "c, 1) & returnYesNo(j.@cycleEnabled), _
.CycleJob = j.@cycle, _
.HeureDebut = j.@minStart, _
.HeureFin = j.@maxStart, _
.DebutDerniereExecution = returnConvertTime(Convert.ToInt32(j.@timeBegin)), _
.FinDerniereExecution = returnConvertTime(Convert.ToInt32(j.@timeEnd)), _
.Duree = returnTimeDiff(CDate(.DebutDerniereExecution), CDate(.FinDerniereExecution)), _
.DateBascule = New String(" "c, 2) & If(j.Attributes("date").Count() > 0, j.@date, Nothing), _
.Queue = If(j.Attributes("queue").Count() > 0, j.@queue, Nothing), _
.Formule = returnFieldEmpty(If(j.Elements("Planning").Count() > 0, j.Elements("Planning").Value, Nothing)), _
.Planning = If(j.Elements("Planning").Count() > 0,
"[" & j.Element("Planning").@daysInWeek & "],[" & _
j.Element("Planning").@daysInMonth & "],[" & _
j.Element("Planning").@weeksInMonth & "],[" & _
j.Element("Planning").@monthsInYearlue & "]", Nothing), _
.Profil = If(j.Attributes("user").Count() > 0, j.@user, Nothing), _
.ApplicationPredecesseur = returnLinks(parent, child, d.@name & _
New String("/"c, 1) & a.@name), _
.ApplicationSuccesseur = returnLinks(child, parent, d.@name & _
New String("/"c, 1) & a.@name), _
.JobPredecesseur = returnLinks(parent, child, d.@name & _
New String("/"c, 1) & a.@name & _
New String("/"c, 1) & j.@name), _
.JobSuccesseur = returnLinks(child, parent, d.@name & _
New String("/"c, 1) & a.@name & _
New String("/"c, 1) & j.@name), _
.Alarme = returnAlarm(d.@name & New String("/"c, 1) &
a.@name & New String("/"c, 1) & j.@name), _
.CodeContrat = returnTicketing(customer, d.@name, "Contract"), _
.Categorie = returnTicketing(customer, d.@name, "Category")
}).ToList()}).ToList()}).ToList()
ListOfJob = (From k In listofenv, a In k.Applications, j In a.Jobs
Select j.AffecteParent(a, k)).OrderBy(Function(j) j.EnvironnementApplicationJob).ToList()
Private Sub CreateDataSetTables(ByVal choice As String, ByVal customer As String, ByVal aliascustomer As String)
' Création Collection arrayListMOP en fonction du choix (Client, Delta, SAVEMUTU ou SV_)
'
If customer.ToString = aliascustomer.ToString Then
' Toutes les Consignes Client ou SAVEMUTU
' Création Collection arrayListMOP pour génération des Consignes .docx
'
' Contrôle des jobs avec trame - Champ family renseigné dans VTOM
Dim listjob = ListOfJob.Where(Function(c) (c.Trame <> String.Empty)).ToList
For Each items In listjob
Dim env As String = items.Environnement
Dim app As String = items.Application
Dim job As String = items.Job
Dim trame As String = returnTrame(items.Trame)
Dim tramefile As String = returnTrameFile(items.Trame)
Dim configalias As String = listofconfigcustomer.Single(Function(c) c.Name = customer).NameAlias.Item(0).Name
Dim configcontract As String = items.CodeContrat
Dim configcategory As String = items.Categorie
Dim configparameters = listofconfigcustomer.Single(Function(c) c.Name = customer).Parameters
Dim parameters = listofconfigcustomer.Single(Function(c) c.Name = customer).Parameters
Dim listparameters As List(Of String) = New List(Of String)()
For i As Integer = 0 To parameters.Count - 1
listparameters.Add(i)
' parameters(i).ToString = Serveur ou TypeJob ou Application ou etc ....
' c'est ce champ que je souhaite rechercher dans listjob
Next i
Next items
End If
End Function
Dim env As String = items.Environnement Dim app As String = items.Application Dim job As String = items.Job Dim trame As String = returnTrame(items.Trame) & Environment.NewLine Dim tramefile As String = returnTrameFile(items.Trame) Dim configalias As String = listofconfigcustomer.Single(Function(c) c.Name = customer).NameAlias.Item(0).Name Dim configcontract As String = items.CodeContrat Dim configcategory As String = items.Categorie
Dim lineMOP As String = customer & "." & _ items.Environnement & "." & items.Application & "." & _ items.Job & "," & _ returnFile(items.Trame) & "," & _ returnTrameFile(items.Trame) & "," & _ returnTrameFile(items.Trame) & "," & _ items.CodeContrat & "," & _ items.Categorie & "," Dim configparameters = listofconfigcustomer.Single(Function(c) c.Name = customer).Parameters For i As Integer = 0 To configparameters.Count - 1 lineMOP += lineMOP & returnItemMOP(configparameters(i) & "," Next i arrayListMOP.Add(lineMOP) Function ReturnItemMOP(ByVal e As String) As String Select Case e Case "Environnement" : Return items.Environnement Case "Application" : Return items.Application Case "Job" : Case "Serveur" : Case "CommentaireApp" : Case "CommentaireJob" : Case "ModeExecEnv" : Case "ModeExecApp" : Case "ModeExecJob" : Case "TypeJob" : Case "Script" : Case "ParametresScript" : Case "RessourcesApp" : Case "RessourcesJob" : Case "TypeFrequence" : Case "Frequence" : Case "Cyclique" : Case "CycleJob" : Case "HeureDebut" : Case "HeureFin" : Case "DebutDerniereExecution" : Case "FinDerniereExecution" : Case "Duree" : Case "DateBascule" : Case "Formule" : Case "Planning" : Case "Queue" : Case "Profil" : Case "ApplicationPredecesseur" : Case "ApplicationSuccesseur" : Case "JobPredecesseur" : Case "JobSuccesseur" : Case "Alarme" : Case Else : Return String.Empty End Select End Function
Nous sommes dans le cas 1.
Ta méthode fonctionne, mais a le désavantage de devoir être retouchée à chaque changement dans la classe Job.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Personne Public Sub New(ByVal Nom As String, ByVal Prenom As String, ByVal Naissance As Date) Me.Nom = Nom Me.Prenom = Prenom Me.Naissance = Naissance 'j'affecte la propriété comme ça l'age sera calculé End Sub Private _naissance As DateTime Public Property Naissance() As DateTime Get Return _naissance End Get Set(ByVal value As Date) _naissance = value Age = DateTime.Now.Year - _naissance.Year End Set End Property Public Property Nom() As String Public Property Prenom() As String Private _age As Integer Public Property Age() As Integer Get Return _age End Get Private Set(ByVal value As Integer) _age = value End Set End Property End Class
Public Class ResultatJMO Public Property Age() As Integer Public Property Parametres() As List(Of String)'je mets une liste et pas un arraylist car linq sait caster tout seul en liste. End Class
Dim personnes As New List(Of Personne)() personnes.Add(New Personne("Di", "Alain", Date.Parse("01/01/2010"))) personnes.Add(New Personne("Sort", "Jean", Date.Parse("01/01/2011"))) personnes.Add(New Personne("Zétofrais", "Mélanie", Date.Parse("02/02/2010"))) personnes.Add(New Personne("Croche", "Sara", Date.Parse("02/02/2011"))) Dim ageATrouver As Integer = 5 Dim champsARetourner() As String = {"Prenom","Nom" } Dim resultats As New List(Of ResultatJMO)() For Each p As Personne In personnes.Where(Function(pp) pp.Age = ageATrouver) Dim r As New ResultatJMO() r.Age = ageATrouver r.Parametres = New List(Of String)() For Each champ As String In champsARetourner Dim pi As PropertyInfo = p.GetType().GetProperty(champ) r.Parametres.Add(CStr(pi.GetValue(p))) Next champ resultats.Add(r) Next p
Dim resultats As List(Of ResultatJMO) = ( From p In personnes.Where(Function(pp) pp.Age = ageATrouver) Select New ResultatJMO With {.Age = ageATrouver, .Parametres = ( From c In champsARetourner Let pi = p.GetType().GetProperty(c) Select CStr(pi.GetValue(p))).ToList() }).ToList()
4 déc. 2015 à 20:52
4 déc. 2015 à 20:57
le <Customer name="SAVEMUTU"> du fichier de config est le nom du fichier xml car je dispose de x fichiers xml client.
Bonne soirée
@+ jean-marc