protected override void ProcessRecord()
 {
     AmazonS3 client = base.GetClient();
     Amazon.S3.Model.SetBucketVersioningRequest request = new Amazon.S3.Model.SetBucketVersioningRequest();
     request.BucketName = this._BucketName;
     Amazon.S3.Model.SetBucketVersioningResponse response = client.SetBucketVersioning(request);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Enables versioning on the bucket. Once versioning is enabled you can not "un-version" the bucket. You can however suspend versioning on the bucket.
        /// </summary>
        public void EnableBucketVersioning()
        {
            try
            {
                using (AmazonS3 s3 = AWSClientFactory.CreateAmazonS3Client(this.cloudServiceConfigProvider.AWSAccessKeyId, this.cloudServiceConfigProvider.AWSSecretKey))
                {
                    S3BucketVersioningConfig versioningConfig = new S3BucketVersioningConfig()
                        .WithStatus("Enabled");
                    SetBucketVersioningRequest setBucketVersioningReq = new SetBucketVersioningRequest()
                        .WithBucketName(this.cloudServiceConfigProvider.AmazonBucket)
                        .WithVersioningConfig(versioningConfig);

                    s3.SetBucketVersioning(setBucketVersioningReq);
                }
            }
            catch (Exception ex)
            {
                throw new CloudServiceException(ex, "Error occured when enabling versioning on the bucket {0}", this.cloudServiceConfigProvider.AmazonBucket);
            }
        }
Ejemplo n.º 3
0
 public static bool CheckVersion(bool forceCheck)
 {
     // first check the last updated date
     _notification = new Notification();
     _notification.SetMessage("Checking for updates");
     try
     {
         if (forceCheck)
         {
             _notification.Show();
             _notification.ShowForm(10);
         }
         if (forceCheck)
         {
             var amazons3 = AWSClientFactory.CreateAmazonS3Client(Utilities.AwsAccessKey, Utilities.AwsSecretKey, new AmazonS3Config { CommunicationProtocol = Protocol.HTTP });
             var listVersionRequest = new ListVersionsRequest { BucketName = Utilities.AppRootBucketName, Prefix = "VersaVaultSyncTool_32Bit.exe" };
             foreach (var s3ObjectVersion in amazons3.ListVersions(listVersionRequest).Versions)
             {
                 if (s3ObjectVersion.IsLatest)
                 {
                     if (!string.IsNullOrEmpty(Utilities.MyConfig.InstallerVersionId) && Utilities.MyConfig.InstallerVersionId != s3ObjectVersion.VersionId)
                     {
                         while (Process.GetProcessesByName("VersaVaultSyncTool_32Bit").Length != 0)
                         {
                             Thread.Sleep(1000);
                             Application.DoEvents();
                         }
                         if (File.Exists(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe")))
                             File.Delete(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe"));
                         if (File.Exists(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe")))
                         {
                             File.Move(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe"),
                                       Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe"));
                         }
                         var service = new S3Service { AccessKeyID = Utilities.AwsAccessKey, SecretAccessKey = Utilities.AwsSecretKey };
                         _notification.SetMessage("Started downloading update.");
                         service.GetObjectProgress += ServiceGetObjectProgress;
                         service.GetObject(Utilities.AppRootBucketName, s3ObjectVersion.Key, Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe"));
                         _notification.SetMessage("Updating VersaVault");
                         Utilities.MyConfig.InstallerVersionId = s3ObjectVersion.VersionId;
                         Utilities.MyConfig.Save();
                         var startInfo = new ProcessStartInfo(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe")) { Verb = "runas" };
                         Process.Start(startInfo);
                         Application.Exit();
                         return false;
                     }
                     Utilities.MyConfig.InstallerVersionId = s3ObjectVersion.VersionId;
                     Utilities.MyConfig.Save();
                     break;
                 }
             }
             listVersionRequest = new ListVersionsRequest { BucketName = Utilities.AppRootBucketName, Prefix = "VersaVaultSyncTool.exe" };
             foreach (var s3ObjectVersion in amazons3.ListVersions(listVersionRequest).Versions)
             {
                 if (s3ObjectVersion.IsLatest)
                 {
                     if (s3ObjectVersion.VersionId != null && s3ObjectVersion.VersionId != "null")
                     {
                         if (!string.IsNullOrEmpty(Utilities.MyConfig.VersionId) && Utilities.MyConfig.VersionId != s3ObjectVersion.VersionId)
                         {
                             _notification.Dispose();
                             Utilities.MyConfig.VersionId = s3ObjectVersion.VersionId;
                             Utilities.MyConfig.Save();
                             var startInfo = new ProcessStartInfo(Path.Combine(Application.StartupPath, "VersaVaultUpdater.exe"), s3ObjectVersion.VersionId + " " + "update") { Verb = "runas" };
                             Process.Start(startInfo);
                             Application.Exit();
                             return false;
                         }
                         Utilities.MyConfig.VersionId = s3ObjectVersion.VersionId;
                         Utilities.MyConfig.Save();
                         return true;
                     }
                     // enable bucker versioning
                     var setBucketVersioning = new SetBucketVersioningRequest { BucketName = Utilities.AppRootBucketName, VersioningConfig = new S3BucketVersioningConfig { Status = "Enabled" } };
                     amazons3.SetBucketVersioning(setBucketVersioning);
                     break;
                 }
             }
             return true;
         }
     }
     catch (Exception)
     {
     }
     finally
     {
         try
         {
             _notification.Controls["LblStatus"].Text = @"VersaVault is upto date.";
             _notification.HideForm(10);
             _notification.Close();
             _notification.Dispose();
         }
         catch (Exception)
         {
         }
     }
     return true;
 }