public override void RunCommand(object sender)
        {
            var engine                 = (IAutomationEngineInstance)sender;
            var vQueueItem             = (Dictionary <string, object>)v_QueueItem.ConvertUserVariableToObject(engine, nameof(v_QueueItem), this);
            var vQueueItemErrorMessage = v_QueueItemErrorMessage.ConvertUserVariableToString(engine);
            var vQueueItemErrorCode    = v_QueueItemErrorCode.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();

            Guid transactionKey = (Guid)vQueueItem["LockTransactionKey"];

            if (transactionKey == null || transactionKey == Guid.Empty)
            {
                throw new NullReferenceException($"Transaction key {transactionKey} is invalid or not found");
            }

            switch (v_QueueItemStatusType)
            {
            case "Successful":
                QueueItemMethods.CommitQueueItem(client, transactionKey);
                break;

            case "Failed - Should Retry":
                QueueItemMethods.RollbackQueueItem(client, transactionKey, vQueueItemErrorCode, vQueueItemErrorMessage, false);
                break;

            case "Failed - Fatal":
                QueueItemMethods.RollbackQueueItem(client, transactionKey, vQueueItemErrorCode, vQueueItemErrorMessage, true);
                break;
            }
        }
Ejemplo n.º 2
0
        public override void RunCommand(object sender)
        {
            var engine                 = (AutomationEngineInstance)sender;
            var vQueueItem             = (Dictionary <string, object>)v_QueueItem.ConvertUserVariableToObject(engine);
            var vQueueItemErrorMessage = v_QueueItemErrorMessage.ConvertUserVariableToString(engine);
            var vQueueItemErrorCode    = v_QueueItemErrorCode.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();

            Guid transactionKey = (Guid)vQueueItem["LockTransactionKey"];

            switch (v_QueueItemStatusType)
            {
            case "Successful":
                QueueItemMethods.CommitQueueItem(client, transactionKey);
                break;

            case "Failed - Should Retry":
                QueueItemMethods.RollbackQueueItem(client, transactionKey, vQueueItemErrorCode, vQueueItemErrorMessage, false);
                break;

            case "Failed - Fatal":
                QueueItemMethods.RollbackQueueItem(client, transactionKey, vQueueItemErrorCode, vQueueItemErrorMessage, true);
                break;
            }
        }
Ejemplo n.º 3
0
        public void WorkQueueItemNoAttachments()
        {
            _engine        = new AutomationEngineInstance(null);
            _addQueueItem  = new AddQueueItemCommand();
            _workQueueItem = new WorkQueueItemCommand();
            VariableMethods.CreateTestVariable(null, _engine, "output", typeof(Dictionary <,>));

            _addQueueItem.v_QueueName          = "UnitTestQueue";
            _addQueueItem.v_QueueItemName      = "WorkQueueItemNoAttachmentTest";
            _addQueueItem.v_QueueItemType      = "Text";
            _addQueueItem.v_JsonType           = "Test Type";
            _addQueueItem.v_QueueItemTextValue = "Test Text";
            _addQueueItem.v_Priority           = "10";

            _addQueueItem.RunCommand(_engine);

            _workQueueItem.v_QueueName = "UnitTestQueue";
            _workQueueItem.v_OutputUserVariableName = "{output}";
            _workQueueItem.v_SaveAttachments        = "No";
            _workQueueItem.v_AttachmentDirectory    = "";

            _workQueueItem.RunCommand(_engine);

            var queueItemObject = (Dictionary <string, object>) "{output}".ConvertUserVariableToObject(_engine, typeof(Dictionary <,>));
            var client          = AuthMethods.GetAuthToken();
            var queueItem       = QueueItemMethods.GetQueueItemByLockTransactionKey(client, queueItemObject["LockTransactionKey"].ToString());

            Assert.Equal("InProgress", queueItem.State);
        }
Ejemplo n.º 4
0
        public override void RunCommand(object sender)
        {
            var engine            = (IAutomationEngineInstance)sender;
            var vAssetName        = v_AssetName.ConvertUserVariableToString(engine);
            var vAssetActionValue = v_AssetActionValue.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();
            var asset  = AssetMethods.GetAsset(client, vAssetName, "Number");

            if (asset == null)
            {
                throw new DataException($"No Asset was found for '{vAssetName}' and type 'Number'");
            }

            switch (v_AssetActionType)
            {
            case "Increment":
                AssetMethods.IncrementAsset(client, asset.Id);
                break;

            case "Decrement":
                AssetMethods.DecrementAsset(client, asset.Id);
                break;

            case "Add":
                AssetMethods.AddAsset(client, asset.Id, vAssetActionValue);
                break;

            case "Subtract":
                AssetMethods.SubtractAsset(client, asset.Id, vAssetActionValue);
                break;
            }
        }
Ejemplo n.º 5
0
        public void SetFailedFatallyStatus()
        {
            _engine       = new AutomationEngineInstance(null);
            _setQueueItem = new SetQueueItemStatusCommand();

            string name = "FailedQueueItem";

            AddQueueItem(name);
            var queueItemDict = WorkQueueItem();

            var client         = AuthMethods.GetAuthToken();
            var transactionKey = queueItemDict["LockTransactionKey"].ToString();
            var queueItem      = QueueItemMethods.GetQueueItemByLockTransactionKey(client, transactionKey);

            VariableMethods.CreateTestVariable(null, _engine, "vQueueItem", typeof(Dictionary <,>));
            _setQueueItem.v_QueueItem = "{vQueueItem}";
            queueItemDict.StoreInUserVariable(_engine, _setQueueItem.v_QueueItem, typeof(Dictionary <,>));
            _setQueueItem.v_QueueItemStatusType = "Failed - Fatal";

            _setQueueItem.RunCommand(_engine);

            queueItem = QueueItemMethods.GetQueueItemById(client, queueItem.Id);

            Assert.Equal("Failed", queueItem.State);
        }
        public override void RunCommand(object sender)
        {
            var engine         = (IAutomationEngineInstance)sender;
            var vAccountName   = v_AccountName.ConvertUserVariableToString(engine);
            var vToRecipients  = v_ToRecipients.ConvertUserVariableToString(engine);
            var vCCRecipients  = v_CCRecipients.ConvertUserVariableToString(engine);
            var vBCCRecipients = v_BCCRecipients.ConvertUserVariableToString(engine);
            var vSubject       = v_Subject.ConvertUserVariableToString(engine);
            var vBody          = v_Body.ConvertUserVariableToString(engine);
            var vAttachments   = v_Attachments.ConvertUserVariableToString(engine);

            var toEmailList  = ServerEmailMethods.GetEmailList(vToRecipients);
            var ccEmailList  = ServerEmailMethods.GetEmailList(vCCRecipients);
            var bccEmailList = ServerEmailMethods.GetEmailList(vBCCRecipients);

            var emailMessage = new EmailMessage()
            {
                To      = toEmailList,
                CC      = ccEmailList,
                BCC     = bccEmailList,
                Subject = vSubject,
                Body    = vBody
            };

            if (string.IsNullOrEmpty(vToRecipients))
            {
                throw new NullReferenceException("To Recipient(s) cannot be empty");
            }

            var client = AuthMethods.GetAuthToken();

            ServerEmailMethods.SendServerEmail(client, emailMessage, vAttachments, vAccountName);
        }
        public override void RunCommand(object sender)
        {
            var engine     = (AutomationEngineInstance)sender;
            var vQueueItem = (Dictionary <string, object>)v_QueueItem.ConvertUserVariableToObject(engine);

            var client = AuthMethods.GetAuthToken();

            Guid transactionKey = (Guid)vQueueItem["LockTransactionKey"];

            QueueItemMethods.ExtendQueueItem(client, transactionKey);
        }
        public override void RunCommand(object sender)
        {
            var engine     = (AutomationEngineInstance)sender;
            var vQueueName = v_QueueName.ConvertUserVariableToString(engine);
            Dictionary <string, object> queueItemDict = new Dictionary <string, object>();

            var client = AuthMethods.GetAuthToken();

            var    settings = EnvironmentSettings.GetAgentSettings();
            string agentId  = settings["AgentId"];

            if (string.IsNullOrEmpty(agentId))
            {
                throw new Exception("Agent is not connected");
            }

            Queue queue = QueueMethods.GetQueue(client, $"name eq '{vQueueName}'");

            if (queue == null)
            {
                throw new Exception($"Queue with name '{vQueueName}' not found");
            }

            var queueItem = QueueItemMethods.DequeueQueueItem(client, Guid.Parse(agentId), queue.Id);

            if (queueItem == null)
            {
                queueItemDict = null;
                queueItemDict.StoreInUserVariable(engine, v_OutputUserVariableName);
                return;
            }


            queueItemDict = queueItem.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
                            .ToDictionary(prop => prop.Name, prop => prop.GetValue(queueItem, null));

            queueItemDict = queueItemDict.Where(kvp => kvp.Key == "LockTransactionKey" ||
                                                kvp.Key == "Name" ||
                                                kvp.Key == "Source" ||
                                                kvp.Key == "Event" ||
                                                kvp.Key == "Type" ||
                                                kvp.Key == "JsonType" ||
                                                kvp.Key == "DataJson" ||
                                                kvp.Key == "Priority" ||
                                                kvp.Key == "LockedUntilUTC")
                            .ToDictionary(i => i.Key, i => i.Value);

            queueItemDict.StoreInUserVariable(engine, v_OutputUserVariableName);
        }
        public override void RunCommand(object sender)
        {
            var engine              = (IAutomationEngineInstance)sender;
            var vQueueName          = v_QueueName.ConvertUserVariableToString(engine);
            var vQueueItemName      = v_QueueItemName.ConvertUserVariableToString(engine);
            var vSource             = v_Source.ConvertUserVariableToString(engine);
            var vEvent              = v_Event.ConvertUserVariableToString(engine);
            var vJsonType           = v_JsonType.ConvertUserVariableToString(engine);
            var vPriority           = v_Priority.ConvertUserVariableToString(engine);
            var vQueueItemTextValue = v_QueueItemTextValue.ConvertUserVariableToString(engine);
            var vAttachments        = v_Attachments.ConvertUserVariableToString(engine);

            var   client = AuthMethods.GetAuthToken();
            Queue queue  = QueueMethods.GetQueue(client, $"name eq '{vQueueName}'");

            if (queue == null)
            {
                throw new DataException($"Queue with name '{vQueueName}' not found");
            }

            int priority = 0;

            if (!string.IsNullOrEmpty(v_Priority))
            {
                priority = int.Parse(vPriority);
            }

            QueueItemModel queueItem = new QueueItemModel()
            {
                IsLocked  = false,
                QueueId   = queue.Id,
                Type      = v_QueueItemType,
                JsonType  = vJsonType,
                DataJson  = vQueueItemTextValue,
                Name      = vQueueItemName,
                IsDeleted = false,
                Priority  = priority,
                Source    = vSource,
                Event     = vEvent
            };

            QueueItemMethods.EnqueueQueueItem(client, queueItem);

            if (!string.IsNullOrEmpty(vAttachments))
            {
                QueueItemMethods.AttachFiles(client, queueItem.Id, vAttachments);
            }
        }
        public override void RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vQueueItem = (Dictionary <string, object>)v_QueueItem.ConvertUserVariableToObject(engine, nameof(v_QueueItem), this);

            var client = AuthMethods.GetAuthToken();

            Guid transactionKey = (Guid)vQueueItem["LockTransactionKey"];

            if (transactionKey == null || transactionKey == Guid.Empty)
            {
                throw new NullReferenceException($"Transaction key {transactionKey} is invalid or not found");
            }

            QueueItemMethods.ExtendQueueItem(client, transactionKey);
        }
Ejemplo n.º 11
0
        public override void RunCommand(object sender)
        {
            var engine      = (IAutomationEngineInstance)sender;
            var vAssetName  = v_AssetName.ConvertUserVariableToString(engine);
            var vAppendText = v_AppendText.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();
            var asset  = AssetMethods.GetAsset(client, vAssetName, "Text");

            if (asset == null)
            {
                throw new DataException($"No Asset was found for '{vAssetName}' with type 'Text'");
            }

            AssetMethods.AppendAsset(client, asset.Id, vAppendText);
        }
Ejemplo n.º 12
0
        public void WorkQueueItemMultipleAttachments()
        {
            _engine        = new AutomationEngineInstance(null);
            _addQueueItem  = new AddQueueItemCommand();
            _workQueueItem = new WorkQueueItemCommand();

            string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;
            string filePath         = Path.Combine(projectDirectory, @"Resources\");
            string fileName1        = "testFile.txt";
            string fileName2        = "testFile2.txt";
            string attachment1      = Path.Combine(filePath, @"Download\", fileName1);
            string attachment2      = Path.Combine(filePath, @"Download\", fileName2);

            VariableMethods.CreateTestVariable(null, _engine, "output", typeof(Dictionary <,>));

            _addQueueItem.v_QueueName          = "UnitTestQueue";
            _addQueueItem.v_QueueItemName      = "WorkQueueItemAttachmentsTest";
            _addQueueItem.v_QueueItemType      = "Text";
            _addQueueItem.v_JsonType           = "Test Type";
            _addQueueItem.v_QueueItemTextValue = "Test Text";
            _addQueueItem.v_Priority           = "10";
            _addQueueItem.v_Attachments        = filePath + @"Upload\" + fileName1
                                                 + ";" + filePath + @"Upload\" + fileName2;

            _addQueueItem.RunCommand(_engine);

            _workQueueItem.v_QueueName = "UnitTestQueue";
            _workQueueItem.v_OutputUserVariableName = "{output}";
            _workQueueItem.v_SaveAttachments        = "Yes";
            _workQueueItem.v_AttachmentDirectory    = filePath + @"Download\";

            _workQueueItem.RunCommand(_engine);

            var    queueItemObject = "{output}".ConvertUserVariableToObject(_engine, typeof(Dictionary <,>));
            string queueItemString = JsonConvert.SerializeObject(queueItemObject);
            var    vQueueItem      = JsonConvert.DeserializeObject <QueueItemModel>(queueItemString);

            var client    = AuthMethods.GetAuthToken();
            var queueItem = QueueItemMethods.GetQueueItemByLockTransactionKey(client, vQueueItem.LockTransactionKey.ToString());

            Assert.Equal("InProgress", queueItem.State);
            Assert.True(File.Exists(attachment1));
            Assert.True(File.Exists(attachment2));

            File.Delete(attachment1);
            File.Delete(attachment2);
        }
Ejemplo n.º 13
0
        public override void RunCommand(object sender)
        {
            var engine               = (IAutomationEngineInstance)sender;
            var vAssetName           = v_AssetName.ConvertUserVariableToString(engine);
            var vOutputDirectoryPath = v_OutputDirectoryPath.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();
            var asset  = AssetMethods.GetAsset(client, vAssetName, v_AssetType);

            if (asset == null)
            {
                throw new DataException($"No Asset was found for '{vAssetName}' with type '{v_AssetType}'");
            }

            dynamic assetValue;

            switch (v_AssetType)
            {
            case "Text":
                assetValue = asset.TextValue;
                break;

            case "Number":
                assetValue = asset.NumberValue;
                break;

            case "Json":
                assetValue = asset.JsonValue;
                break;

            case "File":
                var  fileID = asset.FileID;
                File file   = FileMethods.GetFile(client, fileID);
                AssetMethods.DownloadFileAsset(client, asset.Id, vOutputDirectoryPath, file.Name);
                assetValue = string.Empty;
                break;

            default:
                assetValue = string.Empty;
                break;
            }

            if (v_AssetType != "File")
            {
                ((object)assetValue).StoreInUserVariable(engine, v_OutputUserVariableName, nameof(v_OutputUserVariableName), this);
            }
        }
        public override void RunCommand(object sender)
        {
            var engine               = (AutomationEngineInstance)sender;
            var vAssetName           = v_AssetName.ConvertUserVariableToString(engine);
            var vOutputDirectoryPath = v_OutputDirectoryPath.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();
            var asset  = AssetMethods.GetAsset(client, $"name eq '{vAssetName}' and type eq '{v_AssetType}'");

            if (asset == null)
            {
                throw new Exception($"No Asset was found for '{vAssetName}' with type '{v_AssetType}'");
            }

            string assetValue = string.Empty;

            switch (v_AssetType)
            {
            case "Text":
                assetValue = asset.TextValue;
                break;

            case "Number":
                assetValue = asset.NumberValue.ToString();
                break;

            case "JSON":
                assetValue = asset.JsonValue;
                break;

            case "File":
                var          binaryObjectID = asset.BinaryObjectID;
                BinaryObject binaryObject   = BinaryObjectMethods.GetBinaryObject(client, binaryObjectID);
                AssetMethods.DownloadFileAsset(client, asset.Id, vOutputDirectoryPath, binaryObject.Name);
                break;

            default:
                assetValue = string.Empty;
                break;
            }

            if (v_AssetType != "File")
            {
                assetValue.StoreInUserVariable(engine, v_OutputUserVariableName);
            }
        }
        public override void RunCommand(object sender)
        {
            var engine          = (AutomationEngineInstance)sender;
            var vCredentialName = v_CredentialName.ConvertUserVariableToString(engine);

            var client     = AuthMethods.GetAuthToken();
            var credential = CredentialMethods.GetCredential(client, $"name eq '{vCredentialName}'");

            if (credential == null)
            {
                throw new Exception($"No Credential was found for '{vCredentialName}'");
            }

            string       username = credential.UserName;
            SecureString password = credential.PasswordSecret.GetSecureString();

            username.StoreInUserVariable(engine, v_OutputUserVariableName);
            password.StoreInUserVariable(engine, v_OutputUserVariableName2);
        }
Ejemplo n.º 16
0
        public override void RunCommand(object sender)
        {
            var engine              = (IAutomationEngineInstance)sender;
            var vCredentialName     = v_CredentialName.ConvertUserVariableToString(engine);
            var vCredentialUsername = v_CredentialUsername.ConvertUserVariableToString(engine);
            var vCredentialPassword = v_CredentialPassword.ConvertUserVariableToString(engine);

            var client     = AuthMethods.GetAuthToken();
            var credential = CredentialMethods.GetCredential(client, $"name eq '{vCredentialName}'");

            if (credential == null)
            {
                throw new Exception($"No Credential was found for '{vCredentialName}'");
            }

            credential.UserName       = vCredentialUsername;
            credential.PasswordSecret = vCredentialPassword;

            CredentialMethods.PutCredential(client, credential);
        }
        public void ExtendQueueItem()
        {
            _engine          = new AutomationEngineInstance(null);
            _addQueueItem    = new AddQueueItemCommand();
            _workQueueItem   = new WorkQueueItemCommand();
            _extendQueueItem = new ExtendQueueItemCommand();

            VariableMethods.CreateTestVariable(null, _engine, "output", typeof(Dictionary <,>));
            VariableMethods.CreateTestVariable(null, _engine, "vQueueItem", typeof(Dictionary <,>));

            _addQueueItem.v_QueueName          = "UnitTestQueue";
            _addQueueItem.v_QueueItemName      = "ExtendQueueItemTest";
            _addQueueItem.v_QueueItemType      = "Text";
            _addQueueItem.v_JsonType           = "Test Type";
            _addQueueItem.v_QueueItemTextValue = "Test Text";
            _addQueueItem.v_Priority           = "10";

            _addQueueItem.RunCommand(_engine);

            _workQueueItem.v_QueueName = "UnitTestQueue";
            _workQueueItem.v_OutputUserVariableName = "{output}";
            _workQueueItem.v_SaveAttachments        = "No";
            _workQueueItem.v_AttachmentDirectory    = "";

            _workQueueItem.RunCommand(_engine);

            var queueItemDict  = (Dictionary <string, object>) "{output}".ConvertUserVariableToObject(_engine, typeof(Dictionary <,>));
            var transactionKey = queueItemDict["LockTransactionKey"].ToString();
            var client         = AuthMethods.GetAuthToken();
            var queueItem      = QueueItemMethods.GetQueueItemByLockTransactionKey(client, transactionKey);

            _extendQueueItem.v_QueueItem = "{vQueueItem}";
            queueItemDict.StoreInUserVariable(_engine, _extendQueueItem.v_QueueItem, typeof(Dictionary <,>));

            _extendQueueItem.RunCommand(_engine);

            var extendedQueueItem = QueueItemMethods.GetQueueItemByLockTransactionKey(client, transactionKey);

            Assert.True(queueItem.LockedUntilUTC < extendedQueueItem.LockedUntilUTC);
        }
        public override void RunCommand(object sender)
        {
            var engine         = (AutomationEngineInstance)sender;
            var vAssetName     = v_AssetName.ConvertUserVariableToString(engine);
            var vAssetFilePath = v_AssetFilePath.ConvertUserVariableToString(engine);
            var vAssetValue    = v_AssetValue.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();
            var asset  = AssetMethods.GetAsset(client, $"name eq '{vAssetName}' and type eq '{v_AssetType}'");

            if (asset == null)
            {
                throw new Exception($"No Asset was found for '{vAssetName}' with type '{v_AssetType}'");
            }

            switch (v_AssetType)
            {
            case "Text":
                asset.TextValue = vAssetValue;
                break;

            case "Number":
                asset.NumberValue = double.Parse(vAssetValue);
                break;

            case "JSON":
                asset.JsonValue = vAssetValue;
                break;

            case "File":
                AssetMethods.UpdateFileAsset(client, asset, vAssetFilePath);
                break;
            }

            if (v_AssetType != "File")
            {
                AssetMethods.PutAsset(client, asset);
            }
        }
Ejemplo n.º 19
0
        public override void RunCommand(object sender)
        {
            var engine               = (IAutomationEngineInstance)sender;
            var vQueueName           = v_QueueName.ConvertUserVariableToString(engine);
            var vAttachmentDirectory = v_AttachmentDirectory.ConvertUserVariableToString(engine);
            Dictionary <string, object> queueItemDict = new Dictionary <string, object>();

            var client = AuthMethods.GetAuthToken();

            var    settings = EnvironmentSettings.GetAgentSettings();
            string agentId  = settings["AgentId"];

            if (string.IsNullOrEmpty(agentId))
            {
                throw new NullReferenceException("Agent is not connected");
            }

            Queue queue = QueueMethods.GetQueue(client, $"name eq '{vQueueName}'");

            if (queue == null)
            {
                throw new DataException($"Queue with name '{vQueueName}' not found");
            }

            var queueItem = QueueItemMethods.DequeueQueueItem(client, Guid.Parse(agentId), queue.Id);

            if (queueItem == null)
            {
                queueItemDict = null;
                queueItemDict.StoreInUserVariable(engine, v_OutputUserVariableName, nameof(v_OutputUserVariableName), this);
                return;
            }

            queueItemDict = queueItem.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
                            .ToDictionary(prop => prop.Name, prop => prop.GetValue(queueItem, null));

            queueItemDict = queueItemDict.Where(kvp => kvp.Key == "LockTransactionKey" ||
                                                kvp.Key == "Name" ||
                                                kvp.Key == "Source" ||
                                                kvp.Key == "Event" ||
                                                kvp.Key == "Type" ||
                                                kvp.Key == "JsonType" ||
                                                kvp.Key == "DataJson" ||
                                                kvp.Key == "Priority" ||
                                                kvp.Key == "LockedUntilUTC")
                            .ToDictionary(i => i.Key, i => i.Value);

            queueItemDict.StoreInUserVariable(engine, v_OutputUserVariableName, nameof(v_OutputUserVariableName), this);

            if (v_SaveAttachments == "Yes")
            {
                if (Directory.Exists(vAttachmentDirectory))
                {
                    //get all queue item attachments
                    var attachments = QueueItemMethods.GetAttachments(client, queueItem.Id);
                    //save each attachment in the directory
                    foreach (var attachment in attachments)
                    {
                        //export (save) in appropriate directory
                        QueueItemMethods.DownloadFile(client, attachment, vAttachmentDirectory);
                    }
                }
            }
        }
Ejemplo n.º 20
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);
            }
        }
Ejemplo n.º 21
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);
            }
        }