/// <summary>
        /// Called when [exception].
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public void OnException(ExceptionContext filterContext)
        {
            var exception = filterContext.Exception?.ToExceptionInfo();

            ContextHelper.Clear();
            Framework.ApiTracking?.LogException(exception);
            filterContext.Result = new JsonNetResult {
                Data = exception
            };
        }
Esempio n. 2
0
        protected void PublishNow_OnClick(object sender, EventArgs e)
        {
            if (!CurrentUser.HasPermission(PermissionsEnum.Publish))
            {
                DisplayErrorMessage("Error publishing item", ErrorHelper.CreateError(new Exception("You do not have the appropriate permissions to publish items")));
                return;
            }

            selectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);

            if (selectedItem == null)
            {
                return;
            }

            var mediaType = MediaTypesMapper.GetByID(selectedItem.MediaTypeID);

            selectedItem.PublishDate = DateTime.Now;

            if (selectedItem.ExpiryDate != null)
            {
                selectedItem.ExpiryDate = null;
            }

            selectedItem.ShowInMenu          = mediaType.ShowInMenu;
            selectedItem.ShowInSearchResults = mediaType.ShowInSearchResults;
            selectedItem.EnableCaching       = mediaType.EnableCaching;

            Return returnObj = MediaDetailsMapper.Update(selectedItem);

            if (returnObj.IsError)
            {
                DisplayErrorMessage("Error Publishing Item", returnObj.Error);
            }
            else
            {
                DisplaySuccessMessage("Successfully Published Item");

                var mediaId = (selectedItem.Media.ParentMediaID != null) ? selectedItem.Media.ParentMediaID : selectedItem.MediaID;

                ExecuteRawJS("RefreshSiteTreeNodeById(" + mediaId + "); ReloadPreviewPanel();");

                UpdateFieldsFromObject();

                PublishNow.Visible = false;
                ContextHelper.Clear(ContextType.Cache);
                FileCacheHelper.ClearAllCache();
            }

            UpdateFieldsFromObject();

            OnPublishExecuteCode();
        }
Esempio n. 3
0
 public virtual void TearDown()
 {
     try
     {
         ContextHelper.Clear();
         if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
         {
             WebDriver.SaveScreenshot();
         }
     }
     finally
     {
         if (acquiredWebDrivers.TryRemove(TestWorkerId, out var webDriver))
         {
             webDriver.Manage().Cookies.DeleteAllCookies();
             AssemblySetUpFixture.WebDriverPool.Release(webDriver);
         }
     }
 }
Esempio n. 4
0
        protected void PublishLive_OnClick(object sender, EventArgs e)
        {
            var returnObj = ((MediaDetail)selectedItem).PublishLive();

            if (!returnObj.IsError)
            {
                ContextHelper.Clear(ContextType.Cache);
                FileCacheHelper.ClearAllCache();

                //if (selectedItem.AbsoluteUrl != liveVersion.AbsoluteUrl)
                //    ChangeLinksForAllMediaDetails(liveVersion.AbsoluteUrl, selectedItem.AbsoluteUrl);

                OnPublishExecuteCode();

                RedirectToAdminUrl(selectedItem);
            }
            else
            {
                DisplayErrorMessage("Error Pushing LIVE", returnObj.Error);
            }
        }
 /// <summary>
 /// Disposes this instance.
 /// </summary>
 protected virtual void Dispose()
 {
     ContextHelper.Clear();
 }
Esempio n. 6
0
        //private void ChangeLinksForAllMediaDetails(string oldAbsoluteUrl, string newAbsoluteUrl)
        //{
        //    if (string.IsNullOrEmpty(oldAbsoluteUrl) || oldAbsoluteUrl == newAbsoluteUrl)
        //        return;

        //    var oldTemplateVarUrl = ParserHelper.ParseData(oldAbsoluteUrl, this.TemplateVars, true);
        //    var newTemplateVarUrl = ParserHelper.ParseData(newAbsoluteUrl, this.TemplateVars, true);

        //    var foundItems = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.MainContent.Contains(oldTemplateVarUrl) || i.ShortDescription.Contains(oldTemplateVarUrl));

        //    if (foundItems.Any())
        //    {
        //        foreach (var item in foundItems)
        //        {
        //            item.ShortDescription = item.ShortDescription.Replace(oldTemplateVarUrl, newTemplateVarUrl);
        //            item.MainContent = item.MainContent.Replace(oldTemplateVarUrl, newTemplateVarUrl);
        //        }

        //        var numberOfItemsEffected = MediaDetailsMapper.GetDataModel().SaveChanges();
        //    }
        //}

        protected void Save_OnClick(object sender, EventArgs e)
        {
            if (CanAccessItem != null && CanAccessItem.IsError)
            {
                DisplayErrorMessage("Error saving item", CanAccessItem.Error);
                return;
            }

            if (!CurrentUser.HasPermission(PermissionsEnum.Publish))
            {
                DisplayErrorMessage("Error saving item", ErrorHelper.CreateError(new Exception("You do not have the appropriate permissions to save items")));
                return;
            }

            string commandArgument = ((LinkButton)sender).CommandArgument;

            bool isDraft = false;

            if (commandArgument == "CreateDraft")
            {
                isDraft = true;
            }

            IMediaDetail history = CreateHistory(isDraft);

            Return returnObj = BaseMapper.GenerateReturn();

            if ((history != null) && (history.IsDraft))
            {
                history.CopyFrom(selectedItem);
                UpdateObjectFromFields(history);
                history.IsDraft = isDraft;

                returnObj = SaveHistory(history);

                if (returnObj.IsError)
                {
                    DisplayErrorMessage("Error Saving Item", returnObj.Error);
                }
                else
                {
                    DisplaySuccessMessage("Successfully Saved Item as Draft");

                    UpdateFieldsFromObject();
                }

                RedirectToAdminUrl(selectedItem, history.HistoryVersionNumber);

                return;
            }

            var tmpSelectedItem = BaseMapper.GetObjectFromContext((MediaDetail)selectedItem);

            if (tmpSelectedItem != null)
            {
                selectedItem = tmpSelectedItem;
            }

            if (parentMediaItem != null)
            {
                parentMediaItem = BaseMapper.GetObjectFromContext(parentMediaItem);
            }
            else
            {
                parentMediaItem = selectedItem?.Media?.ParentMedia;
            }

            if (selectedItem == null)
            {
                selectedItem = MediaDetailsMapper.CreateObject(mediaTypeId, selectedMediaItem, parentMediaItem);
            }

            var oldLinkTitle       = selectedItem.LinkTitle;
            var oldVirtualPath     = selectedItem.VirtualPath;
            var canRender          = selectedItem.CanRender;
            var oldAbsoluteUrl     = selectedItem.AbsoluteUrl;
            var oldPostPublishDate = selectedItem.PublishDate;

            UpdateObjectFromFields(selectedItem);

            var validate = selectedItem.Validate();

            if (validate.IsError)
            {
                DisplayErrorMessage("Error saving item", validate.Error);
                return;
            }

            if ((oldPostPublishDate != selectedItem.PublishDate) && !CurrentUser.HasPermission(PermissionsEnum.Publish))
            {
                DisplayErrorMessage("Error saving item", ErrorHelper.CreateError(new Exception("You do not have the appropriate permissions to publish items")));
                return;
            }

            if (selectedItem.ID == 0)
            {
                selectedItem.CreatedByUserID = CurrentUser.ID;

                if ((parentMediaItem != null) && (selectedItem.Media.ID == 0))
                {
                    selectedItem.Media.OrderIndex = parentMediaItem.ChildMedias.Count(i => i.ID != 0);
                }


                returnObj = MediaDetailsMapper.Insert(selectedItem);

                if (!returnObj.IsError)
                {
                    ContextHelper.Clear(ContextType.Cache);
                    FileCacheHelper.ClearAllCache();
                }
                else
                {
                    DisplayErrorMessage("Error", returnObj.Error);
                }
            }
            else
            {
                if (!isDraft)
                {
                    if (history != null)
                    {
                        returnObj = SaveHistory(history);
                    }

                    //selectedItem.Media.ReorderChildren();

                    if (!returnObj.IsError)
                    {
                        returnObj = MediaDetailsMapper.Update(selectedItem);
                    }
                }
            }

            if (returnObj.IsError)
            {
                DisplayErrorMessage("Error Saving Item", returnObj.Error);
            }
            else
            {
                if (history != null)
                {
                    selectedItem.History.Add((MediaDetail)history);
                    Return historyReturnObj = MediaDetailsMapper.Update(selectedItem);
                }

                selectedItem.RemoveFromCache();
                FileCacheHelper.DeleteGenerateNavCache();

                if (oldVirtualPath != selectedItem.VirtualPath || canRender != selectedItem.CanRender || oldLinkTitle != selectedItem.LinkTitle)
                {
                    ContextHelper.Clear(ContextType.Cache);
                    //FileCacheHelper.ClearCacheDir("generatenav");

                    //FileCacheHelper.ClearAllCache();

                    selectedItem.ClearAutoCalculatedVirtualPathCache();

                    if (commandArgument == "SaveAndPublish")
                    {
                        PublishNow_OnClick(sender, e);
                        //RedirectToMediaDetail(mediaTypeEnum, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                    }
                    else
                    {
                        RedirectToAdminUrl(selectedItem.MediaTypeID, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                    }

                    //ChangeLinksForAllMediaDetails(oldAbsoluteUrl, selectedItem.AbsoluteUrl);
                }

                DisplaySuccessMessage("Successfully Saved Item");

                ExecuteRawJS("ReloadPreviewPanel()");

                if (!selectedItem.IsHistory)
                {
                    SelectedMediaDetail = selectedItem;
                    SelectedMedia       = MediasMapper.GetByID(selectedItem.MediaID);
                }

                if (((Request["selectedMediaId"] == null) || (Request["selectedMediaId"].ToString() == "0")) && (commandArgument != "SaveAndPublish"))
                {
                    RedirectToAdminUrl(selectedItem.MediaTypeID, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                }
                else
                {
                    if (commandArgument == "SaveAndPublish")
                    {
                        PublishNow_OnClick(sender, e);
                        //RedirectToMediaDetail(mediaTypeEnum, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                    }

                    UpdateFieldsFromObject();

                    /*else
                     *  Response.Redirect(Request.Url.AbsoluteUri);*/

                    //UpdateFieldsFromObject();
                    //RedirectToMediaDetail(mediaTypeEnum, selectedItem.MediaID, selectedItem.Media.ParentMediaID);
                }
            }
        }
        /// <summary>
        /// Called when [result executed].
        /// </summary>
        /// <param name="filterContext">The filter context.</param>
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            base.OnResultExecuted(filterContext);

            if (!IsOptions)
            {
                // If using BeyovaBaseController, exception should be logger there, and in this method, no exception should appear.
                var baseException = filterContext.Exception?.Handle(new ExceptionScene
                {
                    MethodName = string.Format("{0}: {1}", filterContext.HttpContext.Request.HttpMethod, filterContext.HttpContext.Request.RawUrl)
                }, data: (filterContext.Exception as BaseException)?.ReferenceData);

                if (baseException != null)
                {
                    filterContext.Exception = baseException;
                }

                if (Depth < 2)
                {
                    if (ApiTracking != null)
                    {
                        DateTime exitStamp = DateTime.UtcNow;

                        // API EXCEPTION
                        if (baseException != null)
                        {
                            try
                            {
                                ApiTracking.LogException(baseException.ToExceptionInfo());
                            }
                            catch { }
                        }

                        // API EVENT
                        if (ApiEvent != null)
                        {
                            try
                            {
                                ApiEvent.ExitStamp    = exitStamp;
                                ApiEvent.ExceptionKey = baseException?.Key;

                                ApiTracking.LogApiEvent(ApiEvent);
                            }
                            catch { }
                        }

                        // API TRACE
                        try
                        {
                            ApiTraceContext.Exit((ApiEvent?.ExceptionKey) ?? (baseException?.Key), exitStamp);
                            var traceLog = ApiTraceContext.GetCurrentTraceLog(true);

                            if (traceLog != null)
                            {
                                ApiTracking.LogApiTraceLog(traceLog);
                            }
                        }
                        catch { }
                    }

                    ContextHelper.Clear();
                }

                Depth--;
            }
        }