private async void smartButton_Click(object sender, RoutedEventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.ShowDialog();
if (folderBrowserDialog.SelectedPath != "")
{
string selectedPath = folderBrowserDialog.SelectedPath;
folderBrowserDialog.Dispose();
string[] photos = Directory.GetFiles(selectedPath);
foreach (ModelGroupItem item in listGroupItem)
{
foreach (string photo in photos)
{
using (FileStream imageStreamSource = File.Open(photo, FileMode.Open))
{
BitmapDecoder decoder = BitmapDecoder.Create(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
InPlaceBitmapMetadataWriter pngInplace = decoder.Frames[0].CreateInPlaceBitmapMetadataWriter();
DateTime photoDate = DateTime.Parse(pngInplace.DateTaken); // Дата съемки
// Если фотография соответствует условиям, то перекидываем ее в папку
if (item.timeTo.TimeOfDay > photoDate.TimeOfDay &
item.timeFrom.TimeOfDay < photoDate.TimeOfDay &
photoDate.DayOfWeek.ToString() == item.day &
photoDate.Month == DateTime.Today.Month)
{
string StartDirectory = selectedPath; // Стартовая директория
string EndDirectory = item.path; // Конечная
using (FileStream DestinationStream = File.Create(EndDirectory + photo.Substring(photo.LastIndexOf('\\'))))
{
await imageStreamSource.CopyToAsync(DestinationStream);
}
}
}
}
}
}
}
BitmapDecoder decoder = BitmapDecoder.Create(detectDate, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
InPlaceBitmapMetadataWriter pngInplace = decoder.Frames[0].CreateInPlaceBitmapMetadataWriter();
private async void smartButton_Click(object sender, RoutedEventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.ShowDialog();
if (folderBrowserDialog.SelectedPath != "")
{
string selectedPath = folderBrowserDialog.SelectedPath;
folderBrowserDialog.Dispose();
string[] photos = Directory.GetFiles(selectedPath);
foreach (ModelGroupItem item in listGroupItem)
{
foreach (string photo in photos)
{
using (FileStream detectDate = File.Open(photo, FileMode.Open))
{
BitmapDecoder decoder = BitmapDecoder.Create(detectDate, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
InPlaceBitmapMetadataWriter pngInplace = decoder.Frames[0].CreateInPlaceBitmapMetadataWriter();
DateTime photoDate = DateTime.Parse(pngInplace.DateTaken); // Дата съемки
// Если фотография соответствует условиям, то перекидываем ее в папку
if (item.timeTo.TimeOfDay > photoDate.TimeOfDay &
item.timeFrom.TimeOfDay < photoDate.TimeOfDay &
photoDate.DayOfWeek.ToString() == item.day &
photoDate.Month == DateTime.Today.Month)
{
string StartDirectory = selectedPath; // Стартовая директория
string EndDirectory = item.path; // Конечная
// Освобождаем файл перед копированием
detectDate.Dispose();
using (FileStream imageStreamSource = File.Open(photo, FileMode.Open))
{
using (FileStream DestinationStream = File.Create(EndDirectory + photo.Substring(photo.LastIndexOf('\\'))))
{
await imageStreamSource.CopyToAsync(DestinationStream);
}
}
}
}
}
}
}
}
public async Task CopyFileAsync(string sourcePath, string destinationPath)
{
using (Stream source = File.Open(sourcePath))
{
using(Stream destination = File.Create(destinationPath))
{
await source.CopyToAsync(destination);
}
}
}