private XDocument GetKmzContents(ZipFile zipFile)
{
XDocument xDoc = null;
// Process each file in the archive
foreach (string filename in zipFile.EntryFileNames)
{
// Determine where the last "." character exists in the filename and if is does not appear
// at all, then skip the file.
int lastPeriod = filename.LastIndexOf(".");
if (lastPeriod == -1)
continue;
#if SILVERLIGHT
System.IO.Stream ms = zipFile.GetFileStream(filename);
#else
MemoryStream ms = new MemoryStream();
zipFile.Extract(filename, ms);
#endif
if (ms == null) continue;
ms.Seek(0, SeekOrigin.Begin);
switch (filename.Substring(lastPeriod).ToLower())
{
case ".jpg":
case ".jpeg":
case ".png":
#if !SILVERLIGHT
case ".bmp":
case ".gif":
#endif
// If the file is an image, then add it to the dictionary of images and use
// its filename as the key since this will match the subsequent KML style
// information for point features.
try
{
BitmapImage thumbnailBitmap = new BitmapImage();
#if SILVERLIGHT
thumbnailBitmap.SetSource(ms);
#else
thumbnailBitmap.BeginInit();
thumbnailBitmap.StreamSource = ms;
thumbnailBitmap.EndInit();
#endif
ImageBrush ib = new ImageBrush();
ib.ImageSource = thumbnailBitmap;
_context.Images.Add(filename.ToLower(), ib);
}
catch { }
break;
case ".kml":
// Create the XDocument object from the input stream
xDoc = LoadDocument(ms);
break;
}
}
return xDoc;
}