Esempio n. 1
0
        protected void DeleteAllHistory_Click(object sender, EventArgs e)
        {
            try
            {
                IEnumerable <IMediaDetail> historyMediaDetails = new List <IMediaDetail>();

                if (DeleteSavedDrafts.Checked)
                {
                    historyMediaDetails = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber > 0);
                }
                else
                {
                    historyMediaDetails = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber > 0 && !i.IsDraft);
                }

                historyMediaDetails = historyMediaDetails.ToList();

                foreach (var item in historyMediaDetails)
                {
                    var returnObj = MediaDetailsMapper.DeletePermanently((MediaDetail)item);
                }

                //ClearAllCache_OnClick(sender, e);
            }
            catch (Exception ex)
            {
                ErrorHelper.LogException(ex);

                DisplayErrorMessage("Error Clearing All Cache", ErrorHelper.CreateError(ex));
            }
        }
        public override void SetValue(object value)
        {
            var field        = GetField();
            var hasDeleted   = false;
            var hasReordered = false;

            if (ItemsToDelete.Text != "" && ItemsToDelete.Text != "[]")
            {
                var deleteIds = StringHelper.JsonToObject <List <long> >(ItemsToDelete.Text);

                foreach (var id in deleteIds)
                {
                    var fieldAssociation = field.FieldAssociations.SingleOrDefault(i => i.ID == id);

                    if (fieldAssociation != null)
                    {
                        var returnObj = MediaDetailsMapper.DeletePermanently(fieldAssociation.MediaDetail);

                        if (!returnObj.IsError)
                        {
                            BaseMapper.DeleteObjectFromContext(fieldAssociation);
                        }

                        hasDeleted = true;
                    }
                }
            }

            if (ReorderItems.Text != "" && ReorderItems.Text != "[]")
            {
                var reorderedIds = StringHelper.JsonToObject <List <long> >(ReorderItems.Text);

                var index = 0;
                foreach (var id in reorderedIds)
                {
                    if (id == null)
                    {
                        return;
                    }

                    var fieldAssociation = field.FieldAssociations.SingleOrDefault(i => i.ID == id);

                    if (fieldAssociation != null)
                    {
                        fieldAssociation.OrderIndex = index;
                        hasReordered = true;

                        index++;
                    }
                }
            }

            if (hasDeleted || hasReordered)
            {
                var returnObj = BaseMapper.SaveDataModel();
            }


            BindValues();
        }
        private void HandleDelete(IMediaDetail item)
        {
            Return returnObj = MediaDetailsMapper.DeletePermanently((MediaDetail)item);

            if (returnObj.IsError)
            {
                BasePage.DisplayErrorMessage("Error deleting association", returnObj.Error);
            }
            else
            {
                BasePage.DisplaySuccessMessage("Successfully deleted association");
                selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);

                Bind();
            }
        }
        private void HandleDeletePermanently(Media item)
        {
            if (!FrameworkSettings.CurrentUser.HasPermission(PermissionsEnum.Delete))
            {
                throw new Exception("You do not have the appropriate permissions to delete items permanently");
            }

            if (item == null)
            {
                return;
            }

            MediaDetail detail      = (MediaDetail)GetAtleastOneByMedia(item);
            Media       parentMedia = null;

            if (item.ParentMediaID != null)
            {
                parentMedia = MediasMapper.GetByID((long)item.ParentMediaID);
            }

            Return returnObj = BaseMapper.GenerateReturn("No action performed");

            if (detail == null)
            {
                if (item.ChildMedias.Count == 0)
                {
                    returnObj = MediasMapper.DeletePermanently(item);
                }
            }
            else
            {
                item = BaseMapper.GetObjectFromContext(item);
                if ((item.MediaDetails.Count == 1) && (item.ChildMedias.Count > 0))
                {
                    throw new Exception("You cannot delete this item because it has child items");
                }

                detail    = BaseMapper.GetObjectFromContext(detail);
                returnObj = MediaDetailsMapper.DeletePermanently(detail);

                if (!returnObj.IsError)
                {
                    ContextHelper.ClearAllMemoryCache();
                    detail.RemoveFromCache();
                }
            }
        }
Esempio n. 5
0
        protected void Delete_Click(object sender, EventArgs e)
        {
            var id = ((LinkButton)sender).CommandArgument;

            if (id != "")
            {
                var mediaDetail = MediaDetailsMapper.GetByID(long.Parse(id));

                if (mediaDetail != null)
                {
                    var returnObj = MediaDetailsMapper.DeletePermanently((MediaDetail)mediaDetail);

                    if (returnObj.IsError)
                    {
                        BasePage.DisplayErrorMessage("Error", returnObj.Error);
                    }
                    else
                    {
                        BasePage.DisplaySuccessMessage("Successfully deleted item");
                    }
                }
            }
        }
        private void HandleDeletePermanentlyRecursive(Media item)
        {
            var parentItem = item.ParentMedia;

            if (!FrameworkSettings.CurrentUser.HasPermission(PermissionsEnum.Delete))
            {
                throw new Exception("You do not have the appropriate permissions to delete items permanently");
            }

            if (item == null)
            {
                return;
            }

            var childItems = item.ChildMedias.ToList();

            var returnObj = new Return();

            foreach (var childItem in childItems)
            {
                var childItemMediaDetails = childItem.MediaDetails.Where(i => i.Language.ID == AdminBasePage.CurrentLanguage.ID).ToList();

                foreach (var childItemMediaDetail in childItemMediaDetails)
                {
                    if ((childItemMediaDetail.Media != null) && (childItemMediaDetail.Media.ChildMedias.Count > 0))
                    {
                        HandleDeletePermanentlyRecursive(childItemMediaDetail.Media);
                    }
                    else
                    {
                        returnObj = MediaDetailsMapper.DeletePermanently(childItemMediaDetail);

                        if (returnObj.IsError)
                        {
                            break;
                        }
                    }
                }
            }

            if (!returnObj.IsError)
            {
                var itemMediaDetails = item.MediaDetails.Where(i => i.Language.ID == AdminBasePage.CurrentLanguage.ID).ToList();
                var allHistory       = itemMediaDetails.Where(i => i.HistoryVersionNumber != 0);
                var liveVersion      = itemMediaDetails.Where(i => i.HistoryVersionNumber == 0);

                foreach (var itemMediaDetail in allHistory)
                {
                    returnObj = MediaDetailsMapper.DeletePermanently(itemMediaDetail);

                    if (returnObj.IsError)
                    {
                        throw returnObj.Error.Exception;
                    }
                }

                foreach (var itemMediaDetail in liveVersion)
                {
                    returnObj = MediaDetailsMapper.DeletePermanently(itemMediaDetail);

                    if (returnObj.IsError)
                    {
                        throw returnObj.Error.Exception;
                    }
                }
            }

            if ((!returnObj.IsError) && (parentItem != null))
            {
                var selectItem = parentItem;

                if (parentItem.ChildMedias.Count > 0)
                {
                    selectItem = parentItem.ChildMedias.ElementAt(0);
                }

                if (selectItem == null)
                {
                    selectItem = parentItem;
                }

                parentItem.ReorderChildren();

                //AdminBasePage.SelectedMedia = selectItem;
            }
        }
Esempio n. 7
0
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            RedisCacheHelper.SetRedisCacheConnectionString(AppSettings.RedisCacheConnectionString);
            FileCacheHelper.SetFileSystemCacheDirPath(AppSettings.FileSystemCacheDirPath);

            virtualPath = URIHelper.GetCurrentVirtualPath().ToLower();

            var queryString = HttpContext.Current.Request.QueryString.ToString();

            queryString = System.Web.HttpUtility.UrlDecode(queryString);


            if (!Request.Path.EndsWith("/") || ((virtualPath != "~/") && (!virtualPath.EndsWith("/"))))
            {
                var path = Request.Path + "/";

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                HttpContext.Current.Response.RedirectPermanent(path);
            }

            Settings cmsSettings            = null;
            bool     isAttemptingAdminLogin = false;

            if ((virtualPath != "~/login/") && (virtualPath != "~/admin/") && string.IsNullOrEmpty(Request.QueryString["format"]))
            {
                cmsSettings = SettingsMapper.GetSettings();

                if (cmsSettings != null)
                {
                    var isSiteOnline = cmsSettings.IsSiteOnline();

                    if (isSiteOnline)
                    {
                        if (virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect("~/");
                        }

                        AttemptToLoadFromCache();
                    }
                    else
                    {
                        if (!virtualPath.Contains(cmsSettings.SiteOfflineUrl))
                        {
                            Response.Redirect(cmsSettings.SiteOfflineUrl);
                        }
                    }
                }
                else
                {
                    AttemptToLoadFromCache();
                }
            }
            else
            {
                isAttemptingAdminLogin = true;
            }

            var languageSegment = FrameworkSettings.GetCurrentLanguage().UriSegment;

            if (LanguagesMapper.GetAllActive().Count() > 1 && !Request.Url.PathAndQuery.Contains($"/{languageSegment}/"))
            {
                var url = URIHelper.ConvertToAbsUrl("/" + languageSegment + Request.Url.PathAndQuery);
                Response.RedirectPermanent(url, true);
            }

            var segments = URIHelper.GetUriSegments(virtualPath).ToList();

            string firstSegment = "";

            if (segments.Count > 0)
            {
                firstSegment = segments[0];

                var language = LanguagesMapper.GetAllActive().SingleOrDefault(i => i.UriSegment == firstSegment);

                if (language != null)
                {
                    FrameworkSettings.SetCurrentLanguage(language);
                }
            }

            if (!isAttemptingAdminLogin && AppSettings.EnableUrlRedirectRules)
            {
                var path = virtualPath;

                if (!string.IsNullOrEmpty(queryString))
                {
                    path = path + "?" + queryString;
                }

                var redirectRule = UrlRedirectRulesMapper.GetRuleForUrl(path);

                if (redirectRule != null)
                {
                    var newUrl = redirectRule.RedirectToUrl;

                    if (newUrl.Contains("{"))
                    {
                        newUrl = MediaDetailsMapper.ParseSpecialTags(redirectRule, newUrl);
                    }

                    newUrl = URIHelper.ConvertToAbsUrl(newUrl);

                    var possibleLoopRules      = UrlRedirectRulesMapper.GetRulesFromUrl(URIHelper.ConvertAbsUrlToTilda(newUrl));
                    var foundActiveVirtualPath = MediaDetailsMapper.GetByVirtualPath(path);

                    if (possibleLoopRules.Any())
                    {
                        foreach (var rule in possibleLoopRules)
                        {
                            var returnObj = MediaDetailsMapper.DeletePermanently(rule);
                        }
                    }

                    if (foundActiveVirtualPath != null)
                    {
                        var returnObj = MediaDetailsMapper.DeletePermanently(redirectRule);
                    }

                    if (Request.QueryString.Count > 0)
                    {
                        newUrl += "?" + Request.QueryString;
                    }

                    if (redirectRule.Is301Redirect)
                    {
                        Response.RedirectPermanent(newUrl);
                    }
                    else
                    {
                        Response.Redirect(newUrl);
                    }
                }
            }

            if (!File.Exists(HttpContext.Current.Server.MapPath(virtualPath)) && !virtualPath.Contains(ParserHelper.OpenToken) && !virtualPath.Contains(ParserHelper.CloseToken))
            {
                string viewPath = "";

                long mediaDetailId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaDetailID"], out mediaDetailId);

                long mediaId = 0;
                long.TryParse(requestContext.HttpContext.Request["MediaID"], out mediaId);

                MediaDetail detail = null;

                if (mediaDetailId == 0 && mediaId == 0)
                {
                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByVirtualPath(virtualPath, true);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaDetailId != 0)
                {
                    var mediaDetail = MediaDetailsMapper.GetByID(mediaDetailId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(mediaDetail);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }
                else if (mediaId != 0)
                {
                    var media = MediasMapper.GetByID(mediaId);

                    FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMedia(media);
                    detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                }

                /*if (detail != null && !detail.CanUserAccessSection(FrameworkSettings.CurrentUser))
                 * {
                 *  FormsAuthentication.RedirectToLoginPage();
                 * }*/

                /*if (detail != null)
                 * {
                 *  var absUrlBase = URIHelper.ConvertAbsUrlToTilda(detail.AbsoluteUrl).Replace("~", "");
                 *  var absPathBase = URIHelper.ConvertAbsUrlToTilda(Request.Url.AbsolutePath).Replace("~", "");
                 *
                 *  if (absUrlBase != absPathBase)
                 *  {
                 *      Response.Redirect(detail.AbsoluteUrl + Request.Url.Query);
                 *  }
                 * }*/

                if (detail != null)
                {
                    if (detail.ForceSSL || AppSettings.ForceSSL)
                    {
                        URIHelper.ForceSSL();
                    }
                }
                else
                {
                    var currentLanguageId = FrameworkSettings.GetCurrentLanguage().ID;

                    var historyVersion = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.LanguageID == currentLanguageId && i.CachedVirtualPath == virtualPath && i.MediaType.ShowInSiteTree && i.HistoryVersionNumber != 0 && i.HistoryForMediaDetail != null);

                    if (historyVersion != null && historyVersion.VirtualPath != historyVersion.HistoryForMediaDetail.VirtualPath)
                    {
                        var foundRedirectUrl = UrlRedirectRulesMapper.GetRuleForUrl(virtualPath);

                        if (foundRedirectUrl == null)
                        {
                            var urlRedirectRule = UrlRedirectRulesMapper.CreateUrlRedirect(virtualPath, historyVersion.HistoryForMediaDetail.Media);

                            if (urlRedirectRule != null)
                            {
                                var returnObj = UrlRedirectRulesMapper.Insert(urlRedirectRule);
                                HttpContext.Current.Response.RedirectPermanent(historyVersion.HistoryForMediaDetail.CachedVirtualPath);
                            }
                            else
                            {
                                HttpContext.Current.Response.RedirectPermanent("/");
                            }
                        }
                    }
                    else
                    {
                        HttpContext.Current.Response.RedirectPermanent("/");
                    }
                }

                if ((detail == null) || (!IsValidRequest(detail)))
                {
                    detail = null;
                    if (cmsSettings != null)
                    {
                        if (!string.IsNullOrEmpty(cmsSettings.PageNotFoundUrl))
                        {
                            ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));

                            Response.Redirect(cmsSettings.PageNotFoundUrl);

                            /*FrameworkSettings.CurrentFrameworkBaseMedia = null;
                             *
                             * FrameworkSettings.CurrentFrameworkBaseMedia = FrameworkBaseMedia.GetInstanceByVirtualPath(cmsSettings.PageNotFoundUrl, true);
                             * detail = (MediaDetail)FrameworkSettings.CurrentFrameworkBaseMedia.CurrentMediaDetail;
                             *
                             * ErrorHelper.LogException(new Exception($"Page Not Found: {virtualPath}"));*/

                            //Response.StatusCode = 301;
                        }
                    }
                }

                if (detail != null)
                {
                    var draft = detail.GetLatestDraft();

                    if (draft != null && (draft.PublishDate - detail.PublishDate) > TimeSpan.FromSeconds(10) && draft.CanRender)
                    {
                        var returnObj = draft.PublishLive();

                        if (!returnObj.IsError)
                        {
                            detail.RemoveFromCache();
                            draft.RemoveFromCache();

                            FrameworkSettings.Current = FrameworkBaseMedia.GetInstanceByMediaDetail(draft);
                            detail = (MediaDetail)FrameworkSettings.Current.CurrentMediaDetail;
                        }
                    }

                    if (detail.RedirectToFirstChild)
                    {
                        var child = detail.ChildMediaDetails.FirstOrDefault();

                        if (child != null)
                        {
                            var redirectPath = child.AutoCalculatedVirtualPath;

                            if (!string.IsNullOrEmpty(queryString))
                            {
                                redirectPath = redirectPath + "?" + queryString;
                            }

                            HttpContext.Current.Response.Redirect(redirectPath);
                        }
                    }

                    viewPath = FrameworkSettings.Current.CurrentMediaDetail.Handler;

                    if ((viewPath == null) || (viewPath.Trim() == ""))
                    {
                        viewPath = MediaTypesMapper.GetByID(FrameworkSettings.Current.CurrentMediaDetail.MediaTypeID).MediaTypeHandler;
                    }

                    viewPath = URIHelper.ConvertAbsUrlToTilda(viewPath);

                    if (!string.IsNullOrEmpty(Request.QueryString["format"]))
                    {
                        FrontEndBasePage.HandleFormatQueryString(detail, Request.QueryString["format"], Request.QueryString["depth"]);
                    }

                    return(CreateInstanceFromVirtualPath(viewPath, typeof(BasePage)));
                }
            }

            return(new DefaultHttpHandler());
        }