public ActionResult SubmitTitle(Title submittedTitle) { ActionResult actionResult = null; TextReader reader = null; try { BusinessLogic bizLogic = new BusinessLogic(); TitleSubtitle titleSubtitle = null; if (submittedTitle.SubtitleFile != null) { titleSubtitle = new TitleSubtitle(); reader = new StreamReader(submittedTitle.SubtitleFile.InputStream); titleSubtitle.SubtitleText = reader.ReadToEnd(); } int insertedTitleId = bizLogic.SubmitTitle(submittedTitle, titleSubtitle); actionResult = View("PostProcess", insertedTitleId); } catch (Exception ex) { HandleErrorInfo errorInfo = new HandleErrorInfo(ex, "titles", "SubmitTitle"); actionResult = View("Error", errorInfo); } finally { if (reader != null) { reader.Close(); } } return(actionResult); }
public List <TitleSubtitle> TitleSubtitleGetByTitleId(long titleId) { List <TitleSubtitle> titleSubtitles = null; using (SqlConnection conn = GetNewConnection()) { List <SqlParameter> paramColl = new List <SqlParameter>(); paramColl.Add(new SqlParameter() { ParameterName = "@TitleId", Value = titleId }); using (SqlCommand command = BuildCommand(usp_TitleSubtitle_SelectGetByTitle, CommandType.StoredProcedure, paramColl)) { command.Connection = conn; command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { TitleSubtitle titleSubtitle = new TitleSubtitle() { Id = reader.GetValueOrDefault <long>("Id"), TitleId = reader.GetValueOrDefault <long>("TitleId"), SubtitleText = reader.GetValueOrDefault <string>("SubtitleText"), SubtitleLanguageCode = reader.GetValueOrDefault <string>("SubtitleLanguageCode") }; if (titleSubtitles == null) { titleSubtitles = new List <TitleSubtitle>(); } titleSubtitles.Add(titleSubtitle); } reader.Close(); } } return(titleSubtitles); }
public int SubmitTitle(Title title, TitleSubtitle titleSubtitle) { int titleId = 0; using (TransactionScope tansaction = new TransactionScope()) { DataManager da = new DataManager(); titleId = da.TitlesInsert(title); if (titleSubtitle != null) { if (titleId > 0) { titleSubtitle.TitleId = titleId; } da.TitleSubtitleInsert(titleSubtitle); } tansaction.Complete(); } return(titleId); }
public int TitleSubtitleInsert(TitleSubtitle titleSubtitle) { int titleSubtitleId = 0; using (SqlConnection conn = GetNewConnection()) { List <SqlParameter> paramColl = new List <SqlParameter>(); paramColl.Add(new SqlParameter() { ParameterName = "@Id", Direction = ParameterDirection.Output, Size = int.MaxValue }); paramColl.Add(new SqlParameter() { ParameterName = "@TitleId", Value = NullSafeGetter.IsDefault <long>(titleSubtitle.TitleId) }); paramColl.Add(new SqlParameter() { ParameterName = "@SubtitleText", Value = NullSafeGetter.IsDefault <string>(titleSubtitle.SubtitleText) }); paramColl.Add(new SqlParameter() { ParameterName = "@SubtitleLanguageCode", Value = NullSafeGetter.IsDefault <string>(titleSubtitle.SubtitleLanguageCode) }); using (SqlCommand command = BuildCommand(usp_TitleSubtitle_Insert, CommandType.StoredProcedure, paramColl)) { command.Connection = conn; command.Connection.Open(); command.ExecuteNonQuery(); titleSubtitleId = Convert.ToInt32(command.Parameters["@Id"].Value); } } return(titleSubtitleId); }
public static List <IndexableEntity> ParseIt(Title title, TitleSubtitle titleSubtitle) { string[] theWholeSubtitleFileTextLines = titleSubtitle.SubtitleText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); List <IndexableEntity> parsedSubtitles = null; IndexableEntity currentParsedSubtitle = null; TimeSpan startTime = TimeSpan.MinValue; TimeSpan endTime = TimeSpan.MinValue; bool isPreviousCaptureReadyToInsert = false; for (int i = 0; i < theWholeSubtitleFileTextLines.Length; i++) { string thisLine = theWholeSubtitleFileTextLines[i]; int n; // Check if this line is not empty and not a number if (!string.IsNullOrWhiteSpace(thisLine) && !int.TryParse(thisLine.Trim(), out n)) { if (currentParsedSubtitle == null || currentParsedSubtitle.EndTime != TimeSpan.Zero) { currentParsedSubtitle = new IndexableEntity(); } // This means its a start time and end time indicator if (thisLine.Contains("-->")) { // If the capture for the current dialog is marked complete, add the object in the list and set the object to null. //if (isPreviousCaptureReadyToInsert) //{ // currentParsedSubtitle.EndTime = endTime; // if (parsedSubtitles == null) { parsedSubtitles = new List<IndexableEntity>(); } // currentParsedSubtitle.TitleName = title.TitleName; // currentParsedSubtitle.TitleId = title.Id; // currentParsedSubtitle.SubtitleTextId = titleSubtitle.Id; // parsedSubtitles.Add(currentParsedSubtitle); // currentParsedSubtitle = null; //} // Capture start time and end time string[] timesSplit = thisLine.Split(new string[] { "-->" }, System.StringSplitOptions.RemoveEmptyEntries); if (timesSplit.Length == 2) { if (!string.IsNullOrWhiteSpace(timesSplit[0])) { string startTimeString = timesSplit[0]; startTimeString = startTimeString.Remove(startTimeString.IndexOf(",")); startTime = TimeSpan.Parse(startTimeString); } if (!string.IsNullOrWhiteSpace(timesSplit[1])) { string endTimeString = timesSplit[1]; endTimeString = endTimeString.Remove(endTimeString.IndexOf(",")); endTime = TimeSpan.Parse(endTimeString); } } } else // NOW this means its a logical correct text line to capture as a quote { if (currentParsedSubtitle.StartTime == TimeSpan.Zero) { currentParsedSubtitle.StartTime = startTime; } thisLine = CleanItOfAllSpecialCharcters(thisLine); if (!string.IsNullOrWhiteSpace(currentParsedSubtitle.SubtitleText)) { currentParsedSubtitle.SubtitleText += " "; } currentParsedSubtitle.SubtitleText += thisLine; if ((thisLine.EndsWith(".") || thisLine.EndsWith("?")) && !thisLine.EndsWith("...")) // the last part is just to make sure the statement is not continued { isPreviousCaptureReadyToInsert = true; currentParsedSubtitle.EndTime = endTime; if (parsedSubtitles == null) { parsedSubtitles = new List <IndexableEntity>(); } currentParsedSubtitle.TitleName = title.TitleName; currentParsedSubtitle.TitleId = title.Id; currentParsedSubtitle.SubtitleTextId = titleSubtitle.Id; parsedSubtitles.Add(currentParsedSubtitle); currentParsedSubtitle = null; } else { isPreviousCaptureReadyToInsert = false; } } } } return(parsedSubtitles); }