private async Task UploadAction()
        {
            if (_view.CheckTextboxesEmpty())
            {
                return;
            }
            try
            {
                _resumableFileManager.ProcessingFinishedDelegate = UploadFinshedDelegateHandler;
                _resumableFileManager.ProgressbarChangedDelegate = UploadProgressChangedHandler;
                _resumableFileManager.StatusChangedDelegate      = UpdateStatusChangedHandler;
                _cancellationTokenSource = new CancellationTokenSource();
                var targetFile = string.Empty;
                targetFile = await _resumableFileManager.Upload(_view.Model.PathToFile, _networkPath, string.Empty, false, _cancellationTokenSource.Token);

                if (!string.IsNullOrEmpty(targetFile))
                {
                    var id = _metaData.WriteInfo(_view.Model.DatabaseName, _view.Model.Company, _view.Model.Tags);
                    var checksumForNewFile = _checksum.CalculateChecksum(_view.Model.PathToFile);
                    _metaData.WriteDetails(id, targetFile.ToString(), checksumForNewFile);
                }
                _view.ClearModel();
                LoadTable();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        private async Task StartUpload()
        {
            try
            {
                var    checksumForNewFile   = _checksum.CalculateChecksum(_pathToFile);
                var    resumableFileManager = _fileManager as IResumableFileManager;
                string targetFile           = string.Empty;

                resumableFileManager.ProgressbarChangedDelegate = UploadProgressChangedHandler;
                resumableFileManager.StatusChangedDelegate      = UploadStatusChangedHandler;
                resumableFileManager.ProcessingFinishedDelegate = UploadFinshedDelegateHandler;
                _cancellationTokenSource = new CancellationTokenSource();
                if (resumableFileManager != null && resumableFileManager.CheckInfoFileIsAlreadyDownloaded(_networkPathInfo.GetPathMetaDataFile(), checksumForNewFile))
                {
                    bool userDecision = _messageService.CheckUserWantsToResumeUpload();
                    if (userDecision)
                    {
                        targetFile = await resumableFileManager.ResumeUpload(_pathToFile, _networkPath, checksumForNewFile, true, _cancellationTokenSource.Token);
                    }
                    else
                    {
                        targetFile = await resumableFileManager.Upload(_pathToFile, _networkPath, checksumForNewFile, true, _cancellationTokenSource.Token);
                    }
                }
                else
                {
                    if (!_fileValidator.CheckVersionAlreadyExists(_id, checksumForNewFile))
                    {
                        targetFile = await resumableFileManager.Upload(_pathToFile, _networkPath, checksumForNewFile, true, _cancellationTokenSource.Token);
                    }
                    else
                    {
                        throw new Exception("This version already exists");
                    }
                }

                if (!string.IsNullOrEmpty(targetFile))
                {
                    FileInfo fileInfo       = new FileInfo(targetFile);
                    string   targetFilePath = targetFile;
                    if (fileInfo.Extension.Equals(".tmp"))
                    {
                        targetFilePath = $"{ Path.GetDirectoryName(targetFile)}\\{Path.GetFileNameWithoutExtension(targetFile)}";
                    }
                    _metaData.WriteDetails(_id, targetFilePath, checksumForNewFile);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #3
0
        private bool IsTheSameFile(string checksumSourceFile, string targetPath)
        {
            if (!File.Exists(targetPath))
            {
                return(false);
            }

            var checksumTargetFile = _checksum.CalculateChecksum(targetPath);

            if (checksumSourceFile.Equals(checksumTargetFile))
            {
                return(true);
            }

            return(false);
        }