Example #1
0
        public async 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>)await "{output}".EvaluateCode(_engine);

            var userInfo  = ServerSessionVariableMethods.GetUserInfo(_engine);
            var queueItem = QueueItemMethods.GetQueueItemByLockTransactionKey(userInfo, queueItemObject["LockTransactionKey"].ToString());

            Assert.Equal("InProgress", queueItem.State);
        }
Example #2
0
        public async void SetFailedFatallyStatus()
        {
            _engine       = new AutomationEngineInstance(null);
            _setQueueItem = new SetQueueItemStatusCommand();

            string name = "FailedQueueItem";

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

            var transactionKey = queueItemDict["LockTransactionKey"].ToString();
            var userInfo       = ServerSessionVariableMethods.GetUserInfo(_engine);
            var queueItem      = QueueItemMethods.GetQueueItemByLockTransactionKey(userInfo, transactionKey.ToString());

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

            _setQueueItem.RunCommand(_engine);

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

            Assert.Equal("Failed", queueItem.State);
        }
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vQueueItem = (Dictionary <string, object>) await v_QueueItem.EvaluateCode(engine);

            var vQueueItemErrorMessage = (string)await v_QueueItemErrorMessage.EvaluateCode(engine);

            var vQueueItemErrorCode = (string)await v_QueueItemErrorCode.EvaluateCode(engine);

            var  userInfo       = ServerSessionVariableMethods.GetUserInfo(engine);
            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(userInfo, transactionKey);
                break;

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

            case "Failed - Fatal":
                QueueItemMethods.RollbackQueueItem(userInfo, transactionKey, vQueueItemErrorCode, vQueueItemErrorMessage, true);
                break;
            }
        }
        public async override Task RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            var    jobId     = SessionVariableMethods.GetJobId(engine);
            string jobStatus = string.Empty;
            bool   stopJob;

            if (!string.IsNullOrEmpty(jobId))
            {
                var userInfo = ServerSessionVariableMethods.GetUserInfo(engine);
                jobStatus = JobMethods.GetJobStatus(userInfo, jobId);
            }

            if (jobStatus == "Stopping")
            {
                stopJob = true;
            }
            else
            {
                stopJob = false;
            }

            stopJob.SetVariableValue(engine, v_OutputUserVariableName);
        }
Example #5
0
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vQueueName = (string)await v_QueueName.EvaluateCode(engine);

            var vAttachmentDirectory = (string)await v_AttachmentDirectory.EvaluateCode(engine);

            Dictionary <string, object> queueItemDict = new Dictionary <string, object>();

            var   userInfo = ServerSessionVariableMethods.GetUserInfo(engine);
            Queue queue    = QueueMethods.GetQueue(userInfo, $"name eq '{vQueueName}'");

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

            var queueItem = QueueItemMethods.DequeueQueueItem(userInfo, queue.Id);

            if (queueItem == null)
            {
                queueItemDict = null;
                return;
            }

            queueItemDict.SetVariableValue(engine, v_OutputUserVariableName);

            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.SetVariableValue(engine, v_OutputUserVariableName);

            if (v_SaveAttachments == "Yes")
            {
                if (Directory.Exists(vAttachmentDirectory))
                {
                    //get all queue item attachments
                    var attachments = QueueItemMethods.GetAttachments(userInfo, queueItem.Id);
                    //save each attachment in the directory
                    foreach (var attachment in attachments)
                    {
                        //export (save) in appropriate directory
                        QueueItemMethods.DownloadFile(userInfo, attachment, vAttachmentDirectory);
                    }
                }
            }
        }
        public async override Task RunCommand(object sender)
        {
            var engine       = (IAutomationEngineInstance)sender;
            var vAccountName = (string)await v_AccountName.EvaluateCode(engine);

            var vToRecipients = (List <string>) await v_ToRecipients.EvaluateCode(engine);

            var vSubject = (string)await v_Subject.EvaluateCode(engine);

            var vBody = (string)await v_Body.EvaluateCode(engine);

            var toEmailList = GetEmailList(vToRecipients);

            List <string> vCCRecipients = null;

            if (!string.IsNullOrEmpty(v_CCRecipients))
            {
                vCCRecipients = (List <string>) await v_CCRecipients.EvaluateCode(engine);
            }

            var ccEmailList = GetEmailList(vCCRecipients);

            List <string> vBCCRecipients = null;

            if (!string.IsNullOrEmpty(v_BCCRecipients))
            {
                vBCCRecipients = (List <string>) await v_BCCRecipients.EvaluateCode(engine);
            }

            var bccEmailList = GetEmailList(vBCCRecipients);

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

            if (vToRecipients == null)
            {
                throw new NullReferenceException("To Recipient(s) cannot be empty");
            }

            List <string> vAttachments = null;

            if (!string.IsNullOrEmpty(v_Attachments))
            {
                vAttachments = (List <string>) await v_Attachments.EvaluateCode(engine);
            }

            var userInfo = ServerSessionVariableMethods.GetUserInfo(engine);

            ServerEmailMethods.SendServerEmail(userInfo, emailMessage, vAttachments, vAccountName);
        }
Example #7
0
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vQueueName = (string)await v_QueueName.EvaluateCode(engine);

            var vQueueItemName = (string)await v_QueueItemName.EvaluateCode(engine);

            var vSource = (string)await v_Source.EvaluateCode(engine);

            var vEvent = (string)await v_Event.EvaluateCode(engine);

            var vJsonType = (string)await v_JsonType.EvaluateCode(engine);

            int priority = (int)await v_Priority.EvaluateCode(engine);

            var vQueueItemTextValue = (string)await v_QueueItemTextValue.EvaluateCode(engine);

            var   userInfo = ServerSessionVariableMethods.GetUserInfo(engine);
            Queue queue    = QueueMethods.GetQueue(userInfo, $"Name eq '{vQueueName}'");

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

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

            QueueItemMethods.EnqueueQueueItem(userInfo, queueItem);

            if (!string.IsNullOrEmpty(v_Attachments))
            {
                var vAttachments = (List <string>) await v_Attachments.EvaluateCode(engine);

                QueueItemMethods.AttachFiles(userInfo, queueItem.Id, vAttachments);
            }
        }
Example #8
0
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vQueueItem = (Dictionary <string, object>) await v_QueueItem.EvaluateCode(engine);

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

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

            var userInfo = ServerSessionVariableMethods.GetUserInfo(engine);

            QueueItemMethods.ExtendQueueItem(userInfo, transactionKey);
        }
Example #9
0
        public async 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 = await "{output}".EvaluateCode(_engine);
            string queueItemString = JsonConvert.SerializeObject(queueItemObject);
            var    vQueueItem      = JsonConvert.DeserializeObject <QueueItemModel>(queueItemString);

            var userInfo  = ServerSessionVariableMethods.GetUserInfo(_engine);
            var queueItem = QueueItemMethods.GetQueueItemByLockTransactionKey(userInfo, vQueueItem.LockTransactionKey.ToString());

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

            File.Delete(attachment1);
            File.Delete(attachment2);
        }
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vAssetName = (string)await v_AssetName.EvaluateCode(engine);

            var vOutputDirectoryPath = (string)await v_OutputDirectoryPath.EvaluateCode(engine);

            var userInfo = ServerSessionVariableMethods.GetUserInfo(engine);
            var asset    = AssetMethods.GetAsset(userInfo, 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":
                AssetMethods.DownloadFileAsset(userInfo, asset, vOutputDirectoryPath);
                assetValue = string.Empty;
                break;

            default:
                assetValue = string.Empty;
                break;
            }

            if (v_AssetType != "File")
            {
                ((object)assetValue).SetVariableValue(engine, v_OutputUserVariableName);
            }
        }
Example #11
0
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vAssetName = (string)await v_AssetName.EvaluateCode(engine);

            var vAppendText = (string)await v_AppendText.EvaluateCode(engine);

            var userInfo = ServerSessionVariableMethods.GetUserInfo(engine);
            var asset    = AssetMethods.GetAsset(userInfo, vAssetName, "Text");

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

            AssetMethods.AppendAsset(userInfo, asset.Id, vAppendText);
        }
Example #12
0
        public async override Task RunCommand(object sender)
        {
            var engine          = (IAutomationEngineInstance)sender;
            var vCredentialName = (string)await v_CredentialName.EvaluateCode(engine);

            var userInfo   = ServerSessionVariableMethods.GetUserInfo(engine);
            var credential = CredentialMethods.GetCredential(userInfo, vCredentialName);

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

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

            username.SetVariableValue(engine, v_OutputUserVariableName);
            password.SetVariableValue(engine, v_OutputUserVariableName2);
        }
Example #13
0
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vAssetName = (string)await v_AssetName.EvaluateCode(engine);

            var vAssetFilePath = (string)await v_AssetFilePath.EvaluateCode(engine);

            var vAssetValue = (string)await v_AssetValue.EvaluateCode(engine);

            var userInfo = ServerSessionVariableMethods.GetUserInfo(engine);
            var asset    = AssetMethods.GetAsset(userInfo, vAssetName, v_AssetType);

            if (asset == null)
            {
                throw new DataException($"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(userInfo, asset, vAssetFilePath);
                break;
            }

            if (v_AssetType != "File")
            {
                AssetMethods.PutAsset(userInfo, asset);
            }
        }
Example #14
0
        public async 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>)await "{output}".EvaluateCode(_engine);
            var transactionKey = queueItemDict["LockTransactionKey"].ToString();

            var userInfo  = ServerSessionVariableMethods.GetUserInfo(_engine);
            var queueItem = QueueItemMethods.GetQueueItemByLockTransactionKey(userInfo, transactionKey.ToString());

            _extendQueueItem.v_QueueItem = "{vQueueItem}";
            queueItemDict.SetVariableValue(_engine, _extendQueueItem.v_QueueItem);

            _extendQueueItem.RunCommand(_engine);

            var extendedQueueItem = QueueItemMethods.GetQueueItemByLockTransactionKey(userInfo, transactionKey.ToString());

            Assert.True(queueItem.LockedUntilUTC < extendedQueueItem.LockedUntilUTC);
        }
Example #15
0
        public async override Task RunCommand(object sender)
        {
            var engine          = (IAutomationEngineInstance)sender;
            var vCredentialName = (string)await v_CredentialName.EvaluateCode(engine);

            var vCredentialUsername = (string)await v_CredentialUsername.EvaluateCode(engine);

            var vCredentialPassword = ((SecureString)await v_CredentialPassword.EvaluateCode(engine)).ConvertSecureStringToString();

            var userInfo   = ServerSessionVariableMethods.GetUserInfo(engine);
            var credential = CredentialMethods.GetCredential(userInfo, vCredentialName);

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

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

            CredentialMethods.PutCredential(userInfo, credential);
        }
Example #16
0
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vAssetName = (string)await v_AssetName.EvaluateCode(engine);

            if (string.IsNullOrEmpty(v_AssetActionValue))
            {
                v_AssetActionValue = "0";
            }
            var vAssetActionValue = (int)await v_AssetActionValue.EvaluateCode(engine);

            var userInfo = ServerSessionVariableMethods.GetUserInfo(engine);
            var asset    = AssetMethods.GetAsset(userInfo, vAssetName, "Number");

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

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

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

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

            case "Subtract":
                AssetMethods.SubtractAsset(userInfo, asset.Id, vAssetActionValue);
                break;
            }
        }