[Route("add")] //define the url public IHttpActionResult Add([FromBody] DairyDTO lesson) { try { Lesson.Add(lesson); return(Ok()); } catch (Exception e) { LogManager.LogException(e); return(InternalServerError(e)); } }
public static void CreateJson() { String szLine = ""; String szSoundLine = ""; //String szDir = System.Environment.CurrentDirectory; List <List <VocabularyStruct> > Japanese = new List <List <VocabularyStruct> >(); List <VocabularyStruct> Lesson = null; JavaScriptSerializer serializer = new JavaScriptSerializer(); StreamReader sr = new StreamReader(JPN_FILE_PATH, Encoding.Default); StreamReader soundReader = null; int nLessonCount = 1; int nVocCount = 0; while ((szLine = sr.ReadLine()) != null) { if (szLine.Contains("第") && szLine.Contains("课")) { if (Lesson != null) { Japanese.Add(Lesson); soundReader.Close(); Console.WriteLine(nVocCount); nVocCount = 0; } soundReader = new StreamReader(JPN_SOUND_DIR + String.Format("{0:D6}", nLessonCount++) + ".lrc", Encoding.Default); Lesson = new List <VocabularyStruct>(); } else if (!szLine.Contains("----") && szLine != null && szLine != "") { szLine.Trim(); string[] szSplitArray; szSplitArray = szLine.Split(' '); List <string> szSplitList = szSplitArray.ToList(); while (szSplitList.Remove("")) { ; } if (szSplitList.Count > 0 && szSplitList.Count <= 3 && (szSplitList[0][0] == '~' || IsJapanese(szSplitList[0][0]))) { // 只有一个日文单词 if (szSplitList.Count == 1 && szSplitList[0].Contains("∕")) { string[] szWordSplit = szSplitList[0].Split('∕'); foreach (string wordSplit in szWordSplit) { szSoundLine = soundReader.ReadLine(); szSoundLine.Trim(); String[] szSoundSplitArray = szSoundLine.Split('[', ']', ':'); double dSoundTime = int.Parse(szSoundSplitArray[1]) * 60 + double.Parse(szSoundSplitArray[2]); VocabularyStruct word = new VocabularyStruct(wordSplit, dSoundTime); Lesson.Add(word); nVocCount++; } } else { String szVoc = ""; String szExtVoc = ""; String szType = ""; String szMeaning = ""; if (szSplitList.Count > 1) { if (szSplitList[1][0] == '〔' && szSplitList[1][szSplitList[1].Length - 1] == '〕') { szType = szSplitList[1].Substring(1, szSplitList[1].Length - 2); } else if (IsChinese(szSplitList[1][0])) { szMeaning = szSplitList[1]; } } if (szSplitList.Count > 2) { szMeaning = szSplitList[2]; } string[] szJWordSplit = szSplitList[0].Split('∕'); foreach (string wordSplit in szJWordSplit) { if (wordSplit.Contains("(") && wordSplit.Contains(")")) { wordSplit.Trim(); string[] szWordSplit = wordSplit.Split('(', ')'); szVoc = szWordSplit[0]; szExtVoc = szWordSplit[1]; } else { szVoc = wordSplit; szExtVoc = ""; } szSoundLine = soundReader.ReadLine(); szSoundLine.Trim(); String[] szSoundSplitArray = szSoundLine.Split('[', ']', ':'); double dSoundTime = Math.Round(int.Parse(szSoundSplitArray[1]) * 60 + double.Parse(szSoundSplitArray[2]), 2); VocabularyStruct word = new VocabularyStruct(szVoc, szExtVoc, szType, szMeaning, dSoundTime); Lesson.Add(word); nVocCount++; } } } } } if (Lesson != null) { Japanese.Add(Lesson); Console.WriteLine(nVocCount); } var json = serializer.Serialize(Japanese); FileStream fs = new FileStream(JPN_OUT_PATH, FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(json); sw.Flush(); sw.Close(); }