ContentView is a class responsible for enabling various visualizations of the Content class that it owns.
The two most important properties of ContentView is the collection of FieldControls and the Content it references. These two parts are closely related as every FieldControl wraps a #Field# defined within its Content. Basically the ContentView is a visualizer of the Content assigned to it when created. The FieldControls of this ContentView each visualize a #Field# defined within this Content (but not necessary all of them). Another important role of the ContentView is automatically utilizing the pre-defined ViewModes It renders itself and all of its FieldControls according to the ViewMode assigned to it when created.
상속: System.Web.UI.UserControl, INamingContainer
예제 #1
0
 private void HandleTagReplacement(ContentView contentView)
 {
     var content = contentView.Content;
     var oldTag = content["DisplayName"].ToString();
     this.OnSave(contentView, content);
     var node = GetContextNodeForControl(this);
     if (oldTag != node.DisplayName)
     {
         TagManager.ReplaceTag(oldTag, node.DisplayName, Page.Request.Params["Paths"].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList());
     }
 }
예제 #2
0
 private void OnSave(ContentView contentView, Content content)
 {
     contentView.UpdateContent();
     if (contentView.IsUserInputValid && content.IsValid)
     {
         try
         {
             content.Save();
         }
         catch (Exception ex) //logged
         {
             Logger.WriteException(ex);
             contentView.ContentException = ex;
         }
     }
 }
예제 #3
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();
                //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);

        }
예제 #4
0
		//-- Methods -----------------------------------------------------

		private void CreateNewFormItem()
		{
			if (CurrentForm == null)
				return;

		    var act = CurrentForm.GetAllowedChildTypes();
            var allowedType = act.FirstOrDefault(ct => ct.IsInstaceOfOrDerivedFrom("FormItem"));
		    var typeName = allowedType == null ? "FormItem" : allowedType.Name;

            _cFormItem = SNC.Content.CreateNew(typeName, CurrentForm, null);

		    try
		    {
                if (string.IsNullOrEmpty(ContentViewPath))
                    _cvFormItem = ContentView.Create(_cFormItem, this.Page, ViewMode.New);
                else
                    _cvFormItem = ContentView.Create(_cFormItem, this.Page, ViewMode.New, ContentViewPath);

                _cvFormItem.ID = "cvNewFormItem";
                _cvFormItem.Init += new EventHandler(_cvFormItem_Init);
                _cvFormItem.UserAction += new EventHandler<UserActionEventArgs>(_cvFormItem_UserAction);

                this.Controls.Add(_cvFormItem);
		    }
		    catch (Exception ex) //logged
		    {
                Logger.WriteException(ex);
		        this.Controls.Clear();
                this.Controls.Add(new LiteralControl("ContentView error: " + ex.Message));
		    }
			
		}
예제 #5
0
        private void BuildAfterSubmitForm_ContentView(SNC.Content formitem)
	    {
            if (CurrentForm == null)
                return;

            //FormItem fi = new FormItem(CurrentForm);
            //_cFormItem = SNC.Content.Create(fi);
            if (formitem == null && _formItemID != 0)
            {
                formitem = Content.Load(_formItemID);
            }

            if (formitem != null)
            {
                _cFormItem = formitem;

                _cvFormItem = ContentView.Create(_cFormItem, this.Page, ViewMode.New, AfterSubmitViewPath);

                _cvFormItem.ID = "cvAfterSubmitFormItem";
                //_cvFormItem.Init += new EventHandler(_cvFormItem_Init);
                _cvFormItem.UserAction += new EventHandler<UserActionEventArgs>(_cvAfterSubmitFormItem_UserAction);

                this.Controls.Add(_cvFormItem);
            }
            else if (!string.IsNullOrEmpty(AfterSubmitViewPath))
            {
                this.Controls.Add(Page.LoadControl(AfterSubmitViewPath));
            }
	    }
예제 #6
0
        public CommandButtonsEventArgs(CommandButtonType buttonType, ContentView view, string customCommand)
		{
            ButtonType = buttonType;
            ContentView = view;
            CustomCommand = customCommand;
		}
예제 #7
0
		private void CreateControls()
		{
            if (CurrentForm != null)
            {


                if (!CurrentForm.Security.HasPermission(PermissionType.AddNew))
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(PermissionErrorViewPath))
                        {
                            _cvFormItem = ContentView.Create(SNC.Content.Create(CurrentForm), this.Page, ViewMode.Browse, PermissionErrorViewPath);
                            this.Controls.Add(_cvFormItem);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteException(ex);
                        this.Controls.Clear();
                        this.Controls.Add(new LiteralControl("ContentView error: " + ex.Message));
                    }
                }
                else
                {
                    CreateNewFormItem();
                }
            }
		}
예제 #8
0
        protected virtual void BuildSearchForm()
        {
            if (string.IsNullOrEmpty(SearchFormCtd))
                return;
            var nt = (from t in ActiveSchema.NodeTypes
                      where t.NodeTypePath.Equals(SearchFormCtd.Remove(0, 33))
                      select t).FirstOrDefault();
            if (nt == null) return;
            
            var c = Content.CreateNew(nt.Name, Repository.Root, null);
                
            var s = State;

            if (_state != null && !string.IsNullOrWhiteSpace(_state.ExportQueryFields))
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(_state.ExportQueryFields);
                XmlNodeList allFields = xmlDoc.SelectNodes("/ContentMetaData/Fields/*");
                var transferringContext = new ImportContext(allFields, "", c.Id == 0, true, false);
                //import flat properties
                c.ImportFieldData(transferringContext, false);
                //update references
                transferringContext.UpdateReferences = true;
                c.ImportFieldData(transferringContext, false);
            }

            //override content filed from url parameters
            foreach (KeyValuePair<string, Field> keyValuePair in c.Fields)
            {
                var portletSpecKey = GetPortletSpecificParamName(keyValuePair.Key);
                var requestValue = GetValueFromRequest(portletSpecKey);
                
                if (!string.IsNullOrEmpty(requestValue) && c.Fields.ContainsKey(keyValuePair.Key))
                        c.Fields[keyValuePair.Key].Parse(requestValue);
            }

            var cv = string.IsNullOrEmpty(SearchFormRenderer)
                         ? ContentView.Create(c, this.Page, ViewMode.InlineNew)
                         : ContentView.Create(c, this.Page, ViewMode.InlineNew, SearchFormRenderer);

            //Attach search event
            var iCsView = cv as IContentSearchView;
            if (iCsView != null)
            {
                iCsView.Search += new EventHandler(ContentSearchView_Search_OnClick);
            }
            else
            {
                var btn = cv.FindControl(SearchBtnId) as Button;
                if (btn == null)
                {
                    btn = new Button {ID = SearchBtnId, Text = SenseNetResourceManager.Current.GetString(ResourceCalssName, "SearchBtnText"), CssClass = "sn-submit"};
                    cv.Controls.Add(btn);
                }
                btn.Click += new EventHandler(ContentSearchView_Search_OnClick);
            }
            SearchForm = cv;
        }
예제 #9
0
        private void AddSelectedNewContentView(string selectedContentTypeName)
        {
            var placeHolder = _currentUserControl.FindControl("ContentViewPlaceHolder") as PlaceHolder;
            if (placeHolder == null)
                return;

            var currentContextNode = GetContextNode();

            if (_currentContent != null)
            {
                _contentView = GetContentView(_currentContent);

                // backward compatibility: use eventhandler for contentviews using defaultbuttons and not commandbuttons
                _contentView.UserAction += NewContentViewUserAction;

                placeHolder.Visible = true;
                placeHolder.Controls.Clear();
                placeHolder.Controls.Add(_contentView);
                return;
            }

            if (String.IsNullOrEmpty(selectedContentTypeName))
                selectedContentTypeName = SelectedContentType;

            Content newContent = null;
            var ctd = ContentType.GetByName(selectedContentTypeName);
            if (ctd == null) {
                //
                // In this case, the selectedContentTypeName contains only the templatePath. It is maybe a security issue because path is rendered into value attribute of html option tag.
                //
                string parentPath = currentContextNode.Path;
                string templatePath = selectedContentTypeName;
                newContent = ContentTemplate.CreateTemplated(parentPath, templatePath);
                _contentView = GetContentView(newContent);
            } else {
                //
                //  Yes it is a valid contentTypeName
                //  
                newContent = ContentManager.CreateContentFromRequest(selectedContentTypeName, null, currentContextNode.Path, true);
                _contentView = GetContentView(newContent);
            }

            // backward compatibility: use eventhandler for contentviews using defaultbuttons and not commandbuttons
            _contentView.UserAction += NewContentViewUserAction;

            placeHolder.Visible = true;
            placeHolder.Controls.Clear();
            placeHolder.Controls.Add(_contentView);
        }
예제 #10
0
        private static ContentView CreateFromActualPath(SNC.Content content, System.Web.UI.Page aspNetPage, ViewMode viewMode, string viewPath)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            if (aspNetPage == null)
            {
                throw new ArgumentNullException("aspNetPage");
            }
            if (viewPath == null)
            {
                throw new ArgumentNullException("viewPath");
            }
            if (viewPath.Length == 0)
            {
                throw new ArgumentOutOfRangeException("viewPath", "Parameter 'viewPath' cannot be empty");
            }
            if (viewMode == ViewMode.None)
            {
                throw new ArgumentOutOfRangeException("viewMode", "Parameter 'viewMode' cannot be ViewMode.None");
            }

            string path = String.Concat("~", viewPath);

            if (!SecurityHandler.HasPermission(User.Current, viewPath, 0, 0, PermissionType.RunApplication))
            {
                throw new SenseNetSecurityException(path, PermissionType.RunApplication);
            }

            ContentView view = GetContentViewFromCache(path);

            // if not in request cache
            if (view == null)
            {
                var addToCache = false;
                try
                {
                    view       = aspNetPage.LoadControl(path) as ContentView;
                    addToCache = true;
                }
                catch (Exception e) //logged
                {
                    Logger.WriteException(e);
                    var errorContentViewPath         = RepositoryPath.Combine(Repository.ContentViewFolderName, "Error.ascx");
                    var resolvedErrorContentViewPath = SkinManager.Resolve(errorContentViewPath);
                    path = String.Concat("~", resolvedErrorContentViewPath);
                    view = aspNetPage.LoadControl(path) as ContentView;
                    view.ContentException = e;
                }
                if (view == null)
                {
                    throw new ApplicationException(string.Format("ContentView instantiation via LoadControl for path '{0}' failed.", path));
                }
                if (addToCache)
                {
                    AddContentViewToCache(path, view);
                }
            }

            view.Initialize(content, viewMode);
            return(view);
        }
예제 #11
0
 public CommandButtonsEventArgs(CommandButtonType buttonType, ContentView view, string customCommand)
 {
     ButtonType    = buttonType;
     ContentView   = view;
     CustomCommand = customCommand;
 }
예제 #12
0
		public UserActionEventArgs(string actionName, string eventName, ContentView view)
		{
			ActionName = actionName;
			ContentView = view;
			EventName = eventName;
		}
예제 #13
0
        private static void AddContentViewToCache(string path, ContentView contentView)
        {
            System.Web.HttpContext currentContext = System.Web.HttpContext.Current;

            if (currentContext == null)
                return;

            Dictionary<string, ConstructorInfo> constructorCache;

            constructorCache = currentContext.Items["ContextBasedContentViewCache"] as Dictionary<string, ConstructorInfo>;

            if (constructorCache == null)
            {
                constructorCache = new Dictionary<string, ConstructorInfo>();
                currentContext.Items.Add("ContextBasedContentViewCache", constructorCache);
            }

            constructorCache[path] = contentView.GetType().GetConstructor(Type.EmptyTypes);
        }
        protected virtual void ProcessRegistration()
        {
            if (User.Current.Id != User.Visitor.Id)
            {
                WriteErrorMessageOnly(Configuration.AlreadyRegisteredUserMessage);
                return;
            }

            // creates an empty user
            _content = CreateNewUserContent(Configuration.DefaultDomainPath);
            if (_content == null)
                return;
            _content.ContentHandler.Created += ContentHandler_Created;
            // loads the publicregistration contentviews 
            // and exception raises when registration contentview has not been found.)
            ChangeToAdminAccount();
            try
            {
                _contentView = String.IsNullOrEmpty(Configuration.NewRegistrationContentView)
                    ? ContentView.Create(_content, Page, ViewMode.InlineNew)
                    : ContentView.Create(_content, Page, ViewMode.New, Configuration.NewRegistrationContentView);
            }
            catch (Exception exc) //logged
            {
                Logger.WriteException(exc);
                WriteErrorMessageOnly(String.Format(HttpContext.GetGlobalResourceObject("PublicRegistrationPortlet", "ErrorCreatingContentView") as string, Configuration.NewRegistrationContentView));
                RestoreOriginalUser();
                return;
            }
            _contentView.UserAction += ContentView_UserAction_New;
            Controls.Add(_contentView);
            RestoreOriginalUser();
        }
        private void ProcessUpdateProfile()
        {
            _content = SNC.Content.Load(User.Current.Id);
            if (_content == null)
                return; // todo: could not load current user content.
            var currentUserNodeTypeName = ((Node)User.Current).NodeType.Name;
            if (currentUserNodeTypeName != Configuration.UserTypeName)
            {
                this.Controls.Clear();
                this.Controls.Add(new LiteralControl(HttpContext.GetGlobalResourceObject("PublicRegistrationPortlet", "UserTypeDoesNotMatch") as string));
                return; // todo: update only the correct UserType. It prevents that user updates his/her profile with another user type inlinenew contentview.
            }
            this.ChangeToAdminAccount();
            try
            {
                _contentView = String.IsNullOrEmpty(Configuration.EditProfileContentView)
                    ? ContentView.Create(this._content, this.Page, ViewMode.InlineEdit)
                    : ContentView.Create(this._content, this.Page, ViewMode.InlineEdit, Configuration.EditProfileContentView);
            }
            catch (Exception exc) //logged
            {
                Logger.WriteException(exc);
                WriteErrorMessageOnly(String.Format(HttpContext.GetGlobalResourceObject("PublicRegistrationPortlet", "ErrorCreatingContentView") as string, Configuration.EditProfileContentView));
                this.RestoreOriginalUser();
                return;
            }
            this._contentView.UserAction += new EventHandler<UserActionEventArgs>(ContentView_UserAction_Update);
            this.Controls.Add(this._contentView);
            this.RestoreOriginalUser();

        }
예제 #16
0
        protected override void CreateChildControls()
        {
            try
            {
                var modelData = GetModel() as SN.Content;
                if (modelData == null)
                    return;

                if (!this.HasPermission)
                {
                    Controls.Add(new LiteralControl(HttpContext.GetGlobalResourceObject("Notification", "NotEnoughPermissions") as string));
                    return;
                }

                _contentView = ContentView.Create(modelData, Page, ViewMode.Edit, ContentViewPath);
                this.Controls.Add(_contentView);

                //add event handler
                if (this.SaveButton != null)
                {
                    this.SaveButton.Click += BtnSave_Click;
                }
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex);
                Controls.Clear();
                Controls.Add(new LiteralControl("ContentView error: " + ex.Message));
            }
        }