Ejemplo n.º 1
0
        public NameValueCollection CreateSiteByOnlineTemplateName(int siteId, bool isImportContents, bool isImportTableStyles, string onlineTemplateName, string onlineTemplateUrl, string userKeyPrefix, string administratorName)
        {
            var cacheTotalCountKey   = userKeyPrefix + CacheTotalCount;
            var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount;
            var cacheMessageKey      = userKeyPrefix + CacheMessage;

            CacheUtils.Insert(cacheTotalCountKey, "4");       //存储需要的页面总数
            CacheUtils.Insert(cacheCurrentCountKey, "0");     //存储当前的页面总数
            CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息

            //返回“运行结果”、“错误信息”及“执行JS脚本”的字符串数组
            NameValueCollection retval;

            try
            {
                CacheUtils.Insert(cacheCurrentCountKey, "1");
                CacheUtils.Insert(cacheMessageKey, "开始下载模板压缩包,可能需要几分钟,请耐心等待...");

                var filePath = PathUtility.GetSiteTemplatesPath($"T_{onlineTemplateName}.zip");
                FileUtils.DeleteFileIfExists(filePath);
                //var downloadUrl = OnlineTemplateManager.GetDownloadUrl(onlineTemplateName);
                var downloadUrl = OnlineTemplateManager.GetDownloadUrlByUrl(onlineTemplateUrl);
                WebClientUtils.SaveRemoteFileToLocal(downloadUrl, filePath);

                CacheUtils.Insert(cacheCurrentCountKey, "2");
                CacheUtils.Insert(cacheMessageKey, "模板压缩包下载成功,开始解压缩,可能需要几分钟,请耐心等待...");

                var siteTemplateDir = $"T_{onlineTemplateName}";
                var directoryPath   = PathUtility.GetSiteTemplatesPath(siteTemplateDir);
                DirectoryUtils.DeleteDirectoryIfExists(directoryPath);
                ZipUtils.ExtractZip(filePath, directoryPath);

                CacheUtils.Insert(cacheCurrentCountKey, "3");              //存储当前的页面总数
                CacheUtils.Insert(cacheMessageKey, "模板压缩包解压成功,正在导入数据..."); //存储消息

                SiteTemplateManager.Instance.ImportSiteTemplateToEmptySite(siteId, siteTemplateDir, isImportContents, isImportTableStyles, administratorName);
                CreateManager.CreateByAll(siteId);

                CacheUtils.Insert(cacheCurrentCountKey, "4"); //存储当前的页面总数
                CacheUtils.Insert(cacheMessageKey, "创建成功!");  //存储消息

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                retval = AjaxManager.GetWaitingTaskNameValueCollection($"站点 <strong>{siteInfo.SiteName}<strong> 创建成功!", string.Empty,
                                                                       $"top.location.href='{PageUtils.GetMainUrl(siteId)}';");
            }
            catch (Exception ex)
            {
                retval = AjaxManager.GetWaitingTaskNameValueCollection(string.Empty, ex.Message, string.Empty);
                LogUtils.AddErrorLog(ex);
            }

            CacheUtils.Remove(cacheTotalCountKey);   //取消存储需要的页面总数
            CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数
            CacheUtils.Remove(cacheMessageKey);      //取消存储消息
            CacheUtils.ClearAll();

            return(retval);
        }
Ejemplo n.º 2
0
        //private const string NuGetPackageSource = "https://packages.nuget.org/api/v2";
        //private const string MyGetPackageSource = "https://www.myget.org/F/siteserver/api/v2";

        //public static bool FindLastPackage(string packageId, out string title, out string version, out DateTimeOffset? published, out string releaseNotes)
        //{
        //    title = string.Empty;
        //    version = string.Empty;
        //    published = null;
        //    releaseNotes = string.Empty;

        //    try
        //    {
        //        var repo =
        //            PackageRepositoryFactory.Default.CreateRepository(WebConfigUtils.AllowNightlyBuild
        //                ? MyGetPackageSource
        //                : NuGetPackageSource);

        //        var package = repo.FindPackage(packageId);

        //        title = package.Title;
        //        version = package.Version.ToString();
        //        published = package.Published;
        //        releaseNotes = package.ReleaseNotes;

        //        return true;
        //    }
        //    catch (Exception)
        //    {
        //        // ignored
        //    }

        //    return false;
        //}

        public static void DownloadPackage(string packageId, string version)
        {
            var packagesPath  = PathUtils.GetPackagesPath();
            var idWithVersion = $"{packageId}.{version}";
            var directoryPath = PathUtils.Combine(packagesPath, idWithVersion);

            if (DirectoryUtils.IsDirectoryExists(directoryPath))
            {
                if (FileUtils.IsFileExists(PathUtils.Combine(directoryPath, $"{idWithVersion}.nupkg")) && FileUtils.IsFileExists(PathUtils.Combine(directoryPath, $"{packageId}.nuspec")))
                {
                    return;
                }
            }

            if (StringUtils.EqualsIgnoreCase(packageId, PackageIdSsCms))
            {
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                var localFilePath = PathUtils.Combine(directoryPath, idWithVersion + ".nupkg");

                WebClientUtils.SaveRemoteFileToLocal(
                    $"http://api.siteserver.cn/downloads/update/{version}", localFilePath);

                ZipUtils.UnpackFiles(localFilePath, directoryPath);
            }
            else
            {
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                var localFilePath = PathUtils.Combine(directoryPath, idWithVersion + ".nupkg");

                WebClientUtils.SaveRemoteFileToLocal(
                    $"http://api.siteserver.cn/downloads/package/{packageId}/{version}", localFilePath);

                ZipUtils.UnpackFiles(localFilePath, directoryPath);

                //var repo = PackageRepositoryFactory.Default.CreateRepository(WebConfigUtils.IsNightlyUpdate
                //? MyGetPackageSource
                //: NuGetPackageSource);

                //var packageManager = new PackageManager(repo, packagesPath);

                ////Download and unzip the package
                //packageManager.InstallPackage(packageId, SemanticVersion.Parse(version), true, WebConfigUtils.IsNightlyUpdate);
            }

            //ZipUtils.UnpackFilesByExtension(PathUtils.Combine(directoryPath, idWithVersion + ".nupkg"),
            //    directoryPath, ".nuspec");
        }
Ejemplo n.º 3
0
        public NameValueCollection SiteTemplateDownload(string downloadUrl, string directoryName, string userKeyPrefix)
        {
            var cacheTotalCountKey   = userKeyPrefix + CacheTotalCount;
            var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount;
            var cacheMessageKey      = userKeyPrefix + CacheMessage;

            CacheUtils.Insert(cacheTotalCountKey, "5");       //存储需要的页面总数
            CacheUtils.Insert(cacheCurrentCountKey, "0");     //存储当前的页面总数
            CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息

            //返回“运行结果”和“错误信息”的字符串数组
            NameValueCollection retval;

            try
            {
                CacheUtils.Insert(cacheCurrentCountKey, "1");
                CacheUtils.Insert(cacheMessageKey, "开始下载模板压缩包,可能需要几分钟,请耐心等待");

                var filePath = PathUtility.GetSiteTemplatesPath(directoryName + ".zip");
                FileUtils.DeleteFileIfExists(filePath);
                WebClientUtils.SaveRemoteFileToLocal(downloadUrl, filePath);

                CacheUtils.Insert(cacheCurrentCountKey, "4");
                CacheUtils.Insert(cacheMessageKey, "模板压缩包下载成功,开始解压缩");

                var directoryPath = PathUtility.GetSiteTemplatesPath(directoryName);
                if (!DirectoryUtils.IsDirectoryExists(directoryPath))
                {
                    ZipUtils.UnpackFiles(filePath, directoryPath);
                }

                CacheUtils.Insert(cacheCurrentCountKey, "5");
                CacheUtils.Insert(cacheMessageKey, string.Empty);

                retval = AjaxManager.GetProgressTaskNameValueCollection("站点模板下载成功,请到站点模板管理中查看。", string.Empty);
            }
            catch (Exception ex)
            {
                retval = AjaxManager.GetProgressTaskNameValueCollection(string.Empty,
                                                                        $@"<br />下载失败!<br />{ex.Message}");
            }

            CacheUtils.Remove(cacheTotalCountKey);   //取消存储需要的页面总数
            CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数
            CacheUtils.Remove(cacheMessageKey);      //取消存储消息

            return(retval);
        }
Ejemplo n.º 4
0
        public NameValueCollection PluginDownload(string downloadUrl, string userKeyPrefix)
        {
            var cacheTotalCountKey   = userKeyPrefix + CacheTotalCount;
            var cacheCurrentCountKey = userKeyPrefix + CacheCurrentCount;
            var cacheMessageKey      = userKeyPrefix + CacheMessage;

            CacheUtils.Insert(cacheTotalCountKey, "5");       //存储需要的页面总数
            CacheUtils.Insert(cacheCurrentCountKey, "0");     //存储当前的页面总数
            CacheUtils.Insert(cacheMessageKey, string.Empty); //存储消息

            //返回“运行结果”和“错误信息”的字符串数组
            NameValueCollection retval;

            try
            {
                CacheUtils.Insert(cacheCurrentCountKey, "1");
                CacheUtils.Insert(cacheMessageKey, "开始下载插件压缩包,可能需要几分钟,请耐心等待");

                var fileName = PageUtils.GetFileNameFromUrl(downloadUrl);
                var filePath = PathUtils.GetPluginPath(fileName);
                FileUtils.DeleteFileIfExists(filePath);
                WebClientUtils.SaveRemoteFileToLocal(downloadUrl, filePath);

                CacheUtils.Insert(cacheCurrentCountKey, "4");
                CacheUtils.Insert(cacheMessageKey, "插件压缩包下载成功,开始安装");

                ZipUtils.UnpackFiles(filePath, PathUtils.GetPluginPath(fileName.Substring(0, fileName.IndexOf(".", StringComparison.Ordinal))));

                CacheUtils.Insert(cacheCurrentCountKey, "5");
                CacheUtils.Insert(cacheMessageKey, string.Empty);

                retval = AjaxManager.GetProgressTaskNameValueCollection("插件安装成功,请刷新页面查看。", string.Empty);
            }
            catch (Exception ex)
            {
                retval = AjaxManager.GetProgressTaskNameValueCollection(string.Empty,
                                                                        $@"<br />下载失败!<br />{ex.Message}");
            }

            CacheUtils.Remove(cacheTotalCountKey);   //取消存储需要的页面总数
            CacheUtils.Remove(cacheCurrentCountKey); //取消存储当前的页面总数
            CacheUtils.Remove(cacheMessageKey);      //取消存储消息

            return(retval);
        }
Ejemplo n.º 5
0
        //将编辑器中图片上传至本机
        public static string SaveImage(SiteInfo siteInfo, string content)
        {
            var originalImageSrcs = RegexUtils.GetOriginalImageSrcs(content);

            foreach (var originalImageSrc in originalImageSrcs)
            {
                if (!PageUtils.IsProtocolUrl(originalImageSrc) ||
                    StringUtils.StartsWithIgnoreCase(originalImageSrc, PageUtils.ApplicationPath) ||
                    StringUtils.StartsWithIgnoreCase(originalImageSrc, siteInfo.Additional.WebUrl))
                {
                    continue;
                }
                var fileExtName = PageUtils.GetExtensionFromUrl(originalImageSrc);
                if (!EFileSystemTypeUtils.IsImageOrFlashOrPlayer(fileExtName))
                {
                    continue;
                }

                var fileName      = GetUploadFileName(siteInfo, originalImageSrc);
                var directoryPath = GetUploadDirectoryPath(siteInfo, fileExtName);
                var filePath      = PathUtils.Combine(directoryPath, fileName);

                try
                {
                    if (!FileUtils.IsFileExists(filePath))
                    {
                        WebClientUtils.SaveRemoteFileToLocal(originalImageSrc, filePath);
                        if (EFileSystemTypeUtils.IsImage(PathUtils.GetExtension(fileName)))
                        {
                            FileUtility.AddWaterMark(siteInfo, filePath);
                        }
                    }
                    var fileUrl = PageUtility.GetSiteUrlByPhysicalPath(siteInfo, filePath, true);
                    content = content.Replace(originalImageSrc, fileUrl);
                }
                catch
                {
                    // ignored
                }
            }
            return(content);
        }