private static IStorageContainer CreateFileItemDirectory(Uri uri) { IStorageContainer result = null; result = new FileItemDirectory(uri.LocalPath); return(result); }
/// <summary> /// Initializes a new instance of the <see cref = "StandardFeatureStore" /> class. /// </summary> /// <param name = "storageContainer">The container to / from which the Features will be stored / loaded.</param> public StandardFeatureStore(IStorageContainer storageContainer) { XmlConfigurator.Configure(); m_Logger = LogManager.GetLogger(typeof(StandardFeatureStore)); m_StorageContainer = storageContainer; }
public async Task LoadActivationFile(FileActivatedEventArgs args) { if (args?.Files == null) { return; } if (args.Files.Count < 1) { return; } var path = args.Files[0]?.Path; if (path == null) { return; } var newStore = await LoadTileStore(path); if (newStore == null) { return; } _tileStore?.Dispose(); _tileStore = newStore; _tileCanvas?.ChangeStorage(_tileStore); // The number of files received is args.Files.Size // The name of the first file is args.Files[0].Name }
public void RetrieveDefinedFeaturesThrowsFeatureStoreFaultExceptionOnException() { IStorageContainer storageContainer = m_MockRepository.StrictMock <IStorageContainer>(); FeatureScope scope = FeatureScope.Create(Guid.NewGuid(), Guid.NewGuid()); using (m_MockRepository.Record()) { Expect.Call(storageContainer.Retrieve(scope)).Throw(new CheckFeatureStateException("Bad Mojo Exception")); m_MockRepository.ReplayAll(); FeatureStoreService featureStoreService = new FeatureStoreService(storageContainer); try { featureStoreService.RetrieveDefinedFeatures( RetrieveDefinedFeaturesRequest.Create( "UpdateFeatureStateThrowsFeatureStoreFaultExceptionOnException", scope)); Assert.Fail("Expecting FaultException<FeatureStoreFault>"); } catch (FaultException <FeatureStoreFault> e) { Console.WriteLine(e.Detail.Message); Console.WriteLine(e.Message); StringAssert.Contains(e.Detail.Message, "An exception occurred retrieving defined Features."); } m_MockRepository.VerifyAll(); } }
public void CreateFeatureThrowsFeatureStoreFaultExceptionOnException() { IStorageContainer storageContainer = m_MockRepository.StrictMock <IStorageContainer>(); Feature feature = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), "CreateFeatureThrowsCreateFeatureFaultOnException"); using (m_MockRepository.Record()) { Expect.Call(storageContainer.Retrieve(FeatureKey.Create(feature.Id, feature.OwnerId, feature.Space))). Throw(new CreateFeatureException("Bad Mojo Exception")); m_MockRepository.ReplayAll(); FeatureStoreService featureStoreService = new FeatureStoreService(storageContainer); try { featureStoreService.CreateFeature( CreateFeatureRequest.Create( "CreateFeatureThrowsCreateFeatureFaultOnException", feature)); Assert.Fail("Expecting FaultException<FeatureStoreFault>"); } catch (FaultException <FeatureStoreFault> e) { Console.WriteLine(e.Detail.Message); Console.WriteLine(e.Message); StringAssert.Contains(e.Detail.Message, "Bad Mojo Exception"); } m_MockRepository.VerifyAll(); } }
public void CheckFeatureStateThrowsFeatureStoreFaultExceptionOnException() { IStorageContainer storageContainer = m_MockRepository.StrictMock <IStorageContainer>(); FeatureKey key = FeatureKey.Create(1, Guid.NewGuid(), Guid.NewGuid()); using (m_MockRepository.Record()) { Expect.Call(storageContainer.Retrieve(FeatureKey.Create(key.Id, key.OwnerId, key.Space))).Throw( new CheckFeatureStateException("Bad Mojo Exception")); m_MockRepository.ReplayAll(); FeatureStoreService featureStoreService = new FeatureStoreService(storageContainer); try { featureStoreService.CheckFeatureState( CheckFeatureStateRequest.Create( "CheckFeatureStateThrowsFeatureStoreFaultExceptionOnException", key)); Assert.Fail("Expecting FaultException<FeatureStoreFault>"); } catch (FaultException <FeatureStoreFault> e) { Console.WriteLine(e.Detail.Message); Console.WriteLine(e.Message); StringAssert.Contains(e.Detail.Message, "An exception occurred querying the data store for the Feature."); } m_MockRepository.VerifyAll(); } }
private static IStorageContainer CreateCloudFileContainer(this Uri uri, IStorageConfig storageConfig = null) { IStorageContainer result = null; IStorageConfig scfg = storageConfig ?? new StorageConfig(); CloudStorageAccount sa = scfg.GetStorageAccountByUri(uri); CloudFileDirectory dir = new CloudFileDirectory(uri, sa.Credentials); CloudFileShare share = dir.Share; share.CreateIfNotExistsAsync().GetAwaiter().GetResult(); dir = share.GetRootDirectoryReference(); var directories = uri.Segments.Select(seg => seg.TrimEnd('/')).Where(str => !string.IsNullOrEmpty(str)).ToList(); directories.RemoveAt(0); // remove the share, and leave only dirs var n = 0; while (n < directories.Count) { dir = dir.GetDirectoryReference(directories[n]); dir.CreateIfNotExistsAsync().GetAwaiter().GetResult(); n = n + 1; } result = new CloudFileItemDirectory(dir, scfg); return(result); }
public void CreateFeature() { Feature toCreate = Feature.Create(1, Guid.NewGuid(), Guid.NewGuid(), FeatureName); IStorageContainer container = m_MockRepository.StrictMock <IStorageContainer>(); string messageId = Guid.NewGuid().ToString(); using (m_MockRepository.Record()) { Expect.Call(container.Retrieve(FeatureKey.Create(toCreate.Id, toCreate.OwnerId, toCreate.Space))).Return (null); Expect.Call(container.Store(toCreate)).Return(toCreate); m_MockRepository.ReplayAll(); StandardFeatureStore service = new StandardFeatureStore(container); CreateFeatureRequest request = CreateFeatureRequest.Create(messageId, toCreate); CreateFeatureResponse response = service.CreateFeature(request); Assert.AreEqual(messageId, response.Header.MessageId); Assert.AreEqual(toCreate.Id, response.Result.Id); Assert.AreEqual(toCreate.Name, response.Result.Name); Assert.AreEqual(toCreate.Space, response.Result.Space); Assert.AreEqual(toCreate.OwnerId, response.Result.OwnerId); m_MockRepository.VerifyAll(); } }
/// <summary> /// Conect to a datastore and a canvas view /// </summary> public void SetConnections([NotNull] TileCanvas view, [NotNull] IStorageContainer storage) { _view = view; _storage = storage; // Load pins (adding the default centre view) ThreadPool.QueueUserWorkItem(x => { ReloadPins(); }); }
public override Task OnActivateAsync() { Logger = ServiceProvider.GetService <ILogger <ESGrain <K, S, W> > >(); storageContainer = ServiceProvider.GetService <IStorageContainer>(); mQServiceContainer = ServiceProvider.GetService <IMQServiceContainer>(); Serializer = ServiceProvider.GetService <ISerializer>(); return(RecoveryState()); }
public virtual IStorageLocation GetLocation(IMediaId id) { string key = KeyProvider.GetStorageKey(id); IStorageContainer container = GetContainer(KeyProvider.GetContainerName(key)); var location = container.GetLocation(KeyProvider.GetLocationName(key), id); return(location); }
public async Task AzureStorageCreateAndDeleteContainer() { // Arrange await this._fixture.ContainersCleanup(); const ContainerPermission permission = ContainerPermission.Public; IStorage storage = new AzureBlobStorage(StorageConsts.ConnectionString); bool exceptionCaught = false; // Act var container1 = await storage.CreateOrGetContainerAsync(StorageConsts.Container1Name, permission, failIfExists : true); var container2 = await storage.GetContainerAsync(StorageConsts.Container1Name); IStorageContainer container3 = null; try { container3 = await storage.GetContainerAsync(StorageConsts.Container2Name); } catch (StorageException ex) { if (ex.Reason == StorageExceptionReason.ContainerNotFound) { exceptionCaught = true; } } catch (AggregateException ex) { // async exception can be aggregate if (ex.InnerExceptions.Any(e => e is StorageException)) { exceptionCaught = true; } } var resultPermission1 = await container1.GetPermissionAsync(); var resultPermission2 = await container2.GetPermissionAsync(); var containersList1 = await storage.GetContainersListAsync(StorageConsts.ContainerNamesPrefix); var containersList2 = await storage.GetContainersListAsync(StorageConsts.Container2Name.Substring(0, 12)); await storage.DeleteContainerAsync(StorageConsts.Container1Name); var containersList3 = await storage.GetContainersListAsync(StorageConsts.ContainerNamesPrefix); // Assert Assert.NotNull(container1); Assert.NotNull(container2); Assert.Null(container3); Assert.True(exceptionCaught); Assert.Equal(permission, resultPermission1); Assert.Equal(permission, resultPermission2); Assert.NotNull(containersList1); Assert.NotNull(containersList2); Assert.True(containersList1.Any()); Assert.True(!containersList2.Any()); Assert.Equal(1, containersList1.Count() - containersList3.Count()); }
private void OnCloseRequest(object sender, SystemNavigationCloseRequestedPreviewEventArgs e) { if (_tileStore == null) { return; } _tileStore.Dispose(); _tileStore = null; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { byte hardCreate = requestStream.ReadUInt8(); ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { throw new StorageItemNotFoundException(); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { throw new StorageItemNotFoundException(); } IStorageFile existingFile = container.Content(pathName) as IStorageFile; if (existingFile != null && hardCreate == 0) { return(AfpResultCode.FPObjectExists); } IStorageFile newFile = container.CreateFile(pathName); return(AfpResultCode.FPNoErr); }
public App( IKeyStorageContainer keyStorageContainer, IStorageContainer storageContainer, IPreferencesManager preferencesManager, IDeviceInformationService deviceInformationService) { Mvx.RegisterSingleton(keyStorageContainer); Mvx.RegisterSingleton(storageContainer); Mvx.RegisterSingleton(preferencesManager); Mvx.RegisterSingleton(deviceInformationService); }
/// <summary> /// Use this if the tile data is changed /// </summary> public void ChangeStorage([NotNull] IStorageContainer newTileStore) { _tileStore = newTileStore; // recentre and reset zoom X = 0.0; Y = 0.0; CentreAndZoom(_displayContainer.ActualWidth / 2, _displayContainer.ActualHeight / 2); // clear caches and invalidate ResetCache(); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer newContainer = container.CreateContainer(pathName); uint newContainerId = volume.GetNode(newContainer); responseStream.WriteUInt32(newContainerId); return(AfpResultCode.FPNoErr); }
private static void CreateAndAssert(string configSectionName, string expectedContainerTypeKey, string expectedStorageLocation, Type expectedImplementationType) { StorageContainerConfigurationSection storageContainerConfigurationSection = (StorageContainerConfigurationSection)ConfigurationManager.GetSection(configSectionName); Assert.AreEqual(expectedContainerTypeKey, storageContainerConfigurationSection.ContainerTypeKey); Assert.AreEqual(expectedStorageLocation, storageContainerConfigurationSection.StorageLocation); IStorageContainer storageContainer = StorageContainerFactory.Create(storageContainerConfigurationSection); Assert.IsInstanceOfType(storageContainer, expectedImplementationType); }
public static async Task <IStorageRecord> CreateRecordAsync( this IStorageContainer storageContainer, string name, byte[] data, string contentType = null, IProgress progress = null, CancellationToken cancellationToken = default(CancellationToken)) { using (var buffer = new MemoryStream(data, 0, data.Length, false, true)) { return(await storageContainer.CreateRecordAsync(name, buffer, contentType, progress, cancellationToken).ConfigureAwait(false)); } }
public async Task DesktopStorageGetDirectories() { // Arrange IStorage storage = new FileSystemStorage(this._storagePath); IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName); // Act IEnumerable <string> dirs = await container.GetDirectoriesAsync(""); // Assert Assert.NotNull(dirs); Assert.True(dirs.Any(d => string.Equals(d, DesktopStorageContainerTests._precreatedFolderName, StringComparison.OrdinalIgnoreCase))); }
private static IStorageContainer CreateCloudBlobContainer(Uri uri, IStorageConfig storageConfig = null) { IStorageContainer result = null; IStorageConfig scfg = storageConfig ?? new StorageConfig(); CloudStorageAccount sa = scfg.GetStorageAccountByUri(uri); CloudBlob blob = new CloudBlob(uri, sa.Credentials); CloudBlobContainer blobContainer = blob.Container; blobContainer.CreateIfNotExistsAsync().GetAwaiter().GetResult(); result = new CloudBlobItemContainer(blobContainer, scfg); return(result); }
public static SqlTransaction GetSqlTransaction() { IStorageContainer <SqlTransaction> _container = DataContextStorageFactory <SqlTransaction> .CreateStorageContainer(); var tran = _container.GetObject(key); if (tran == null) { tran = SqlConnectionContextFactory.GetSqlConnection().BeginTransaction(); _container.Store(key, tran); } return(tran); }
/// <summary> /// Load a storage container for the currently selected storage file /// </summary> [NotNull] private async Task <IStorageContainer> LoadTileStore([NotNull] string path) { var directoryName = Path.GetDirectoryName(path); if (string.IsNullOrWhiteSpace(directoryName)) { throw new Exception("Path directory is invalid"); } var folder = await StorageFolder.GetFolderFromPathAsync(directoryName).NotNull(); if (folder == null) { throw new Exception("Path to Slick file is not available"); } var fileName = Path.GetFileName(path); if (string.IsNullOrWhiteSpace(fileName)) { throw new Exception("Path file name is invalid"); } var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists).NotNull(); if (file == null || !file.IsAvailable) { throw new Exception("Failed to load Slick file"); } if (_tileStore != null) { _tileStore.Dispose(); _tileStore = null; } var accessStream = await file.OpenAsync(FileAccessMode.ReadWrite).NotNull(); var wrapper = new StreamWrapper(accessStream); var store = LoadStorageFile(wrapper); if (_tileCanvas != null) { pinsView?.SetConnections(_tileCanvas, store); ImageImportFloater?.SetCanvasTarget(_tileCanvas); TextFloater?.SetCanvasTarget(_tileCanvas); } return(store); }
public static SqlConnection GetSqlConnection() { IStorageContainer <SqlConnection> _container = DataContextStorageFactory <SqlConnection> .CreateStorageContainer(); var _connection = _container.GetObject(key); if (_connection == null || _connection.State == System.Data.ConnectionState.Closed) { _connection = new SqlConnection(conStr); _connection.Open(); _container.Store(key, _connection); } return(_connection); }
void BuildContainers(ConfigNode [] container_nodes) { foreach (var node in container_nodes) { var name = node.GetValue("name"); IStorageContainer sc = CreateContainer(name); if (sc == null) { continue; } sc.Load(node); containers.Add(sc); } }
public SecureChannelService( ICryptoService cryptoService, IStorageContainer storageContainer, IKeyStorageContainer keyStorageContainer, IDeviceInformationService deviceInformationService) { _storageContainer = storageContainer; _keyStorageContainer = keyStorageContainer; _deviceId = deviceInformationService.DeviceId; _cryptoService = cryptoService; _httpClient = new HttpClient { BaseAddress = new Uri(_baseUrl), Timeout = TimeSpan.FromSeconds(20) }; }
public static IStorageContainer <Object> CreateStorageContainer() { if (_storageContainer == null) { //这里实际应该根据配置文件来判定 if (HttpContext.Current == null) { _storageContainer = new ThreadStorageContainer <Object>(); } else { _storageContainer = new HttpStorageContainer <Object>(); } } return(_storageContainer); }
public async Task DesktopStorageGetFilesList() { // Arrange IStorage storage = new FileSystemStorage(this._storagePath); IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName); // Act var files = await container.GetFilesAsync("", StorageSearchOption.AllDirectories | StorageSearchOption.StripPaths); var filesFull = await container.GetFilesAsync("", StorageSearchOption.AllDirectories); // Assert Assert.NotNull(files); Assert.NotNull(filesFull); Assert.True(files.Any()); Assert.True(filesFull.Any()); }
private async void PickPageButton_Click(object sender, RoutedEventArgs e) { if (pinsView != null) { pinsView.Opacity = 0.0; } if (paletteView != null) { paletteView.Opacity = 0.0; } // Save picker won't pick existing files without prompting for overwrite var picker = new Windows.Storage.Pickers.FileSavePicker { CommitButtonText = "Select" }; picker.FileTypeChoices?.Add("Slick files", new[] { ".slick" }); // TODO: How do we stop the 'replace' message? // TODO: how do we ignore selecting the currently open file? // I think I need to make my own file picker :-( //NEVER DO THIS: var file = Sync.Run(() => picker.PickSingleFileAsync()); // doing anything synchronous here causes a deadlock. // ReSharper disable once PossibleNullReferenceException var file = await picker.PickSaveFileAsync().AsTask(); if (file == null || !file.IsAvailable) { return; } var newStore = await LoadTileStore(file.Path); if (newStore == null) { return; } _tileStore?.Dispose(); _tileStore = newStore; _tileCanvas?.ChangeStorage(_tileStore); // Application now has read/write access to the picked file SetTitleBarString(file.DisplayName); }
public async Task DesktopStorageContainerCreateDirectory() { // Arrange string dirName = "CreateDirectory"; IStorage storage = new FileSystemStorage(this._storagePath); IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName); // Act IEnumerable <string> initialDirs = await container.GetDirectoriesAsync(""); await container.CreateDirectoryAsync(dirName); IEnumerable <string> finalDirs = await container.GetDirectoriesAsync(""); // Assert Assert.False(initialDirs.Any(d => string.Equals(d, dirName, StringComparison.OrdinalIgnoreCase))); Assert.True(finalDirs.Any(d => string.Equals(d, dirName, StringComparison.OrdinalIgnoreCase))); }