private void Initialize(WorkflowHost host, string templateData) { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); _host = host; _workspaceContainerName = WorkflowShared.WorkflowInstanceWorkspaceName(Id); Workspace = Catalog.Preconfigure() .Add(WorkspaceLocalConfig.WorkspaceName, _workspaceContainerName) .ConfiguredResolve <IWorkspace>(_workflowWorkspaceKey); if (null == _wfLock) { _wfLock = ConstructLock(Id); } SpecifyUsingTemplate(templateData); var instance = new WorkflowInstanceInfo { Id = Id, TemplateName = Name, LastActivity = DateTime.UtcNow, NextActivationTime = DateTime.UtcNow, Status = WorkflowStatus.Active.ToString(), }; _instanceData.Store(instance); }
public DocumentDistributedMutex() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); _name = config[DistributedMutexLocalConfig.Name].ToLowerInvariant(); var seconds = config.Get <int>(DistributedMutexLocalConfig.UnusedExpirationSeconds); if (seconds < 15) { seconds = 15; } _expireUnused = TimeSpan.FromSeconds(seconds); _renewWait = TimeSpan.FromSeconds(seconds - 5); _cts = new CancellationTokenSource(); _cancelGrooming = new CancellationTokenSource(); _cancelGroomingToken = _cancelGrooming.Token; _groomingTask = Task.Factory.StartNew(GroomExpired, _cancelGroomingToken); _acquirer = Guid.NewGuid(); CreateIfNotExists(); }
public AzureFilesBlobContainer() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); _containerName = config[BlobContainerLocalConfig.ContainerName]; EntityAccess access = (EntityAccess)Enum.Parse(typeof(EntityAccess), config.Get(BlobContainerLocalConfig.OptionalAccess, EntityAccess.Private.ToString())); _contentType = config.Get(BlobContainerLocalConfig.OptionalContentType, "application/raw"); _account = Client.FromConfig(); _client = _account.CreateCloudBlobClient(); _client.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5)); var blobContainerPermissions = new BlobContainerPermissions { PublicAccess = AzureEntityAccessTranslator.Translate(access) }; _blobContainerPermissions = blobContainerPermissions; _container = _client.GetContainerReference(_containerName.ToLowerInvariant()); if (_container.CreateIfNotExist()) { _container.SetPermissions(_blobContainerPermissions); } }
public PayPalIPNGateway() { _accountBroker = Catalog.Factory.Resolve <IAccountTypeBroker>(); _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); _config = Catalog.Factory.Resolve <IConfig>(); }
public LocalMessageBus() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); var source = new CancellationTokenSource(); _ct = source.Token; }
/// <summary> /// use the expiration metadata attribute to remove expired containers. /// </summary> /// <param name="prefix"> </param> /// <param name="ct"> </param> public static void GroomExpiredContainers(string prefix = null, CancellationToken?ct = null) { ILog log = ClassLogger.Create(typeof(AzureStorageAssistant)); DebugOnlyLogger dblog = DebugOnlyLogger.Create(log); try { var account = CloudStorageAccount.FromConfigurationSetting(CommonConfiguration.DefaultStorageConnection.ToString()); var bc = account.CreateCloudBlobClient(); if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } IEnumerable <CloudBlobContainer> containers; if (!string.IsNullOrEmpty(prefix)) { containers = bc.ListContainers(prefix); } else { containers = bc.ListContainers(); } if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } Parallel.ForEach(containers, c => { c.FetchAttributes(); if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } if (c.Metadata.AllKeys.Contains(BlobMetaPropertyExpired)) { DateTime expirationTime = DateTime.Parse(c.Metadata[BlobMetaPropertyExpired], CultureInfo.InvariantCulture); if (DateTime.UtcNow > expirationTime) { c.Delete(); } } }); } catch (Exception ex) { log.Warn(ex.Message); log.Warn(ex.ToString()); throw; } }
public AccountTypeBrokerBase() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); _config = Catalog.Factory.Resolve <IConfig>(); _sender = _config[SendEmailSettings.EmailReplyAddress]; _authCode = string.Empty; }
public void Initialize(CancellationToken token) { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); _ct = token; Compose(); }
public RavenGlobalConfig() { var cf = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); var company = cf[ApplicationTopologyLocalConfig.CompanyKey]; var product = cf[ApplicationTopologyLocalConfig.ApplicationKey]; _reg = new ApplicationNodeRegistry(company, product); _log = ClassLogger.Create(GetType()); _dbLog = DebugOnlyLogger.Create(_log); _updateCycle = Catalog.Factory.Resolve <IRecurrence <object> >(); }
public AzureEnvironmentDistributedMutex() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); _name = config[DistributedMutexLocalConfig.Name].ToLowerInvariant(); _expireUnused = TimeSpan.FromSeconds(config.Get <int>(DistributedMutexLocalConfig.UnusedExpirationSeconds)); var account = Client.FromConfig().ForBlobs(); _container = account.GetContainerReference(AzureConstants.LeaseContainer); _container.CreateIfNotExist(); _leaseBlob = _container.GetBlobReference(_name); _cts = new CancellationTokenSource(); _cancelGrooming = new CancellationTokenSource(); try { if (!_leaseBlob.Exists()) { _leaseBlob.UploadText("1"); _leaseBlob.SetExpiration(_expireUnused); _log.InfoFormat("Creating distributed mutex for {0}, auto expires in {1}", _name, _expireUnused); } } catch (StorageClientException storageClientException1) { StorageClientException storageClientException = storageClientException1; if (storageClientException.ErrorCode == StorageErrorCode.BlobAlreadyExists || storageClientException.StatusCode == HttpStatusCode.PreconditionFailed) { } else { throw; } } _groomingTask = Task.Factory.StartNew( () => AzureStorageAssistant.CleanExpiredBlobsFrom(AzureConstants.LeaseContainer, _cancelGrooming.Token, false)); }
public BlobFileDownload(string container = null) { if (string.IsNullOrWhiteSpace(container)) { IConfig config = Catalog.Factory.Resolve <IConfig>(); _container = config.Get(CommonConfiguration.DefaultDownloadContainer, "downloads"); } else { _container = container; } _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); }
public ScheduledJobWorker() { _hostEnv = Catalog.Factory.Resolve <IHostEnvironment>(); _logger = ClassLogger.Create(typeof(ScheduledJobWorker)); _dlog = DebugOnlyLogger.Create(_logger); _jobScheduler = Catalog.Factory.Resolve <IJobScheduler>(); var config = Catalog.Factory.Resolve <IConfig>(); _sender = Catalog.Preconfigure() .Add(MessagePublisherLocalConfig.HostConnectionString, config[CommonConfiguration.DefaultBusConnection]) .Add(MessagePublisherLocalConfig.ExchangeName, ExchangeName) .ConfiguredResolve <IMessagePublisher>(ScopeFactoryContexts.Distributed); }
public AzureBlobBlobContainer() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); _containerName = config.Get(BlobContainerLocalConfig.ContainerName, string.Empty); EntityAccess access = (EntityAccess)Enum.Parse(typeof(EntityAccess), config.Get(BlobContainerLocalConfig.OptionalAccess, EntityAccess.Private.ToString())); _contentType = config.Get(BlobContainerLocalConfig.OptionalContentType, "application/json"); _account = Client.FromConfig(); if (String.IsNullOrEmpty(_containerName)) { var type = typeof(T); if (!type.IsClass) { throw new ArgumentNullException("You must specify a container for containers that use value types."); } _containerName = type.Name.ToLowerInvariant(); if ((_containerName.EndsWith("blob") || _containerName.EndsWith("view")) && _containerName.Length > 4) { _containerName = _containerName.Substring(0, _containerName.Length - 4); } } _client = _account.CreateCloudBlobClient(); _client.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(5)); var blobContainerPermissions = new BlobContainerPermissions { PublicAccess = AzureEntityAccessTranslator.Translate(access) }; _blobContainerPermissions = blobContainerPermissions; _container = _client.GetContainerReference(_containerName.ToLowerInvariant()); if (_container.CreateIfNotExist()) { _container.SetPermissions(_blobContainerPermissions); } }
public BlobDataSpooler() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); var spoolId = config[DataSpoolerLocalConfig.SpoolId]; var pageSize = config.Get <int>(DataSpoolerLocalConfig.PageSize); var lifeTimeMinutes = config.Get(DataSpoolerLocalConfig.OptionalLifeTimeMinutes, -1); TimeSpan?lifeTime = null; if (lifeTimeMinutes != -1) { lifeTime = TimeSpan.FromMinutes(lifeTimeMinutes); } Initialize(spoolId, pageSize, lifeTime); }
public HorizonalScaleCloudQueue(CloudQueueClient queueClient, string queueBaseName, int numberOfPartitions) { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); _queueClient = queueClient; _queueBaseName = queueBaseName; List <CloudQueue> partitions = new List <CloudQueue>(); for (int i = 0; i < numberOfPartitions; i++) { CloudQueue q = queueClient.GetQueueReference(_queueBaseName + i); partitions.Add(q); } _queues = new List <CloudQueue>(Shuffle(partitions)); }
public AzureBlobImageStorage() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); var maxCacheSize = config.Get <int>(ImageStorageLocalConfig.CacheSize); var hitRenewsExpiration = config.Get <bool>(ImageStorageLocalConfig.CacheHitRenewsExpiration); var minutes = config.Get(ImageStorageLocalConfig.OptionalExpirationTimeMinutes, 60); var expirationLife = TimeSpan.FromMinutes(minutes); _containerName = config[ImageStorageLocalConfig.ContainerName]; _cache = Catalog.Preconfigure() .Add(CachedDataLocalConfig.OptionalCacheHitRenewsExpiration, hitRenewsExpiration) .Add(CachedDataLocalConfig.OptionalDefaultExpirationTimeSeconds, expirationLife) .Add(CachedDataLocalConfig.OptionalGroomExpiredData, true) .Add(CachedDataLocalConfig.OptionalMaximumCacheSize, maxCacheSize) .ConfiguredResolve <ICachedData <string, byte[]> >(DurabilityFactoryContexts.Volatile); _bc = Client.FromConfig().ForBlobs(); }
public AzureDistributedMessageBus() { var account = CloudStorageAccount.FromConfigurationSetting(CommonConfiguration.DefaultStorageConnection.ToString()); account.Ensure(containers: new[] { _containerName }); _qc = account.CreateCloudQueueClient(); IConfig config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); int partitionCount = 5; var busName = config.Get(MessageBusLocalConfig.OptionalNamedMessageBus, GlobalBusName); if (GlobalBusName != busName) { _queueName = busName; } _q = new HorizonalScaleCloudQueue(_qc, _queueName, partitionCount); _bc = account.CreateCloudBlobClient(); _container = _bc.GetContainerReference(_containerName); _log = ClassLogger.Create(typeof(AzureDistributedMessageBus)); _dblog = DebugOnlyLogger.Create(_log); }
public static void Check(params string[] roles) { Debug.Assert(roles.EmptyIfNull().Any()); var log = ClassLogger.Create(typeof(WebPermitRoles)); var dblog = DebugOnlyLogger.Create(log); var context = HttpContext.Current; var user = context.User; foreach (string role in roles) { if (user.IsInRole(role)) { dblog.InfoFormat("{0} granted access through role {1}", user.Identity.Name, role); return; } } log.ErrorFormat("{0} is not in any role {1}, security exception", user.Identity.Name, string.Join(",", roles)); throw new SecurityException(string.Format("user {0} does not have role required for action.", user.Identity.Name)); }
public BlobBufferedFileUpload() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); }
public void BeginLogging() { _log = ClassLogger.Create(GetType()); _dbLog = DebugOnlyLogger.Create(_log); }
public void SetUp() { target = new DebugOnlyLogger(); Log.Entries += LogFailure; }
public PayPalAccountTypeBroker() { _logger = ClassLogger.Create(GetType()); _dblogger = DebugOnlyLogger.Create(_logger); }
/// <summary> /// groom using the expired metadata attribute /// </summary> /// <param name="containerName"> </param> /// <param name="ct"> </param> /// <param name="removeEmptyContainer"> </param> public static void CleanExpiredBlobsFrom(string containerName, CancellationToken?ct = null, bool removeEmptyContainer = false) { ILog log = ClassLogger.Create(typeof(AzureStorageAssistant)); DebugOnlyLogger dblog = DebugOnlyLogger.Create(log); try { var account = CloudStorageAccount.FromConfigurationSetting(CommonConfiguration.DefaultStorageConnection.ToString()); account.Ensure(containers: new[] { containerName }); var bc = account.CreateCloudBlobClient(); var container = bc.GetContainerReference(containerName); BlobRequestOptions blobQuery = new BlobRequestOptions(); blobQuery.BlobListingDetails = BlobListingDetails.Metadata; blobQuery.UseFlatBlobListing = true; if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } IEnumerable <IListBlobItem> blobs; blobs = container.ListBlobs(blobQuery).ToArray(); foreach (IListBlobItem blob in blobs) { if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } CloudBlob cloudBlob; cloudBlob = container.GetBlobReference(blob.Uri.ToString()); var md = cloudBlob.Metadata[BlobMetaPropertyExpired]; if (!string.IsNullOrWhiteSpace(md)) { DateTime expirationDate = DateTime.Parse(md, CultureInfo.InvariantCulture); if (DateTime.UtcNow > expirationDate) { dblog.InfoFormat("Grooming blob {0}", cloudBlob.Uri); cloudBlob.DeleteIfExists(blobQuery); } } } if (removeEmptyContainer) { if (!container.ListBlobs().Any()) { container.Delete(); } } } catch (Exception ex) { log.Warn(ex.Message); log.Warn(ex.ToString()); throw; } }
public AzureLocalFileMirror() { _log = ClassLogger.Create(GetType()); _dblog = DebugOnlyLogger.Create(_log); InitializeConfig(); }
/// <summary> /// using the expiration metadata attribute, delete the container of all contents are expired. /// </summary> /// <param name="containerName"> </param> /// <param name="ct"> </param> public static void GroomContainerIfAllExpired(string containerName, CancellationToken?ct = null) { ILog log = ClassLogger.Create(typeof(AzureStorageAssistant)); DebugOnlyLogger dblog = DebugOnlyLogger.Create(log); try { var account = CloudStorageAccount.FromConfigurationSetting(CommonConfiguration.DefaultStorageConnection.ToString()); account.Ensure(containers: new[] { containerName }); var bc = account.CreateCloudBlobClient(); var container = bc.GetContainerReference(containerName); BlobRequestOptions blobQuery = new BlobRequestOptions(); blobQuery.BlobListingDetails = BlobListingDetails.Metadata; blobQuery.UseFlatBlobListing = true; if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } ResultSegment <IListBlobItem> blobs; blobs = container.ListBlobsSegmented(blobQuery); bool more = false; long freshContent = 0; do { Parallel.ForEach(blobs.Results, blob => { if (Interlocked.Read(ref freshContent) > 0) { return; } if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } try { CloudBlob cloudBlob; cloudBlob = container.GetBlobReference(blob.Uri.ToString()); cloudBlob.FetchAttributes(); var md = cloudBlob.Metadata[BlobMetaPropertyExpired]; if (Interlocked.Read(ref freshContent) > 0) { return; } if (!string.IsNullOrWhiteSpace(md)) { DateTime expirationDate = DateTime.Parse(md, CultureInfo. InvariantCulture); if (DateTime.UtcNow < expirationDate) { Interlocked.Increment(ref freshContent); return; } } } catch { Interlocked.Increment(ref freshContent); // make no assumptions at this point } }); more = blobs.HasMoreResults; if (more) { blobs = blobs.GetNext(); } } while (more && freshContent == 0); if (freshContent == 0) { container.Delete(); } } catch (Exception ex) { log.Warn(ex.Message); log.Warn(ex.ToString()); throw; } }
protected ParallelWorkersRoleEntryPoint() { _lg = ClassLogger.Create(typeof(ParallelWorkersRoleEntryPoint)); _dbg = DebugOnlyLogger.Create(_lg); }
/// <summary> /// groom out blobs that are too old /// </summary> /// <param name="containerName"> </param> /// <param name="old"> </param> /// <param name="ct"> </param> /// <param name="removeEmptyContainer"> </param> public static void GroomOldBlobsFrom(string containerName, TimeSpan old, CancellationToken?ct = null, bool removeEmptyContainer = false) { ILog log = ClassLogger.Create(typeof(AzureStorageAssistant)); DebugOnlyLogger dblog = DebugOnlyLogger.Create(log); try { log.InfoFormat("Grooming blobs from {0} older than {1}", containerName, old.ToString()); var account = CloudStorageAccount.FromConfigurationSetting(CommonConfiguration.DefaultStorageConnection.ToString()); account.Ensure(containers: new[] { containerName }); var bc = account.CreateCloudBlobClient(); var container = bc.GetContainerReference(containerName); BlobRequestOptions blobQuery = new BlobRequestOptions(); blobQuery.BlobListingDetails = BlobListingDetails.None; blobQuery.UseFlatBlobListing = true; blobQuery.AccessCondition = AccessCondition.IfNotModifiedSince(DateTime.UtcNow.AddDays(-1 * old.Days)); if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } IEnumerable <IListBlobItem> blobs; blobs = container.ListBlobs(blobQuery).ToArray(); foreach (IListBlobItem blob in blobs) { if (ct.HasValue) { ct.Value.ThrowIfCancellationRequested(); } CloudBlob cloudBlob; cloudBlob = container.GetBlobReference(blob.Uri.ToString()); dblog.InfoFormat("Grooming blob {0}", cloudBlob.Uri); cloudBlob.DeleteIfExists(blobQuery); } if (removeEmptyContainer) { if (!container.ListBlobs().Any()) { container.Delete(); } } } catch (Exception ex) { log.Warn(ex.Message); log.Warn(ex.ToString()); throw; } }