Exemple #1
0
 /// <summary>
 /// Registers automation methods.
 /// </summary>
 public override void Init()
 {
     AutomationMethods.RegisterMethods();
 }
        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);
            }
        }
 public AutomationHelper(IntPtr handle, AutomationMethods method)
 {
     _myHandle = handle;
     _myMethod = method;
 }
 public AutomationHelper(IntPtr handle, AutomationMethods method)
 {
     _myHandle = handle;
     _myMethod = method;
 }
Exemple #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);
            }
        }