SlideShow with dynamic XML

Jan 22, 2009 at 10:26 PM
Edited Jan 22, 2009 at 10:35 PM
I wanted to pass data instead of data.xml as a dynamic xml string in initparams like:

writer.Write(

"<param name=\"initParams\" value=\"ConfigurationProvider=LightTheme,DataProvider=XmlDataProvider;XmlSource=" + strXmlSource + "\" />");

I modified App.xaml.cs for this

private void SplitStartupEventArgs(StartupEventArgs e, ref Dictionary<string, Dictionary<string, string>> initParams)
        {
            // TODO: # 385 - Make sure the user doesn't identify the same key twice or we'll get an exception when adding to dictionary.
            Dictionary<string, string> subParams;
            string[] keyValuePair;
            foreach (KeyValuePair<string, string> subParamsCollection in e.InitParams)
            {
                subParams = new Dictionary<string, string>();
                string[] custParams;
                if (subParamsCollection.Value.IndexOf(';') > 0)
                {
                    custParams = new string[2];
                    custParams[0] = subParamsCollection.Value.Substring(0, subParamsCollection.Value.IndexOf(';'));
                    custParams[1] = subParamsCollection.Value.Substring(subParamsCollection.Value.IndexOf(';') + 1);
                }
                else
                {
                    custParams = new string[1];
                    custParams[0] = subParamsCollection.Value;
                }
                //foreach (string subParamPair in subParamsCollection.Value.Split(';'))
                foreach (string subParamPair in custParams)
                {
                    if (subParamPair.StartsWith("XmlSource"))
                    {
                        string[] xmlSource = { subParamPair.Substring(0, subParamPair.IndexOf('=')), subParamPair.Substring(subParamPair.IndexOf('=') + 1) };
                        subParams.Add(xmlSource[0], xmlSource[1]);
                    }
                    else
                    {//Kiran
                        keyValuePair = subParamPair.Split('=');
                        if (keyValuePair.Count() == 1)
                        {
                            subParams.Add(subParamsCollection.Key, keyValuePair[0]);
                        }

                        if (keyValuePair.Count() == 2)
                        {
                            subParams.Add(keyValuePair[0], keyValuePair[1]);
                        }
                    }
                }

                initParams.Add(subParamsCollection.Key, subParams);
            }
        }

And then, I modified XMLDataProvider as follows

public

 

XmlDataProvider(Dictionary<string, Dictionary<string, string>> initParams)
{
string strXmlSource = initParams.ContainsKey("DataProvider") ?
    initParams[
"DataProvider"].ContainsKey("XmlSource") ?
    initParams[
"DataProvider"]["XmlSource"] :
    string.Empty :
    string.Empty;

 

 

XmlReader reader = XmlReader.Create(new StringReader(strXmlSource));
while (reader.Read())
{
if (reader.IsStartElement() && reader.Name == "data")
{
Data.StartAlbumIndex = Convert.ToInt32(reader.GetAttribute("startalbumindex"), CultureInfo.InvariantCulture);
Data.Albums = ParseAlbums(reader.ReadSubtree(), reader.GetAttribute("transition"));
}
}
DataFinishedLoading(
this, EventArgs.Empty);
}


(Removed Event -  client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)

I am getting my xml data in XmlReader. but the code is breaking somewhere that I am unable to get the slideshow. Any help please???

 

 

 

 

Feb 7, 2009 at 3:08 PM
I did this by building a class in my asp.net application after I compiled the .XAP file (I am using Slide.Show2).

You can see my blog post on it here
http://www.dotnetblogger.com/post/2009/02/04/SlideShow2-Database-Config-(Singleton).aspx

Since you are using the Slide.Show (1) project, I am sure you can use the same concept just not with the XAP stuff.  I pesonally would suggest moving to the Slide.Show2 project.