Beispiel #1
0
        public void CopyFile(string filename)
        {
            if (SourcePath.Equals("") || DestPath.Equals(""))
            {
                return;
            }

            if (SourcePath.Equals(DestPath))
            {
                var result = MessageBox.Show("Такой файл уже существует, вы " +
                                             "хотите его заменить?", "Замена файла",
                                             MessageBoxButton.YesNo, MessageBoxImage.Warning);

                if (result != MessageBoxResult.OK)
                {
                    return;
                }
            }
            File.Copy(SourcePath + filename, DestPath + filename, true);

            if (UpdateListListener != null)
            {
                UpdateListListener.UpdateList(SourcePath, filename);
            }
        }
Beispiel #2
0
        /// <summary>
        /// TODO: description
        /// </summary>
        /// <param name="context"></param>
        public void Run(ActionContext context = null)
        {
            if (!SourcePath.IsAbsolute && context?.BasePath == null)
            {
                throw new ArgumentException("The context BasePath must be specified when the SourcePath is relative.", nameof(context));
            }

            if (!TargetPath.IsAbsolute && context?.BasePath == null)
            {
                throw new ArgumentException("The context BasePath must be specified when the TargetPath is relative.", nameof(context));
            }

            if (SourcePath.Equals(TargetPath))
            {
                throw new NotSupportedException("The SourcePath cannot equal the TargetPath.");
            }

            if (SourcePath.IsDirectory != TargetPath.IsDirectory)
            {
                throw new NotSupportedException("Both the source and target paths must be of the same type.");
            }

            try
            {
                // get the absolute paths, rooted off of the context base path if necessary
                Path sourcePath = SourcePath.IsAbsolute ? SourcePath : Path.Combine(context.BasePath, SourcePath);
                Path targetPath = TargetPath.IsAbsolute ? TargetPath : Path.Combine(context.BasePath, TargetPath);

                // ensure that target directory path exists
                Directory.CreateDirectory(Path.GetDirectoryName(targetPath));   // TODO: support for remote paths

                Logger?.Info("Moving {0} to {1}", sourcePath, targetPath);
                if (SourcePath.IsDirectory)
                {
                    Directory.Move(sourcePath, targetPath);   // TODO: support for remote paths
                }
                else
                {
                    File.Move(sourcePath, targetPath);   // TODO: support for remote paths
                }
            }
            catch (Exception ex)
            {
                // swallow the exception and log a warning if optional, otherwise propagate upwards
                if (Optional)
                {
                    Logger?.Warn(ex, "Optional action failure.");
                }
                else
                {
                    throw;
                }
            }
        }
Beispiel #3
0
 public bool Equals(MLTProject pProject)
 {
     return(
         pProject != null &&
         SourceExists.Equals(pProject.SourceExists) &&
         SourceIsValid.Equals(pProject.SourceIsValid) &&
         TargetExists.Equals(pProject.TargetExists) &&
         TargetIsValid.Equals(pProject.TargetIsValid) &&
         TargetName.Equals(pProject.TargetName) &&
         TargetPath.Equals(pProject.TargetPath) &&
         FullPath.Equals(pProject.FullPath) &&
         Job.Equals(pProject.Job) &&
         Name.Equals(pProject.Name) &&
         SourcePath.Equals(pProject.SourcePath));
 }
        /// Adds file or its chunks to Consumer queue
        protected long AddFileToConsumerQueue(string fileFullName, long fileLength, bool isToBeChunked, out long fileSizeToTransfer)
        {
            string relativePath;

            if (SourcePath.Equals(fileFullName)) //This is the case when the input path is a file
            {
                relativePath = "";
            }
            else
            {
                relativePath = fileFullName.Substring(SourcePath.Length);
                relativePath = GetDestDirectoryFormatted(relativePath);
            }
            long   numChunks       = 0;
            string tempChunkFolder = null;

            fileSizeToTransfer = 0;
            // We will never be here if the log has detected that the file is done
            if (isToBeChunked)
            {
                //If RecordedMetadata.EntryTransferAttemptedLastTime(fileFullName) is true then the file was attempted and incomplete. Because if it is successful then we will not be here
                int numChunksAlreadyTransferred = RecordedMetadata.EntryTransferAttemptedLastTime(fileFullName) ? RecordedMetadata.LoadedMetaData[fileFullName].Chunks.Count : -1;
                // numChunksAlreadyTransferred is -1 means this file was not attempted before so effectively 0 chunks were done
                numChunks       = fileLength / ChunkSize + (fileLength % ChunkSize == 0 ? 0 : 1);
                tempChunkFolder = RecordedMetadata.EntryTransferAttemptedLastTime(fileFullName) ? RecordedMetadata.LoadedMetaData[fileFullName].SegmentFolder : DestPath + relativePath + Guid.NewGuid() + "Segments";
                var bulk = AssignMetaData(fileFullName, tempChunkFolder, DestPath + relativePath, fileLength, numChunks, numChunksAlreadyTransferred);
                if (numChunksAlreadyTransferred == numChunks)
                {// If all chunks were transferred correctly then add a CopyFileJob only. CopyFileJob will make the necessary checks and determine which state we are in
                    ConsumerQueue.Add(new CopyFileJob(0, bulk, Client));
                }
                else
                {
                    // If this file was attempted in last transfer and it is being resumed, at the enumeration time we just add the jobs for the chunks which are not
                    // reported in the log file. In reality there can be different states 1) Only those reported in resume file are done 2) More than reported are done however concat wasn't started yet
                    // 3) All chunks are actually done and concat is half done 4) All chunks are done and concat is done. The discrepancy between the resume file and actual events is because the
                    // log file is written in a separate producer-consumer queue (not serialized) for perf reasons. All these cases checked and are taken care in FileMetaData.
                    // If we are in state 1 and 2 then the jobs are done as expected. If we are in states beyond 2 then we do the required concat job and chunks
                    // are reported done without any actual transfer.
                    for (int i = 0; i < numChunks; i++)
                    {
                        if (RecordedMetadata.EntryTransferAttemptedLastTime(fileFullName) && RecordedMetadata.LoadedMetaData[fileFullName].Chunks.Contains(i))
                        {
                            continue;
                        }
                        ConsumerQueue.Add(new CopyFileJob(i, bulk, Client));
                        fileSizeToTransfer += i == numChunks - 1 ? fileLength - i * ChunkSize : ChunkSize;
                    }
                }
                // Number of chunks to be uploaded for this file will be the total chunks minus the chunks already transferred
                numChunks -= numChunksAlreadyTransferred < 0 ? 0 : numChunksAlreadyTransferred;
            }
            else
            {
                FileMetaData bulk = AssignMetaData(fileFullName, null, DestPath + relativePath, fileLength, numChunks);
                ConsumerQueue.Add(new CopyFileJob(-1, bulk, Client));
                fileSizeToTransfer = fileLength;
            }
            if (FileTransferLog.IsDebugEnabled)
            {
                FileTransferLog.Debug($"FileTransfer.FileProduced, Name: {fileFullName}, Dest: {tempChunkFolder ?? DestPath + relativePath}, Length: {fileLength}, Chunks: {numChunks}");
            }
            return(numChunks);
        }
Beispiel #5
0
        /// <summary>
        /// TODO: description
        /// </summary>
        /// <param name="context"></param>
        public void Run(ActionContext context)
        {
            if (!SourcePath.IsAbsolute && context?.BasePath == null)
            {
                throw new ArgumentException("The context BasePath must be specified when the SourcePath is relative.", nameof(context));
            }

            if (!TargetPath.IsAbsolute && context?.BasePath == null)
            {
                throw new ArgumentException("The context BasePath must be specified when the TargetPath is relative.", nameof(context));
            }

            if (Content != null && context?.ContentBasePath == null)
            {
                throw new ArgumentException("The context ContentBasePath must be specified when working with Content.", nameof(context));
            }

            if (SourcePath.IsDirectory || TargetPath.IsDirectory)
            {
                throw new NotSupportedException("Both the source and target paths must be files.");
            }

            string tempPatchPath      = Utility.GetTempFilePath();
            string tempTargetCopyPath = Utility.GetTempFilePath();

            try
            {
                // get the absolute paths, rooted off of the context base path if necessary
                Path sourcePath = SourcePath.IsAbsolute ? SourcePath : Path.Combine(context.BasePath, SourcePath);
                Path targetPath = TargetPath.IsAbsolute ? TargetPath : Path.Combine(context.BasePath, TargetPath);
                Logger?.Info("Patching {0} against {1} to {2} using the {3} algorithm", sourcePath, tempPatchPath, targetPath, Algorithm);

                IPatcher patcher = Utility.GetPatcher(Algorithm);

                // write the patch file to a temp location
                Content.Save(Path.Combine(context.ContentBasePath, Content.Id + "\\"), tempPatchPath,
                             Overwrite); // TODO: specify remote content path format as part of context

                // if source and target paths are the same, copy source to temp location first to patch against
                if (SourcePath.Equals(TargetPath))
                {
                    File.Copy(sourcePath, tempTargetCopyPath);                    // TODO: support for remote paths
                    patcher.Apply(tempTargetCopyPath, tempPatchPath, targetPath); // TODO: support for remote paths
                }
                else
                {
                    patcher.Apply(sourcePath, tempPatchPath, targetPath); // TODO: support for remote paths
                }
            }
            catch (Exception ex)
            {
                // swallow the exception and log a warning if optional, otherwise propagate upwards
                if (Optional)
                {
                    Logger?.Warn(ex, "Optional action failure.");
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                File.Delete(tempPatchPath);
                File.Delete(tempTargetCopyPath);
            }
        }
Beispiel #6
0
 public bool Equals(IConversionItem other)
 {
     return(SourcePath.Equals(other.SourcePath));
 }
Beispiel #7
0
 public override bool Equals(object obj)
 {
     return(SourcePath.Equals(obj));
 }