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: , , , ,

Find twitter RSS feed

November 20, 2011 at 10:39 PMdsoltesz

All Twitter RSS feeds are accessible via a URL in the following format:

https://twitter.com/statuses/user_timeline/(account-ID).rss 

In order to access yours (or anyone else’s) feed, you will need to determine their user ID number via IDfromUser.com. Simply enter the account user name and the account ID will be revealed.

So, for example, my username is “dansoltesz”. By entering “dansoltesz” into IDfromUser.com, the following ID is provided: 88685965.

In the example above, (account-ID) is substituted for 88685965and therefore my Twitter RSS feed URL is https://twitter.com/statuses/user_timeline/88685965.rss

Posted in:

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: , ,

C# Reflection Utility

October 4, 2011 at 8:52 PMdsoltesz

Here is a reflection utility helper class that will allow you to get a property from a object at runtime.  This utility will also support nested properties via the "." operator.

Using the class is pretty easy

var myObject = (IMyObjectType)ReflectionUtility.GetObjectProperty(item, "Model");

public static class ReflectionUtility { public static object GetObjectProperty(object item, string property) { if (item == null) return null; var dotIdx = property.IndexOf('.'); if (dotIdx > 0) { object obj = GetObjectProperty(item, property.Substring(0, dotIdx)); return GetObjectProperty(obj, property.Substring(dotIdx + 1)); } PropertyInfo propInfo = null; var objectType = item.GetType(); while (propInfo == null && objectType != null) { propInfo = objectType.GetProperty(property, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); objectType = objectType.BaseType; } if (propInfo != null) return propInfo.GetValue(item, null); var fieldInfo = item.GetType().GetField(property, BindingFlags.Public | BindingFlags.Instance); return fieldInfo != null ? fieldInfo.GetValue(item) : null; } }

Posted in:

Tags:

Deleting a parent entity and related child entities with RIA Services

September 22, 2011 at 12:31 AMdsoltesz

I created an extension that will allow you to traverse child entities easily so that you can remove each one from the parent.  Code is below.

 

public static class EntityExtensions { #region Static Methods (public) public static IEnumerable TraverseChildEntities ( this Entity parent, EntityContainer container ) { IEnumerable entityCollectionProperties = from p in parent.GetType( ).GetProperties( ) where p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition( ) == typeof ( EntityCollection<> ) select p; //// For every entity list, bind to the entity removed event foreach ( PropertyInfo property in entityCollectionProperties ) { var collectionType = property.PropertyType.GetGenericArguments()[0]; EntitySet set; if (!container.TryGetEntitySet(collectionType,out set)) { continue; } var entityCollection = ( IEnumerable )property.GetValue( parent, null ); foreach ( Entity entity in entityCollection ) { foreach ( Entity childEntity in entity.TraverseChildEntities(container ) ) { yield return childEntity; } yield return entity; } } } #endregion }

 With this extension in place now when I want to delete a parent entity and related child entities I can do somethig like this.

 

foreach (var child in new List(Parent.TraverseChildEntities(DomainContext.EntityContainer))) { DomainContext.EntityContainer.GetEntitySet(child.GetType()).Remove(child); } DomainContext.Parents.Remove(parent);

Posted in: c# | silverlight | wcf ria services

Tags: , ,

silverlight listbox autoscroll behavior

July 29, 2011 at 2:09 AMdsoltesz

Sometimes your list boxes can have a lot of items in them.  Even though you may order the list it still can be difficult for the user to find and item.  I like to give the user the abiltiy to search for an item in the listbox.  To keep this clean with MVVM, I created a behavior that can autoscroll for your via databinding.

 

Here is the behavior

 


/// <summary>
    /// Auto scroll listbox to item that is bound to the FoundItem property
    /// </summary>
    public class ListBoxItemAutoScrollBehavior : Behavior<ListBox>
    {
        #region Properties
        /// <summary>
        /// Item that is bound to listbox that you want to autoscroll to
        /// </summary>
        public object FoundItem
        {
            get { return GetValue(FoundItemProperty); }
            set { SetValue(FoundItemProperty, value); }
        }
 
        public static readonly DependencyProperty FoundItemProperty = DependencyProperty.Register("FoundItem"typeof(object), typeof(ListBoxItemAutoScrollBehavior), new PropertyMetadata(FoundItemChanged));
 
        private static void FoundItemChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((ListBoxItemAutoScrollBehavior)d).AssociatedObject.ScrollIntoView(e.NewValue);
        }
        #endregion
    }

 

Make sure you add a reference to System.Windows.Interactivity.

 

To use the behavior I do something like this.

<ListBox ItemsSource="{Binding MyItems}"  DisplayMemberPath="ItemName"  SelectionMode="Multiple">
                        <i:Interaction.Behaviors>
                            <behaviors:ListBoxItemAutoScrollBehavior FoundItem="{Binding FoundItem}"/>
                        </i:Interaction.Behaviors>
                    </ListBox>
<TextBox Text="{Binding ItemToFind, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" BorderThickness="1" />

 

Now in your view model just define your properties to bind to.


public ObservableCollection<Item> MyItems
        {
            get { return _myItems; }
            set
            {
 
                if (_myItems == valuereturn;
                _myItems = value;
                OnPropertyChanged(() => MyItems);
            }
        }
 
        public string ItemToFind
        {
            get { return _itemToFind; }
            set
            {
                if (_itemToFind == valuereturn;
                _itemToFind = value;
                 FoundItem = MyItems.FirstOrDefault(o => o.ItemName.StartsWith(_itemToFind, StringComparison.CurrentCultureIgnoreCase));
                OnPropertyChanged(() => ItemToFind);
                OnPropertyChanged(() => FoundItem);
            }
        }
         public Item FoundItem { getset; }

 Now when the user types in something into the textbox, it will autoscroll to the item that is found

Posted in: behaviors | c# | silverlight

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: , ,