Exemple #1
0
 public void OnLockDatabase(bool lockedByTimeout)
 {
     TimeoutHelper.Lock(this, lockedByTimeout);
 }
Exemple #2
0
        public Database LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compositeKey, ProgressDialogStatusLogger statusLogger, IDatabaseFormat databaseFormat, bool makeCurrent)
        {
            var prefs        = PreferenceManager.GetDefaultSharedPreferences(LocaleManager.LocalizedAppContext);
            var createBackup = prefs.GetBoolean(LocaleManager.LocalizedAppContext.GetString(Resource.String.CreateBackups_key), true) &&
                               !(new LocalFileStorage(this).IsLocalBackup(ioConnectionInfo));

            MemoryStream backupCopy = new MemoryStream();

            if (createBackup)
            {
                memoryStream.CopyTo(backupCopy);
                backupCopy.Seek(0, SeekOrigin.Begin);
                //reset stream if we need to reuse it later:
                memoryStream.Seek(0, SeekOrigin.Begin);
            }

            foreach (Database openDb in _openDatabases)
            {
                if (openDb.Ioc.IsSameFileAs(ioConnectionInfo))
                {
                    //TODO check this earlier and simply open the database's root group
                    throw new Exception("Database already loaded!");
                }
            }

            _openAttempts.Add(ioConnectionInfo);
            var newDb = new Database(new DrawableFactory(), this);

            newDb.LoadData(this, ioConnectionInfo, memoryStream, compositeKey, statusLogger, databaseFormat);



            if ((_currentDatabase == null) || makeCurrent)
            {
                _currentDatabase = newDb;
            }
            _openDatabases.Add(newDb);



            if (createBackup)
            {
                statusLogger.UpdateMessage(LocaleManager.LocalizedAppContext.GetString(Resource.String.UpdatingBackup));
                Java.IO.File internalDirectory = IoUtil.GetInternalDirectory(LocaleManager.LocalizedAppContext);
                string       baseDisplayName   = App.Kp2a.GetFileStorage(ioConnectionInfo).GetDisplayName(ioConnectionInfo);
                string       targetPath        = baseDisplayName;
                var          charsToRemove     = "|\\?*<\":>+[]/'";
                foreach (char c in charsToRemove)
                {
                    targetPath = targetPath.Replace(c.ToString(), string.Empty);
                }
                if (targetPath == "")
                {
                    targetPath = "local_backup";
                }

                var targetIoc = IOConnectionInfo.FromPath(new Java.IO.File(internalDirectory, targetPath).CanonicalPath);

                using (var transaction = new LocalFileStorage(App.Kp2a).OpenWriteTransaction(targetIoc, false))
                {
                    using (var file = transaction.OpenFile())
                    {
                        backupCopy.CopyTo(file);
                        transaction.CommitWrite();
                    }
                }
                Java.Lang.Object baseIocDisplayName = baseDisplayName;

                string keyfile = App.Kp2a.FileDbHelper.GetKeyFileForFile(ioConnectionInfo.Path);
                App.Kp2a.StoreOpenedFileAsRecent(targetIoc, keyfile, false, LocaleManager.LocalizedAppContext.
                                                 GetString(Resource.String.LocalBackupOf, new Java.Lang.Object[] { baseIocDisplayName }));

                prefs.Edit()
                .PutBoolean(IoUtil.GetIocPrefKey(ioConnectionInfo, "has_local_backup"), true)
                .PutBoolean(IoUtil.GetIocPrefKey(targetIoc, "is_local_backup"), true)
                .Commit();
            }
            else
            {
                prefs.Edit()
                .PutBoolean(IoUtil.GetIocPrefKey(ioConnectionInfo, "has_local_backup"), false)             //there might be an older local backup, but we won't "advertise" this anymore
                .Commit();
            }

            TimeoutHelper.ResumingApp();

            UpdateOngoingNotification();

            return(newDb);
        }
Exemple #3
0
        protected override void OnPause()
        {
            base.OnPause();

            TimeoutHelper.Pause(this);
        }
Exemple #4
0
        protected override void OnResume()
        {
            base.OnResume();

            TimeoutHelper.Resume(this);
        }
 protected override void OnPause()
 {
     base.OnPause();
     TimeoutHelper.Pause(this);
     Kp2aLog.Log(ClassName + ".OnPause");
 }