/// <summary>
        /// Adds tasks from Test entities containing multiple test commands
        /// </summary>
        /// <param name="jobId"></param>
        /// <param name="taskIDPrefix"></param>
        /// <param name="inputFilesDict"></param>
        /// <param name="CommandEntities"></param>
        /// <returns></returns>
        public async Task <List <CloudTask> > AddTasksFromTestEntities(string jobId, string taskIDPrefix, Dictionary <PSharpTestEntities, List <ResourceFile> > inputFilesDict, List <PSharpTestEntities> TestEntities)
        {
            List <CloudTask> tasks = new List <CloudTask>();
            //Creating tasks with iterations
            List <string> taskCommands = new List <string>();

            foreach (var tEntity in TestEntities)
            {
                foreach (var cEntity in tEntity.CommandEntities)
                {
                    for (int i = 0; i < cEntity.NumberOfParallelTasks; i++)
                    {
                        //Todo: Incase of Portfolio : give additional flags /testing-process-id: along with /sch:portfolio

                        string command = string.Empty;
                        if (string.IsNullOrEmpty(cEntity.SchedulingStratergy))
                        {
                            //No shceduling statergy provided
                            command = string.Format(Constants.PSharpTaskCommandFormatWithFlags, Path.GetFileName(tEntity.ApplicationPath), cEntity.CommandFlags);
                        }
                        else
                        {
                            //Schduling stratergy provided. In case of portfolio testing-process-id is added.
                            string schFlag = string.Empty;
                            if (cEntity.SchedulingStratergy.ToLower().Equals("portfolio"))
                            {
                                schFlag = "/sch:" + cEntity.SchedulingStratergy + " /testing-process-id:" + i;
                            }
                            else
                            {
                                schFlag = "/sch:" + cEntity.SchedulingStratergy;
                            }
                            command = string.Format(Constants.PSharpTaskCommandFormatWithSchFlags, Path.GetFileName(tEntity.ApplicationPath), cEntity.CommandFlags, schFlag);
                        }
                        taskCommands.Add(command);
                        string    taskId          = taskIDPrefix + "_" + tEntity.TestName + "_" + cEntity.CommandName + "_" + i;
                        string    taskCommandLine = command;
                        CloudTask task            = new CloudTask(taskId, taskCommandLine);
                        task.ResourceFiles = inputFilesDict[tEntity];
                        tasks.Add(task);
                    }
                }
            }

            Console.WriteLine("Adding {0} tasks to job [{1}]...", tasks.Count, jobId);

            //Add tasks in chunks
            var TaskChunks = PSharpOperations.SplitList(tasks, Constants.BatchTestChunkSize);

            foreach (List <CloudTask> subTaskList in TaskChunks)
            {
                await batchClient.JobOperations.AddTaskAsync(jobId, subTaskList, timeout : TimeSpan.FromMinutes(30));
            }

            //await batchClient.JobOperations.AddTaskAsync(jobId, tasks, timeout: TimeSpan.FromMinutes(30));

            return(tasks);
        }
        public void ValidateAndParse()
        {
            //Validate all the properties

            if (string.IsNullOrEmpty(PoolId))
            {
                throw new PSharpConfigValidateException(Constants.ExceptionPoolIdMessage);
            }
            if (string.IsNullOrEmpty(JobDefaultId))
            {
                throw new PSharpConfigValidateException(Constants.ExceptionJobIdMessage);
            }
            if (JobDefaultId.Length > 20)
            {
                throw new PSharpConfigValidateException(Constants.ExceptionJobIdLengthMessage);
            }
            if (string.IsNullOrEmpty(TaskDefaultId))
            {
                throw new PSharpConfigValidateException(Constants.ExceptionTaskIdMessage);
            }
            if (NumberOfNodesInPool < 2)
            {
                throw new PSharpConfigValidateException(Constants.ExceptionNumNodesMessage);
            }

            int tempOsVal = 0;

            if (string.IsNullOrEmpty(NodeOsFamily) || !int.TryParse(NodeOsFamily, out tempOsVal))
            {
                throw new PSharpConfigValidateException(Constants.ExceptionNodeOsFamilyMessage);
            }

            if (string.IsNullOrEmpty(NodeVirtualMachineSize))
            {
                throw new PSharpConfigValidateException(Constants.ExceptionNodeVirtualMachineSizeMessage);
            }
            PSharpBinariesFolderPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(PSharpBinariesFolderPath));
            if (string.IsNullOrEmpty(PSharpBinariesFolderPath) || !Directory.Exists(PSharpBinariesFolderPath))
            {
                throw new PSharpConfigValidateException(Constants.ExceptionPSharpBinariesPathMessage);
            }

            if (string.IsNullOrEmpty(OutputFolderPath))
            {
                throw new PSharpConfigValidateException(Constants.ExceptionOutputFolderPathMessage);
            }

            if (TaskWaitHours < 1)
            {
                throw new PSharpConfigValidateException(Constants.ExceptionTaskWaitHoursMessage);
            }

            if (MonitorBatch)
            {
                if (!string.IsNullOrEmpty(BatchFilePath) && !File.Exists(BatchFilePath))
                {
                    throw new PSharpConfigValidateException(Constants.ExceptionBatchFileNotFoundMessage);
                }
            }

            if (null == TestEntities || TestEntities.Count == 0)
            {
                throw new PSharpConfigValidateException(Constants.ExceptionNoTestEntityMessage);
            }

            foreach (var variable in Variables)
            {
                if (!DeclareDictionary.ContainsKey(variable.Name))
                {
                    DeclareDictionary.Add(variable.Name, variable.Value);
                }
            }

            foreach (var tEntity in TestEntities)
            {
                if (null == tEntity)
                {
                    throw new PSharpConfigValidateException(Constants.ExceptionTestEntityNullMessage);
                }
                if (null == tEntity.TestName)
                {
                    tEntity.TestName = string.Empty;
                }
                tEntity.ApplicationPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(tEntity.ApplicationPath));
                if (string.IsNullOrEmpty(tEntity.ApplicationPath) || !File.Exists(tEntity.ApplicationPath))
                {
                    throw new PSharpConfigValidateException(string.Format(Constants.ExceptionApplicationPathMessage, TestEntities.IndexOf(tEntity)));
                }

                if (null == tEntity.CommandEntities || tEntity.CommandEntities.Count() == 0)
                {
                    throw new PSharpConfigValidateException(string.Format(Constants.ExceptionNoCommandEntityMessage, TestEntities.IndexOf(tEntity)));
                }

                for (int i = 0; i < tEntity.CommandEntities.Count(); i++)
                {
                    var cEntity = tEntity.CommandEntities[i];

                    PSharpOperations.ParseCommandEntities(DeclareDictionary, ref cEntity);

                    if (null == cEntity)
                    {
                        throw new PSharpConfigValidateException(Constants.ExceptionCommandEntityNullMessage);
                    }

                    if (cEntity.NumberOfParallelTasks < 1)
                    {
                        throw new PSharpConfigValidateException(string.Format(Constants.ExceptionParallelTaskMessage, i, TestEntities.IndexOf(tEntity)));
                    }
                    if (string.IsNullOrEmpty(cEntity.CommandName))
                    {
                        throw new PSharpConfigValidateException(string.Format(Constants.ExceptionCommandNameMessage, i, TestEntities.IndexOf(tEntity)));
                    }

                    //Todo : check list of supported schedulers
                    //if (!string.IsNullOrEmpty(cEntity.SchedulingStratergy) && !cEntity.SchedulingStratergy.StartsWith("/sch:"))
                    //{
                    //    throw new PSharpConfigValidateException(string.Format(Constants.ExceptionSchedulingStatergyMessage, i, TestEntities.IndexOf(tEntity)));
                    //}
                }
            }
        }