Ejemplo n.º 1
0
        public static void ParsePackage(string file, string installPath, Dictionary <string, PackageInfo> packages, List <string> invalidPackages)
        {
            Stream inputStream = new FileStream(file, FileMode.Open, FileAccess.Read);
            var    unzip       = new ZipInputStream(inputStream);

            try
            {
                ZipEntry entry = unzip.GetNextEntry();

                while (entry != null)
                {
                    if (!entry.IsDirectory)
                    {
                        var    fileName  = entry.Name;
                        string extension = Path.GetExtension(fileName);
                        if (extension != null && (extension.ToLower() == ".dnn" || extension.ToLower() == ".dnn5"))
                        {
                            //Manifest
                            var manifestReader = new StreamReader(unzip);
                            var manifest       = manifestReader.ReadToEnd();

                            var package = new PackageInfo {
                                Manifest = manifest
                            };
                            if (!string.IsNullOrEmpty(manifest))
                            {
                                var            doc         = new XPathDocument(new StringReader(manifest));
                                XPathNavigator rootNav     = doc.CreateNavigator().SelectSingleNode("dotnetnuke");
                                string         packageType = String.Empty;
                                if (rootNav.Name == "dotnetnuke")
                                {
                                    packageType = XmlUtils.GetAttributeValue(rootNav, "type");
                                }
                                else if (rootNav.Name.ToLower() == "languagepack")
                                {
                                    packageType = "LanguagePack";
                                }

                                XPathNavigator nav = null;
                                switch (packageType.ToLower())
                                {
                                case "package":
                                    nav = rootNav.SelectSingleNode("packages/package");
                                    break;

                                case "module":
                                case "languagepack":
                                case "skinobject":
                                    nav = Installer.ConvertLegacyNavigator(rootNav, new InstallerInfo()).SelectSingleNode("packages/package");
                                    break;
                                }

                                if (nav != null)
                                {
                                    package.Name            = XmlUtils.GetAttributeValue(nav, "name");
                                    package.PackageType     = XmlUtils.GetAttributeValue(nav, "type");
                                    package.IsSystemPackage = XmlUtils.GetAttributeValueAsBoolean(nav, "isSystem", false);
                                    package.Version         = new Version(XmlUtils.GetAttributeValue(nav, "version"));
                                    package.FriendlyName    = XmlUtils.GetNodeValue(nav, "friendlyName");
                                    if (String.IsNullOrEmpty(package.FriendlyName))
                                    {
                                        package.FriendlyName = package.Name;
                                    }
                                    package.Description = XmlUtils.GetNodeValue(nav, "description");
                                    package.FileName    = file.Replace(installPath + "\\", "");

                                    XPathNavigator foldernameNav;
                                    switch (package.PackageType)
                                    {
                                    case "Module":
                                        //In Dynamics moduels, a component:type=File can have a basePath pointing to the App_Conde folder. This is not a correct FolderName
                                        //To ensure that FolderName is DesktopModules...
                                        var folderNameValue = GetSpecificFolderName(nav, "components/component/files|components/component/resourceFiles", "basePath", "DesktopModules");
                                        if (!String.IsNullOrEmpty(folderNameValue))
                                        {
                                            package.FolderName = folderNameValue.Replace('\\', '/');
                                        }
                                        break;

                                    case "Auth_System":
                                        foldernameNav = nav.SelectSingleNode("components/component/files");
                                        if (foldernameNav != null)
                                        {
                                            package.FolderName = Util.ReadElement(foldernameNav, "basePath").Replace('\\', '/');
                                        }
                                        break;

                                    case "Container":
                                        foldernameNav = nav.SelectSingleNode("components/component/containerFiles");
                                        if (foldernameNav != null)
                                        {
                                            package.FolderName = Globals.glbContainersPath + Util.ReadElement(foldernameNav, "containerName").Replace('\\', '/');
                                        }
                                        break;

                                    case "Skin":
                                        foldernameNav = nav.SelectSingleNode("components/component/skinFiles");
                                        if (foldernameNav != null)
                                        {
                                            package.FolderName = Globals.glbSkinsPath + Util.ReadElement(foldernameNav, "skinName").Replace('\\', '/');
                                        }
                                        break;

                                    default:
                                        break;
                                    }

                                    XPathNavigator iconFileNav = nav.SelectSingleNode("iconFile");
                                    if (package.FolderName != string.Empty && iconFileNav != null)
                                    {
                                        if ((iconFileNav.Value != string.Empty) && (package.PackageType == "Module" || package.PackageType == "Auth_System" || package.PackageType == "Container" || package.PackageType == "Skin"))
                                        {
                                            if (iconFileNav.Value.StartsWith("~/"))
                                            {
                                                package.IconFile = iconFileNav.Value;
                                            }
                                            else if (iconFileNav.Value.StartsWith("DesktopModules", StringComparison.InvariantCultureIgnoreCase))
                                            {
                                                package.IconFile = string.Format("~/{0}", iconFileNav.Value);
                                            }
                                            else
                                            {
                                                package.IconFile = (String.IsNullOrEmpty(package.FolderName) ? "" : package.FolderName + "/") + iconFileNav.Value;
                                                package.IconFile = (!package.IconFile.StartsWith("~/")) ? "~/" + package.IconFile : package.IconFile;
                                            }
                                        }
                                    }

                                    //Parse the Dependencies
                                    foreach (XPathNavigator dependencyNav in nav.CreateNavigator().Select("dependencies/dependency"))
                                    {
                                        var dependency       = DependencyFactory.GetDependency(dependencyNav);
                                        var packageDependecy = dependency as IManagedPackageDependency;

                                        if (packageDependecy != null)
                                        {
                                            package.Dependencies.Add(packageDependecy.PackageDependency);
                                        }
                                    }

                                    packages.Add(file, package);
                                }
                            }

                            break;
                        }
                    }
                    entry = unzip.GetNextEntry();
                }
            }
            catch (Exception)
            {
                invalidPackages.Add(file);
            }
            finally
            {
                unzip.Close();
                unzip.Dispose();
            }
        }
Ejemplo n.º 2
0
        private void BindGrid(string installPath, DataGrid grid)
        {
            var packages        = new List <PackageInfo>();
            var invalidPackages = new List <string>();

            foreach (string file in Directory.GetFiles(installPath))
            {
                if (file.ToLower().EndsWith(".zip") || file.ToLower().EndsWith(".resources"))
                {
                    Stream inputStream = new FileStream(file, FileMode.Open, FileAccess.Read);
                    var    unzip       = new ZipInputStream(inputStream);

                    try
                    {
                        ZipEntry entry = unzip.GetNextEntry();

                        while (entry != null)
                        {
                            if (!entry.IsDirectory)
                            {
                                var    fileName  = entry.Name;
                                string extension = System.IO.Path.GetExtension(fileName);
                                if (extension.ToLower() == ".dnn" || extension.ToLower() == ".dnn5")
                                {
                                    //Manifest
                                    var manifestReader = new StreamReader(unzip);
                                    var manifest       = manifestReader.ReadToEnd();

                                    var package = new PackageInfo();
                                    package.Manifest = manifest;
                                    if (!string.IsNullOrEmpty(manifest))
                                    {
                                        var            doc         = new XPathDocument(new StringReader(manifest));
                                        XPathNavigator rootNav     = doc.CreateNavigator().SelectSingleNode("dotnetnuke");
                                        string         packageType = String.Empty;
                                        if (rootNav.Name == "dotnetnuke")
                                        {
                                            packageType = XmlUtils.GetAttributeValue(rootNav, "type");
                                        }
                                        else if (rootNav.Name.ToLower() == "languagepack")
                                        {
                                            packageType = "LanguagePack";
                                        }
                                        XPathNavigator nav = null;
                                        switch (packageType.ToLower())
                                        {
                                        case "package":
                                            nav = rootNav.SelectSingleNode("packages/package");
                                            break;

                                        case "module":
                                        case "languagepack":
                                        case "skinobject":
                                            nav = Installer.ConvertLegacyNavigator(rootNav, new InstallerInfo()).SelectSingleNode("packages/package");
                                            break;
                                        }

                                        if (nav != null)
                                        {
                                            package.Name            = XmlUtils.GetAttributeValue(nav, "name");
                                            package.PackageType     = XmlUtils.GetAttributeValue(nav, "type");
                                            package.IsSystemPackage = XmlUtils.GetAttributeValueAsBoolean(nav, "isSystem", false);
                                            package.Version         = new Version(XmlUtils.GetAttributeValue(nav, "version"));
                                            package.FriendlyName    = XmlUtils.GetNodeValue(nav, "friendlyName");
                                            if (String.IsNullOrEmpty(package.FriendlyName))
                                            {
                                                package.FriendlyName = package.Name;
                                            }
                                            package.Description = XmlUtils.GetNodeValue(nav, "description");
                                            package.FileName    = file.Replace(installPath + "\\", "");

                                            XPathNavigator foldernameNav = null;
                                            switch (package.PackageType)
                                            {
                                            case "Module":
                                            case "Auth_System":
                                                foldernameNav = nav.SelectSingleNode("components/component/files");
                                                if (foldernameNav != null)
                                                {
                                                    package.FolderName = Util.ReadElement(foldernameNav, "basePath").Replace('\\', '/');
                                                }
                                                break;

                                            case "Container":
                                                foldernameNav = nav.SelectSingleNode("components/component/containerFiles");
                                                if (foldernameNav != null)
                                                {
                                                    package.FolderName = Globals.glbContainersPath + Util.ReadElement(foldernameNav, "containerName").Replace('\\', '/');
                                                }
                                                break;

                                            case "Skin":
                                                foldernameNav = nav.SelectSingleNode("components/component/skinFiles");
                                                if (foldernameNav != null)
                                                {
                                                    package.FolderName = Globals.glbSkinsPath + Util.ReadElement(foldernameNav, "skinName").Replace('\\', '/');
                                                }
                                                break;

                                            default:
                                                break;
                                            }

                                            XPathNavigator iconFileNav = nav.SelectSingleNode("iconFile");
                                            if (package.FolderName != string.Empty && iconFileNav != null)
                                            {
                                                if ((iconFileNav.Value != string.Empty) && (package.PackageType == "Module" || package.PackageType == "Auth_System" || package.PackageType == "Container" || package.PackageType == "Skin"))
                                                {
                                                    package.IconFile = package.FolderName + "/" + iconFileNav.Value;
                                                    package.IconFile = (!package.IconFile.StartsWith("~/")) ? "~/" + package.IconFile : package.IconFile;
                                                }
                                            }

                                            packages.Add(package);
                                        }
                                    }

                                    break;
                                }
                            }
                            entry = unzip.GetNextEntry();
                        }
                    }
                    catch (Exception)
                    {
                        invalidPackages.Add(file);
                    }
                    finally
                    {
                        unzip.Close();
                        unzip.Dispose();
                    }
                }
            }

            if (invalidPackages.Count > 0)
            {
                var pkgErrorsMsg = invalidPackages.Aggregate(string.Empty, (current, pkg) => current + (pkg + "<br />"));
                UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("PackageErrors.Text", LocalResourceFile) + pkgErrorsMsg, ModuleMessage.ModuleMessageType.RedError);
            }

            grid.DataSource = packages;
            grid.DataBind();
        }
Ejemplo n.º 3
0
        private void BindGrid(string installPath, DataGrid grid)
        {
            var packages        = new List <PackageInfo>();
            var invalidPackages = new List <string>();

            foreach (string file in Directory.GetFiles(installPath))
            {
                if (file.ToLower().EndsWith(".zip") || file.ToLower().EndsWith(".resources"))
                {
                    Stream inputStream = new FileStream(file, FileMode.Open, FileAccess.Read);
                    var    unzip       = new ZipInputStream(inputStream);

                    try
                    {
                        ZipEntry entry = unzip.GetNextEntry();

                        while (entry != null)
                        {
                            if (!entry.IsDirectory)
                            {
                                string fileName  = entry.Name;
                                string extension = Path.GetExtension(fileName);
                                if (extension.ToLower() == ".dnn" || extension.ToLower() == ".dnn5")
                                {
                                    //Manifest
                                    var    manifestReader = new StreamReader(unzip);
                                    string manifest       = manifestReader.ReadToEnd();

                                    var package = new PackageInfo();
                                    package.Manifest = manifest;
                                    if (!string.IsNullOrEmpty(manifest))
                                    {
                                        var            doc         = new XPathDocument(new StringReader(manifest));
                                        XPathNavigator rootNav     = doc.CreateNavigator().SelectSingleNode("dotnetnuke");
                                        string         packageType = String.Empty;
                                        if (rootNav.Name == "dotnetnuke")
                                        {
                                            packageType = XmlUtils.GetAttributeValue(rootNav, "type");
                                        }
                                        else if (rootNav.Name.ToLower() == "languagepack")
                                        {
                                            packageType = "LanguagePack";
                                        }
                                        XPathNavigator nav = null;
                                        switch (packageType.ToLower())
                                        {
                                        case "package":
                                            nav = rootNav.SelectSingleNode("packages/package");
                                            break;

                                        case "languagepack":

                                            nav = Installer.ConvertLegacyNavigator(rootNav, new InstallerInfo()).SelectSingleNode("packages/package");
                                            break;
                                        }

                                        if (nav != null)
                                        {
                                            package.Name            = XmlUtils.GetAttributeValue(nav, "name");
                                            package.PackageType     = XmlUtils.GetAttributeValue(nav, "type");
                                            package.IsSystemPackage = XmlUtils.GetAttributeValueAsBoolean(nav, "isSystem", false);
                                            package.Version         = new Version(XmlUtils.GetAttributeValue(nav, "version"));
                                            package.FriendlyName    = XmlUtils.GetNodeValue(nav, "friendlyName");
                                            if (String.IsNullOrEmpty(package.FriendlyName))
                                            {
                                                package.FriendlyName = package.Name;
                                            }
                                            package.Description = XmlUtils.GetNodeValue(nav, "description");
                                            package.FileName    = file.Replace(installPath + "\\", "");

                                            packages.Add(package);
                                        }
                                    }

                                    break;
                                }
                            }
                            entry = unzip.GetNextEntry();
                        }
                    }
                    catch (Exception)
                    {
                        invalidPackages.Add(file);
                    }
                    finally
                    {
                        unzip.Close();
                        unzip.Dispose();
                    }
                }
            }

            //now add language packs from update service
            try
            {
                StreamReader myResponseReader = UpdateService.GetLanguageList();
                var          xmlDoc           = new XmlDocument();
                xmlDoc.Load(myResponseReader);
                XmlNodeList languages = xmlDoc.SelectNodes("available/language");

                if (languages != null)
                {
                    var installedPackages  = PackageController.GetPackagesByType("CoreLanguagePack");
                    var installedLanguages = installedPackages.Select(package => LanguagePackController.GetLanguagePackByPackage(package.PackageID)).ToList();
                    foreach (XmlNode language in languages)
                    {
                        string cultureCode = "";
                        string version     = "";
                        foreach (XmlNode child in language.ChildNodes)
                        {
                            if (child.Name == "culturecode")
                            {
                                cultureCode = child.InnerText;
                            }

                            if (child.Name == "version")
                            {
                                version = child.InnerText;
                            }
                        }
                        if (!string.IsNullOrEmpty(cultureCode) && !string.IsNullOrEmpty(version) && version.Length == 6)
                        {
                            var myCIintl = new CultureInfo(cultureCode, true);
                            version = version.Insert(4, ".").Insert(2, ".");
                            var package = new PackageInfo {
                                Owner = OwnerUpdateService, Name = "LanguagePack-" + myCIintl.Name, FriendlyName = myCIintl.NativeName
                            };
                            package.Name        = myCIintl.NativeName;
                            package.Description = cultureCode;
                            Version ver = null;
                            Version.TryParse(version, out ver);
                            package.Version = ver;

                            if (
                                installedLanguages.Any(
                                    l =>
                                    LocaleController.Instance.GetLocale(l.LanguageID).Code.ToLowerInvariant().Equals(cultureCode.ToLowerInvariant()) &&
                                    installedPackages.First(p => p.PackageID == l.PackageID).Version >= ver))
                            {
                                continue;
                            }

                            if (packages.Any(p => p.Name == package.Name))
                            {
                                var existPackage = packages.First(p => p.Name == package.Name);
                                if (package.Version > existPackage.Version)
                                {
                                    packages.Remove(existPackage);
                                    packages.Add(package);
                                }
                            }
                            else
                            {
                                packages.Add(package);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //suppress for now - need to decide what to do when webservice is unreachable
                //throw;
                //same problem happens in InstallWizard.aspx.cs in BindLanguageList method
            }


            if (invalidPackages.Count > 0)
            {
                string pkgErrorsMsg = invalidPackages.Aggregate(string.Empty, (current, pkg) => current + (pkg + "<br />"));
                Skin.AddModuleMessage(this, Localization.GetString("PackageErrors.Text", LocalResourceFile) + pkgErrorsMsg, ModuleMessage.ModuleMessageType.RedError);
            }

            grid.DataSource = packages;
            grid.DataBind();
        }