public void SetUp()
        {
            _blobContainer = new Mock <IBlobContainerRepository>();
            _cloudBlob     = new Mock <ICloudBlob>();

            _sourceFileRepository = new SourceFileRepository(_blobContainer.Object);
        }
Example #2
0
 private FileHandle ResolveFileHandle(Guid handleId)
 {
     return(SourceFileRepository.ResolveFileByHandleId(handleId));
 }
Example #3
0
        /// <summary>
        /// Execute this operation. Exceptions are handled by calling method.
        /// </summary>
        public void ExecuteOperation()
        {
            try
            {
                int status = 0;
                FCSH.EventHub.CopyOperationCreationHandler(this, _targets, ref status);

                //::::::::::::::::::::::::::::::

                if (_executeCalledViaEvent)
                {
                    ExecuteEvent();
                }

                //::::::::::::::::::::::::::::::

                LogManager.GetLogger("FileMate").Trace("Entry of ExecuteOperation() ...");
                if (!IsExecuting)
                {
                    LogManager.GetLogger("FileMate").Debug("Executing operation ...");

                    bool     overallResultOk = true;
                    string[] sourceFiles     = SourceFileRepository.GetFileList();

                    LogManager.GetLogger("FileMate").Debug(string.Format("sourceFiles count = {0}", sourceFiles.Length));

                    status = 0;

                    if (sourceFiles.Length > 0)
                    {      // only do work if necessary
                        LogManager.GetLogger("FileMate").Debug("Found source files ...");

                        // initialise targets (for use with dynamic targets i.e., c:\target\{date}\)
                        foreach (IFileRepository t in _targets)
                        {
                            FCSH.EventHub.BackupInitiationHandler(this, t.Name, ref status);
                            t.Initialise();
                        }

                        // do the transfer
                        foreach (String file in sourceFiles)
                        {
                            string fileName = Path.GetFileName(file);
                            //FileInfo fi = new FileInfo(file);
                            //lastTransferSize = fi.Length;

                            status = 0;

                            foreach (IFileRepository t in _targets)
                            {
                                LogManager.GetLogger("FileMate").Debug(string.Format("transferring {0} to {1} ...", fileName, t.Url));
                                try
                                {
                                    if ((overallResultOk = t.TransferFile(_source.GetFileStream(fileName), fileName)))
                                    {
                                        FCSH.EventHub.BackupCompletionHandler(this, t.Name, ref status);
                                    }
                                }
                                catch (FCE.Base te)
                                {
                                    FCSH.EventHub.FailureHandler(this, new Object[2] {
                                        transferInterval, te
                                    }, ref status);
                                }

                                if (status == (int)OperationStatus.ForceToTerminate)
                                {
                                    overallResultOk = false;
                                    break;
                                }
                            }
                            if (!overallResultOk)
                            {
                                break;
                            }
                        }

                        // delete source files only if all transfers completed ok
                        if (overallResultOk)
                        {
                            LogManager.GetLogger("FileMate").Debug("deleting source ...");
                            if (_deleteSource)
                            {
                                _source.DeleteFiles();
                            }
                        }
                        else
                        {
                            LogManager.GetLogger("FileMate").Error("errors occured during transfer, processing stopped");
                        }
                    }
                    else
                    {
                        LogManager.GetLogger("FileMate").Debug("No files to transfer.");
                    }
                    IsExecuting = false;
                }

                //::::::::::::::::::::::::::::::

                FCSH.EventHub.CopyOperationShutdownHandler(this, _targets, ref status);
            }
            catch (Exception e)
            {
                LogManager.GetLogger("FileMate").FatalException("Unhandled exception while executing operation; throwing!", e);
                throw new FCE.TransferOperation(String.Format("Failure transfering file to {0}", _name), _name, e);
            }
        }