コード例 #1
0
        public bool TryFindPlantPhoto(string photoId, out PlantPhoto plantPhoto)
        {
            var found = _plantPhotos.FirstOrDefault(p => p.PhotoId == photoId);

              if (found == null) {
            plantPhoto = new PlantPhoto {PhotoId = "Not found"};
            return false;
              }

              plantPhoto = found;
              return true;
        }
コード例 #2
0
        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, " ")));
              }
        }