private static List <ManifestDependencySet> CreateManifestDependencySet(IPackage package, string destination) { List <ManifestDependencySet> depSetList = new List <ManifestDependencySet>(); ManifestDependencySet depSet = new ManifestDependencySet(); List <ManifestDependency> depList = new List <ManifestDependency>(); var dependencies = from dSets in package.DependencySets from d in dSets.Dependencies select d; foreach (var d in dependencies) { ManifestDependency manDep = new ManifestDependency(); manDep.Id = d.Id; manDep.Exclude = d.Exclude; manDep.Include = d.Include; manDep.Version = GetLatestPackageVersion(d.Id, d.VersionSpec.ToString(), destination); depList.Add(manDep); } depSet.Dependencies = depList; depSetList.Add(depSet); return(depSetList); }
private static void AssertDependency(ManifestDependency expected, ManifestDependency actual) { Assert.Equal(expected.Id, actual.Id); Assert.Equal(expected.Version, actual.Version); }
private bool PublishProject() { try { string[] scriptFiles = SystemFile.Directory.GetFiles(_projectPath, "*.*", SystemFile.SearchOption.AllDirectories); List <ManifestContentFiles> manifestFiles = new List <ManifestContentFiles>(); foreach (string file in scriptFiles) { ManifestContentFiles manifestFile = new ManifestContentFiles { Include = file.Replace(_projectPath, "") }; manifestFiles.Add(manifestFile); } ManifestMetadata metadata = new ManifestMetadata() { Id = _projectName.Replace(" ", "_"), Title = _projectName, Authors = txtAuthorName.Text.Trim(), Version = txtVersion.Text.Trim(), Description = txtDescription.Text.Trim(), RequireLicenseAcceptance = false, IconUrl = "https://openbots.ai/wp-content/uploads/2020/11/Studio-Icon-256px.png", DependencySets = new List <ManifestDependencySet>() { new ManifestDependencySet() { Dependencies = new List <ManifestDependency>() { new ManifestDependency() { Id = "OpenBots.Studio", Version = new Version(Application.ProductVersion).ToString() }, } } }, ContentFiles = manifestFiles, }; foreach (var dependency in _projectDependencies) { var dep = new ManifestDependency { Id = dependency.Key, Version = dependency.Value }; metadata.DependencySets[0].Dependencies.Add(dep); } PackageBuilder builder = new PackageBuilder(); builder.PopulateFiles(_projectPath, new[] { new ManifestFile() { Source = "**" } }); builder.Populate(metadata); if (!SystemFile.Directory.Exists(txtLocation.Text)) { SystemFile.Directory.CreateDirectory(txtLocation.Text); } string nugetFilePath = SystemFile.Path.Combine(txtLocation.Text.Trim(), $"{_projectName}_{txtVersion.Text.Trim()}.nupkg"); using (SystemFile.FileStream stream = File.Open(nugetFilePath, SystemFile.FileMode.OpenOrCreate)) builder.Save(stream); NotificationMessage = $"'{_projectName}' published successfully"; if (cbxLocation.Text == "Local Only") { return(true); } try { lblError.Text = $"Publishing {_projectName} to the server..."; var environmentSettings = new EnvironmentSettings(); environmentSettings.Load(); AuthMethods authMethods = new AuthMethods(); authMethods.Initialize(environmentSettings.ServerType, environmentSettings.OrganizationName, environmentSettings.ServerUrl, environmentSettings.Username, environmentSettings.Password); var automation = AutomationMethods.UploadAutomation(_projectName, nugetFilePath, _automationEngine, authMethods); if (_projectArguments.Count > 0) { IEnumerable <AutomationParameter> automationParameters = _projectArguments.Select(arg => new AutomationParameter() { Name = arg.ArgumentName, DataType = GetServerType(arg.ArgumentType), Value = arg.ArgumentValue?.ToString(), AutomationId = automation.Id }); AutomationMethods.UpdateParameters(automation.Id, automationParameters, authMethods); } } catch (Exception ex) { if (ex.Message != "Agent is not connected" && !string.IsNullOrEmpty(ex.InnerException.Message)) { NotificationMessage = $"'{_projectName}' was published locally. To publish to an OpenBots Server please install and connect the OpenBots Agent." + $" Error: {ex.InnerException.Message}"; } else { NotificationMessage = $"'{_projectName}' was published locally. To publish to an OpenBots Server please install and connect the OpenBots Agent." + $" Error: {ex.Message}"; } } return(true); } catch (Exception ex) { lblError.Text = ex.Message; return(false); } }
private IEnumerable<ManifestDependency> GenerateDependencies(IEnumerable<string> specifiedDependencies, string binFolderPath, string sitecoreReleaseVersion, IEnumerable<string> singleDLLPackages, IEnumerable<string> customPackages, string packageNamePrefix) { var confirmedDependencies = new List<ManifestDependency>(); var packageDiscoverer = new ThirdPartyPackageDiscoverer(); foreach (string dependencyPackage in specifiedDependencies) { // check if the dependency starts with 'Sitecore', does it exist in the singleDLLpackages // i.e is it a Sitecore package and does it exist in this Sitecore version? if (dependencyPackage.StartsWith("Sitecore")) { if (singleDLLPackages.Any(x => x.EndsWith(dependencyPackage + "." + sitecoreReleaseVersion + ".nupkg")) || customPackages.Any(x => x.EndsWith(dependencyPackage + "." + sitecoreReleaseVersion + ".nupkg"))) { confirmedDependencies.Add(new ManifestDependency() { Id = packageNamePrefix + dependencyPackage, Version = sitecoreReleaseVersion }); } } else { bool isMvcPackage = dependencyPackage == "Microsoft.AspNet.Mvc"; bool isWebApiPackage = dependencyPackage == "Microsoft.AspNet.WebApi"; bool isSitecoreZipWithoutMvcDLLs = sitecoreReleaseVersion.StartsWith("7.1") || sitecoreReleaseVersion.StartsWith("7.0") || sitecoreReleaseVersion.StartsWith("6"); bool isSitecoreZipWithoutWebApiDLLs = sitecoreReleaseVersion.StartsWith("7.2") || sitecoreReleaseVersion.StartsWith("7.1") || sitecoreReleaseVersion.StartsWith("7.0") || sitecoreReleaseVersion.StartsWith("6"); // if you're using Sitecore 5 or earlier, a Nuget package generator is the last thing you need to worry about ManifestDependency publicNugetPackage = null; if (isWebApiPackage && isSitecoreZipWithoutWebApiDLLs) { publicNugetPackage = new ManifestDependency() { Id = dependencyPackage, Version = "4.0.30506" }; } else if (isMvcPackage && isSitecoreZipWithoutMvcDLLs) { if (sitecoreReleaseVersion.StartsWith("7.1")) { publicNugetPackage = new ManifestDependency() { Id = dependencyPackage, Version = "4.0.30506" }; } else // if (sitecoreReleaseVersion.StartsWith("7.0") || sitecoreReleaseVersion.StartsWith("6")) { publicNugetPackage = new ManifestDependency() { Id = dependencyPackage, Version = "3.0.20105.1" }; } } else { // check Public Nuget Repo for packages publicNugetPackage = packageDiscoverer.FindPublicThirdPartyNugetPackage(dependencyPackage, binFolderPath); } if (publicNugetPackage != null) { confirmedDependencies.Add(publicNugetPackage); } } } return confirmedDependencies; }
static Manifest InitiateManifestFromAssembly(Assembly assembly, IEnumerable <PackageReference> deps) { Manifest manifest = new Manifest(); AssemblyInfo ainfo = new AssemblyInfo(assembly); //Version manifest.Metadata.Version = ManifestVersionFromAssembly(ainfo); // Copyright manifest.Metadata.Copyright = ainfo.Copyright; // Authors if (ainfo.Authors != null) { manifest.Metadata.Authors = ainfo.Authors.Keys.Aggregate((key, next) => key + "," + next); manifest.Metadata.Owners = ainfo.Authors.Keys.Aggregate((key, next) => key + "," + next); } // Description manifest.Metadata.Description = ainfo.Description; // Icon Url if (ainfo.IconUrl != null) { manifest.Metadata.IconUrl = ainfo.IconUrl.ToString(); } // Id manifest.Metadata.Id = ainfo.ProductTitle; // License Url if (ainfo.LicenseUrl != null) { manifest.Metadata.LicenseUrl = ainfo.LicenseUrl.ToString(); } // Project Url if (ainfo.ProjectUrl != null) { manifest.Metadata.ProjectUrl = ainfo.ProjectUrl.ToString(); } // Tags manifest.Metadata.Tags = ainfo.Tags; // Title manifest.Metadata.Title = ainfo.ProductTitle; // Dependencies if (deps != null) { manifest.Metadata.DependencySets = new List <ManifestDependencySet>(); NetPortableProfile npp = new NetPortableProfile(ainfo.TargetFramework, new FrameworkName[1] { new FrameworkName(ainfo.TargetFramework) }); ManifestDependencySet mds = new ManifestDependencySet(); mds.Dependencies = new List <ManifestDependency>(); mds.TargetFramework = npp.CustomProfileString; manifest.Metadata.DependencySets.Add(mds); foreach (var dep in deps) { ManifestDependency md = new ManifestDependency(); md.Id = dep.Id; md.Version = dep.Version.ToNormalizedString(); mds.Dependencies.Add(md); } } return(manifest); }
private bool PublishProject() { try { string[] scriptFiles = Directory.GetFiles(_projectPath, "*.*", SearchOption.AllDirectories); List <ManifestContentFiles> manifestFiles = new List <ManifestContentFiles>(); foreach (string file in scriptFiles) { ManifestContentFiles manifestFile = new ManifestContentFiles { Include = file.Replace(_projectPath, "") }; manifestFiles.Add(manifestFile); } ManifestMetadata metadata = new ManifestMetadata() { Id = _projectName.Replace(" ", "_"), Title = _projectName, Authors = txtAuthorName.Text.Trim(), Version = txtVersion.Text.Trim(), Description = txtDescription.Text.Trim(), RequireLicenseAcceptance = false, IconUrl = "https://openbots.ai/wp-content/uploads/2020/11/Studio-Icon-256px.png", DependencySets = new List <ManifestDependencySet>() { new ManifestDependencySet() { Dependencies = new List <ManifestDependency>() { new ManifestDependency() { Id = "OpenBots.Studio", Version = new Version(Application.ProductVersion).ToString() }, } } }, ContentFiles = manifestFiles, }; foreach (var dependency in _projectDependencies) { var dep = new ManifestDependency { Id = dependency.Key, Version = dependency.Value }; metadata.DependencySets[0].Dependencies.Add(dep); } PackageBuilder builder = new PackageBuilder(); builder.PopulateFiles(_projectPath, new[] { new ManifestFile() { Source = "**" } }); builder.Populate(metadata); if (!Directory.Exists(txtLocation.Text)) { Directory.CreateDirectory(txtLocation.Text); } string nugetFilePath = Path.Combine(txtLocation.Text.Trim(), $"{_projectName}_{txtVersion.Text.Trim()}.nupkg"); using (FileStream stream = File.Open(nugetFilePath, FileMode.OpenOrCreate)) builder.Save(stream); NotificationMessage = $"'{_projectName}' published successfully"; if (cbxLocation.Text == "Local Only") { return(true); } try { lblError.Text = $"Publishing {_projectName} to the server..."; var client = AuthMethods.GetAuthToken(); AutomationMethods.UploadAutomation(client, _projectName, nugetFilePath, _automationEngine); } catch (Exception) { NotificationMessage = $"'{_projectName}' was published locally. To publish to an OpenBots Server please install and connect the OpenBots Agent."; } return(true); } catch (Exception ex) { lblError.Text = ex.Message; return(false); } }