Ejemplo n.º 1
0
        /// <summary>
        /// The Transcribed Data is moved to Paratext SFM
        /// </summary>
        /// <param name="taskId">Task Id</param>
        /// <param name="heading">Heading for scripture</param>
        /// <returns>true if upload successful</returns>
        public static bool Upload(string taskId, string heading)
        {
            if (!ParatextInfo.IsParatextInstalled)
            {
                return(false);
            }

            try
            {
                // Get Task Details
                var currentTask = new Task();
                currentTask = currentTask.GetTask(taskId);

                // Get the Task Transcription Text from EAF
                var    folder      = Util.FileFolder(taskId);
                string eafFilePath = Path.Combine(folder, Path.GetFileNameWithoutExtension(taskId) + ".eaf");

                var transcriptionArray = GetTranscriptionTextFromEaf(eafFilePath);
                if (transcriptionArray[0].Trim().ToUpper().StartsWith("File Error:"))
                {
                    return(false);
                }
                ParatextData.Initialize();
                var paratextProject = ScrTextCollection.Find(currentTask.Project);
                if (paratextProject == null)
                {
                    return(false);
                }

                var bookNum =
                    paratextProject.BookNames.ScrText.BookNames.GetBookNumFromName(currentTask.BookName, true,
                                                                                   BookNameSource.Abbreviation);
                if (bookNum == 0)
                {
                    bookNum = (from i in paratextProject.BookNames.GetBookNames()
                               where i.BookCode == currentTask.BookName
                               select i.BookNum).FirstOrDefault();
                }

                var vRef = new VerseRef(bookNum, currentTask.ChapterNumber, Convert.ToInt32(currentTask.VerseStart),
                                        paratextProject.Settings.Versification);

                var chapterContent = paratextProject.GetText(vRef, true, true);

                var sb = GenerateParatextData(currentTask, chapterContent, transcriptionArray[1], heading);

                paratextProject.PutText(bookNum, currentTask.ChapterNumber, true, sb.ToString(), null);
                return(true);
            }
            catch (Exception ex)
            {
                var error = ex.Message;
                Debug.Print(error);
                Logger.WriteEvent(error);
            }

            return(false);
        }