Beispiel #1
0
        private ValiditySetting GetValiditySetting(SNC.Content content)
        {
            ValiditySetting result = new ValiditySetting();

            //if (!String.IsNullOrEmpty(this.ValidFromPropertyName))
            //    result.ValidFromPropertyName = this.ValidFromPropertyName;
            //if (!String.IsNullOrEmpty(this.ValidTillPropertyName))
            //    result.ValidTillPropertyName = this.ValidTillPropertyName;

            // try to fetch PreviewDate value
            if (content.Security.HasPermission(SenseNet.ContentRepository.Storage.Schema.PermissionType.OpenMinor))
            {
                result.CurrentDateTime = GetPreviewDate();
            }

            // reads property values
            result.Fill(content);

            // if error has been occured while parsing property values, returns null.
            if (!result.IsValid)
            {
                return(null);
            }

            return(result);
        }
Beispiel #2
0
        private void BuildContentView(string contentTypeName, Node parent, ViewMode viewMode)
        {
            var viewPath = string.Empty;

            #region creates container)
            if (_container == null)
            {
                CreateContainer();
            }
            else
            {
                _container.Controls.Clear();
            }

            if (this._container.Parent == null)
            {
                this.Controls.Add(this._container);
            }
            #endregion

            #region creates new content or loads an existing one
            // when we are in InlineNew creates an empty content
            if (viewMode == ViewMode.InlineNew)
            {
                if (!string.IsNullOrEmpty(contentTypeName) && !((GenericContent)PortalContext.Current.ContextNode).IsAllowedChildType(contentTypeName))
                {
                    var ct = ContentType.GetByName(contentTypeName);
                    this._errorMessage = string.Format(SR.GetString("SingleContentPortlet", "TypeIsNotAllowed"), ct != null ? Content.Create(ct).DisplayName : contentTypeName);
                    ShowSimpleErrorMessage();
                    return;
                }

                _content = SNC.Content.CreateNew(contentTypeName, parent, string.Empty);
            }

            // when the portlet is in browse, edit, inlineedit states, loads the content
            if (viewMode == ViewMode.Browse ||
                viewMode == ViewMode.Edit ||
                viewMode == ViewMode.InlineEdit)
            {
                Node node = Node.LoadNode(this.AbsoulteContentPath);

                // check if can select a single node (ie smartfolderex)
                ICustomSingleNode singleNode = node as ICustomSingleNode;

                // select single node
                if (singleNode != null)
                {
                    node = singleNode.SelectedItem();
                }

                if (node == null)
                {
                    _content = null;
                }
                else
                {
                    _content = SNC.Content.Create(node);
                }
            }

            #endregion

            if (viewMode == ViewMode.InlineEdit || viewMode == ViewMode.Edit)
            {
                this._displayMode = GetViewModeName(ViewMode.Edit);
            }

            // if content does not exist stop creating controls.
            if (_content == null)
            {
                this._errorMessage = String.Format(HttpContext.GetGlobalResourceObject("SingleContentPortlet", "PathNotFound") as string, AbsoulteContentPath);
                return;
            }

            #region checks validity

            // if content is not valid, exit the method, and an empty contol will be shown to the user.
            if (this.ValidationSetting != ValidationOption.DontCheckValidity)
            {
                // Use cache setting for deciding if we need to check content expiration.
                // This code will not run if the user is in one of the administrator groups.
                // Equivalent to: !PortalContext.IsInAdminGroup(User.Current, AdminGroupPaths)
                if (PortalContext.Current.LoggedInUserCacheEnabled)
                {
                    _validitySetting = GetValiditySetting(_content);
                    if (_validitySetting != null)
                    {
                        // User has been set the ValidationSetting,
                        // and checks the content will be displayed or not.
                        // if the content is not visible, just return (and don't do anything else)
                        // otherwise the content processing will be going on.
                        switch (this.ValidationSetting)
                        {
                        case ValidationOption.ShowAllValid:
                            if (!_validitySetting.ShowAllValidContent)
                            {
                                return;
                            }
                            break;

                        case ValidationOption.ShowValidButArchived:
                            if (!_validitySetting.ShowValidAndArchived)
                            {
                                return;
                            }
                            break;

                        case ValidationOption.ShowValidButNotArchived:
                            if (!_validitySetting.ShowValidAndNotArchived)
                            {
                                return;
                            }
                            break;

                        case ValidationOption.DontCheckValidity:
                        default:
                            break;
                        }
                    }
                }
            }
            #endregion


            viewPath = GetViewPath();


            // try to create ContentView which contains all webcontrols of the content
            try
            {
                if (this.UseUrlPath)
                {
                    _contentView = ContentView.Create(_content, this.Page, viewMode, String.IsNullOrEmpty(this.ContentViewPath) ? viewPath : this.ContentViewPath);
                }
                else
                {
                    _contentView = ContentView.Create(_content, this.Page, viewMode, viewPath);
                }

                _container.Controls.Remove(_contentView);
            }
            catch (Exception e) // logged
            {
                SnLog.WriteException(e);
                this._errorMessage = String.Format("Message: {0} {1} Source: {2} {3} StackTrace: {4} {5}", e.Message, Environment.NewLine, e.Source, Environment.NewLine, e.StackTrace, Environment.NewLine);
                return;
            }

            _contentView.UserAction           += _contentView_UserAction;
            _contentView.CommandButtonsAction += _contentView_CommandButtonsAction;
            _container.Controls.Add(_contentView);
        }
        private void BuildContentView(string contentTypeName, Node parent, ViewMode viewMode)
        {
            var viewPath = string.Empty;

            #region creates container)
            if (_container == null)
                CreateContainer();
            else
            {
                _container.Controls.Clear();
                //this.Controls.Remove(_container);
            }
            
            if (this._container.Parent == null) this.Controls.Add(this._container);
            #endregion

            #region creates new content or loads an existing one
            // when we are in InlineNew creates an empty content
            if (viewMode == ViewMode.InlineNew)
                _content = SNC.Content.CreateNew(contentTypeName, parent, string.Empty);

            // when the portlet is in browse, edit, inlineedit states, loads the content
            if (viewMode == ViewMode.Browse ||
                viewMode == ViewMode.Edit ||
                viewMode == ViewMode.InlineEdit)
            {
                
                Node node = Node.LoadNode(this.AbsoulteContentPath);

                // check if can select a single node (ie smartfolderex)
                ICustomSingleNode singleNode = node as ICustomSingleNode;

                // select single node
                if (singleNode != null)
                    node = singleNode.SelectedItem();

                if (node == null)
                    _content = null;
                else
                    _content = SNC.Content.Create(node);

                //_content = SNC.Content.Load(this.AbsoulteContentPath);
            }

            #endregion

            if (viewMode == ViewMode.InlineEdit || viewMode == ViewMode.Edit)
                this._displayMode = GetViewModeName(ViewMode.Edit);

            // if content does not exist stop creating controls.
            if (_content == null)
            {               
               this._errorMessage = String.Format(HttpContext.GetGlobalResourceObject("SingleContentPortlet", "PathNotFound") as string,AbsoulteContentPath);
               return;
            }

            #region checks validity
            // if content is not valid, exit the method, and an empty contol will be shown to the user.

            if (User.Current.Id == User.Visitor.Id)
            {
                if (this.ValidationSetting != ValidationOption.DontCheckValidity)
                {
                    _validitySetting = GetValiditySetting(_content);
                    if (_validitySetting != null)
                    {
                        // User has been set the ValidationSetting,
                        // and checks the content will be displayed or not.
                        // if the content is not visible, just return (and don't do anything else)
                        // otherwise the content processing will be going on.
                        switch (this.ValidationSetting)
                        {
                            case ValidationOption.ShowAllValid:
                                if (!_validitySetting.ShowAllValidContent)
                                    return;
                                break;
                            case ValidationOption.ShowValidButArchived:
                                if (!_validitySetting.ShowValidAndArchived)
                                    return;
                                break;
                            case ValidationOption.ShowValidButNotArchived:
                                if (!_validitySetting.ShowValidAndNotArchived)
                                    return;
                                break;
                            case ValidationOption.DontCheckValidity:    // not used
                            default:
                                break;
                        }


                    }
                }
            }
            #endregion

            
            viewPath = GetViewPath();


            // try to create ContentView which contains all webcontrols of the content
            try
            {
                if (this.UseUrlPath )
                    _contentView = ContentView.Create(_content, this.Page, viewMode, String.IsNullOrEmpty(this.ContentViewPath) ? viewPath : this.ContentViewPath);
                else
                    _contentView = ContentView.Create(_content, this.Page, viewMode, viewPath);
                
                _container.Controls.Remove(_contentView);
            }
            catch (Exception e) //logged
            {
                Logger.WriteException(e);
                this._errorMessage = String.Format("Message: {0} {1} Source: {2} {3} StackTrace: {4} {5}", e.Message, Environment.NewLine, e.Source, Environment.NewLine, e.StackTrace, Environment.NewLine);
                return;
            }

            _contentView.UserAction += new EventHandler<UserActionEventArgs>(_contentView_UserAction);
            _container.Controls.Add(_contentView);

        }
		private ValiditySetting GetValiditySetting(SNC.Content content)
		{
			ValiditySetting result = new ValiditySetting();

			//if (!String.IsNullOrEmpty(this.ValidFromPropertyName))
			//    result.ValidFromPropertyName = this.ValidFromPropertyName;
			//if (!String.IsNullOrEmpty(this.ValidTillPropertyName))
			//    result.ValidTillPropertyName = this.ValidTillPropertyName;

			// try to fetch PreviewDate value
			if (content.Security.HasPermission(SenseNet.ContentRepository.Storage.Schema.PermissionType.OpenMinor))
				result.CurrentDateTime = GetPreviewDate();

			// reads property values
			result.Fill(content);

			// if error has been occured while parsing property values, returns null.
			if (!result.IsValid)
				return null;

			return result;
		}
        private void BuildContentView(string contentTypeName, Node parent, ViewMode viewMode)
        {
            var viewPath = string.Empty;

            #region creates container)
            if (_container == null)
            {
                CreateContainer();
            }
            else
            {
                _container.Controls.Clear();
                //this.Controls.Remove(_container);
            }

            if (this._container.Parent == null)
            {
                this.Controls.Add(this._container);
            }
            #endregion

            #region creates new content or loads an existing one
            // when we are in InlineNew creates an empty content
            if (viewMode == ViewMode.InlineNew)
            {
                _content = SNC.Content.CreateNew(contentTypeName, parent, string.Empty);
            }

            // when the portlet is in browse, edit, inlineedit states, loads the content
            if (viewMode == ViewMode.Browse ||
                viewMode == ViewMode.Edit ||
                viewMode == ViewMode.InlineEdit)
            {
                Node node = Node.LoadNode(this.AbsoulteContentPath);

                // check if can select a single node (ie smartfolderex)
                ICustomSingleNode singleNode = node as ICustomSingleNode;

                // select single node
                if (singleNode != null)
                {
                    node = singleNode.SelectedItem();
                }

                if (node == null)
                {
                    _content = null;
                }
                else
                {
                    _content = SNC.Content.Create(node);
                }

                //_content = SNC.Content.Load(this.AbsoulteContentPath);
            }

            #endregion

            if (viewMode == ViewMode.InlineEdit || viewMode == ViewMode.Edit)
            {
                this._displayMode = GetViewModeName(ViewMode.Edit);
            }

            // if content does not exist stop creating controls.
            if (_content == null)
            {
                this._errorMessage = String.Format(HttpContext.GetGlobalResourceObject("SingleContentPortlet", "PathNotFound") as string, AbsoulteContentPath);
                return;
            }

            #region checks validity
            // if content is not valid, exit the method, and an empty contol will be shown to the user.

            if (User.Current.Id == User.Visitor.Id)
            {
                if (this.ValidationSetting != ValidationOption.DontCheckValidity)
                {
                    _validitySetting = GetValiditySetting(_content);
                    if (_validitySetting != null)
                    {
                        // User has been set the ValidationSetting,
                        // and checks the content will be displayed or not.
                        // if the content is not visible, just return (and don't do anything else)
                        // otherwise the content processing will be going on.
                        switch (this.ValidationSetting)
                        {
                        case ValidationOption.ShowAllValid:
                            if (!_validitySetting.ShowAllValidContent)
                            {
                                return;
                            }
                            break;

                        case ValidationOption.ShowValidButArchived:
                            if (!_validitySetting.ShowValidAndArchived)
                            {
                                return;
                            }
                            break;

                        case ValidationOption.ShowValidButNotArchived:
                            if (!_validitySetting.ShowValidAndNotArchived)
                            {
                                return;
                            }
                            break;

                        case ValidationOption.DontCheckValidity:        // not used
                        default:
                            break;
                        }
                    }
                }
            }
            #endregion


            viewPath = GetViewPath();


            // try to create ContentView which contains all webcontrols of the content
            try
            {
                if (this.UseUrlPath)
                {
                    _contentView = ContentView.Create(_content, this.Page, viewMode, String.IsNullOrEmpty(this.ContentViewPath) ? viewPath : this.ContentViewPath);
                }
                else
                {
                    _contentView = ContentView.Create(_content, this.Page, viewMode, viewPath);
                }

                _container.Controls.Remove(_contentView);
            }
            catch (Exception e) //logged
            {
                Logger.WriteException(e);
                this._errorMessage = String.Format("Message: {0} {1} Source: {2} {3} StackTrace: {4} {5}", e.Message, Environment.NewLine, e.Source, Environment.NewLine, e.StackTrace, Environment.NewLine);
                return;
            }

            _contentView.UserAction += new EventHandler <UserActionEventArgs>(_contentView_UserAction);
            _container.Controls.Add(_contentView);
        }