public void ToStringTest()
        {
            StringWriter writer = new StringWriter ();
            writer.WriteLine ("[Test]");
            writer.WriteLine (" cat = muffy");
            writer.WriteLine (" dog = rover");
            writer.WriteLine (" bird = tweety");
            IniConfigSource source =
                new IniConfigSource (new StringReader (writer.ToString ()));

            string eol = Environment.NewLine;

            string compare = "[Test]" + eol
                             + "cat = muffy" + eol
                             + "dog = rover" + eol
                             + "bird = tweety" + eol;
            Assert.AreEqual (compare, source.ToString ());
        }
Exemple #2
0
 public static void Save(string fileName, IList<DEngine> engines, DPoint pageSize, BackgroundFigure bf, Dictionary<string, byte[]> extraEntries)
 {
     System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
     using (ZipOutputStream zipOut = new ZipOutputStream(File.Create(fileName)))
     {
         IniConfigSource source = new IniConfigSource();
         // write each page
         int i = 0;
         Dictionary<string, byte[]> images = new Dictionary<string, byte[]>();
         foreach (DEngine de in engines)
         {
             IConfig config = source.AddConfig(string.Format("page{0}", i));
             config.Set(PAGESIZE, DPoint.FormatToString(de.PageSize));
             if (de.PageName != null)
                 config.Set(PAGENAME, de.PageName);
             string figureListName = string.Format("figureList{0}.xml", i);
             byte[] data = encoding.GetBytes(FigureSerialize.FormatToXml(de.Figures, images));
             config.Set(FIGURELIST, figureListName);
             Write(zipOut, figureListName, data);
             if (de.CustomBackgroundFigure)
             {
                 string backgroundFigureName = string.Format("backgroundFigure{0}.xml", i);
                 config.Set(BACKGROUNDFIGURE, backgroundFigureName);
                 data = encoding.GetBytes(FigureSerialize.FormatToXml(de.BackgroundFigure, images));
                 Write(zipOut, backgroundFigureName, data);
             }
             i += 1;
         }
         // write background figure
         if (bf != null)
         {
             // store page size to background figure
             if (pageSize != null)
             {
                 bf.Width = pageSize.X;
                 bf.Height = pageSize.Y;
             }
             else
             {
                 DPoint sz = PageTools.FormatToSize(PageFormat.Default);
                 bf.Width = sz.X;
                 bf.Height = sz.Y;
             }
             byte[] data = encoding.GetBytes(FigureSerialize.FormatToXml(bf, images));
             Write(zipOut, GENBKGNDFIGURE, data);
         }
         // write images
         foreach (KeyValuePair<string, byte[]> kvp in images)
             if (kvp.Key != null && kvp.Key.Length > 0)
                 Write(zipOut, IMAGES_DIR + Path.DirectorySeparatorChar + Path.GetFileName(kvp.Key), kvp.Value);
         // write extra entries
         if (extraEntries != null)
             foreach (string name in extraEntries.Keys)
                 Write(zipOut, name, extraEntries[name]);
         // write pages ini
         Write(zipOut, PAGES_INI, encoding.GetBytes(source.ToString()));
     }
 }