private void Application_Activated(object sender, ActivatedEventArgs e)
        {
            if (PhoneApplicationService.Current.StartupMode == StartupMode.Activate)
            {
                // Returning from a tombstone event - restore application state
                IDictionary<string, object> appState = PhoneApplicationService.Current.State;

                _menuCollection = appState["ApplicationMenu"] as MenuCollection;
                XamlFileDetailsCollection = appState["XamlFileDetailsCollection"] as XAMLFileDetailsCollection;
                FormMappings = appState["FormMappings"] as FormMappings;

                if (appState["SessionToken"] != null)
                {
                    ActiveSession = new Session(ServerApplicationService);
                    HasOpenSession = true;
                }

                if (appState["SessionToken"] != null)
                    ActiveSession.SessionToken = appState["SessionToken"].ToString();

                if (appState["ApplicationMenu"] != null)
                    ActiveSession.UserName = appState["ApplicationMenu"].ToString();
            }
        }
        private void ActiveSession_SessionCreated(Session session)
        {
            if (SessionCreated != null)
                SessionCreated(session);

            HasOpenSession = true;

            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("ActiveSession"));
        }
        /// <summary>
        /// Creates session call to the server. It needs client credentials to validate them against the server.
        /// </summary>
        /// <param name="userName">Client username</param>
        /// <param name="password">Client password</param>
        /// <param name="site"></param>
        /// <param name="deviceName"></param>
        public void CreateSession(string userName, string password, string site, string deviceName, AuthenticationMode authenticationMode, EventHandler<AuthenticationCompletedEventArgs> authenticationComplete)
        {
            ActiveSession = new Session(ServerApplicationService);

            var auth = new ExpanzAuthentication(ClientType.Xaml, site, deviceName, authenticationMode);
            auth.Authenticate(userName, password, ActiveSession.AuthenticationComplete);

            if (authenticationComplete != null)
                ActiveSession.AuthenticationCompleted += authenticationComplete;

            ActiveSession.SessionCreated += new SessionCreatedDelegate(ActiveSession_SessionCreated);
        }