using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using C1.Silverlight.Data;
using System.IO;

namespace PdfCreator
{
    public static class DataAccess
    {
        public static Stream GetStream(string resName)
        {
            var asm = typeof(DataAccess).Assembly;
            string resovedResName = string.Format("{0}.Resources.{1}", asm.FullName.Split(',')[0].Trim(), resName);
            Stream str = asm.GetManifestResourceStream(resovedResName);
            if (str == null)
            {
                // <<IP>> the fix for SL5 version
                // try to get without platform-specific number
                resovedResName = string.Format("{0}.Resources.{1}", asm.FullName.Split('.')[0].Trim(), resName);
                str = asm.GetManifestResourceStream(resovedResName);
            }
            return str;
        }

        public static DataSet GetDataSet()
        {
            var ds = new DataSet();
            using (var s = GetStream("nwind.zip"))
            {
                var zip = new C1.C1Zip.C1ZipFile(s);
                using (var zr = zip.Entries[0].OpenReader())
                {
                    ds.ReadXml(zr);
                }
            }
            return ds;
        }

    }
}
