public static void DeleteLanguagePack(LanguagePackInfo languagePack)
 {
     if (languagePack.PackageType == LanguagePackType.Core)
     {
         Locale language = LocaleController.Instance.GetLocale(languagePack.LanguageID);
         if (language != null)
         {
             Localization.DeleteLanguage(language);
         }
     }
     DataProvider.Instance().DeleteLanguagePack(languagePack.LanguagePackID);
     var objEventLog = new EventLogController();
     objEventLog.AddLog(languagePack, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.LANGUAGEPACK_DELETED);
 }
        public static void DeleteLanguagePack(LanguagePackInfo languagePack)
        {
            if (languagePack.PackageType == LanguagePackType.Core)
            {
                Locale language = LocaleController.Instance.GetLocale(languagePack.LanguageID);
                if (language != null)
                {
                    Localization.DeleteLanguage(language);
                }
            }
            DataProvider.Instance().DeleteLanguagePack(languagePack.LanguagePackID);
            var objEventLog = new EventLogController();

            objEventLog.AddLog(languagePack, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.LANGUAGEPACK_DELETED);
        }
        public static void DeleteLanguagePack(LanguagePackInfo languagePack)
        {
            // fix DNN-26330     Removing a language pack extension removes the language
            // we should not delete language when deleting language pack, as there is just a loose relationship

            // if (languagePack.PackageType == LanguagePackType.Core)
            // {
            //    Locale language = LocaleController.Instance.GetLocale(languagePack.LanguageID);
            //    if (language != null)
            //    {
            //        Localization.DeleteLanguage(language);
            //    }
            // }
            DataProvider.Instance().DeleteLanguagePack(languagePack.LanguagePackID);
            EventLogController.Instance.AddLog(languagePack, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, string.Empty, EventLogController.EventLogType.LANGUAGEPACK_DELETED);
        }
        public static void DeleteLanguagePack(LanguagePackInfo languagePack)
        {
            // fix DNN-26330	 Removing a language pack extension removes the language
            // we should not delete language when deleting language pack, as there is just a loose relationship

            //if (languagePack.PackageType == LanguagePackType.Core)
            //{
            //    Locale language = LocaleController.Instance.GetLocale(languagePack.LanguageID);
            //    if (language != null)
            //    {
            //        Localization.DeleteLanguage(language);
            //    }
            //}

            DataProvider.Instance().DeleteLanguagePack(languagePack.LanguagePackID);
            EventLogController.Instance.AddLog(languagePack, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.LANGUAGEPACK_DELETED);
        }
 public static void SaveLanguagePack(LanguagePackInfo languagePack)
 {
     if (languagePack.LanguagePackID == Null.NullInteger)
     {
         //Add Language Pack
         languagePack.LanguagePackID = DataProvider.Instance().AddLanguagePack(languagePack.PackageID,
                                                                               languagePack.LanguageID,
                                                                               languagePack.DependentPackageID,
                                                                               UserController.Instance.GetCurrentUserInfo().UserID);
         EventLogController.Instance.AddLog(languagePack, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.LANGUAGEPACK_CREATED);
     }
     else
     {
         //Update LanguagePack
         DataProvider.Instance().UpdateLanguagePack(languagePack.LanguagePackID,
                                                    languagePack.PackageID,
                                                    languagePack.LanguageID,
                                                    languagePack.DependentPackageID,
                                                    UserController.Instance.GetCurrentUserInfo().UserID);
         EventLogController.Instance.AddLog(languagePack, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.LANGUAGEPACK_UPDATED);
     }
 }
        public static void SaveLanguagePack(LanguagePackInfo languagePack)
        {
            if (languagePack.LanguagePackID == Null.NullInteger)
            {
				//Add Language Pack
                languagePack.LanguagePackID = DataProvider.Instance().AddLanguagePack(languagePack.PackageID,
                                                                                      languagePack.LanguageID,
                                                                                      languagePack.DependentPackageID,
                                                                                      UserController.Instance.GetCurrentUserInfo().UserID);
                EventLogController.Instance.AddLog(languagePack, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.LANGUAGEPACK_CREATED);
            }
            else
            {
				//Update LanguagePack
                DataProvider.Instance().UpdateLanguagePack(languagePack.LanguagePackID,
                                                           languagePack.PackageID,
                                                           languagePack.LanguageID,
                                                           languagePack.DependentPackageID,
                                                           UserController.Instance.GetCurrentUserInfo().UserID);
                EventLogController.Instance.AddLog(languagePack, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.LANGUAGEPACK_UPDATED);
            }
        }
        public LanguagePackWriter(PackageInfo package) : base(package)
        {
            _LanguagePack = LanguagePackController.GetLanguagePackByPackage(package.PackageID);
            if (LanguagePack != null)
            {
                _Language = LocaleController.Instance.GetLocale(_LanguagePack.LanguageID);
                if (LanguagePack.PackageType == LanguagePackType.Core)
                {
                    BasePath = Null.NullString;
                }
                else
                {
					//Get the BasePath of the Dependent Package
                    PackageInfo dependendentPackage = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == LanguagePack.DependentPackageID);
                    PackageWriterBase dependentPackageWriter = PackageWriterFactory.GetWriter(dependendentPackage);
                    BasePath = dependentPackageWriter.BasePath;
                }
            }
            else
            {
                BasePath = Null.NullString;
            }
        }
        private void ReadLegacyManifest(XPathNavigator manifestNav)
        {
            string fileName = Null.NullString;
            string filePath = Null.NullString;
            string sourceFileName = Null.NullString;
            string resourcetype = Null.NullString;
            string moduleName = Null.NullString;
            foreach (XPathNavigator fileNav in manifestNav.Select("Files/File"))
            {
                fileName = Util.ReadAttribute(fileNav, "FileName").ToLowerInvariant();
                resourcetype = Util.ReadAttribute(fileNav, "FileType");
                moduleName = Util.ReadAttribute(fileNav, "ModuleName").ToLowerInvariant();
                sourceFileName = Path.Combine(resourcetype, Path.Combine(moduleName, fileName));
                string extendedExtension = "." + Language.Code.ToLowerInvariant() + ".resx";
                switch (resourcetype)
                {
                    case "GlobalResource":
                        filePath = "App_GlobalResources";
                        _IsCore = true;
                        break;
                    case "ControlResource":
                        filePath = "Controls\\App_LocalResources";
                        break;
                    case "AdminResource":
                        _IsCore = true;
                        switch (moduleName)
                        {
                            case "authentication":
                                filePath = "DesktopModules\\Admin\\Authentication\\App_LocalResources";
                                break;
                            case "controlpanel":
                                filePath = "Admin\\ControlPanel\\App_LocalResources";
                                break;
                            case "files":
                                filePath = "DesktopModules\\Admin\\FileManager\\App_LocalResources";
                                break;
                            case "host":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "authentication.ascx":
                                        filePath = "";
                                        break;
                                    case "friendlyurls.ascx":
                                        filePath = "DesktopModules\\Admin\\HostSettings\\App_LocalResources";
                                        break;
                                    case "hostsettings.ascx":
                                        filePath = "DesktopModules\\Admin\\HostSettings\\App_LocalResources";
                                        break;
                                    case "requestfilters.ascx":
                                        filePath = "DesktopModules\\Admin\\HostSettings\\App_LocalResources";
                                        break;
                                    case "solutions.ascx":
                                        filePath = "DesktopModules\\Admin\\Solutions\\App_LocalResources";
                                        break;
                                }
                                break;
                            case "lists":
                                filePath = "DesktopModules\\Admin\\Lists\\App_LocalResources";
                                break;
                            case "localization":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "languageeditor.ascx":
                                        filePath = "DesktopModules\\Admin\\Extensions\\Editors\\App_LocalResources";
                                        break;
                                    case "languageeditorext.ascx":
                                        filePath = "DesktopModules\\Admin\\Extensions\\Editors\\App_LocalResources";
                                        break;
                                    case "timezoneeditor.ascx":
                                        filePath = "DesktopModules\\Admin\\Extensions\\Editors\\App_LocalResources";
                                        break;
                                    case "resourceverifier.ascx":
                                        filePath = "DesktopModules\\Admin\\Extensions\\Editors\\App_LocalResources";
                                        break;
                                    default:
                                        filePath = "";
                                        break;
                                }
                                break;
                            case "log":
                                filePath = "DesktopModules\\Admin\\SiteLog\\App_LocalResources";
                                break;
                            case "logging":
                                filePath = "DesktopModules\\Admin\\LogViewer\\App_LocalResources";
                                break;
                            case "moduledefinitions":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "editmodulecontrol.ascx":
                                        filePath = "DesktopModules\\Admin\\Extensions\\Editors\\App_LocalResources";
                                        break;
                                    case "importmoduledefinition.ascx":
                                        filePath = "DesktopModules\\Admin\\Extensions\\Editors\\App_LocalResources";
                                        break;
                                    case "timezoneeditor.ascx":
                                        filePath = "DesktopModules\\Admin\\Extensions\\Editors\\App_LocalResources";
                                        break;
                                    default:
                                        filePath = "";
                                        break;
                                }
                                break;
                            case "modules":
                                filePath = "Admin\\Modules\\App_LocalResources";
                                break;
                            case "packages":
                                filePath = "DesktopModules\\Admin\\Extensions\\App_LocalResources";
                                break;
                            case "portal":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "editportalalias.ascx":
                                        filePath = "DesktopModules\\Admin\\Portals\\App_LocalResources";
                                        break;
                                    case "portalalias.ascx":
                                        filePath = "DesktopModules\\Admin\\Portals\\App_LocalResources";
                                        break;
                                    case "portals.ascx":
                                        filePath = "DesktopModules\\Admin\\Portals\\App_LocalResources";
                                        break;
                                    case "privacy.ascx":
                                        filePath = "Admin\\Portal\\App_LocalResources";
                                        break;
                                    case "signup.ascx":
                                        filePath = "DesktopModules\\Admin\\Portals\\App_LocalResources";
                                        break;
                                    case "sitesettings.ascx":
                                        filePath = "DesktopModules\\Admin\\Portals\\App_LocalResources";
                                        break;
                                    case "sitewizard.ascx":
                                        filePath = "DesktopModules\\Admin\\SiteWizard\\App_LocalResources";
                                        break;
                                    case "sql.ascx":
                                        filePath = "DesktopModules\\Admin\\SQL\\App_LocalResources";
                                        break;
                                    case "systemmessages.ascx":
                                        filePath = "";
                                        break;
                                    case "template.ascx":
                                        filePath = "DesktopModules\\Admin\\Portals\\App_LocalResources";
                                        break;
                                    case "terms.ascx":
                                        filePath = "Admin\\Portal\\App_LocalResources";
                                        break;
                                }
                                break;
                            case "scheduling":
                                filePath = "DesktopModules\\Admin\\Scheduler\\App_LocalResources";
                                break;
                            case "search":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "inputsettings.ascx":
                                        filePath = "DesktopModules\\Admin\\SearchInput\\App_LocalResources";
                                        break;
                                    case "resultssettings.ascx":
                                        filePath = "DesktopModules\\Admin\\SearchResults\\App_LocalResources";
                                        break;
                                    case "searchadmin.ascx":
                                        filePath = "DesktopModules\\Admin\\SearchAdmin\\App_LocalResources";
                                        break;
                                    case "searchinput.ascx":
                                        filePath = "DesktopModules\\Admin\\SearchInput\\App_LocalResources";
                                        break;
                                    case "searchresults.ascx":
                                        filePath = "DesktopModules\\Admin\\SearchResults\\App_LocalResources";
                                        break;
                                }
                                break;
                            case "security":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "accessdenied.ascx":
                                        filePath = "Admin\\Security\\App_LocalResources";
                                        break;
                                    case "authenticationsettings.ascx":
                                        filePath = "";
                                        break;
                                    case "editgroups.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "editroles.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "register.ascx":
                                        filePath = "";
                                        break;
                                    case "roles.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "securityroles.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "sendpassword.ascx":
                                        filePath = "Admin\\Security\\App_LocalResources";
                                        break;
                                    case "signin.ascx":
                                        filePath = "";
                                        break;
                                }
                                break;
                            case "skins":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "attributes.ascx":
                                        filePath = "DesktopModules\\Admin\\SkinDesigner\\App_LocalResources";
                                        break;
                                    case "editskins.ascx":
                                        filePath = "DesktopModules\\Admin\\Extensions\\Editors\\App_LocalResources";
                                        break;
                                    default:
                                        filePath = "Admin\\Skins\\App_LocalResources";
                                        break;
                                }
                                break;
                            case "syndication":
                                filePath = "DesktopModules\\Admin\\FeedExplorer\\App_LocalResources";
                                break;
                            case "tabs":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "export.ascx":
                                        filePath = "Admin\\Tabs\\App_LocalResources";
                                        break;
                                    case "import.ascx":
                                        filePath = "Admin\\Tabs\\App_LocalResources";
                                        break;
                                    case "managetabs.ascx":
                                        filePath = "DesktopModules\\Admin\\Tabs\\App_LocalResources";
                                        break;
                                    case "recyclebin.ascx":
                                        filePath = "DesktopModules\\Admin\\RecycleBin\\App_LocalResources";
                                        break;
                                    case "tabs.ascx":
                                        filePath = "DesktopModules\\Admin\\Tabs\\App_LocalResources";
                                        break;
                                }
                                break;
                            case "users":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "bulkemail.ascx":
                                        filePath = "DesktopModules\\Admin\\Newsletters\\App_LocalResources";
                                        fileName = "Newsletter.ascx" + extendedExtension;
                                        break;
                                    case "editprofiledefinition.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "manageusers.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "memberservices.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "membership.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "password.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "profile.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "profiledefinitions.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "user.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "users.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "usersettings.ascx":
                                        filePath = "DesktopModules\\Admin\\Security\\App_LocalResources";
                                        break;
                                    case "viewprofile.ascx":
                                        filePath = "Admin\\Users\\App_LocalResources";
                                        break;
                                }
                                break;
                            case "vendors":
                                switch (fileName.Replace(extendedExtension, ""))
                                {
                                    case "adsense.ascx":
                                        filePath = "";
                                        break;
                                    case "editadsense.ascx":
                                        filePath = "";
                                        break;
                                    case "affiliates.ascx":
                                        filePath = "DesktopModules\\Admin\\Vendors\\App_LocalResources";
                                        break;
                                    case "banneroptions.ascx":
                                        filePath = "DesktopModules\\Admin\\Banners\\App_LocalResources";
                                        break;
                                    case "banners.ascx":
                                        filePath = "DesktopModules\\Admin\\Vendors\\App_LocalResources";
                                        break;
                                    case "displaybanners.ascx":
                                        filePath = "DesktopModules\\Admin\\Banners\\App_LocalResources";
                                        break;
                                    case "editaffiliate.ascx":
                                        filePath = "DesktopModules\\Admin\\Vendors\\App_LocalResources";
                                        break;
                                    case "editbanner.ascx":
                                        filePath = "DesktopModules\\Admin\\Vendors\\App_LocalResources";
                                        break;
                                    case "editvendors.ascx":
                                        filePath = "DesktopModules\\Admin\\Vendors\\App_LocalResources";
                                        break;
                                    case "vendors.ascx":
                                        filePath = "DesktopModules\\Admin\\Vendors\\App_LocalResources";
                                        break;
                                }
                                break;
                        }
                        break;
                    case "LocalResource":
                        filePath = Path.Combine("DesktopModules", Path.Combine(moduleName, "App_LocalResources"));
                        //Two assumptions are made here
                        //1. Core files appear in the package before extension files
                        //2. Module packages only include one module
                        if (!_IsCore && _LanguagePack == null)
                        {
							//Check if language is installed
                            Locale locale = LocaleController.Instance.GetLocale(_Language.Code);
                            if (locale == null)
                            {
                                LegacyError = "CoreLanguageError";
                            }
                            else
                            {
								//Attempt to figure out the Extension
                                foreach (KeyValuePair<int, DesktopModuleInfo> kvp in
                                    DesktopModuleController.GetDesktopModules(Null.NullInteger))
                                {
                                    if (kvp.Value.FolderName.ToLowerInvariant() == moduleName)
                                    {
										//Found Module - Get Package
                                        var dependentPackage = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.PackageID == kvp.Value.PackageID);
                                        Package.Name += "_" + dependentPackage.Name;
                                        Package.FriendlyName += " " + dependentPackage.FriendlyName;
                                        _LanguagePack = new LanguagePackInfo();
                                        _LanguagePack.DependentPackageID = dependentPackage.PackageID;
                                        _LanguagePack.LanguageID = locale.LanguageId;
                                        break;
                                    }
                                }
                                if (_LanguagePack == null)
                                {
                                    LegacyError = "DependencyError";
                                }
                            }
                        }
                        break;
                    case "ProviderResource":
                        filePath = Path.Combine("Providers", Path.Combine(moduleName, "App_LocalResources"));
                        break;
                    case "InstallResource":
                        filePath = "Install\\App_LocalResources";
                        break;
                }
                if (!string.IsNullOrEmpty(filePath))
                {
                    AddFile(Path.Combine(filePath, fileName), sourceFileName);
                }
            }
        }
        public static void ProcessLegacyLanguages()
        {
            string filePath = Globals.ApplicationMapPath + Localization.Localization.SupportedLocalesFile.Substring(1).Replace("/", "\\");
            if (File.Exists(filePath))
            {
                var doc = new XPathDocument(filePath);

                //Check for Browser and Url settings
                XPathNavigator browserNav = doc.CreateNavigator().SelectSingleNode("root/browserDetection");
                if (browserNav != null)
                {
                    HostController.Instance.Update("EnableBrowserLanguage", Util.ReadAttribute(browserNav, "enabled", false, null, Null.NullString, "true"));
                }
                XPathNavigator urlNav = doc.CreateNavigator().SelectSingleNode("root/languageInUrl");
                if (urlNav != null)
                {
                    HostController.Instance.Update("EnableUrlLanguage", Util.ReadAttribute(urlNav, "enabled", false, null, Null.NullString, "true"));
                }
				
                //Process each language
                foreach (XPathNavigator nav in doc.CreateNavigator().Select("root/language"))
                {
                    if (nav.NodeType != XPathNodeType.Comment)
                    {
                        var language = new Locale();
                        language.Text = Util.ReadAttribute(nav, "name");
                        language.Code = Util.ReadAttribute(nav, "key");
                        language.Fallback = Util.ReadAttribute(nav, "fallback");
                        //Save Language
                        Localization.Localization.SaveLanguage(language);
                        if (language.Code != Localization.Localization.SystemLocale)
                        {
                            //Create a Package
                            var package = new PackageInfo(new InstallerInfo())
                                {
                                    Name = language.Text,
                                    FriendlyName = language.Text,
                                    Description = Null.NullString,
                                    Version = new Version(1, 0, 0),
                                    PackageType = "CoreLanguagePack",
                                    License = Util.PACKAGE_NoLicense
                                };

                            //Create a LanguagePackWriter
                            var packageWriter = new LanguagePackWriter(language, package);

                            //Save the manifest
                            package.Manifest = packageWriter.WriteManifest(true);

                            //Save Package
                            PackageController.Instance.SaveExtensionPackage(package);

                            var languagePack = new LanguagePackInfo
                                {
                                    LanguageID = language.LanguageId,
                                    PackageID = package.PackageID,
                                    DependentPackageID = -2
                                };
                            LanguagePackController.SaveLanguagePack(languagePack);
                        }
                    }
                }
            }
			
            //Process Portal Locales files
            foreach (PortalInfo portal in PortalController.Instance.GetPortals())
            {
                int portalID = portal.PortalID;
                filePath = string.Format(Globals.ApplicationMapPath + Localization.Localization.ApplicationResourceDirectory.Substring(1).Replace("/", "\\") + "\\Locales.Portal-{0}.xml", portalID);

                if (File.Exists(filePath))
                {
                    var doc = new XPathDocument(filePath);

                    //Check for Browser and Url settings
                    XPathNavigator browserNav = doc.CreateNavigator().SelectSingleNode("locales/browserDetection");
                    if (browserNav != null)
                    {
                        PortalController.UpdatePortalSetting(portalID, "EnableBrowserLanguage", Util.ReadAttribute(browserNav, "enabled", false, null, Null.NullString, "true"));
                    }
                    XPathNavigator urlNav = doc.CreateNavigator().SelectSingleNode("locales/languageInUrl");
                    if (urlNav != null)
                    {
                        PortalController.UpdatePortalSetting(portalID, "EnableUrlLanguage", Util.ReadAttribute(urlNav, "enabled", false, null, Null.NullString, "true"));
                    }
                    foreach (Locale installedLanguage in LocaleController.Instance.GetLocales(Null.NullInteger).Values)
                    {
                        string code = installedLanguage.Code;
                        bool bFound = false;

                        //Check if this language is "inactive"
                        foreach (XPathNavigator inactiveNav in doc.CreateNavigator().Select("locales/inactive/locale"))
                        {
                            if (inactiveNav.Value == code)
                            {
                                bFound = true;
                                break;
                            }
                        }
                        if (!bFound)
                        {
							//Language is enabled - add to portal
                            Localization.Localization.AddLanguageToPortal(portalID, installedLanguage.LanguageId, false);
                        }
                    }
                }
                else
                {
                    foreach (Locale installedLanguage in LocaleController.Instance.GetLocales(Null.NullInteger).Values)
                    {
						//Language is enabled - add to portal
                        Localization.Localization.AddLanguageToPortal(portalID, installedLanguage.LanguageId, false);
                    }
                }
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The Install method installs the language component
        /// </summary>
        /// <history>
        /// 	[cnurse]	02/11/2008  created
        /// </history>
        /// -----------------------------------------------------------------------------
        public override void Install()
        {
            if (LanguagePackType == LanguagePackType.Core || LanguagePack.DependentPackageID > 0)
            {
                try
                {
                    //Attempt to get the LanguagePack
                    InstalledLanguagePack = LanguagePackController.GetLanguagePackByPackage(Package.PackageID);
                    if (InstalledLanguagePack != null)
                    {
                        LanguagePack.LanguagePackID = InstalledLanguagePack.LanguagePackID;
                    }

                    //Attempt to get the Locale
                    TempLanguage = LocaleController.Instance.GetLocale(Language.Code);
                    if (TempLanguage != null)
                    {
                        Language.LanguageId = TempLanguage.LanguageId;
                    }
                    if (LanguagePack.PackageType == LanguagePackType.Core)
                    {
                        //Update language
                        Localization.Localization.SaveLanguage(Language);
                    }

                    //Set properties for Language Pack
                    LanguagePack.PackageID = Package.PackageID;
                    LanguagePack.LanguageID = Language.LanguageId;

                    //Update LanguagePack
                    LanguagePackController.SaveLanguagePack(LanguagePack);

                    Log.AddInfo(string.Format(Util.LANGUAGE_Registered, Language.Text));

                    //install (copy the files) by calling the base class
                    base.Install();
                }
                catch (Exception ex)
                {
                    Log.AddFailure(ex);
                }
            }
            else
            {
                Completed = true;
                Skipped = true;
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// The ReadCustomManifest method reads the custom manifest items
        /// </summary>
        /// <param name="nav">The XPathNavigator representing the node</param>
        /// <history>
        /// 	[cnurse]	08/22/2007  created
        /// </history>
        /// -----------------------------------------------------------------------------
        protected override void ReadCustomManifest(XPathNavigator nav)
        {
            Language = new Locale();
            LanguagePack = new LanguagePackInfo();

            //Get the Skin name
            Language.Code = Util.ReadElement(nav, "code");
            Language.Text = Util.ReadElement(nav, "displayName");
            Language.Fallback = Util.ReadElement(nav, "fallback");

            if (LanguagePackType == LanguagePackType.Core)
            {
                LanguagePack.DependentPackageID = -2;
            }
            else
            {
                string packageName = Util.ReadElement(nav, "package");
                PackageInfo package = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.Name == packageName);
                if (package != null)
                {
                    LanguagePack.DependentPackageID = package.PackageID;
                }
            }
			
            //Call base class
            base.ReadCustomManifest(nav);
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// wizNewExtension_NextButtonClick when the next Button is clicked.  It provides
        ///	a mechanism for cancelling the page change if certain conditions aren't met.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// 	[cnurse]	08/25/2008	created
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void wizNewExtension_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            switch (e.CurrentStepIndex)
            {
                case 0:
                    if (extensionForm.IsValid)
                    {
                        var newPackage = extensionForm.DataSource as PackageInfo;
                        PackageInfo tmpPackage = PackageController.Instance.GetExtensionPackage(Null.NullInteger, p => p.Name == newPackage.Name);
                        if (tmpPackage == null)
                        {
                            switch (Mode)
                            {
                                case "All":
                                    newPackage.PackageType = cboExtensionType.SelectedValue;
                                    break;
                                default:
                                    newPackage.PackageType = Mode;
                                    break;
                            }
                            PackageController.Instance.SaveExtensionPackage(newPackage);

                            Locale locale;
                            LanguagePackInfo languagePack;
                            switch (newPackage.PackageType)
                            {
                                case "Auth_System":
                                    //Create a new Auth System
                                    var authSystem = new AuthenticationInfo
                                    {
                                        AuthenticationType = newPackage.Name,
                                        IsEnabled = Null.NullBoolean,
                                        PackageID = newPackage.PackageID
                                    };
                                    AuthenticationController.AddAuthentication(authSystem);
                                    break;
                                case "Container":
                                case "Skin":
                                    var skinPackage = new SkinPackageInfo
                                    {
                                        SkinName = newPackage.Name,
                                        PackageID = newPackage.PackageID,
                                        SkinType = newPackage.PackageType
                                    };
                                    SkinController.AddSkinPackage(skinPackage);
                                    break;
                                case "CoreLanguagePack":
                                    locale = LocaleController.Instance.GetLocale(PortalController.Instance.GetCurrentPortalSettings().DefaultLanguage);
                                    languagePack = new LanguagePackInfo
                                    {
                                        PackageID = newPackage.PackageID,
                                        LanguageID = locale.LanguageId,
                                        DependentPackageID = -2
                                    };
                                    LanguagePackController.SaveLanguagePack(languagePack);
                                    break;
                                case "ExtensionLanguagePack":
                                    locale = LocaleController.Instance.GetLocale(PortalController.Instance.GetCurrentPortalSettings().DefaultLanguage);
                                    languagePack = new LanguagePackInfo
                                    {
                                        PackageID = newPackage.PackageID,
                                        LanguageID = locale.LanguageId,
                                        DependentPackageID = Null.NullInteger
                                    };
                                    LanguagePackController.SaveLanguagePack(languagePack);
                                    break;
                                case "Module":
                                    //Create a new DesktopModule
                                    var desktopModule = new DesktopModuleInfo
                                    {
                                        PackageID = newPackage.PackageID,
                                        ModuleName = newPackage.Name,
                                        FriendlyName = newPackage.FriendlyName,
                                        FolderName = newPackage.Name,
                                        Description = newPackage.Description,
                                        Version = newPackage.Version.ToString(3),
                                        SupportedFeatures = 0
                                    };
                                    int desktopModuleId = DesktopModuleController.SaveDesktopModule(desktopModule, false, true);
                                    if (desktopModuleId > Null.NullInteger)
                                    {
                                        DesktopModuleController.AddDesktopModuleToPortals(desktopModuleId);
                                    }
                                    break;
                                case "SkinObject":
                                    var skinControl = new SkinControlInfo { PackageID = newPackage.PackageID, ControlKey = newPackage.Name };
                                    SkinControlController.SaveSkinControl(skinControl);
                                    break;
                            }

                        }
                        else
                        {
                            e.Cancel = true;
                            lblError.Text = string.Format(Localization.GetString("DuplicateName", LocalResourceFile), newPackage.Name);
                        	lblError.Visible = true;
                        }
                    }
                    if (PackageEditor != null && PackageID > Null.NullInteger)
                    {
                        BindPackageEditor();
                    }
                    break;
                case 1:
                    if (PackageEditor != null)
                    {
                        PackageEditor.UpdatePackage();
                    }
                    break;
                case 2:
                    if (ownerForm.IsValid)
                    {
                        PackageController.Instance.SaveExtensionPackage(ownerForm.DataSource as PackageInfo);
                    }
                    Response.Redirect(Globals.NavigateURL(), true);
                    break;
            }
        }
 /// -----------------------------------------------------------------------------
 /// <summary>
 /// Constructs the LanguageComponentWriter
 /// </summary>
 /// <param name="languagePack">Language Package info.</param>
 /// <param name="basePath">Base Path.</param>
 /// <param name="files">A Dictionary of files</param>
 /// <param name="package">Package Info.</param>
 /// <history>
 /// 	[cnurse]	02/08/2008	created
 /// </history>
 /// -----------------------------------------------------------------------------
 public LanguageComponentWriter(LanguagePackInfo languagePack, string basePath, Dictionary<string, InstallFile> files, PackageInfo package) : base(basePath, files, package)
 {
     _Language = LocaleController.Instance.GetLocale(languagePack.LanguageID);
     _PackageType = languagePack.PackageType;
     _DependentPackageID = languagePack.DependentPackageID;
 }
        private void CreatePackage(PackageInfo package, int dependentPackageID, string basePath, string fileName, bool createZip)
        {
            string manifest;

            Locale language = LocaleController.Instance.GetLocale(cboLanguage.SelectedValue);
            var languagePack = new LanguagePackInfo();
            languagePack.LanguageID = language.LanguageId;
            languagePack.DependentPackageID = dependentPackageID;

            if (dependentPackageID == -2)
            {
                package.PackageType = "CoreLanguagePack";
            }
            else
            {
                package.PackageType = "ExtensionLanguagePack";
            }
            package.Name += " " + language.Text;
            package.FriendlyName += " " + language.Text;

            packageWriter = PackageWriterFactory.GetWriter(package) as Services.Installer.Writers.LanguagePackWriter;
            packageWriter.Language = language;
            packageWriter.LanguagePack = languagePack;
            packageWriter.BasePath = basePath;
            packageWriter.GetFiles(false);

            if (packageWriter.Files.Count > 0)
            {
                _IsPackCreated = true;
                if (createZip)
                {
                    manifest = packageWriter.WriteManifest(true);
                    fileName = fileName + "." + package.Version.ToString(3) + "." + language.Code + ".zip";
                    packageWriter.CreatePackage(fileName, package.Name + ".dnn", manifest, true);
                }
                else
                {
                    packageWriter.BasePath = "";
                    _Manifest += packageWriter.WriteManifest(true);
                    foreach (KeyValuePair<string, InstallFile> kvp in packageWriter.Files)
                    {
                        _Files[kvp.Key] = kvp.Value;
                    }
                }
            }
            else
            {
                _IsPackCreated = false;
            }
        }
        public static int AddPackage(PackageInfo package, bool includeDetail)
        {
            int packageID = provider.AddPackage(package.PortalID,
                                                package.Name,
                                                package.FriendlyName,
                                                package.Description,
                                                package.PackageType,
                                                package.Version.ToString(3),
                                                package.License,
                                                package.Manifest,
                                                package.Owner,
                                                package.Organization,
                                                package.Url,
                                                package.Email,
                                                package.ReleaseNotes,
                                                package.IsSystemPackage,
                                                UserController.GetCurrentUserInfo().UserID,
                                                package.FolderName,
                                                package.IconFile);
            var objEventLog = new EventLogController();
            objEventLog.AddLog(package, PortalController.GetCurrentPortalSettings(), UserController.GetCurrentUserInfo().UserID, "", EventLogController.EventLogType.PACKAGE_CREATED);
            if (includeDetail)
            {
                Locale locale;
                LanguagePackInfo languagePack;
                switch (package.PackageType)
                {
                    case "Auth_System":
                        //Create a new Auth System
                        var authSystem = new AuthenticationInfo();
                        authSystem.AuthenticationType = package.Name;
                        authSystem.IsEnabled = Null.NullBoolean;
                        authSystem.PackageID = packageID;
                        AuthenticationController.AddAuthentication(authSystem);
                        break;
                    case "Container":
                    case "Skin":
                        var skinPackage = new SkinPackageInfo();
                        skinPackage.SkinName = package.Name;
                        skinPackage.PackageID = packageID;
                        skinPackage.SkinType = package.PackageType;
                        SkinController.AddSkinPackage(skinPackage);
                        break;
                    case "CoreLanguagePack":
                        locale = LocaleController.Instance.GetLocale(PortalController.GetCurrentPortalSettings().DefaultLanguage);
                        languagePack = new LanguagePackInfo();
                        languagePack.PackageID = packageID;
                        languagePack.LanguageID = locale.LanguageId;
                        languagePack.DependentPackageID = -2;
                        LanguagePackController.SaveLanguagePack(languagePack);
                        break;
                    case "ExtensionLanguagePack":
                        locale = LocaleController.Instance.GetLocale(PortalController.GetCurrentPortalSettings().DefaultLanguage);
                        languagePack = new LanguagePackInfo();
                        languagePack.PackageID = packageID;
                        languagePack.LanguageID = locale.LanguageId;
                        languagePack.DependentPackageID = Null.NullInteger;
                        LanguagePackController.SaveLanguagePack(languagePack);
                        break;
                    case "Module":
                        //Create a new DesktopModule
                        var desktopModule = new DesktopModuleInfo();
                        desktopModule.PackageID = packageID;
                        desktopModule.ModuleName = package.Name;
                        desktopModule.FriendlyName = package.FriendlyName;
                        desktopModule.FolderName = package.Name;
                        desktopModule.Description = package.Description;
                        desktopModule.Version = package.Version.ToString(3);
                        desktopModule.SupportedFeatures = 0;
                        int desktopModuleId = DesktopModuleController.SaveDesktopModule(desktopModule, false, true);
                        if (desktopModuleId > Null.NullInteger)
                        {
                            DesktopModuleController.AddDesktopModuleToPortals(desktopModuleId);
                        }
                        break;
                    case "SkinObject":
                        var skinControl = new SkinControlInfo();
                        skinControl.PackageID = packageID;
                        skinControl.ControlKey = package.Name;
                        SkinControlController.SaveSkinControl(skinControl);
                        break;
                }
            }

			DataCache.ClearPackagesCache(package.PortalID);
            return packageID;
        }