예제 #1
0
        internal void ConfigurePage(
            SiteSection section,
            Pages page,
            PageTitle title,
            PageSubTitle subTitle,
            PageDescription description,
            NavControlPath controlPath,
            Banner banner,
            bool showMap,
            PageKeyWords keyWords)
        {
            SetBanner(banner);
            Page.Title = title.Value;
            subTitleText.Text = subTitle.Value;
            SetMetaData(description, keyWords);
            ShowMap(showMap);

            if (controlPath.Value != string.Empty)
            {
                Control navControl = LoadControl(controlPath.Value);
                navControl.ID = "navBar";
                SidePanel1.AddControl(navControl);
            }

            SetNavBars(section, page);
        }
예제 #2
0
        protected override void InTransaction()
        {
            List <Image> images = new List <Image>();

            var exists = Context.PageDescriptions.FirstOrDefault(x => x.ControllerName == _controller && x.ActionName == _action && !x.Deleted);

            if (exists != null)
            {
                Errors.Add("ActionName", "Страница с таким адресом уже существует!");
            }
            else
            {
                if (_images != null)
                {
                    foreach (var imageFile in _images)
                    {
                        if (imageFile != null)
                        {
                            var url = String.Format("~/Content/images/pages/{0}/{1}/", _controller, _action);

                            var path = HttpContext.Current.Server.MapPath(url);
                            imageFile.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
                            int point    = imageFile.FileName.LastIndexOf('.');
                            var filename = imageFile.FileName.Substring(0, point) + "_" + DateTime.Now.ToFileTime();

                            ImageBuilder.Current.Build(
                                new ImageJob(imageFile.InputStream,
                                             path + filename,
                                             new Instructions("maxwidth=1600&maxheight=1200&format=jpg&quality=80"),
                                             false,
                                             true));

                            var image = new Image
                            {
                                FileName = filename + ".jpg",
                                Url      = url,
                            };
                            Context.Images.Add(image);
                            images.Add(image);
                        }
                    }
                }
                PageDescription page = new PageDescription
                {
                    ActionName     = _action,
                    ControllerName = _controller,
                    Description    = _description,
                    Title          = _title,
                    VideoURL       = _videoUrl,
                    Images         = images,
                };
                Context.PageDescriptions.Add(page);
                Context.SaveChanges();
            }
        }
예제 #3
0
        public ActionResult Add(PageDescription model, HttpPostedFileBase[] images)
        {
            AddPagesDescOperation op = new AddPagesDescOperation(model.ControllerName, model.ActionName, model.Description, model.Title, model.VideoURL, images);

            op.ExcecuteTransaction();
            if (!op.Success)
            {
                ErrorHelpers.AddModelErrors(ModelState, op.Errors);
            }
            return(View(model));
        }
예제 #4
0
 private void SetMetaData(PageDescription pageDescription, PageKeyWords pageKeyWords)
 {
     HtmlMeta description = new HtmlMeta();
     description.Name = "description";
     description.Content = pageDescription.Value;
     HtmlMeta keyWords = new HtmlMeta();
     keyWords.Name = "keywords";
     keyWords.Content = pageKeyWords.Value;
     this.Header.Controls.Add(keyWords);
     this.Header.Controls.Add(description);
 }
예제 #5
0
 protected override void InTransaction()
 {
     if (_id < 1)
     {
         _pageDescription = Context.PageDescriptions.FirstOrDefault(x => x.ControllerName == _controller && x.ActionName == _action && !x.Deleted);
     }
     else
     {
         _pageDescription = Context.PageDescriptions.FirstOrDefault(x => x.Id == _id && !x.Deleted);
     }
 }
예제 #6
0
        protected override void InTransaction()
        {
            if (_id < 1)
            {
                _pageDescription = Context.PageDescriptions.FirstOrDefault(x => x.ControllerName == _controller && x.ActionName == _action && !x.Deleted);
            }
            else
            {
                _pageDescription = Context.PageDescriptions.FirstOrDefault(x => x.Id == _id && !x.Deleted);
            }
            if (_pageDescription != null)
            {
                if (_images != null)
                {
                    foreach (var imageFile in _images)
                    {
                        if (imageFile != null)
                        {
                            var url = String.Format("~/Content/images/pages/{0}/{1}/", _pageDescription.ControllerName, _pageDescription.ActionName);

                            var path = HttpContext.Current.Server.MapPath(url);
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            imageFile.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
                            int point    = imageFile.FileName.LastIndexOf('.');
                            var filename = imageFile.FileName.Substring(0, point) + "_" + DateTime.Now.ToFileTime();

                            ImageBuilder.Current.Build(
                                new ImageJob(imageFile.InputStream,
                                             path + filename,
                                             new Instructions("maxwidth=1600&maxheight=1200&format=jpg&quality=80"),
                                             false,
                                             true));

                            var image = new Image
                            {
                                FileName = filename + ".jpg",
                                Url      = url,
                            };
                            Context.Images.Add(image);
                            _pageDescription.Images.Add(image);
                        }
                    }
                }
                _pageDescription.Title       = _title;
                _pageDescription.Description = _description;
                _pageDescription.VideoURL    = _videoUrl;
                Context.SaveChanges();
            }
        }
예제 #7
0
 internal void ConfigurePage(
     SiteSection section,
     Pages page,
     PageTitle title,
     PageSubTitle subTitle,
     PageDescription description,
     NavControlPath controlPath,
     Banner banner,
     bool showMap)
 {
     Default master = this.Master as Default;
     master.ConfigurePage(section, page, title, subTitle, description, controlPath, banner, showMap);
 }
예제 #8
0
 internal void ConfigurePage(
     SiteSection section,
     Pages page,
     PageTitle title,
     PageSubTitle subTitle,
     PageDescription description,
     NavControlPath controlPath,
     Banner banner,
     bool showMap)
 {
     ConfigurePage(section, page, title, subTitle, description, controlPath, banner, showMap,
         new PageKeyWords("Recording Rehearsal Blackpool Lancashire Fylde Studio Rooms Drum School Academy Music"));
 }
예제 #9
0
        public ActionResult Detail(PageDescription model, HttpPostedFileBase[] images)
        {
            if (!SessionHelpers.IsAuthentificated())
            {
                return(RedirectToAction("Login", "Authorize"));
            }
            UpdatePagesDescOperation op = new UpdatePagesDescOperation(model.Id, model.Description, model.Title, model.VideoURL, images);

            op.ExcecuteTransaction();
            if (op._pageDescription == null)
            {
                return(HttpNotFound());
            }

            return(View(op._pageDescription));
        }
예제 #10
0
        internal static void BuildChunks(IServer server, IList <ChunkBase> chunks, PageDescription description)
        {
            foreach (var chunkDescription in description.Chunks)
            {
                var nameParts = chunkDescription.Name.Split(ColonSplitter, 2);
                var ns        = description.Namespaces[nameParts[0]];
                var nsParts   = ns.Split(CommaSplitter, 2);
                nsParts[0] += "." + nameParts[1] + "Chunk+Creator";

                string typeName = string.Join(", ", nsParts);

                Type type = Type.GetType(typeName);

                var          chunkCreatorWrap = Activator.CreateInstance(type);
                ChunkCreator chunkCreator     = (ChunkCreator)chunkCreatorWrap;
                ChunkBase    chunk            = chunkCreator.Create(server, chunkDescription.Config);
                chunk.SendType = SendTypeEnum.None;
                chunks.Add(chunk);
            }
        }
예제 #11
0
        private async Task Render(HttpClientImpl client)
        {
            FileChunk fileChunk = new FileChunk(Server);

            fileChunk.SendType = SendTypeEnum.None;

            PageDescription description = null;

            using (MemoryStream fileContents = new MemoryStream())
            {
                await fileChunk.Send(client, fileContents);

                fileContents.Position = 0;

                using (StreamReader reader = new StreamReader(fileContents))
                {
                    var data = await reader.ReadToEndAsync();

                    description = await JsonConvert.DeserializeObjectAsync <PageDescription>(data);
                }
            }

            BuildChunks(Server, _chunks, description);
        }
        /// <summary>
        /// Generates a page containing a photo.
        /// The image will be rotated if detected that there is a gain from that regarding size (try to maximize photo size).
        /// </summary>
        /// <param name="photoNumber">The photo number.</param>
        /// <param name="pageDescription">The description of the printer page.</param>
        /// <returns>A task that will return the page.</returns>
        private async Task <UIElement> GeneratePageAsync(int photoNumber, PageDescription pageDescription)
        {
            Canvas page = new Canvas
            {
                Width  = pageDescription.PageSize.Width,
                Height = pageDescription.PageSize.Height
            };

            Canvas viewablePage = new Canvas()
            {
                Width  = pageDescription.ViewablePageSize.Width,
                Height = pageDescription.ViewablePageSize.Height
            };

            viewablePage.SetValue(Canvas.LeftProperty, pageDescription.Margin.Width);
            viewablePage.SetValue(Canvas.TopProperty, pageDescription.Margin.Height);

            // The image "frame" which also acts as a viewport.
            Grid photoView = new Grid
            {
                Width  = pageDescription.PictureViewSize.Width,
                Height = pageDescription.PictureViewSize.Height
            };

            // Center the frame.
            photoView.SetValue(Canvas.LeftProperty, (viewablePage.Width - photoView.Width) / 2);
            photoView.SetValue(Canvas.TopProperty, (viewablePage.Height - photoView.Height) / 2);

            // Return an async task that will complete when the image is fully loaded.
            WriteableBitmap bitmap = new WriteableBitmap(Export.ExportWidth, Export.ExportHeight);

            System.IO.Stream bitmapStream = null;
            bitmapStream          = bitmap.PixelBuffer.AsStream();
            bitmapStream.Position = 0;

            await bitmapStream.WriteAsync(Export.Pixels.ToArray(), 0, 4 *Export.ExportHeight *Export.ExportWidth);

            bitmapStream.Flush();

            if (bitmap != null)
            {
                Image image = new Image
                {
                    Source = bitmap,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center
                };

                // Use the real image size when croping or if the image is smaller then the target area (prevent a scale-up).
                if (PhotoScale == Scaling.Crop ||
                    (bitmap.PixelWidth <= pageDescription.PictureViewSize.Width &&
                     bitmap.PixelHeight <= pageDescription.PictureViewSize.Height))
                {
                    image.Stretch = Stretch.None;
                    image.Width   = bitmap.PixelWidth;
                    image.Height  = bitmap.PixelHeight;
                }

                // Add the newly created image to the visual root.
                photoView.Children.Add(image);
                viewablePage.Children.Add(photoView);
                page.Children.Add(viewablePage);
            }

            // Return the page with the image centered.
            return(page);
        }
        /// <summary>
        /// This is the event handler for Pagination.
        /// </summary>
        /// <param name="sender">The document for which pagination occurs.</param>
        /// <param name="e">The pagination event arguments containing the print options.</param>
        protected override void CreatePrintPreviewPages(object sender, PaginateEventArgs e)
        {
            var printDoc = sender as PrintDocument;

            // A new "session" starts with each paginate event.
            Interlocked.Increment(ref RequestCount);

            PageDescription pageDescription = new PageDescription();

            // Get printer's page description.
            PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(e.PrintTaskOptions);
            PrintPageDescription   printPageDescription = e.PrintTaskOptions.GetPageDescription(0);

            // Reset the error state.
            printDetailedOptions.Options["photoSize"].ErrorText = string.Empty;

            // Compute the printing page description (page size & center printable area).
            pageDescription.PageSize = printPageDescription.PageSize;

            pageDescription.Margin = new Size(
                Math.Max(printPageDescription.ImageableRect.Left,
                         printPageDescription.ImageableRect.Right - printPageDescription.PageSize.Width),
                Math.Max(printPageDescription.ImageableRect.Top,
                         printPageDescription.ImageableRect.Bottom - printPageDescription.PageSize.Height));

            pageDescription.ViewablePageSize = new Size(
                printPageDescription.PageSize.Width - (pageDescription.Margin.Width * 2),
                printPageDescription.PageSize.Height - (pageDescription.Margin.Height * 2));

            // Compute print photo area.
            switch (PhotoSizeSetting)
            {
            case PhotoSize.Size4x6:
                pageDescription.PictureViewSize = new Size(4 * DPI96, 6 * DPI96);
                break;

            case PhotoSize.Size5x7:
                pageDescription.PictureViewSize = new Size(5 * DPI96, 7 * DPI96);
                break;

            case PhotoSize.Size8x10:
                pageDescription.PictureViewSize = new Size(8 * DPI96, 10 * DPI96);
                break;

            case PhotoSize.SizeFullPage:
                pageDescription.PictureViewSize = new Size(
                    pageDescription.ViewablePageSize.Width,
                    pageDescription.ViewablePageSize.Height);
                break;

            default:
                break;
            }

            // Try to maximize photo-size based on it's aspect-ratio.
            if ((pageDescription.ViewablePageSize.Width > pageDescription.ViewablePageSize.Height) && (PhotoSizeSetting != PhotoSize.SizeFullPage))
            {
                // Swap the Height and Width values.
                pageDescription.PictureViewSize = new Size(pageDescription.PictureViewSize.Height, pageDescription.PictureViewSize.Width);
            }

            pageDescription.IsContentCropped = PhotoScale == Scaling.Crop;

            // Recreate content only when:
            // - There is no current page description.
            // - The current page description doesn't match the new one.
            if (CurrentPageDescription == null || !CurrentPageDescription.Equals(pageDescription))
            {
                ClearPageCollection();

                if (pageDescription.PictureViewSize.Width > pageDescription.ViewablePageSize.Width ||
                    pageDescription.PictureViewSize.Height > pageDescription.ViewablePageSize.Height)
                {
                    printDetailedOptions.Options["photoSize"].ErrorText = Tools.GetResourceString("Printer/PhotoSizeError");

                    // Inform preview that it has only 1 page to show.
                    printDoc.SetPreviewPageCount(1, PreviewPageCountType.Intermediate);

                    // Add a custom "preview" unavailable page.
                    lock (PrintSync)
                    {
                        PageCollection[0] = new PreviewUnavailablePage(pageDescription.PageSize, pageDescription.ViewablePageSize);
                    }
                }
                else
                {
                    // Inform preview that is has #NumberOfPhotos pages to show.
                    printDoc.SetPreviewPageCount(NumberOfPhotos, PreviewPageCountType.Intermediate);
                }

                CurrentPageDescription = pageDescription;
            }
        }
        /// <summary>
        /// This is the event handler for PrintManager.PrintTaskRequested.
        /// In order to ensure a good user experience, the system requires that the app handle
        /// the PrintTaskRequested event within the time specified
        /// by PrintTaskRequestedEventArgs->Request->Deadline.
        /// Therefore, we use this handler to only create the print task.
        /// The print settings customization can be done when the print document source is requested.
        /// </summary>
        /// <param name="sender">The print manager for which a print task request was made.</param>
        /// <param name="e">The print taks request associated arguments.</param>
        protected override void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
        {
            PrintTask printTask = null;

            printTask = e.Request.CreatePrintTask(Tools.GetResourceString("Printer/PrintingTask"), sourceRequestedArgs =>
            {
                PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options);

                // Choose the printer options to be shown.
                // The order in which the options are appended determines the order in which they appear in the UI.
                printDetailedOptions.DisplayedOptions.Clear();
                printDetailedOptions.DisplayedOptions.Add(StandardPrintTaskOptions.MediaSize);
                printDetailedOptions.DisplayedOptions.Add(StandardPrintTaskOptions.Copies);

                // Create a new list option.
                PrintCustomItemListOptionDetails photoSize = printDetailedOptions.CreateItemListOption(
                    "photoSize", Tools.GetResourceString("Printer/SizeHeading"));
                photoSize.AddItem("SizeFullPage", Tools.GetResourceString("Printer/SizeFullPage"));
                photoSize.AddItem("Size4x6", Tools.GetResourceString("Printer/Size4x6"));
                photoSize.AddItem("Size5x7", Tools.GetResourceString("Printer/Size5x7"));
                photoSize.AddItem("Size8x10", Tools.GetResourceString("Printer/Size8x10"));

                // Add the custom option to the option list.
                printDetailedOptions.DisplayedOptions.Add("photoSize");

                PrintCustomItemListOptionDetails scaling = printDetailedOptions.CreateItemListOption(
                    "scaling", Tools.GetResourceString("Printer/ScalingHeading"));
                scaling.AddItem("ShrinkToFit", Tools.GetResourceString("Printer/Shrink"));
                scaling.AddItem("Crop", Tools.GetResourceString("Printer/Crop"));

                // Add the custom option to the option list.
                printDetailedOptions.DisplayedOptions.Add("scaling");

                // Set default orientation to landscape.
                printTask.Options.Orientation = PrintOrientation.Landscape;

                // Register for print task option changed notifications.
                printDetailedOptions.OptionChanged += OnPrintDetailedOptionsOptionChanged;

                // Register for print task Completed notification.
                // Print Task event handler is invoked when the print job is completed.
                printTask.Completed += async(s, args) =>
                {
                    await ScenarioPage.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        ClearPageCollection();

                        // Reset image options to default values.
                        PhotoScale       = Scaling.ShrinkToFit;
                        PhotoSizeSetting = PhotoSize.SizeFullPage;

                        // Reset the current page description.
                        CurrentPageDescription = null;

                        // Notify the user when the print operation fails.
                        if (args.Completion == PrintTaskCompletion.Failed)
                        {
                            ColoringPage.NotifyUserAsync(Tools.GetResourceString("Printer/ErrorMessage")).ContinueWithoutWaiting();
                        }
                    });
                };

                // Set the document source.
                sourceRequestedArgs.SetSource(PrintDocumentSource);
            });
        }