コード例 #1
0
        private View GetOrCreateConent(ITabItem tab)
        {
            if (!(Tabs?.Any() == true && ContentTemplate != null))
            {
                return(null);
            }
            View element = null;

            if (!(_tabViews.TryGetValue(tab, out element)))
            {
                var selector = ContentTemplate as DataTemplateSelector;
                if (selector != null)
                {
                    var template = selector.SelectTemplate(tab, this);
                    element = template?.CreateContent() as View;
                }
                else
                {
                    element = (View)ContentTemplate.CreateContent();
                }
                if (element == null)
                {
                    throw new InvalidOperationException(
                              "Could not instantiate content. Please make sure that your ContentTemplate is configured correctly.");
                }
                _tabViews[tab]         = element;
                element.BindingContext = tab;
            }
            return(element);
        }
コード例 #2
0
ファイル: ContentEditorField.cs プロジェクト: howej/dotnetage
        /// <summary>
        /// Initializes a new instance of ContentEditorField class.
        /// </summary>
        /// <param name="form">The form object.</param>
        /// <param name="field">The content field.</param>
        public ContentEditorField(ContentFormDecorator form, ContentField field)
        {
            this.ParentForm = form;
            this.Parent = form.Parent;
            field.CopyTo(this, "Parent");
            Template = new ContentTemplate();

            switch ((ContentFormTypes)form.FormType)
            {
                case ContentFormTypes.Display:
                    if (field.HasDisplayTemlpate)
                        Template.Source = field.DisplayTemplate;
                    break;
                case ContentFormTypes.Activity:
                    if (field.HasActivityTemplate)
                        Template.Source = field.ActivityTemplate;
                    break;
                case ContentFormTypes.Edit:
                    if (field.HasEditTemlpate)
                        Template.Source = field.EditTemplate;
                    break;
                case ContentFormTypes.New:
                    if (field.HasNewTemlpate)
                        Template.Source = field.NewTemplate;
                    break;
            }
        }
コード例 #3
0
ファイル: CreateContent.cs プロジェクト: vyctorbh/sn-workflow
        protected static Content CreateContentInternal(string contentTypeName, string contentName, string parentPath)
        {
            if (string.IsNullOrEmpty(contentTypeName))
            {
                throw new ArgumentNullException(nameof(contentTypeName));
            }
            if (string.IsNullOrEmpty(parentPath))
            {
                throw new ArgumentNullException(nameof(parentPath));
            }

            var parentNode = Node.LoadNode(parentPath);

            if (parentNode == null)
            {
                throw new ApplicationException($"Cannot create new content: invalid parent ({parentPath})");
            }

            if (string.IsNullOrEmpty(contentName))
            {
                contentName = contentTypeName;
            }

            var contentType = ContentType.GetByName(contentTypeName);

            if (contentType == null)
            {
                // full template path is given as content type name
                return(ContentTemplate.CreateTemplated(parentNode.Path, contentTypeName));
            }

            return(Content.CreateNew(contentTypeName, parentNode, contentName));
        }
コード例 #4
0
 private void OnWhenChanged(bool value)
 {
     if (value)
     {
         if (ContentTemplate != null)
         {
             _element = ContentTemplate.GetElement(new ElementFactoryGetArgs
             {
                 Data   = Content,
                 Parent = this
             });
             if (_element is FrameworkElement element && element.DataContext != Content)
             {
                 element.DataContext = Content;
             }
             Children.Add(_element);
         }
     }
     else
     {
         if (ContentTemplate != null && _element != null)
         {
             ContentTemplate.RecycleElement(new ElementFactoryRecycleArgs
             {
                 Element = _element,
                 Parent  = this
             });
             _element = null;
         }
         Children.Clear();
     }
 }
コード例 #5
0
        /// <summary>
        /// Page is appeared to screen and animation is finished
        /// </summary>
        public virtual void OnAppeared(AppearEventArgs args)
        {
            if (IsDebugEnabled)
            {
                Debug.WriteLine(NavigationBar.GetTitle(this) + ": OnAppeared");
            }

            LifecycleState = LifecycleStates.Appeared;

            if (ContentCreateEvent == ContentCreateEvents.Appeared && ContentTemplate != null && Content is View == false && _contentElement == null)
            {
                if (_contentElement != null && Children.Contains(_contentElement))
                {
                    Children.Remove(_contentElement);
                }

                _contentElement = ContentTemplate.CreateContent() as View;
                Children.Insert(0, _contentElement);

                if (Content != null)
                {
                    _contentElement.BindingContext = Content;
                }
            }
        }
コード例 #6
0
        private void RenderJsonList(HttpContext context)
        {
            context.Response.ContentType = "text/javascript";
            Encoding encoding = new UTF8Encoding();

            context.Response.ContentEncoding = encoding;

            siteRoot = SiteUtils.GetNavigationSiteRoot();

            context.Response.Write("var tinyMCETemplateList = [");

            if (WebConfigSettings.AddSystemContentTemplatesAboveSiteTemplates) //true by default
            {
                RenderSystemTemplateItems(context);
            }

            List <ContentTemplate> templates = ContentTemplate.GetAll(siteSettings.SiteGuid);

            foreach (ContentTemplate t in templates)
            {
                context.Response.Write(comma);
                context.Response.Write("['" + t.Title + "','" + siteRoot + "/Services/TinyMceTemplates.ashx?g=" + t.Guid.ToString() + "','']");
                comma = ",";
            }

            if (WebConfigSettings.AddSystemContentTemplatesBelowSiteTemplates) //false by default
            {
                RenderSystemTemplateItems(context);
            }

            context.Response.Write("];");
        }
コード例 #7
0
        private void BindGrid()
        {
            List <ContentTemplate> ContentTemplateList
                = ContentTemplate.GetPage(
                      siteSettings.SiteGuid,
                      pageNumber,
                      pageSize,
                      out totalPages);

            string pageUrl = SiteRoot + "/Admin/ContentTemplates.aspx?pagenumber={0}";

            pgrTop.PageURLFormat = pageUrl;
            pgrTop.ShowFirstLast = true;
            pgrTop.CurrentIndex  = pageNumber;
            pgrTop.PageSize      = pageSize;
            pgrTop.PageCount     = totalPages;
            pgrTop.Visible       = (totalPages > 1);

            pgrBottom.PageURLFormat = pageUrl;
            pgrBottom.ShowFirstLast = true;
            pgrBottom.CurrentIndex  = pageNumber;
            pgrBottom.PageSize      = pageSize;
            pgrBottom.PageCount     = totalPages;
            pgrBottom.Visible       = (totalPages > 1);

            rptTemplates.DataSource = ContentTemplateList;
            rptTemplates.DataBind();
        }
コード例 #8
0
ファイル: BoxSet.ascx.cs プロジェクト: holmes2136/ShopCart
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        uxTitlePlaceHolder.Controls.Clear();
        uxContentPlaceHolder.Controls.Clear();

        ContentContainer container = new ContentContainer();

        if (TitleTemplate != null)
        {
            TitleTemplate.InstantiateIn(container);
            uxTitlePlaceHolder.Controls.Add(container);
        }
        else
        {
            uxTitlePlaceHolder.Visible = false;
        }

        container = new ContentContainer();
        if (ContentTemplate != null)
        {
            ContentTemplate.InstantiateIn(container);
            uxContentPlaceHolder.Controls.Add(container);
        }
        else
        {
            uxContentPanel.CssClass = "Clear";
        }
    }
コード例 #9
0
        public object DesrializeTemplateModel(IPost post, ContentTemplate template)
        {
            string modelString;

            if (!string.IsNullOrWhiteSpace(post.DraftSerializedModel))
            {
                modelString = post.DraftSerializedModel;
            }
            else
            {
                modelString = post.SerializedModel;
            }
            if (string.IsNullOrWhiteSpace(modelString))
            {
                _log.LogError($"could not deserialize model from empty string on page {post.Title}");
                return(null);
            }
            var serializer = GetSerializer(template.SerializerName);

            try
            {
                var result = serializer.Deserialize(template.ModelType, modelString);
                return(result);
            }
            catch (Exception ex)
            {
                _log.LogError($"Failed to deserialize model for page {post.Title} returning null. Exception was {ex.Message}:{ex.StackTrace}");
                return(null);
            }
        }
コード例 #10
0
        /// <summary>
        /// Adds a new content template.
        /// </summary>
        /// <param name="wiki">The wiki.</param>
        /// <param name="name">The name of the template.</param>
        /// <param name="content">The content of the template.</param>
        /// <param name="provider">The target provider (<c>null</c> for the default provider).</param>
        /// <returns><c>true</c> if the template is added, <c>false</c> otherwise.</returns>
        public static bool AddTemplate(string wiki, string name, string content, IPagesStorageProviderV40 provider)
        {
            if (Find(wiki, name) != null)
            {
                return(false);
            }

            if (provider == null)
            {
                provider = Collectors.CollectorsBox.PagesProviderCollector.GetProvider(GlobalSettings.DefaultPagesProvider, wiki);
            }

            ContentTemplate result = provider.AddContentTemplate(name, content);

            if (result != null)
            {
                Log.LogEntry("Content Template " + name + " created", EntryType.General, Log.SystemUsername, wiki);
            }
            else
            {
                Log.LogEntry("Creation failed for Content Template " + name, EntryType.Error, Log.SystemUsername, wiki);
            }

            return(result != null);
        }
コード例 #11
0
        internal void CreateNewWorkspace()
        {
            try
            {
                var state          = WizardState;
                var newName        = state.WorkspaceNewName;
                var sourceNodePath = state.SelectedWorkspacePath;
                var targetNode     = PortalContext.Current.ContextNodeHead ?? NodeHead.Get(TargetPath);

                var sourceNode      = Node.LoadNode(sourceNodePath);
                var contentTypeName = sourceNode.Name;


                Content workspace = null;

                workspace = ContentTemplate.HasTemplate(contentTypeName)
                    ? ContentTemplate.CreateTemplated(Node.LoadNode(targetNode.Id), ContentTemplate.GetTemplate(contentTypeName), newName)
                    : Content.CreateNew(contentTypeName, Node.LoadNode(targetNode.Id), newName);

                workspace.Fields["Description"].SetData(state.WorkspaceNewDescription);
                workspace.Save();

                var newPath = new StringBuilder(PortalContext.Current.OriginalUri.GetLeftPart(UriPartial.Authority)).Append(targetNode.Path).Append("/").Append(newName);
                NewWorkspaceLink.HRef = newPath.ToString();
            }
            catch (Exception exc) //logged
            {
                Logger.WriteException(exc);
                HasError = true;
                ErrorMessageControl.Visible = true;
                ErrorMessageControl.Text    = exc.Message;
                // log exception
            }
        }
コード例 #12
0
 public SimpleContent()
 {
     Template = new ContentTemplate()
     {
         DisplayView = "SimpleContentView",
         EditView    = "SimpleContentEditView"
     };
 }
コード例 #13
0
        protected override void OnLoad(IDotvvmRequestContext context)
        {
            var container = FindControlByClientId("TemplateHost", true);

            ContentTemplate.BuildContent(context, container);

            base.OnLoad(context);
        }
コード例 #14
0
        /// <summary>
        /// Selects a template for editing.
        /// </summary>
        /// <param name="name">The name of the template.</param>
        private void SelectTemplate(string name)
        {
            ContentTemplate template = Templates.Find(name);

            providerSelector.SelectedProvider = template.Provider.GetType().FullName;
            editor.SetContent(template.Content, Settings.UseVisualEditorAsDefault);
            SetTitleForTemplate();
        }
コード例 #15
0
 public SimpleContentWithImageListView()
 {
     Template = new ContentTemplate()
     {
         DisplayView = "SimpleContentWithImageListView",
         EditView    = "SimpleContentWithImageListEditView"
     };
 }
コード例 #16
0
 protected override void RenderContent(string innerText, string rawInnerText)
 {
     base.RenderContent(innerText, rawInnerText);
     if (ContentTemplate != null)
     {
         ContentTemplate.Render(CurrentContext);
     }
 }
コード例 #17
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);
        }
コード例 #18
0
        public override void DrawItem(Graphics g, Rectangle bounds, object item)
        {
            ContentTemplate template = (ContentTemplate)item;

            g.DrawString(template.Name, normalTextFont, Brushes.Black, new PointF(bounds.Left + 3, bounds.Top + 2));
            g.DrawString(template.Shortcut, subTextFont, Brushes.LightGray, new PointF(bounds.Left + 5, bounds.Top + 15));

            base.DrawItem(g, bounds, item);
        }
コード例 #19
0
 protected override void OnInit(EventArgs e)
 {
     this.ContentTemplateContainer = new HtmlGenericControl("div");
     if (ContentTemplate != null)
     {
         ContentTemplate.InstantiateIn(container);
     }
     plcContent.Controls.Add(container);
 }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SnippetTemplateRow" /> class.
 /// </summary>
 /// <param name="template">The original template.</param>
 /// <param name="selected">A value indicating whether the template is selected.</param>
 public SnippetTemplateRow(ContentTemplate template, bool selected)
 {
     type = Properties.Messages.Template;
     name = template.Name;
     distinguishedName = "T." + template.Name;
     parameterCount    = "";
     provider          = template.Provider.Information.Name;
     additionalClass   = selected ? " selected" : "";
 }
コード例 #21
0
ファイル: RouteLink.cs プロジェクト: MBeleuca/dotvvm-webforms
        protected override void OnInit(EventArgs e)
        {
            if (ContentTemplate != null)
            {
                ContentTemplate.InstantiateIn(this);
            }

            base.OnInit(e);
        }
コード例 #22
0
ファイル: Templates.cs プロジェクト: mono/ScrewTurnWiki
        /// <summary>
        /// Modifies a content template.
        /// </summary>
        /// <param name="template">The template to modify.</param>
        /// <param name="content">The new content of the template.</param>
        /// <returns><c>true</c> if the template is modified, <c>false</c> otherwise.</returns>
        public static bool ModifyTemplate(ContentTemplate template, string content)
        {
            ContentTemplate result = template.Provider.ModifyContentTemplate(template.Name, content);

            if(result != null) Log.LogEntry("Content Template " + template.Name + " updated", EntryType.General, Log.SystemUsername);
            else Log.LogEntry("Update failed for Content Template " + template.Name, EntryType.Error, Log.SystemUsername);

            return result != null;
        }
コード例 #23
0
 void OnContentTemplateChanged(AbstractProperty property, object oldValue)
 {
     if (ContentTemplate == null)
     {
         InstallAutomaticContentDataTemplate();
         return;
     }
     SetTemplateControl(ContentTemplate.LoadContent(this) as FrameworkElement);
 }
コード例 #24
0
        private void RenderJsonList(HttpContext context)
        {
            context.Response.ContentType = "text/javascript";
            Encoding encoding = new UTF8Encoding();

            context.Response.ContentEncoding = encoding;

            siteRoot = SiteUtils.GetNavigationSiteRoot();

            // Register a templates definition set named "mojo".
            context.Response.Write("CKEDITOR.addTemplates( 'mojo',{");

            context.Response.Write("\"imagesPath\":\"" + siteRoot + "/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/htmltemplateimages/" + "\"");
            context.Response.Write(",\"templates\":");
            context.Response.Write("[");

            //2018/10/31 -- we don't really want to use these anymore. we're adding the ability to have templates in the skin but not system wide templates
            if (WebConfigSettings.AddSystemContentTemplatesAboveSiteTemplates) //false by default
            {
                RenderSystemTemplateItems(context);
            }


            List <ContentTemplate> templates = ContentTemplate.GetAll(siteSettings.SiteGuid);

            foreach (ContentTemplate t in templates)
            {
                if (!WebUser.IsInRoles(t.AllowedRoles))
                {
                    continue;
                }

                context.Response.Write(comma);
                context.Response.Write("{");

                context.Response.Write("\"title\":\"" + t.Title.JsonEscape() + "\"");
                context.Response.Write(",\"image\":\"" + t.ImageFileName.JsonEscape() + "\"");
                context.Response.Write(",\"description\":\"" + t.Description.RemoveLineBreaks().JsonEscape() + "\"");
                // is this going to work?
                context.Response.Write(",\"html\":\"" + t.Body.RemoveLineBreaks().JsonEscape() + "\"");

                context.Response.Write("}");

                comma = ",";
            }

            //2018/10/31 -- we don't really want to use these anymore. we're adding the ability to have templates in the skin but not system wide templates
            if (WebConfigSettings.AddSystemContentTemplatesBelowSiteTemplates)             //false by default
            {
                RenderSystemTemplateItems(context);
            }

            context.Response.Write("]");

            context.Response.Write("});");
        }
コード例 #25
0
        public async Task <IHttpActionResult> Update(ContentTemplate template)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _templateRepo.AddOrUpdateContentTemplate(template);

            return(Ok());
        }
コード例 #26
0
        public async Task <int> AddOrUpdateContentTemplate(ContentTemplate contentTemplate)
        {
            _dataContext.Entry(contentTemplate).State = contentTemplate.Id == 0 ?
                                                        EntityState.Added :
                                                        EntityState.Modified;

            await _dataContext.SaveChangesAsync();

            return(contentTemplate.Id);
        }
コード例 #27
0
        public ContentTemplate Create(ContentTemplate template)
        {
            if (template.ContentId == 0)
            {
                throw new ArgumentException("Content ID is missing.");
            }

            int accountId = template.AccountId > 0 ? template.AccountId : CurrentAccount;

            return(Create(accountId, template.ContentId, template));
        }
コード例 #28
0
        public AppsResult GetTemplateModel()
        {
            var result      = new AppsResult();
            var newTemplate = new ContentTemplate();
            var newprop     = new ContentTemplateProperty();

            newTemplate.TemplateProperties.Add(newprop);
            result.Data    = newTemplate;
            result.Success = true;
            return(result);
        }
コード例 #29
0
        ///<summary>
        ///Set campaign content
        ///</summary>
        internal async Task <dynamic> SetCampaignContentAsync(string campaign_id, ContentTemplate contentTemplate)
        {
            string endpoint = Authenticate.EndPoint(TargetTypes.campaigns, SubTargetType.content, SubTargetType.not_applicable, campaign_id);

            RootContent content = new RootContent()
            {
                template = contentTemplate,
            };

            return(await BaseOperation.PutAsync <RootContent>(endpoint, content));
        }
コード例 #30
0
ファイル: UpdatePanel.cs プロジェクト: raj581/Marvin
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            ScriptManager.RegisterUpdatePanel(this);

            if (ContentTemplate != null)
            {
                ContentTemplate.InstantiateIn(ContentTemplateContainer);
            }
        }
コード例 #31
0
        void btnDelete_Click(object sender, EventArgs e)
        {
            if (templateGuid == Guid.Empty)
            {
                WebUtils.SetupRedirect(this, SiteRoot + "/Admin/ContentTemplates.aspx");
                return;
            }

            ContentTemplate.Delete(templateGuid);
            WebUtils.SetupRedirect(this, SiteRoot + "/Admin/ContentTemplates.aspx");
        }
コード例 #32
0
        private void OnGotTextBlockFocus(object sender, RoutedEventArgs e)
        {
            if (Context == null)
            {
                return;
            }

            DesignerView designerView = Context.Services.GetService <DesignerView>();

            if (!designerView.IsMultipleSelectionMode)
            {
                TextBlock textBlock        = sender as TextBlock;
                bool      isInReadOnlyMode = IsReadOnly;
                if (Context != null)
                {
                    ReadOnlyState readOnlyState = Context.Items.GetValue <ReadOnlyState>();
                    isInReadOnlyMode |= readOnlyState.IsReadOnly;
                }
                if (null != textBlock)
                {
                    BlockHeight = textBlock.ActualHeight;
                    BlockHeight = Math.Max(BlockHeight, textBlock.MinHeight);
                    BlockHeight = Math.Min(BlockHeight, textBlock.MaxHeight);
                    BlockWidth  = textBlock.ActualWidth;
                    BlockWidth  = Math.Max(BlockWidth, textBlock.MinWidth);
                    BlockWidth  = Math.Min(BlockWidth, textBlock.MaxWidth);

                    // If it's already an editor, don't need to switch it/reload it (don't create another editor/grid if we don't need to)
                    // Also don't create editor when we are in read only mode
                    if (ContentTemplate.Equals((DataTemplate)FindResource("textblock")) && !isInReadOnlyMode)
                    {
                        if (Context != null)
                        {
                            // Get the ExpressionEditorService
                            ExpressionEditorService1 = Context.Services.GetService <IExpressionEditorService>();
                        }

                        // If the service exists, use the editor template - else switch to the textbox template
                        if (ExpressionEditorService1 != null)
                        {
                            ContentTemplate = (DataTemplate)FindResource("expressioneditor");
                        }
                    }
                }

                if (!isInReadOnlyMode)
                {
                    //disable the error icon
                    StartValidator();
                    EditingState = EditingState.Editing;
                    e.Handled    = true;
                }
            }
        }
コード例 #33
0
ファイル: ContentFieldRef.cs プロジェクト: howej/dotnetage
 /// <summary>
 /// Initializes a new instance of the ContentFieldRef class.
 /// </summary>
 /// <param name="parent">The parent view object.</param>
 /// <param name="field">The content field.</param>
 public ContentFieldRef(ContentViewDecorator parent, ContentField field)
 {
     this.ParentView = parent;
     this.Parent = parent.Parent;
     field.CopyTo(this, "Parent");
     isFilterable = field.IsFilterable;
     this.Field = field;
     Template = new ContentTemplate();
     if (field.HasViewTemplate)
         Template.Source = field.ViewTemplate;
 }
コード例 #34
0
ファイル: FormController.cs プロジェクト: howej/dotnetage
 public ActionResult Code(string name, string type, string code, string locale)
 {
     var form = _GetForm(name, type);
     var bodyTmpl = new ContentTemplate()
     {
         ContentType = TemplateContentTypes.Razor,
         Text = code
     };
     form.BodyTemplateXml = bodyTmpl.Element().OuterXml();
     form.Save();
     TemplateHelper.SaveAsView(form.Parent, code, string.Format("_form_{0}_tmpl.cshtml", form.FormTypeString.ToLower()), true);
     return new HttpStatusCodeResult(200);
 }
コード例 #35
0
        /// <summary>
        /// Returns a template instance for the given TemplateId. If an instance for the given id
        /// already exists, then it is returned. Otherwise, either a RuntimeTemplate or
        /// ContentTemplate is created with an associated id based on the GameEngineContext.
        /// </summary>
        /// <param name="templateId">The id of the template to get an instance for.</param>
        /// <param name="context">The GameEngineContext, used to determine if we should create a
        /// ContentTemplate or RuntimeTemplate instance.</param>
        public ITemplate GetTemplateInstance(int templateId, GameEngineContext context) {
            if (CreatedTemplates.ContainsKey(templateId)) {
                return CreatedTemplates[templateId];
            }

            ITemplate template;
            if (context.GameEngine.IsEmpty) {
                template = new ContentTemplate(templateId);
            }
            else {
                template = new RuntimeTemplate(templateId, context.GameEngine.Value);
            }

            CreatedTemplates[templateId] = template;
            return template;
        }
コード例 #36
0
        public void MigratePagesStorageProviderData()
        {
            MockRepository mocks = new MockRepository();

            IPagesStorageProviderV30 source = mocks.StrictMock<IPagesStorageProviderV30>();
            IPagesStorageProviderV30 destination = mocks.StrictMock<IPagesStorageProviderV30>();

            // Setup SOURCE -------------------------

            // Setup snippets
            Snippet s1 = new Snippet("S1", "Blah1", source);
            Snippet s2 = new Snippet("S2", "Blah2", source);
            Expect.Call(source.GetSnippets()).Return(new Snippet[] { s1, s2 });

            // Setup content templates
            ContentTemplate ct1 = new ContentTemplate("CT1", "Template 1", source);
            ContentTemplate ct2 = new ContentTemplate("CT2", "Template 2", source);
            Expect.Call(source.GetContentTemplates()).Return(new ContentTemplate[] { ct1, ct2 });

            // Setup namespaces
            NamespaceInfo ns1 = new NamespaceInfo("NS1", source, null);
            NamespaceInfo ns2 = new NamespaceInfo("NS2", source, null);
            Expect.Call(source.GetNamespaces()).Return(new NamespaceInfo[] { ns1, ns2 });

            // Setup pages
            PageInfo p1 = new PageInfo("Page", source, DateTime.Now);
            PageInfo p2 = new PageInfo(NameTools.GetFullName(ns1.Name, "Page"), source, DateTime.Now);
            PageInfo p3 = new PageInfo(NameTools.GetFullName(ns1.Name, "Page1"), source, DateTime.Now);
            Expect.Call(source.GetPages(null)).Return(new PageInfo[] { p1 });
            Expect.Call(source.GetPages(ns1)).Return(new PageInfo[] { p2, p3 });
            Expect.Call(source.GetPages(ns2)).Return(new PageInfo[0]);

            // Set default page for NS1
            ns1.DefaultPage = p2;

            // Setup categories/bindings
            CategoryInfo c1 = new CategoryInfo("Cat", source);
            c1.Pages = new string[] { p1.FullName };
            CategoryInfo c2 = new CategoryInfo(NameTools.GetFullName(ns1.Name, "Cat"), source);
            c2.Pages = new string[] { p2.FullName };
            CategoryInfo c3 = new CategoryInfo(NameTools.GetFullName(ns1.Name, "Cat1"), source);
            c3.Pages = new string[0];
            Expect.Call(source.GetCategories(null)).Return(new CategoryInfo[] { c1 });
            Expect.Call(source.GetCategories(ns1)).Return(new CategoryInfo[] { c2, c3 });
            Expect.Call(source.GetCategories(ns2)).Return(new CategoryInfo[0]);

            // Setup drafts
            PageContent d1 = new PageContent(p1, "Draft", "NUnit", DateTime.Now, "Comm", "Cont", new string[] { "k1", "k2" }, "Descr");
            Expect.Call(source.GetDraft(p1)).Return(d1);
            Expect.Call(source.GetDraft(p2)).Return(null);
            Expect.Call(source.GetDraft(p3)).Return(null);

            // Setup content
            PageContent ctn1 = new PageContent(p1, "Title1", "User1", DateTime.Now, "Comm1", "Cont1", null, "Descr1");
            PageContent ctn2 = new PageContent(p2, "Title2", "User2", DateTime.Now, "Comm2", "Cont2", null, "Descr2");
            PageContent ctn3 = new PageContent(p3, "Title3", "User3", DateTime.Now, "Comm3", "Cont3", null, "Descr3");
            Expect.Call(source.GetContent(p1)).Return(ctn1);
            Expect.Call(source.GetContent(p2)).Return(ctn2);
            Expect.Call(source.GetContent(p3)).Return(ctn3);

            // Setup backups
            Expect.Call(source.GetBackups(p1)).Return(new int[] { 0, 1 });
            Expect.Call(source.GetBackups(p2)).Return(new int[] { 0 });
            Expect.Call(source.GetBackups(p3)).Return(new int[0]);
            PageContent bak1_0 = new PageContent(p1, "K1_0", "U1_0", DateTime.Now, "", "Cont", null, null);
            PageContent bak1_1 = new PageContent(p1, "K1_1", "U1_1", DateTime.Now, "", "Cont", null, null);
            PageContent bak2_0 = new PageContent(p2, "K2_0", "U2_0", DateTime.Now, "", "Cont", null, null);
            Expect.Call(source.GetBackupContent(p1, 0)).Return(bak1_0);
            Expect.Call(source.GetBackupContent(p1, 1)).Return(bak1_1);
            Expect.Call(source.GetBackupContent(p2, 0)).Return(bak2_0);

            // Messages
            Message m1 = new Message(1, "User1", "Subject1", DateTime.Now, "Body1");
            m1.Replies = new Message[] { new Message(2, "User2", "Subject2", DateTime.Now, "Body2") };
            Message[] p1m = new Message[] { m1 };
            Message[] p2m = new Message[0];
            Message[] p3m = new Message[0];
            Expect.Call(source.GetMessages(p1)).Return(p1m);
            Expect.Call(source.GetMessages(p2)).Return(p2m);
            Expect.Call(source.GetMessages(p3)).Return(p3m);

            // Setup navigation paths
            NavigationPath n1 = new NavigationPath("N1", source);
            n1.Pages = new string[] { p1.FullName };
            NavigationPath n2 = new NavigationPath(NameTools.GetFullName(ns1.Name, "N1"), source);
            n2.Pages = new string[] { p2.FullName, p3.FullName };
            Expect.Call(source.GetNavigationPaths(null)).Return(new NavigationPath[] { n1 });
            Expect.Call(source.GetNavigationPaths(ns1)).Return(new NavigationPath[] { n2 });
            Expect.Call(source.GetNavigationPaths(ns2)).Return(new NavigationPath[0]);

            // Setup DESTINATION --------------------------

            // Snippets
            Expect.Call(destination.AddSnippet(s1.Name, s1.Content)).Return(new Snippet(s1.Name, s1.Content, destination));
            Expect.Call(source.RemoveSnippet(s1.Name)).Return(true);
            Expect.Call(destination.AddSnippet(s2.Name, s2.Content)).Return(new Snippet(s2.Name, s2.Content, destination));
            Expect.Call(source.RemoveSnippet(s2.Name)).Return(true);

            // Content templates
            Expect.Call(destination.AddContentTemplate(ct1.Name, ct1.Content)).Return(new ContentTemplate(ct1.Name, ct1.Name, destination));
            Expect.Call(source.RemoveContentTemplate(ct1.Name)).Return(true);
            Expect.Call(destination.AddContentTemplate(ct2.Name, ct2.Content)).Return(new ContentTemplate(ct2.Name, ct2.Name, destination));
            Expect.Call(source.RemoveContentTemplate(ct2.Name)).Return(true);

            // Namespaces
            NamespaceInfo ns1Out = new NamespaceInfo(ns1.Name, destination, null);
            NamespaceInfo ns2Out = new NamespaceInfo(ns2.Name, destination, null);
            Expect.Call(destination.AddNamespace(ns1.Name)).Return(ns1Out);
            Expect.Call(source.RemoveNamespace(ns1)).Return(true);
            Expect.Call(destination.AddNamespace(ns2.Name)).Return(ns2Out);
            Expect.Call(source.RemoveNamespace(ns2)).Return(true);

            // Pages/drafts/content/backups/messages
            PageInfo p1Out = new PageInfo(p1.FullName, destination, p1.CreationDateTime);
            Expect.Call(destination.AddPage(null, p1.FullName, p1.CreationDateTime)).Return(p1Out);
            Expect.Call(destination.ModifyPage(p1Out, ctn1.Title, ctn1.User, ctn1.LastModified, ctn1.Comment, ctn1.Content, ctn1.Keywords, ctn1.Description, SaveMode.Normal)).Return(true);
            Expect.Call(destination.ModifyPage(p1Out, d1.Title, d1.User, d1.LastModified, d1.Comment, d1.Content, d1.Keywords, d1.Description, SaveMode.Draft)).Return(true);
            Expect.Call(destination.SetBackupContent(bak1_0, 0)).Return(true);
            Expect.Call(destination.SetBackupContent(bak1_1, 1)).Return(true);
            Expect.Call(destination.BulkStoreMessages(p1Out, p1m)).Return(true);
            Expect.Call(source.RemovePage(p1)).Return(true);

            PageInfo p2Out = new PageInfo(p2.FullName, destination, p2.CreationDateTime);
            Expect.Call(destination.AddPage(NameTools.GetNamespace(p2.FullName), NameTools.GetLocalName(p2.FullName),
                p2.CreationDateTime)).Return(p2Out);
            Expect.Call(destination.ModifyPage(p2Out, ctn2.Title, ctn2.User, ctn2.LastModified, ctn2.Comment, ctn2.Content, ctn2.Keywords, ctn2.Description, SaveMode.Normal)).Return(true);
            Expect.Call(destination.SetBackupContent(bak2_0, 0)).Return(true);
            Expect.Call(destination.BulkStoreMessages(p2Out, p2m)).Return(true);
            Expect.Call(source.RemovePage(p2)).Return(true);

            PageInfo p3Out = new PageInfo(p3.FullName, destination, p3.CreationDateTime);
            Expect.Call(destination.AddPage(NameTools.GetNamespace(p3.FullName), NameTools.GetLocalName(p3.FullName),
                p3.CreationDateTime)).Return(p3Out);
            Expect.Call(destination.ModifyPage(p3Out, ctn3.Title, ctn3.User, ctn3.LastModified, ctn3.Comment, ctn3.Content, ctn3.Keywords, ctn3.Description, SaveMode.Normal)).Return(true);
            Expect.Call(destination.BulkStoreMessages(p3Out, p3m)).Return(true);
            Expect.Call(source.RemovePage(p3)).Return(true);

            // Categories/bindings
            CategoryInfo c1Out = new CategoryInfo(c1.FullName, destination);
            CategoryInfo c2Out = new CategoryInfo(c2.FullName, destination);
            CategoryInfo c3Out = new CategoryInfo(c3.FullName, destination);
            Expect.Call(destination.AddCategory(null, c1.FullName)).Return(c1Out);
            Expect.Call(destination.AddCategory(NameTools.GetNamespace(c2.FullName), NameTools.GetLocalName(c2.FullName))).Return(c2Out);
            Expect.Call(destination.AddCategory(NameTools.GetNamespace(c3.FullName), NameTools.GetLocalName(c3.FullName))).Return(c3Out);
            Expect.Call(destination.RebindPage(p1Out, new string[] { c1.FullName })).Return(true);
            Expect.Call(destination.RebindPage(p2Out, new string[] { c2.FullName })).Return(true);
            Expect.Call(destination.RebindPage(p3Out, new string[0])).Return(true);
            Expect.Call(source.RemoveCategory(c1)).Return(true);
            Expect.Call(source.RemoveCategory(c2)).Return(true);
            Expect.Call(source.RemoveCategory(c3)).Return(true);

            // Navigation paths
            NavigationPath n1Out = new NavigationPath(n1.FullName, destination);
            n1Out.Pages = n1.Pages;
            NavigationPath n2Out = new NavigationPath(n2.FullName, destination);
            n2Out.Pages = n2.Pages;

            Expect.Call(destination.AddNavigationPath(null, n1.FullName, new PageInfo[] { p1 })).Return(n1Out).Constraints(
                RMC.Is.Null(), RMC.Is.Equal(n1.FullName),
                RMC.Is.Matching<PageInfo[]>(delegate(PageInfo[] array) {
                    return array[0].FullName == p1.FullName;
                }));

            Expect.Call(destination.AddNavigationPath(NameTools.GetNamespace(n2.FullName), NameTools.GetLocalName(n2.FullName), new PageInfo[] { p2, p3 })).Return(n2Out).Constraints(
                RMC.Is.Equal(NameTools.GetNamespace(n2.FullName)), RMC.Is.Equal(NameTools.GetLocalName(n2.FullName)),
                RMC.Is.Matching<PageInfo[]>(delegate(PageInfo[] array) {
                    return array[0].FullName == p2.FullName && array[1].FullName == p3.FullName;
                }));

            Expect.Call(source.RemoveNavigationPath(n1)).Return(true);
            Expect.Call(source.RemoveNavigationPath(n2)).Return(true);

            Expect.Call(destination.SetNamespaceDefaultPage(ns1Out, p2Out)).Return(ns1Out);
            Expect.Call(destination.SetNamespaceDefaultPage(ns2Out, null)).Return(ns2Out);

            // Used for navigation paths
            Expect.Call(destination.GetPages(null)).Return(new PageInfo[] { p1Out });
            Expect.Call(destination.GetPages(ns1Out)).Return(new PageInfo[] { p2Out, p3Out });
            Expect.Call(destination.GetPages(ns2Out)).Return(new PageInfo[0]);

            mocks.Replay(source);
            mocks.Replay(destination);

            DataMigrator.MigratePagesStorageProviderData(source, destination);

            mocks.Verify(source);
            mocks.Verify(destination);
        }
コード例 #37
0
ファイル: ViewController.cs プロジェクト: howej/dotnetage
        public ActionResult NewView(int id, string name, string style, string mode, string title, string website = "home", bool nopage = false)
        {
            var web = App.Get().Webs[website];
            var list = web.Lists[id];
            var view = list.CreateView(name, title);

            var contentTmpl = new ContentTemplate()
            {
                //ContentType = mode == "server" ? "text/xslt" : "text/x-jquery-tmpl",
                Source = style
                //Source = "_" + style + ".cshtml"
            };

            view.BodyTemplateXml = contentTmpl.ToXml();
            view.Save();

            if (!nopage)
            {
                var defaultView = view.Parent.DefaultView;
                web.CreatePage(view, defaultView != null && defaultView.Page != null ? defaultView.Page.ID : 0, title);
            }

            return Redirect(view.SettingUrl);
        }
コード例 #38
0
ファイル: ViewController.cs プロジェクト: howej/dotnetage
        public ActionResult SetStyle(string name, string slug, string style)
        {
            var view = Find(name, slug);
            var tmplFile = "~/content/types/base/views/" + style + (style.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase) ? "" : ".cshtml");
            if (!System.IO.File.Exists(Server.MapPath(tmplFile)))
                throw new HttpException("View template file not found.");

            var bodyTmpl = new ContentTemplate()
            {
                ContentType = TemplateContentTypes.Razor,
                Source = style + (style.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase) ? "" : ".cshtml")
            };
            view.BodyTemplateXml = bodyTmpl.Element().OuterXml();
            view.Save();

            return new HttpStatusCodeResult(200);
        }
コード例 #39
0
ファイル: Templates.cs プロジェクト: mono/ScrewTurnWiki
        /// <summary>
        /// Removes a content template.
        /// </summary>
        /// <param name="template">The template to remove.</param>
        /// <returns><c>true</c> if the template is removed, <c>false</c> otherwise.</returns>
        public static bool RemoveTemplate(ContentTemplate template)
        {
            bool done = template.Provider.RemoveContentTemplate(template.Name);

            if(done) Log.LogEntry("Content Template " + template.Name + " deleted", EntryType.General, Log.SystemUsername);
            else Log.LogEntry("Deletion failed for Content Template " + template.Name, EntryType.Error, Log.SystemUsername);

            return done;
        }
コード例 #40
0
        public void Transform(string text, ContentView view)
        {
            var xTmpl = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                 "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\" exclude-result-prefixes=\"msxsl\">" +
                                 "<xsl:output method=\"html\" indent=\"yes\"/>" +
                                 "<xsl:template match=\"/\"></xsl:template></xsl:stylesheet>";
            var xsltDoc = XDocument.Parse(xTmpl);
            XNamespace ns = "http://www.w3.org/1999/XSL/Transform";

            //var text = "<div class=\"d-layout-box d-h-box\" data-box=\"hbox\"><div style=\"width: 105px; height: 100px;\" class=\"d-box d-inline\"><div class=\"d-field-holder d-inline\" data-type=\"image\" data-link=\"true\" data-label=\"Cover\" data-field=\"cover\"></div></div><div style=\"width: 441px;\" class=\"d-box d-inline\"><div class=\"d-field-holder\" data-type=\"text\" data-link=\"true\" data-label=\"Title\" data-field=\"title\"></div><div class=\"d-field-holder\" data-type=\"note\" data-link=\"true\" data-label=\"Body\" data-field=\"body\"></div></div></div>";
            //Add params
            xsltDoc.Root.Add(new XElement(ns + "param", new XAttribute("name", "appPath")),
                new XElement(ns + "param", new XAttribute("name", "web")),
                new XElement(ns + "param", new XAttribute("name", "list")),
                new XElement(ns + "param", new XAttribute("name", "view")),
                new XElement(ns + "param", new XAttribute("name", "lang"))
                );

            var tmplElement = xsltDoc.Root.Element(ns + "template");
            var listElement = new XElement("ul", new XAttribute("class", "d-view-list"));
            tmplElement.Add(listElement);
            var rowTmpl = XElement.Parse(text);
            var forEachElement = new XElement(ns + "for-each",
                new XAttribute("select", @"//rows/row"), new XElement("li",new XAttribute("class","d-view-item"), rowTmpl));

            listElement.Add(forEachElement);

            rowTmpl.DescendantsAndSelf()
                .Where(f => f.Attribute("data-field") != null)
                .ToList()
                .AsParallel()
                .ForAll(e =>
                {
                    var fieldName = e.Attribute("data-field").Value;
                    var linkToItem = e.BoolAttr("data-link");
                    var inline = e.BoolAttr("data-line");
                    var fieldType = e.Attribute("data-type").Value;

                    var showLabel = !e.BoolAttr("data-label-hidden");
                    //label=e.Element("label")
                    //e.ReplaceWith(new XElement(ns + "value-of", new XAttribute("select", fieldName)));
                    var applyTemplate = new XElement(ns + "apply-templates", new XAttribute("select", fieldName));

                    var fieldTmpl = new XElement(ns + "template", new XAttribute("match", fieldName));
                    XElement linkTmpl = null;
                    if (linkToItem)
                    {
                        linkTmpl = new XElement(ns + "element", new XAttribute("name", "a"),
                            new XElement(ns + "attribute", new XAttribute("name", "href"), new XElement(ns + "value-of", new XAttribute("select", "concat($appPath,'/',$web,'/',$lang,'/lists/',$list,'/items/',../@Slug,'.html')"))));
                    }

                    XElement fieldContentTmpl = null;

                    if (fieldType == "image")
                    {
                        fieldContentTmpl = new XElement(ns + "element", new XAttribute("name", "img"),
                            new XElement(ns + "attribute", new XAttribute("name", "src"),
                            new XElement(ns + "value-of", new XAttribute("select", ".")))
                            );
                    }
                    else
                    {
                        fieldContentTmpl = new XElement(ns + "element", new XAttribute("name", inline ? "span" : "div"),
                            new XElement(ns + "value-of", new XAttribute("select", ".")));
                    }

                    if (inline)
                        fieldContentTmpl.Add(new XAttribute("class", "d-inline"));

                    if (linkTmpl != null)
                    {
                        linkTmpl.Add(fieldContentTmpl);
                        fieldTmpl.Add(linkTmpl);
                    }
                    else
                        fieldTmpl.Add(fieldContentTmpl);

                    xsltDoc.Root.Add(fieldTmpl);
                    //new template
                    //e.ReplaceWith(applyTemplate);
                    e.Add(applyTemplate);
                });

            //return xsltDoc.ToString();
            var result = new ContentTemplate()
            {
                ContentType = this.ContentType,
                Text = xsltDoc.ToString()
            };

            view.BodyTemplateXml = result.ToXml();
        }
コード例 #41
0
ファイル: TemplateGroup.cs プロジェクト: jyunfan2015/forge
 ITemplate ITemplateGroup.CreateTemplate() {
     ITemplate template = new ContentTemplate(TemplateIdGenerator.Next());
     Templates.Add(template);
     return template;
 }
コード例 #42
0
        /// <summary>
        /// Gets all the content templates.
        /// </summary>
        /// <returns>All the content templates, sorted by name.</returns>
        public ContentTemplate[] GetContentTemplates()
        {
            lock(this) {
                string[] files = Directory.GetFiles(GetFullPath(ContentTemplatesDirectory), "*.cs");

                ContentTemplate[] templates = new ContentTemplate[files.Length];
                for(int i = 0; i < files.Length; i++) {
                    templates[i] = new ContentTemplate(Path.GetFileNameWithoutExtension(files[i]), File.ReadAllText(files[i]), this);
                }

                Array.Sort(templates, new ContentTemplateNameComparer());

                return templates;
            }
        }
コード例 #43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SnippetTemplateRow" /> class.
 /// </summary>
 /// <param name="template">The original template.</param>
 /// <param name="selected">A value indicating whether the template is selected.</param>
 public SnippetTemplateRow(ContentTemplate template, bool selected)
 {
     type = Properties.Messages.Template;
     name = template.Name;
     distinguishedName = "T." + template.Name;
     parameterCount = "";
     provider = template.Provider.Information.Name;
     additionalClass = selected ? " selected" : "";
 }
コード例 #44
0
ファイル: ViewController.cs プロジェクト: howej/dotnetage
 public ActionResult Code(string name, string slug, string code, string locale)
 {
     var view = Find(name, slug);
     var bodyTmpl = new ContentTemplate()
     {
         ContentType = TemplateContentTypes.Razor,
         Text = code
     };
     view.BodyTemplateXml = bodyTmpl.Element().OuterXml();
     view.Save();
     TemplateHelper.SaveAsView(view.Parent, code, string.Format("_view_{0}_tmpl.cshtml", view.Name), true);
     return new HttpStatusCodeResult(200);
 }