private void ExecuteImportDataFromFile() { var openFileDialog = new OpenFileDialog() { Filter = string.Format("UAD-файлы (*.{0})|*.{0}", XmlUserActivityDataContext.UadFileExtension), Multiselect = true, }; bool?result = openFileDialog.ShowDialog(); if (result == true) { var serializer = new XmlSerializer(typeof(SessionGroup)); foreach (var stream in openFileDialog.OpenFiles()) { using (stream) { SessionGroup sessionGroup = XmlUserActivityDataContext.LoadSessionGroup(stream); SessionGroups.Add(sessionGroup); } } var newRegions = new List <RegionImageItemVM>(); foreach (var region in SessionGroups.SelectMany(sg => sg.Sessions).SelectMany(s => s.Regions)) { foreach (var image in region.Variations) { if (newRegions.FirstOrDefault(r => r.RegionName == region.Name && r.ImageName == image.Name) == null) { var newRegion = new RegionImageItemVM() { RegionName = region.Name, Image = image }; newRegions.Add(newRegion); } } } RegionSelector.Clear(); RegionSelector.AddRange(newRegions.OrderBy(r => r.RegionName)); RegionSelector.SelectedItem = RegionSelector.FirstOrDefault(); } }
public void SetRegion(RegionImageItemVM region) { if ((region != null) && (region.Image != null)) { var image = region.Image; ImageSource imageSource = null; if ((image.ImageType == ImageType.FileBmp) || (image.ImageType == ImageType.FileJpg) || (image.ImageType == ImageType.FilePng)) { var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; string filepath = System.IO.Path.Combine(Environment.CurrentDirectory, "Assets", "Images", image.Source); bitmapImage.UriSource = new Uri(filepath, UriKind.Absolute); bitmapImage.StreamSource = null; bitmapImage.EndInit(); imageSource = bitmapImage; } else if ((image.ImageType == ImageType.RawBmp) || (image.ImageType == ImageType.RawJpg) || (image.ImageType == ImageType.RawPng)) { var bitmapImage = new BitmapImage(); using (var mem = new MemoryStream(region.Image.Data)) { mem.Position = 0; bitmapImage.BeginInit(); bitmapImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.UriSource = null; bitmapImage.StreamSource = mem; bitmapImage.EndInit(); } imageSource = bitmapImage; } BackgroundImage.Source = imageSource; } }
/// <summary> /// Import UAD-file(s), load available regions. /// </summary> private void ExecuteImportFile() { var groups = _import.ImportFile(); Files.AddRange(groups); var newRegions = new List <RegionImageItemVM>(); foreach (var region in Files.SelectMany(sg => sg.Sessions).SelectMany(s => s.Regions)) { foreach (var image in region.Variations) { if (newRegions.FirstOrDefault(r => r.RegionName == region.Name && r.ImageName == image.Name) == null) { var newRegion = new RegionImageItemVM() { RegionName = region.Name, Image = image }; newRegions.Add(newRegion); } } } //var regions = Files.SelectMany(sg => sg.Sessions) // .SelectMany(s => s.RegionCollection) // .SelectMany(r => r.Images.Select(v => new { r, v })) // .DistinctBy((r1, r2) => r1.r.Name == r2.r.Name && r1.v.Name == r2.v.Name); RegionSelector.Clear(); RegionSelector.AddRange(newRegions.OrderBy(r => r.RegionName)); RegionSelector.SelectFirst(); int fileCount = Files.Count; int sessionCount = Files.Sum(sg => sg.Sessions.Count); int eventCount = Files.Sum(sg => sg.Sessions.Sum(a => a.Events.Count)); LoadedDataInfo = string.Format(DataStatusStringFormat, fileCount, sessionCount, eventCount); }