Microsoft Developer Network > Página principal de foros > Visual C# General > LINQ to a jagged array - or is there a better way to do this?
Formular una preguntaFormular una pregunta
 

RespondidaLINQ to a jagged array - or is there a better way to do this?

  • miércoles, 04 de noviembre de 2009 15:31Jason A. Ward Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hey,

    I'm not the most experienced C# developer in the world, so forgive me if my question seems rather elementary.  Here's what I'm trying to accomplish:  I have a media portal server that runs a web service, and I am sending a search query to its web service that should return a list of media on the portal.  The issue I'm encountering is that I'm currently placing the returned data from the web service into a jagged array, and I need to be able to execute a LINQ query (well, it doesn't have to be a LINQ query, but at first I thought that would be easiest) against this array to select a few different fields for each item and return them as a single row to be placed in a GridView, then based on which value is selected in the GridView, select the appropriate identifier again and place it into a variable.

    Here's the code I'm using right now to call the web service method, GetLiveVEMSContent:


    ids_vems1.MCSContent[] liveContent = new
     ids_vems1.MCSContent[1];
    string
     newResult = client.GetLiveVEMSContent(sessionID, ""
    , startDate, endDate,
                    5, 1, "broadcast"
    , "title"
    , "ascending"
    , out
     totalPages, out
     liveContent);
    

    I'm instantiating the returned datasource as liveContent.  Here are the fields in the resulting array that I want to get to:


    liveContent[0].data[0].name = "Title"
    liveContent[0].data[0].value = "VBrick-IDCast-Presenter"
    liveContent[0].data[8].name = "GID"
    liveContent[0].data[8].value = //a long string of numbers and letters

    In this case, my search only returned one result, which is located at liveContent[0].  Additional results would be subsequent indexes in that array, with the nested data[] array inside each of them.

    Like I said above, I want to list the various titles in a GridView with a select button, then based upon which row is selected in the GridView I want to set a variable to the GID, which is the long string of numbers and letters found at liveContent[].data[8].value.

    Any idea how I would go about doing this?  Am I approaching this from the wrong direction?

    If it helps, here's the sample SOAP response from the web service:

    HTTP/1.1 200 OK
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <GetLiveVEMSContentResponse xmlns="http://tempuri.org/">
          <GetLiveVEMSContentResult>string</GetLiveVEMSContentResult>
          <totalPages>int</totalPages>
          <liveContent>
            <MCSContent>
              <data>
                <NameValue xsi:nil="true" />
                <NameValue xsi:nil="true" />
              </data>
            </MCSContent>
            <MCSContent>
              <data>
                <NameValue xsi:nil="true" />
                <NameValue xsi:nil="true" />
              </data>
            </MCSContent>
          </liveContent>
        </GetLiveVEMSContentResponse>
      </soap12:Body>
    </soap12:Envelope>

    And here's an actual SOAP response for the search results I'm working with:

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body>
          <GetLiveVEMSContentResponse xmlns="http://tempuri.org/">
             <GetLiveVEMSContentResult/>
             <totalPages>1</totalPages>
             <liveContent>
                <MCSContent>
                   <data>
                      <NameValue>
                         <name>Title</name>
                         <value>VBrick-IDCast-Presenter</value>
                      </NameValue>
                      <NameValue>
                         <name>CustomTitle</name>
                         <value/>
                      </NameValue>
                      <NameValue>
                         <name>Channel</name>
                         <value/>
                      </NameValue>
                      <NameValue>
                         <name>URL</name>
                         <value>/asxGet.aspx?ip=239.1.127.5+vac&amp;pt=4444+vac&amp;v=UNK&amp;cc=off&amp;license=/licenses/playerlicense/CombinedLicensedUser.lic</value>
                      </NameValue>
                      <NameValue>
                         <name>Address</name>
                         <value>239.1.127.5 vac</value>
                      </NameValue>
                      <NameValue>
                         <name>Port</name>
                         <value>4444 vac</value>
                      </NameValue>
                      <NameValue>
                         <name>Type</name>
                         <value>WM</value>
                      </NameValue>
                      <NameValue>
                         <name>VideoType</name>
                         <value>Stream</value>
                      </NameValue>
                      <NameValue>
                         <name>GID</name>
                         <value>4d43535365617263684c6f6769632e5341504275636b6574103233392e312e3132372e35207661633a3434343420766163</value>
                      </NameValue>
                   </data>
                </MCSContent>
             </liveContent>
          </GetLiveVEMSContentResponse>
       </soap:Body>
    </soap:Envelope>

    Any help would be appreciated...
    • EditadoJason A. Ward miércoles, 04 de noviembre de 2009 15:32formatting
    •  

Respuestas

  • miércoles, 04 de noviembre de 2009 16:41Louis.fr Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
    Something like this:

    var titles = (from c in liveContent from d in c.data where d.name == "Title" select d.value);
    

    to retrieve all the titles.

    And this to get the GID for a selectedTitle:

    var gid = (from c in liveContent where c.data.Any(d => d.name == "Title" && d.value == selectedTitle) from d in c.data where d.name == "GID" select d.value).First();
    
    • Marcado como respuestaJason A. Ward jueves, 05 de noviembre de 2009 15:00
    •  

Todas las respuestas

  • miércoles, 04 de noviembre de 2009 16:41Louis.fr Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
    Something like this:

    var titles = (from c in liveContent from d in c.data where d.name == "Title" select d.value);
    

    to retrieve all the titles.

    And this to get the GID for a selectedTitle:

    var gid = (from c in liveContent where c.data.Any(d => d.name == "Title" && d.value == selectedTitle) from d in c.data where d.name == "GID" select d.value).First();
    
    • Marcado como respuestaJason A. Ward jueves, 05 de noviembre de 2009 15:00
    •  
  • jueves, 05 de noviembre de 2009 15:02Jason A. Ward Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Thanks, that worked.