Ejemplo n.º 1
0
        private string Get_Token()
        {
            var loginModel = new
            {
                tenancyName            = string.Empty,
                usernameOrEmailAddress = "username",
                password = "******"
            };

            string token = OrchestratorAPIHelper.GetToken(loginModel);

            return(token);
        }
Ejemplo n.º 2
0
        protected override void Execute(CodeActivityContext context)
        {
            if (context == null)
            {
                return;
            }

            var minutes         = this.BeforeMinutes.Get(context);
            var queueName       = this.QueueName.Get(context);
            var currentDateTime = this.CurrentDateTime.Get(context);

            WriteLine("Current DateTime : " + currentDateTime.ToString());

            queueName = queueName.Trim();

            try
            {
                string token      = string.Empty;
                bool   queueFound = false;

                if (string.IsNullOrEmpty(token))
                {
                    token = Get_Token();
                }
                var queueDefinitions = OrchestratorAPIHelper.GetQueueDefinitionByName(token, queueName);
                if (queueDefinitions.Length > 0)
                {
                    queueFound = true;
                    var queueItem = queueDefinitions.First();
                    queueName = queueItem.QueueDefinitionName;
                }
                else
                {
                    WriteLine("No Queues with name '" + queueName + "' exist in Orchestrator.. Please use a valid queue name.", context);
                }

                if (queueFound)
                {
                    var queueDefinition = queueDefinitions.Single(q => q.QueueDefinitionName.ToUpper() == queueName.ToUpper());
                    queueName = queueDefinition.QueueDefinitionName;

                    var queueItems = OrchestratorAPIHelper.GetAllFailedQueueItems(token, queueDefinition.QueueDefinitionId);
                    int count      = queueItems.Count();
                    if (count > 0)
                    {
                        var dateTime = currentDateTime.AddMinutes(minutes * -1);
                        WriteLine("From DateTime : " + dateTime.ToString());

                        var filteredQueueItems = queueItems.Where(q => q.StartProcessing >= dateTime);
                        count = filteredQueueItems.Count();
                        if (count > 0)
                        {
                            foreach (var qItem in filteredQueueItems)
                            {
                                OrchestratorAPIHelper.SetItemReviewStatus(token, qItem.Id, qItem.RowVersion);
                            }

                            WriteLine("Successfully retried " + count + " transaction items for queue '" + queueName + "'.", context);
                        }
                        else
                        {
                            WriteLine("No failed transaction items in past " + minutes + " minutes", context);
                        }
                    }
                    else
                    {
                        WriteLine("No top 50 failed transaction items exist for queue '" + queueName + "'.", context);
                    }
                }
            }
            catch (Exception e)
            {
                WriteLine("An exception has been caught::" + e.ToString(), context);
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            if (context == null)
            {
                return;
            }

            var queueDataTable = this.QueueDataTable.Get(context);
            var queueName      = this.QueueName.Get(context);

            if (queueDataTable is null)
            {
                WriteLine("Queue Data Table is NULL or EMPTY, Please check the workflow.", context);
            }
            else if (string.IsNullOrEmpty(queueName))
            {
                WriteLine("Queue Name is NULL or EMPTY, Please check the workflow.", context);
            }
            else
            {
                try
                {
                    string token      = string.Empty;
                    bool   queueFound = false;

                    if (string.IsNullOrEmpty(token))
                    {
                        token = Get_Token();
                    }
                    var queueDefinitions = OrchestratorAPIHelper.GetQueueDefinitions(token);
                    if (queueDefinitions.Length > 0)
                    {
                        queueFound = queueDefinitions.Any(q => q.Name.ToUpper() == queueName.ToUpper());
                        if (queueFound == false)
                        {
                            WriteLine("Queue name does not exist. Please use a valid queue name.", context);
                        }
                        else
                        {
                            var queueItem = queueDefinitions.Single(q => q.Name.ToUpper() == queueName.ToUpper());
                            queueName = queueItem.Name;
                        }
                    }
                    else
                    {
                        WriteLine("No Queues with name '" + queueName + "' exist in Orchestrator.", context);
                    }

                    if (queueFound)
                    {
                        //Method 1:
                        var dictionaryList = ExcelUtility.DataTableToDictionaryList(queueDataTable);

                        foreach (var dictionary in dictionaryList)
                        {
                            Dictionary <string, object> queueDictionay = new Dictionary <string, object>();
                            foreach (var key in dictionary.Keys)
                            {
                                queueDictionay.Add(key, dictionary[key]);
                            }

                            var specificContent = GetDynamicObject(queueDictionay);
                            Add_to_Queue(token, queueName, specificContent);
                        }

                        //Method 2:
                        //var transactionItems = ExcelUtility.ExcelToList<TransactionItem>(queueInputFile);
                        //foreach (var transactionItem in transactionItems)
                        //{
                        //    transactionItem.SpecificData = transactionItem.SpecificData.TrimStart(("{\"DynamicProperties\":").ToCharArray());
                        //    transactionItem.SpecificData = transactionItem.SpecificData.TrimEnd('}');
                        //    transactionItem.SpecificData = "{\"" + transactionItem.SpecificData + "}";
                        //    var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(transactionItem.SpecificData);
                        //    Dictionary<string, object> queueDictionay = new Dictionary<string, object>();
                        //    foreach (var key in dictionary.Keys)
                        //    {
                        //        queueDictionay.Add(key, dictionary[key]);
                        //    }

                        //    var specificContent = GetDynamicObject(queueDictionay);
                        //    Add_to_Queue(token, queueName, specificContent);
                        //}

                        WriteLine("Successfully added transaction items to queue '" + queueName + "'.", context);
                    }
                }
                catch (Exception e)
                {
                    WriteLine("An exception has been caught::" + e.ToString(), context);
                }
            }
        }
 private void Add_to_Queue(string token, string queueName, object specificContent)
 {
     OrchestratorAPIHelper.AddQueue(token, queueName, specificContent);
 }