public static ICommandingDependencyResolver UseAzureStorageCommandAuditing(this ICommandingDependencyResolver dependencyResolver, CloudQueue queue, CloudBlobContainer blobContainer = null, IStorageStrategy storageStrategy = null, AzureStorageAuditorOptions options = null) { options = options ?? new AzureStorageAuditorOptions(); ICloudAuditQueueProvider cloudAuditQueueProvider = new CloudAuditQueueProvider(queue, null); ICloudAuditQueueBlobContainerProvider cloudAuditQueueBlobContainerProvider = new CloudAuditQueueBlobContainerProvider(blobContainer); dependencyResolver.RegisterInstance(cloudAuditQueueProvider); dependencyResolver.RegisterInstance(cloudAuditQueueBlobContainerProvider); dependencyResolver.TypeMapping <IAzureStorageQueueSerializer, AzureStorageQueueSerializer>(); if (options.UsePreDispatchAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UsePreDispatchCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditPreDispatchRootOnly); } if (options.UsePostDispatchAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UsePostDispatchCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditPostDispatchRootOnly); } if (options.UseExecutionAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UseExecutionCommandingAuditor <AzureStorageQueueCommandAuditor>(dependencyResolver, options.AuditExecuteDispatchRootOnly); } return(dependencyResolver); }
public AzureStorageTableCommandAuditor( ICloudStorageProvider cloudStorageProvider, IStorageStrategy storageStrategy) { _cloudStorageProvider = cloudStorageProvider; _storageStrategy = storageStrategy; }
public AutoConvertedModFile(string newFileName, string legacyFileName, IStorageStrategy <TNew> newStorageStrategy, IStorageStrategy <TLegacy> legacyStorageStrategy, IConverter <TLegacy, TNew> converter) { _newFileName = newFileName; _legacyFileName = legacyFileName; _newStorageStrategy = newStorageStrategy; _legacyStorageStrategy = legacyStorageStrategy; _converter = converter; }
/// <summary>初始化</summary> protected void Initialize() { // 绑定存储策略信息 this.storageStrategy = (IStorageStrategy)KernelContext.CreateObject(this.storageSchema.StrategyClassName); // 绑定存储节点信息 this.storageNodes = StorageContext.Instance.StorageNodeService.FindAllBySchemaId(storageSchema.Id); }
/// <summary>构造函数</summary> public TaskReceiverProvider() { this.configuration = TasksConfigurationView.Instance.Configuration; this.ibatisMapping = this.configuration.Keys["IBatisMapping"].Value; this.ibatisMappers = StorageContext.Instance.CreateSqlMappers(this.storageSchemaId, this.ibatisMapping); this.storageStrategy = StorageContext.Instance.StorageSchemaService[this.storageSchemaId].GetStrategyClass(); }
/// <summary>构造函数</summary> public AccountCacheProvider() { this.configuration = SessionsConfigurationView.Instance.Configuration; this.ibatisMapping = this.configuration.Keys["IBatisMapping"].Value; this.storageSchemaId = this.configuration.Keys["StorageSchemaId"].Value; this.ibatisMappers = StorageContext.Instance.CreateSqlMappers(this.storageSchemaId, this.ibatisMapping); this.storageStrategy = StorageContext.Instance.StorageSchemaService[this.storageSchemaId].GetStrategyClass(); }
public PhotoRepository(ApplicationDbContext db, IStorageStrategyFactorySelector storageStrategyFactorySelector, IHostingEnvironment environment) { _db = db; _hostingEnvironment = environment; _storageStrategy = storageStrategyFactorySelector.GetStorageStrategyFactory(new StorageStrategySelectionData { StorageStrategyName = _db.ConfigurationEntities.Find("StorageType").Value, Params = new Dictionary <string, string> { { "folderPath", Path.Combine(_hostingEnvironment.WebRootPath, "uploads") } } }).GetStorageStrategy(); }
public Deck(IStorageStrategy storageStrategy) { _storageStrategy = storageStrategy; _cards = new List <Card>(); foreach (Suit suit in Enum.GetValues(typeof(Suit))) { foreach (Rank rank in Enum.GetValues(typeof(Rank))) { _cards.Add(new Card(suit, rank)); } } }
internal static Photo SavePhoto(CreatePhotoViewModel model, IStorageStrategy storageStrategy, string userId, ApplicationDbContext db) { string[] hashtags = model.HashtagsString.Split(' '); Photo photo = GetPhotoFromCreatePhotoViewModel(model, userId); var extension = model.OriginalImageExtension; if (model.DoConversion) { extension = model.ConversionExtension; } if (!GetAvailableFormats().Any(f => f == extension)) { extension = "Jpeg"; } //var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads"); string uniqueFileName = GetUniqueFileName(extension); //var filePath = Path.Combine(uploads, uniqueFileName); long imageSize = 0; MemoryStream ms = new MemoryStream(); using (Image <Rgba32> image = Image.Load <Rgba32>(model.PhotoFile.OpenReadStream())) { if (model.DoResize) { image.Mutate(x => x .Resize(model.ResizeWidth, model.ResizeHeight) ); } image.Save(ms, ResolveImageEncoder(extension)); photo.Width = image.Width; photo.Height = image.Height; } photo.Url = storageStrategy.Store(ms, uniqueFileName, out imageSize); ms.Close(); photo.Size = imageSize; db.Photos.Add(photo); AddHashtagsToPhoto(db, hashtags, photo.Id); db.SaveChanges(); return(photo); }
public static ICommandingDependencyResolver UseAzureStorageCommandAuditing(this ICommandingDependencyResolver dependencyResolver, CloudStorageAccount cloudStorageAccount, CloudBlobContainer commandPayloadContainer = null, IStorageStrategy storageStrategy = null, AzureStorageAuditorOptions options = null) { options = options ?? new AzureStorageAuditorOptions(); if (!options.UseExecutionAuditor && !options.UsePostDispatchAuditor && !options.UsePreDispatchAuditor) { throw new AzureStorageConfigurationException("At least one auditor type must be configured"); } CloudTableClient cloudTableClient = cloudStorageAccount.CreateCloudTableClient(); if (commandPayloadContainer == null) { commandPayloadContainer = cloudStorageAccount.CreateCloudBlobClient().GetContainerReference("commandauditpayload"); } if (storageStrategy == null) { storageStrategy = new SingleTableStrategy(); } ICloudStorageProvider cloudStorageProvider = new CloudStorageProvider(cloudTableClient, commandPayloadContainer); dependencyResolver.RegisterInstance(cloudStorageProvider); dependencyResolver.RegisterInstance(storageStrategy); if (options.UsePreDispatchAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UsePreDispatchCommandingAuditor <AzureStorageTableCommandAuditor>(dependencyResolver, options.AuditPreDispatchRootOnly); } if (options.UsePostDispatchAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UsePostDispatchCommandingAuditor <AzureStorageTableCommandAuditor>(dependencyResolver, options.AuditPostDispatchRootOnly); } if (options.UseExecutionAuditor) { EnsureCommandingRuntime(dependencyResolver); dependencyResolver.AssociatedCommandingRuntime.UseExecutionCommandingAuditor <AzureStorageTableCommandAuditor>(dependencyResolver, options.AuditExecuteDispatchRootOnly); } return(dependencyResolver); }
static void Main(string[] args) { Task dequeueTask; CancellationTokenSource source = new CancellationTokenSource(); do { Console.WriteLine("1. Use single table storage strategy"); Console.WriteLine("2. Use per day table storage strategy"); Console.WriteLine("3. Use queue auditor (enqueue)"); Console.WriteLine("4. Launch queue auditor processor (dequeue)"); ConsoleKeyInfo info = Console.ReadKey(); if (info.Key == ConsoleKey.D1 || info.Key <= ConsoleKey.D2) { IStorageStrategy storageStrategy = info.Key == ConsoleKey.D1 ? (IStorageStrategy) new SingleTableStrategy() : new TablePerDayStrategy(); #pragma warning disable 4014 RunDemo(storageStrategy); #pragma warning restore 4014 } else if (info.Key == ConsoleKey.D3) { #pragma warning disable 4014 RunQueueDemo(); #pragma warning restore 4014 } else if (info.Key == ConsoleKey.D4) { dequeueTask = RunDequeueDemo(source.Token); } else if (info.Key == ConsoleKey.Escape) { break; } Console.ReadKey(); } while (true); source.Cancel(); Thread.Sleep(500); }
private static ICommandDispatcher Configure(IStorageStrategy storageStrategy) { CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; IServiceCollection serviceCollection = new ServiceCollection(); ICommandingDependencyResolverAdapter dependencyResolver = serviceCollection.GetCommandingDependencyResolver(() => _serviceProvider); IReadOnlyDictionary <string, object> Enricher(IReadOnlyDictionary <string, object> existing) => new Dictionary <string, object> { { "ExampleEnrichedCounter", Interlocked.Increment(ref _counter) } }; Options options = new Options { Reset = true, // we reset the registry because we allow repeat runs, in a normal app this isn't required Enrichers = new [] { new FunctionWrapperCommandDispatchContextEnricher(Enricher) } }; dependencyResolver.AddCommanding(options) .Register <ChainCommandHandler>() .Register <OutputWorldToConsoleCommandHandler>(); dependencyResolver.AddAzureStorageCommandAuditing(storageAccount, storageStrategy: storageStrategy); _serviceProvider = serviceCollection.BuildServiceProvider(); return(_serviceProvider.GetService <ICommandDispatcher>()); }
private static async Task RunDemo(IStorageStrategy storageStrategy) { ICommandDispatcher dispatcher = Configure(storageStrategy); await dispatcher.DispatchAsync(new ChainCommand()); }
private static async Task <IAzureStorageAuditQueueProcessorFactory> ConfigureDequeue(IStorageStrategy storageStrategy) { CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; CloudQueue auditQueue = storageAccount.CreateCloudQueueClient().GetQueueReference("auditqueue"); await auditQueue.CreateIfNotExistsAsync(); IServiceCollection serviceCollection = new ServiceCollection(); ICommandingDependencyResolverAdapter resolver = serviceCollection.GetCommandingDependencyResolver(() => _serviceProvider); Options options = new Options { Reset = true // we reset the registry because we allow repeat runs, in a normal app this isn't required }; resolver.AddCommanding(options); resolver.AddQueues(); resolver.AddAzureStorageCommandAuditing(storageAccount, storageStrategy: storageStrategy); // this sets up the table store auditors resolver.AddAzureStorageAuditQueueProcessor(auditQueue); // this sets up queue listening _serviceProvider = serviceCollection.BuildServiceProvider(); return(_serviceProvider.GetService <IAzureStorageAuditQueueProcessorFactory>()); }
/// <summary>Registers custom storage strategy implementation. /// By default, the <code>DefaultStorageStrategy</code> instance is used. /// There is no need to explicitly call this method until some more complex storage implementation is needed. /// </summary> /// <param name="customStorageStrategy">IStorageStrategy interface implementation.</param> public void RegisterCustomStorageStrategy(IStorageStrategy customStorageStrategy) { _storageStrategy = customStorageStrategy; }
private ILocalData GetLocalData(IStorageStrategy strategy) { return new LocalDataImpl(strategy, handler); }
public StorageService(IStorageStrategy strategy) { _strategy = strategy; }
public ILocalData GetCustomStore(IStorageStrategy strategy) { return GetLocalData(strategy); }
public ModFile(string filename, IStorageStrategy <T> storageStrategy) { FileName = filename; _storageStrategy = storageStrategy; _data = new Lazy <T>(() => _storageStrategy.ReadData(_stream), LazyThreadSafetyMode.ExecutionAndPublication); }