示例#1
0
        //<summary>
        //Does the task of randomly selecting a table record and generates the 'rename' chaos in an asynchronous way.
        //</summary>
        public async void RandomRenamingAsync()
        {
            try
            {
                var result = GetRandomTableResult();
                if (result != null)
                {
                    bool renameOperation = await RenameAsync(result);

                    if (renameOperation)
                    {
                        string scrapeName  = ((TableRecord)result.Result).ScrapeName;
                        string newFileName = "renamed" + scrapeName;
                        RestoreOperationFields restoreOperationField = new RestoreOperationFields
                        {
                            ScrapeName      = scrapeName,
                            RetreiveResult  = result,
                            RenameOperation = renameOperation,
                            NewFileName     = newFileName
                        };
                        RestoreOperationFieldsList.Add(restoreOperationField);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.StackTrace);
            }
        }
示例#2
0
        //<summary>
        //Rollback to the original filename caused by the RenameChaos.
        //</summary>
        public async void RestoreAsync(RestoreOperationFields restoreOperationField, double renameConfigurationTime)
        {
            try
            {
                TableResult retreiveResult = restoreOperationField.RetreiveResult;
                if (restoreOperationField.RenameOperation)
                {
                    Console.WriteLine("The rename operation is completed");
                    //do use database
                    string StorageAccountName = ((TableRecord)retreiveResult.Result).StorageAccountName;
                    string StorageAccessKey   = ((TableRecord)retreiveResult.Result).KeyValue;

                    if (((TableRecord)retreiveResult.Result).ContainerName != null)
                    {
                        string StorageConnectionString     = "DefaultEndpointsProtocol=https;AccountName=afimssav;AccountKey=ZiLCuZ6WvK8aZYLzXUNbTn+Tjl1hhPMaOeBhIdi00Urk8nTl3fwAsyCkXOXXcYzsjlBDDNG1Sahgte0q/3SJgQ==;EndpointSuffix=core.windows.net";
                        CloudStorageAccount storageaccount = CloudStorageAccount.Parse(StorageConnectionString);
                        CloudBlobClient     blobClient     = storageaccount.CreateCloudBlobClient();
                        CloudBlobContainer  containername  = blobClient.GetContainerReference(((TableRecord)retreiveResult.Result).ContainerName);
                        string         newFileName         = restoreOperationField.NewFileName;
                        CloudBlockBlob blob = containername.GetBlockBlobReference(newFileName);
                        if (blob.Exists())
                        {
                            Console.WriteLine("The rename blob has been created");
                        }

                        TimeSpan timeSpan = TimeSpan.FromMinutes(renameConfigurationTime);
                        if (DateTime.UtcNow - blob.Properties.LastModified > timeSpan)
                        {
                            bool restoreOperation = await RestoreHelperAsync(retreiveResult, newFileName, restoreOperationField.ScrapeName);

                            if (restoreOperation)
                            {
                                Console.WriteLine("The restore has been done");
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("The rename task is not done yet..");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.StackTrace);
            }
        }
示例#3
0
        public async void RestoreAsync(RestoreOperationFields restoreOperationField)
        {
            string scrapeName = restoreOperationField.ScrapeName;

            Microsoft.WindowsAzure.Storage.Table.TableResult retreiveResult = restoreOperationField.RetreiveResult;
            bool   renameOperation = restoreOperationField.RenameOperation;
            string newFileName     = restoreOperationField.NewFileName;

            if (renameOperation)
            {
                Console.WriteLine("The rename operation is completed");
                //do use database
                string Container          = ((Json_File)retreiveResult.Result).ContainerName;
                string StorageAccountName = ((Json_File)retreiveResult.Result).StorageAccountName;
                string StorageAccessKey   = ((Json_File)retreiveResult.Result).KeyValue;

                if (Container != null)
                {
                    string StorageConnectionString     = "DefaultEndpointsProtocol=https;AccountName=afimssav;AccountKey=ZiLCuZ6WvK8aZYLzXUNbTn+Tjl1hhPMaOeBhIdi00Urk8nTl3fwAsyCkXOXXcYzsjlBDDNG1Sahgte0q/3SJgQ==;EndpointSuffix=core.windows.net";
                    CloudStorageAccount storageaccount = CloudStorageAccount.Parse(StorageConnectionString);
                    CloudBlobClient     blobClient     = storageaccount.CreateCloudBlobClient();
                    CloudBlobContainer  containername  = blobClient.GetContainerReference(Container);
                    CloudBlockBlob      blob           = containername.GetBlockBlobReference(newFileName);
                    if (blob.Exists())
                    {
                        Console.WriteLine("The rename blob has been created");
                    }
                    TimeSpan timeSpan = TimeSpan.FromMinutes(1);
                    if (DateTime.UtcNow - blob.Properties.LastModified > timeSpan)
                    {
                        bool restoreOperation = await RestoreHelperAsync(retreiveResult, newFileName, scrapeName);

                        if (restoreOperation)
                        {
                            Console.WriteLine("The restore has been done");
                        }
                    }
                    //if present time - newfileblobtime is > 1hr then call for restore operation
                    //if(blob.Properties.LastModified - (DateTimeOffset?)((Json_File)retreiveResult.Result).LastModified > )
                }
            }
            else
            {
                Console.WriteLine("The rename task is not done yet..");
            }
        }
示例#4
0
        public async void RandomRenamingAsync()
        {
            var result = GetRandomTableResult();

            if (result != null)
            {
                bool renameOperation = await RenameAsync(result);

                if (renameOperation)
                {
                    string scrapeName  = ((Json_File)result.Result).ScrapeName;
                    string newFileName = "renamed" + scrapeName;
                    RestoreOperationFields restoreOperationField = new RestoreOperationFields();
                    restoreOperationField.ScrapeName      = scrapeName;
                    restoreOperationField.RetreiveResult  = result;
                    restoreOperationField.RenameOperation = renameOperation;
                    restoreOperationField.NewFileName     = newFileName;
                    RestoreOperationFieldsList.Add(restoreOperationField);
                    //add the fields renameOperation,retreive result,newFileName,scrapeName to the list of new class
                }
            }
        }
示例#5
0
 public static void Add(RestoreOperationFields value)
 {
     RestoreOperationFields.Add(value);
 }