Exemple #1
0
        protected void SelectStarterKitDesign(object sender, EventArgs e)
        {
            if (((Button)sender).CommandName == "apply")
            {
                Skinning.ActivateAsCurrentSkin(Skin.CreateFromName(((Button)sender).CommandArgument));
                this.Page.Response.Redirect(library.NiceUrl(int.Parse(UmbracoContext.Current.PageId.ToString())) + "?umbSkinning=true");
            }
            else if (((Button)sender).CommandName == "remove")
            {
                Template template = new Template(Node.GetCurrent().template);
                Skinning.RollbackSkin(template.Id);
                this.Page.Response.Redirect(library.NiceUrl(int.Parse(UmbracoContext.Current.PageId.ToString())) + "?umbSkinning=true");
            }
            else
            {
                Guid guid = new Guid(((Button)sender).CommandArgument);

                InstalledPackage p = InstalledPackage.GetByGuid(guid.ToString());
                if (p.Data.SkinRepoGuid != null && p.Data.SkinRepoGuid != Guid.Empty && p.Data.SkinRepoGuid.ToString() != repoGuid)
                {
                    this.repo = cms.businesslogic.packager.repositories.Repository.getByGuid(p.Data.SkinRepoGuid.ToString());
                }


                Installer installer = new Installer();
                if (this.repo.HasConnection())
                {
                    Installer installer2 = new Installer();
                    string    tempDir    = installer2.Import(this.repo.fetch(guid.ToString()));
                    installer2.LoadConfig(tempDir);
                    int packageId = installer2.CreateManifest(tempDir, guid.ToString(), this.repoGuid);
                    installer2.InstallFiles(packageId, tempDir);
                    installer2.InstallBusinessLogic(packageId, tempDir);
                    installer2.InstallCleanUp(packageId, tempDir);
                    //NOTE: This seems excessive to have to re-load all content from the database here!?
                    library.RefreshContent();
                    Skinning.ActivateAsCurrentSkin(Skin.CreateFromName(((Button)sender).CommandName));
                    this.Page.Response.Redirect(library.NiceUrl(int.Parse(UmbracoContext.Current.PageId.ToString())) + "?umbSkinning=true");
                }
                else
                {
                    this.ShowConnectionError();
                }
            }
        }
Exemple #2
0
        protected void LoadSkins()
        {
            List <string> skinNames = new List <string>();

            Guid?nullable = Skinning.StarterKitGuid(Node.GetCurrent().template);

            if (nullable.HasValue)
            {
                InstalledPackage p = InstalledPackage.GetByGuid(nullable.Value.ToString());
                if (p.Data.SkinRepoGuid != null && p.Data.SkinRepoGuid != Guid.Empty && p.Data.SkinRepoGuid.ToString() != repoGuid)
                {
                    this.repo = cms.businesslogic.packager.repositories.Repository.getByGuid(p.Data.SkinRepoGuid.ToString());
                }
            }

            if (!(nullable.HasValue && Skinning.HasAvailableSkins(Node.GetCurrent().template)))
            {
                this.pChangeSkin.Visible = false;
            }
            else if (this.repo.HasConnection())
            {
                try
                {
                    var skins = this.repo.Webservice.Skins(nullable.ToString());
                    this.rep_starterKitDesigns.DataSource = skins;
                    this.rep_starterKitDesigns.DataBind();

                    foreach (var s in skins)
                    {
                        if (!skinNames.Contains(s.Text))
                        {
                            skinNames.Add(s.Text);
                        }
                    }
                }
                catch (Exception exception)
                {
                    LogHelper.Error <SkinCustomizer>("An error occurred", exception);
                }
            }
            else
            {
                this.ShowConnectionError();
            }

            //check for local skins

            List <string> localSkins = new List <string>();
            DirectoryInfo dirInfo    = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Masterpages));

            foreach (DirectoryInfo subDur in dirInfo.GetDirectories())
            {
                var skinFile = subDur.GetFiles("skin.xml");

                if (skinFile.Length > 0)
                {
                    string c = Skin.GetSkinNameFromFile(skinFile[0].FullName);

                    if (!skinNames.Contains(c))
                    {
                        localSkins.Add(c);
                    }
                }
            }

            if (localSkins.Count > 0)
            {
                rep_starterKitDesignsLocal.DataSource = localSkins;
                rep_starterKitDesignsLocal.DataBind();
            }
            else
            {
                localSkinsContainer.Visible = false;
            }
        }