WP7 Tombstone Helper Library

Jul 28, 2011 at 6:20 PM

The above dll doesn't appear to work. After successfully adding it to my project, when I try to call the SaveState and RestoreState methods, like below 

 

 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
       base.OnNavigatedFrom(e);
        this.SaveState();  // <- first line
    }

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        this.RestoreState();  // <- second line
    }

But doesnt seem to work ... any ideas????
Coordinator
Jul 29, 2011 at 9:20 AM

What are you expecting it to save?

And have you named those controls?

Jul 29, 2011 at 11:04 AM

I have declared set of text box like below . 

 

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">                     

  <TextBlock Height="30" HorizontalAlignment="Left" Margin="19,152,0,0" Name="Block1" Text="Name:" VerticalAlignment="Top" Width="104" Foreground="#FFEFE9ED" FontStyle="Normal" FontStretch="Normal" FontWeight="ExtraBold" FontSize="20" />         

  <TextBox Height="63" HorizontalAlignment="Left" Margin="129,133,0,0" Name="imageName" Text="" VerticalAlignment="Top" Width="315" FontSize="20" />     

      <TextBlock Height="34" HorizontalAlignment="Left" Margin="16,215,0,0" Name="textBlock2" Text="Tags:" VerticalAlignment="Top" Width="106" Foreground="#FFE3E2F2" FontWeight="ExtraBold" FontSize="20" />       

    <TextBox FontSize="20" Height="63" HorizontalAlignment="Left" Margin="130,202,0,0" Name="imageTags" Text="" VerticalAlignment="Top" Width="315" />           

<TextBlock Height="30" HorizontalAlignment="Left" Margin="9,298,0,0" Name="textBlock3" Text="Description" VerticalAlignment="Top" Width="104" FontSize="20" FontWeight="ExtraBold" />           

<TextBox FontSize="20" Height="126" HorizontalAlignment="Left" Margin="130,284,0,0" Name="imageDesc" Text="" VerticalAlignment="Top" Width="315" />         

  <TextBlock Height="30" HorizontalAlignment="Left" Margin="19,439,0,0" Name="textBlock4" Text="Preview" VerticalAlignment="Top" Width="104" FontWeight="ExtraBold" />       

    <Image Height="203" HorizontalAlignment="Left" Margin="146,420,0,0" Name="image1" Stretch="UniformToFill" VerticalAlignment="Top" Width="283" Opacity="10" OpacityMask="#FF100E0E" Visibility="Visible" DataContext="{Binding}" />         

  <ProgressBar Height="16" HorizontalAlignment="Left" Margin="140,93,0,0" Name="UploadProgressBar" VerticalAlignment="Top" Width="310" IsIndeterminate="True" Visibility="Collapsed" />       

    <TextBlock x:Name="PageTitle" Text="Flickr" Margin="180,0,-183,627" Style="{StaticResource PhoneTextTitle1Style}" FontWeight="ExtraBold" Foreground="#FFDF1FC1" />         

  <Button Content="Upload" Height="76" HorizontalAlignment="Left" Margin="132,634,0,0" Name="uploadButton" VerticalAlignment="Top" Width="312" Click="upload_Click" /> 

      </Grid>

 

Please let me know how to save these stuff 

Coordinator
Jul 29, 2011 at 2:44 PM

I put your XAML in the main page of a new (7.0) app with the TombstoneHelper version from NuGet and added the following page navigation handlers and it preserved the text fine while tombstoned. (Tested with the Mango-Beta2Refresh tools & emulator)

Support for images and bindings is not currently included so I wouldn't expect it to do anything with the image.

        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            if (e.NavigationMode != NavigationMode.Back)
            {
                this.SaveState();
            }

            base.OnNavigatingFrom(e);
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.RestoreState();

            base.OnNavigatedTo(e);
        } 

        private void upload_Click(object sender, RoutedEventArgs e)
        {
            throw new NotImplementedException();
        }

 

I've also converted the test app to 7.1 and forced the debugger to tombstone upon deactivation and the above still works.

Can you please provide full deatils of what you're doing, what happens and what you were expecting to happen.
Can you also please confirm the versions of the tools and library you are using.
With these I'll be able to investigate further.

 

Jul 29, 2011 at 5:43 PM

I m trying to write a flickr uploader client for WP7 . There  3 pages in my app. First is the authentication , next is the main page  and next is the upload page

once the authentication is sucessful it goes to the main page where you have options to upload, launch camera, select photo from folder and launch internet browser.

Here is the MainPage.xaml.cs

 

====================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Threading;
using System.Windows.Controls.Primitives;
using System.ComponentModel;
using Microsoft.Phone.Tasks;
using System.IO;
using FlickrApp.Helper;
using ControlTiltEffect;


namespace FlickrApp
{
    public partial class MainPage : PhoneApplicationPage
    {
        CameraCaptureTask cameraCapture;
        PhotoChooserTask photoChooser;
        private HttpWebRequest _webRequest;
        private CookieContainer _cookieContainer = new CookieContainer();
        private static readonly Uri FlickrUri = new Uri("https://login.yahoo.com/config/login");

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(PhoneApplicationPage_Loaded);
            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
            this._webRequest = (HttpWebRequest)HttpWebRequest.Create("https://login.yahoo.com/config/login");
            this._webRequest.CookieContainer = this._cookieContainer;

        }

        void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {

            cameraCapture = new CameraCaptureTask();
            cameraCapture.Completed += new EventHandler<PhotoResult>(photoChooser_Completed);

            photoChooser = new PhotoChooserTask();
            photoChooser.Completed += new EventHandler<PhotoResult>(photoChooser_Completed);
            
            //throw new NotImplementedException();
        }
        
/*
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            
            var queryStrings = this.NavigationContext.QueryString;

            //This code ensures that there is at least one key in the query string, and check if the "file" key is present.
            if (queryStrings.Count > 0 && queryStrings.ContainsKey("file"))
            {
                //The value for the key "file" is filename.
                string filename = queryStrings["file"];

                //This code appends the folder name (Incoming) to the file path. The isolated storage folder "Incoming"
                // was specified in the Extras.xml file.     
                SetImage(AppHelper.LoadImage(AppHelper.IncomingDirectory, filename));

                // Clean up incoming directory
                AppHelper.DeleteImage(AppHelper.IncomingDirectory, filename);
            }
        } */

        void photoChooser_Completed(object sender, PhotoResult e)
        {
            if (e == null || e.TaskResult != TaskResult.OK) return;

            SetImage(e.ChosenPhoto);
            
            //throw new NotImplementedException();
        }

        private void SetImage(Stream imageStream)
        {
            AppHelper.SaveImage(imageStream,AppHelper.ImageDirectory,AppSettings.ImageFilename);
            BitmapImage bmp = new BitmapImage();
            bmp.SetSource(imageStream);
            PlaceHolderImage.Source = bmp;

            if (ApplicationBarUploadIconButton != null)
                ApplicationBarUploadIconButton.IsEnabled = true;

        }

        public void ClearCookies(Uri uri)
        {
            var cookies = this._cookieContainer.GetCookies(uri);
            foreach (Cookie cookie in cookies)
            {
                cookie.Discard = true;
                cookie.Expired = true;
            }
        }

      /*  void cameraCapture_Completed(object sender, PhotoResult e)
        {
            if (e == null || e.TaskResult != TaskResult.OK)
            {
                MessageBox.Show(e.Error.Message);
            }
            else
            {
                AppHelper.SaveImage(e.ChosenPhoto);
            }
            //throw new NotImplementedException();
        } */

        private void ApplicationBarCameraButton_Click(object sender, EventArgs e)
        {
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame, true);         
            cameraCapture.Show();
        }

        private void ApplicationBarUploadButton_Click(object sender, EventArgs e)
        {
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame, true);
            if (!AppHelper.ImageExists(AppHelper.ImageDirectory, AppSettings.ImageFilename))
            {
                MessageBox.Show("You must take a photo or choose a photo to continue.");
                return;
            }

            else
            {
                NavigationService.Navigate(new Uri("/Upload.xaml", UriKind.Relative));
            }
        }

        private void ApplicationBarSearchButton_Click(object sender, EventArgs e)
        {
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame, true);
            photoChooser.Show();
        }

        private void ApplicationBarBrowserButton_Click(object sender, EventArgs e)
        {
            // Launch Internet Explorer Browser
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame, true);
            WebBrowserTask task = new WebBrowserTask() { URL = "http://www.flickr.com/" };
            task.Show();
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            // On Back Key Press Quit Application
            App.Quit();
        }

       
        private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You will be logged out. Press Ok to Continue");
            // Delete Cookies from browser
            ClearCookies(FlickrUri);
            // Set Authentication token to null
            AppHelper.AuthenticationToken = null;
            // Quit the application
            App.Quit();
        }
        
    }
}

===========================================================================

 

 

 

 

 

 

Jul 29, 2011 at 5:53 PM

I have my next page as Upload.xaml.cs  where I m uploading the picture . it has 3 text boxes name,tags and description ... I have the code below 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Threading;
using System.Windows.Controls.Primitives;
using System.ComponentModel;
using Microsoft.Phone.Tasks;
using System.IO;
using FlickrApp.Helper;
using ControlTiltEffect;


namespace FlickrApp
{
    public partial class MainPage : PhoneApplicationPage
    {
        CameraCaptureTask cameraCapture;
        PhotoChooserTask photoChooser;
        private HttpWebRequest _webRequest;
        private CookieContainer _cookieContainer = new CookieContainer();
        private static readonly Uri FlickrUri = new Uri("https://login.yahoo.com/config/login");

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(PhoneApplicationPage_Loaded);
            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;
            this._webRequest = (HttpWebRequest)HttpWebRequest.Create("https://login.yahoo.com/config/login");
            this._webRequest.CookieContainer = this._cookieContainer;

        }

        void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {

            cameraCapture = new CameraCaptureTask();
            cameraCapture.Completed += new EventHandler<PhotoResult>(photoChooser_Completed);

            photoChooser = new PhotoChooserTask();
            photoChooser.Completed += new EventHandler<PhotoResult>(photoChooser_Completed);
            
            //throw new NotImplementedException();
        }
        
/*
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            
            var queryStrings = this.NavigationContext.QueryString;

            //This code ensures that there is at least one key in the query string, and check if the "file" key is present.
            if (queryStrings.Count > 0 && queryStrings.ContainsKey("file"))
            {
                //The value for the key "file" is filename.
                string filename = queryStrings["file"];

                //This code appends the folder name (Incoming) to the file path. The isolated storage folder "Incoming"
                // was specified in the Extras.xml file.     
                SetImage(AppHelper.LoadImage(AppHelper.IncomingDirectory, filename));

                // Clean up incoming directory
                AppHelper.DeleteImage(AppHelper.IncomingDirectory, filename);
            }
        } */

        void photoChooser_Completed(object sender, PhotoResult e)
        {
            if (e == null || e.TaskResult != TaskResult.OK) return;

            SetImage(e.ChosenPhoto);
            
            //throw new NotImplementedException();
        }

        private void SetImage(Stream imageStream)
        {
            AppHelper.SaveImage(imageStream,AppHelper.ImageDirectory,AppSettings.ImageFilename);
            BitmapImage bmp = new BitmapImage();
            bmp.SetSource(imageStream);
            PlaceHolderImage.Source = bmp;

            if (ApplicationBarUploadIconButton != null)
                ApplicationBarUploadIconButton.IsEnabled = true;

        }

        public void ClearCookies(Uri uri)
        {
            var cookies = this._cookieContainer.GetCookies(uri);
            foreach (Cookie cookie in cookies)
            {
                cookie.Discard = true;
                cookie.Expired = true;
            }
        }

      /*  void cameraCapture_Completed(object sender, PhotoResult e)
        {
            if (e == null || e.TaskResult != TaskResult.OK)
            {
                MessageBox.Show(e.Error.Message);
            }
            else
            {
                AppHelper.SaveImage(e.ChosenPhoto);
            }
            //throw new NotImplementedException();
        } */

        private void ApplicationBarCameraButton_Click(object sender, EventArgs e)
        {
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame, true);         
            cameraCapture.Show();
        }

        private void ApplicationBarUploadButton_Click(object sender, EventArgs e)
        {
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame, true);
            if (!AppHelper.ImageExists(AppHelper.ImageDirectory, AppSettings.ImageFilename))
            {
                MessageBox.Show("You must take a photo or choose a photo to continue.");
                return;
            }

            else
            {
                NavigationService.Navigate(new Uri("/Upload.xaml", UriKind.Relative));
            }
        }

        private void ApplicationBarSearchButton_Click(object sender, EventArgs e)
        {
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame, true);
            photoChooser.Show();
        }

        private void ApplicationBarBrowserButton_Click(object sender, EventArgs e)
        {
            // Launch Internet Explorer Browser
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame, true);
            WebBrowserTask task = new WebBrowserTask() { URL = "http://www.flickr.com/" };
            task.Show();
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            // On Back Key Press Quit Application
            App.Quit();
        }

       
        private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You will be logged out. Press Ok to Continue");
            // Delete Cookies from browser
            ClearCookies(FlickrUri);
            // Set Authentication token to null
            AppHelper.AuthenticationToken = null;
            // Quit the application
            App.Quit();
        }
        
    }
}

Jul 29, 2011 at 5:58 PM

Please help me out to solve this issue 

Coordinator
Jul 29, 2011 at 8:26 PM

@mailmugu
You've posted the same block of code twice.
Even that isn't helpful in identifying what your issue is.
Please provide a complete working example which demonstrates your issue. Or ALL the elements to recreate it. (This shoudl include details of any dependencies or other classes/libraries you are using.)

You still haven't said what the actual issue you are experiencing is.

There are a few things I can conclude/suggest from the above code though:

  • I'd do away with using both PhotoChooser and CameraCapture tasks as PhotoChooser can be used to capture pictures from the camera also. (see http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.photochoosertask.showcamera(v=vs.92).aspx)
  • While you haven't identified where you're getting the ControlTiltEffect namespace from but I'd be amazed if you really need to repeatedly call "TiltEffect.SetIsTiltEnabled()"
  • You should set up your tasks and their callbacks in the page's constructor (not after the page has loaded) or they may not work correctly.
  • While you haven't shown what it does, having an "App.Quit()" method is probably a bad idea. You can't/shouldn't forcibly exit your app. It will fail marketplace certifiction if you do. Respect the back button and it's standard/default behaviour.
Jul 29, 2011 at 8:44 PM

sorry for that ... my issue is I m not able to tombstone the application page... I type some text to  text boxes like "Name,Tags, and description" . Then I press the windows button to go back to main  menu. Now again launch my application now my upload page should appear with the entered text in text boxes .But I m getting only my MainPage.xaml. Dont know what is the real issue. 

 

I dont know how to upload the entire working code . Please let me know how to upload so that u can see what my app is doing. I will also make the changes which you have mentioned ... thanks a lot 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Net.NetworkInformation;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using FlickrNet;
using FlickrApp.Helper;
using System.IO;
using System.Windows.Navigation;
using ControlTiltEffect;
using TombstoneHelper;

namespace FlickrApp
{
    public partial class Upload : PhoneApplicationPage
    {
        App app = Application.Current as App;
        
 
        public Upload()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Upload_Loaded);
        }

        void Upload_Loaded(object sender, RoutedEventArgs e)
        {
            BitmapImage bmp = new BitmapImage();
            bmp.SetSource(AppHelper.LoadImage(AppHelper.ImageDirectory,AppSettings.ImageFilename));
            image1.Source = bmp;
            //throw new NotImplementedException();
        }
        
        // Tombstone application state
        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            if (e.NavigationMode != NavigationMode.Back)
            {
                this.SaveState();
            }

            base.OnNavigatingFrom(e);
        }

        // Restore application state
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.RestoreState();

            base.OnNavigatedTo(e);
        } 

        private void upload_Click(object sender, RoutedEventArgs e)
        {
            TiltEffect.SetIsTiltEnabled((App.Current as App).RootFrame,true);
            if (NetworkInterface.GetIsNetworkAvailable())
            {


                uploadButton.IsEnabled = false;

                App app = Application.Current as App;

                Flickr Flk = app.Flickr;
                UploadDataModel data = app.DataModel;

                Stream stream = AppHelper.LoadImage(AppHelper.ImageDirectory, AppSettings.ImageFilename);


                if (stream == null)
                {
                    MessageBox.Show("Image Not Selected For Upload");
                    return;
                }

                //ContentGrid.Visibility = System.Windows.Visibility.Collapsed;
                UploadProgressBar.Visibility = System.Windows.Visibility.Visible;

                app.Flickr.UploadPictureAsync(stream, AppSettings.ImageFilename, imageName.Text, imageDesc.Text, imageTags.ToString(), true, true, true, ContentType.Photo, SafetyLevel.None, HiddenFromSearch.None, r =>
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        if (r.HasError)
                        {
                            MessageBox.Show(r.Error.Message);
                        }
                        else
                        {
                            UploadProgressBar.Visibility = System.Windows.Visibility.Collapsed;
                            MessageBox.Show("Uploaded Sucessfully");
                            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                        }
                    });
                });

            }
            else
            {
                MessageBox.Show("No internet connection is available. Try again later.");
                return;
            }
        }

        private void back_Click(object sender, EventArgs e)
        {
            //NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }

    }
}

Aug 1, 2011 at 8:38 AM

can you please update me why tombstoning is not happening

Coordinator
Aug 1, 2011 at 12:32 PM

@mailmugu How are you starting the app again after pressing the windows key?  If you're not doing it via the back button then it shouldn't retain state.

codeplex doesn't have a file upload facility for discussion/issues but you could put the repro in SkyDrive or similar.