public bool Matches(UploaderKey key) { return(this.Key.Matches(key)); }
private bool CreateUploaderForApplicationFolder( string uploaderId, string source, string workFolder, out AzureFileUploader uploader) { uploader = null; bool success = true; AzureFileUploader newUploader; // Check if we can use an existing uploader object UploaderKey key = new UploaderKey() { SourcePath = source, // Destination path is an concatenation of storage account name and container name DestinationPath = string.Concat( this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage ? AzureConstants.DevelopmentStorageConnectionString : this.blobUploadSettings.StorageAccountFactory.Connection.AccountName, ";", // This separator cannot occur in account name or container name this.blobUploadSettings.ContainerName), ApplicationType = this.configReader.GetApplicationType(), }; lock (AllUploaders) { UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Matches(key)); if (null != uploaderInfo) { // Existing uploader object is available. Increment its reference count this.traceSource.WriteInfo( this.logSourceId, "Existing uploader object for application type {0}, source {1}, storage account {2}, container {3} is available and will be used.", key.ApplicationType, source, this.blobUploadSettings.StorageAccountFactory.Connection.AccountName, this.blobUploadSettings.ContainerName); uploaderInfo.RefCount++; newUploader = uploaderInfo.Uploader; success = true; } else { // Create a new uploader object this.traceSource.WriteInfo( this.logSourceId, "Creating uploader object for application type {0}, source {1}, storage account {2}, container {3} ...", key.ApplicationType, source, this.blobUploadSettings.StorageAccountFactory.Connection.AccountName, this.blobUploadSettings.ContainerName); // Create and initialize the uploader // // NOTE: We do not make any assumptions about the contents of general // data folders. Hence, as part of old data deletion, we attempt to // delete all files in the corresponding container, without trying to // filter files by Fabric node ID. We do this by specifying 'false' // for the 'filterDeletionByNodeId' parameter. try { var destinationPath = string.Concat( this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage ? AzureConstants.DevelopmentStorageConnectionString : this.blobUploadSettings.StorageAccountFactory.Connection.AccountName, ";", // This separator cannot occur in account name or container name this.blobUploadSettings.ContainerName); newUploader = new AzureFileUploader( this.traceSource, this.logSourceId, source, destinationPath, workFolder, this.blobUploadSettings.StorageAccountFactory, this.blobUploadSettings.ContainerName, this.blobUploadSettings.UploadInterval, this.blobUploadSettings.FileSyncInterval, this.blobUploadSettings.BlobDeletionAge, this.initParam.FabricNodeInstanceName, this.blobUploadSettings.DeploymentId); newUploader.Start(); uploaderInfo = new UploaderInfo() { Key = key, RefCount = 1, Uploader = newUploader }; AllUploaders.Add(uploaderInfo); this.traceSource.WriteInfo( this.logSourceId, "Upload to file share is configured. Storage account: {0}, Container: {1}, Local folder path: {2}, Upload interval (minutes): {3}.", this.blobUploadSettings.StorageAccountFactory.Connection.AccountName, this.blobUploadSettings.ContainerName, source, this.blobUploadSettings.UploadInterval); uploader = newUploader; } catch (Exception) { this.traceSource.WriteError( this.logSourceId, "Failed to create uploader object for application type {0}, source {1}, storage account {2}, container {3}.", key.ApplicationType, source, this.blobUploadSettings.StorageAccountFactory.Connection.AccountName, this.blobUploadSettings.ContainerName); } } } return(success); }
internal bool Matches(UploaderKey other) { return(this.SourcePath.Equals(other.SourcePath, StringComparison.OrdinalIgnoreCase) && this.DestinationPath.Equals(other.DestinationPath, StringComparison.Ordinal) && this.ApplicationType.Equals(other.ApplicationType, StringComparison.Ordinal)); }
private bool CreateUploaderForApplicationFolder( string uploaderId, string source, string destination, string workFolder, out FileShareUploader uploader) { uploader = null; bool success; FileShareUploader newUploader = null; // Check if we can use an existing uploader object UploaderKey key = new UploaderKey() { SourcePath = source, DestinationPath = destination, ApplicationType = this.configReader.GetApplicationType(), }; lock (AllUploaders) { UploaderInfo uploaderInfo = AllUploaders.FirstOrDefault(w => w.Matches(key)); if (null != uploaderInfo) { // Existing uploader object is available. Increment its reference count this.traceSource.WriteInfo( this.logSourceId, "Existing uploader object for application type {0}, source {1} and destination {2} is available and will be used.", key.ApplicationType, source, destination); uploaderInfo.RefCount++; newUploader = uploaderInfo.Uploader; success = true; } else { // Create a new uploader object this.traceSource.WriteInfo( this.logSourceId, "Creating uploader object for application type {0}, source {1} and destination {2} ...", key.ApplicationType, source, destination); // Create and initialize the uploader try { newUploader = new FileShareUploader( this.traceSource, uploaderId, true, // runningOnBehalfOfApplication source, destination, this.fileUploadSettings.AccessInfo, workFolder, this.fileUploadSettings.UploadInterval, this.fileUploadSettings.FileSyncInterval, this.fileUploadSettings.FileDeletionAgeMinutes, this.fileUploadSettings.DestinationIsLocalAppFolder, this.initParam.FabricNodeId); newUploader.Start(); success = true; } catch (Exception) { success = false; } if (success) { uploaderInfo = new UploaderInfo() { Key = key, RefCount = 1, Uploader = newUploader }; AllUploaders.Add(uploaderInfo); } else { this.traceSource.WriteError( this.logSourceId, "Failed to create uploader object for application type {0}, source {1} and destination {2}.", key.ApplicationType, source, destination); } } } if (success) { this.traceSource.WriteInfo( this.logSourceId, "Upload to file share is configured. Destination: {0}, Local folder path: {1}, Upload interval (minutes): {2}.", destination, source, this.fileUploadSettings.UploadInterval); uploader = newUploader; } return(success); }