コード例 #1
0
ファイル: Chunk.cs プロジェクト: wait4amigo/Chunker
        public List<ChunkEnt> Get(int courseId, int blockId, int fromChunkId, int toChunkId, ref string errorInfo)
        {
            _log.Debug(string.Format("Get chunk info for course {0}, block {1}, from {2}, to {3} ", courseId, blockId, fromChunkId, toChunkId));

            string sql = string.Format("SELECT * FROM chunk WHERE course_id={0} and block_id={1} and chunk_id>={2} and chunk_id<={3}"
                , courseId, blockId, fromChunkId, toChunkId);

            DataSet ds = Query(sql);
            if (ds == null)
                throw new Exception("Failed to query chunk info");

            if (ds.Tables[0].Rows.Count == 0)
            {
                errorInfo = "Chunk info not exist";
                return null;
            }

            List<ChunkEnt> ents = new List<ChunkEnt>();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ChunkEnt ent = new ChunkEnt();

                ent.CourseId = int.Parse(row["course_id"].ToString());
                ent.BlockId = int.Parse(row["block_id"].ToString());
                ent.ChunkId = int.Parse(row["chunk_id"].ToString());
                ent.TargetWord = row["target_word"].ToString();
                ent.Form = row["form"].ToString();
                ent.ChunkEn = row["chunk_en"].ToString();
                ent.ChunkChs = row["chunk_chs"].ToString();
                ent.WordByWord = row["word_by_word"].ToString();
                ent.PronUrl = row["pron_url"].ToString();
                ent.SketchUrl = row["sketch_url"].ToString();
                ent.CreateTime = DateTime.Parse(row["create_time"].ToString());
                ent.UpdateTime = DateTime.Parse(row["update_time"].ToString());
                ent.Editor = row["editor"].ToString();
                ent.Translator = row["translator"].ToString();
                ent.Recorder = row["recorder"].ToString();

                ents.Add(ent);
            }

            return ents;
        }
コード例 #2
0
        private List<ChunkEnt> GetChunks()
        {
            List<ChunkEnt> ents = new List<ChunkEnt>();

            try
            {
                string appPath = HostingEnvironment.ApplicationPhysicalPath;
                string filePath = Path.Combine(appPath, @"Data\\chunks.txt");

                List<string> chunkLines = new List<string>(File.ReadAllLines(filePath, Encoding.Default));

                foreach (string line in chunkLines)
                {
                    string[] arr = line.Split('\t');
                    if (arr.Length != 11)
                    {
                        _log.Error("Chunk " + line + " has wrong format");
                        continue;
                    }

                    ChunkEnt ent = new ChunkEnt();
                    ent.CourseId = int.Parse(arr[0]);
                    ent.BlockId = int.Parse(arr[1]);
                    ent.ChunkId = int.Parse(arr[2]);
                    ent.TargetWord = arr[3];
                    ent.Form = arr[4];
                    ent.ChunkEn = arr[5];
                    ent.ChunkChs = arr[6];
                    ent.WordByWord = arr[7];
                    ent.PronUrl = "https://chunk.oss-cn-shanghai.aliyuncs.com/" + arr[0] + "/" + arr[1] + "/" + arr[2] + ".mp3";
                    ent.Editor = arr[8];
                    ent.Translator = arr[9];
                    ent.Recorder = arr[10];

                    ents.Add(ent);
                }

                return ents;
            }
            catch (Exception ex)
            {
                _log.Error(ex.ToString());
                return null;
            }
        }