コード例 #1
0
        public void Save_CanReadSavedFile()
        {
            var mediafile       = MediaFileInfoTests.GetShortTestAudioFile();
            var expectedEafFile = AnnotationFileHelper.ComputeEafFileNameFromOralAnnotationFile(mediafile);

            try
            {
                var savedEafFile = _collection.Save(mediafile);
                Assert.AreEqual(expectedEafFile, savedEafFile);
                var tiers = AnnotationFileHelper.Load(savedEafFile).GetTierCollection();

                // We expect only 3 tiers in the saved file, because the AnnotationFileHelper only saves
                // the Transcription and Free Translation tiers. The "otherTextTier" is discarded.
                Assert.AreEqual(3, tiers.Count);

                for (var i = 0; i < tiers.Count; i++)
                {
                    CheckTier(_collection[i], tiers[i]);
                }
            }
            finally
            {
                try { File.Delete(mediafile); } catch { }
                try { File.Delete(expectedEafFile); } catch { }
            }
        }
コード例 #2
0
        /// ------------------------------------------------------------------------------------
        private string GetAudacityOrElanFile(string caption, string filter)
        {
            using (var dlg = new OpenFileDialog())
            {
                dlg.Title           = caption;
                dlg.CheckFileExists = true;
                dlg.CheckPathExists = true;
                dlg.Multiselect     = false;
                dlg.Filter          = filter + "|" + LocalizationManager.GetString(
                    "DialogBoxes.Transcription.CreateAnnotationFileDlg.AllFileTypeString",
                    "All Files (*.*)|*.*");

                return(dlg.ShowDialog() != DialogResult.OK ? null :
                       AnnotationFileHelper.CreateFileFromFile(dlg.FileName, _file.PathToAnnotatedFile));
            }
        }
コード例 #3
0
        private ComponentFile CreateVideoComponentFile(string filename)
        {
            var file = new ComponentFile(null, _parentFolder.Combine(filename),
                                         new FileType[] { new VideoFileType(null, null, null), new UnknownFileType(null, null) },
                                         new ComponentRole[] { }, new XmlFileSerializer(null), null, null, null);

            var annotationPath = Path.Combine(_parentFolder.Path,
                                              AnnotationFileHelper.ComputeEafFileNameFromOralAnnotationFile(filename));

            AnnotationFileHelperTests.CreateTestEaf(annotationPath);
            var annotationFile = new AnnotationComponentFile(null, annotationPath,
                                                             file, _fileTypes, null);

            file.SetAnnotationFile(annotationFile);
            return(file);
        }
コード例 #4
0
        /// ------------------------------------------------------------------------------------
        public override void RenameAnnotatedFile(string newPath)
        {
            var oldPfsxFile = Path.ChangeExtension(PathToAnnotatedFile, ".pfsx");

            base.RenameAnnotatedFile(newPath);
            AnnotationFileHelper.ChangeMediaFileName(PathToAnnotatedFile, GetPathToAssociatedMediaFile());

            if (!File.Exists(oldPfsxFile))
            {
                return;
            }

            var newPfsxFile = Path.ChangeExtension(PathToAnnotatedFile, ".pfsx");

            File.Move(oldPfsxFile, newPfsxFile);

            if (_oralAnnotationFile != null)
            {
                _oralAnnotationFile.RenameAnnotatedFile(GetSuggestedPathToOralAnnotationFile());
            }
        }
コード例 #5
0
        /// ------------------------------------------------------------------------------------
        static internal bool FileCopySpecialHandler(ArchivingDlgViewModel model, string source, string dest)
        {
            if (!source.EndsWith(AnnotationFileHelper.kAnnotationsEafFileSuffix))
            {
                return(false);
            }

            // Fix EAF file to refer to modified name.
            AnnotationFileHelper annotationFileHelper = AnnotationFileHelper.Load(source);

            var mediaFileName = annotationFileHelper.MediaFileName;

            if (mediaFileName != null)
            {
                var normalizedName = model.NormalizeFilename(string.Empty, mediaFileName);
                if (normalizedName != mediaFileName)
                {
                    annotationFileHelper.SetMediaFile(normalizedName);
                    annotationFileHelper.Root.Save(dest);
                    return(true);
                }
            }
            return(false);
        }
コード例 #6
0
        public void Save_CanReadSavedFile()
        {
            var mediafile       = MediaFileInfoTests.GetShortTestAudioFile();
            var expectedEafFile = AnnotationFileHelper.ComputeEafFileNameFromOralAnnotationFile(mediafile);

            try
            {
                var savedEafFile = _collection.Save(mediafile);
                Assert.AreEqual(expectedEafFile, savedEafFile);
                var tiers = AnnotationFileHelper.Load(savedEafFile).GetTierCollection();
                Assert.AreEqual(4, tiers.Count);

                for (int i = 0; i < tiers.Count; i++)
                {
                    CheckTier(_collection[i], tiers[i]);
                }
            }
            catch { }
            finally
            {
                try { File.Delete(mediafile); } catch { }
                try { File.Delete(expectedEafFile); } catch { }
            }
        }
コード例 #7
0
ファイル: ProjectElement.cs プロジェクト: tombogle/saymore
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// The reason this is separate from the Id property is: 1) You're not supposed to do
        /// anything non-trivial in property accessors (like renaming folders) and 2) It may
        /// fail, and needs a way to indicate that to the caller.
        ///
        /// NB: at the moment, all the change is done immediately, so a Save() is needed to
        /// keep things consistent. We could imagine just making the change pending until
        /// the next Save.
        /// </summary>
        /// <returns>true if the change was possible and occurred</returns>
        /// ------------------------------------------------------------------------------------
        public virtual bool TryChangeIdAndSave(string newId, out string failureMessage)
        {
            failureMessage = null;
            Save();
            newId = newId.Trim();

            if (_id == newId)
            {
                return(true);
            }

            if (newId == string.Empty)
            {
                failureMessage = NoIdSaveFailureMessage;
                return(false);
            }

            var    parent        = Directory.GetParent(FolderPath).FullName;
            string newFolderPath = Path.Combine(parent, newId);

            if (Directory.Exists(newFolderPath))
            {
                failureMessage = string.Format(AlreadyExistsSaveFailureMessage, Id, newId);
                return(false);
            }

            try
            {
                //todo... need a way to make this all one big all or nothing transaction.  As it is, some things can be
                //renamed and then we run into a snag, and we're left in a bad, inconsistent state.

                // for now, at least check for the very common situation where the rename of the
                // directory itself will fail, and find that out *before* we do the file renamings
                if (!CanPerformRename())
                {
                    failureMessage = LocalizationManager.GetString("CommonToMultipleViews.ChangeIdFailureMsg",
                                                                   "Something is holding onto that folder or a file in it, so it cannot be renamed. You can try restarting this program, or restarting the computer.",
                                                                   "Message displayed when attempt failed to change a session id or a person's name (i.e. id)");

                    return(false);
                }

                foreach (var file in Directory.GetFiles(FolderPath))
                {
                    var name = Path.GetFileName(file);
                    if (name.ToLower().StartsWith(Id.ToLower()))                    // to be conservative, let's only trigger if it starts with the id
                    {
                        //todo: do a case-insensitive replacement
                        //todo... this could over-replace

                        var newFileName = Path.Combine(FolderPath, name.Replace(Id, newId));
                        File.Move(file, newFileName);

                        if (Path.GetExtension(newFileName) == Settings.Default.AnnotationFileExtension)
                        {
                            // If the file just renamed is an annotation file (i.e. .eaf) then we
                            // need to make sure the annotation file is updated internally so it's
                            // pointing to the renamed media file. This fixes SP-399.
                            var newMediaFileName = newFileName.Replace(
                                AnnotationFileHelper.kAnnotationsEafFileSuffix, string.Empty);

                            AnnotationFileHelper.ChangeMediaFileName(newFileName, newMediaFileName);
                        }
                        else if (Directory.Exists(file + Settings.Default.OralAnnotationsFolderSuffix))
                        {
                            Directory.Move(file + Settings.Default.OralAnnotationsFolderSuffix,
                                           newFileName + Settings.Default.OralAnnotationsFolderSuffix);
                        }
                    }
                }

                Directory.Move(FolderPath, newFolderPath);
            }
            catch (Exception e)
            {
                failureMessage = ExceptionHelper.GetAllExceptionMessages(e);
                return(false);
            }

            var oldId = _id;

            _id = newId;
            Save();

            if (IdChangedNotificationReceiver != null)
            {
                IdChangedNotificationReceiver(this, oldId, newId);
            }

            return(true);
        }
コード例 #8
0
        /// ------------------------------------------------------------------------------------
        public static string ShowDialog(ComponentFile file, EditorBase parent, int segmentToHighlight)
        {
            Exception error;
            string    msg;

            using (var viewModel = new ManualSegmenterDlgViewModel(file))
                using (var dlg = new ManualSegmenterDlg(viewModel, segmentToHighlight))
                {
                    try
                    {
                        if (dlg.ShowDialog(parent) != DialogResult.OK || !viewModel.WereChangesMade)
                        {
                            viewModel.DiscardChanges();
                            return(null);
                        }

                        Analytics.Track("Changes made using Manual Segmentation");

                        var annotationFile = file.GetAnnotationFile();

                        if (!viewModel.TimeTier.Segments.Any())
                        {
                            if (annotationFile != null)
                            {
                                annotationFile.Delete();
                                parent.RefreshComponentFiles(file.FileName, null);
                            }
                            return(null);
                        }

                        var eafFile = AnnotationFileHelper.Save(file.PathToAnnotatedFile, viewModel.Tiers);

                        if (annotationFile == null)
                        {
                            return(eafFile);
                        }

                        error = annotationFile.TryLoadAndReturnException();
                        if (error == null)
                        {
                            WaitCursor.Show();
                            try
                            {
                                annotationFile.AssociatedComponentFile.GenerateOralAnnotationFile(viewModel.Tiers,
                                                                                                  parent, ComponentFile.GenerateOption.ClearAndRegenerateOnDemand);
                            }
                            finally
                            {
                                WaitCursor.Hide();
                            }
                            return(eafFile);
                        }

                        msg = LocalizationManager.GetString(
                            "DialogBoxes.Transcription.ManualSegmenterDlg.SavingSegmentsErrorMsg",
                            "There was an error while trying to save segments for the file '{0}'.");
                    }
                    catch (Exception e)
                    {
                        error = e;
                        msg   = LocalizationManager.GetString(
                            "DialogBoxes.Transcription.ManualSegmenterDlg.GeneralSegmentingErrorMsg",
                            "There was an error segmenting the file '{0}'.");
                    }
                }

            ErrorReport.NotifyUserOfProblem(error, msg, file.PathToAnnotatedFile);
            return(null);
        }