/// <summary>
        /// Uninstalls a package.
        /// </summary>
        /// <param name="fileName"></param>
        public List <PackageImportEventArgs> UninstallPackage(string fileName)
        {
            // Validate that the package is still valid, just in case somebody else deleted it
            string packagePath = Path.Combine(ProgramDataFolder.MapPath("Packages"),
                                              fileName);
            FileInfo packageDetails = new FileInfo(packagePath);
            List <PackageImportEventArgs> events = null;

            if (packageDetails.Exists)
            {
                // Load the package and uninstall it
                events = new List <PackageImportEventArgs>();
                using (Stream packageStream = File.OpenRead(packagePath))
                {
                    using (Package package = new Package(packageStream))
                    {
                        package.Message += delegate(object source, PackageImportEventArgs args)
                        {
                            events.Add(args);
                        };
                        package.Uninstall();

                        // Update the list
                        XmlDocument packageList = LoadPackageList();
                        package.Manifest.IsInstalled = false;
                        UpdatePackagesList(package.Manifest, packageList, true);
                        SavePackageList(packageList);
                    }
                }
            }
            return(events);
        }
Exemple #2
0
        /// <summary>
        /// Copies files to the install location.
        /// </summary>
        /// <param name="folder">The details of the files to copy.</param>
        private void CopyFiles(FileLocation folder)
        {
            // Make sure the target folder exists
            FireMessage(TraceLevel.Verbose, "Copying files to target '{0}'", folder.Location);
            string target = ProgramDataFolder.MapPath(folder.Location);

            if (!Directory.Exists(target))
            {
                FireMessage(TraceLevel.Info, "Adding target folder '{0}'", folder.Location);
                Directory.CreateDirectory(target);
            }
            foreach (string file in folder.Files)
            {
                // Make sure the source file exists
                string source = Path.Combine(tempFolder, file);
                if (File.Exists(source))
                {
                    // Set to overwrite in case there is an older version of the file
                    FireMessage(TraceLevel.Info, "Deploying file '{0}' to target '{1}'", file, folder.Location);
                    File.Copy(source, Path.Combine(target, file), true);
                }
                else
                {
                    FireMessage(TraceLevel.Warning, "Source file '{0}' does not exist in package", file);
                }
            }
        }
        /// <summary>
        /// Stores a package locally on the server
        /// </summary>
        /// <param name="fileName">The file name of the package.</param>
        /// <param name="stream">The stream containing the package.</param>
        public PackageManifest StorePackage(string fileName, Stream stream)
        {
            // Initialise the path and make sure the folder is there
            FileInfo packageDetails = new FileInfo(fileName);
            string   packagePath    = Path.Combine(ProgramDataFolder.MapPath("Packages"),
                                                   packageDetails.Name);

            packageDetails = new FileInfo(packagePath);
            if (!packageDetails.Directory.Exists)
            {
                packageDetails.Directory.Create();
            }

            // We will always overwrite an existing packages, maybe we should do a back-up first?
            if (packageDetails.Exists)
            {
                packageDetails.Delete();
            }
            SaveToFile(stream, packageDetails.FullName);
            bool delete = false;

            // Load the package and extract the manifest details
            PackageManifest manifest = null;

            using (Stream inputStream = File.OpenRead(packagePath))
            {
                using (Package newPackage = new Package(inputStream))
                {
                    if (!newPackage.IsValid)
                    {
                        delete = true;
                    }
                    else
                    {
                        manifest          = newPackage.Manifest;
                        manifest.FileName = packageDetails.Name;
                    }
                }
            }

            if (manifest != null)
            {
                // Update the package list
                XmlDocument packageList = LoadPackageList();
                UpdatePackagesList(manifest, packageList, true);
                SavePackageList(packageList);
            }

            // Don't forget to clean-up, otherwise the packages directory will have invalid packages
            if (delete && packageDetails.Exists)
            {
                packageDetails.Delete();
            }
            return(manifest);
        }
        public static string CalculateDashboardConfigPath()
        {
            string path = ConfigurationManager.AppSettings[DashboardConfigAppSettingKey];

            if (path == null || path == string.Empty)
            {
                path = DefaultDashboardConfigLocation;
            }
            if (!Path.IsPathRooted(path))
            {
                path = ProgramDataFolder.MapPath(path);
            }
            return(path);
        }
        /// <summary>
        /// Load the package list.
        /// </summary>
        /// <returns></returns>
        private XmlDocument LoadPackageList()
        {
            string packagePath = Path.Combine(ProgramDataFolder.MapPath("Packages"),
                                              "packages.xml");
            FileInfo    listDetails = new FileInfo(packagePath);
            XmlDocument document    = new XmlDocument();

            if (listDetails.Exists)
            {
                document.Load(listDetails.FullName);
            }
            else
            {
                document.AppendChild(
                    document.CreateElement("packages"));
            }
            return(document);
        }
        /// <summary>
        /// Save the package list.
        /// </summary>
        private void SavePackageList(XmlDocument packageList)
        {
            string packagePath = Path.Combine(ProgramDataFolder.MapPath("Packages"),
                                              "packages.xml");

            // Configure the document options
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent             = true;
            settings.OmitXmlDeclaration = true;

            // Save the document
            using (XmlWriter writer = XmlWriter.Create(packagePath, settings))
            {
                packageList.Save(writer);
                writer.Close();
                writer.Close();
            }
        }
        /// <summary>
        /// Removes a package stored locally on the server
        /// </summary>
        /// <param name="fileName">The file name of the package.</param>
        /// <returns>The name of the package.</returns>
        public string RemovePackage(string fileName)
        {
            // Initialise the path and make sure the folder is there
            FileInfo packageDetails = new FileInfo(fileName);
            string   packagePath    = Path.Combine(ProgramDataFolder.MapPath("Packages"),
                                                   packageDetails.Name);

            packageDetails = new FileInfo(packagePath);
            string packageName = null;

            if (packageDetails.Directory.Exists)
            {
                // Load the package and extract the manifest details
                PackageManifest manifest = null;
                using (Stream inputStream = File.OpenRead(packagePath))
                {
                    using (Package newPackage = new Package(inputStream))
                    {
                        if (newPackage.IsValid)
                        {
                            manifest          = newPackage.Manifest;
                            manifest.FileName = packageDetails.Name;
                        }
                    }
                }

                if (manifest != null)
                {
                    // Update the package list
                    XmlDocument packageList = LoadPackageList();
                    UpdatePackagesList(manifest, packageList, false);
                    SavePackageList(packageList);
                    packageName = manifest.Name;
                }

                // Finally, remove the package
                packageDetails.Delete();
            }

            return(packageName);
        }
Exemple #8
0
        /// <summary>
        /// Removes files to the install location.
        /// </summary>
        /// <param name="folder">The details of the files to remove.</param>
        private void RemoveFiles(FileLocation folder)
        {
            // Make sure the target folder exists
            FireMessage(TraceLevel.Verbose, "Removing files from target '{0}'", folder.Location);
            string target = ProgramDataFolder.MapPath(folder.Location);

            if (Directory.Exists(target))
            {
                foreach (string file in folder.Files)
                {
                    // Make sure the file exists
                    string targetFile = Path.Combine(target, file);
                    if (File.Exists(targetFile))
                    {
                        // Set to overwrite in case there is an older version of the file
                        FireMessage(TraceLevel.Info, "Removing file '{0}' from target '{1}'", file, folder.Location);
                        File.Delete(targetFile);
                    }
                }
            }
        }