Dim lignes As List(Of String) = File.ReadAllLines("---- presets ----.xml").ToList() 'on met toutes les lignes du fichier dans une liste lignes(1) = "<MA>" Dim texteCorrige As String = String.Join(Environment.NewLine, lignes) 'on refait un texte complet texteCorrige = texteCorrige.Replace("xsi:nil=""true""", "")'on supprime toutes les occurrences de "xsi:nil="true" Dim xDoc As XDocument = XDocument.Parse(texteCorrige) 'on parse le texte corrigé Dim presetsWidthHandle As List(Of Les_Presets) = ( From p In xDoc.Descendants("Preset") Where p.Element("Values")?.Element("ChannelTypes")?.Elements("PresetValue")?.Any(Function(x) x IsNot Nothing) Select New Les_Presets With { .Name = p.Attribute("name")?.Value } ).ToList()
<Preset index="12" name="313" SpecialUse="Normal"> <Values> <Channels> <PresetValue> <Handle name="301 0.12"> <No>1</No> <No>0</No> <No>12</No> </Handle> <Channel fixture_id="3" channel_id="3" attribute_name="SHUTTER" /> </PresetValue> . . .
<PresetValue Value="41.601875"> <Channel fixture_id="3" channel_id="3" attribute_name="SHUTTER" />
<Preset index="12" name="313" SpecialUse="Normal"> <Values> <Channels> <PresetValue Value="41.601875"> <Channel fixture_id="3" channel_id="3" attribute_name="SHUTTER" /> </PresetValue> ...
12 - 1,parce que
"PresetPool" 0parce que
l'attribute_name SHUTTER du fixture 10je ne voie pas d'où sort le 10.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<Preset index="227" name="201 francois" preset_mode="Global" SpecialUse="Normal"> <Values> <ChannelTypes> <PresetValue Value="69.5"> <ChannelType fixture_type="Alpha Profile 800ST Standard Lamp on" module="1" attribute="COLORRGB1" /> </PresetValue> <PresetValue Value="88.25"> <ChannelType fixture_type="Alpha Profile 800ST Standard Lamp on" module="1" attribute="COLORRGB2" /> </PresetValue> <PresetValue Value="93"> <ChannelType fixture_type="Alpha Profile 800ST Standard Lamp on" module="1" attribute="COLORRGB3" /> </PresetValue> <PresetValue Value="0"> <ChannelType fixture_type="Alpha Profile 800ST Standard Lamp on" module="1" attribute="COLOR1" /> </PresetValue> <PresetValue Value="0"> <ChannelType fixture_type="Alpha Profile 800ST Standard Lamp on" module="1" attribute="COLORMIXER" /> </PresetValue> <PresetValue> <Handle name="L201 4.246"> <No>1</No> <No>4</No> <No>246</No> </Handle> <ChannelType fixture_type="933+cc10couleurs 00" module="1" attribute="SCROLLER" /> </PresetValue> </ChannelTypes> </Values> </Preset>
En résumé, je voudrais supprimer le noeud Handle(la référence à l'autre preset) pour mettre à la place les valeur de la preset référencée en fonction du fixture_id et de "attribute_name" :
Imports System.Globalization Imports System.Runtime.CompilerServices Module Extension <Extension()> Function ToInt(ByVal Texte As String) As Integer Dim res As Integer = -1 Integer.TryParse(Texte, res) Return res End Function <Extension()> Function ToInt(ByVal Attribut As XAttribute) As Integer If Attribut Is Nothing Then Return -1 Return Attribut.Value.ToInt() End Function <Extension()> Function ToInt(ByVal Element As XElement) As Integer If Element Is Nothing Then Return -1 Return Element.Value.ToInt() End Function <Extension()> Function ToDouble(ByVal Texte As String) As Double Dim res As Double = Double.NaN Double.TryParse(Texte.Replace(","c, "."c), NumberStyles.Number, CultureInfo.InvariantCulture, res) Return res End Function <Extension()> Function ToDouble(ByVal Attribut As XAttribute) As Double If Attribut Is Nothing Then Return Double.NaN Return Attribut.Value.ToDouble() End Function <Extension()> Function ToDouble(ByVal Element As XElement) As Double If Element Is Nothing Then Return Double.NaN Return Element.Value.ToDouble() End Function End Module
Class PresetValue Public Property FixtureId As Integer Public Property ChannelId As Integer Public Property AttributeName As String Public Property Value As Double End Class Class Preset Public Property ID As Integer Public Property Name As String Public Property PresetValues As List(Of PresetValue) End Class Class PresetPool Public Property ID As Integer Public Property Presets As List(Of Preset) End Class
Dim lignes As List(Of String) = File.ReadAllLines("---- presets ----.xml").ToList() lignes(1) = "<MA>" Dim texteCorrige As String = String.Join(Environment.NewLine, lignes) texteCorrige = texteCorrige.Replace("xsi:nil=""true""", "") Dim xdoc As XDocument = XDocument.Parse(texteCorrige) Dim passe1 = (From pp In xdoc.Descendants("PresetPool") Select New With { .Index = pp.Attribute("index").ToInt(), .Presets = (From p In pp.Descendants("Preset") Select New With { .Index = p.Attribute("index").ToInt(), .Name = p.Attribute("name")?.Value, .PresetValues = (From pv In p.Descendants("PresetValue") Let c = pv.Element("Channel") Let h = pv.Element("Handle") Select New With { .Value = pv.Attribute("Value").ToDouble(), .Channel = If(c IsNot Nothing, New With { .FixtureId = c.Attribute("fixture_id").ToInt(), .ChanelId = c.Attribute("channel_id").ToInt(), .AttributeName = c.Attribute("attribute_name").Value }, Nothing), .Handle = If(h IsNot Nothing, New With { .name = h.Attribute("name")?.Value, .PresetPoolId = h.Elements("No").ElementAt(1).ToInt(), .PresetId = h.Elements("No").ElementAt(2).ToInt() - 1 }, Nothing) }).ToList() }).ToList() }).ToList() Dim presetPools As List(Of PresetPool) = New List(Of PresetPool)() For Each pp In passe1 Dim psp As PresetPool = New PresetPool With { .ID = pp.Index, .Presets = New List(Of Preset)() } presetPools.Add(psp) For Each p In pp.Presets Dim ps As Preset = New Preset With { .ID = p.Index, .Name = p.Name, .PresetValues = New List(Of PresetValue)() } psp.Presets.Add(ps) For Each pv In p.PresetValues Dim psv As PresetValue = New PresetValue With { .Value = pv.Value } If pv.Channel IsNot Nothing Then psv.AttributeName = pv.Channel.AttributeName psv.ChannelId = pv.Channel.ChanelId psv.FixtureId = pv.Channel.FixtureId End If If pv.Handle IsNot Nothing Then Dim reference = passe1.SingleOrDefault(Function(x) x.Index = pv.Handle.PresetPoolId)?.Presets.SingleOrDefault(Function(y) y.Index = pv.Handle.PresetId)?.PresetValues.SingleOrDefault(Function(z) z.Channel IsNot Nothing AndAlso z.Channel.AttributeName = pv.Channel.AttributeName AndAlso z.Channel.FixtureId = pv.Channel.FixtureId) If reference IsNot Nothing Then psv.Value = reference.Value End If ps.PresetValues.Add(psv) Next Next Next
<PresetValue> <Handle name="L201 4.246"> <No>1</No> <No>4</No> <No>246</No> </Handle> <ChannelType fixture_type="933+cc10couleurs 00" module="1" attribute="SCROLLER" /> </PresetValue>
<Preset index="245" name="L201" SpecialUse="Normal"> <Appearance Color="0000ff" /> <Values> <Channels> <PresetValue Value="46.696079"> <Channel fixture_id="201" channel_id="201" attribute_name="SCROLLER" /> </PresetValue> <PresetValue Value="46.696079"> <Channel fixture_id="301" channel_id="301" attribute_name="SCROLLER" /> </PresetValue> <PresetValue Value="48.696079"> <Channel fixture_id="17" channel_id="17" attribute_name="SCROLLER" /> </PresetValue> <PresetValue Value="46.196079"> <Channel fixture_id="20" channel_id="20" attribute_name="SCROLLER" /> </PresetValue> </Channels> .........
Dim lignes As List(Of String) = File.ReadAllLines("---- presets ----.xml").ToList() lignes(1) = "<MA>" Dim texteCorrige As String = String.Join(Environment.NewLine, lignes) texteCorrige = texteCorrige.Replace("xsi:nil=""true""", "") Dim xdoc As XDocument = XDocument.Parse(texteCorrige) Dim passe1 = ( From pp In xdoc.Descendants("PresetPool") Select New With {Key .Index = pp.Attribute("index").ToInt(), Key .Presets = ( From p In pp.Descendants("Preset") Select New With { .Index = p.Attribute("index").ToInt(), .Name = p.Attribute("name")?.Value, .PresetValues = ( From pv In p.Descendants("PresetValue") Let c = pv.Element("Channel") Let h = pv.Element("Handle") Let ct = pv.Element("ChannelType") Select New With { .Value = pv.Attribute("Value").ToDouble(), .Channel = If(c IsNot Nothing, New With { .FixtureId = c.Attribute("fixture_id").ToInt(), .ChanelId = c.Attribute("channel_id").ToInt(), .AttributeName = c.Attribute("attribute_name").Value }, Nothing), .Handle = If(h IsNot Nothing, New With { .name = h.Attribute("name")?.Value, .PresetPoolId = h.Elements("No").ElementAt(1).ToInt(), .PresetId = h.Elements("No").ElementAt(2).ToInt() - 1 }, Nothing), .ChannelType = If(ct IsNot Nothing, New With { .FixtureType = ct.Attribute("fixture_type").Value, .Module = ct.Attribute("module").ToInt(), .Attribute = ct.Attribute("attribute").Value }, Nothing) }).ToList() }).ToList() }).ToList() Dim presetPools As New List(Of PresetPool)() For Each pp In passe1 Dim psp As PresetPool = New PresetPool With {.ID = pp.Index, .Presets = New List(Of Preset)()} presetPools.Add(psp) For Each p In pp.Presets Dim ps As Preset = New Preset With {.ID = p.Index, .Name = p.Name, .PresetValues = New List(Of PresetValue)()} psp.Presets.Add(ps) For Each pv In p.PresetValues Dim psv As PresetValue = New PresetValue With {.Value = pv.Value} If pv.Channel IsNot Nothing Then psv.AttributeName = pv.Channel.AttributeName psv.ChannelId = pv.Channel.ChanelId psv.FixtureId = pv.Channel.FixtureId End If If pv.Handle IsNot Nothing Then Dim leprset = passe1.SingleOrDefault(Function(x) x.Index = pv.Handle.PresetPoolId)?.Presets.SingleOrDefault(Function(y) y.Index = pv.Handle.PresetId) If pv.Channel IsNot Nothing Then Dim reference = leprset?.PresetValues.SingleOrDefault(Function(z) z.Channel IsNot Nothing AndAlso z.Channel.AttributeName = pv.Channel.AttributeName AndAlso z.Channel.FixtureId = pv.Channel.FixtureId) If reference IsNot Nothing Then psv.Value = reference.Value End If ElseIf pv.ChannelType IsNot Nothing Then Dim lesPresetValues = ( From x In leprset.PresetValues Where x.Channel IsNot Nothing AndAlso x.Channel.AttributeName = pv.ChannelType.Attribute Select New PresetValue With {.AttributeName = x.Channel.AttributeName, .ChannelId = x.Channel.ChanelId, .FixtureId = x.Channel.FixtureId, .Value = x.Value}) ps.PresetValues.AddRange(lesPresetValues) Continue For 'on passe à l'itération suivante Else Throw New Exception("Cas non prévu") End If End If ps.PresetValues.Add(psv) Next pv Next p Next pp
<Preset index="12" name="313" SpecialUse="Normal"> <Values> <Channels> <PresetValue Value="41.601875"> <Channel fixture_id="3" channel_id="3" attribute_name="SHUTTER" /> </PresetValue> </Channels> </Values> </Preset> <!-- C'est une preset classique avec une valeur pour un attribut d'un channel ------------------------------------------------------------------------------------------- --> <Preset index="1" name="ch4 HOME"> <Values> <Channels> <PresetValue> <Handle name="warp niches 0.1"> <No>1</No> <No>0</No> <No>1</No> </Handle> <Channel fixture_id="4" channel_id="4" attribute_name="FIXTUREGLOBALRESET" /> </PresetValue> </Channels> </Values> </Preset> <!-- C'est une preset classique avec un lien vers une autre preset ------------------------------------------------------------------------------------------- --> <Preset index="227" name="201 francois" preset_mode="Global" SpecialUse="Normal"> <Values> <ChannelTypes> <PresetValue Value="69.5"> <ChannelType fixture_type="Alpha Profile 800ST Standard Lamp on" module="1" attribute="COLORRGB1" /> <PresetValue> </ChannelType> </PresetValue> </ChannelTypes> </Values> </Preset> <!-- C'est une preset où la valeur s'applique pour tout le FixtureType. Il peut donc y avoir plusieurs "ChannelTypes, mais avec des "attribut" différents. ON A JUSTE BESOIN DE RÉCUPÉRER LES INFOS ET DE LES METTRE DANS LA LISTE Un seul ChannelType à chaque PresetValue ------------------------------------------------------------------------------------------- --> <Preset index="228" name="202" preset_mode="Global" SpecialUse="Normal"> <Values> <ChannelTypes> <PresetValue> <Handle name="L201 4.246"> <No>1</No> <No>4</No> <No>246</No> </Handle> <ChannelType fixture_type="933+cc10couleurs 00" module="1" attribute="SCROLLER" /> </PresetValue> </ChannelTypes> </Values> </Preset> <!-- Même preset que pérécédement mais avec la valeur lier à une autre preset. Là aussi qu'un seul "ChannelType" par "PresetValue" ------------------------------------------------------------------------------------------- --> <Preset index="0" name="H_0 S_0" preset_mode="Universal" SpecialUse="Normal"> <Values> <Attributes> <PresetValue Value="100"> <Attribute name="COLORRGB1" /> </PresetValue> <PresetValue Value="100"> <Attribute name="COLORRGB2" /> </PresetValue> <PresetValue Value="100"> <Attribute name="COLORRGB3" /> </PresetValue> </Attributes> </Values> </Preset> <!-- Ici il n'y a pas de "ChannelType" donc elle peut s'appliquer à tous les "FixtureType". Il faut récupérer les valeurs. -->
mesFixtures = ( From f In xDoc.Descendants("Fixture") Select New Fixture With { .Nom = f.Attribute("name")?.Value, .Numéro = f.Attribute("fixture_id").Value.ToInt(), .NomType = f.Element("FixtureType")?.Attribute("name")?.Value }).ToList()
mesFixtures = ( From f In xDoc.Descendants("Fixture") Select New Fixture With { .Nom = f.Attribute("name")?.Value, .Numéro = f.Attribute("fixture_id").Value.ToInt(), .NomType = f.Element("FixtureType")?.Attribute("name")?.Value }).GroupBy(function(x) x.NomType).ToList
Dim mesFixturesGroupees As List(Of IGrouping(Of String, Fixture)) = ( From f In xDoc.Descendants("Fixture") Select New Fixture With { .Nom = f.Attribute("name")?.Value, .Numero = f.Attribute("fixture_id").Value.ToInt(), .NomType = f.Element("FixtureType")?.Attribute("name")?.Value } ).GroupBy(Function(x) x.NomType).ToList() Dim cle1 As String = mesFixturesGroupees(1).Key Dim laFixture As Fixture = mesFixturesGroupees.Single(Function(x) x.Key = "4 TW1 80V mode etendu Extended mode").Last() 'dernière fixture du groupement en question
Dim laFixture As Fixture = mesFixturesGroupees.Single(Function(x) x.Key = "4 TW1 80V mode etendu Extended mode").Last()
Select(Funtion(toto) toto.Numero)
Modifié le 16 avril 2019 à 21:42