Windows Phone 7 Error Handling - BugSense

December 21, 2011 at 2:25 AMdsoltesz

Its always good practice to have proper error handling in your application and a way for users to report the errror.  Recently I learned of a new service called http://www.bugsense.com. BugSense is a library made for mobile developers. Get the context of the errors, track errors in specific app version or filter errors by device. There was Internet connectivity at the time of the crash? BugSense collects all the information the mobile developer needs and create reports for you to easliy be able to track and resolve application errors.  Using BugSense in your Windows Phone 7.x application is super easy and its FREE! Start with installing the BugSense library for Windows Phone. Use NuGet by typing “Install-Package BugSense.WP7” to NuGet Console or Search for BugSense using the NuGet Package Manager UI or download the BugSense-WP7-v0.9.zip unzip and add a reference to BugSense.dll in your Windows Phone Project.

Then, all you need to do is go inside you App.xaml.cs file and add the following code inside the constructor: Don't forget to use your Project API key you'll find in your dashboard!

public App()
{    
    BugSenseHandler.Instance.Init(this, "Your_API_Key");    
    // You app's code
}

 I have in corporated bugsense into my nightly prayer application and its working great!!!

 

Posted in: .NET | c# | Windows Phone 7

Tags: ,

Windows Phone 7 app - Nightly Prayer

November 23, 2011 at 7:03 PMdsoltesz

I recently created my first wp7 app http://www.windowsphone.com/en-US/apps/3ca7bb09-7710-4114-bb97-62d2657c7e95.  I did something simple just to see what it took to build an app and go through the market place app submission process.  I spent about a week creating this app.  That includes setting up a dev machine, creating database and admin app to manage data, web services that the phone can talk to and then building of the actual app.  This app was built using MVVM design pattern and this MVVM Framework I mentioned in this post http://www.dansoltesz.com/post/2011/11/14/Windows-Phone-7-MVVM-Framework.aspx

 

While this app is simple in nature, it uses several core features that any app would need.  It handles proper tombstoning, page navigation with nice transitions, communicates with external services, uses ad control with location services, context menu support, application button and menu databinding,splash startup screen, proper error handling and reporting, background services and live tile updates and several windows phone 7 tasks for emailing and sharing.

 

In order to have my app ready for the submission process, I used the new windows phone 7 market place test kit that was available with the mango sdk.  This proved priceless in helping to identify any potential issues before submitting the app to the market place.  The biggest issue I ran into is having a fast startup time.  Per the certification process your app has to have the main page visible within 5 seconds.  This seems pretty easy to do but when your initializing viewmodels, databinding UI, using Panorama view which supports multiple UI's, checking data connections and connection to services, 5 seconds goes by pretty quick.  My first test was well over 5 seconds so I started doing some refactoring, added in splash screen that enabled my real main page to get loaded properly and when all was said an done, the app launches ina  few seconds on average.

 

Please check out the app and let me know of any issues or improvements and if you would like any details of anything, just ask.

Posted in: .NET | c# | Windows Phone 7

Tags: , , , ,

windows phone 7 serialize object to isolated storage

November 16, 2011 at 11:41 PMdsoltesz

I have been working with windows phone 7 recently and i want to be able to serialize an object to xml to save into isolated storage.  Here is a Isolated storage helper that will allow you to do jus that.

public class IsolatedStorageHelper
    {
        public const string MyObjectFile = "myObject.xml";
        public static void WriteToXml<T>(T data, string path)
        {
            // Write to the Isolated Storage
            var xmlWriterSettings = new XmlWriterSettings { Indent = true };

            using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var stream = myIsolatedStorage.OpenFile(path, FileMode.Create))
                {
                    var serializer = new XmlSerializer(typeof(T));
                    using (var xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
                    {
                        serializer.Serialize(xmlWriter, data);
                    }
                }
            }
        }
        public static T ReadFromXml<T>(string path)
        {
            T data = default(T);
            try
            {
                using (var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (var stream = myIsolatedStorage.OpenFile(path, FileMode.Open))
                    {
                        var serializer = new XmlSerializer(typeof(T));
                        data = (T)serializer.Deserialize(stream);
                    }
                }
            }
            catch
            {    //add some code here
            }
            return data;
        }


    }

To save your object call

IsolatedStorageHelper.WriteToXml(MyObject, IsolatedStorageHelper.MyObjectFile);

To fetch your object

var myObject = IsolatedStorageHelper.ReadFromXml<MyObject> (IsolatedStorageHelper.MyObjectFile);

Posted in: .NET | c# | silverlight | Windows Phone 7

Tags: , , ,

Windows Phone 7 MVVM Framework

November 14, 2011 at 7:04 PMdsoltesz

I have recently starting building a new windows phone 7 application and I was looking for a nice MVVM framework to use.  After reviewing several frameworks, I decided to go with UltraLight MVVM framework.  This is a great light weight framework for developing MVVM Silverlight applications with support for tombstoning on the Windows Phone 7.

UltraLight.mvvm provides a quick, easy and light way to add the following features to your Windows Phone 7 applications:

  • Commands
  • Command binding for buttons (with parameters)
  • Support for binding commands to application buttons / menu items on the application bar
  • Dialogs, both notification and confirmation
  • Messaging using the event aggregator publisher/subscriber model
  • Service location
  • Design-time friendly view models
  • Tombstone-friendly view models with control hooks for tombstone events
  • Decoupled navigation support from the view model
  • Decoupled visual state support from the view model
  • Back button interception on the view model
  • Notify property changed using expressions instead of magic strings
  • Dispatcher helper for UI thread access

Posted in: .NET | c# | silverlight | Windows Phone 7

Tags: , , ,

wcf ria services complex type parameters

October 8, 2011 at 12:07 AMdsoltesz

I always seem to forget how to get complex types to work as parameters in wcf ria services sp1.  You first have to make sure you expose your complex type as an IEnumerable

public IQueryable<MyComplexType> ExposeComplexType()
        {
            //stub to expose complex type to client
            throw new NotSupportedException();
        }

Then in order to use the complex type as a parameter, you have to mark your domain service method with the Invoke attribute

 

 [Invoke]
        public IEnumerable<SomeEntity> QueryMyEntity(MyComplexType param)
        { return myObjects;}

Posted in: .NET | wcf ria services

Tags: , ,

ListBox load data when user reaches end of list

January 25, 2011 at 10:48 PMdsoltesz

Great post on a behavior that will raise a command when the users scrolls to the end of a listbox to fetch more data.

This can easily be applied to wpf or silverlight as well.

http://danielvaughan.orpius.com/post/Scroll-Based-Data-Loading-in-Windows-Phone-7.aspx

Posted in: .NET | behaviors | silverlight

Tags: , ,

silverlight attach behavior in code

October 27, 2010 at 9:51 PMdsoltesz

I had a scenario where I needed to build part of the UI completely from Code and wanted to include a behavior as part of one of the UI controls.

Lets walk through and example of how to do this.

I want to create a WrapPanel that has the FluidMoveBehavior associated to the WrapPanel and applies the behavior to all its children.



var panel = new WrapPanel
{
   HorizontalAlignment = HorizontalAlignment.Left
};

var timeSpan = new TimeSpan(0, 0, 0, 0, 400);
var ease = new CubicEase
{
    EasingMode = EasingMode.EaseIn
};
var fluidMoveBehavior = new FluidMoveBehavior
{
    AppliesTo = FluidMoveScope.Children,
    Duration = new Duration(timeSpan),
    EaseX = ease,
    EaseY = ease
};

System.Windows.Interactivity.Interaction.GetBehaviors(panel).Add(fluidMoveBehavior);

 

Pretty easy, just make sure you add references to

  • System.Windows.Interactivity
  • Microsoft.Expression.Effects
  • Microsoft.Express.Interactions

Posted in: .NET | behaviors | c# | silverlight

Tags: , ,

Silverlight datagrid double click behavior MVVM

October 1, 2010 at 6:20 PMdsoltesz

I originally created a behavior to add double click support to a silverlight datagrid.  Post here http://www.dansoltesz.com/post/2010/02/19/Silverlight-datagrid-double-click-behavior.aspx

I had someone ask me how they could get this to work with MVVM so I want to post the changes to the DataGridDoubleClickBehavior class in the original post to support commanding.

Add a new dependency property

public ICommand DoubleClickCommand
        {
            get { return (ICommand)GetValue(DoubleClickCommandProperty); }
            set { SetValue(DoubleClickCommandProperty, value); }
        }

        public static readonly DependencyProperty DoubleClickCommandProperty = DependencyProperty.Register("DoubleClickCommand"typeof(ICommand), typeof(DataGridDoubleClickBehavior), new PropertyMetadata(DoubleClickCommandChanged));

        private static void DoubleClickCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // Code for dealing with your property changes
        }


 public object CommandParameter
        {
            get { return (object)GetValue(CommandParameterProperty); }
            set { SetValue(CommandParameterProperty, value); }
        }

        public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter"typeof(object), typeof(DataGridDoubleClickBehavior), new PropertyMetadata(CommandParameterChanged));

        private static void CommandParameterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // Code for dealing with your property changes
        }

Now in the _gridClickManager_DoubleClick event defined in the behavior add this new line

 void _gridClickManager_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (DoubleClick != null)
                DoubleClick(sender, e);

           if(DoubleClickCommand != null) DoubleClickCommand.Execute(CommandParameter); //code added

        } 

the behavior class now looks like this

 public class DataGridDoubleClickBehavior : Behavior<DataGrid>
    {

        private readonly MouseClickManager _gridClickManager;
        public event EventHandler<MouseButtonEventArgs> DoubleClick;
        public object CommandParameter
        {
            get { return (object)GetValue(CommandParameterProperty); }
            set { SetValue(CommandParameterProperty, value); }
        }

        public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter"typeof(object), typeof(DataGridDoubleClickBehavior), new PropertyMetadata(CommandParameterChanged));

        private static void CommandParameterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // Code for dealing with your property changes
        }
        public ICommand DoubleClickCommand
        {
            get { return (ICommand)GetValue(DoubleClickCommandProperty); }
            set { SetValue(DoubleClickCommandProperty, value); }
        }

        public static readonly DependencyProperty DoubleClickCommandProperty = DependencyProperty.Register("DoubleClickCommand"typeof(ICommand), typeof(DataGridDoubleClickBehavior), new PropertyMetadata(DoubleClickCommandChanged));

        private static void DoubleClickCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // Code for dealing with your property changes
        }

        public DataGridDoubleClickBehavior()
        {
            _gridClickManager = new MouseClickManager(300);
            _gridClickManager.DoubleClick += new MouseButtonEventHandler(_gridClickManager_DoubleClick);
        }

        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.LoadingRow += OnLoadingRow;
            AssociatedObject.UnloadingRow += OnUnloadingRow;
        }

        void OnUnloadingRow(object sender, DataGridRowEventArgs e)
        {
            //row is no longer visible so remove double click event otherwise
            //row events will miss fire
            e.Row.MouseLeftButtonUp -= _gridClickManager.HandleClick;
        }

        void OnLoadingRow(object sender, DataGridRowEventArgs e)
        {
            //row is visible in grid, wire up double click event
            e.Row.MouseLeftButtonUp += _gridClickManager.HandleClick;
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.LoadingRow -= OnLoadingRow;
            AssociatedObject.UnloadingRow -= OnUnloadingRow;
        }

        void _gridClickManager_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (DoubleClick != null)
                DoubleClick(sender, e);
 if (DoubleClickCommand != null)
DoubleClickCommand.Execute(CommandParameter);
        }

    }

 

Now in your datagrid instead of wiring up an event for the double click you bind to the DoubleClickCommand of your viewmodel.

Originally was

<data:DataGrid x:Name="myDataGrid">

<i:Interaction.Behaviors>

            <behaviors:DataGridDoubleClickBehavior DoubleClick="myDataGrid_DoubleClick"/>

      </i:Interaction.Behaviors> 

</data:DataGrid>

Now change to

That its, now when a user double clicks a grid row, the command will be raised in your viewModel.

<data:DataGrid x:Name="myDataGrid">

<i:Interaction.Behaviors>

            <behaviors:DataGridDoubleClickBehavior

DoubleClickCommand="{Binding DoubleCommand}

CommandParameter="{Binding SelectedItem, ElementName=myDataGrid}"/>

 

    </i:Interaction.Behaviors>

</data:DataGrid>

 

Posted in: .NET | behaviors | silverlight

Tags: , , ,

set asp.net version using aspnet_regiis

July 15, 2010 at 6:32 PMdsoltesz

I ran into a issue when trying to set a web site to use a specific .NET framework version when ASP.NET tab does not appear in IIS. (Note: this only happens on 64 bit windows 2003 server running iis in 32 bit mode).

  1. Open IIS and click on the web sites folder to get the Identifier for the web site where you want set the version of the .Net framework.
  2.  

  3. Verify the version of .Net configured for the different web sites by running aspnet_regiis –lk 
  4.  Set the framework version for the site by running aspnet_regiis –sn <PATH> where <PATH> is the path to the web site you wish to configure.
    Example: aspnet_regiis – sn w3svc/75913688/root/
    IMPORTANT:  You must run the version of aspnet_regiis associated to the version of the .Net framework you wish to register the site to use.  There is a copy of the utility in the folder for each version of the framework.

 

Posted in: .NET

Tags: ,

Silverlight confirm dialog imported by MEF

April 6, 2010 at 4:55 PMdsoltesz

I wanted to created a user control that would allow to me ask the user a question and then based on their answer, do something, hence I needed a confirm dialog.  I wanted to be able to use this control by adding a reference or by using MEF just to export/import my confirm dialog.  To start, I created a new silverlight application and then added a childwindow control and named it "ConfirmWindow".  Since I wanted to be able to export this control via MEF, I also created an interface for our confirm dialog.

<controls:ChildWindow x:Class="Axis.iDoc.Window.ConfirmWindow"

         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 

           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"

           Title="Confirm">

    <Grid x:Name="LayoutRoot" Width="400" Margin="2">

        <Grid.RowDefinitions>

            <RowDefinition />

            <RowDefinition Height="Auto" />

        </Grid.RowDefinitions>

 

        <TextBlock x:Name="tbMessage" TextWrapping="Wrap" Grid.Row="0" />

        <Button x:Name="CancelButton" Content="No" Click="CancelButton_Click"  Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />

        <Button x:Name="OKButton" Content="Yes" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />

    </Grid>

</controls:ChildWindow>

Code behind

[Export(PartContracts.ConfirmWindow,typeof(IConfirmWindow))]

    public partial class ConfirmWindow : ChildWindow,IConfirmWindow

    {

        public ConfirmWindow()

        {

            InitializeComponent();

            this.Closed += (s, e) => dialogResult(this.DialogResult);

        }

        Action<bool?> dialogResult;

        public void Show(string message,Action<bool?> windowClosedFunc)

        {

            if (windowClosedFunc != null)

            {

                dialogResult = windowClosedFunc;

            }

 

            tbMessage.Text = message;

            this.Show();

        }

 

        private void OKButton_Click(object sender, RoutedEventArgs e)

        {

            this.DialogResult = true;

        }

 

        private void CancelButton_Click(object sender, RoutedEventArgs e)

        {

            this.DialogResult = false;

        }

 

 

    }

 

 

You will notice that I have an Export attribute at the top because I want to be able to export my confirm window via MEF.

 

IConfirmWindow.cs

public interface IConfirmWindow

   {

       void Show(string message, Action<bool?> windowClosedFunc);

   }


 

To use this control you can either add a reference to this silverlight application or you can import it via MEF. I decided to import it via MEF.

 

private Lazy<IConfirmWindow> confirmWindow;

 

       [Import(PartContracts.ConfirmWindow, AllowDefault = true, AllowRecomposition = true)]

       public Lazy<IConfirmWindow> ConfirmWindow

       {

           get { return confirmWindow; }

           set

           {

               if (confirmWindow == value)

               {

                   return;

               }

               confirmWindow = value;

 

           }

       }

 

 I created a little helper method to show confirm window.

 

 

public void ShowConfirmWindow(string message, Action<bool?> windowClosedAction)

 

if (ConfirmWindow != null)

 

 To use the confirm dialog is the same regardless if you added a reference to it or you imported from MEF.

 

private void deleteButton_Click(object sender, RoutedEventArgs e)

{

   _window.ShowConfirmWindow("Are you sure you want to delete item?", d => confirmDelete_Closed(d));

}

void confirmDelete_Closed(bool? dialogResult)

{

    if (dialogResult.HasValue && dialogResult.Value)

    {

       //user wants to delete   

    }

}

 

{

ConfirmWindow.Value.Show(message, windowClosedAction);

}

}

 

{

 

Posted in: .NET | c# | silverlight

Tags: ,