Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the date/time the data source was last modified. The return value is a
        /// flag indicating whether or not the new value is different from the previous.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public bool UpdateLastModifiedTime()
        {
            if (Type == DataSourceType.FW && FwSourceDirectFromDB)
            {
                return(m_fwDataSourceInfo.UpdateLastModifiedTime());
            }

            // We don't have a way to get the last modified time for server-based projects.
            // TODO: Figure out how to deal with getting modifed time for server-based projects.
            if (Type == DataSourceType.FW7 && m_fwDataSourceInfo.IsMultiAccessProject)
            {
                return(false);
            }

            var latestModification = (Type == DataSourceType.SA ?
                                      SaAudioDocument.GetTranscriptionFileModifiedTime(SourceFile) :
                                      File.GetLastWriteTimeUtc(SourceFile));

            if (latestModification <= LastModification)
            {
                return(false);
            }

            LastModification = latestModification;
            return(true);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Copies the transcription data from one audio document to another.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void Copy(string destFilePath, bool md5MustMatch)
        {
            // first check MD5
            if (md5MustMatch && (AudioReader.GetMD5HashCode(destFilePath) != m_doc.MD5HashCode))
            {
                return;
            }

            // copy the transcription data
            m_doc           = m_doc.Clone();
            m_doc.AudioFile = destFilePath;
            Commit();
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes an object to read SA data from the SA database.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public bool Initialize(string audioFilePath, bool isForTmpOperation)
        {
            // Check if the DB used in some beta versions still exists. If so,
            // then convert the documents therein to companion transcription files.
            ConvertOldDatabaseToCompanionFiles();

            m_doc = SaAudioDocument.Load(audioFilePath, isForTmpOperation, true);
            if (m_doc != null)
            {
                ResetSegmentEnumerators();
                return(true);
            }

            try {
                using (AudioReader audioReader = new AudioReader()) {
                    AudioReader.InitResult result = audioReader.Initialize(audioFilePath);
                    if (result == AudioReader.InitResult.FileNotFound)
                    {
                        string msg = string.Format(Resources.kstidWaveFileNotFound, GUI.Utils.PrepFilePathForMsgBox(audioFilePath));
                        GUI.Utils.MsgBox(msg, MessageBoxButtons.OK);
                        return(false);
                    }

                    if ((result == AudioReader.InitResult.InvalidFormat))
                    {
                        string msg = string.Format(Resources.kstidInvalidWaveFile, GUI.Utils.PrepFilePathForMsgBox(audioFilePath));
                        GUI.Utils.MsgBox(msg, MessageBoxButtons.OK);
                        return(false);
                    }

                    // Try reading data from older SA audio files, converting
                    // it to Unicode along the way.
                    if (!audioReader.Read())
                    {
                        return(false);
                    }

                    // Now try reading the companion transcription file again.
                    m_doc = SaAudioDocument.Load(audioFilePath, isForTmpOperation, false);
                    ResetSegmentEnumerators();
                }
            } catch (Exception e) {
                string msg = string.Format(Resources.kstidErrorInitializingDocReader, e.Message);
                GUI.Utils.MsgBox(msg, MessageBoxButtons.OK);
                return(false);
            }

            return(true);
        }
Example #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private bool Initialize(string audioFilePath)
        {
            m_doc = SaAudioDocument.Load(audioFilePath, false, true);
            if (m_doc != null)
            {
                ResetSegmentEnumerators();
                return(true);
            }

            try
            {
                using (AudioReader audioReader = new AudioReader())
                {
                    AudioReader.InitResult result = audioReader.Initialize(audioFilePath);
                    if (result == AudioReader.InitResult.FileNotFound)
                    {
                        return(false);
                    }

                    if ((result == AudioReader.InitResult.InvalidFormat))
                    {
                        return(false);
                    }

                    // Try reading data from older SA audio files, converting
                    // it to Unicode along the way.
                    if (!audioReader.Read(true))
                    {
                        return(false);
                    }

                    // Now try reading the companion transcription file again.
                    m_doc = SaAudioDocument.Load(audioFilePath, false, false);
                    ResetSegmentEnumerators();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// This is not really necessary since the garbage collector should handle clearing
 /// memory. But this is provided so COM clients can force freeing some of the memory.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void Close()
 {
     m_doc = null;
 }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes an object to write SA data to the SA database.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public bool Initialize(string audioFilePath, bool isForTmpOperation)
 {
     m_doc = SaAudioDocument.Load(audioFilePath, isForTmpOperation, false);
     return(true);
 }