/// <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> /// Updates the known local provider state if it doesn't match the remote state. /// </summary> /// <param name="remoteState"></param> public bool UpdateLocalStateIfRemoteStateDoesNotMatch(StorageProviderFileStatus remoteState) { if (CopyState == null) { throw new InvalidOperationException("Unable to compare copy state, it is not populated when it should be."); } var hasChanged = false; if (CopyState.ContainsKey(remoteState.Provider)) { var localState = CopyState[remoteState.Provider]; if (localState.SyncStatus != remoteState.SyncStatus) { hasChanged = true; } else if (localState.HydrationStatus != remoteState.HydrationStatus) { hasChanged = true; } else if (localState.LastCompletedFileBlockIndex != remoteState.LastCompletedFileBlockIndex) { hasChanged = true; } } else { hasChanged = true; } if (hasChanged) { CopyState[remoteState.Provider] = remoteState; SetOverallStateFromCopyState(); } return(hasChanged); }
/// <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(); }