예제 #1
0
 public SpecificationBuilder WithContentFiles(ManifestContentFiles files)
 {
     if (files == null)
     {
         throw new ArgumentNullException(nameof(files));
     }
     Specification.ContentFiles.Add(files);
     return(this);
 }
        private static XElement GetXElementFromManifestContentFile(XNamespace ns, ManifestContentFiles file)
        {
            var attributes = new List <XAttribute>();

            attributes.Add(GetXAttributeFromNameAndValue("include", file.Include));
            attributes.Add(GetXAttributeFromNameAndValue("exclude", file.Exclude));
            attributes.Add(GetXAttributeFromNameAndValue("buildAction", file.BuildAction));
            attributes.Add(GetXAttributeFromNameAndValue("copyToOutput", file.CopyToOutput));
            attributes.Add(GetXAttributeFromNameAndValue("flatten", file.Flatten));

            attributes = attributes.Where(xAtt => xAtt != null).ToList();

            return(new XElement(ns + Files, attributes));
        }
        private void AddContentFiles(PackageBuilder builder)
        {
            foreach (var sourcePath in PackTargetArgs.ContentFiles.Keys)
            {
                var listOfContentMetadata = PackTargetArgs.ContentFiles[sourcePath];
                foreach (var contentMetadata in listOfContentMetadata)
                {
                    string target      = contentMetadata.Target;
                    var    packageFile = new ManifestFile()
                    {
                        Source = sourcePath,
                        Target = target.EndsWith(Path.DirectorySeparatorChar.ToString()) || string.IsNullOrEmpty(target)
                        ? Path.Combine(target, Path.GetFileName(sourcePath))
                        : target
                    };
                    AddFileToBuilder(packageFile);

                    // Add contentFiles entry to the nuspec if applicable
                    if (IsContentFile(contentMetadata.Target))
                    {
                        var includePath = PathUtility.GetRelativePath("contentFiles" + Path.DirectorySeparatorChar, packageFile.Target, '/');
                        // This is just a check to see if the filename has already been appended to the target path.
                        // We do this by comparing extensions of the file
                        if (!Path.GetExtension(includePath)
                            .Equals(Path.GetExtension(sourcePath), StringComparison.OrdinalIgnoreCase))
                        {
                            includePath = Path.Combine(includePath, Path.GetFileName(sourcePath));
                        }

                        var manifestContentFile = new ManifestContentFiles()
                        {
                            BuildAction  = contentMetadata.BuildAction,
                            Include      = includePath,
                            CopyToOutput = contentMetadata.CopyToOutput,
                            Flatten      = contentMetadata.Flatten
                        };

                        builder.ContentFiles.Add(manifestContentFile);
                    }
                }
            }
        }
        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);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        private bool PublishProject()
        {
            try
            {
                string[] scriptFiles = Directory.GetFiles(_projectPath, "*.json", 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          = _projectId.ToString(),
                    Title       = _projectName,
                    Authors     = txtAuthorName.Text.Trim(),
                    Version     = txtVersion.Text.Trim(),
                    Description = txtDescription.Text.Trim(),
                    RequireLicenseAcceptance = false,
                    DependencySets           = new List <ManifestDependencySet>()
                    {
                        new ManifestDependencySet()
                        {
                            Dependencies = new List <ManifestDependency>()
                            {
                                new ManifestDependency()
                                {
                                    Id      = "OpenBots.Studio",
                                    Version = new Version(Application.ProductVersion).ToString()
                                }
                            }
                        }
                    },
                    ContentFiles = manifestFiles,
                };

                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";

                try {
                    lblError.Text = $"Publishing {_projectName} to the server...";
                    var client = AuthMethods.GetAuthToken();
                    ProcessMethods.UploadProcess(client, _projectName, nugetFilePath);
                }
                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);
            }
        }