Exemplo n.º 1
0
        private static string SaveBackupInfo(Context context, BackupInfo backupInfo)
        {
            OutputStreamWriter streamWriter = new OutputStreamWriter(context.OpenFileOutput("backup.json", FileCreationMode.Private));

            streamWriter.Write(JsonConvert.SerializeObject(backupInfo));
            streamWriter.Close();
            return(context.FilesDir + "/" + "backup.json");
        }
Exemplo n.º 2
0
        public static void ExportData(Context context)
        {
            BackupInfo backupInfo = new BackupInfo();

            backupInfo.Date            = DateTime.Now;
            backupInfo.UniqueId        = Guid.NewGuid();
            backupInfo.DatabaseVersion = DatabaseHelper.GetVersion(context);
            backupInfo.PackageName     = context.PackageName;
            try
            {
                backupInfo.AppVersionCode = context.ApplicationContext.PackageManager.GetPackageInfo(context.PackageName, 0).VersionCode;
                backupInfo.AppVersionName = context.ApplicationContext.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName;
            }
            catch (Exception ex)
            {
                NLog.LogManager.GetCurrentClassLogger().Error(ex);
            }
            String backupInfoFileName = SaveBackupInfo(context, backupInfo);

            Java.IO.File  file         = new Java.IO.File(GlobalClass.GetLogDirectory(context));
            List <String> logFilePaths = new List <string>();

            if (file.Exists())
            {
                Java.IO.File[] logFiles = file.ListFiles(new FileNameFilter());
                foreach (Java.IO.File f in
                         logFiles)
                {
                    logFilePaths.Add(f.AbsolutePath);
                }
            }
            List <String> files = new List <string>();

            files.Add(backupInfoFileName);
            foreach (var appId in VdmServiceHandler.GetAppIds(context))
            {
                files.Add(DatabaseHelper.GetDatabaseFilePath(appId));
            }
            files.AddRange(logFilePaths);
            string zipFilename = CreateBackupName();

            Zip(context, files, zipFilename);
            String path = Path.Combine(context.ExternalCacheDir.AbsolutePath);

            MediaScannerConnection.ScanFile(context, new String[] { path }, null, null);
        }