public static bool UpdateWebpage(ConfigurationSettings config, IList <ProductStandard> installedProducts)
        {
            ParseTemplate parseTemplate = new ParseTemplate(config, installedProducts);

            string webcontentPath       = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), Constants.WebsiteTemplatePath);
            string templateFile         = Path.Combine(webcontentPath, Constants.WebsiteMainTemplateFile);
            string redirectTemplateFile = Path.Combine(webcontentPath, Constants.WebsiteRedirectTemplateFile);
            string webpage = Path.Combine(config.GetMainVirtualDirectoryPath(), Constants.WebsiteMainWebpage);

            parseTemplate.DoParse(templateFile, webpage);

            // Copy static files
            if (!FileHandler.CopyDirectory(Path.Combine(webcontentPath, Constants.WebsiteStaticFilesFolder), config.GetMainVirtualDirectoryPath()))
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public void Import(string kitFilePath, string instanceToUpdate)
        {
            string  tempDir;
            string  version    = string.Empty;
            Product product    = null;
            bool    oldVersion = false;

            // Create the name for the temporary directory
            RaiseStatusChange("Creating temporary directory", 0, 0, -1);

            do
            {
                tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            }while (Directory.Exists(tempDir));


            try
            {
                // Create the temporary directory
                Directory.CreateDirectory(tempDir);

                RaiseStatusChange("Extracting kit", 0, 0, -1);
                // Open the archive
                using (ZipFile zip = ZipFile.Read(kitFilePath))
                {
                    // Do checks with the zipfile and reads the Product file
                    try
                    {
                        CheckZipfile(zip, tempDir, out version, out product);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("The selected zip file doesn't contain a valid product.\n{0}", ex.Message), ex);
                    }


                    if (product.ProductType == ProductType.Standard)
                    {
                        // Check if trying to import an older version than the latest
                        // version installed for the product.
                        if (_productList.Exists(product.ProductId) && VersionHandler.VersionStringCompare(_productList.Get(product.ProductId).LatestVersion, version) == 1)
                        {
                            oldVersion = true;
                        }
                    }



                    // Set eventhandler to do something useful.
                    zip.ExtractProgress += new EventHandler <ExtractProgressEventArgs>(zip_ExtractProgress);

                    // If no errors was found during the check then continue with extracting
                    // all files from the archive.
                    zip.ExtractAll(tempDir, true);

                    // Remove event again
                    zip.ExtractProgress -= zip_ExtractProgress;

                    // Remove readonly attribute on the extracted files since it only creates problems.
                    FileHandler.RemoveReadOnlyAttribute(tempDir, true);
                }


                if (product.ProductType == ProductType.Standard)
                {
                    RaiseStatusChange("Creating/Updating product and version", 0, 0, -1);
                    string installDir;
                    string versionInstallDir;
                    bool   productExist = _productList.Exists(product.ProductId);

                    // Check if product exist
                    if (productExist)
                    {
                        installDir = _productList.Get(product.ProductId).InstallPath;
                    }
                    else
                    {
                        installDir = FileHandler.GetNewInstallDirectory(product.ProductName, _stagingAreaPath);
                    }

                    // Versions install directory
                    versionInstallDir = Path.Combine(installDir, Constants.SubPathToVersions);

                    // Copy the version directory from temp to install directory
                    if (!FileHandler.CopyDirectory(Path.Combine(tempDir, version), Path.Combine(versionInstallDir, version)))
                    {
                        throw new Exception("Unable to copy the new version to the staging area.");
                    }

                    // Copy the product file
                    // Only do this if the version is newer than the LatestVersion or new parameters
                    // for newer versions will be removed etc.
                    if (!oldVersion)
                    {
                        try
                        {
                            FileHandler.CopyFileForced(Path.Combine(tempDir, SerializeHandler.ProductFilename), installDir);
                        }
                        catch
                        {
                            throw new Exception(string.Format("Error copying the file {0} to the staging area.", SerializeHandler.ProductFilename));
                        }
                    }

                    // Now create or update the ProductList
                    _productList.CreateOrUpdate(product, installDir);

                    //Update manifest to force download even if same version
                    foreach (Instance instance in _productList.Get(product.ProductId).Instances)
                    {
                        if (string.IsNullOrEmpty(instanceToUpdate))
                        {
                            if (VersionHandler.VersionStringCompare(instance.ProductVersion, version) == 0)
                            {
                                RaiseStatusChange("Updating instance using same product version: " + instance.Name, 0, 0, -1);
                                UpdateDeployManifest(_productList.Get(product.ProductId), instance, true, null);
                            }
                        }
                        else
                        {
                            if (instance.Name == instanceToUpdate)
                            {
                                bool changed = false;
                                RaiseStatusChange("Updating instance: " + instance.Name, 0, 0, -1);
                                if (instance.ProductVersion != version)
                                {
                                    instance.ProductVersion          = version;
                                    instance.VersionPath             = Path.Combine(versionInstallDir, version);
                                    instance.ApplicationManifestFile = Directory.GetFiles(instance.VersionPath, "*.manifest")[0];
                                    changed = true;
                                }

                                UpdateDeployManifest(_productList.Get(product.ProductId), instance, true, null);

                                if (changed)
                                {
                                    SerializeHandler.SaveProductStandardData(_productList.Get(product.ProductId).GetProductData(), _productList.Get(product.ProductId).InstallPath);
                                }
                            }
                        }
                    }

                    WebpageHandler.UpdateWebpage(_config, _productList);
                }
            }
            finally
            {
                // Clean the temp dir
                Directory.Delete(tempDir, true);
            }
        }