public PageViewModel(IAnalyticsService analytics, INavigator navigator, Models.Page page, IDialogProvider dialogProvider)
 : base(analytics) {
     Title = page.Title;
     _navigator = navigator;
     _dialogProvider = dialogProvider;
     Page = page;
     ShowPageCommand = new Command(ShowPage);
 }
Example #2
0
        /// <summary>
        /// Async method retrieving the string content of the HTML page to load and wrapping it in a class.
        /// </summary>
        /// <param name="address">String of the web page address to visit</param>
        /// <param name="formerPage"><seealso cref="Models.Page"/> instance of the former page</param>
        /// <returns><seealso cref="Task{Models.Page}"/>: loaded page returned in a Task. Can also return any error page depending on the HttpError exception thrown by the <seealso cref="HttpRequestController"/></returns>
        public async Task <Models.Page> LoadPage(string address, Models.Page formerPage)
        {
            if (formerPage != null)
            {
                backwardPages.Push(formerPage);
            }
            if (address != null && address != "")
            {
                try
                {
                    var responseBody = await httpRequestController.SendGetAsync(address);

                    return(new Models.Page(address, responseBody));
                }
                catch (Exceptions.PageNotFoundException e)
                {
                    return(new Models.NotFoundPage(address));
                }
                catch (Exceptions.ServerErrorException)
                {
                    return(new Models.ServerErrorPage(address));
                }
                catch (Exceptions.BadRequestException)
                {
                    return(new Models.BadRequestPage(address));
                }
                catch (Exceptions.ForbiddenPageException)
                {
                    return(new Models.ForbiddenPage(address));
                }
                catch (Exceptions.UnsupportedErrorException)
                {
                    return(new Models.UnsupportedErrorPage(address));
                }
            }
            else
            {
                Models.Page page = new Models.NotFoundPage(address);
                return(page);
            }
        }
Example #3
0
 /// <summary>
 /// Retrieve the <seealso cref="Models.Page"/> instance that was right after the current page
 /// </summary>
 /// <param name="currentPage">Current page to be added to the <seealso cref="Controllers.NavigationController.backwardPages"/> stack</param>
 /// <returns><seealso cref="Models.Page"/>: the Page instance that came after the current page. If no page after, returns the currentPage</returns>
 public Models.Page ForwardPage(Models.Page currentPage)
 {
     if (currentPage == null)
     {
         throw new Exceptions.InvalidValuedVariableException("currentPage cannot be null.");
     }
     if (forwardPages.Count != 0)
     {
         backwardPages.Push(currentPage);
         Models.Page toReturn = forwardPages.Pop();
         if (toReturn == null)
         {
             throw new Exceptions.InvalidValuedVariableException("Returned Page cannot be null.");
         }
         return(toReturn);
     }
     else
     {
         return(currentPage);
     }
 }
Example #4
0
        public string AddPage(string blogid, string username, string password, WilderMinds.MetaWeblog.Post post, bool publish)
        {
            ValidateUser(username, password);

            var newPage = new Models.Page
            {
                Title       = post.title,
                Slug        = !string.IsNullOrWhiteSpace(post.wp_slug) ? post.wp_slug : Models.Post.CreateSlug(post.title),
                Content     = post.description,
                IsPublished = publish
            };

            if (post.dateCreated != DateTime.MinValue)
            {
                newPage.PubDate = post.dateCreated;
            }

            _page.SavePage(newPage).GetAwaiter().GetResult();

            return(newPage.ID);
        }
Example #5
0
        private void InsertOrUpdate(Models.Page @new, Models.Page old)
        {
            @new.OnSaving();

            var dbContext = SiteDbContext.CreateDbContext();

            var entity = dbContext.Pages
                         .Where(it => it.SiteName == old.Site.FullName && it.FullName == old.FullName)
                         .FirstOrDefault();

            if (entity != null)
            {
                PageEntityHelper.ToPageEntity(@new, entity);
            }
            else
            {
                dbContext.Pages.Add(PageEntityHelper.ToPageEntity <PageEntity>(@new));
            }
            dbContext.SaveChanges();
            ClearCache();
        }
Example #6
0
        public static async Task <StorageFile> giveMeImage(string link, Models.Page page)
        {
            StorageFile tempFile = null;
            string      type     = Helpers.Any.GetType(link);
            string      hash     = Helpers.Any.CreateMD5(link);

            try
            {
                tempFile = await ApplicationData.Current.TemporaryFolder.GetFileAsync(hash + type);

                System.Diagnostics.Debug.WriteLine("File from cache:" + link);
            }
            catch (Exception)
            {
                tempFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(hash + type, CreationCollisionOption.OpenIfExists);

                await Helpers.Request.rh.DownloadFile(link, tempFile, page);

                System.Diagnostics.Debug.WriteLine("File to cache:" + link);
            }
            return(tempFile);
        }
Example #7
0
        //
        // GET: /Page/
        public ActionResult Index()
        {
            RoteValueHelper rvh = new RoteValueHelper();
            var pageId = rvh.GetInt("pageId", 1);

            var pageBll = new BLL.Page();
            var tagBll = new BLL.Tag();
            var fileBll = new BLL.File();
            Models.Page page = null;
            try
            {
                var pageInfo = pageBll.GetPage(pageId);
                var tagInfos = tagBll.GetPageTags(pageId);
                var imgs = fileBll.GetFileInfos(pageId);

                page = new Models.Page
                {
                    Title = pageInfo.title,
                    AddTime = pageInfo.add_time
                };
                page.Tags = (from t in tagInfos
                             select new Models.Tag
                             {
                                 ID = t.id,
                                 Name = t.tag
                             }).ToList();
                page.Imgs = (from i in imgs
                             select new Models.Img
                             {
                                 Id = i.id,
                                 Path = i.path
                             }).ToList();
            }
            catch (Exception ex) { }
            return View(page);
        }
Example #8
0
        public static Models.Page UpdatePage(ContentServiceConfiguration settings, Models.Page pageToUpdate)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(settings.BaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("api-version", "1.0");

                var stringContent = new StringContent(JsonConvert.SerializeObject(pageToUpdate),
                                                      Encoding.UTF8,
                                                      "application/json");

                HttpResponseMessage response = client.PutAsync(settings.ResourceRoot + "/pages/" + pageToUpdate.PageId.ToString(), stringContent).Result;
                if (response.IsSuccessStatusCode)
                {
                    string stringData = response.Content.ReadAsStringAsync().Result;
                    return(JsonConvert.DeserializeObject <Models.Page>(stringData));
                }
            }

            return(null);
        }
Example #9
0
        // к следующей главе
        private void MangaPages_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MangaPages.SelectedItem == null)
            {
                return;
            }

            Models.Page page = MangaPages.SelectedItem as Models.Page;

            // Next chapter
            if (page.number == Models.Page.NEXT_CHAPTER)
            {
                if (MangaOnPagesPage.Manga.CurrentChapter + 1 != MangaOnPagesPage.Manga.ChaptersCount)
                {
                    MangaOnPagesPage.NextChapter();
                    Helpers.Cache.checkAndFixSize();
                }
                else
                {
                    ClosePages();
                    return;
                }
            }

            // Scroll to 0 0 then page open
            if (page.is_loaded)
            {
                SetZoomAll();
            }
            else
            {
                //System.Diagnostics.Debug.WriteLine("MangaPages_SelectionChanged:" + page.number);
                page.PropertyChanged += Page_PropertyChanged;
            }
            ApplicationView.GetForCurrentView().Title = (MangaPages.SelectedIndex + 1) + " / " + MangaOnPagesPage.Manga.PagesCount;
        }
Example #10
0
 private void BtnCancel_Click(object sender, RoutedEventArgs e)
 {
     Page = null;
     Close();
 }
Example #11
0
        private DataTable GetDataTable()
        {
            int        productionID   = Utils.StringToInt(HiddenProductionID.Value);
            DataTable  dtImageGallery = new DataTable();
            DataColumn newColumn;

            newColumn = dtImageGallery.Columns.Add("ID", Type.GetType("System.Int32"));
            newColumn = dtImageGallery.Columns.Add("Picture", Type.GetType("System.String"));
            newColumn = dtImageGallery.Columns.Add("Description", Type.GetType("System.String"));


            string errmsg = "";

            DataProviders.DBaccess db            = new DataProviders.DBaccess();
            List <int>             masterSetList = new List <int>();

            if (db.GetMasterCopySeparationSetsForProduction(productionID, ref masterSetList, out errmsg) == false)
            {
                return(dtImageGallery);
            }

            string virtualImageFolder = "/CCPreviews";
            string realImageFolder    = HttpContext.Current.Server.MapPath(virtualImageFolder);


            foreach (int masterSet in masterSetList)
            {
                Models.Page page = new Models.Page()
                {
                    MasterCopySeparationSet = masterSet
                };

                db.MasterCopySeparationSetPage(ref page, out errmsg);
                if (page.ProofStatus >= 10 && page.Status >= 10)
                {
                    string fileTitle = $"{page.MasterCopySeparationSet}-{page.Version}.jpg";
                    if (System.IO.File.Exists(realImageFolder + "\\" + fileTitle))
                    {
                        page.VirtualImagePath = virtualImageFolder + "/" + fileTitle;
                    }
                    else
                    {
                        fileTitle = $"{page.MasterCopySeparationSet}.jpg";
                        if (System.IO.File.Exists(realImageFolder + "\\" + fileTitle))
                        {
                            page.VirtualImagePath = virtualImageFolder + "/" + fileTitle;
                        }
                    }
                }

                if (page.VirtualImagePath == "")
                {
                    page.VirtualImagePath = "/Images/NoPage.png";
                }

                DataRow newRow = dtImageGallery.NewRow();
                newRow["ID"]          = page.MasterCopySeparationSet;
                newRow["Picture"]     = page.VirtualImagePath;
                newRow["Description"] = page.PageName + " of " + masterSetList.Count.ToString();
                dtImageGallery.Rows.Add(newRow);
            }
            return(dtImageGallery);
        }
Example #12
0
        private UInt32Value CreateSummaryTableHeader(Worksheet worksheet, SheetData sheetData, UInt32Value currentRowIndex, Models.Page currentPage)
        {
            Row summaryTableCaptionRow = new Row {
                RowIndex = currentRowIndex
            };
            Cell summaryTableCaptionCell = new Cell
            {
                DataType      = CellValues.String,
                CellValue     = new CellValue($"Riepilogo {currentPage.NumberSeriesName}"),
                CellReference = $"A{currentRowIndex}",
                StyleIndex    = 1,
            };

            summaryTableCaptionRow.Append(summaryTableCaptionCell);
            sheetData.Append(summaryTableCaptionRow);

            Merge(worksheet, summaryTableCaptionCell.CellReference, $"C{currentRowIndex}");

            currentRowIndex += 1;
            Row summaryHeaderRow = new Row {
                RowIndex = currentRowIndex
            };
            Cell summaryHeaderCell_VatCode = new Cell
            {
                DataType      = CellValues.String,
                CellValue     = new CellValue("Cod. IVA"),
                CellReference = $"A{currentRowIndex}",
                StyleIndex    = 2,
            };

            Cell summaryHeaderCell_VatDescription = new Cell
            {
                DataType      = CellValues.String,
                CellValue     = new CellValue("Descrizione IVA"),
                CellReference = $"B{currentRowIndex}",
                StyleIndex    = 2,
            };

            Cell summaryHeaderCell_VatRate = new Cell
            {
                DataType      = CellValues.String,
                CellValue     = new CellValue("% IVA"),
                CellReference = $"D{currentRowIndex}",
                StyleIndex    = 2,
            };

            Cell summaryHeaderCell_Amount = new Cell
            {
                DataType      = CellValues.String,
                CellValue     = new CellValue("Imponibile"),
                CellReference = $"E{currentRowIndex}",
                StyleIndex    = 2,
            };

            Cell summaryHeaderCell_Vat = new Cell
            {
                DataType      = CellValues.String,
                CellValue     = new CellValue("Imposta"),
                CellReference = $"F{currentRowIndex}",
                StyleIndex    = 2,
            };

            Cell summaryHeaderCell_Total = new Cell
            {
                DataType      = CellValues.String,
                CellValue     = new CellValue("Totale"),
                CellReference = $"G{currentRowIndex}",
                StyleIndex    = 2,
            };

            summaryHeaderRow.Append(summaryHeaderCell_VatCode, summaryHeaderCell_VatDescription, summaryHeaderCell_VatRate,
                                    summaryHeaderCell_Amount, summaryHeaderCell_Vat, summaryHeaderCell_Total);

            sheetData.Append(summaryHeaderRow);

            Merge(worksheet, summaryHeaderCell_VatDescription.CellReference, $"C{currentRowIndex}");

            return(currentRowIndex);
        }
Example #13
0
 public static Models.Page RaisePageEvent(enumEventType eventtype, RenderContext context, Models.Page page = null)
 {
     if (eventtype == enumEventType.PageFinding)
     {
         PageFinding finding = new PageFinding(context);
         RaiseEvent(context, finding);
         return(finding.Page);
     }
     else if (eventtype == enumEventType.PageFound)
     {
         if (page != null)
         {
             PageFound found = new PageFound(context, page);
             RaiseEvent(context, found);
             if (found.DataChange && found.Page != null)
             {
                 return(found.Page);
             }
         }
     }
     //else if (eventtype == enumEventType.)
     //{
     //    PageNotFound notfound = new PageNotFound(context);
     //    RaiseEvent(context, notfound);
     //    return notfound.Page;
     //}
     return(null);
 }
Example #14
0
        private UInt32Value CreateSummaryTableRows(Worksheet worksheet, SheetData sheetData, UInt32Value currentRowIndex, Models.Page currentPage)
        {
            foreach (var item in currentPage.Summary)
            {
                Row summaryRow = new Row {
                    RowIndex = currentRowIndex
                };
                Cell summaryCell_VatCode = new Cell
                {
                    DataType      = CellValues.String,
                    CellValue     = new CellValue(item.VatCode),
                    CellReference = $"A{currentRowIndex}",
                    StyleIndex    = 0,
                };

                Cell summaryCell_VatDescription = new Cell
                {
                    DataType      = CellValues.String,
                    CellValue     = new CellValue(item.VatDescription),
                    CellReference = $"B{currentRowIndex}",
                    StyleIndex    = 0,
                };

                Cell summaryCell_VatRate = new Cell
                {
                    DataType      = CellValues.Number,
                    CellValue     = new CellValue(Convert.ToString(item.RatePercentage.Value)),
                    CellReference = $"D{currentRowIndex}",
                    StyleIndex    = 0,
                };

                Cell summaryCell_Amount = new Cell
                {
                    DataType      = CellValues.Number,
                    CellValue     = new CellValue(Convert.ToString(item.Amount.Value)),
                    CellReference = $"E{currentRowIndex}",
                    StyleIndex    = 0,
                };

                Cell summaryCell_Vat = new Cell
                {
                    DataType      = CellValues.Number,
                    CellValue     = new CellValue(Convert.ToString(item.Vat.Value)),
                    CellReference = $"F{currentRowIndex}",
                    StyleIndex    = 0,
                };

                Cell summaryCell_Total = new Cell
                {
                    DataType      = CellValues.Number,
                    CellValue     = new CellValue(Convert.ToString(item.Total.Value)),
                    CellReference = $"G{currentRowIndex}",
                    StyleIndex    = 0,
                };

                summaryRow.Append(summaryCell_VatCode, summaryCell_VatDescription, summaryCell_VatRate,
                                  summaryCell_Amount, summaryCell_Vat, summaryCell_Total);

                sheetData.Append(summaryRow);

                Merge(worksheet, summaryCell_VatDescription.CellReference, $"C{currentRowIndex}");

                currentRowIndex += 1;
            }

            Row summaryTotalRow = new Row {
                RowIndex = currentRowIndex
            };
            Cell summaryTotalCaptionCell = new Cell
            {
                DataType      = CellValues.String,
                CellValue     = new CellValue("Totale"),
                CellReference = $"D{currentRowIndex}",
                StyleIndex    = 1,
            };

            Cell summaryAmountCell = new Cell
            {
                DataType      = CellValues.Number,
                CellValue     = new CellValue(Convert.ToString(currentPage.SummaryAmount.Value)),
                CellReference = $"E{currentRowIndex}",
                StyleIndex    = 1,
            };

            Cell summaryVatCell = new Cell
            {
                DataType      = CellValues.Number,
                CellValue     = new CellValue(Convert.ToString(currentPage.SummaryVat.Value)),
                CellReference = $"F{currentRowIndex}",
                StyleIndex    = 1,
            };

            Cell summaryTotalCell = new Cell
            {
                DataType      = CellValues.Number,
                CellValue     = new CellValue(Convert.ToString(currentPage.SummaryTotal.Value)),
                CellReference = $"G{currentRowIndex}",
                StyleIndex    = 1,
            };


            summaryTotalRow.Append(summaryTotalCaptionCell, summaryAmountCell, summaryVatCell, summaryTotalCell);
            sheetData.Append(summaryTotalRow);

            return(currentRowIndex);
        }
Example #15
0
        private void Initialize(BaseViewModel parent, ProjectItemViewModel item, Models.PageType type)
        {
            _ProjectItem = item;

            _Model = new Models.Page();
            Header = item.Name;
            Identifier = Guid.NewGuid();
            Type = type;

            item.PropertyChanged += ProjectItem_PropertyChanged;

            BuildEditor();

            _CloseFileCommand = new Commands.DelegateCommand(PerformCloseFile);
            _SelectPageCommand = new Commands.DelegateCommand(PerformSelectPage);
        }
Example #16
0
 public void Update(Models.Page @new, Models.Page old)
 {
     InsertOrUpdate(@new, old);
 }
Example #17
0
 public IEnumerable <Models.Page> ChildPages(Models.Page parentPage)
 {
     return(ChildPagesEnumerable(parentPage).AsQueryable());
 }
Example #18
0
 /// <summary>
 /// Sets the current page to the given value. This can be
 /// useful when using the UI helper in passive mode and the
 /// routing never sets the current page.
 /// </summary>
 /// <param name="page">The page</param>
 public static void SetCurrent(Models.Page page)
 {
     HttpContext.Current.Items["Piranha_CurrentPage"] = page;
 }
Example #19
0
 public void Remove(Models.Page item)
 {
     RemovePageWithChildPages(item);
 }
Example #20
0
 public IEnumerable <Page> ChildPages(Models.Page parentPage)
 {
     return(DataHelper.QueryList <Page>(parentPage.Site, ModelExtensions.GetQueryView(ModelExtensions.PageDataType), createModel)
            .Where(it => it.Parent == parentPage));
 }
Example #21
0
 public PageViewModel(Models.Page page)
 {
     SetPage(page);
 }
Example #22
0
 public SelectSection(Models.Page page)
 {
     InitializeComponent();
     LoadSections(page);
 }
        public async Task <ResponseAddCommentViewModel> Post(PostCommentViewModel model)
        {
            if (model.AuthenticatedMode && (string.IsNullOrEmpty(model.Id) || string.IsNullOrEmpty(model.Token)))
            {
                return(new ResponseAddCommentViewModel(ResponseAddCommentViewModel.OperationResult.Invalid));
            }
            if (string.IsNullOrEmpty(model.SourcePlatform) || string.IsNullOrWhiteSpace(model.PageIdentifier) ||
                string.IsNullOrWhiteSpace(model.Content))
            {
                return(new ResponseAddCommentViewModel(ResponseAddCommentViewModel.OperationResult.Invalid));
            }

            if (!(await _authorizationService.AuthorizeAsync(null, model, new Requirements.AuthorizedUserRequirement())))
            {
                return(new ResponseAddCommentViewModel(ResponseAddCommentViewModel.OperationResult.AuthorizationFailed));
            }

            bool IsNewPage = false;

            var page = await _dbContext.Pages.SingleOrDefaultAsync(p => p.PublicIdentifier == model.PageIdentifier && p.SourcePlatformId == model.SourcePlatform);

            if (page == null)
            {
                page = new Models.Page()
                {
                    Id = ShortGuid.NewGuid().Value,
                    SourcePlatformId = model.SourcePlatform,
                    PublicIdentifier = model.PageIdentifier
                };
                IsNewPage = true;
            }

            var parentComment = await _dbContext.Comments.SingleOrDefaultAsync(c => c.Id == model.Parent && c.PageId == page.Id);

            bool added = true;
            ResponseAddCommentViewModel commentResponse = null;

            Models.Comment comment = null;
            if (!string.IsNullOrWhiteSpace(model.Current) && model.Current.Length == 22)
            {
                //Editing comment is only available in authenticated mode.
                if (model.AuthenticatedMode)
                {
                    comment = await _dbContext.Comments.SingleOrDefaultAsync(c => c.Id == model.Current && c.AuthorId == model.Id);
                }
                if (comment == null)
                {
                    return(new ResponseAddCommentViewModel(ResponseAddCommentViewModel.OperationResult.AuthorizationFailed));
                }
                commentResponse = new ResponseAddCommentViewModel(ResponseAddCommentViewModel.OperationResult.CommentEdited);
                comment.Content = model.Content;
                added           = false;
            }
            else
            {
                commentResponse = new ResponseAddCommentViewModel(ResponseAddCommentViewModel.OperationResult.CommentAdded);
                comment         = new Models.Comment()
                {
                    Title    = model.Title,
                    Content  = model.Content,
                    PostDate = DateTime.UtcNow,
                    PageId   = page.Id,
                };
            }

            if (!model.AuthenticatedMode)
            {
                Models.Author AnonymousAuthor = new Models.Author()
                {
                    Id = ShortGuid.NewGuid().Value,
                    SourcePlatformId = model.SourcePlatform,
                    DisplayName      = model.Pseudonym ?? "Anonymous",
                    Email            = model.Email,
                    IsAnonymous      = true,
                    WebSite          = model.Website,
                };
                //set comment's author to newly created Anonymous Author
                comment.AuthorId = AnonymousAuthor.Id;
                //Fill response data
                commentResponse.Author     = AnonymousAuthor.DisplayName;
                commentResponse.ProfileUrl = AnonymousAuthor.WebSite;
                //Add anonymous user to database.
                await _dbContext.Authors.AddAsync(AnonymousAuthor);
            }
            else
            {
                var author = await _dbContext.Authors.SingleOrDefaultAsync(a => a.Id == model.Id);

                //Set AuthorId
                comment.AuthorId = model.Id;
                //Fill Response data
                commentResponse.Author    = author.DisplayName;
                commentResponse.AvatarUrl = author.AvatarUrl;
                //todo : profile url.
            }

            commentResponse.Title   = model.Title;
            commentResponse.Content = model.Content;

            if (parentComment != null)
            {
                comment.Depth    = (byte)(parentComment.Depth + 1);
                comment.ParentId = parentComment.Id;
                commentResponse.ParentCommentId = parentComment.Id;
                commentResponse.Depth           = comment.Depth;
            }
            else
            {
                commentResponse.Depth = 1;
            }

            if (added)
            {
                //Add comment
                await _dbContext.Comments.AddAsync(comment);

                //Update page count
                page.CommentsCount++;
                //Insert/Update page in dbContext.
                if (!IsNewPage)
                {
                    _dbContext.Pages.Update(page);
                }
                else
                {
                    await _dbContext.Pages.AddAsync(page);
                }
            }
            else
            {
                //Update comment
                _dbContext.Comments.Update(comment);
            }

            //Save changes
            await _dbContext.SaveChangesAsync();

            return(commentResponse);
        }
Example #24
0
        public Models.Page Get(Models.Page dummy)
        {
            var bucketDocumentKey = ModelExtensions.GetBucketDocumentKey(ModelExtensions.PageDataType, dummy.FullName);

            return(DataHelper.QueryByKey <Page>(dummy.Site, bucketDocumentKey, createModel));
        }
Example #25
0
 public void Localize(Models.Page o, Models.Site targetSite)
 {
     inner.Localize(o, targetSite);
     targetSite.ClearCache();
 }
Example #26
0
 public void Localize(Models.Page o, Models.Site targetSite)
 {
     LocalizeWithChildPages(o, targetSite);
 }
Example #27
0
 public PageView(Models.Page page)
 {
     InitializeComponent();
     Page = page;
 }
Example #28
0
 public NewSection(Models.Page page)
 {
     this.page = page;
     InitializeComponent();
 }
Example #29
0
 public async Task WhenIReadUsers()
 {
     _pageUser = await _usersController.ReadAll(null, CancellationToken.None);
 }
Example #30
0
 public void Add(Models.Page item)
 {
     InsertOrUpdate(item, item);
 }
Example #31
0
        public Page(Models.Page businessPage)
        {
            _width  = Convert.ToInt32(businessPage.Width.Points);
            _height = Convert.ToInt32(businessPage.Height.Points);

            //TODO: Bleed and slug

            _bitmap = new System.Drawing.Bitmap(_width, _height);
            Graphics pageGraphics = Graphics.FromImage(_bitmap);

            _bitmap.MakeTransparent();


            foreach (IPageElement bElement in businessPage.Contents.Elements)
            {
                switch (bElement.GetType().Name.ToLower())
                {
                case "image":
                    var bImage = (Image)bElement;
                    try
                    {
                        System.Drawing.Image dImage = System.Drawing.Image.FromFile(new Uri(bImage.Uri).LocalPath);
                        pageGraphics.DrawImage(dImage,
                                               new Rectangle(bImage.LayoutContainer.Layout.Left.GetIntegerValue(),
                                                             bImage.LayoutContainer.Layout.Top.GetIntegerValue(),
                                                             bImage.LayoutContainer.Layout.Width.GetIntegerValue(),
                                                             bImage.LayoutContainer.Layout.Height.GetIntegerValue()));
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    break;

                case "line":

                    var bLine   = (Line)bElement;
                    var linePen =
                        new Pen(Color.FromArgb(bLine.Color.RGBColor.Red, bLine.Color.RGBColor.Green,
                                               bLine.Color.RGBColor.Blue), bLine.Width.Points);
                    pageGraphics.DrawLine(linePen, bLine.LayoutContainer.Layout.Left.GetIntegerValue(),
                                          bLine.LayoutContainer.Layout.Top.GetIntegerValue(),
                                          bLine.LayoutContainer.Layout.Right.GetIntegerValue(),
                                          bLine.LayoutContainer.Layout.Bottom.GetIntegerValue());

                    break;

                case "rectangle":

                    var bRectangle = (Models.Rectangle)bElement;
                    var rectPen    =
                        new Pen(Color.FromArgb(bRectangle.BorderColor.RGBColor.Red,
                                               bRectangle.BorderColor.RGBColor.Green,
                                               bRectangle.BorderColor.RGBColor.Blue,
                                               bRectangle.BorderWidth.GetIntegerValue()));
                    var rectangle =
                        new Rectangle(bElement.LayoutContainer.Layout.Left.GetIntegerValue(),
                                      bElement.LayoutContainer.Layout.Top.GetIntegerValue(),
                                      bElement.LayoutContainer.Layout.Width.GetIntegerValue(),
                                      bElement.LayoutContainer.Layout.Height.GetIntegerValue());
                    pageGraphics.DrawRectangle(rectPen, rectangle);

                    if (bRectangle.FillColor != null)
                    {
                        Color fillColor = Color.FromArgb(bRectangle.FillColor.RGBColor.Red,
                                                         bRectangle.FillColor.RGBColor.Green,
                                                         bRectangle.FillColor.RGBColor.Blue);
                        pageGraphics.FillRectangle(new SolidBrush(fillColor), rectangle);
                    }

                    break;

                case "text":
                    var bText = (Text)bElement;

                    var placeholderRectangle =
                        new RectangleF(bText.LayoutContainer.Layout.Left.GetIntegerValue(),
                                       bText.LayoutContainer.Layout.Top.GetIntegerValue(),
                                       bText.LayoutContainer.Layout.Width.GetIntegerValue(),
                                       bText.LayoutContainer.Layout.Height.GetIntegerValue());

                    foreach (Paragraph bTextParagraph in bText.Paragraphs)
                    {
                        var paragraphFormat = new StringFormat();
                        paragraphFormat.LineAlignment = GetAligment(bTextParagraph.Alignment);


                        foreach (TextElement bTextElement in bTextParagraph.TextElements)
                        {
                            //TODO: Use logic from PDF text to calculate text width and height + placement.
                            var font = new Font(bTextElement.FontStyle.Path,
                                                bTextElement.FontSize.Points, FontStyle.Regular);

                            var brush =
                                new SolidBrush(Color.FromArgb(bTextElement.Color.RGBColor.Red,
                                                              bTextElement.Color.RGBColor.Green,
                                                              bTextElement.Color.RGBColor.Blue));
                            pageGraphics.DrawString(bTextElement.Text, font, brush, placeholderRectangle,
                                                    paragraphFormat);
                            SizeF stringArea = pageGraphics.MeasureString(bTextElement.Text, font,
                                                                          bElement.LayoutContainer.Layout.Width.
                                                                          GetIntegerValue(), paragraphFormat);
                        }
                    }

                    break;
                }


                pageGraphics.Save();
            }

            _bitmap.Save("Page_" + businessPage.Key + ".png");
        }
        /// <summary>
        /// Triggered before an action is executed on the controller
        /// </summary>
        /// <param name="filterContext">The context</param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string permalink = Request["permalink"];
            bool   draft     = false;
            bool   cached    = false;

            // Check if we want to see the draft
            if (User.HasAccess("ADMIN_PAGE"))
            {
                if (!String.IsNullOrEmpty(Request["draft"]))
                {
                    try {
                        draft = Convert.ToBoolean(Request["draft"]);
                    } catch {}
                }
            }

            // Load the current page
            if (!String.IsNullOrEmpty(permalink))
            {
                page = Models.Page.GetByPermalink(permalink, draft);
            }
            else
            {
                page = Models.Page.GetStartpage(draft);
            }

            // Check permissions
            if (page.GroupId != Guid.Empty)
            {
                if (!User.IsMember(page.GroupId))
                {
                    SysParam param = SysParam.GetByName("LOGIN_PAGE");
                    if (param != null)
                    {
                        Response.Redirect(param.Value);
                    }
                    else
                    {
                        Response.Redirect("~/");
                    }
                }
                Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
            }
            else
            {
                // Only cache public pages
                DateTime mod = GetLastModified();
                cached = false;                 // ClientCache.HandleClientCache(HttpContext.Current, page.Id.ToString(), mod) ;
            }
            // Load the model if the page wasn't cached
            if (!cached)
            {
                model = PageModel.Get(page);
            }

            // Execute hook, if it exists
            if (WebPages.Hooks.Model.PageModelLoaded != null)
            {
                WebPages.Hooks.Model.PageModelLoaded(model);
            }

            base.OnActionExecuting(filterContext);
        }
Example #33
0
        public ActionResult Create()
        {
            var page = new Models.Page();

            return(View(page));
        }