Beispiel #1
0
        public ResultVO InsertTemplate(TemplateVO template)
        {
            var tempPath = template.StoredName;

            var staticFolderPath = "statics\\tmpl\\";

            var tmplRootPath = string.Format("{0}{1}", RootPath, staticFolderPath);


            var targetTmplPath = FileHelper.InitTmplPath(tmplRootPath);

            ZipHelper.Decompression(tempPath, targetTmplPath, true);

            //var tmpUser = _userInfoService.GetUserInfoById()

            var tmpl = new TemplateInfo()
            {
                TmplTitle       = template.TmplTitle,
                TmplDescription = template.TmplDescription,
                PreviewUrl      = template.PreviewUrl,
                StoredName      = targetTmplPath,
                CreateTime      = DateTime.Now,
                Deleted         = false,
                Remark          = string.Empty
            };

            var ret = _templateService.InsertTemplate(tmpl);

            return(ret);
        }
Beispiel #2
0
        public void TestMethod2()
        {
            var id  = Guid.Empty;
            var dir = $"{TestConfig.TestDir}Files/{id}/Temp/";

            dir.CreateDir();

            var path1 = $"{dir}文件1.txt";

            File.WriteAllText(path1, "文件1", Encoding.UTF8);
            var path2 = $"{dir}文件2.txt";

            File.WriteAllText(path2, "文件2", Encoding.UTF8);

            //压缩文件夹
            var zipPath = $"{TestConfig.TestDir}Files/{id}/1.zip";

            DirectoryHelper.DeleteFile(zipPath, false);
            var flag = ZipHelper.Eecompression(new List <string>()
            {
                path1,
                path2
            }, zipPath, out var msg);

            Assert.IsTrue(flag, msg);

            //解压缩文件
            var f1 = $"{TestConfig.TestDir}Files/{id}/文件1.txt";
            var f2 = $"{TestConfig.TestDir}Files/{id}/文件2.txt";

            DirectoryHelper.DeleteFiles(f1, f2);

            var flag2 = ZipHelper.Decompression(zipPath, $"{TestConfig.TestDir}Files/{id}", out msg);

            Assert.IsTrue(flag2, msg);

            var b1 = File.Exists(f1) && File.Exists(f2);

            Assert.IsTrue(b1);

            //验证文件内容
            var c1 = File.ReadAllText(f1);
            var c2 = File.ReadAllText(f2);
            var b2 = c1.IsEquals("文件1") && c2.IsEquals("文件2");

            Assert.IsTrue(b2);

            DirectoryHelper.DeleteDirectory($"{TestConfig.TestDir}Files/{id}", false);
        }