public void AddNode_adds_node_into_list() { Graph graph = new Graph(); PackageDefinition definition = new PackageDefinition("A"); graph.AddPackageDefinition(definition); Assert.IsTrue(graph.Contains(definition.Package)); }
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); }
void ExtractLayouts(Package package, PackageDefinition manifest, string workingDirectory) { var localContentDirectory = Path.Combine(workingDirectory, AzureCloudServiceConventions.PackageFolders.LocalContent); fileSystem.EnsureDirectoryExists(localContentDirectory); foreach (var layout in manifest.Layouts) { if (!layout.Name.StartsWith(AzureCloudServiceConventions.RoleLayoutPrefix)) continue; var layoutDirectory = Path.Combine(localContentDirectory, layout.Name.Substring(AzureCloudServiceConventions.RoleLayoutPrefix.Length)); fileSystem.EnsureDirectoryExists(layoutDirectory); foreach (var fileDefinition in layout.FileDefinitions) { var contentDefinition = manifest.GetContentDefinition(fileDefinition.Description.DataContentReference); var destinationFileName = Path.Combine(layoutDirectory, fileDefinition.FilePath.TrimStart('\\')); ExtractPart( package.GetPart(PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), contentDefinition.Description.DataStorePath)), destinationFileName); } } }
public void MarkAsVisited_sets_PackageDefinition_as_Visited() { PackageDefinition def = new PackageDefinition("A"); Assert.IsFalse(def.Visited); def.MarkAsVisited(); Assert.IsTrue(def.Visited); }
public void MarkAsAdded_PackageDefinition_sets_it_as_Added() { PackageDefinition def = new PackageDefinition("A"); Assert.IsFalse(def.Added); def.MarkAsAdded(); Assert.IsTrue(def.Added); }
void AddContent(Package package, PackageDefinition manifest, Uri partUri, string file) { var part = package.CreatePart( PackUriHelper.CreatePartUri(partUri), System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum); using (var partStream = part.GetStream()) using (var fileStream = fileSystem.OpenFile(file, FileMode.Open)) { fileStream.CopyTo(partStream); partStream.Flush(); fileStream.Position = 0; var hashAlgorithm = new SHA256Managed(); hashAlgorithm.ComputeHash(fileStream); manifest.Contents.Add(new ContentDefinition { Name = partUri.ToString(), Description = new ContentDescription { DataStorePath = partUri, LengthInBytes = (int) fileStream.Length, HashAlgorithm = IntegrityCheckHashAlgorithm.Sha256, Hash = Convert.ToBase64String(hashAlgorithm.Hash) } }); } }
public void given_a_string_constructs_a_correct_PackageNode(string input, string package, List<string> dependencies) { PackageDefinition packageDef = new PackageDefinition(input); Assert.AreEqual(packageDef.Package, package); Assert.IsFalse(dependencies.Except(packageDef.Dependencies).Any()); Assert.IsFalse(packageDef.Dependencies.Except(dependencies).Any()); }
public void SortTopologicallyAsString_does_not_scan_dependencies_for_Visited_packages() { Graph graph = new Graph(); PackageDefinition definitionA = new PackageDefinition("A:B"); definitionA.MarkAsAdded(); graph.AddPackageDefinition(definitionA); Queue<string> result = graph.SortTopologically(); Assert.IsEmpty(result); }
void ExtractContents(Package package, PackageDefinition manifest, string contentNamePrefix, string workingDirectory) { foreach (var namedStreamsContent in manifest.Contents.Where(x => x.Name.StartsWith(contentNamePrefix))) { var destinationFileName = Path.Combine(workingDirectory, ConvertToWindowsPath(namedStreamsContent.Description.DataStorePath.ToString()).TrimStart('\\')); ExtractPart(package.GetPart(PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), namedStreamsContent.Description.DataStorePath)), destinationFileName); } }
public void SortTopologicallyAsString_returns_dependency_package_before_the_package_itself_regardless_of_addition_order_to_graph() { Graph graph = new Graph(); PackageDefinition definitionB = new PackageDefinition("B"); PackageDefinition definitionA = new PackageDefinition("A:B"); graph.AddPackageDefinition(definitionB); graph.AddPackageDefinition(definitionA); string sortedList = graph.SortTopologicallyAsString(); Assert.AreEqual("B, A", sortedList); }
public void ShouldProduceValidManifestXml() { var manifest = new PackageDefinition {MetaData = {AzureVersion = "2.6"}}; manifest.Contents.Add( new ContentDefinition { Name = "ServiceDefinition/ServiceDefinition.csdef", Description = new ContentDescription { LengthInBytes = 688, HashAlgorithm = IntegrityCheckHashAlgorithm.Sha256, Hash = "NMkHuVQbi+g+ny+kvjiunBgt8rLQT8Jd9FGJvWsRtZE=", DataStorePath = new Uri("ServiceDefinition/ServiceDefinition.csdef", UriKind.Relative) } }); manifest.Contents.Add( new ContentDefinition { Name = "LocalContent/ab3574e8f52d4c939aa6ff065e8b7cfd", Description = new ContentDescription { LengthInBytes = 19469, HashAlgorithm = IntegrityCheckHashAlgorithm.Sha256, Hash = "UK4lyWPyRI6I8WNzlVP2dtiFZj+kjMIjyGieq5b4TiE=", DataStorePath = new Uri("LocalContent/ab3574e8f52d4c939aa6ff065e8b7cfd", UriKind.Relative) } }); var workerRoleLayout = new LayoutDefinition {Name = "Roles/WorkerRole1"}; workerRoleLayout.FileDefinitions.Add(new FileDefinition { FilePath = "\\Cloud.uar.csman", Description = new FileDescription { DataContentReference = "LocalContent/ab3574e8f52d4c939aa6ff065e8b7cfd", Created = DateTime.UtcNow, Modified = DateTime.UtcNow } }); manifest.Layouts.Add(workerRoleLayout); var manifestXml = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); manifestXml.Add(manifest.ToXml()); var schemaSet = new XmlSchemaSet(); schemaSet.Add(null, XmlReader.Create(new StringReader(GetPackageManifestSchema()), XmlUtils.DtdSafeReaderSettings)); manifestXml.Validate(schemaSet, (o, e) => { Assert.Fail("Xml failed to validate: " + e.Message); }); }
public void SortTopologicallyAsString_returns_dependency_package_before_the_package_itself_when_multiple_dependencies_involved() { Graph graph = new Graph(); PackageDefinition definitionA = new PackageDefinition("A:B,C,D"); PackageDefinition definitionB = new PackageDefinition("B:C"); PackageDefinition definitionC = new PackageDefinition("C"); PackageDefinition definitionD = new PackageDefinition("D"); graph.AddPackageDefinition(definitionA); graph.AddPackageDefinition(definitionC); graph.AddPackageDefinition(definitionB); graph.AddPackageDefinition(definitionD); string sortedList = graph.SortTopologicallyAsString(); Assert.AreEqual("C, B, D, A", sortedList); }
public bool SavePackage(PackageDefinition definition) { if (definition == null) { throw new NullReferenceException("PackageDefinition cannot be null when saving"); } if (definition.Name == null || string.IsNullOrEmpty(definition.Name) || definition.PackagePath == null) { return(false); } // Ensure it's valid ValidatePackage(definition); if (definition.Id == default) { // Create dto from definition var dto = new CreatedPackageSchemaDto() { Name = definition.Name, Value = _xmlParser.ToXml(definition).ToString(), UpdateDate = DateTime.Now, PackageId = Guid.NewGuid() }; // Set the ids, we have to save in database first to get the Id _umbracoDatabase !.Insert(dto); definition.Id = dto.Id; } // Save snapshot locally, we do this to the updated packagePath ExportPackage(definition); // Create dto from definition var updatedDto = new CreatedPackageSchemaDto() { Name = definition.Name, Value = _xmlParser.ToXml(definition).ToString(), Id = definition.Id, PackageId = definition.PackageId, UpdateDate = DateTime.Now }; _umbracoDatabase?.Update(updatedDto); return(true); }
public PackageInstallModel Import(PackageInstallModel model) { var zipFile = new FileInfo(Path.Combine(IOHelper.MapPath(SystemDirectories.Packages), model.ZipFileName)); var packageInfo = Services.PackagingService.GetCompiledPackageInfo(zipFile); //now we need to check for version comparison if (packageInfo.UmbracoVersionRequirementsType == RequirementsType.Strict) { var packageMinVersion = packageInfo.UmbracoVersion; if (UmbracoVersion.Current < packageMinVersion) { throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("packager/targetVersionMismatch", new[] { packageMinVersion.ToString() }))); } } var installType = Services.PackagingService.GetPackageInstallType(packageInfo.Name, SemVersion.Parse(packageInfo.Version), out var alreadyInstalled); var packageDefinition = PackageDefinition.FromCompiledPackage(packageInfo); packageDefinition.PackagePath = zipFile.FullName; packageDefinition.PackageId = model.PackageGuid; //We must re-map the original package GUID that was generated switch (installType) { case PackageInstallType.AlreadyInstalled: throw new InvalidOperationException("The package is already installed"); case PackageInstallType.NewInstall: case PackageInstallType.Upgrade: //save to the installedPackages.config, this will create a new entry with a new Id if (!Services.PackagingService.SaveInstalledPackage(packageDefinition)) { throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Could not save the package")); } model.Id = packageDefinition.Id; break; default: throw new ArgumentOutOfRangeException(); } return(model); }
public void PackageRepository_Can_Update_Package() { var packageDefinition = new PackageDefinition() { Name = "TestPackage" }; CreatedPackageSchemaRepository.SavePackage(packageDefinition); packageDefinition.Name = "UpdatedName"; CreatedPackageSchemaRepository.SavePackage(packageDefinition); var results = CreatedPackageSchemaRepository.GetAll().ToList(); Assert.AreEqual(expected: 1, actual: results.Count); Assert.AreEqual(expected: "UpdatedName", actual: results.FirstOrDefault()?.Name); }
GetMasterPackage( bool enforceBamAssemblyVersions = true) { var workingDir = Graph.Instance.ProcessState.WorkingDirectory; var isWorkingPackageWellDefined = IsPackageDirectory(workingDir); if (!isWorkingPackageWellDefined) { throw new Exception("Working directory package is not well defined"); } var masterDefinitionFile = new PackageDefinition(GetPackageDefinitionPathname(workingDir), !Graph.Instance.ForceDefinitionFileUpdate); masterDefinitionFile.Read(true, enforceBamAssemblyVersions); return(masterDefinitionFile); }
private static XElement GetAuthor(PackageDefinition definition) { var author = new XElement("author"); if (string.IsNullOrWhiteSpace(definition.Author) == false) { author.Add(new XElement("name", definition.Author)); } if (string.IsNullOrWhiteSpace(definition.AuthorUrl) == false) { author.Add(new XElement("website", definition.AuthorUrl)); } return(author); }
public void PackageRepository_Can_Update_Package() { var packageDefinition = new PackageDefinition() { Name = "TestPackage" }; CreatedPackageSchemaRepository.SavePackage(packageDefinition); packageDefinition.Name = "UpdatedName"; CreatedPackageSchemaRepository.SavePackage(packageDefinition); var result = CreatedPackageSchemaRepository.GetAll().ToList(); Assert.AreEqual(result.Count, 1); Assert.AreEqual(result.FirstOrDefault()?.Name, "UpdatedName"); }
private static XElement GetLicense(PackageDefinition definition) { var license = new XElement("license"); if (string.IsNullOrWhiteSpace(definition.License) == false) { license.Add(definition.License); } if (string.IsNullOrWhiteSpace(definition.LicenseUrl) == false) { license.Add(new XAttribute("url", definition.LicenseUrl)); } return(license); }
public void Delete() { var def1 = new PackageDefinition { Name = "test", }; bool result = PackageBuilder.SavePackage(def1); Assert.IsTrue(result); PackageBuilder.Delete(def1.Id); def1 = PackageBuilder.GetById(def1.Id); Assert.IsNull(def1); }
/// <inheritdoc /> public UninstallationSummary UninstallPackage(PackageDefinition package, int userId) { //running this will update the PackageDefinition with the items being removed var summary = _packageDataInstallation.UninstallPackageData(package, userId); summary.Actions = CompiledPackageXmlParser.GetPackageActions(XElement.Parse(package.Actions), package.Name); //run actions before files are removed summary.ActionErrors = UndoPackageActions(package, summary.Actions).ToList(); var filesRemoved = _packageFileInstallation.UninstallFiles(package); summary.FilesUninstalled = filesRemoved; return(summary); }
TryToResolveDuplicate( PackageDefinition masterDefinitionFile, string dupName, System.Collections.Generic.IEnumerable <PackageDefinition> duplicates, Array <PackageDefinition> packageDefinitions, Array <StringArray> packageVersionSpecifiers, Array <PackageDefinition> toRemove) { // command line specifications take precedence to resolve a duplicate foreach (var specifier in packageVersionSpecifiers) { if (!specifier.Contains(dupName)) { continue; } foreach (var dupPackage in duplicates) { if (specifier[1] == dupPackage.Version) { toRemove.AddRange(packageDefinitions.Where(item => (item.Name == dupName) && (item != dupPackage))); return(dupPackage); } } var noMatchMessage = new System.Text.StringBuilder(); noMatchMessage.AppendFormat("Command line version specified, {0}, could not resolve to one of the available versions of package {1}:", specifier[1], duplicates.First().Name); noMatchMessage.AppendLine(); foreach (var dup in duplicates) { noMatchMessage.AppendFormat("\t{0}", dup.Version); noMatchMessage.AppendLine(); } throw new Exception(noMatchMessage.ToString()); } // now look at the master dependency file, for any 'default' specifications var masterDependency = masterDefinitionFile.Dependents.FirstOrDefault(item => item.Item1 == dupName && item.Item3.HasValue && item.Item3.Value); if (null != masterDependency) { toRemove.AddRange(packageDefinitions.Where(item => (item.Name == dupName) && (item.Version != masterDependency.Item2))); return(packageDefinitions.First(item => (item.Name == dupName) && (item.Version == masterDependency.Item2))); } return(null); }
void OnGUI() { EditorGUIUtility.labelWidth = 100; // Package EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(); this.package = EditorGUILayout.ObjectField("Package", this.package, typeof(PackageDefinition), false) as PackageDefinition; EditorGUILayout.EndHorizontal(); // Type var dataSetTypes = ReflectionUtils.GetAssignableConcreteClasses(typeof(EntityFileAsset)); var setTypes = dataSetTypes as Type[] ?? dataSetTypes.ToArray(); var options = from assetType in setTypes select assetType.Name.Substring(0, assetType.Name.Length - 5); this.typeIndex = EditorGUILayout.Popup("Type", this.typeIndex, options.ToArray()); // Name this.name = EditorGUILayout.TextField("Name", this.name); // Input validation if (string.IsNullOrEmpty(this.name)) { GUI.enabled = false; } if (this.forbiddenNames.Contains(this.name)) { GUI.enabled = false; } else if (this.package == null) { GUI.enabled = false; } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Create", GUILayout.ExpandWidth(false), GUILayout.Width(100))) { CreateDataSet(this.name, this.package, setTypes.ToArray()[this.typeIndex]); } EditorGUILayout.EndHorizontal(); }
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); }
public bool SavePackage(PackageDefinition definition) { if (definition == null) { throw new ArgumentNullException(nameof(definition)); } XDocument packagesXml = EnsureStorage(out var packagesFile); if (packagesXml?.Root == null) { return(false); } // ensure it's valid ValidatePackage(definition); if (definition.Id == default) { // need to gen an id and persist // Find max id var maxId = packagesXml.Root.Elements("package").Max(x => x.AttributeValue <int?>("id")) ?? 0; var newId = maxId + 1; definition.Id = newId; definition.PackageId = definition.PackageId == default ? Guid.NewGuid() : definition.PackageId; XElement packageXml = _parser.ToXml(definition); packagesXml.Root.Add(packageXml); } else { // existing XElement?packageXml = packagesXml.Root.Elements("package") .FirstOrDefault(x => x.AttributeValue <int>("id") == definition.Id); if (packageXml == null) { return(false); } XElement updatedXml = _parser.ToXml(definition); packageXml.ReplaceWith(updatedXml); } packagesXml.Save(packagesFile); return(true); }
public InstallationSummary InstallPackageData(PackageDefinition packageDefinition, CompiledPackage compiledPackage, int userId) { var installationSummary = _packageDataInstallation.InstallPackageData(compiledPackage, userId); installationSummary.Actions = CompiledPackageXmlParser.GetPackageActions(XElement.Parse(compiledPackage.Actions), compiledPackage.Name); installationSummary.MetaData = compiledPackage; installationSummary.FilesInstalled = packageDefinition.Files; //make sure the definition is up to date with everything foreach (var x in installationSummary.DataTypesInstalled) { packageDefinition.DataTypes.Add(x.Id.ToInvariantString()); } foreach (var x in installationSummary.LanguagesInstalled) { packageDefinition.Languages.Add(x.Id.ToInvariantString()); } foreach (var x in installationSummary.DictionaryItemsInstalled) { packageDefinition.DictionaryItems.Add(x.Id.ToInvariantString()); } foreach (var x in installationSummary.MacrosInstalled) { packageDefinition.Macros.Add(x.Id.ToInvariantString()); } foreach (var x in installationSummary.TemplatesInstalled) { packageDefinition.Templates.Add(x.Id.ToInvariantString()); } foreach (var x in installationSummary.DocumentTypesInstalled) { packageDefinition.DocumentTypes.Add(x.Id.ToInvariantString()); } foreach (var x in installationSummary.StylesheetsInstalled) { packageDefinition.Stylesheets.Add(x.Id.ToInvariantString()); } var contentInstalled = installationSummary.ContentInstalled.ToList(); packageDefinition.ContentNodeId = contentInstalled.Count > 0 ? contentInstalled[0].Id.ToInvariantString() : null; //run package actions installationSummary.ActionErrors = RunPackageActions(packageDefinition, installationSummary.Actions).ToList(); return(installationSummary); }
public void Install_Data() { var package = PackageInstallation.ReadPackage( //this is where our test zip file is new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); var def = PackageDefinition.FromCompiledPackage(package); def.Id = 1; def.PackageId = Guid.NewGuid(); var summary = PackageInstallation.InstallPackageData(def, package, -1); Assert.AreEqual(1, summary.DataTypesInstalled.Count()); //make sure the def is updated too Assert.AreEqual(summary.DataTypesInstalled.Count(), def.DataTypes.Count); }
private void PackageStylesheets(PackageDefinition definition, XContainer root) { var stylesheetsXml = new XElement("Stylesheets"); foreach (var stylesheetName in definition.Stylesheets) { if (stylesheetName.IsNullOrWhiteSpace()) { continue; } var xml = GetStylesheetXml(stylesheetName, true); if (xml != null) { stylesheetsXml.Add(xml); } } root.Add(stylesheetsXml); }
private void PackageDataTypes(PackageDefinition definition, XContainer root) { var dataTypes = new XElement("DataTypes"); foreach (var dtId in definition.DataTypes) { if (!int.TryParse(dtId, out var outInt)) { continue; } var dataType = _dataTypeService.GetDataType(outInt); if (dataType == null) { continue; } dataTypes.Add(_serializer.Serialize(dataType)); } root.Add(dataTypes); }
private void PackageLanguages(PackageDefinition definition, XContainer root) { var languages = new XElement("Languages"); foreach (var langId in definition.Languages) { if (!int.TryParse(langId, out var outInt)) { continue; } var lang = _languageService.GetLanguageById(outInt); if (lang == null) { continue; } languages.Add(_serializer.Serialize(lang)); } root.Add(languages); }
private void PackageDictionaryItems(PackageDefinition definition, XContainer root) { var dictionaryItems = new XElement("DictionaryItems"); foreach (var dictionaryId in definition.DictionaryItems) { if (!int.TryParse(dictionaryId, out var outInt)) { continue; } var di = _languageService.GetDictionaryItemById(outInt); if (di == null) { continue; } dictionaryItems.Add(_serializer.Serialize(di, false)); } root.Add(dictionaryItems); }
private void PackageTemplates(PackageDefinition definition, XContainer root) { var templatesXml = new XElement("Templates"); foreach (var templateId in definition.Templates) { if (!int.TryParse(templateId, out var outInt)) { continue; } var template = _fileService.GetTemplate(outInt); if (template == null) { continue; } templatesXml.Add(_serializer.Serialize(template)); } root.Add(templatesXml); }
/// <summary> /// Creates or updates a package /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult <PackageDefinition> PostSavePackage(PackageDefinition model) { if (ModelState.IsValid == false) { return(ValidationProblem(ModelState)); } // Save it if (!_packagingService.SaveCreatedPackage(model)) { return(ValidationProblem( model.Id == default ? $"A package with the name {model.Name} already exists" : $"The package with id {model.Id} was not found")); } // The packagePath will be on the model return(model); }
public void Delete() { var def1 = new PackageDefinition { Name = "test", Url = "http://test.com", Author = "Someone", AuthorUrl = "http://test.com" }; var result = PackageBuilder.SavePackage(def1); Assert.IsTrue(result); PackageBuilder.Delete(def1.Id); def1 = PackageBuilder.GetById(def1.Id); Assert.IsNull(def1); }
MakePackage() { var packageDir = Graph.Instance.ProcessState.WorkingDirectory; var bamDir = System.IO.Path.Combine(packageDir, BamSubFolder); if (System.IO.Directory.Exists(bamDir)) { throw new Exception("Cannot create new package: A Bam package already exists at {0}", packageDir); } var packageNameArgument = new Options.PackageName(); var packageName = CommandLineProcessor.Evaluate(packageNameArgument); if (null == packageName) { throw new Exception("Cannot create new package: No name was defined. Use {0} on the command line to specify it.", (packageNameArgument as ICommandLineArgument).LongName); } var packageVersion = CommandLineProcessor.Evaluate(new Options.PackageVersion()); var definition = new PackageDefinition(bamDir, packageName, packageVersion); IOWrapper.CreateDirectory(bamDir); definition.Write(); var scriptsDir = System.IO.Path.Combine(bamDir, ScriptsSubFolder); IOWrapper.CreateDirectory(scriptsDir); var initialScriptFile = System.IO.Path.Combine(scriptsDir, packageName) + ".cs"; using (System.IO.TextWriter writer = new System.IO.StreamWriter(initialScriptFile)) { writer.NewLine = "\n"; writer.WriteLine("using Bam.Core;"); writer.WriteLine("namespace {0}", packageName); writer.WriteLine("{"); writer.WriteLine(" // write modules here ..."); writer.WriteLine("}"); } Log.Info("Package {0} was successfully created at {1}", definition.FullName, packageDir); }
private PackageDefinition GetPackageDefinition() { var definition = new PackageDefinition { Name = Name, Readme = Description, Version = Version.ToString(), Author = Author, AuthorUrl = AuthorUrl, Url = ProjectUrl, IconUrl = IconUrl, LicenseUrl = LicenseUrl }; if (System.Version.TryParse(UmbracoVersion, out Version umbracoVersion)) { definition.UmbracoVersion = umbracoVersion; } return(definition); }
public XDocument ExportPackage(PackageDefinition definition) { ValidatePackage(definition); var root = new XElement("umbPackage"); var info = new XElement("info"); info.Add(GetPackageInfo(definition)); info.Add(GetAuthor(definition)); info.Add(GetReadme(definition)); root.Add(info); root.Add(GetFiles(definition)); root.Add(GetPackageView(definition)); var doc = new XDocument(root); return(doc); }
public void Install_Files() { var package = PackageInstallation.ReadPackage( //this is where our test zip file is new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); var def = PackageDefinition.FromCompiledPackage(package); def.Id = 1; def.PackageId = Guid.NewGuid(); def.Files = new List <string>(); //clear out the files of the def for testing, this should be populated by the install var result = PackageInstallation.InstallPackageFiles(def, package, -1).ToList(); Assert.AreEqual(1, result.Count); Assert.AreEqual("bin\\Auros.DocumentTypePicker.dll", result[0]); Assert.IsTrue(File.Exists(Path.Combine(IOHelper.MapPath("~/" + _testBaseFolder), result[0]))); //make sure the def is updated too Assert.AreEqual(result.Count, def.Files.Count); }
private static XElement GetRequirements(PackageDefinition definition) { var requirements = new XElement("requirements"); if (definition.UmbracoVersion != null) { requirements.Add(new XElement("major", definition.UmbracoVersion.Major)); requirements.Add(new XElement("minor", definition.UmbracoVersion.Minor)); requirements.Add(new XElement("patch", definition.UmbracoVersion.Build)); requirements.Add(new XAttribute("type", RequirementsType.Strict.ToString())); } else { requirements.Add(new XElement("major", UmbracoVersion.SemanticVersion.Major)); requirements.Add(new XElement("minor", UmbracoVersion.SemanticVersion.Minor)); requirements.Add(new XElement("patch", UmbracoVersion.SemanticVersion.Patch)); } return(requirements); }
public InstallationSummary InstallCompiledPackageData(PackageDefinition packageDefinition, FileInfo packageFile, int userId = Constants.Security.SuperUserId) { if (packageDefinition == null) { throw new ArgumentNullException(nameof(packageDefinition)); } if (packageDefinition.Id == default) { throw new ArgumentException("The package definition has not been persisted"); } if (packageDefinition.Name == default) { throw new ArgumentException("The package definition has incomplete information"); } var compiledPackage = GetCompiledPackageInfo(packageFile); if (compiledPackage == null) { throw new InvalidOperationException("Could not read the package file " + packageFile); } if (ImportingPackage.IsRaisedEventCancelled(new ImportPackageEventArgs <string>(packageFile.Name, compiledPackage), this)) { return new InstallationSummary { MetaData = compiledPackage } } ; var summary = _packageInstallation.InstallPackageData(packageDefinition, compiledPackage, userId); SaveInstalledPackage(packageDefinition); _auditService.Add(AuditType.PackagerInstall, userId, -1, "Package", $"Package data installed for package '{compiledPackage.Name}'."); ImportedPackage.RaiseEvent(new ImportPackageEventArgs <InstallationSummary>(summary, compiledPackage, false), this); return(summary); }
private void PackageLanguages(PackageDefinition definition, XContainer root) { var languages = new XElement("Languages"); foreach (var langId in definition.Languages) { if (!int.TryParse(langId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt)) { continue; } ILanguage?lang = _localizationService.GetLanguageById(outInt); if (lang == null) { continue; } languages.Add(_serializer.Serialize(lang)); } root.Add(languages); }
/// <summary> /// Creates or updates a package /// </summary> /// <param name="model"></param> /// <returns></returns> public PackageDefinition PostSavePackage(PackageDefinition model) { if (ModelState.IsValid == false) { throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState)); } //save it if (!Services.PackagingService.SaveCreatedPackage(model)) { throw new HttpResponseException( Request.CreateNotificationValidationErrorResponse( model.Id == default ? $"A package with the name {model.Name} already exists" : $"The package with id {model.Id} was not found")); } Services.PackagingService.ExportCreatedPackage(model); //the packagePath will be on the model return(model); }
void AddLocalContentParts(Package package, PackageDefinition manifest, LayoutDefinition layout, string baseDirectory, string relativeDirectory) { var currentDirectory = Path.Combine(baseDirectory, relativeDirectory); foreach (var file in fileSystem.EnumerateFiles(currentDirectory)) { var uniqueFileName = Guid.NewGuid().ToString("N"); var partUri = new Uri("LocalContent/" + uniqueFileName, UriKind.Relative); AddContent(package, manifest, partUri, file); //add file definition var fileDate = DateTime.UtcNow; //todo: use original timestamps if un-modified layout.FileDefinitions.Add( new FileDefinition { FilePath = "\\" + Path.Combine(relativeDirectory, Path.GetFileName(file)), Description = new FileDescription { DataContentReference = partUri.ToString(), ReadOnly = false, Created = fileDate, Modified = fileDate } }); } foreach (var subDirectory in Directory.GetDirectories(currentDirectory).Select(x => new DirectoryInfo(x))) { AddLocalContentParts(package, manifest, layout, baseDirectory, Path.Combine(relativeDirectory, subDirectory.Name)); } }
public void SortTopologically_returns_dependency_package_before_the_package_itself_regardless_of_addition_order_to_graph() { Graph graph = new Graph(); PackageDefinition definitionB = new PackageDefinition("B"); PackageDefinition definitionA = new PackageDefinition("A:B"); graph.AddPackageDefinition(definitionB); graph.AddPackageDefinition(definitionA); Queue<string> sortedQueue = graph.SortTopologically(); Assert.AreEqual(2, sortedQueue.Count); Assert.AreEqual(definitionB.Package, sortedQueue.Dequeue()); Assert.AreEqual(definitionA.Package, sortedQueue.Dequeue()); }
public void SortTopologically_returns_dependency_package_before_the_package_itself_when_multiple_dependencies_involved() { Graph graph = new Graph(); PackageDefinition definitionA = new PackageDefinition("A:B,C,D"); PackageDefinition definitionB = new PackageDefinition("B:C"); PackageDefinition definitionC = new PackageDefinition("C"); PackageDefinition definitionD = new PackageDefinition("D"); graph.AddPackageDefinition(definitionA); graph.AddPackageDefinition(definitionC); graph.AddPackageDefinition(definitionB); graph.AddPackageDefinition(definitionD); Queue<string> sortedQueue = graph.SortTopologically(); Assert.AreEqual(4, sortedQueue.Count); Assert.AreEqual(definitionC.Package, sortedQueue.Dequeue()); Assert.AreEqual(definitionB.Package, sortedQueue.Dequeue()); Assert.AreEqual(definitionD.Package, sortedQueue.Dequeue()); Assert.AreEqual(definitionA.Package, sortedQueue.Dequeue()); }
public void SortTopologically_returns_the_node_if_it_has_no_dependency_list() { Graph graph = new Graph(); PackageDefinition definition = new PackageDefinition("A"); graph.AddPackageDefinition(definition); Queue<string> sortedQueue = graph.SortTopologically(); Assert.IsTrue(sortedQueue.Count == 1); Assert.AreEqual(definition.Package, sortedQueue.Peek()); }
private bool ExtractExcelPackages(Workbook xlWorkbook) { log.Log("Extract Packages to local variables - start"); //THIS IS NEW PROCESSING TO USE XLS INSTEAD OF TXT FORMAT _Worksheet sheet = xlWorkbook.Sheets[1]; Range xlRange = sheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; string oldName = ""; log.Log("Importing Packages - start"); try { //iterate through all columns/rows in xls for (int i = 2; i != rowCount + 1; i++) { PackageDefinition package = new PackageDefinition(); int count = 3; package.Name = sheet.Cells[i, count].Value2.ToString(); count++; package.LineType = sheet.Cells[i, count].Value2.ToString(); count++; package.CodeLine = Convert.ToInt32(sheet.Cells[i, count].Value2); count++; package.Body = sheet.Cells[i, count].Value2.ToString(); package.PackageType = "Undefined"; //write processing output to same line if (!oldName.Equals(package.Name)) { log.Log(String.Format("Reading Package {0} \r", package.Name)); oldName = package.Name; } _packages.Add(package); } log.Log("Extract Packages to local variables - complete"); } catch (Exception e) { log.Log(string.Format("Error reading Package file: {0}", e)); return false; } return true; }
public void SortTopologically_throws_exception_if_package_definitions_contain_cycle_even_for_more_complex_scenarios() { Graph graph = new Graph(); PackageDefinition definitionA = new PackageDefinition("A:B, C"); PackageDefinition definitionD = new PackageDefinition("D:A"); PackageDefinition definitionB = new PackageDefinition("B:C"); PackageDefinition definitionC = new PackageDefinition("C:E"); PackageDefinition definitionE = new PackageDefinition("E:D"); graph.AddPackageDefinition(definitionA); graph.AddPackageDefinition(definitionB); graph.AddPackageDefinition(definitionC); graph.AddPackageDefinition(definitionD); graph.AddPackageDefinition(definitionE); Assert.Throws<InvalidOperationException>(() => graph.SortTopologically()); }
void AddPackageManifest(Package package, PackageDefinition manifest) { var manifestPartUri = PackUriHelper.CreatePartUri(new Uri("/package.xml", UriKind.Relative)); var manifestPart = package.CreatePart(manifestPartUri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum); using (var manifestPartStream = manifestPart.GetStream()) { manifest.ToXml().Save(manifestPartStream); } package.CreateRelationship(manifestPartUri, TargetMode.External, AzureCloudServiceConventions.CtpFormatPackageDefinitionRelationshipType); }
void AddLocalContent(Package package, PackageDefinition manifest, string workingDirectory) { foreach (var roleDirectory in fileSystem.EnumerateDirectories(Path.Combine(workingDirectory, "LocalContent"))) { var layout = new LayoutDefinition {Name = "Roles/" + new DirectoryInfo(roleDirectory).Name}; manifest.Layouts.Add(layout); AddLocalContentParts(package, manifest, layout, roleDirectory, ""); } }
public void SortTopologicallyAsString_returns_the_node_if_it_has_no_dependency_list() { Graph graph = new Graph(); PackageDefinition definition = new PackageDefinition("A"); graph.AddPackageDefinition(definition); string sortedList = graph.SortTopologicallyAsString(); Assert.AreEqual("A", sortedList); }
public void SortTopologicallyAsString_throws_exception_if_package_definitions_contain_cycle() { Graph graph = new Graph(); PackageDefinition definitionA = new PackageDefinition("A:B"); PackageDefinition definitionB = new PackageDefinition("B:A"); graph.AddPackageDefinition(definitionA); graph.AddPackageDefinition(definitionB); Assert.Throws<InvalidOperationException>(() => graph.SortTopologically()); }
void AddParts(Package package, PackageDefinition manifest, string directory, string baseDataStorePath) { foreach (var file in fileSystem.EnumerateFiles(directory)) { var partUri = new Uri(baseDataStorePath + "/" + Path.GetFileName(file), UriKind.Relative); AddContent(package, manifest, partUri, file); } foreach (var subDirectory in fileSystem.EnumerateDirectories(directory).Select(x => new DirectoryInfo(x))) { AddParts(package, manifest, subDirectory.FullName, baseDataStorePath + "/" + subDirectory.Name); } }
public void Contains_returns_false_if_PackageDefinition_does_not_exist() { Graph graph = new Graph(); PackageDefinition definition = new PackageDefinition("A"); Assert.IsFalse(graph.Contains(definition.Package)); }