Exemplo n.º 1
0
        /// <summary>
        /// Saves a FramedImageDTO to a persistent storage
        /// </summary>
        /// <param name="framedImage"></param>
        /// <exception cref="Exception">Will throw if errors occured while saving the FramedImageDTO to a persistent storage.</exception>
        /// <exception cref="Exception">Will throw if received file is not an image.</exception>
        public void Save(FramedImageDTO framedImage)
        {
            if (framedImage != null)
            {
                try
                {
                    FileStream fileStream = new FileStream(framedImage.ImageFilepath, FileMode.Open, FileAccess.Read);
                    if (fileStream.IsImage())
                    {
                        string ext = framedImage.ImageFilepath.Substring(framedImage.ImageFilepath.LastIndexOf(".") + 1);

                        int imageNumber = framedImagedPersistence.GetCount();

                        string datetime = DateTime.Now.Ticks.ToString();

                        string newFilename = String.Format("Image-{0}-{1}.{2}", imageNumber++, datetime, ext);

                        FramedImageModel model = new FramedImageModel
                        {
                            Id               = framedImage.Id,
                            Filename         = newFilename,
                            Witdh            = framedImage.Witdh,
                            Height           = framedImage.Height,
                            LocationX        = framedImage.LocationX,
                            LocationY        = framedImage.LocationY,
                            FrameThickness   = framedImage.FrameThickness,
                            RotateAngle      = framedImage.RotateAngle,
                            Caption          = framedImage.Caption,
                            EnableCaption    = framedImage.EnableCaption,
                            EnableShadow     = framedImage.EnableShadow,
                            ShadowOpacity    = framedImage.ShadowOpacity,
                            ShadowDepth      = framedImage.ShadowDepth,
                            ShadowDirection  = framedImage.ShadowDirection,
                            ShadowBlurRadius = framedImage.ShadowBlurRadius
                        };

                        framedImagedPersistence.Save(model);

                        framedImage.Id = model.Id;

                        CopyImage(framedImage.ImageFilepath, newFilename);

                        framedImage.ImageFilepath = ImageDirectoryPath + "\\" + model.Filename;

                        fileStream.Close();
                        fileStream.Dispose();
                    }
                    else
                    {
                        throw FILE_NOT_IMAGE_ERROR;
                    }
                }
                catch (Exception ex)
                {
                    logger.LogException(ex);
                    throw SAVE_ERROR;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Permanently removes a FramedImageDTO from the persistent storage.
        /// </summary>
        /// <param name="framedImage"></param>
        /// <exception cref="Exception">Will throw if errors occured while removing FramedImageDTO from persistent storage.</exception>
        public void Delete(FramedImageDTO framedImage)
        {
            try
            {
                if (framedImage != null)
                {
                    framedImagedPersistence.Delete(framedImage.Id);

                    DeleteImage(framedImage.ImageFilepath);
                }
            }
            catch (Exception ex)
            {
                logger.LogException(ex);
                throw DELETE_ERROR;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves changes made to a FramedImageDTO back to the persistent storage.
        /// </summary>
        /// <param name="framedImage"></param>
        /// <exception cref="Exception">Will throw if errors occured while updating the FramedImageDTO back to a persistent storage.</exception>
        public void Edit(FramedImageDTO framedImage)
        {
            if (framedImage != null)
            {
                try
                {
                    string filename = Path.GetFileName(framedImage.ImageFilepath);

                    framedImagedPersistence.Edit(
                        framedImage.Id,
                        new FramedImageModel
                    {
                        Id               = framedImage.Id,
                        Filename         = filename,
                        Witdh            = framedImage.Witdh,
                        Height           = framedImage.Height,
                        LocationX        = framedImage.LocationX,
                        LocationY        = framedImage.LocationY,
                        FrameThickness   = framedImage.FrameThickness,
                        RotateAngle      = framedImage.RotateAngle,
                        Caption          = framedImage.Caption,
                        EnableCaption    = framedImage.EnableCaption,
                        EnableShadow     = framedImage.EnableShadow,
                        ShadowOpacity    = framedImage.ShadowOpacity,
                        ShadowDepth      = framedImage.ShadowDepth,
                        ShadowDirection  = framedImage.ShadowDirection,
                        ShadowBlurRadius = framedImage.ShadowBlurRadius
                    });
                }
                catch (Exception ex)
                {
                    logger.LogException(ex);
                    throw EDIT_ERROR;
                }
            }
        }