ChinhDo.Transactions.TxFileManager.Move C# (CSharp) Method

Move() public method

Moves the specified file to a new location.
public Move ( string srcFileName, string destFileName ) : void
srcFileName string The name of the file to move.
destFileName string The new path for the file.
return void
        public void Move(string srcFileName, string destFileName)
        {
            GetEnlistment().Move(srcFileName, destFileName);
        }

Usage Example

        public void RenameImageAndUsages(PlantPhoto plantPhoto)
        {
            var dateString = _now.ToString("yyyy-MM-dd HH:mm:ss.fff");
              var fileManager = new TxFileManager();

              try {
            using (var conn = new SqlConnection(_settings.ConnectionString))
            using (var scope = new TransactionScope()) {
              conn.Open();

              conn.Execute(_photoUpdateQuery,
            new { OldPhotoId = plantPhoto.PhotoId, NewPhotoId = plantPhoto.PhotoId.AddTif(), NewUpdatedAt = _now });

              conn.Execute(_usageUpdateQuery,
            new { plantPhoto.PhotoId, NewPhotoId = plantPhoto.PhotoId.AddTif() });

              foreach (var imageRoot in _settings.ImageRoots)
              {
            var imagePath = plantPhoto.GetActualImagePath(imageRoot);
            var newPath = plantPhoto.GetReplacementPath(imageRoot, _settings.TargetExtension);

            if (File.Exists(imagePath)) {
              fileManager.Move(imagePath, newPath);
            }
              }

              foreach (var thumbnailRoot in _settings.ThumbnailRoots)
              {
            var thumbPath = plantPhoto.GetThumbnailPath(thumbnailRoot);
            var newPath = plantPhoto.GetReplacementPath(thumbnailRoot, _settings.TargetExtension, true);

            if (File.Exists(thumbPath)) {
              fileManager.Move(thumbPath, newPath);
            }
              }

              scope.Complete();
              var message = string.Format("{0}\t{0}{1}\t{2}", plantPhoto.PhotoId, _settings.TargetExtension, dateString);
              Logger.Info(message);
            }
              }
              catch (TransactionAbortedException trex)
              {
            Logger.Error(string.Format("{0}\t{1}", plantPhoto.PhotoId, trex.Message.Replace(Environment.NewLine, " ")));
              }
              catch (Exception exc)
              {
            Logger.Error(string.Format("{0}\t{1}", plantPhoto.PhotoId, exc.Message.Replace(Environment.NewLine, " ")));
              }
        }