Beispiel #1
0
 private void SaveShapesToStream(IShapeLoader shapeLoader, Stream stream)
 {
     try
     {
         shapeLoader.Save(stream, shapes_);
     }
     catch (Exception ex)
     {
         errorLabel.Text = ex.Message;
     }
 }
Beispiel #2
0
 private ICollection <IShape> LoadShapesFromStream(IShapeLoader shapeLoader, Stream stream)
 {
     try
     {
         return(shapeLoader.Load(stream).ToList());
     }
     catch (Exception ex)
     {
         errorLabel.Text = ex.Message;
         return(null);
     }
 }
Beispiel #3
0
        private void saveToFileButton_Click(object sender, EventArgs e)
        {
            IShapeLoader shapeLoader = shapeLoaderFactory_.Create();

            saveFileDialog1.DefaultExt = shapeLoader.FileExtension;
            DialogResult dialogResult = saveFileDialog1.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                using (Stream stream = saveFileDialog1.OpenFile())
                {
                    SaveShapesToStream(shapeLoader, stream);
                }
            }
        }
Beispiel #4
0
        private void openFileButton_Click(object sender, EventArgs e)
        {
            IShapeLoader shapeLoader = shapeLoaderFactory_.Create();

            openFileDialog1.DefaultExt = shapeLoader.FileExtension;
            DialogResult dialogResult = openFileDialog1.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                using (Stream stream = openFileDialog1.OpenFile())
                {
                    var shapes = LoadShapesFromStream(shapeLoader, stream);
                    Redraw(shapes);
                }
            }
        }
Beispiel #5
0
 public ShapeLoaderAdapter(IShapeLoader loader, IStreamWrapper wrapper)
 {
     loader_  = loader;
     wrapper_ = wrapper;
 }
Beispiel #6
0
 public ShapeLoaderFactory(IShapeLoader coreLoader)
 {
     coreLoader_ = coreLoader;
 }
 public IShapeLoader Wrap(IShapeLoader shapeLoader)
 {
     return(new ShapeLoaderAdapter(shapeLoader, wrapper_));
 }
Beispiel #8
0
 public IShapeLoader Wrap(IShapeLoader shapeLoader)
 {
     return(new ZipShapeLoaderDecorator(shapeLoader));
 }
 public IShapeLoader Wrap(IShapeLoader shapeLoader)
 {
     return(new ChecksumShapeLoaderDecorator(shapeLoader, new Md5Hash()));
 }
 public ZipShapeLoaderDecorator(IShapeLoader loader)
 {
     loader_ = loader;
 }
 public ChecksumShapeLoaderDecorator(IShapeLoader loader, IHash hash)
 {
     loader_ = loader;
     hash_   = hash;
 }