public void Delete(string filename) { try { using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) { isStore.DeleteFile(PicturesFolder + "\\" + filename); } all.RemoveAll(x => x.Equals(filename)); SessionLog.RecordTraceValue("Deleted picture", filename); } catch (Exception ex) { LittleWatson.ReportException(ex); } foreach (var vm in vms) { vm.Refresh(); } }
public void UpdateNewItemWithID(string text) { try { var NewFilename = string.Format("item{0}-", text); using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) { foreach (var filename in isStore.GetFileNames(PicturesFolder + "\\item0-*")) { isStore.MoveFile(PicturesFolder + "\\" + filename, PicturesFolder + "\\" + filename.Replace("item0-", NewFilename)); } all.Clear(); all.AddRange(isStore.GetFileNames(PicturesFolder + "\\*")); } } catch (Exception ex) { LittleWatson.ReportException(ex); } foreach (var vm in vms) { vm.Refresh(); } }
private PictureCache() { try { using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isStore.DirectoryExists(PicturesFolder)) { isStore.CreateDirectory(PicturesFolder); } List <string> ToDelete = new List <string>(); ToDelete.AddRange(isStore.GetFileNames(PicturesFolder + "\\item0-*")); foreach (var filename in ToDelete) { SessionLog.RecordTraceValue("Deleting zombie picture", filename); isStore.DeleteFile(PicturesFolder + "\\" + filename); } all.AddRange(isStore.GetFileNames(PicturesFolder + "\\*")); } } catch (Exception ex) { LittleWatson.ReportException(ex); } }
public void Save(MemoryStream stream, string filename, string foodId, bool rotate) { BitmapImage b = new BitmapImage(); b.CreateOptions = BitmapCreateOptions.None; b.SetSource(stream); //calculate bounding box int w = b.PixelWidth; int h = b.PixelHeight; WriteableBitmap wb; if (w == h) { wb = new WriteableBitmap(b); } else { // crop to square int s = (h < w) ? h : w; Image temporaryImage = new Image { Source = b, Width = w, Height = h }; wb = new WriteableBitmap(s, s); Transform t; var tt = new TranslateTransform(); tt.X = (s - w) / 2.0; tt.Y = (s - h) / 2.0; if (rotate) { t = new CompositeTransform() { TranslateX = tt.X, TranslateY = tt.Y, CenterX = 0.5 * w, CenterY = 0.5 * h, Rotation = 90 } } ; else { t = tt; } wb.Render(temporaryImage, t); wb.Invalidate(); } long len = 0; using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication()) { using (var outstream = isStore.CreateFile(PicturesFolder + "\\" + filename)) { wb.SaveJpeg(outstream, PictureSize, PictureSize, 0, PictureQuality); len = outstream.Length / 1024; all.Add(filename); } } SessionLog.RecordTraceValue("New picture", filename, len.ToString() + " kb"); var bw = new System.ComponentModel.BackgroundWorker(); bw.DoWork += (s, a) => { try { MessageQueue.Push(new PictureMessage(wb, foodId, filename)); SessionLog.RecordTrace("Picture msg saved."); } catch (Exception ex) { LittleWatson.ReportException(ex); } }; bw.RunWorkerAsync(); foreach (var vm in vms) { vm.Refresh(); } }