public async Task Get_Short_Portal_Claims_Model_In_Postgre_Test()
        {
            if (!_context.AllowPostgreSQL)
            {
                Assert.True(true);
                return;
            }
            // Arrange
#pragma warning disable CA2000 // Dispose objects before losing scope
            PageEFRepository pageRepository = new PageEFRepository(_context.GetPostgreSQLContext());
#pragma warning restore CA2000 // Dispose objects before losing scope
            // Act
            Page pageBuilderTest = new Page
            {
                Id           = DataUtil.GenerateUniqueId(),
                Name         = "page-builder-2",
                DisplayName  = "Page Builder",
                UrlPath      = "portal/page/builder",
                ShellOptions = new List <ShellOption>(),
                Claims       = new List <PortalClaim>
                {
                    PortalClaimStandards.AllowAccess
                }
            };

            await pageRepository.AddAsync(pageBuilderTest);

            List <LetPortal.Portal.Models.Pages.ShortPortalClaimModel> result = await pageRepository.GetShortPortalClaimModelsAsync();

            pageRepository.Dispose();
            // Assert
            Assert.NotEmpty(result);
        }
        public async Task Get_One_By_Name_In_MySql_Test()
        {
            if (!_context.AllowMySQL)
            {
                Assert.True(true);
                return;
            }
            // Arrange
#pragma warning disable CA2000 // Dispose objects before losing scope
            PageEFRepository pageRepository = new PageEFRepository(_context.GetMySQLContext());
#pragma warning restore CA2000 // Dispose objects before losing scope
            // Act
            Page pageBuilderTest = new Page
            {
                Id           = DataUtil.GenerateUniqueId(),
                Name         = "page-builder",
                DisplayName  = "Page Builder",
                UrlPath      = "portal/page/builder",
                ShellOptions = new List <ShellOption>(),
                Claims       = new List <PortalClaim>
                {
                    PortalClaimStandards.AllowAccess
                }
            };

            await pageRepository.AddAsync(pageBuilderTest);

            Page result = await pageRepository.GetOneByNameAsync("page-builder");

            pageRepository.Dispose();
            // Assert
            Assert.NotNull(result);
        }
Exemple #3
0
        public async Task <IEnumerable <string> > Proceed(
            string folderPath,
            DatabaseOptions databaseOptions)
        {
            // Ensure this folder is exist
            if (!Directory.Exists(folderPath))
            {
                return(Enumerable.Empty <string>());
            }
            var allZipFiles     = Directory.GetFiles(folderPath, "*.zip");
            var allRunningFiles = new List <string>();

            if (allZipFiles != null && allZipFiles.Length > 0)
            {
                if (Directory.Exists("Temp"))
                {
                    Directory.Delete("Temp", true);
                }

                Directory.CreateDirectory("Temp");

                foreach (var file in allZipFiles)
                {
                    var fileNameWithoutExt = Path.GetFileNameWithoutExtension(file);
                    var extractFolder      = Path.Combine("Temp", fileNameWithoutExt);
                    ZipFile.ExtractToDirectory(file, extractFolder);

                    var backupFlatternModel = ConvertUtil.DeserializeObject <BackupFlatternFileModel>(File.ReadAllText(Path.Combine(extractFolder, fileNameWithoutExt + ".json")));

                    foreach (var chainingFile in backupFlatternModel.ChainingFiles)
                    {
                        switch (chainingFile)
                        {
                        case BackupService.APP_FILE:
                            var            appFilePath    = Path.Combine(extractFolder, BackupService.APP_FILE);
                            var            appsListString = File.ReadAllText(appFilePath);
                            var            appsList       = ConvertUtil.DeserializeObject <IEnumerable <App> >(appsListString);
                            IAppRepository appRepository;
                            if (databaseOptions.ConnectionType == ConnectionType.MongoDB)
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                appRepository = new AppMongoRepository(new MongoConnection(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            else
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                appRepository = new AppEFRepository(new Portal.Repositories.PortalDbContext(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }

                            var appServiceProvider = new InternalAppServiceProvider(appRepository);
                            await appServiceProvider.ForceUpdateApps(appsList);

                            appServiceProvider.Dispose();
                            break;

                        case BackupService.STANDARD_FILE:
                            var standardFilePath = Path.Combine(extractFolder, BackupService.STANDARD_FILE);
                            var standardsString  = File.ReadAllText(standardFilePath);
                            var standardsList    = ConvertUtil.DeserializeObject <IEnumerable <StandardComponent> >(standardsString);
                            IStandardRepository standardRepository;
                            if (databaseOptions.ConnectionType == ConnectionType.MongoDB)
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                standardRepository = new StandardMongoRepository(new MongoConnection(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            else
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                standardRepository = new StandardEFRepository(new Portal.Repositories.PortalDbContext(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            var standardServiceProvider = new InternalStandardServiceProvider(standardRepository);
                            await standardServiceProvider.ForceUpdateStandards(standardsList);

                            standardServiceProvider.Dispose();
                            break;

                        case BackupService.CHART_FILE:
                            var chartFilePath = Path.Combine(extractFolder, BackupService.CHART_FILE);
                            var chartsString  = File.ReadAllText(chartFilePath);
                            var chartsList    = ConvertUtil.DeserializeObject <IEnumerable <Chart> >(chartsString);
                            IChartRepository chartRepository;
                            if (databaseOptions.ConnectionType == ConnectionType.MongoDB)
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                chartRepository = new ChartMongoRepository(new MongoConnection(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            else
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                chartRepository = new ChartEFRepository(new Portal.Repositories.PortalDbContext(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            var chartServiceProvider = new InternalChartServiceProvider(chartRepository);
                            await chartServiceProvider.ForceUpdateCharts(chartsList);

                            chartServiceProvider.Dispose();
                            break;

                        case BackupService.DATABASE_FILE:
                            var databaseFilePath = Path.Combine(extractFolder, BackupService.DATABASE_FILE);
                            var databasesString  = File.ReadAllText(databaseFilePath);
                            var databasesList    = ConvertUtil.DeserializeObject <IEnumerable <DatabaseConnection> >(databasesString);
                            IDatabaseRepository databaseRepository;
                            if (databaseOptions.ConnectionType == ConnectionType.MongoDB)
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                databaseRepository = new DatabaseMongoRepository(new MongoConnection(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            else
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                databaseRepository = new DatabaseEFRepository(new PortalDbContext(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            var databaseServiceProvider = new InternalDatabaseServiceProvider(new DatabaseService(null, null), databaseRepository);
                            await databaseServiceProvider.ForceUpdateDatabases(databasesList);

                            databaseServiceProvider.Dispose();
                            break;

                        case BackupService.PAGE_FILE:
                            var             pageFilePath = Path.Combine(extractFolder, BackupService.PAGE_FILE);
                            var             pagesString  = File.ReadAllText(pageFilePath);
                            var             pagesList    = ConvertUtil.DeserializeObject <IEnumerable <Page> >(pagesString);
                            IPageRepository pageRepository;
                            if (databaseOptions.ConnectionType == ConnectionType.MongoDB)
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                pageRepository = new PageMongoRepository(new MongoConnection(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            else
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                pageRepository = new PageEFRepository(new PortalDbContext(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            var pageServiceProvider = new InternalPageServiceProvider(pageRepository, null, null, null);
                            await pageServiceProvider.ForceUpdatePages(pagesList);

                            pageServiceProvider.Dispose();
                            break;

                        case BackupService.DYNAMICLIST_FILE:
                            var dynamicListFilePath = Path.Combine(extractFolder, BackupService.DYNAMICLIST_FILE);
                            var dynamicListString   = File.ReadAllText(dynamicListFilePath);
                            var dynamicListsList    = ConvertUtil.DeserializeObject <IEnumerable <DynamicList> >(dynamicListString);
                            IDynamicListRepository dynamicListRepository;
                            if (databaseOptions.ConnectionType == ConnectionType.MongoDB)
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                dynamicListRepository = new DynamicListMongoRepository(new MongoConnection(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            else
                            {
#pragma warning disable CA2000 // Dispose objects before losing scope
                                dynamicListRepository = new DynamicListEFRepository(new PortalDbContext(databaseOptions));
#pragma warning restore CA2000 // Dispose objects before losing scope
                            }
                            var dynamicListServiceProvider = new InternalDynamicListServiceProvider(dynamicListRepository);
                            await dynamicListServiceProvider.ForceUpdateDynamicLists(dynamicListsList);

                            dynamicListServiceProvider.Dispose();
                            break;

                        default:
                            break;
                        }
                    }

                    allRunningFiles.Add(fileNameWithoutExt + ".zip");
                }
            }

            return(allRunningFiles);
        }
        public async Task Get_One_By_Name_For_Render_MySql_Test()
        {
            if (!_context.AllowMySQL)
            {
                Assert.True(true);
                return;
            }
            // Arrange
#pragma warning disable CA2000 // Dispose objects before losing scope
            PageEFRepository pageRepository = new PageEFRepository(_context.GetMySQLContext());
#pragma warning restore CA2000 // Dispose objects before losing scope

            // Act
            Page pageBuilderTest = new Page
            {
                Id           = DataUtil.GenerateUniqueId(),
                Name         = "page-builder-3",
                DisplayName  = "Page Builder",
                UrlPath      = "portal/page/builder",
                ShellOptions = new List <ShellOption>(),
                Claims       = new List <PortalClaim>
                {
                    PortalClaimStandards.AllowAccess
                },
                PageDatasources = new List <PageDatasource>
                {
                    new PageDatasource
                    {
                        Id       = "asd",
                        IsActive = true,
                        Name     = "data",
                        Options  = new LetPortal.Portal.Entities.Shared.DatasourceOptions
                        {
                            Type            = LetPortal.Portal.Entities.Shared.DatasourceControlType.Database,
                            DatabaseOptions = new LetPortal.Portal.Entities.Shared.DatabaseOptions
                            {
                                DatabaseConnectionId = "sfasfasf",
                                Query = "{\"$query\":{\"databases\":[{\"$match\":{\"_id\":\"ObjectId('{{queryparams.id}}')\"}}]}}"
                            }
                        }
                    }
                },
                Commands = new List <PageButton>
                {
                    new PageButton
                    {
                        Id                   = "180b55dd-e31f-387f-0844-7a9c74f88941",
                        Name                 = "Save",
                        Icon                 = "save",
                        Color                = "primary",
                        AllowHidden          = "!!queryparams.id",
                        IsRequiredValidation = true,
                        ButtonOptions        = new ButtonOptions
                        {
                            ActionCommandOptions = new ActionCommandOptions
                            {
                                ActionType        = ActionType.ExecuteDatabase,
                                DbExecutionChains = new DatabaseExecutionChains
                                {
                                    Steps = new List <DatabaseExecutionStep>
                                    {
                                        new DatabaseExecutionStep
                                        {
                                            DatabaseConnectionId = "fasdfas",
                                            ExecuteCommand       = "{\"$insert\":{\"{{options.entityname}}\":{ \"$data\": \"{{data}}\"}}}"
                                        }
                                    }
                                },
                                NotificationOptions = new NotificationOptions
                                {
                                    CompleteMessage = "Insert new database successfully!",
                                    FailedMessage   = "Oops! Something went wrong, please try again!"
                                },
                                ConfirmationOptions = new ConfirmationOptions
                                {
                                    IsEnable         = true,
                                    ConfirmationText = "Are you sure to create a database?"
                                }
                            },
                            RouteOptions = new RouteOptions
                            {
                                IsEnable = false
                            }
                        }
                    }
                }
            };

            await pageRepository.AddAsync(pageBuilderTest);

            Page page = await pageRepository.GetOneByNameForRenderAsync("page-builder-3");

            pageRepository.Dispose();
            // Assert
            Assert.NotNull(page);
        }