Example #1
0
        /// <summary>
        /// 根据文件内容,生成 Lrc 对象实例集合
        /// <para>异常:</para>
        /// <para>FileNotFoundException,无法获取指定的歌词文件</para>
        /// </summary>
        private void BuildLrcCollection()
        {
            List <LrcItem> unOrderLrcList = new List <LrcItem>();
            FileInfo       f = new FileInfo(FilePath);

            if (f.Exists && f.Length > 10)
            {
                string       ec = ENCODER.GetEncodingName(f);
                StreamReader sr = new StreamReader(f.FullName, ENCODER.GetEncoding(ec));
                while (!sr.EndOfStream)
                {
                    string lineString = sr.ReadLine();
                    unOrderLrcList.AddRange(_ParseLine(lineString));
                }
            }
            else if (f.Exists && f.Length < 10)
            {
                throw new FileLoadException("文件长度太短");
            }
            else
            {
                //歌词文件不存在
                throw new FileNotFoundException("未找到歌词文件。");
            }

            this.Items = new LinkedList <LrcItem>(unOrderLrcList.OrderBy(pp => pp.Time.Ticks));
        }
Example #2
0
        /// <summary>
        /// 文件写入到 Oracle Blob 字段中。type = 1 表示地图文件,其他值表示战斗文件
        /// </summary>
        public static bool SaveFileToDB(int file_type, string DBKey, string FullFileName)
        {
            FileStream mapfs;

            try
            {
                mapfs = new FileStream(FullFileName, FileMode.Open, FileAccess.Read);
            }
            catch (Exception ex)
            {
                Logging.Write("SaveFileToDB error: " + ex.ToString());
                return(false);
            }

            string sql;

            if (file_type == 1)
            {
                //sql = string.Format("select file_context from map_file where map_name = '{0}' for update", DBKey);
                sql = string.Format("update map_file set file_context = :1 where map_name = '{0}'", DBKey);
            }
            else
            {
                //sql = string.Format("select file_context from fight_file where roll_type = '{0}' for update", DBKey);
                sql = string.Format("update fight_file set file_context = :2 where roll_type = '{0}'", DBKey);
            }

            OracleTransaction transaction = null;

            try
            {
                if (!isConnected)
                {
                    OraConnect();
                }
                // 利用事务处理(必须)
                transaction = conn.BeginTransaction();
                OracleCommand   oCmd  = new OracleCommand(sql, conn);
                OracleParameter param = oCmd.Parameters.Add("1", OracleDbType.Clob, ParameterDirection.Input);

                IdentifyEncoding sinodetector = new IdentifyEncoding();
                FileInfo         finfo        = new FileInfo(FullFileName);
                StreamReader     sr           = new StreamReader(mapfs, sinodetector.GetEncoding(sinodetector.GetEncodingName(finfo)));
                string           context      = sr.ReadToEnd();
                param.Value = context;

                oCmd.ExecuteNonQuery();

                transaction.Commit();
                sr.Close();
                mapfs.Close();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                Logging.Write("SaveFileToDB error: " + ex.ToString());
                return(false);
            }

            return(true);
        }