Exemple #1
0
        /*
         * Metodo resize bounding box con chiamata al vertice in questione
         */

        private void ResizeRect(SKPoint coordinatePixelDetected, ResizeInfo resizeDetected, RectangleArea rectangleArea)
        {
            MovimentInfo resizeMovimentDetected = MovimentMethods.GetResizeInfo(coordinatePixelDetected.X, coordinatePixelDetected.Y,
                                                                                bitMapArea.Left, bitMapArea.Top, bitMapArea.Right, bitMapArea.Bottom);

            switch (resizeDetected)
            {
            case ResizeInfo.LeftTopAround:
                LeftTopResizeCase(coordinatePixelDetected, resizeMovimentDetected, rectangleArea);
                break;

            case ResizeInfo.LeftBottomAround:
                LeftBottomResizeCase(coordinatePixelDetected, resizeMovimentDetected, rectangleArea);
                break;

            case ResizeInfo.RightTopAround:
                RightTopResizeCase(coordinatePixelDetected, resizeMovimentDetected, rectangleArea);
                break;

            case ResizeInfo.RightBottomAround:
                RightBottomResizeCase(coordinatePixelDetected, resizeMovimentDetected, rectangleArea);
                break;
            }
            rectangleArea.OffSetRectHeight = rectangleArea.Bottom - rectangleArea.Top;
            rectangleArea.OffSetRectWidth  = rectangleArea.Right - rectangleArea.Left;
            rectangleArea.ResizeMove       = true;
            canvasBitMap.InvalidateSurface();
        }
Exemple #2
0
        /*
         * Metodo di controllo attività di ridimensionamento bounding box
         */

        private ResizeInfo CheckIfResize(Point coordinateDetected, RectangleArea rectangleArea)
        {
            rectangleArea.CalculateVertexCoordinate();
            rectangleArea.CalculateOneRadiousCoordinate(coordinateDetected, canvasBitMap);

            ResizeInfo resizeDetected = MovimentMethods.CheckIfResize(rectangleArea.PixelCoordinateDetected, rectangleArea.OneRadiousPixelCoordinate,
                                                                      rectangleArea.LeftTopPixelCoordinate, rectangleArea.LeftBottomPixelCoordinate,
                                                                      rectangleArea.RightTopPixelCoordinate, rectangleArea.RightBottomPixelCoordinate);

            return(resizeDetected);
        }
Exemple #3
0
        public void DragResizer(GridResizer resizer, ResizeInfo data)
        {
            List <RowColInfo> info;
            List <int>        percents;
            int index;

            if (resizer.Orientation == Orientation.Vertical)
            {
                info     = _colInfo;
                percents = _model.ColumnPercents;
                index    = resizer.StartCol;
            }
            else
            {
                info     = _rowInfo;
                percents = _model.RowPercents;
                index    = resizer.StartRow;
            }

            int nextPercent = data.CurrentPercent + data.AdjacentPercent + info[index + 1].Percent;

            percents[index]     = info[index].Percent = data.NewPercent - data.AdjacentPercent;
            percents[index + 1] = info[index + 1].Percent = nextPercent - data.NewPercent;
        }
Exemple #4
0
        /// <summary>
        /// From a single uploaded file, creates thumbnail, preview and original images in underlying storage that may be associated with a page.
        /// </summary>
        /// <param name="tenantId">Website that page belongs to.</param>
        /// <param name="masterPageId">Master page containing image upload rules.</param>
        /// <param name="model">Image upload.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Identifiers of newly created thumbnail, preview and source images.</returns>
        public ImageUploadIds PrepareImages(long tenantId, long masterPageId, CreateUploadModel model, IUnitOfWork unitOfWork = null)
        {
            // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            // Begin work
            try
            {
                // Check that master page allows page images and that uploaded content is valid image
                ValidatePrepareImagesResult result = _pageValidator.ValidatePrepareImages(tenantId, masterPageId, model);

                // Create thumbnail model
                ResizeInfo thumbnailResizeInfo = new ResizeInfo
                {
                    Width      = result.MasterPage.ThumbnailImageWidth.Value,
                    Height     = result.MasterPage.ThumbnailImageHeight.Value,
                    ResizeMode = result.MasterPage.ThumbnailImageResizeMode.Value
                };
                byte[]            thumbnailContent = _imageAnalysisService.ResizeImage(model.Content, thumbnailResizeInfo);
                CreateUploadModel thumbnailModel   = new CreateUploadModel
                {
                    Content     = thumbnailContent,
                    ContentType = model.ContentType,
                    Name        = model.Name,
                    TenantId    = model.TenantId
                };

                // Create preview model
                ResizeInfo previewResizeInfo = new ResizeInfo
                {
                    Width      = result.MasterPage.PreviewImageWidth.Value,
                    Height     = result.MasterPage.PreviewImageHeight.Value,
                    ResizeMode = result.MasterPage.PreviewImageResizeMode.Value
                };
                byte[]            previewContent = _imageAnalysisService.ResizeImage(model.Content, previewResizeInfo);
                CreateUploadModel previewModel   = new CreateUploadModel
                {
                    Content     = previewContent,
                    ContentType = model.ContentType,
                    Name        = model.Name,
                    TenantId    = model.TenantId
                };

                // Create uploads for thumbnail, preview and original image
                long thumbnailImageUploadId = _uploadService.Create(thumbnailModel, unitOfWork ?? localUnitOfWork);
                long previewImageUploadId   = _uploadService.Create(previewModel, unitOfWork ?? localUnitOfWork);
                long imageUploadId          = _uploadService.Create(model, unitOfWork ?? localUnitOfWork);

                // Commit work if local unit of work in place and return result
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
                return(new ImageUploadIds {
                    ThumbnailImageUploadId = thumbnailImageUploadId, PreviewImageUploadId = previewImageUploadId, ImageUploadId = imageUploadId
                });
            }
            catch (ValidationErrorException)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            catch (Exception ex)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }
Exemple #5
0
        public ResizeInfo CalculateResizeInfo(GridResizer resizer, double delta)
        {
            ResizeInfo res = new ResizeInfo();

            int rowIndex = resizer.StartRow;
            int colIndex = resizer.StartCol;

            int[,] indices = _model.CellChildMap;

            List <RowColInfo> info;
            List <int>        percents;
            int index;

            if (resizer.Orientation == Orientation.Vertical)
            {
                res.CurrentExtent  = _colInfo[colIndex].Extent;
                res.CurrentPercent = _colInfo[colIndex].Percent;

                info     = _colInfo;
                percents = _model.ColumnPercents;
                index    = colIndex;

                Func <int, bool> indexCmpr = (ind) =>
                {
                    bool sameIndices = true;
                    for (int i = resizer.StartRow; i < resizer.EndRow && sameIndices; i++)
                    {
                        sameIndices &= indices[i, ind] == indices[i, ind - 1];
                    }

                    return(sameIndices);
                };

                res.CalcAdjacentZones(colIndex, _model.Columns, _colInfo, indexCmpr);
            }
            else
            {
                res.CurrentExtent  = _rowInfo[rowIndex].Extent;
                res.CurrentPercent = _rowInfo[rowIndex].Percent;

                info     = _rowInfo;
                percents = _model.RowPercents;
                index    = rowIndex;

                Func <int, bool> indexCmpr = (ind) =>
                {
                    bool sameIndices = true;
                    for (int i = resizer.StartCol; i < resizer.EndCol && sameIndices; i++)
                    {
                        sameIndices &= indices[ind, i] == indices[ind - 1, i];
                    }

                    return(sameIndices);
                };

                res.CalcAdjacentZones(rowIndex, _model.Rows, _rowInfo, indexCmpr);
            }

            res.FixAccuracyError(info, percents, delta > 0 ? index + 2 : index + 1);
            res.CalcNewPercent(delta);
            return(res);
        }
        public long PrepareImages(long tenantId, long elementId, CreateUploadModel model, IUnitOfWork unitOfWork = null)
        {
            // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            // Begin work
            try
            {
                // Check that uploaded content is valid image
                System.Drawing.Size imageSize = _htmlValidator.ValidatePrepareImages(tenantId, elementId, model);

                // Get HTML settings (does not have to be within unit of work)
                HtmlSettings htmlSettings = (HtmlSettings)New(tenantId);
                htmlSettings.ElementId = elementId;
                Read(htmlSettings);

                // Create thumbnail model
                byte[] thumbnailContent = model.Content;
                if (imageSize.Width > htmlSettings.ThumbnailImageWidth || imageSize.Height > htmlSettings.ThumbnailImageHeight)
                {
                    ResizeInfo thumbnailResizeInfo = new ResizeInfo
                    {
                        Width      = htmlSettings.ThumbnailImageWidth,
                        Height     = htmlSettings.ThumbnailImageHeight,
                        ResizeMode = htmlSettings.ThumbnailImageResizeMode
                    };
                    thumbnailContent = _imageAnalysisService.ResizeImage(model.Content, thumbnailResizeInfo);
                }
                CreateUploadModel thumbnailModel = new CreateUploadModel
                {
                    Content     = thumbnailContent,
                    ContentType = model.ContentType,
                    Name        = model.Name,
                    TenantId    = model.TenantId
                };

                // Create preview model
                byte[] previewContent = model.Content;
                if (imageSize.Width > htmlSettings.PreviewImageWidth || imageSize.Height > htmlSettings.PreviewImageHeight)
                {
                    ResizeInfo previewResizeInfo = new ResizeInfo
                    {
                        Width      = htmlSettings.PreviewImageWidth,
                        Height     = htmlSettings.PreviewImageHeight,
                        ResizeMode = htmlSettings.PreviewImageResizeMode
                    };
                    previewContent = _imageAnalysisService.ResizeImage(model.Content, previewResizeInfo);
                }
                CreateUploadModel previewModel = new CreateUploadModel
                {
                    Content     = previewContent,
                    ContentType = model.ContentType,
                    Name        = model.Name,
                    TenantId    = model.TenantId
                };

                // Create uncommitted uploads for thumbnail, preview and original image
                long thumbnailImageUploadId = _uploadService.Create(thumbnailModel, unitOfWork ?? localUnitOfWork);
                long previewImageUploadId   = _uploadService.Create(previewModel, unitOfWork ?? localUnitOfWork);
                long imageUploadId          = _uploadService.Create(model, unitOfWork ?? localUnitOfWork);

                // Commit uploads
                _uploadService.Commit(tenantId, thumbnailImageUploadId, GetHtmlUploadStorageHierarchy(elementId), unitOfWork ?? localUnitOfWork);
                _uploadService.Commit(tenantId, previewImageUploadId, GetHtmlUploadStorageHierarchy(elementId), unitOfWork ?? localUnitOfWork);
                _uploadService.Commit(tenantId, imageUploadId, GetHtmlUploadStorageHierarchy(elementId), unitOfWork ?? localUnitOfWork);

                // Create HTML image, recording upload IDs of newly created images
                HtmlUpload upload = new HtmlUpload
                {
                    TenantId               = tenantId,
                    ElementId              = elementId,
                    ImageTenantId          = tenantId,
                    ThumbnailImageUploadId = thumbnailImageUploadId,
                    PreviewImageUploadId   = previewImageUploadId,
                    ImageUploadId          = imageUploadId
                };
                long htmlImageId = _htmlRepository.CreateUpload(upload, unitOfWork ?? localUnitOfWork);

                // Commit work if local unit of work in place and return result
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
                return(htmlImageId);
            }
            catch (ValidationErrorException)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            catch (Exception ex)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }