Retrieving XML Data from MS CRM 2011 MultilineText field in SilverLight using DataServiceCollection (PAGING & PageProcessing)

Retrieving XML Data from MS CRM 2011 MultilineText field in SilverLight using DataServiceCollection (PAGING & PageProcessing)

private void RetrieveXmlCongiguration()

{

DataServiceCollection<new_datagridxmlconfiguration> VFD = null;

try

{

DataServiceQuery<new_datagridxmlconfiguration> query = (DataServiceQuery<new_datagridxmlconfiguration>)context.new_datagridxmlconfigurationSet.AddQueryOption(“$filter”, “new_PrimaryEntityName ne null”);

query.BeginExecute(ProcessPages<new_datagridxmlconfiguration>, new PagingContext<new_datagridxmlconfiguration>()

{

ServiceContext = context,

Query = query,

PageProcessor =

delegate(DataServiceCollection<new_datagridxmlconfiguration> results)

{

try

{

if (null == VFD)

{

VFD =new DataServiceCollection<new_datagridxmlconfiguration>(context);

VFD.Load(results);

}

else

for (int i = 0; i < results.Count; i++)

VFD.Add(results[i]);    }   }

foreach (new_datagridxmlconfiguration entityValues in VFD)  {

stringXml = entityValues.new_XmlConfiguration;

break;

}      }

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

ReadXmlValues();

return true;  }

});    }

catch (Exception)

{ }

}

sealed class PagingContext<T>

{

public System.Data.Services.Client.DataServiceContext ServiceContext { get; set; }

public DataServiceQuery<T> Query { get; set; }

public Func<DataServiceCollection<T>, bool> PageProcessor { get; set; }

}

private static void ProcessPages<T>(IAsyncResult result)

{

try

{

PagingContext<T> context = (PagingContext<T>)result.AsyncState;

QueryOperationResponse<T> response;

if (null == context.Query)

{

response = (

QueryOperationResponse<T>)context.ServiceContext.EndExecute<T>(result);

}

else

{

response = (

QueryOperationResponse<T>)context.Query.EndExecute(result);

context.Query =

null;

}

DataServiceCollection<T> results = new DataServiceCollection<T>(response);

if (null != context.PageProcessor && !context.PageProcessor(results))

{

return;

}

DataServiceQueryContinuation<T> token = results.Continuation;

if (null == token)

{

return;

}

context.ServiceContext.BeginExecute(token, ProcessPages<T>, context);

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

}

 

Cheers,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s