public void Install(RunningDeployment deployment)
        {
            if (deployment.Variables.GetFlag(SpecialVariables.Action.Azure.CloudServicePackageExtractionDisabled, false))
            {
                return;
            }

            Log.Verbose("Re-packaging cspkg.");
            var workingDirectory    = deployment.CurrentDirectory;
            var originalPackagePath = deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServicePackagePath);
            var newPackagePath      = Path.Combine(Path.GetDirectoryName(originalPackagePath), Path.GetFileNameWithoutExtension(originalPackagePath) + "_repacked.cspkg");

            using (var originalPackage = Package.Open(originalPackagePath, FileMode.Open))
                using (var newPackage = Package.Open(newPackagePath, FileMode.CreateNew))
                {
                    var originalManifest = AzureCloudServiceConventions.ReadPackageManifest(originalPackage);

                    var newManifest = new PackageDefinition
                    {
                        MetaData = { AzureVersion = originalManifest.MetaData.AzureVersion }
                    };

                    AddParts(newPackage, newManifest, Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.ServiceDefinition),
                             AzureCloudServiceConventions.PackageFolders.ServiceDefinition);
                    AddParts(newPackage, newManifest, Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.NamedStreams),
                             AzureCloudServiceConventions.PackageFolders.NamedStreams);
                    AddLocalContent(newPackage, newManifest, workingDirectory);

                    AddPackageManifest(newPackage, newManifest);

                    newPackage.Flush();
                }

            fileSystem.OverwriteAndDelete(originalPackagePath, newPackagePath);
        }
Beispiel #2
0
        void Write(IEnumerable <XElement> elements)
        {
            if (string.IsNullOrWhiteSpace(JournalPath))
            {
                throw new InvalidOperationException("JournalPath has not been set");
            }

            fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(JournalPath));

            var tempPath = JournalPath + ".temp-" + Guid.NewGuid() + ".xml";

            var root     = new XElement("Deployments");
            var document = new XDocument(root);

            foreach (var element in elements)
            {
                root.Add(element);
            }

            using (var stream = fileSystem.OpenFile(tempPath, FileMode.Create, FileAccess.Write))
            {
                document.Save(stream);
            }

            fileSystem.OverwriteAndDelete(JournalPath, tempPath);
        }
Beispiel #3
0
        void ConvertPackage(string packagePath)
        {
            string newPackagePath = Path.Combine(Path.GetDirectoryName(packagePath), Path.GetFileNameWithoutExtension(packagePath) + "_new.cspkg");

            using (var packageStore = new OpcPackageStore(newPackagePath, FileMode.CreateNew, FileAccess.ReadWrite))
                using (var fileStream = fileSystem.OpenFile(packagePath, FileMode.Open))
                {
                    PackageConverter.ConvertFromLegacy(fileStream, packageStore);
                }

            fileSystem.OverwriteAndDelete(packagePath, newPackagePath);
        }
Beispiel #4
0
        void Save()
        {
            var onlyJournalEntries = journalEntries.Select(p => p.Value);
            var json = JsonConvert.SerializeObject(new PackageData(onlyJournalEntries, Cache));

            fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(journalPath));
            //save to temp file first
            var tempFilePath = $"{journalPath}.temp.{Guid.NewGuid()}.json";

            fileSystem.WriteAllText(tempFilePath, json, Encoding.UTF8);
            fileSystem.OverwriteAndDelete(journalPath, tempFilePath);
        }
        public void Install(RunningDeployment deployment)
        {
            if (deployment.Variables.GetFlag(SpecialVariables.Action.Azure.CloudServicePackageExtractionDisabled, false))
            {
                return;
            }

            Log.Verbose("Re-packaging cspkg.");
            var workingDirectory    = deployment.CurrentDirectory;
            var originalPackagePath = deployment.Variables.Get(SpecialVariables.Action.Azure.CloudServicePackagePath);
            var newPackagePath      = Path.Combine(Path.GetDirectoryName(originalPackagePath), Path.GetFileNameWithoutExtension(originalPackagePath) + "_repacked.cspkg");

            using (semaphoreFactory.Acquire("Calamari - multi threaded packaging causes IsolatedStorage errors", "Waiting to re-package"))
                using (var originalPackage = Package.Open(originalPackagePath, FileMode.Open))
                    using (var newPackage = Package.Open(newPackagePath, FileMode.CreateNew))
                    {
                        try
                        {
                            var originalManifest = AzureCloudServiceConventions.ReadPackageManifest(originalPackage);

                            var newManifest = new PackageDefinition
                            {
                                MetaData = { AzureVersion = originalManifest.MetaData.AzureVersion }
                            };

                            AddParts(newPackage, newManifest,
                                     Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.ServiceDefinition),
                                     AzureCloudServiceConventions.PackageFolders.ServiceDefinition);
                            AddParts(newPackage, newManifest,
                                     Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.NamedStreams),
                                     AzureCloudServiceConventions.PackageFolders.NamedStreams);
                            AddLocalContent(newPackage, newManifest, workingDirectory);

                            AddPackageManifest(newPackage, newManifest);

                            newPackage.Flush();
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.PrettyPrint());
                            throw new Exception("An exception occured re-packaging the cspkg");
                        }
                    }

            fileSystem.OverwriteAndDelete(originalPackagePath, newPackagePath);
        }
Beispiel #6
0
        private void Write(IEnumerable <XElement> elements)
        {
            fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(JournalPath));

            var tempPath = JournalPath + ".temp-" + Guid.NewGuid() + ".xml";

            var root     = new XElement("Deployments");
            var document = new XDocument(root);

            foreach (var element in elements)
            {
                root.Add(element);
            }

            using (var stream = fileSystem.OpenFile(tempPath, FileMode.Create, FileAccess.Write))
                document.Save(stream);

            fileSystem.OverwriteAndDelete(JournalPath, tempPath);
        }