Beispiel #1
0
        private static BitmapImage DownloadFromWeb(Uri uri, string filename)
        {
            var webClient = new WebClient();
            var bm        = new BitmapImage();

            webClient.OpenReadCompleted += (o, e) =>
            {
                if (e.Error != null || e.Cancelled)
                {
                    return;
                }
                using (var inputStream = e.Result)
                {
                    IsolatedStorage.WriteToFile(filename, outputStream =>
                    {
                        byte[] buffer = new byte[32768];
                        int read;
                        while ((read = inputStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            outputStream.Write(buffer, 0, read);
                        }
                    });
                    using (var stream = IsolatedStorage.OpenFileToRead(filename))
                    {
                        bm.SetSource(stream);
                    }
                }
            };
            webClient.OpenReadAsync(uri);
            return(bm);
        }
Beispiel #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var uri = new Uri((string)value);

            if (uri.Scheme == "http" || uri.Scheme == "https")
            {
                var filename = CacheFolder + "/" + uri.AbsoluteUri.GetHashCode() + ".img";
                try
                {
                    if (IsolatedStorage.FileExists(filename))
                    {
                        var bm = new BitmapImage();
                        using (var stream = IsolatedStorage.OpenFileToRead(filename))
                        {
                            bm.SetSource(stream);
                        }
                        return(bm);
                    }
                    else
                    {
                        return(DownloadFromWeb(uri, filename));
                    }
                }
                catch
                {
                    // crashes in the VS preview when trying to access isolated storage
                    return(new BitmapImage(uri));
                }
            }
            else
            {
                return(new BitmapImage(uri));
            }
        }
Beispiel #3
0
 public static void ReportException(Exception ex, string header)
 {
     try
     {
         var content = "[" + ToString(DateTime.UtcNow) + "]" + " " + header;
         if (ex != null)
         {
             content += "\n" + ex.ToString();
         }
         content += "\n";
         IsolatedStorage.AppendText(ErrorReportFile, content);
     }
     catch { }
 }
Beispiel #4
0
        public static void CheckForPreviousException(bool startingUp)
        {
            string contents = null;

            try
            {
                contents = IsolatedStorage.ReadAllText(ErrorReportFile);
                IsolatedStorage.Delete(ErrorReportFile);
            }
            catch { }
            if (contents != null)
            {
                var text = "A problem occurred" + (startingUp ? " the last time you ran this application" : "") + ". Would you like to send an email to report it?";
                if (Extensions.ShowMessageBox("Problem Report", text, "Send report", "No thanks"))
                {
                    var email = new EmailComposeTask();
                    email.To      = AppMetadata.Current.Email;
                    email.Subject = AppMetadata.Current.Name + " " + AppMetadata.Current.Version + " auto-generated problem report";
                    email.Body    = GetMailBody(contents);
                    email.Show();
                }
            }
        }