public MMPicture LoadOrCreate(Byte[] pictureToHandle, String pictureName, String extension, bool DuplicateAllowed = false, Guid? pictureSourceId = null) { String sha1Hash = pictureToHandle.Sha1Hash().ConvertTo_Hex(); extension = extension.ToLower(); //if ((sha1Hash == "AADD0FE8A153C1EB7AC17741E779E8E85C085065") // || (sha1Hash == "1494495D8FA25B1E01544E65B08D55FFD0823913")) // // { // return DataContext.MultiMedia.MMPictures.FirstOrDefault(); // } MMPicture mmPicture = null; if (DuplicateAllowed) { MMPicture[] mmPictures = FindOrLoad_via_HashCode_MultipleAllowed(sha1Hash); if (mmPictures.Length > 0) { foreach (MMPicture picture in mmPictures) { if (picture.NameId == pictureName) return picture; } } } else { mmPicture = FindOrLoad_via_HashCode(sha1Hash); if (mmPicture != null) { return mmPicture; } } mmPicture = NewRow(); mmPicture.Id = Guid.NewGuid(); mmPicture.HashCode = sha1Hash; mmPicture.NameId = pictureName; if (extension == "jpg") { mmPicture.TypId = Guid.Parse("9D5E28CC-BBC4-4F3B-B236-ECC9C2BB756F"); mmPicture.ValueThumb = pictureToHandle.ConvertTo_Image().ResizeToMaximum(300, 200).ConvertTo_JpgByteArray(); } else if (extension == "png") { mmPicture.TypId = Guid.Parse("AC48A5BA-EFC5-41C8-825A-E6BC6660EB73"); mmPicture.ValueThumb = pictureToHandle.ConvertTo_Image().ResizeToMaximum(300, 200).ConvertTo_PngByteArray(); } else if (extension == "bmp") { mmPicture.TypId = Guid.Parse("44D0A3D2-F95A-4E44-81DB-A8A8B8A8DF71"); mmPicture.ValueThumb = pictureToHandle.ConvertTo_Image().ResizeToMaximum(300, 200).ConvertTo_JpgByteArray(); } else { Debug.WriteLine($"Fehler, der Typ wurde nicht erkannt --- > Hash= {sha1Hash}"); return null; } mmPicture.Value = pictureToHandle; if (pictureSourceId != null) mmPicture.PictureSourceId = pictureSourceId; Rows.Add(mmPicture); SaveChanges(new Object()); AcceptChanges(); return mmPicture; }