/// <summary> /// Sets the provider status to failed. /// </summary> /// <param name="Provider"></param> public void SetProviderToFailed(StorageProviderTypes Provider) { if (!CopyState.ContainsKey(Provider)) { CopyState.Add(Provider, new StorageProviderFileStatus(Provider)); } var state = CopyState[Provider]; state.SyncStatus = FileStatus.ProviderError; SetOverallStateFromCopyState(); }
/// <summary> /// Calculates the provider-specific remote path. /// </summary> /// <param name="Provider"></param> /// <returns></returns> public string GetRemoteContainerName(StorageProviderTypes Provider) { // Different cloud providers may have different naming rules for URIs. // Azure for example is all lowercase required. if (ID == Guid.Empty) { throw new InvalidOperationException("Cannot generate container name. Directory ID has not been set."); } if (Provider == StorageProviderTypes.Azure) { return(string.Format("{0}-directory-{1}", Constants.Logging.AppName, ID.ToString()).ToLower()); } else { throw new NotImplementedException("unexpected provider type: " + Provider.ToString()); } }
/// <summary> /// Flags a particular block index as sent for the specified provider. /// </summary> /// <param name="BlockIndex"></param> /// <param name="Providers"></param> public void SetBlockAsSent(int BlockIndex, StorageProviderTypes Provider) { if (BlockIndex < 0) { throw new ArgumentException(nameof(BlockIndex) + " argument must be provided with a positive number."); } if (OverallState == FileStatus.Synced) { throw new InvalidOperationException("File is already synced."); } if (CopyState == null || CopyState.Count == 0) { throw new InvalidOperationException("File has no copystate set."); } if (CopyState.ContainsKey(Provider)) { var state = CopyState[Provider]; state.LastCompletedFileBlockIndex = BlockIndex; if (state.LastCompletedFileBlockIndex + 1 == TotalFileBlocks) { // flag this particular destination as completed. state.SyncStatus = FileStatus.Synced; } else { // file transfer is still in progress. state.SyncStatus = FileStatus.InProgress; } } else { throw new InvalidOperationException("Attempted to set copy state for destination that wasn't found in the copy state."); } SetOverallStateFromCopyState(); }
/// <summary> /// Returns the remote file name for the specified provider. /// </summary> /// <param name="provider">The cloud provider.</param> /// <returns>A </returns> public string GetRemoteFileName(StorageProviderTypes provider) { // Different cloud providers may have different naming rules for URIs. // Azure for example is all lowercase required. if (FileID == Guid.Empty) { throw new InvalidOperationException("Cannot generate file name. FileID has not been set."); } if (provider == StorageProviderTypes.Azure) { if (Filename.Contains(".")) { // file with an extension. var split = Filename.Split('.'); var extension = split[split.Length - 1]; // we only want alphanumeric characters in the uri // if for some reason windows allows special characters in the extension, dont use the extension in the uri then. var reg = new Regex("^[a-zA-Z0-9]*$"); if (extension.Length > 0 && reg.IsMatch(extension)) { return(string.Format("{0}-file-{1}-v{2}.{3}", Constants.Logging.AppName, FileID.ToString(), FileRevisionNumber, extension).ToLower()); } } // extensionless (or problematic extension) file. return(string.Format("{0}-file-{1}-v{2}", Constants.Logging.AppName, FileID.ToString(), FileRevisionNumber).ToLower()); } else { throw new NotImplementedException("unexpected provider type: " + provider.ToString()); } }
/// <summary> /// A constructor that accepts a <c>ProviderTypes</c> enumeration. /// </summary> /// <param name="provider"></param> public StorageProviderFileStatus(StorageProviderTypes provider) { Provider = provider; ResetState(); }