示例#1
0
        /// <summary>
        /// Bind the template files from the given template location
        /// </summary>
        /// <param name="TemplateType">The template type</param>
        /// <param name="TemplateLocation">The template location</param>
        /// <param name="TemplateDropDown">The template dropdown to databind</param>
        private void BindTemplateFiles(string TemplateType, string TemplateLocation, DropDownList TemplateDropDown)
        {
            var tm = new Internal.TemplateManager(App);

            TemplateDropDown.DataSource = tm.GetTemplateFiles(Server, TemplateType, TemplateLocation);
            TemplateDropDown.DataBind();
        }
示例#2
0
        /// <summary>
        /// After the Update button is clicked, updates the template or creates a new one,
        /// depending if in edit mode or not.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            var tm = new Internal.TemplateManager(App);

            var templatePath = ddlTemplateFiles.SelectedValue;

            if (!pnlSelectTemplateFile.Visible)
            {
                templatePath = tm.CreateTemplateFileIfNotExists(txtTemplateFileName.Text, ddlTemplateTypes.SelectedValue, ddlTemplateLocations.SelectedValue, Server, LocalizeString("NewTemplateFile.DefaultText"));
            }

            var templateId       = ModeIsEdit ? Template.TemplateId : new int?();
            var pipelineEntityId = ddlDataPipeline.SelectedValue == "0" ? (int?)null : Int32.Parse(ddlDataPipeline.SelectedValue);

            if (!chkSeparateContentPresentation.Checked)
            {
                ctrPresentationType.ContentTypeStaticName = "";
            }

            App.TemplateManager.UpdateTemplate(templateId, txtTemplateName.Text, templatePath, ctrContentType.ContentTypeStaticName, ctrContentType.DemoEntityID, ctrPresentationType.ContentTypeStaticName, ctrPresentationType.DemoEntityID, ctrListContentType.ContentTypeStaticName, ctrListContentType.DemoEntityID, ctrListPresentationType.ContentTypeStaticName, ctrListPresentationType.DemoEntityID, ddlTemplateTypes.SelectedValue, chkHidden.Checked, ddlTemplateLocations.SelectedValue, chkEnableList.Checked, chkPublishSource.Checked, txtPublishStreams.Text, pipelineEntityId, txtViewNameInUrl.Text);

            // old Redirect to the manage templates control
            //var RedirectUrl = UrlUtils.PopUpUrl(Globals.NavigateURL(SexyContent.ControlKeys.ManageTemplates, "mid", ModuleId.ToString(), SexyContent.AppIDString, AppId.ToString()), this, PortalSettings, false, true);
            //Response.Redirect(RedirectUrl);

            // New 2015-09-19 close this window - temporary solution till this dialog is obsolete
            Response.Write("<script>window.close();</script>");
        }
示例#3
0
 // todo: try to cache the result of settings-stored in a static variable, this full check
 // todo: shouldn't have to happen every time
 /// <summary>
 /// Returns true if the Portal HomeDirectory Contains the 2sxc Folder and this folder contains the web.config and a Content folder
 /// </summary>
 public void EnsurePortalIsConfigured(SxcInstance sxc, HttpServerUtility server, string controlPath)
 {
     var sexyFolder = new DirectoryInfo(server.MapPath(Path.Combine(sxc.AppPortalSettings.HomeDirectory, Settings.TemplateFolder)));
     var contentFolder = new DirectoryInfo(Path.Combine(sexyFolder.FullName, Constants.ContentAppName));
     var webConfigTemplate = new FileInfo(Path.Combine(sexyFolder.FullName, Settings.WebConfigFileName));
     if (!(sexyFolder.Exists && webConfigTemplate.Exists && contentFolder.Exists))
     {
         // configure it
         var tm = new TemplateManager(sxc.App);
         tm.EnsureTemplateFolderExists(Settings.TemplateLocations.PortalFileSystem);
     };
 }
示例#4
0
文件: XmlImport.cs 项目: 2sic/2sxc
        private void ImportXmlTemplates(XElement root)
        {
            var templates = root.Element(XmlConstants.Templates);
            if (templates == null) return;

            var cache = DataSource.GetCache(_zoneId, _appId);

            foreach (var template in templates.Elements(XmlConstants.Template))
            {
                var name = "";
                try
                {
                    name = template.Attribute("Name").Value;
                    var path = template.Attribute("Path").Value;

                    var contentTypeStaticName = template.Attribute(XmlConstants.AttSetStatic).Value;

                    if (!IsNullOrEmpty(contentTypeStaticName) && cache.GetContentType(contentTypeStaticName) == null)
                    {
                        ImportLog.Add(
                            new ExportImportMessage(
                                "Content Type for Template '" + name +
                                "' could not be found. The template has not been imported.",
                                ExportImportMessage.MessageTypes.Warning));
                        continue;
                    }

                    var demoEntityGuid = template.Attribute("DemoEntityGUID").Value;
                    var demoEntityId = new int?();

                    if (!IsNullOrEmpty(demoEntityGuid))
                    {
                        var entityGuid = Guid.Parse(demoEntityGuid);
                        if ( /*App.*/_eavContext.Entities.EntityExists(entityGuid))
                            demoEntityId = /*App.*/ _eavContext.Entities.GetEntity(entityGuid).EntityID;
                        else
                            ImportLog.Add(
                                new ExportImportMessage(
                                    "Demo Entity for Template '" + name + "' could not be found. (Guid: " +
                                    demoEntityGuid +
                                    ")", ExportImportMessage.MessageTypes.Information));

                    }

                    var type = template.Attribute("Type").Value;
                    var isHidden = Parse(template.Attribute("IsHidden").Value);
                    var location = template.Attribute("Location").Value;
                    var publishData =
                        Parse(template.Attribute("PublishData") == null
                            ? "False"
                            : template.Attribute("PublishData").Value);
                    var streamsToPublish = template.Attribute("StreamsToPublish") == null
                        ? ""
                        : template.Attribute("StreamsToPublish").Value;
                    var viewNameInUrl = template.Attribute("ViewNameInUrl") == null
                        ? null
                        : template.Attribute("ViewNameInUrl").Value;

                    var pipelineEntityGuid = template.Attribute("PipelineEntityGUID");
                    var pipelineEntityId = new int?();

                    if (!IsNullOrEmpty(pipelineEntityGuid?.Value))
                    {
                        var entityGuid = Guid.Parse(pipelineEntityGuid.Value);
                        if (_eavContext.Entities.EntityExists(entityGuid))
                            pipelineEntityId = _eavContext.Entities.GetEntity(entityGuid).EntityID;
                        else
                            ImportLog.Add(
                                new ExportImportMessage(
                                    "Pipeline Entity for Template '" + name + "' could not be found. (Guid: " +
                                    pipelineEntityGuid.Value +
                                    ")", ExportImportMessage.MessageTypes.Information));
                    }

                    var useForList = false;
                    if (template.Attribute("UseForList") != null)
                        useForList = Parse(template.Attribute("UseForList").Value);

                    var lstTemplateDefaults = template.Elements(XmlConstants.Entity).Select(e =>
                    {
                        var xmlItemType =
                            e.Elements("Value")
                                .FirstOrDefault(v => v.Attribute("Key").Value == "ItemType")?
                                .Attribute("Value")
                                .Value;
                        var xmlContentTypeStaticName =
                            e.Elements("Value")
                                .FirstOrDefault(v => v.Attribute("Key").Value == "ContentTypeID")?
                                .Attribute("Value")
                                .Value;
                        var xmlDemoEntityGuidString =
                            e.Elements("Value")
                                .FirstOrDefault(v => v.Attribute("Key").Value == "DemoEntityID")?
                                .Attribute("Value")
                                .Value;
                        if (xmlItemType == null || xmlContentTypeStaticName == null || xmlDemoEntityGuidString == null)
                        {
                            ImportLog.Add(new ExportImportMessage(
                                $"trouble with template '{name}' - either type, static or guid are null", ExportImportMessage.MessageTypes.Error));
                            return null;
                        }
                        var xmlDemoEntityId = new int?();
                        if (xmlDemoEntityGuidString != "0" && xmlDemoEntityGuidString != "")
                        {
                            var xmlDemoEntityGuid = Guid.Parse(xmlDemoEntityGuidString);
                            if (_eavContext.Entities.EntityExists(xmlDemoEntityGuid))
                                xmlDemoEntityId = _eavContext.Entities.GetEntity(xmlDemoEntityGuid).EntityID;
                        }

                        return new TemplateDefault
                        {
                            ItemType = xmlItemType,
                            ContentTypeStaticName =
                                xmlContentTypeStaticName == "0" || xmlContentTypeStaticName == ""
                                    ? ""
                                    : xmlContentTypeStaticName,
                            DemoEntityId = xmlDemoEntityId
                        };
                    }).ToList();

                    // Array lstTemplateDefaults has null objects 

                    //Remove null objects if any
                    var templateDefaults = new List<TemplateDefault>();
                    foreach (var lstItem in lstTemplateDefaults)
                    {
                        if (lstItem != null)
                        {
                            templateDefaults.Add(lstItem);
                        }
                    }

                    var presentationTypeStaticName = "";
                    var presentationDemoEntityId = new int?();
                    //if list templateDefaults would have null objects, we would have an exception
                    var presentationDefault = templateDefaults.FirstOrDefault(t => t.ItemType == Constants.PresentationKey);
                    if (presentationDefault != null)
                    {
                        presentationTypeStaticName = presentationDefault.ContentTypeStaticName;
                        presentationDemoEntityId = presentationDefault.DemoEntityId;
                    }

                    var listContentTypeStaticName = "";
                    var listContentDemoEntityId = new int?();
                    var listContentDefault = templateDefaults.FirstOrDefault(t => t.ItemType == "ListContent");
                    if (listContentDefault != null)
                    {
                        listContentTypeStaticName = listContentDefault.ContentTypeStaticName;
                        listContentDemoEntityId = listContentDefault.DemoEntityId;
                    }

                    var listPresentationTypeStaticName = "";
                    var listPresentationDemoEntityId = new int?();
                    var listPresentationDefault = templateDefaults.FirstOrDefault(t => t.ItemType == "ListPresentation");
                    if (listPresentationDefault != null)
                    {
                        listPresentationTypeStaticName = listPresentationDefault.ContentTypeStaticName;
                        listPresentationDemoEntityId = listPresentationDefault.DemoEntityId;
                    }

                    var tm = new TemplateManager(_eavContext.ZoneId, _eavContext.AppId);
                    tm.UpdateTemplate(null, name, path, contentTypeStaticName, demoEntityId, presentationTypeStaticName,
                        presentationDemoEntityId, listContentTypeStaticName, listContentDemoEntityId,
                        listPresentationTypeStaticName, listPresentationDemoEntityId, type, isHidden, location,
                        useForList, publishData, streamsToPublish, pipelineEntityId, viewNameInUrl);

                    ImportLog.Add(new ExportImportMessage("Template '" + name + "' successfully imported.",
                        ExportImportMessage.MessageTypes.Information));
                }

                catch (Exception e)
                {
                    ImportLog.Add(new ExportImportMessage("Import for template '" + name + "' failed.",
                        ExportImportMessage.MessageTypes.Information));
                }

            }
        }
示例#5
0
 private TemplateManager TemplateManager(int appId)
 {
     var zoneId = ZoneHelpers.GetZoneID(PortalSettings.PortalId).Value;
     var tm = new TemplateManager(zoneId, appId);
     return tm;
 }