Beispiel #1
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);
                    }
                }
            }
        }
Beispiel #2
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);
            }
        }
        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);
            }
        }
Beispiel #5
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);
                    }
                }
            }
        }