void ProfileSvc_ProfileLoaded(AsyncOperationInstance operation)
        {
            ProfileSvc.ProfileLoaded -= ProfileSvc_ProfileLoaded;
            var project = ProfileSvc.ProjectID;

            var paths = Settings.getOptions().Paths;


            if (CM.truncateSyncTable())
            {
                CM.disconnectFromMobileDB();
                SessionMgr.endSession();
                SessionMgr.startSession();
                var workingPaths = SessionMgr.createCleanWorkingCopies(paths);
                CM.connectToMobileDB(workingPaths);
            }
            else
            {
                if (CurrentOperation != null)
                {
                    CurrentOperation.failure("Actions_Error_CouldntTruncateSync", "");
                }
                _Log.Info("Could not truncate Sync Table, aborting clean.");
            }


            if (ProfileSvc.ProjectID != project)
            {
                ProfileSvc.ProjectID = project;
            }
            if (CurrentOperation != null)
            {
                CurrentOperation.success();
            }
        }
        private void saveAndClose()
        {
            if (CM != null)
            {
                CM.disconnectEverything();
            }

            if (SessionMgr != null)
            {
                if (SessionMgr.endSession())
                {
                    showMessageBox("Actions_Saved_Title", "Actions_Saved_Content",
                                   (res) =>
                    {
                        //Execute Shutdown.
                        MessengerInstance.Send <ApplicationClosing>(new ApplicationClosing(false));
                    });
                }
                else
                {
                    showMessageBox("MessageBox_Error_Title", "Actions_Error_CouldntSave", null);
                }
            }
            else
            {
                _Log.Error("Session Manager N/A");
            }
        }
 private void disconnectFromMobile()
 {
     new Action(() =>
     {
         SessionMgr.endSession();
         ConnectionManager.disconnectFromMobileDB();
     }).BeginInvoke(null, null);
 }