Esempio n. 1
0
        public static void RenderJsResource(string RsPath, string JsPath)
        {
            //var RsPath = "~//App_GlobalResources//resource1.resx";
            //var JsPath = "~//common//js//abc.js";
            RsPath = HttpContext.Current.Server.MapPath(RsPath);
            JsPath = HttpContext.Current.Server.MapPath(JsPath);
            var script = new StringBuilder();

            using (var resourceReader = new System.Resources.ResXResourceReader(RsPath))
            {
                foreach (DictionaryEntry entry in resourceReader)
                {
                    var key   = ZConvert.ToString(entry.Key).Replace('.', '_');
                    var value = ZConvert.ToString(entry.Value);
                    script.Append(",");
                    script.Append(key);
                    script.Append(":");
                    script.Append('"' + value + '"');
                    script.Append("\r\n");
                }
            }

            try
            {
                var str = "var lang = {\r\n " + script.ToString().Trim(',') + "}";
                ZFiles.DeleteFiles(JsPath);
                ZFiles.WriteStrToTxtFile(JsPath, str, FileMode.CreateNew);
            }
            catch
            {
            }
        }
Esempio n. 2
0
        private string GetTemplate(string pageType, string codeType)
        {
            var templatePath = HttpContext.Current.Server.MapPath(String.Format("~/Areas/Sys/Template/{0}/{1}.cshtml", pageType, codeType));
            var template     = ZFiles.ReadTxtFile(templatePath);

            return(template);
        }
Esempio n. 3
0
 public void Download()
 {
     if (_fileStream != null && _fileStream.Length > 0)
     {
         ZFiles.DownloadFile(HttpContext.Current, _fileStream, string.Format("{0}.{1}", _fileName, _suffix), 1024 * 1024 * 10);
     }
 }
Esempio n. 4
0
        private string GetFilePath(string path, string fileName = "")
        {
            var server = HttpContext.Current.Server;

            ZFiles.CreateDirectory(server.MapPath(path));
            return(server.MapPath(path + fileName));
        }
Esempio n. 5
0
        public void Post(JToken data)
        {
            var type       = data.Value <string>("type");
            var database   = data.Value <string>("database");
            var area       = data.Value <string>("area");
            var table      = data.Value <string>("table");
            var controller = data.Value <string>("controller");
            var path       = data.Value <string>("path");

            var SQLProvider = this.GetSQLProvider(database);

            using (var db = Db.Context(database))
            {
                var Columns = db.Sql(SQLProvider.SqlGetTableSchemas(table)).QueryMany <TableSchema>();
                var Keys    = db.Sql(SQLProvider.SqlGetTableKeys(table)).QueryMany <TableKey>().Select <TableKey, string>(x => x.column_name).ToList <string>();
                var Model   = new
                {
                    Database    = database,
                    Area        = area,
                    TableName   = table,
                    Columns     = Columns,
                    PrimaryKeys = Keys,
                    Identity    = Zephyr.Core.Generator.Util.GetIdentity(Columns),
                    Data        = data
                };

                var modelCode = Razor.Parse(GetTemplate(type, "Model"), Model);
                //这而报错,提示索引超出范围
                var controllerCode = Razor.Parse(GetTemplate(type, "Controller"), Model);
                var viewCode       = Razor.Parse(GetTemplate(type, "View"), Model);

                // var codePath = path + controller + "/"; //张欢欢 修改2015 12 14
                var codePath = path + "/Models/";
                ZFiles.SaveStreamToFile(GetStreamFromString(modelCode), GetFilePath(codePath, table + ".cs"));
                codePath = path + "/Controllers/";
                ZFiles.SaveStreamToFile(GetStreamFromString(controllerCode), GetFilePath(codePath, controller + "Controller.cs"));
                codePath = path + "/Views/" + controller + "/";
                ZFiles.SaveStreamToFile(GetStreamFromString(viewCode), GetFilePath(codePath, "Index.cshtml"));

                if (this.Request.RequestUri.Host == "localhost")
                {
                    System.Diagnostics.Process.Start(GetFilePath(codePath)); //如果是本地访问就直接打开文件夹
                }
                //return new {
                //    model=modelCode,
                //    controller=controllerCode,
                //    view=viewCode
                //};

                //using (var zip = new ZipFile())
                //{
                //    zip.AddEntry(table + ".cs", GetStreamFromString(modelCode));
                //    zip.AddEntry(controller + "Controller.cs", GetStreamFromString(controllerCode));
                //    zip.AddEntry("Index.cshtml", GetStreamFromString(viewCode));
                //    Stream zipStream = new MemoryStream();
                //    zip.Save(zipStream);
                //    ZFiles.DownloadFile(HttpContext.Current, zipStream, controller + "-Code.zip", 1024 * 1024 * 10);
                //}
            }
        }
        public static void PopulateFromRomFiles(ZFiles romFiles)
        {
            var banks = new List <IAnimationBank>();

            banks.Add(new AnimationBank("Inline with model"));

            foreach (var other in romFiles.Others)
            {
                var region = other.Region;

                if (other.FileName == "link_animetion")
                {
                    banks.Add(new AnimationBank(other.FileName,
                                                new RomBank {
                        Region = region
                    }));
                }
            }

            foreach (var obj in romFiles.Objects)
            {
                var fileName = obj !.FileName !.ToLower();
                var region   = obj.Region;

                if (fileName.Contains("object_") && fileName.Contains("_anime"))
                {
                    banks.Add(new AnimationBank(obj.BetterFileName !,
                                                new RomBank {
                        Region = region
                    }));
                }
            }

            AnimationBanks.Banks = banks;
        }
Esempio n. 7
0
        public void Populate(ZFiles zFiles)
        {
            this.betterTreeView_.BeginUpdate();

            var root = this.betterTreeView_.Root;

            var modelsNode = root.Add("Actor models");

            this.AddZFileNodeFor(null, modelsNode);
            foreach (var model in zFiles.Objects)
            {
                var modelNode = modelsNode.Add(model.BetterFileName !);
                this.AddZFileNodeFor(model, modelNode);
            }

            var actorCodeNode = root.Add("Actor code");

            this.AddZFileNodeFor(null, actorCodeNode);
            foreach (var code in zFiles.ActorCode)
            {
                var codeNode = actorCodeNode.Add(code.BetterFileName !);
                this.AddZFileNodeFor(code, codeNode);
            }

            var scenesNode = root.Add("Scenes");

            this.AddZFileNodeFor(null, scenesNode);
            foreach (var scene in zFiles.Scenes)
            {
                var sceneNode = scenesNode.Add(scene.BetterFileName !);
                this.AddZFileNodeFor(scene, sceneNode);

                foreach (var map in Asserts.Assert(scene.Maps))
                {
                    var mapNode = sceneNode.Add(map.BetterFileName !);
                    this.AddZFileNodeFor(map, mapNode);
                }
            }

            var othersNode = root.Add("Others");

            this.AddZFileNodeFor(null, othersNode);
            foreach (var other in zFiles.Others)
            {
                var otherNode = othersNode.Add(other.BetterFileName !);
                this.AddZFileNodeFor(other, otherNode);
            }

            this.InitializeAutocomplete_();

            this.betterTreeView_.EndUpdate();
        }
Esempio n. 8
0
        public static void PopulateFromRomFiles(ZFiles romFiles)
        {
            RamBanks.ActiveBank5Type = Bank5Type.FIELD;

            foreach (var other in romFiles.Others)
            {
                var region = other.Region;

                switch (other.FileName)
                {
                case "gameplay_keep": {
                    RamBanks.GameplayKeep.Region = region;
                    break;
                }

                case "gameplay_field_keep": {
                    RamBanks.GameplayFieldKeep.Region = region;
                    break;
                }

                case "gameplay_dangeon_keep": {
                    RamBanks.GameplayDangeonKeep.Region = region;
                    break;
                }

                case "icon_item_static": {
                    RamBanks.IconItemStatic.Region = region;
                    break;
                }

                case "icon_item_24_static": {
                    RamBanks.IconItem24Static.Region = region;
                    break;
                }
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 上传文件,并添加到数据库
        /// </summary>
        /// <param name="rsm">通知参数类</param>
        /// <param name="hpFile">http文件</param>
        /// <param name="lenth">最大长度,kb</param>
        /// <param name="SourceTable">来源表</param>
        /// <param name="ToId">主体Id</param>
        /// <param name="ShowName">显示名</param>
        /// <returns></returns>
        private TT_FilesInsuran AddFileOne(out HttpReSultMode rsm, HttpPostedFile hpFile, string[] allowExtensions, int lenth, string SourceTable, string ToId, string ShowName)
        {
            try
            {
                string FileName = hpFile.FileName;
                string ext      = System.IO.Path.GetExtension(FileName);// 后缀名

                FileName = FileName.Substring(FileName.LastIndexOf("\\") + 1);
                TT_FilesInsuran file = new TT_FilesInsuran();
                file.ToId        = ToId;
                file.AddTime     = DateTime.Now;
                file.SourceTable = SourceTable;

                if (!string.IsNullOrEmpty(ShowName))
                {
                    file.ShowName = ShowName + ext;
                }
                else
                {
                    file.ShowName = FileName;
                }
                file.Suffix    = ext;
                file.FileType  = "文件";
                file.isValid   = true;
                file.isDeleted = false;

                string HttpFileWeb       = ConfigurationManager.AppSettings["HttpFileWeb"].ToString();   //文件 http站点
                string HttpFileRoute     = ConfigurationManager.AppSettings["HttpFileRoute"].ToString(); //文件保存本地路径根目录
                string FileRelativeRoute = ConfigurationManager.AppSettings["TransactRoute"].ToString(); //文件保存相对目录
                //给文件取随及名
                Guid Pguid = Guid.NewGuid();
                FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + Pguid + ext;


                file.Route        = HttpFileWeb;
                file.RelativePath = FileRelativeRoute + FileName;
                file.FileName     = FileName;


                //保存文件路径
                string path = HttpFileRoute + FileRelativeRoute;

                rsm = ZFiles.FilesUpload(hpFile, allowExtensions, lenth, path, FileName);

                if (rsm.Code > 0)
                {
                    /*添加一条信息;*/
                    object resId = OPBiz.Add(file);
                    if (resId != null)
                    {
                        file.FileId = long.Parse(resId.ToString());
                        return(file);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                rsm = new HttpReSultMode()
                {
                    Code = -13,
                    Data = ex.Message,
                    Msg  = "系统出错:" + ex.Message
                };

                return(null);
            }
        }
Esempio n. 10
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string action = context.Request["action"];


            HttpReSultMode jmsg = new HttpReSultMode();

            switch (action)
            {
            case "addImg":    //上传单图片 返回文件信息json

                jmsg = addImg(context);
                context.Response.Write(JsonHelper.ToJson(jmsg));
                context.Response.End();
                break;

            case "addFile":    //上传文件 返回文件信息json

                jmsg = addFile(context);
                context.Response.Write(JsonHelper.ToJson(jmsg));
                context.Response.End();
                break;

            case "GetFileList":    //根据id集获取文件列表

                #region
                string id          = context.Request["ToId"];
                string SourceTable = context.Request["SourceTable"];
                if (!string.IsNullOrEmpty(id))
                {
                    var mql = TT_FilesInsuranSet.SelectAll().Where(TT_FilesInsuranSet.ToId.Equal(id).And(TT_FilesInsuranSet.SourceTable.Equal(SourceTable)));
                    List <TT_FilesInsuran> list = OPBiz.GetOwnList(mql);
                    context.Response.Write(JsonHelper.ToJson(list, true));
                }
                else
                {
                    context.Response.Write("[]");
                }
                context.Response.End();
                #endregion
                break;

            case "SaveToid":    //保存更改ToID

                #region

                string Tid   = FilterTools.FilterSpecial(context.Request["ToId"]);
                string IdSet = FilterTools.FilterSpecial(context.Request["IdSet"]);
                if (!string.IsNullOrEmpty(context.Request["ToId"]) && !string.IsNullOrEmpty(context.Request["IdSet"]))
                {
                    string sql = " update TT_FilesInsuran set ToId='" + Tid + "'  where FileId in (" + IdSet + ")";
                    int    i   = OPBiz.ExecuteSqlWithNonQuery(sql);
                    if (i > 0)
                    {
                        jmsg.Code = 11;
                        jmsg.Data = i.ToString();
                        jmsg.Msg  = "上传成功";
                    }
                    else
                    {
                        jmsg.Code = -11;
                        jmsg.Data = "0";
                        jmsg.Msg  = "上传失败";
                    }
                }
                else
                {
                    jmsg.Code = -11;
                    jmsg.Data = "0";
                    jmsg.Msg  = "数据为空";
                }
                context.Response.Write(JsonHelper.ToJson(jmsg, true));
                context.Response.End();

                #endregion
                break;

            case "Delfile":    //删除文件

                #region


                if (!string.IsNullOrEmpty(context.Request["IdSet"]))
                {
                    string[] IDSet = context.Request["IdSet"].ToString().Split(',');
                    var      mql2  = TT_FilesInsuranSet.FileId.In(IDSet);

                    var selectm = TT_FilesInsuranSet.SelectAll().Where(mql2);
                    List <TT_FilesInsuran> listDel = OPBiz.GetEntities(selectm);

                    //数据库删除
                    int f = OPBiz.Remove <TT_FilesInsuranSet>(mql2);


                    if (f > 0)
                    {
                        jmsg.Code = 11;
                        jmsg.Data = f.ToString();
                        jmsg.Msg  = "删除成功";

                        #region 文件删除
                        try
                        {
                            string HttpFileRoute = ConfigurationManager.AppSettings["HttpFileRoute"].ToString();    //文件保存本地路径根目录
                            for (int i = 0; i < listDel.Count; i++)
                            {
                                string path = HttpFileRoute + listDel[i].RelativePath;
                                ZFiles.FilePicDelete(path);
                            }
                        }
                        catch (Exception ex)
                        {
                            //jmsg.Code = -13;
                            //jmsg.Data = ex.Message;
                            //jmsg.Msg = "删除失败";
                        }
                        #endregion
                    }
                    else
                    {
                        jmsg.Code = -11;
                        jmsg.Data = "0";
                        jmsg.Msg  = "删除失败";
                    }
                }
                else
                {
                    jmsg.Code = -11;
                    jmsg.Data = "0";
                    jmsg.Msg  = "数据为空";
                }
                context.Response.Write(JsonHelper.ToJson(jmsg, true));
                context.Response.End();

                #endregion
                break;

            case "Download":
                #region
                if (!string.IsNullOrEmpty(context.Request["Url"]))
                {
                    // 检查请求下载文件的有效性
                    string filePath = System.Web.HttpContext.Current.Server.MapPath(context.Request["Url"]);
                    if (!System.IO.File.Exists(filePath))
                    {
                        throw new ArgumentException("无效文件,文件不存在!");
                    }

                    //WriteFile实现下载
                    string   fileName = context.Request["fileName"];  //客户端保存的文件名
                    FileInfo fileInfo = new FileInfo(filePath);
                    context.Response.Clear();
                    context.Response.ClearContent();
                    context.Response.ClearHeaders();
                    context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                    context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                    context.Response.AddHeader("Content-Transfer-Encoding", "binary");
                    context.Response.ContentType     = "application/octet-stream";
                    context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                    context.Response.WriteFile(fileInfo.FullName);
                    context.Response.Flush();
                    context.Response.End();
                }
                #endregion

                break;
            }
        }
Esempio n. 11
0
        private void DownCourseQrCode()
        {
            var Server = HttpContext.Current.Server;

            int    course_id      = RequestHelper.GetFormInt("course_id");
            string WebPath        = System.Configuration.ConfigurationManager.AppSettings["WebPath"];
            string webApi_address = WebPath + "/QrCode.aspx";

            BLL.course_info   bll    = new BLL.course_info();
            Model.course_info course = bll.GetModel(course_id);
            if (course != null)
            {
                string course_name = course.name.Trim();
                //1、生成书籍的二维码文件夹
                string virualRootPath = string.Format("/tempDown/{0}", course.name.Trim());
                string tempRootPath   = Server.MapPath(string.Format("/tempDown/{0}", course_name)).Trim();

                if (Directory.Exists(tempRootPath))
                {
                    Directory.Delete(tempRootPath, true);
                }
                if (!Directory.Exists(tempRootPath))
                {
                    Directory.CreateDirectory(tempRootPath);
                }

                if (string.IsNullOrWhiteSpace(webApi_address))
                {
                    writeMsgError(-1, "没有配置WebPath地址!");
                    return;
                }

                string bookQrCodePath = System.IO.Path.Combine(tempRootPath, string.Format("{0}_书籍资源.png", course_name)).Trim();

                string course_qrcode = string.Format("{0}/html/course_details.html?id={1}", WebPath, course.id); //要根据各个的生成规则生成二维码

                string logoPath = course.qrcode_logo;                                                            //二维码logo
                if (string.IsNullOrEmpty(logoPath))
                {
                    Model.common_albums defaultlogo = new BLL.common_albums().GetModel(" group_id = " + (int)Appoa.Common.EnumCollection.img_group.系统默认二维码logo);
                    if (defaultlogo != null)
                    {
                        logoPath = defaultlogo.original_path;
                    }
                    else
                    {
                        logoPath = "/html/images/Logo.png";
                    }
                }
                using (var ms = new MemoryStream())
                {
                    QrCodeHelper.GetRQCodeCombin(course_qrcode, ms, bookQrCodePath, Server.MapPath(logoPath));
                }
                //2、生成章的文件夹
                BLL.course_chapter          ccBll            = new BLL.course_chapter();
                BLL.common_resource         crBll            = new BLL.common_resource();
                List <Model.course_chapter> firstChapterList = ccBll.GetModelList(" group_id = 1 and chapter_level = 1 and course_id = " + course.id);
                foreach (Model.course_chapter chapter in firstChapterList)
                {
                    string chapterPath = System.IO.Path.Combine(tempRootPath, string.Format("章_{0}", chapter.name)).Trim();
                    if (Directory.Exists(chapterPath))
                    {
                        Directory.Delete(chapterPath, true);
                    }
                    if (!Directory.Exists(chapterPath))
                    {
                        Directory.CreateDirectory(chapterPath);
                    }

                    //3、生成节的文件夹
                    //List<Model.course_chapter> secondChapterList = ccBll.GetModelList(" group_id = 1 and chapter_level = 2 and course_id = " + course.id + " and parent_id = " + chapter.id);
                    //foreach (Model.course_chapter part in secondChapterList)
                    //{
                    //    string partPath = System.IO.Path.Combine(chapterPath, string.Format("节_{0}", part.name)).Trim();
                    //    if (Directory.Exists(partPath))
                    //    {
                    //        Directory.Delete(partPath, true);
                    //    }
                    //    if (!Directory.Exists(partPath))
                    //    {
                    //        Directory.CreateDirectory(partPath);
                    //    }

                    //4、生成章下所有资源二维码图片
                    List <Model.common_resource> resourceList = crBll.GetModelList(" is_del = 0 and from_id = " + (int)EnumCollection.resource_from.精品微课 + " and data_id = " + chapter.id);
                    foreach (Model.common_resource item in resourceList)
                    {
                        string resCode = string.Empty;
                        switch (item.type)
                        {
                        case (int)EnumCollection.resource_type.图文资源:
                            if (item.from_id == (int)EnumCollection.resource_from.精品微课)
                            {
                                resCode = WebPath + "/html/article_details.html?id=" + item.id;
                            }
                            else
                            {
                                resCode = WebPath + "/html/knowledge_details.html?id=" + item.id;
                            }
                            break;

                        case (int)EnumCollection.resource_type.文档资源:
                            item.path = item.path.Substring(0, item.path.LastIndexOf('.'));
                            //resCode = WebPath + item.path + ".html";
                            resCode = "/html/doc_detail.html?id=" + item.id;
                            break;

                        case (int)EnumCollection.resource_type.音频资源:
                            resCode = WebPath + "/html/video_details.html?id=" + item.id;
                            break;

                        case (int)EnumCollection.resource_type.视频资源:
                            resCode = WebPath + "/html/video_details.html?id=" + item.id;
                            break;

                        case (int)EnumCollection.resource_type.英文发音:
                            resCode = WebPath + "/html/voice_detail.html?id=" + item.id;
                            break;

                        case (int)EnumCollection.resource_type.维模型:
                            resCode = WebPath + "/html/3d.html?id=" + item.id;
                            break;
                        }
                        //生成明细资源
                        //string resPath = System.IO.Path.Combine(partPath, string.Format("{0}_{1}_资源_{2}.png", chapter.name, part.name, item.title.Trim())).Trim();
                        string resPath = System.IO.Path.Combine(chapterPath, item.title.Trim() + ".png").Trim();

                        using (var ms = new MemoryStream())
                        {
                            QrCodeHelper.GetRQCodeCombin(resCode, ms, resPath, Server.MapPath(logoPath));
                        }
                    }
                    //}
                }

                //打包—下载
                FastZip fz = new FastZip();
                fz.CreateEmptyDirectories = true;
                fz.CreateZip(string.Format("{0}.zip", tempRootPath), tempRootPath, true, "");
                // ZFiles.DownLoadFile(Server.MapPath(string.Format("{0}.zip", virualRootPath)));
                ZFiles.DownloadFile(System.Web.HttpContext.Current, Server.MapPath(string.Format("{0}.zip", virualRootPath)), 1024 * 50);
            }
        }
        public string PostFileData(string id, string tName, string tId, int type)
        {
            if (tId != null && tId != "")
            {
                tId = tId.Remove(tId.Length - 1, 1);
                string sql = string.Format(@"
delete QMS_QualityReportDoc where ID in({0})", tId);
                using (var db = Db.Context("Mms"))
                {
                    db.Sql(sql).Execute();
                }
            }
            string info = string.Empty;

            try
            {
                //获取客户端上传的文件集合
                HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                //判断是否存在文件
                Random rd = new Random();
                if (files.Count > 0)
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        //获取文件集合中的第一个文件(每次只上传一个文件)
                        HttpPostedFile file = files[i];
                        if (file.FileName == "")
                        {
                            continue;
                        }
                        //定义文件存放的目标路径
                        string targetDir = HttpContext.Current.Server.MapPath("~/Upload/" + new HomeApiController().GetPath(tName));
                        //创建目标路径
                        ZFiles.CreateDirectory(targetDir);
                        //组合成文件的完整路径
                        var    r           = rd.Next(9999, 99999);
                        string newFileName = DateTime.Now.ToString("yyyyMMddhhmmss") + r + "." + file.FileName.Substring(file.FileName.LastIndexOf('.') + 1, file.FileName.Length - file.FileName.LastIndexOf('.') - 1);
                        string path        = System.IO.Path.Combine(targetDir, System.IO.Path.GetFileName(newFileName));
                        //保存上传的文件到指定路径中
                        try
                        {
                            file.SaveAs(path);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                        info = "上传成功";

                        //string filePath = HttpContext.Current.Server.MapPath("~/Upload/" + path) + newFileName;
                        string InsertSql = string.Format(@"insert into QMS_QualityReportDoc values('',{5},'{0}','{1}',1,'{2}',getdate(),'{2}',getdate(),'{3}','{4}')", newFileName, path, MmsHelper.GetUserName(), file.FileName, id, type);
                        using (var db = Db.Context("Mms"))
                        {
                            db.Sql(InsertSql).Execute();
                        }
                    }
                }
                else
                {
                    info = "上传失败";
                }
            }
            catch
            {
                info = "上传失败";
            }
            return(info);
        }