public void StyleSheet_Make_New_AddProperty()
        {
            var s = StyleSheet.MakeNew(m_User, Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N") + ".css", Guid.NewGuid().ToString("N"));

            Assert.IsTrue(s.Id > 0);
            Assert.IsInstanceOf <StyleSheet>(s);

            //add property
            var p = s.AddProperty(Guid.NewGuid().ToString("N"), m_User);

            Assert.IsTrue(p.Id > 0);
            Assert.IsInstanceOf <StylesheetProperty>(p);

            //now remove it
            s.delete();
            Assert.IsFalse(StyleSheet.IsNode(s.Id));

            //make sure the property is gone too
            Assert.IsFalse(StylesheetProperty.IsNode(p.Id));
        }
 set => SetValue(StylesheetProperty, value);
Пример #3
0
        /// <summary>
        /// Invoking this method installs the current package
        /// </summary>
        /// <param Name="tempDir">Temporary folder where the package's content are extracted to</param>
        public void Install(string tempDir)
        {
            callCommands("start");

            // Install macros
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("//macro"))
            {
                Cms.BusinessLogic.macro.Macro m = Cms.BusinessLogic.macro.Macro.MakeNew(XmlHelper.GetNodeValue(n.SelectSingleNode("Name")));
                m.Alias       = XmlHelper.GetNodeValue(n.SelectSingleNode("alias"));
                m.Assembly    = XmlHelper.GetNodeValue(n.SelectSingleNode("scriptAssembly"));
                m.Type        = XmlHelper.GetNodeValue(n.SelectSingleNode("scriptType"));
                m.Xslt        = XmlHelper.GetNodeValue(n.SelectSingleNode("xslt"));
                m.RefreshRate = int.Parse(XmlHelper.GetNodeValue(n.SelectSingleNode("refreshRate")));
                try
                {
                    m.UseInEditor = bool.Parse(XmlHelper.GetNodeValue(n.SelectSingleNode("useInEditor")));
                }
                catch
                { }

                // macro properties
                foreach (XmlNode mp in n.SelectNodes("properties/property"))
                {
                    try
                    {
                        Cms.BusinessLogic.macro.MacroProperty.MakeNew(
                            m,
                            bool.Parse(mp.Attributes.GetNamedItem("show").Value),
                            mp.Attributes.GetNamedItem("alias").Value,
                            mp.Attributes.GetNamedItem("Name").Value,
                            new Cms.BusinessLogic.macro.MacroPropertyType(mp.Attributes.GetNamedItem("propertyType").Value)
                            );
                    }
                    catch (Exception macroPropertyExp)
                    {
                        BusinessLogic.Log.Add(BusinessLogic.LogTypes.Error, BusinessLogic.User.GetUser(0), -1, "Error creating macro property: " + macroPropertyExp.ToString());
                    }
                }
            }

            // Copy files
            string appPath = System.Web.HttpContext.Current.Request.ApplicationPath;

            if (appPath == "/")
            {
                appPath = "";
            }
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("//file"))
            {
                if (!Directory.Exists(HttpContext.Current.Server.MapPath(appPath + XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")))))
                {
                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath(appPath + XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath"))));
                }
                File.Copy(tempDir + Path.DirectorySeparatorChar + XmlHelper.GetNodeValue(n.SelectSingleNode("guid")), HttpContext.Current.Server.MapPath(appPath + XmlHelper.GetNodeValue(n.SelectSingleNode("orgPath")) + Path.DirectorySeparatorChar + XmlHelper.GetNodeValue(n.SelectSingleNode("orgName"))), true);
                File.Delete(tempDir + Path.DirectorySeparatorChar + XmlHelper.GetNodeValue(n.SelectSingleNode("guid")));
            }


            // Get current user
            BasePages.UmbracoEnsuredPage uep = new Umbraco.BasePages.UmbracoEnsuredPage();
            BusinessLogic.User           u   = uep.ValidatedUser;

            // Add Templates
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("Templates/Template"))
            {
                template.Template t = template.Template.MakeNew(XmlHelper.GetNodeValue(n.SelectSingleNode("Name")), u);
                t.Alias  = XmlHelper.GetNodeValue(n.SelectSingleNode("Alias"));
                t.Design = XmlHelper.GetNodeValue(n.SelectSingleNode("Design"));
            }

            // Add master templates
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("Templates/Template"))
            {
                string master = XmlHelper.GetNodeValue(n.SelectSingleNode("Master"));
                if (master.Trim() != "")
                {
                    template.Template t = template.Template.GetByAlias(XmlHelper.GetNodeValue(n.SelectSingleNode("Alias")));
                    template.Template masterTemplate = template.Template.GetByAlias(master);
                    if (masterTemplate != null)
                    {
                        t.MasterTemplate = template.Template.GetByAlias(master).Id;
                    }
                }
            }

            // Add documenttypes

            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("DocumentTypes/DocumentType"))
            {
                ImportDocumentType(n, u, false);
            }

            // Add documenttype structure
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("DocumentTypes/DocumentType"))
            {
                DocumentType dt = DocumentType.GetByAlias(XmlHelper.GetNodeValue(n.SelectSingleNode("Info/Alias")));
                if (dt != null)
                {
                    ArrayList allowed = new ArrayList();
                    foreach (XmlNode structure in n.SelectNodes("Structure/DocumentType"))
                    {
                        DocumentType dtt = DocumentType.GetByAlias(XmlHelper.GetNodeValue(structure));
                        allowed.Add(dtt.Id);
                    }
                    int[] adt = new int[allowed.Count];
                    for (int i = 0; i < allowed.Count; i++)
                    {
                        adt[i] = (int)allowed[i];
                    }
                    dt.AllowedChildContentTypeIDs = adt;
                }
            }

            // Stylesheets
            foreach (XmlNode n in _packageConfig.DocumentElement.SelectNodes("Stylesheets/Stylesheet"))
            {
                StyleSheet s = StyleSheet.MakeNew(
                    u,
                    XmlHelper.GetNodeValue(n.SelectSingleNode("Name")),
                    XmlHelper.GetNodeValue(n.SelectSingleNode("FileName")),
                    XmlHelper.GetNodeValue(n.SelectSingleNode("Content")));

                foreach (XmlNode prop in n.SelectNodes("Properties/Property"))
                {
                    StylesheetProperty sp = StylesheetProperty.MakeNew(
                        XmlHelper.GetNodeValue(prop.SelectSingleNode("Name")),
                        s,
                        u);
                    sp.Alias = XmlHelper.GetNodeValue(prop.SelectSingleNode("Alias"));
                    sp.value = XmlHelper.GetNodeValue(prop.SelectSingleNode("Value"));
                }
                s.saveCssToFile();
            }

            // Documents
            foreach (XmlElement n in _packageConfig.DocumentElement.SelectNodes("Documents/DocumentSet [@importMode = 'root']/node"))
            {
                Cms.BusinessLogic.web.Document.Import(-1, u, n);
            }

            callCommands("end");
        }
Пример #4
0
        public void InstallBusinessLogic(int packageId, string tempDir)
        {
            using (Current.ProfilingLogger.DebugDuration <Installer>(
                       "Installing business logic for package id " + packageId + " into temp folder " + tempDir,
                       "Package business logic installation complete for package id " + packageId))
            {
                InstalledPackage insPack;
                try
                {
                    //retrieve the manifest to continue installation
                    insPack = InstalledPackage.GetById(packageId);
                    //bool saveNeeded = false;

                    // Get current user, with a fallback
                    var currentUser = Current.Services.UserService.GetUserById(Constants.Security.SuperUserId);

                    //TODO: Get rid of this entire class! Until then all packages will be installed by the admin user


                    //Xml as XElement which is used with the new PackagingService
                    var rootElement      = Config.DocumentElement.GetXElement();
                    var packagingService = Current.Services.PackagingService;

                    //Perhaps it would have been a good idea to put the following into methods eh?!?

                    #region DataTypes
                    var dataTypeElement = rootElement.Descendants("DataTypes").FirstOrDefault();
                    if (dataTypeElement != null)
                    {
                        var dataTypeDefinitions = packagingService.ImportDataTypeDefinitions(dataTypeElement, currentUser.Id);
                        foreach (var dataTypeDefinition in dataTypeDefinitions)
                        {
                            insPack.Data.DataTypes.Add(dataTypeDefinition.Id.ToString(CultureInfo.InvariantCulture));
                        }
                    }
                    #endregion

                    #region Languages
                    var languageItemsElement = rootElement.Descendants("Languages").FirstOrDefault();
                    if (languageItemsElement != null)
                    {
                        var insertedLanguages = packagingService.ImportLanguages(languageItemsElement);
                        insPack.Data.Languages.AddRange(insertedLanguages.Select(l => l.Id.ToString(CultureInfo.InvariantCulture)));
                    }

                    #endregion

                    #region Dictionary items
                    var dictionaryItemsElement = rootElement.Descendants("DictionaryItems").FirstOrDefault();
                    if (dictionaryItemsElement != null)
                    {
                        var insertedDictionaryItems = packagingService.ImportDictionaryItems(dictionaryItemsElement);
                        insPack.Data.DictionaryItems.AddRange(insertedDictionaryItems.Select(d => d.Id.ToString(CultureInfo.InvariantCulture)));
                    }
                    #endregion

                    #region Macros
                    var macroItemsElement = rootElement.Descendants("Macros").FirstOrDefault();
                    if (macroItemsElement != null)
                    {
                        var insertedMacros = packagingService.ImportMacros(macroItemsElement);
                        insPack.Data.Macros.AddRange(insertedMacros.Select(m => m.Id.ToString(CultureInfo.InvariantCulture)));
                    }
                    #endregion

                    #region Templates
                    var templateElement = rootElement.Descendants("Templates").FirstOrDefault();
                    if (templateElement != null)
                    {
                        var templates = packagingService.ImportTemplates(templateElement, currentUser.Id);
                        foreach (var template in templates)
                        {
                            insPack.Data.Templates.Add(template.Id.ToString(CultureInfo.InvariantCulture));
                        }
                    }
                    #endregion

                    #region DocumentTypes
                    //Check whether the root element is a doc type rather then a complete package
                    var docTypeElement = rootElement.Name.LocalName.Equals("DocumentType") ||
                                         rootElement.Name.LocalName.Equals("DocumentTypes")
                        ? rootElement
                        : rootElement.Descendants("DocumentTypes").FirstOrDefault();

                    if (docTypeElement != null)
                    {
                        var contentTypes = packagingService.ImportContentTypes(docTypeElement, currentUser.Id);
                        foreach (var contentType in contentTypes)
                        {
                            insPack.Data.Documenttypes.Add(contentType.Id.ToString(CultureInfo.InvariantCulture));
                            //saveNeeded = true;
                        }
                    }
                    #endregion

                    #region Stylesheets
                    foreach (XmlNode n in Config.DocumentElement.SelectNodes("Stylesheets/Stylesheet"))
                    {
                        //StyleSheet s = StyleSheet.Import(n, currentUser);


                        string stylesheetName = XmlHelper.GetNodeValue(n.SelectSingleNode("Name"));
                        //StyleSheet s = GetByName(stylesheetName);
                        var s = Current.Services.FileService.GetStylesheetByName(stylesheetName);
                        if (s == null)
                        {
                            s = new Stylesheet(XmlHelper.GetNodeValue(n.SelectSingleNode("FileName")))
                            {
                                Content = XmlHelper.GetNodeValue(n.SelectSingleNode("Content"))
                            };
                            Current.Services.FileService.SaveStylesheet(s);
                        }

                        foreach (XmlNode prop in n.SelectNodes("Properties/Property"))
                        {
                            string alias = XmlHelper.GetNodeValue(prop.SelectSingleNode("Alias"));
                            var    sp    = s.Properties.SingleOrDefault(p => p != null && p.Alias == alias);
                            string name  = XmlHelper.GetNodeValue(prop.SelectSingleNode("Name"));
                            if (sp == null)
                            {
                                //sp = StylesheetProperty.MakeNew(
                                //    name,
                                //    s,
                                //    u);

                                sp = new StylesheetProperty(name, "#" + name.ToSafeAlias(), "");
                                s.AddProperty(sp);
                            }
                            else
                            {
                                //sp.Text = name;
                                //Changing the name requires removing the current property and then adding another new one
                                if (sp.Name != name)
                                {
                                    s.RemoveProperty(sp.Name);
                                    var newProp = new StylesheetProperty(name, sp.Alias, sp.Value);
                                    s.AddProperty(newProp);
                                    sp = newProp;
                                }
                            }
                            sp.Alias = alias;
                            sp.Value = XmlHelper.GetNodeValue(prop.SelectSingleNode("Value"));
                        }
                        //s.saveCssToFile();
                        Current.Services.FileService.SaveStylesheet(s);



                        insPack.Data.Stylesheets.Add(s.Id.ToString(CultureInfo.InvariantCulture));
                        //saveNeeded = true;
                    }

                    //if (saveNeeded) { insPack.Save(); saveNeeded = false; }
                    #endregion

                    #region Documents
                    var documentElement = rootElement.Descendants("DocumentSet").FirstOrDefault();
                    if (documentElement != null)
                    {
                        var content          = packagingService.ImportContent(documentElement, -1, currentUser.Id);
                        var firstContentItem = content.First();
                        insPack.Data.ContentNodeId = firstContentItem.Id.ToString(CultureInfo.InvariantCulture);
                    }
                    #endregion

                    #region Package Actions
                    foreach (XmlNode n in Config.DocumentElement.SelectNodes("Actions/Action"))
                    {
                        if (n.Attributes["undo"] == null || n.Attributes["undo"].Value == "true")
                        {
                            insPack.Data.Actions += n.OuterXml;
                        }

                        //Run the actions tagged only for 'install'

                        if (n.Attributes["runat"] != null && n.Attributes["runat"].Value == "install")
                        {
                            var alias = n.Attributes["alias"] != null ? n.Attributes["alias"].Value : "";

                            if (alias.IsNullOrWhiteSpace() == false)
                            {
                                PackageAction.RunPackageAction(insPack.Data.Name, alias, n);
                            }
                        }
                    }
                    #endregion

                    insPack.Save();
                }
                catch (Exception ex)
                {
                    Current.Logger.Error <Installer>(ex, "Error installing businesslogic");
                    throw;
                }

                OnPackageBusinessLogicInstalled(insPack);
                OnPackageInstalled(insPack);
            }
        }