Example #1
0
        /// <summary>
        /// Parse skin package.
        /// </summary>
        /// <param name="portalSettings"></param>
        /// <param name="theme"></param>
        /// <param name="parseType"></param>
        public void ParseTheme(PortalSettings portalSettings, ThemeInfo theme, ParseType parseType)
        {
            var strRootPath = Null.NullString;

            switch (theme.Level)
            {
            case ThemeLevel.Global:     //global
                strRootPath = Globals.HostMapPath;
                break;

            case ThemeLevel.Site:     //local
                strRootPath = portalSettings.HomeDirectoryMapPath;
                break;
            }
            var objSkinFiles = new SkinFileProcessor(strRootPath, theme.Type == ThemeType.Container ? SkinController.RootContainer : SkinController.RootSkin, theme.PackageName);
            var arrSkinFiles = new ArrayList();

            var strFolder = Path.Combine(Globals.ApplicationMapPath, theme.Path);

            if (Directory.Exists(strFolder))
            {
                var arrFiles = Directory.GetFiles(strFolder);
                foreach (var strFile in arrFiles)
                {
                    switch (Path.GetExtension(strFile))
                    {
                    case ".htm":
                    case ".html":
                    case ".css":
                        if (strFile.ToLower().IndexOf(Globals.glbAboutPage.ToLower()) < 0)
                        {
                            arrSkinFiles.Add(strFile);
                        }
                        break;

                    case ".ascx":
                        if (File.Exists(strFile.Replace(".ascx", ".htm")) == false && File.Exists(strFile.Replace(".ascx", ".html")) == false)
                        {
                            arrSkinFiles.Add(strFile);
                        }
                        break;
                    }
                }
            }
            switch (parseType)
            {
            case ParseType.Localized:     //localized
                objSkinFiles.ProcessList(arrSkinFiles, SkinParser.Localized);
                break;

            case ParseType.Portable:     //portable
                objSkinFiles.ProcessList(arrSkinFiles, SkinParser.Portable);
                break;
            }
        }
        private string ParseSkinPackage(string strType, string strRoot, string strName, string strFolder, string strParse)
        {
            var strRootPath = Null.NullString;

            switch (strType)
            {
            case "G":                     //global
                strRootPath = Request.MapPath(Globals.HostPath);
                break;

            case "L":                     //local
                strRootPath = Request.MapPath(PortalSettings.HomeDirectory);
                break;
            }
            var objSkinFiles = new SkinFileProcessor(strRootPath, strRoot, strName);
            var arrSkinFiles = new ArrayList();

            if (Directory.Exists(strFolder))
            {
                var arrFiles = Directory.GetFiles(strFolder);
                foreach (var strFile in arrFiles)
                {
                    switch (Path.GetExtension(strFile))
                    {
                    case ".htm":
                    case ".html":
                    case ".css":
                        if (strFile.ToLower().IndexOf(Globals.glbAboutPage.ToLower()) < 0)
                        {
                            arrSkinFiles.Add(strFile);
                        }
                        break;

                    case ".ascx":
                        if (File.Exists(strFile.Replace(".ascx", ".htm")) == false && File.Exists(strFile.Replace(".ascx", ".html")) == false)
                        {
                            arrSkinFiles.Add(strFile);
                        }
                        break;
                    }
                }
            }
            switch (strParse)
            {
            case "L":                     //localized
                return(objSkinFiles.ProcessList(arrSkinFiles, SkinParser.Localized));

            case "P":                     //portable
                return(objSkinFiles.ProcessList(arrSkinFiles, SkinParser.Portable));
            }
            return(Null.NullString);
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The Install method installs the skin component
        /// </summary>
        public override void Install()
        {
            bool bAdd = Null.NullBoolean;

            try
            {
                //Attempt to get the Skin Package
                TempSkinPackage = SkinController.GetSkinPackage(SkinPackage.PortalID, SkinPackage.SkinName, SkinType);
                if (TempSkinPackage == null)
                {
                    bAdd = true;
                    SkinPackage.PackageID = Package.PackageID;
                }
                else
                {
                    SkinPackage.SkinPackageID = TempSkinPackage.SkinPackageID;
                    if (TempSkinPackage.PackageID != Package.PackageID)
                    {
                        Completed = false;
                        Log.AddFailure(Util.SKIN_Installed);
                        return;
                    }
                    else
                    {
                        SkinPackage.PackageID = TempSkinPackage.PackageID;
                    }
                }
                SkinPackage.SkinType = SkinType;
                if (bAdd)
                {
                    //Add new skin package
                    SkinPackage.SkinPackageID = SkinController.AddSkinPackage(SkinPackage);
                }
                else
                {
                    //Update skin package
                    SkinController.UpdateSkinPackage(SkinPackage);
                }
                Log.AddInfo(string.Format(Util.SKIN_Registered, SkinPackage.SkinName));

                //install (copy the files) by calling the base class
                base.Install();

                //process the list of skin files
                if (SkinFiles.Count > 0)
                {
                    Log.StartJob(Util.SKIN_BeginProcessing);
                    string strMessage = Null.NullString;
                    var    NewSkin    = new SkinFileProcessor(RootPath, SkinRoot, SkinPackage.SkinName);
                    foreach (string skinFile in SkinFiles)
                    {
                        strMessage += NewSkin.ProcessFile(skinFile, SkinParser.Portable);
                        skinFile.Replace(Globals.HostMapPath + "\\", "[G]");
                        switch (Path.GetExtension(skinFile))
                        {
                        case ".htm":
                            SkinController.AddSkin(SkinPackage.SkinPackageID, skinFile.Replace("htm", "ascx"));
                            break;

                        case ".html":
                            SkinController.AddSkin(SkinPackage.SkinPackageID, skinFile.Replace("html", "ascx"));
                            break;

                        case ".ascx":
                            SkinController.AddSkin(SkinPackage.SkinPackageID, skinFile);
                            break;
                        }
                    }
                    Array arrMessage = strMessage.Split(new[] { "<br />" }, StringSplitOptions.None);
                    foreach (string strRow in arrMessage)
                    {
                        Log.AddInfo(HtmlUtils.StripTags(strRow, true));
                    }
                    Log.EndJob(Util.SKIN_EndProcessing);
                }
                Completed = true;
            }
            catch (Exception ex)
            {
                Log.AddFailure(ex);
            }
        }