Esempio n. 1
0
        public void UploadContent(string tag, string sourceSoftLink, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag, bool acquireSourceReaderLock)
        {
            TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout);

            sourceSoftLink = this.GetLocalPath(sourceSoftLink);
            if ((!FabricFile.Exists(sourceSoftLink)) &&
                (!FabricDirectory.Exists(sourceSoftLink)))
            {
                throw new IOException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              StringResources.ImageStoreError_DoesNotExistError,
                              sourceSoftLink));
            }

            try
            {
                using (XStoreFileOperations xstoreFileOperation =
                           new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName)))
                {
                    tag = XStoreCommon.FormatXStoreUri(tag);
                    if (copyFlag == CopyFlag.AtomicCopy)
                    {
                        this.DeleteContent(tag, helper == null ? timeout : helper.GetRemainingTime());
                    }

                    if (FabricFile.Exists(sourceSoftLink))
                    {
                        // This is a file copy
                        xstoreFileOperation.CopyFile(
                            sourceSoftLink,
                            tag,
                            XStoreFileOperationType.CopyFromSMBToXStore,
                            helper);
                    }
                    else
                    {
                        // this is a folder copy
                        xstoreFileOperation.CopyFolder(
                            sourceSoftLink,
                            tag,
                            XStoreFileOperationType.CopyFromSMBToXStore,
                            copyFlag,
                            null,
                            null,
                            helper);
                    }
                }
            }
            catch (Exception ex)
            {
                this.HandleException(ex);
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Copies content from a path in the XStore to the destination path in the XStore
        /// </summary>
        /// <param name="remoteSource"> Location relative to RootUri where the content to be copied will be found. </param>
        /// <param name="remoteDestination"> Location relative to RootUri where the content needs to be copied. </param>
        /// <param name="timeout">The timeout for performing the copying operation.</param>
        /// <param name="skipFiles">The list of the blobs to be skipped for copying </param>
        /// <param name="copyFlag">The copying control information to specify how blob can be overwritten.</param>
        /// <param name="checkMarkFile">Indicats whether to check mark file during copying.</param>
        public void CopyContent(string remoteSource, string remoteDestination, TimeSpan timeout, string[] skipFiles, CopyFlag copyFlag, bool checkMarkFile)
        {
            TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout);

            try
            {
                using (
                    XStoreFileOperations xstoreFileOperation =
                        new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName)))
                {
                    remoteSource      = XStoreCommon.FormatXStoreUri(remoteSource);
                    remoteDestination = XStoreCommon.FormatXStoreUri(remoteDestination);

                    bool xstoreFileExist   = xstoreFileOperation.XStoreFileExists(remoteSource, helper);
                    bool xstoreFolderExist = xstoreFileOperation.XStoreFolderExists(remoteSource, checkMarkFile, helper);

                    if ((!xstoreFileExist) && (!xstoreFolderExist))
                    {
                        throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.ImageStoreError_DoesNotExistError, remoteSource));
                    }

                    if (copyFlag == CopyFlag.AtomicCopy)
                    {
                        this.DeleteContent(remoteDestination, helper == null ? timeout : helper.GetRemainingTime());
                    }

                    if (xstoreFileExist)
                    {
                        // this is a single blob copy from xstore to xstore
                        xstoreFileOperation.CopyFile(
                            remoteSource,
                            remoteDestination,
                            XStoreFileOperationType.CopyFromXStoreToXStore,
                            helper);
                    }
                    else
                    {
                        xstoreFileOperation.CopyFolder(
                            remoteSource,
                            remoteDestination,
                            XStoreFileOperationType.CopyFromXStoreToXStore,
                            copyFlag,
                            null,
                            skipFiles,
                            helper);
                    }
                }
            }
            catch (Exception ex)
            {
                this.HandleException(ex);
                throw;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Downloads content from the XStore to local destination.
        /// </summary>
        /// <param name="tag">Location (relative to RootUri) from where to download the content.</param>
        /// <param name="destinationSoftLink">Physical location where to download the content.</param>
        /// <param name="handler">Defines the behavior to process progress information from the downloading operation.</param>
        /// <param name="timeout">The timeout for performing the downloading operation.</param>
        /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param>
        public void DownloadContent(string tag, string destinationSoftLink, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag)
        {
            TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout);

            destinationSoftLink = this.GetLocalPath(destinationSoftLink);
            try
            {
                using (XStoreFileOperations xstoreFileOperation =
                           new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName)))
                {
                    tag = XStoreCommon.FormatXStoreUri(tag);
                    bool xstoreFileExist   = xstoreFileOperation.XStoreFileExists(tag, helper);
                    bool xstoreFolderExist = xstoreFileOperation.XStoreFolderExists(tag, true, helper);

                    if ((!xstoreFileExist) && (!xstoreFolderExist))
                    {
                        throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.ImageStoreError_DoesNotExistError, tag));
                    }

                    if (xstoreFileExist)
                    {
                        // this is a single blob copy from xstore to smb
                        xstoreFileOperation.CopyFile(
                            tag,
                            destinationSoftLink,
                            XStoreFileOperationType.CopyFromXStoreToSMB,
                            helper);
                    }
                    else
                    {
                        // this is a multiple blob (folder) copy from xstore to smb
                        xstoreFileOperation.CopyFolder(
                            tag,
                            destinationSoftLink,
                            XStoreFileOperationType.CopyFromXStoreToSMB,
                            copyFlag,
                            null,
                            null,
                            helper);
                    }
                }
            }
            catch (Exception ex)
            {
                this.HandleException(ex);
                throw;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Downloads content from the XStore to local destination.
        /// </summary>
        /// <param name="tag">Location (relative to RootUri) from where to download the content.</param>
        /// <param name="destinationSoftLink">Physical location where to download the content.</param>
        /// <param name="handler">Defines the behavior to process progress information from the downloading operation.</param>
        /// <param name="timeout">The timeout for performing the downloading operation.</param>
        /// <param name="copyFlag">The copying control information to specify how file can be overwritten.</param>
        public void DownloadContent(string tag, string destinationSoftLink, IImageStoreProgressHandler handler, TimeSpan timeout, CopyFlag copyFlag)
        {
            TimeoutHelper helper = timeout == TimeSpan.MaxValue ? null : new TimeoutHelper(timeout);

            destinationSoftLink = this.GetLocalPath(destinationSoftLink);
            try
            {
                using (XStoreFileOperations xstoreFileOperation =
                           new XStoreFileOperations(new XStoreParameters(this.providerParams.ConnectionString, this.providerParams.SecondaryConnectionString, this.providerParams.ContainerName)))
                {
                    tag = XStoreCommon.FormatXStoreUri(tag);
                    bool xstoreFileExist   = xstoreFileOperation.XStoreFileExists(tag, helper);
                    bool xstoreFolderExist = xstoreFileOperation.XStoreFolderExists(tag, true, helper);

                    if ((!xstoreFileExist) && (!xstoreFolderExist))
                    {
                        throw new FileNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.ImageStoreError_DoesNotExistError, tag));
                    }

                    if (xstoreFileExist)
                    {
                        // this is a single blob copy from xstore to smb
                        xstoreFileOperation.CopyFile(
                            tag,
                            destinationSoftLink,
                            XStoreFileOperationType.CopyFromXStoreToSMB,
                            helper);
                    }
                    else
                    {
                        var operationId = Guid.NewGuid();

                        // this is a multiple blob (folder) copy from xstore to smb
                        xstoreFileOperation.CopyFolder(
                            tag,
                            destinationSoftLink,
                            XStoreFileOperationType.CopyFromXStoreToSMB,
                            copyFlag,
                            null,
                            null,
                            helper,
                            operationId);

                        var blobContentEntries = XStoreCommon.GetDownloadContentEntries(operationId);
                        if (blobContentEntries == null)
                        {
                            return;
                        }

                        var missingFiles = blobContentEntries.Where(entry => !File.Exists(entry.Item2));
                        if (missingFiles.Count() > 0)
                        {
                            //The missing file count will be traced out and there will be no retrying without remaining time.
                            //The following step to do will return proper error code after sync up with hosting and image builder.
                            if (helper != null && helper.GetRemainingTime() == TimeSpan.Zero)
                            {
                                this.traceSource.WriteWarning(
                                    ClassName,
                                    "{0} files missing after downloading, OperationID: {1}", missingFiles.Count(), operationId);
                                return;
                            }

                            this.traceSource.WriteWarning(
                                ClassName,
                                "Retry to download the {0} missing files, operationID: {1}", missingFiles.Count(), operationId);

                            foreach (var file in missingFiles)
                            {
                                xstoreFileOperation.CopyFile(
                                    file.Item1,
                                    file.Item2,
                                    XStoreFileOperationType.CopyFromXStoreToSMB,
                                    helper);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.HandleException(ex);
                throw;
            }
        }