Example #1
0
        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();
            }
        }
Example #2
0
        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); }
        }
Example #3
0
        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();
            }
        }
Example #4
0
 public static void Push()
 {
     MessageQueue.Push(me); me = new SessionLog();
 }
Example #5
0
        internal static void ReportException(Exception ex)
        {
            string caughtIn = new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name;

            SessionLog.ReportException(ex, caughtIn);
        }
Example #6
0
 protected virtual void Dispose(bool boolarg)
 {
     SessionLog.RecordPerformance(message, value, (DateTime.Now - start));
 }