public void CreateRule(TraceWriter log)
        {
            try
            {
                var loadBalancer = GetRandomLoadBalancer();
                if (loadBalancer == null)
                {
                    log.Info("Loadbalancer RuleEngine: No load balancer found with virtual machines.");
                    return;
                }

                var filteredVmSet = GetVirtualMachineSet(loadBalancer.Id);
                if (filteredVmSet == null)
                {
                    log.Info("Loadbalancer RuleEngine: No virtual machines found for the load balancer name: " + loadBalancer.ResourceName);
                    return;
                }

                var table = StorageAccountProvider.CreateOrGetTable(StorageTableNames.ScheduledRulesTableName);
                if (table == null)
                {
                    return;
                }

                var count = VmCount(filteredVmSet.Count);
                var tasks = new List <Task>();

                //  do
                //  {
                var randomSets = filteredVmSet.Take(count).ToList();
                filteredVmSet = filteredVmSet.Except(randomSets).ToList();
                for (var i = 0;
                     i < randomSets.Count;
                     i += TableConstants.TableServiceBatchMaximumOperations)
                {
                    var batchItems = randomSets.Skip(i)
                                     .Take(TableConstants.TableServiceBatchMaximumOperations).ToList();

                    var batchOperation = VirtualMachineHelper.CreateScheduleEntity(batchItems,
                                                                                   _azureClient.AzureSettings.Chaos.SchedulerFrequency,
                                                                                   _azureClient.AzureSettings.Chaos.AzureFaultInjectionActions,
                                                                                   VirtualMachineGroup.LoadBalancer);

                    var operation = batchOperation;
                    tasks.Add(table.ExecuteBatchAsync(operation));
                }

                //  } while (filteredVmSet.Any());

                Task.WhenAll(tasks);
                log.Info("Loadbalancer RuleEngine: Completed creating rule engine.");
            }
            catch (Exception ex)
            {
                log.Error("LoadBalancer RuleEngine: Exception thrown. ", ex);
            }
        }
        /// <summary>Create the virtual machine rules</summary>
        /// <param name="log"></param>
        public void CreateRule(TraceWriter log)
        {
            try
            {
                log.Info("VirtualMachine RuleEngine: Started the creating rules for the virtual machines.");
                var vmSets = GetRandomVmSet();
                if (vmSets == null)
                {
                    log.Info("VirtualMachine RuleEngine: No virtual machines found..");
                    return;
                }

                var table = StorageAccountProvider.CreateOrGetTable(StorageTableNames.ScheduledRulesTableName);
                var count = VmCount(vmSets.Count);
                var tasks = new List <Task>();

                //do
                //{
                var randomSets = vmSets.Take(count).ToList();
                vmSets = vmSets.Except(randomSets).ToList();
                for (var i = 0;
                     i < randomSets.Count;
                     i += TableConstants.TableServiceBatchMaximumOperations)
                {
                    var batchItems = randomSets.Skip(i)
                                     .Take(TableConstants.TableServiceBatchMaximumOperations).ToList();

                    var batchOperation = VirtualMachineHelper.CreateScheduleEntity(batchItems,
                                                                                   azureClient.AzureSettings.Chaos.SchedulerFrequency,
                                                                                   azureClient.AzureSettings.Chaos.AzureFaultInjectionActions,
                                                                                   VirtualMachineGroup.VirtualMachines);
                    if (batchOperation == null)
                    {
                        continue;
                    }

                    tasks.Add(table.ExecuteBatchAsync(batchOperation));
                }
                // } while (vmSets.Any());

                Task.WhenAll(tasks);
                log.Info("VirtualMachine RuleEngine: Completed creating rule engine..");
            }
            catch (Exception ex)
            {
                log.Error("VirtualMachine RuleEngine: Exception thrown. ", ex);
            }
        }