/// <summary>
        /// 单行转化为版本实例
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public Model.FileContentModel ChangeSimpleRowToFile(DataRow row)
        {
            FileContentModel model = new FileContentModel();

            if (row["id"].ToString() != "")
            {
                model.ID = row["id"].ToString();
            }

            if (row["File_ID"].ToString() != "")
            {
                model.File_ID = int.Parse(row["File_Size"].ToString());
            }

            if (row["File_VerID"].ToString() != "")
            {
                model.File_VerID = int.Parse(row["File_VerID"].ToString());
            }

            if (row["File_Ver"].ToString() != "")
            {
                model.File_Ver = row["File_Ver"].ToString();
            }

            if (row["Add_Time"].ToString() != "")
            {
                model.Add_Time = DateTime.Parse(row["add_time"].ToString());
            }
            return(model);
        }
Пример #2
0
        internal FileContentModel GetFileById(int fileId)
        {
            FileContentModel result = new FileContentModel();

            try
            {
                using (FileStoreModel db = new FileStoreModel())
                {
                    result = (from p in db.PersonalFiles
                              where p.IsActive == true && p.Id == fileId
                              select new FileContentModel {
                        Id = fileId, FileName = p.FileName, Content = p.FileContent
                    }).FirstOrDefault <FileContentModel>();
                }

                if (result == null)
                {
                    result = new FileContentModel();
                }

                if (result.Content == null)
                {
                    result.Content = new byte[] { };
                }
            }
            catch (Exception ex)
            {
                result = null;
                LogManager.LogException(ex, AppVariables.UserId, "FileManager", "GetFileById");
            }

            return(result);
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FileContentModel GetSimpleModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 * from [" + databaseprefix + "DetailContent] ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            FileContentModel model = new FileContentModel();
            DataSet          ds    = DbHelperFileContentSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                model = ChangeSimpleRowToFile(ds.Tables[0].Rows[0]);
                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        private void Save()
        {
            try
            {
                if (grdFiles.SelectedRows.Count == 0)
                {
                    MessageBox.Show("Dosya Seçiniz.");
                    return;
                }

                int fileId = grdFiles.SelectedRows[0].Cells["Id"].Value.ToInt();

                if (fileId < 1)
                {
                    MessageBox.Show("Geçersiz Dosya!..");
                    return;
                }

                using (SaveFileDialog svFlDialog = new SaveFileDialog())
                {
                    svFlDialog.Title = "Dosya Kaydetme yeri seçiniz.";

                    DialogResult dr = svFlDialog.ShowDialog();

                    if (dr == System.Windows.Forms.DialogResult.OK)
                    {
                        FileContentModel fcm = fileMan.GetFileById(fileId);
                        if (fcm != null)
                        {
                            string fileName = svFlDialog.FileName;

                            if (fileName.EndsWith(fcm.FileExtension) == false)
                            {
                                fileName = string.Format("{0}{1}", fileName, fcm.FileExtension);
                            }

                            File.WriteAllBytes(fileName, fcm.Content);
                            // Logging File Saving
                            LogManager.LogTransaction("Files", AppVariables.UserId, fileId, TransactionTypes.FileSave);
                            MessageBox.Show("Dosya Kaydedildi.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.LogException(ex, AppVariables.UserId, "FrmFileList", "Save");
                MessageBox.Show("Dosya Kaydedilemedi.");
            }
        }
Пример #5
0
        public JsonResult SaveFile(FileContentModel fileContent)
        {
            var fileName = DateTime.Now.Ticks + ".txt";

            if (!System.IO.Directory.Exists(Path.Combine(Server.MapPath("~/EricosnUpload"))))
            {
                System.IO.Directory.CreateDirectory(Path.Combine(Server.MapPath("~/EricosnUpload")));
            }
            var path        = Path.Combine(Server.MapPath("~/EricosnUpload/"), fileName);
            var returnValue = new JSONReturnValue();

            try
            {
                using (var file = new System.IO.StreamWriter(path))
                {
                    file.WriteLine(fileContent.Content);
                }
            }
            catch (Exception)
            {
                returnValue.Status  = false;
                returnValue.Message = "File Not Saved.";
            }
            try
            {
                var batMasterId = SaveBatMasterAndDetails(fileName, fileContent.Statements);
                if (batMasterId > 0)
                {
                    SendEmail(path, batMasterId);
                    returnValue.Status  = true;
                    returnValue.Message = "Mail with file attachment send successfully.";
                }
                else
                {
                    returnValue.Status  = false;
                    returnValue.Message = "Record not saved. Please try again";
                }
            }
            catch (Exception)
            {
                returnValue.Status  = false;
                returnValue.Message = "Error Sending Mail.";
            }

            return(Json(returnValue));
        }
Пример #6
0
        public byte[] HandleRequest(string requestPath)
        {
            string path = Path.Combine(_gameModeFolder, requestPath);

            // check if it's a directory request:
            if (Directory.Exists(path))
            {
                var dataModels = Directory.GetFiles(path).Select(file => new FileContentModel()
                {
                    FileName    = Path.Combine(requestPath, Path.GetFileName(file)),
                    FileContent = File.ReadAllText(file)
                }).ToArray();
                string returnStr = "[";
                for (int i = 0; i < dataModels.Length; i++)
                {
                    returnStr += dataModels[i].ToString(DataType.Json);
                    if (i < dataModels.Length - 1)
                    {
                        returnStr += ",";
                    }
                }
                returnStr += "]";
                return(Encoding.UTF8.GetBytes(returnStr));
            }
            // else, check if it's a request to a single file:
            else if (File.Exists(path))
            {
                string fileContent = File.ReadAllText(path);
                var    dataModel   = new FileContentModel()
                {
                    FileName    = requestPath,
                    FileContent = fileContent
                };
                string returnStr = "[" + dataModel.ToString(DataType.Json) + "]";
                return(Encoding.UTF8.GetBytes(returnStr));
            }

            // Return empty byte array:
            return(new byte[] { });
        }
Пример #7
0
        public byte[] HandleRequest(string requestPath)
        {
            string path = Path.Combine(_gameModeFolder, requestPath);

            // check if it's a directory request:
            if (Directory.Exists(path))
            {
                var dataModels = Directory.GetFiles(path).Select(file => new FileContentModel()
                {
                    FileName = Path.Combine(requestPath, Path.GetFileName(file)),
                    FileContent = File.ReadAllText(file)
                }).ToArray();
                string returnStr = "[";
                for (int i = 0; i < dataModels.Length; i++)
                {
                    returnStr += dataModels[i].ToString(DataType.Json);
                    if (i < dataModels.Length - 1)
                    {
                        returnStr += ",";
                    }
                }
                returnStr += "]";
                return Encoding.UTF8.GetBytes(returnStr);
            }
            // else, check if it's a request to a single file:
            else if (File.Exists(path))
            {
                string fileContent = File.ReadAllText(path);
                var dataModel = new FileContentModel()
                {
                    FileName = requestPath,
                    FileContent = fileContent
                };
                string returnStr = "[" + dataModel.ToString(DataType.Json) + "]";
                return Encoding.UTF8.GetBytes(returnStr);
            }

            // Return empty byte array:
            return new byte[] { };
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.FileVersion model)
        {
            string contentId = Guid.NewGuid().ToString();

            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into [" + databaseprefix + "FileVersion](");
            strSql.Append("Ver,UserID,UserName,File_Id,File_Type,File_Size,File_Md5,File_Ext,File_SmallImage,File_LargeImage,Content,File_Modify_Time,IsDeleted,ActionNum,ComputerName,Ip,ClientPath,Remark,Add_Time,FileContentId)");
            strSql.Append(" values (");
            strSql.Append("@Ver,@UserID,@UserName,@File_Id,@File_Type,@File_Size,@File_Md5,@File_Ext,@File_SmallImage,@File_LargeImage,@Content,@File_Modify_Time,@IsDeleted,@ActionNum,@ComputerName,@Ip,@ClientPath,@Remark,@Add_Time,@FileContentId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Ver",              SqlDbType.Int,           4),
                new SqlParameter("@UserID",           SqlDbType.Int),
                new SqlParameter("@UserName",         SqlDbType.NVarChar,    100),
                new SqlParameter("@File_Id",          SqlDbType.Int),
                new SqlParameter("@File_Type",        SqlDbType.NVarChar,    100),
                new SqlParameter("@File_Size",        SqlDbType.Int),
                new SqlParameter("@File_Md5",         SqlDbType.NVarChar,    100),
                new SqlParameter("@File_Ext",         SqlDbType.NVarChar,    200),
                new SqlParameter("@File_SmallImage",  SqlDbType.VarBinary),
                new SqlParameter("@File_LargeImage",  SqlDbType.VarBinary),
                new SqlParameter("@Content",          SqlDbType.VarBinary),
                new SqlParameter("@File_Modify_Time", SqlDbType.BigInt),
                new SqlParameter("@IsDeleted",        SqlDbType.TinyInt),
                new SqlParameter("@ActionNum",        SqlDbType.TinyInt),
                new SqlParameter("@ComputerName",     SqlDbType.NVarChar,    200),
                new SqlParameter("@Ip",               SqlDbType.NVarChar,    200),
                new SqlParameter("@ClientPath",       SqlDbType.NVarChar,   2000),
                new SqlParameter("@Remark",           SqlDbType.NVarChar,   2000),
                new SqlParameter("@Add_Time",         SqlDbType.DateTime),
                new SqlParameter("@FileContentId",    SqlDbType.NVarChar),
            };

            parameters[0].Value  = model.Ver;
            parameters[1].Value  = model.UserID;
            parameters[2].Value  = model.UserName;
            parameters[3].Value  = model.File_Id;
            parameters[4].Value  = model.File_Type;
            parameters[5].Value  = model.File_Size;
            parameters[6].Value  = model.File_Md5;
            parameters[7].Value  = model.File_Ext;
            parameters[8].Value  = model.File_SmallImage;
            parameters[9].Value  = model.File_LargeImage;
            parameters[10].Value = new byte[1];
            parameters[11].Value = model.File_Modify_Time;
            parameters[12].Value = model.IsDeleted;
            parameters[13].Value = model.ActionNum;
            parameters[14].Value = model.ComputerName;
            parameters[15].Value = model.Ip;
            parameters[16].Value = model.ClientPath;
            parameters[17].Value = model.Remark;
            parameters[18].Value = model.Add_Time;
            parameters[19].Value = contentId;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            int retId = Convert.ToInt32(obj);

            //文件内容的上传
            Model.FileContentModel contentModel = new FileContentModel()
            {
                ID           = contentId,
                Add_Time     = DateTime.Now,
                File_Content = model.Content,
                File_ID      = model.File_Id,
                File_Ver     = model.Ver.ToString(),
                File_VerID   = retId
            };
            string fileContentId = new DAL.FileContentDal(databaseprefix).Add(contentModel);

            if (obj == null || string.IsNullOrEmpty(fileContentId))
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #9
0
        private async Task DumpMap(string fp, Territory territory)
        {
            using (var sw = File.CreateText(fp))
            {
                //sw.WriteLine("mtllib nav_test.mtl");

                //sw.WriteLine($"o {territory.Name}.obj");

                var cnt = 1;

                //if (territory.Terrain != null)
                //{
                //    foreach (var part in territory.Terrain.Parts)
                //    {
                //        var fc = new FileContentModel(part, false);
                //        cnt = fc.MakeObj(sw, cnt);
                //    }
                //}

                foreach (var lgb in territory.LgbFiles)
                {
                    foreach (var group in lgb.Groups)
                    {
                        Console.WriteLine(group.Name);
                        foreach (var part in group.Entries)
                        {
                            var asMdl = part as SaintCoinach.Graphics.Lgb.LgbModelEntry;
                            var asGim = part as SaintCoinach.Graphics.Lgb.LgbGimmickEntry;

                            if (asMdl?.Collider != null)
                            {
                                sw.WriteLine("c " + asMdl.Header.Id);
                                var x = new FileContentModel(asMdl.Collider, false);
                                cnt = x.MakeObj(sw, cnt);
                            }

                            if (asGim?.Gimmick != null)
                            {
                                //if (gimicks.Contains(asGim.Header.Id))
                                //    asGim.Toggle();
                                sw.WriteLine("w " + asGim.Header.Id);
                                var x = new FileContentSgbModel(asGim.Gimmick, true)
                                {
                                    Transformation =
                                        Matrix.Scaling(asGim.Header.Scale.ToDx())
                                        * Matrix.RotationX(asGim.Header.Rotation.X)
                                        * Matrix.RotationY(asGim.Header.Rotation.Y)
                                        * Matrix.RotationZ(asGim.Header.Rotation.Z)
                                        * Matrix.Translation(asGim.Header.Translation.ToDx()),
                                };
                                cnt = x.MakeObj(sw, cnt);
                                //Console.WriteLine(cnt);
                            }
                        }
                    }
                }

                /*
                 * foreach (var lgb in territory.LgbFiles) {
                 *     foreach (var group in lgb.Groups) {
                 *         foreach (var part in group.Entries) {
                 *             var asMdl = part as SaintCoinach.Graphics.Lgb.LgbModelEntry;
                 *             var asGim = part as SaintCoinach.Graphics.Lgb.LgbGimmickEntry;
                 *
                 *             //we only care about gimmicks.
                 *             if (asGim == null)
                 *                 continue;
                 *
                 *             //Console.WriteLine(asGim.Header.Id);
                 *
                 *
                 *           //  if (asGim.Gimmick != null) {
                 *                 sw.WriteLine("w " + asGim.Header.Id);
                 *             if (asGim.Header.Id == 7350862) {
                 *                 //find the wall
                 *
                 *                 var x = new FileContentSgbModel(asGim.Gimmick, true) {
                 *                     Transformation =
                 *                         Matrix.Scaling(asGim.Header.Scale.ToDx())
                 * Matrix.RotationX(asGim.Header.Rotation.X)
                 * Matrix.RotationY(asGim.Header.Rotation.Y)
                 * Matrix.RotationZ(asGim.Header.Rotation.Z)
                 * Matrix.Translation(asGim.Header.Translation.ToDx()),
                 *                 };
                 *
                 *                cnt = x.MakeObj(sw, cnt);
                 *                 //Console.WriteLine(
                 *                 Console.WriteLine();
                 *                 Console.WriteLine(asGim.Header.Translation.X);
                 *                 Console.WriteLine(asGim.Header.Translation.Y);
                 *                 Console.WriteLine(asGim.Header.Translation.Z);
                 *
                 *                 Console.WriteLine(asGim.Header.Rotation.X);
                 *                 Console.WriteLine(asGim.Header.Rotation.Z);
                 *             }
                 *         }
                 *     }
                 * }*/
            }
        }