Example #1
0
        public IFileSystem GetFileSystem()
        {
            IFileSystem fileSystem = null;

            var fs = _fileSystemProviderRepository.GetFileSystem();

            if (fs != null)
            {
                if (fs.Type == "PhysicalFileSystem")
                {
                    fileSystem = new PhysicalFileSystem("~/media");
                }
                else
                {
                    try
                    {
                        fileSystem = AzureFileSystem.GetInstance(
                            ConfigurationManager.AppSettings["AzureBlobFileSystem.ContainerName:media"],
                            ConfigurationManager.AppSettings["AzureBlobFileSystem.RootUrl:media"],
                            ConfigurationManager.AppSettings["AzureBlobFileSystem.ConnectionString:media"],
                            ConfigurationManager.AppSettings["AzureBlobFileSystem.MaxDays:media"],
                            ConfigurationManager.AppSettings["AzureBlobFileSystem.UseDefaultRoute:media"],
                            ConfigurationManager.AppSettings["AzureBlobFileSystem.UsePrivateContainer:media"]);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }

            return(fileSystem ?? new PhysicalFileSystem("~/media"));
        }
Example #2
0
        private AzureFileSystem GetAzureFileSystem()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(source.ConnectionString);
            AzureFileSystem     fileSystem     = new AzureFileSystem(new LocalCache(), new Uri(source.Path), new Uri(source.Path), storageAccount, source.Name, source.FeedSubPath);

            return(fileSystem);
        }
        public IFileSystem Create(string sUser, string sPassword)
        {
            string containerName = "";

            // TODO: Put your authentication call here. Return NULL if authentication fails. Return an initialised AzureFileSystem() object if authentication is successful.
            // In the example below, to demonstrate, any username will work so long as the password == "test".
            // Remember: you can plug in your own authentication & authorisation API to fetch the correct container name for the specified user.
            /*
            #region "REPLACE THIS WITH CODE TO YOUR OWN AUTHENTICATION API"
            if (sPassword == "test")
            {
                containerName = sUser;
            }
            else
            {
                return null;
            }
            #endregion  */

            var accountManager = new AccountManager();
            if (accountManager.CertificateAccount(sUser, sPassword))
                containerName = sUser;
            else
                return null;

            var system = new AzureFileSystem(sUser, sPassword, containerName, Modes.Development);
            return system;
        }
Example #4
0
        private async Task <bool> InitAsync()
        {
            LocalSettings   settings   = GetSettings();
            AzureFileSystem fileSystem = GetAzureFileSystem();
            bool            result     = await InitCommand.RunAsync(settings, fileSystem, enableCatalog : false, enableSymbols : false, log : new SleetLogger(Log), token : CancellationToken);

            return(result);
        }
Example #5
0
        private async Task <bool> InitAsync()
        {
            LocalSettings   settings   = GetSettings();
            AzureFileSystem fileSystem = GetAzureFileSystem();
            bool            result     = await InitCommand.RunAsync(settings, fileSystem, true, true, new SleetLogger(Log), CancellationToken);

            return(result);
        }
Example #6
0
        private async Task <bool> PushAsync(IEnumerable <string> items, bool allowOverwrite)
        {
            LocalSettings   settings   = GetSettings();
            AzureFileSystem fileSystem = GetAzureFileSystem();
            bool            result     = await PushCommand.RunAsync(settings, fileSystem, items.ToList(), allowOverwrite, false, new SleetLogger(Log));

            return(result);
        }
Example #7
0
        private async Task <bool> InitAsync()
        {
            using (var fileCache = CreateFileCache())
            {
                LocalSettings   settings   = GetSettings();
                AzureFileSystem fileSystem = GetAzureFileSystem(fileCache);
                bool            result     = await InitCommand.RunAsync(settings, fileSystem, enableCatalog : false, enableSymbols : false, log : new SleetLogger(Log, NuGet.Common.LogLevel.Verbose), token : CancellationToken);

                return(result);
            }
        }
Example #8
0
 public AzureTestContext()
 {
     ContainerName  = Guid.NewGuid().ToString();
     StorageAccount = CloudStorageAccount.Parse(GetConnectionString());
     BlobClient     = StorageAccount.CreateCloudBlobClient();
     Container      = BlobClient.GetContainerReference(ContainerName);
     LocalCache     = new LocalCache();
     LocalSettings  = new LocalSettings();
     FileSystem     = new AzureFileSystem(LocalCache, Uri, StorageAccount, ContainerName);
     Logger         = new TestLogger();
 }
        public AzureLuceneIndexProvider(
            IAppDataFolder appDataFolder,
            ShellSettings shellSettings,
            ILuceneAnalyzerProvider analyzerProvider,
            ILuceneAzureFileSystemFactory fileSystemFactory)
            : base(new StubAppDataFolder(appDataFolder), shellSettings, analyzerProvider)
        {
            _appDataFolder = appDataFolder;
            _shellSettings = shellSettings;

            _fileSystem     = fileSystemFactory.Create(shellSettings.Name);
            _storageAccount = CloudStorageAccount.Parse(_fileSystem.StorageConnectionString);
        }
        public AzureBlobShellSettingsManager(IMimeTypeProvider mimeTypeProvider, IShellSettingsManagerEventHandler events)
        {
            var connectionString = CloudConfigurationManager.GetSetting(Constants.ShellSettingsStorageConnectionStringSettingName);
            var containerName    = CloudConfigurationManager.GetSetting(Constants.ShellSettingsContainerNameSettingName);

            if (String.IsNullOrEmpty(containerName))
            {
                containerName = Constants.ShellSettingsDefaultContainerName;
            }
            _fileSystem = new AzureFileSystem(connectionString, containerName, String.Empty, true, mimeTypeProvider);
            _events     = events;
            Logger      = NullLogger.Instance;
        }
Example #11
0
        public async Task GivenAStorageAccountVerifyPushWithBaseURI()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new AzureTestContext())
                {
                    var baseUri    = new Uri("http://tempuri.org/abc/");
                    var fileSystem = new AzureFileSystem(testContext.LocalCache, testContext.Uri, baseUri, testContext.StorageAccount, testContext.ContainerName);
                    testContext.FileSystem = fileSystem;

                    await testContext.InitAsync();

                    var testPackage = new TestNupkg("packageA", "1.0.0");
                    var zipFile     = testPackage.Save(packagesFolder.Root);

                    var result = await InitCommand.RunAsync(testContext.LocalSettings,
                                                            testContext.FileSystem,
                                                            enableCatalog : true,
                                                            enableSymbols : true,
                                                            log : testContext.Logger,
                                                            token : CancellationToken.None);

                    result &= await PushCommand.RunAsync(testContext.LocalSettings,
                                                         testContext.FileSystem,
                                                         new List <string>() { zipFile.FullName },
                                                         force : false,
                                                         skipExisting : false,
                                                         log : testContext.Logger);

                    result &= await ValidateCommand.RunAsync(testContext.LocalSettings,
                                                             testContext.FileSystem,
                                                             testContext.Logger);

                    result.Should().BeTrue();

                    // Check baseURIs
                    await BaseURITestUtil.VerifyBaseUris(testContext.FileSystem.Files.Values, baseUri);

                    await testContext.CleanupAsync();
                }
        }
        private AzureFileSystem Init(ConnectionStringsSection connectionStrings, string containerName, bool isPrivate = false)
        {
            ConnectionStringSettings css = connectionStrings.ConnectionStrings["AzureStorageConnection"];
            string connectionString = css != null
                                   ? css.ConnectionString
                                   : (ConfigurationManager.AppSettings["AzureStorageConnectionString"] ?? "UseDevelopmentStorage=true");
            var account = CloudStorageAccount.Parse(connectionString);
            if (string.IsNullOrEmpty(containerName))
                containerName = ConfigurationManager.AppSettings["AzureStorageContainerName"] ?? "n2tests";
            _root = ConfigurationManager.AppSettings["AzureStorageRootFolderName"] ?? "default"; // orchard: default
            string delAll = ConfigurationManager.AppSettings["AzureStorageDeleteAllOnStartup"] ?? "false";

            if (account == null) 
                throw new ConfigurationErrorsException("Bad Azure Storage Configuration");
            
            var isp = new AzureFileSystem(containerName, _root, isPrivate, account);
            if (delAll.Equals("true", StringComparison.InvariantCultureIgnoreCase))
            {
                isp.Container.DeleteAllBlobs(); // start with a fresh container, used in unit tests
            }
            return isp;
        }
        public IFileSystem Create(string sUser, string sPassword)
        {
            string containerName = "";
            // TODO: Put your authentication call here. Return NULL if authentication fails. Return an initialised AzureFileSystem() object if authentication is successful.
            // In the example below, to demonstrate, any username will work so long as the password == "test".
            // Remember: you can plug in your own authentication & authorisation API to fetch the correct container name for the specified user.

            #region "REPLACE THIS WITH CODE TO YOUR OWN AUTHENTICATION API"
            EcommercePlatformDataContext db = new EcommercePlatformDataContext();
            try {
                Profile p = AzureFtpServer.General.ProfileModel.GetProfile(sUser, sPassword);
                if (!AzureFtpServer.General.ProfileModel.hasPermission(p.id)) {
                    throw new Exception("You do not have permission.");
                }
                containerName = p.username;
            } catch {
                return null;
            };

            #endregion

            var system = new AzureFileSystem(sUser, sPassword, containerName, Modes.Development);
            return system;
        }
 public AzureStorageFileSystem(ConnectionStringsSection connectionStrings)
 {
     isp = Init(connectionStrings, null);
 }
 public AzureShellSettingsManager(CloudStorageAccount storageAccount, IShellSettingsManagerEventHandler events) {
     _events = events;
     _fileSystem = new AzureFileSystem(ContainerName, String.Empty, true, storageAccount);
 }
 public AzureBlobShellSettingsManager(IMimeTypeProvider mimeTypeProvider, IShellSettingsManagerEventHandler events)
 {
     _fileSystem = new AzureFileSystem(CloudConfigurationManager.GetSetting(Constants.ShellSettingsStorageConnectionStringSettingName), Constants.ShellSettingsContainerName, String.Empty, true, mimeTypeProvider);
     _events     = events;
     Logger      = NullLogger.Instance;
 }
Example #17
0
        private async Task <bool> PushAsync(
            IEnumerable <string> items,
            PushOptions options)
        {
            LocalSettings   settings   = GetSettings();
            AzureFileSystem fileSystem = GetAzureFileSystem();
            SleetLogger     log        = new SleetLogger(Log);

            var packagesToPush = items.ToList();

            if (!options.AllowOverwrite && options.PassIfExistingItemIdentical)
            {
                var context = new SleetContext
                {
                    LocalSettings = settings,
                    Log           = log,
                    Source        = fileSystem,
                    Token         = CancellationToken
                };
                context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                    context.Source,
                    context.Log,
                    context.Token);

                var flatContainer = new FlatContainer(context);

                var packageIndex = new PackageIndex(context);

                // Check packages sequentially: Task.WhenAll caused IO exceptions in Sleet.
                for (int i = packagesToPush.Count - 1; i >= 0; i--)
                {
                    string item = packagesToPush[i];

                    bool?identical = await IsPackageIdenticalOnFeedAsync(
                        item,
                        packageIndex,
                        context.Source,
                        flatContainer,
                        log);

                    if (identical == null)
                    {
                        continue;
                    }

                    packagesToPush.RemoveAt(i);

                    if (identical == true)
                    {
                        Log.LogMessage(
                            MessageImportance.Normal,
                            "Package exists on the feed, and is verified to be identical. " +
                            $"Skipping upload: '{item}'");
                    }
                    else
                    {
                        Log.LogError(
                            "Package exists on the feed, but contents are different. " +
                            $"Upload failed: '{item}'");
                    }
                }

                if (!packagesToPush.Any())
                {
                    Log.LogMessage("After skipping idempotent uploads, no items need pushing.");
                    return(true);
                }
            }

            return(await PushCommand.RunAsync(
                       settings,
                       fileSystem,
                       packagesToPush,
                       options.AllowOverwrite,
                       skipExisting : false,
                       log : log));
        }
Example #18
0
        private async Task <bool> PushAsync(
            IEnumerable <string> items,
            PushOptions options)
        {
            LocalSettings settings       = GetSettings();
            SleetLogger   log            = new SleetLogger(Log, NuGet.Common.LogLevel.Verbose);
            var           packagesToPush = items.ToList();

            // Create a separate LocalCache to use for read only operations on the feed.
            // Files added to the cache before the lock could be modified by the process
            // currently holding the lock. Sleet assumes that files in the cache
            // are valid and identical to the ones on the feed since operations are
            // normally performed inside the lock.
            using (var preLockCache = CreateFileCache())
            {
                AzureFileSystem preLockFileSystem = GetAzureFileSystem(preLockCache);

                if (!options.AllowOverwrite && options.PassIfExistingItemIdentical)
                {
                    var context = new SleetContext
                    {
                        LocalSettings = settings,
                        Log           = log,
                        Source        = preLockFileSystem,
                        Token         = CancellationToken
                    };
                    context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault(
                        context.Source,
                        context.Log,
                        context.Token);

                    var flatContainer = new FlatContainer(context);

                    var packageIndex = new PackageIndex(context);

                    // Check packages sequentially: Task.WhenAll caused IO exceptions in Sleet.
                    for (int i = packagesToPush.Count - 1; i >= 0; i--)
                    {
                        string item = packagesToPush[i];

                        bool?identical = await IsPackageIdenticalOnFeedAsync(
                            item,
                            packageIndex,
                            context.Source,
                            flatContainer,
                            log);

                        if (identical == null)
                        {
                            continue;
                        }

                        packagesToPush.RemoveAt(i);

                        if (identical == true)
                        {
                            Log.LogMessage(
                                MessageImportance.Normal,
                                "Package exists on the feed, and is verified to be identical. " +
                                $"Skipping upload: '{item}'");
                        }
                        else
                        {
                            Log.LogError(
                                "Package exists on the feed, but contents are different. " +
                                $"Upload failed: '{item}'");
                        }
                    }

                    if (!packagesToPush.Any())
                    {
                        Log.LogMessage("After skipping idempotent uploads, no items need pushing.");
                        return(true);
                    }
                }
            }

            // Create a new cache to be used once a lock is obtained.
            using (var fileCache = CreateFileCache())
            {
                var lockedFileSystem = GetAzureFileSystem(fileCache);

                return(await PushCommand.RunAsync(
                           settings,
                           lockedFileSystem,
                           packagesToPush,
                           options.AllowOverwrite,
                           skipExisting : false,
                           log : log));
            }
        }
 public AzureAppDataFolder() {
     _fs = new AzureFileSystem("appdata", null, true);
 }
 protected override void OnInit()
 {
     // http://stackoverflow.com/questions/13110488/azure-october-2012-sdk-broke-usedevelopmentstorage-true
     _devAccount = CloudStorageAccount.DevelopmentStorageAccount;
     _azureBlobStorageProvider = new AzureFileSystem("media", "default", false, _devAccount);
 }
 protected override void OnInit() {
     // http://stackoverflow.com/questions/13110488/azure-october-2012-sdk-broke-usedevelopmentstorage-true
     _devAccount = CloudStorageAccount.DevelopmentStorageAccount;
     _azureBlobStorageProvider = new AzureFileSystem("media", "default", false, _devAccount);        
 }
Example #22
0
 public AzureShellSettingsManager(CloudStorageAccount storageAccount, IShellSettingsManagerEventHandler events)
 {
     _events     = events;
     _fileSystem = new AzureFileSystem(ContainerName, String.Empty, true, storageAccount);
 }
 public AzureStorageFileSystem(ConnectionStringsSection connectionStrings, string containerName, bool isPrivate)
 {
     isp = Init(connectionStrings, containerName, isPrivate);
 }