Esempio n. 1
0
        private void LoadProductList()
        {
            // Find all products in the staging area that can have instances.
            string[] productDirs = Directory.GetDirectories(_stagingAreaPath);

            // Clear Productlist
            _productList.Clear();

            // Check if any directories was found
            if (productDirs.GetUpperBound(0) >= 0)
            {
                // Loop through list of directories and find the correct product directories.
                foreach (string productDir in productDirs)
                {
                    // Read the product.xml file from the path
                    Product product = SerializeHandler.GetProduct(productDir);

                    if (product != null)
                    {
                        // Check type of product
                        if (product.ProductType == ProductType.Standard)
                        {
                            _productList.CreateOrUpdate(product, productDir);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void CheckZipfile(ZipFile zip, string extractDir, out string version, out Product product)
        {
            ZipEntry productXMLentry = null;
            bool     manifestFound   = false;

            version = string.Empty;

            // First loop and try to find the version directory
            foreach (ZipEntry entry in zip.Entries)
            {
                // Check if product.xml file
                if (entry.FileName.ToUpper() == SerializeHandler.ProductFilename.ToUpper())
                {
                    productXMLentry = entry;
                    continue;
                }

                if (entry.IsDirectory)
                {
                    // Check that the "root" directory is a versionnumber
                    string[] directories = entry.FileName.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                    if (directories.Length > 0)
                    {
                        // The first part of the path should always be the version number
                        if (VersionHandler.IsVersion(directories[0]))
                        {
                            // Fetch the version number
                            if (directories.Length == 1)
                            {
                                if (string.IsNullOrEmpty(version))
                                {
                                    version = directories[0];
                                }
                                else
                                {
                                    // More than one version directory was found. Error!
                                    throw new Exception("The zip file contains more than one version directory.");
                                }
                            }
                        }
                        else
                        {
                            // It's not a version directory.
                            throw new Exception("The zip file contains directories other than the version directory.");
                        }
                    }
                    else
                    {
                        // Split generated no result
                        throw new Exception("The zip file contains invalid directory entries.");
                    }

                    continue;
                }
            }

            if (string.IsNullOrEmpty(version))
            {
                // The version wasn't found
                throw new Exception("The zip file does not contain a version directory.");
            }

            if (productXMLentry == null)
            {
                throw new Exception(string.Format("The zip file is missing the file {0}.", SerializeHandler.ProductFilename));
            }

            // Read the Product.xml
            productXMLentry.Extract(extractDir);

            // Read the product.xml file from the path
            product = SerializeHandler.GetProduct(extractDir);

            // Throw an exception if the product couldn't be read.
            if (product == null)
            {
                throw new Exception(string.Format("The {0} file couldn't be read.", productXMLentry.FileName));
            }

            // Do additional controls of standard products.
            if (product.ProductType == ProductType.Standard)
            {
                // Check the files in the zipfile
                foreach (ZipEntry entry in zip.Entries)
                {
                    // Ignore directories since we checked them above
                    if (entry.IsDirectory)
                    {
                        continue;
                    }

                    // Check if product.xml file
                    if (entry.FileName.ToUpper() == SerializeHandler.ProductFilename.ToUpper())
                    {
                        continue;
                    }

                    // Check if it's a deploy file
                    if (Path.GetExtension(entry.FileName).ToUpper() == Constants.ValidZIPVersionDirExtension_Deploy.ToUpper())
                    {
                        continue;
                    }

                    // Check if it's a manifest file
                    if (Path.GetExtension(entry.FileName).ToUpper() == Constants.ValidZIPVersionDirExtension_Manifest.ToUpper())
                    {
                        if (!manifestFound)
                        {
                            manifestFound = true;
                        }
                        else
                        {
                            // More than one manifest file found in zip file! Error!
                            throw new Exception("The zip file contains more than one manifest file.");
                        }

                        continue;
                    }

                    // We should not reach this line since then we have found an unknown file
                    // that shouldn't be in the archive.
                    throw new Exception("The zip file contains one or more unknown files.");
                }
            }
        }