private XmlDocument LoadManifestFile(string manifestFilePath, ManifestReport manifestReport)
        {
            manifestFilePath += this.manifestFilePath.Split(new char[] { '/', '\\' }).Last();

            if (!System.IO.File.Exists(manifestFilePath))
            {
                logger.Warn("Could not report on deployment as ship cannot find manifest file at " + manifestFilePath);
                return(null);
            }

            var manifestFile = new XmlDocument();

            manifestFile.Load(manifestFilePath);

            if (manifestFile.ChildNodes.Count == 0)
            {
                logger.Warn(manifestReport.SetError("Ship's manifest file appears to be blank at " + manifestFilePath).Error);
                return(null);
            }

            return(manifestFile);
        }
        private string ExtractPackageFiles(string packageFilePath, ManifestReport manifestReport)
        {
            if (!System.IO.File.Exists(packageFilePath))
            {
                logger.Warn(manifestReport.SetError("Could not report on deployment as ship cannot find pacakge file at " + packageFilePath).Error);
                return(null);
            }

            if (SessionTempDirectory != null)
            {
                CleanSessionTempDirectory();
            }
            var guid = Guid.NewGuid();

            SessionTempDirectory = tempDirectory + guid + "\\";
            System.IO.Directory.CreateDirectory(SessionTempDirectory);

            ExtractedTempPackagePath = SessionTempDirectory + "package." + guid + ".zip";
            if (!Utilities.UnzipTargetFile(packageFilePath, "package.zip", ExtractedTempPackagePath))
            {
                logger.Error(manifestReport.SetError("Could not report on deployment as ship cannot find package zip in the update file at " + packageFilePath).Error);
                return(null);
            }

            try
            {
                UnzipPackageFiles(ExtractedTempPackagePath, SessionTempDirectory);
            }
            catch (Exception ex)
            {
                logger.Error(manifestReport.SetError("Could not report on deployment as ship cannot unzip all files in " + packageFilePath + ". " + ex.Message).Error);
                return(null);
            }

            return(SessionTempDirectory);
        }
        public ManifestReport ReportPackage(string packageFilePath)
        {
            var manifestReport = new ManifestReport()
            {
                Databases = new List <ManifestReportDataBase>()
            };

            // get the all the files (extracting it from update or zip)
            string extractionPath = ExtractPackageFiles(packageFilePath, manifestReport);

            if (extractionPath == null)
            {
                return(manifestReport);
            }

            var manifestFile = LoadManifestFile(extractionPath, manifestReport);

            if (manifestFile == null)
            {
                return(manifestReport);
            }

            logger.Info("***************** Begin manifest ****************");

            var rootNode = manifestFile.ChildNodes.Cast <XmlNode>().FirstOrDefault(item => item.Name == "DeployedItems");

            manifestReport.CanDeleteItems = UpdateCanDeleteItems(rootNode);
            if (manifestReport.CanDeleteItems)
            {
                logger.Info("Update can delete items");
            }
            else
            {
                logger.Info("Update cannot delete items");
            }

            // Pull out the manifest items
            var allManifestItems = rootNode.ChildNodes.Cast <XmlNode>().Where(item => item.Name == "DeployedItem");


            logger.Info("----- CORE -----");
            var addedItemsPath = extractionPath + "\\core";
            var itemsList      = allManifestItems.Where(item => item.Attributes["Database"].Value == "core");
            var reportDb       = ReportManifestList(itemsList, addedItemsPath + "\\", manifestReport.CanDeleteItems, Sitecore.Data.Database.GetDatabase("core"));

            manifestReport.Databases.Add(reportDb);

            logger.Info("----- MASTER -----");
            addedItemsPath = extractionPath + "\\master";
            itemsList      = allManifestItems.Where(item => item.Attributes["Database"].Value == "master");
            reportDb       = ReportManifestList(itemsList, addedItemsPath + "\\", manifestReport.CanDeleteItems, Sitecore.Data.Database.GetDatabase("master"));
            manifestReport.Databases.Add(reportDb);

            logger.Info("----- WEB -----");
            addedItemsPath = extractionPath + "\\web";
            itemsList      = allManifestItems.Where(item => item.Attributes["Database"].Value == "web");
            reportDb       = ReportManifestList(itemsList, addedItemsPath + "\\", manifestReport.CanDeleteItems, Sitecore.Data.Database.GetDatabase("web"));
            manifestReport.Databases.Add(reportDb);

            logger.Info("***************** End manifest ****************");

            return(manifestReport);
        }