예제 #1
0
        public async Task RestoreBackupPoint(string backupId)
        {
            var backup = await _backupRepository.GetOneAsync(backupId);

            var zipFile = await _fileSeviceProvider.DownloadFileAsync(backup.FileId);

            var fileNameWithoutExt = FileUtil.GetFileNameWithoutExt(zipFile.FileName);
            var restoreFilePath    = Path.Combine(_backupOptions.CurrentValue.RestoreFolderPath, zipFile.FileName);

            Directory.CreateDirectory(_backupOptions.CurrentValue.RestoreFolderPath);
            using (var fileStream = File.Create(restoreFilePath))
            {
                fileStream.Write(zipFile.FileBytes, 0, zipFile.FileBytes.Length);
            }

            // Release file in memory
            zipFile.FileBytes = null;
            var folderExtractingPath = Path.Combine(_backupOptions.CurrentValue.RestoreFolderPath, fileNameWithoutExt);

            if (Directory.Exists(folderExtractingPath))
            {
                Directory.Delete(folderExtractingPath, true);
            }
            ZipFile.ExtractToDirectory(restoreFilePath, folderExtractingPath);

            var jsonBackupFilePath = Path.Combine(folderExtractingPath, fileNameWithoutExt + ".json");

            var jsonBackupString    = File.ReadAllText(jsonBackupFilePath);
            var backupFlatternModel = ConvertUtil.DeserializeObject <BackupFlatternFileModel>(jsonBackupString);

            foreach (var chainingFile in backupFlatternModel.ChainingFiles)
            {
                switch (chainingFile)
                {
                case APP_FILE:
                    var appFilePath    = Path.Combine(folderExtractingPath, APP_FILE);
                    var appsListString = File.ReadAllText(appFilePath);
                    var appsList       = ConvertUtil.DeserializeObject <IEnumerable <App> >(appsListString);
                    await _appServiceProvider.ForceUpdateApps(appsList);

                    break;

                case STANDARD_FILE:
                    var standardFilePath = Path.Combine(folderExtractingPath, STANDARD_FILE);
                    var standardsString  = File.ReadAllText(standardFilePath);
                    var standardsList    = ConvertUtil.DeserializeObject <IEnumerable <StandardComponent> >(standardsString);
                    await _standardServiceProvider.ForceUpdateStandards(standardsList);

                    break;

                case TREE_FILE:
                    var treeFilePath = Path.Combine(folderExtractingPath, TREE_FILE);
                    var treeString   = File.ReadAllText(treeFilePath);
                    var treeList     = ConvertUtil.DeserializeObject <IEnumerable <StandardComponent> >(treeString);
                    await _standardServiceProvider.ForceUpdateStandards(treeList);

                    break;

                case ARRAY_FILE:
                    var arrayFilePath = Path.Combine(folderExtractingPath, ARRAY_FILE);
                    var arrayString   = File.ReadAllText(arrayFilePath);
                    var arrayList     = ConvertUtil.DeserializeObject <IEnumerable <StandardComponent> >(arrayString);
                    await _standardServiceProvider.ForceUpdateStandards(arrayList);

                    break;

                case CHART_FILE:
                    var chartFilePath = Path.Combine(folderExtractingPath, CHART_FILE);
                    var chartsString  = File.ReadAllText(chartFilePath);
                    var chartsList    = ConvertUtil.DeserializeObject <IEnumerable <Chart> >(chartsString);
                    await _chartServiceProvider.ForceUpdateCharts(chartsList);

                    break;

                case DATABASE_FILE:
                    var databaseFilePath = Path.Combine(folderExtractingPath, DATABASE_FILE);
                    var databasesString  = File.ReadAllText(databaseFilePath);
                    var databasesList    = ConvertUtil.DeserializeObject <IEnumerable <DatabaseConnection> >(databasesString);
                    await _databaseServiceProvider.ForceUpdateDatabases(databasesList);

                    break;

                case PAGE_FILE:
                    var pageFilePath = Path.Combine(folderExtractingPath, PAGE_FILE);
                    var pagesString  = File.ReadAllText(pageFilePath);
                    var pagesList    = ConvertUtil.DeserializeObject <IEnumerable <Page> >(pagesString);
                    await _pageServiceProvider.ForceUpdatePages(pagesList);

                    break;

                case DYNAMICLIST_FILE:
                    var dynamicListFilePath = Path.Combine(folderExtractingPath, DYNAMICLIST_FILE);
                    var dynamicListString   = File.ReadAllText(dynamicListFilePath);
                    var dynamicListsList    = ConvertUtil.DeserializeObject <IEnumerable <DynamicList> >(dynamicListString);
                    await _dynamicListServiceProvider.ForceUpdateDynamicLists(dynamicListsList);

                    break;

                case COMPOSITE_CONTROL_FILE:
                    var compositeFilePath = Path.Combine(folderExtractingPath, COMPOSITE_CONTROL_FILE);
                    var compositeString   = File.ReadAllText(compositeFilePath);
                    var compositeList     = ConvertUtil.DeserializeObject <IEnumerable <CompositeControl> >(compositeString);
                    await _compositeControlServiceProvider.ForceUpdate(compositeList);

                    break;

                default:
                    break;
                }
            }

            Directory.Delete(folderExtractingPath, true);
            File.Delete(restoreFilePath);
        }
예제 #2
0
        public async Task Install(string uploadFileId, InstallWay installWay = InstallWay.Merge)
        {
            var zipFile = await _fileSeviceProvider.DownloadFileAsync(uploadFileId);

            var fileNameWithoutExt = FileUtil.GetFileNameWithoutExt(zipFile.FileName);
            var restoreFolderPath  = Path.Combine(Environment.CurrentDirectory, "Temp", "InstallationPackages");

            Directory.CreateDirectory(restoreFolderPath);
            var restoreFilePath = Path.Combine(restoreFolderPath, zipFile.FileName);

            using (var fileStream = File.Create(restoreFilePath))
            {
                fileStream.Write(zipFile.FileBytes, 0, zipFile.FileBytes.Length);
            }
            // Release file in memory
            zipFile.FileBytes = null;
            var folderExtractingPath = Path.Combine(restoreFolderPath, fileNameWithoutExt);

            if (Directory.Exists(folderExtractingPath))
            {
                Directory.Delete(folderExtractingPath, true);
            }
            ZipFile.ExtractToDirectory(restoreFilePath, folderExtractingPath);

            var jsonAppPackageFilePath = Path.Combine(folderExtractingPath, fileNameWithoutExt + ".json");

            var jsonAppPackageString = File.ReadAllText(jsonAppPackageFilePath);
            var appFlatternModel     = ConvertUtil.DeserializeObject <AppPackageFlatternModel>(jsonAppPackageString);

            var isExist = await _appRepository.IsExistAsync(a => a.Id == appFlatternModel.App.Id);

            switch (installWay)
            {
            case InstallWay.Merge:
                break;

            case InstallWay.Wipe:
                if (isExist)
                {
                    // Wipe all data
                    await _standardServiceProvider.DeleteAllByAppIdAsync(appFlatternModel.App.Id);

                    await _dynamicListServiceProvider.DeleteByAppIdAsync(appFlatternModel.App.Id);

                    await _chartServiceProvider.DeleteByAppIdAsync(appFlatternModel.App.Id);

                    await _pageServiceProvider.DeleteByAppIdAsync(appFlatternModel.App.Id);

                    await _localizationProvider.DeleteByAppIdAsync(appFlatternModel.App.Id);
                }
                break;
            }

            foreach (var chainingFile in appFlatternModel.ChainingFiles)
            {
                switch (chainingFile)
                {
                case STANDARD_FILE:
                    var standardFilePath = Path.Combine(folderExtractingPath, STANDARD_FILE);
                    var standardsString  = File.ReadAllText(standardFilePath);
                    var standardsList    = ConvertUtil.DeserializeObject <IEnumerable <StandardComponent> >(standardsString);
                    await _standardServiceProvider.ForceUpdateStandards(standardsList);

                    break;

                case DYNAMICLIST_FILE:
                    var dynamicListFilePath = Path.Combine(folderExtractingPath, DYNAMICLIST_FILE);
                    var dynamicListString   = File.ReadAllText(dynamicListFilePath);
                    var dynamicListsList    = ConvertUtil.DeserializeObject <IEnumerable <DynamicList> >(dynamicListString);
                    await _dynamicListServiceProvider.ForceUpdateDynamicLists(dynamicListsList);

                    break;

                case CHART_FILE:
                    var chartFilePath = Path.Combine(folderExtractingPath, CHART_FILE);
                    var chartsString  = File.ReadAllText(chartFilePath);
                    var chartsList    = ConvertUtil.DeserializeObject <IEnumerable <Chart> >(chartsString);
                    await _chartServiceProvider.ForceUpdateCharts(chartsList);

                    break;

                case PAGE_FILE:
                    var pageFilePath = Path.Combine(folderExtractingPath, PAGE_FILE);
                    var pagesString  = File.ReadAllText(pageFilePath);
                    var pagesList    = ConvertUtil.DeserializeObject <IEnumerable <Page> >(pagesString);
                    await _pageServiceProvider.ForceUpdatePages(pagesList);

                    break;

                case LOCALE_FILE:
                    var localeFilePath = Path.Combine(folderExtractingPath, LOCALE_FILE);
                    var localesString  = File.ReadAllText(localeFilePath);
                    var localesList    = ConvertUtil.DeserializeObject <IEnumerable <Localization> >(localesString);
                    await _localizationProvider.ForceUpdateLocalizations(localesList);

                    break;
                }
            }

            await _appRepository.ForceUpdateAsync(appFlatternModel.App.Id, appFlatternModel.App);

            Directory.Delete(folderExtractingPath, true);
            File.Delete(restoreFilePath);
        }