示例#1
0
        public static MessageResult AssembleContents(int id)
        {
            var site = SiteRepository.GetById(id);

            if (site == null)
            {
                throw new Exception(string.Format(SiteStrings.SiteNotFound, id));
            }

            if (!site.IsDotNet)
            {
                return(MessageResult.Error(string.Format(SiteStrings.ShouldBeDotNet)));
            }

            var sqlMetalPath = QPConfiguration.ConfigVariable(Config.SqlMetalKey);

            if (site.ExternalDevelopment)
            {
                var liveTempDirectory  = $@"{site.TempDirectoryForClasses}\live";
                var stageTempDirectory = $@"{site.TempDirectoryForClasses}\stage";

                if (Directory.Exists(liveTempDirectory))
                {
                    Directory.Delete(liveTempDirectory, true);
                }

                Directory.CreateDirectory(liveTempDirectory);
                if (Directory.Exists(stageTempDirectory))
                {
                    Directory.Delete(stageTempDirectory, true);
                }

                Directory.CreateDirectory(stageTempDirectory);
                if (File.Exists(site.TempArchiveForClasses))
                {
                    File.Delete(site.TempArchiveForClasses);
                }

                new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString)
                {
                    SiteRoot = liveTempDirectory,
                    IsLive   = true,
                    DisableClassGeneration = site.DownloadEfSource
                }.Assemble();

                new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString)
                {
                    SiteRoot = stageTempDirectory,
                    IsLive   = false,
                    DisableClassGeneration = site.DownloadEfSource
                }.Assemble();

                ZipFile.CreateFromDirectory(site.TempDirectoryForClasses, site.TempArchiveForClasses);
                return(MessageResult.Download($"/Backend/Site/GetClassesZip/{id}"));
            }

            new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString).Assemble();
            return(null);
        }
示例#2
0
        public static MessageResult AssembleContents(int id)
        {
            var site = SiteRepository.GetById(id);

            if (site == null)
            {
                throw new Exception(string.Format(SiteStrings.SiteNotFound, id));
            }

            if (!site.IsDotNet)
            {
                return(MessageResult.Error(string.Format(SiteStrings.ShouldBeDotNet)));
            }

            var sqlMetalPath = QPConfiguration.ConfigVariable(Config.SqlMetalKey);
            var extDbType    = (QP.ConfigurationService.Models.DatabaseType)QPContext.DatabaseType;

            if (site.ExternalDevelopment)
            {
                var liveTempDirectory  = $@"{site.TempDirectoryForClasses}{Path.DirectorySeparatorChar}live";
                var stageTempDirectory = $@"{site.TempDirectoryForClasses}{Path.DirectorySeparatorChar}stage";

                if (Directory.Exists(liveTempDirectory))
                {
                    Directory.Delete(liveTempDirectory, true);
                }

                Directory.CreateDirectory(liveTempDirectory);
                if (Directory.Exists(stageTempDirectory))
                {
                    Directory.Delete(stageTempDirectory, true);
                }

                Directory.CreateDirectory(stageTempDirectory);
                if (File.Exists(site.TempArchiveForClasses))
                {
                    File.Delete(site.TempArchiveForClasses);
                }
                new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString, extDbType)
                {
                    SiteRoot = liveTempDirectory,
                    IsLive   = true,
                    DisableClassGeneration = site.DownloadEfSource
                }.Assemble();

                new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString, extDbType)
                {
                    SiteRoot = stageTempDirectory,
                    IsLive   = false,
                    DisableClassGeneration = site.DownloadEfSource
                }.Assemble();
                var urlHelper = HttpContext.RequestServices.GetRequiredService <IUrlHelper>();
                ZipFile.CreateFromDirectory(site.TempDirectoryForClasses, site.TempArchiveForClasses);
                return(MessageResult.Download(urlHelper.Content($"~/Site/GetClassesZip/{id}")));
            }
            new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString, extDbType).Assemble();

            return(null);
        }