Esempio n. 1
0
        /// <summary>
        /// Resets existing copy progress state with the specified providers.
        /// </summary>
        /// <param name="providers"></param>
        public void ResetCopyState(ProviderCollection providers)
        {
            CopyState = new Dictionary <StorageProviderTypes, StorageProviderFileStatus>();

            foreach (var provider in providers)
            {
                if (provider.Type == ProviderTypes.Storage)
                {
                    var item = new StorageProviderFileStatus(provider.Name);
                    CopyState.Add(item.Provider, item);
                }
            }

            SetOverallStateFromCopyState();
        }
Esempio n. 2
0
        /// <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>
        /// Returns the status of a file as it exists (or doesn't) in Azure cloud storage.
        /// </summary>
        /// <param name="file"><c>BackupFile</c></param>
        /// <param name="sourceLocation"><c>SourceLocation</c></param>
        /// <param name="directory"><c>DirectoryMapItem</c></param>
        /// <returns><c>ProviderFileStatus</c></returns>
        public async Task <StorageProviderFileStatus> GetFileStatusAsync(BackupFile file, SourceLocation sourceLocation, DirectoryMapItem directory)
        {
            // calculate my uri
            string sasBlobUri = null;

            if (sourceLocation.Priority == FileBackupPriority.Meta)
            {
                // file has a specific destination container. this is reserved for meta folders.
                // use that specific container and filename instead of a guid-based uri.
                sasBlobUri = ProviderUtilities.GetFileUri(AzureStorage.Credentials.AccountName, sourceLocation.DestinationContainerName, file.Filename.ToLower());
            }
            else
            {
                sasBlobUri = ProviderUtilities.GetFileUri(AzureStorage.Credentials.AccountName, directory.GetRemoteContainerName(StorageProviderTypes.Azure), file.GetRemoteFileName(StorageProviderTypes.Azure));
            }

            // the default state for a freshly initialized file status object is unsynced.
            // if the blob doesn't exist, the file is unsynced.

            CloudBlockBlob blob       = new CloudBlockBlob(new Uri(sasBlobUri), AzureStorage.Credentials);
            var            fileStatus = new StorageProviderFileStatus(StorageProviderTypes.Azure);

            // does the file exist at the specified uri?

            if (await blob.ExistsAsync(MetaDataRequestOptions, null).ConfigureAwait(false))
            {
                // -- query metadata
                // -- determine state from metadata

                await blob.FetchAttributesAsync(null, MetaDataRequestOptions, null).ConfigureAwait(false);

                var allPropsAndMetadata = new Dictionary <string, string>(blob.Metadata);
                allPropsAndMetadata.Add(ProviderMetadata.HydrationStateKeyName, ProviderUtilities.GetHydrationStatusFromAzureState(blob.Properties.RehydrationStatus));

                fileStatus.ApplyMetadataToState(allPropsAndMetadata);
            }

            return(fileStatus);
        }