示例#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);
                    }
                }
            }
        }
示例#2
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);
                    }
                }
            }
        }