Exemple #1
0
        public SpeakersManager(Speaker originalSpeaker, WPFTranscription transcription, SpeakerCollection documentSpeakers, SpeakerCollection localSpeakers = null)
        {
            DataContext       = this;//not good :)
            _originalSpeaker  = originalSpeaker;
            _localSpeakers    = localSpeakers;
            _documentSpeakers = documentSpeakers;
            _transcription    = transcription;

            InitializeComponent();
            SpeakerProvider = new SpeakerManagerViewModel(new SpeakerCollection(documentSpeakers.Concat(transcription.EnumerateParagraphs().Select(p => p.Speaker)).Where(s => s != Speaker.DefaultSpeaker).Distinct()), localSpeakers, transcription.Api, this);

            var ss = SpeakerProvider.GetContainerForSpeaker(originalSpeaker);

            if (ss != null)
            {
                ss.Marked = true;
            }
            SpeakersBox.SelectedValue = ss;
            SpeakersBox.ScrollIntoView(SpeakersBox.SelectedItem);

            if (_transcription.Api != null)
            {
                SpeakerProvider.ShowLocal  = false;
                SpeakerProvider.ShowOnline = true;
            }
            //SpeakersBox.Items.SortDescriptions.Add( new SortDescription("",ListSortDirection.Ascending));
        }
Exemple #2
0
        new public static WPFTranscription Deserialize(string path)
        {
            WPFTranscription t;

            using (var s = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                t = WPFTranscription.Deserialize(s);
            t.FileName = path;
            return(t);
        }
Exemple #3
0
        public SpeakerSynchronizer(WPFTranscription Transcription, AdvancedSpeakerCollection SpeakersDatabase)
            : this()
        {
            this._transcription    = Transcription;
            this._speakersDatabase = SpeakersDatabase;


            _pairs = _transcription.Speakers
                     .OrderBy(s => s.Surname)
                     .ThenBy(s => s.FirstName)
                     .ThenBy(s => s.MiddleName)
                     .Select(s => new SpeakerPair {
                Speaker1 = new SpeakerContainer(s)
            })
                     .ToList();

            //Join speakers from document with speakers from localDB by fullname and order pairs
            var first = _pairs
                        .Join(_speakersDatabase, p => p.Speaker1.Speaker.FullName.ToLower(), s => s.FullName.ToLower(), (sp, s) => new { document = sp, local = s })
                        .GroupBy(s => s.document)
                        .Select(g => g.First())
                        .OrderBy(s => s.local.Surname)
                        .ThenBy(s => s.local.FirstName)
                        .ThenBy(s => s.local.MiddleName);

            //get all speakers from local DB that was not joined
            var other = _speakersDatabase.Except(first.Select(s => s.local).ToArray())
                        .OrderBy(s => s.Surname)
                        .ThenBy(s => s.FirstName)
                        .ThenBy(s => s.MiddleName);

            //concat all speakers from local DB but ordered to match remaining speakers in document.
            listlocal.ItemsSource = first.Select(s => s.local).Concat(other).ToList();


            //add pairs with order matching to listlocal and concat speakers without matching name in local DB
            listdocument.ItemsSource = _pairs = first.Select(s => s.document)
                                                .OrderBy(s => s.Speaker1.SurName)
                                                .ThenBy(s => s.Speaker1.FirstName)
                                                .ThenBy(s => s.Speaker1.MiddleName)
                                                .Concat(_pairs.Except(first.Select(s => s.document))).ToList();
        }
Exemple #4
0
        public SpeakersManager(Speaker originalSpeaker, WPFTranscription transcription, SpeakerCollection documentSpeakers, SpeakerCollection localSpeakers = null)
        {
            DataContext = this;//not good :)
            _originalSpeaker = originalSpeaker;
            _localSpeakers = localSpeakers;
            _documentSpeakers = documentSpeakers;
            _transcription = transcription;

            InitializeComponent();
            SpeakerProvider = new SpeakerManagerViewModel(documentSpeakers, localSpeakers, transcription.Api,this);
            var ss = SpeakerProvider.GetContainerForSpeaker(originalSpeaker);
            if (ss != null)
                ss.Marked = true;
            SpeakersBox.SelectedValue = ss;
            SpeakersBox.ScrollIntoView(SpeakersBox.SelectedItem);

            if (_transcription.Api != null)
            {
                SpeakerProvider.ShowLocal = false;
                SpeakerProvider.ShowOnline = true;
            }
            //SpeakersBox.Items.SortDescriptions.Add( new SortDescription("",ListSortDirection.Ascending));
        }
Exemple #5
0
        public static new WPFTranscription Deserialize(Stream stream)
        {
            //on some remote data storage this can be more effective than lot of small direct reads by XMLTextReader
            #region copy stream to internal buffer

            byte[] bfr = new byte[32*1024];
            int read = 0;

            int initsize = 500*1024;
            MemoryStream bufferStream;
            try
            {
                initsize = (int)stream.Length;
            }finally
            {
                bufferStream = new MemoryStream(initsize);
            }

            while((read = stream.Read(bfr,0,bfr.Length)) > 0)
                bufferStream.Write(bfr,0,read);
            #endregion

            #if DEBUG
            #region validation
            bufferStream.Seek(0, SeekOrigin.Begin);
            XmlSchemaSet schemas = new XmlSchemaSet();
            XNamespace xNamespace = XNamespace.Get("http://www.ite.tul.cz/TRSXSchema3.xsd");
            using (var s = File.Open(FilePaths.TrsxSchemaPath,FileMode.Open,FileAccess.Read,FileShare.Read))
                schemas.Add(null, XmlReader.Create(s));

            XDocument doc = XDocument.Load(bufferStream);

            foreach (XElement xElement in doc.Descendants())
            {
                // First make sure that the xmlns-attribute is changed
                xElement.SetAttributeValue("xmlns", xNamespace.NamespaceName);
                // Then also prefix the name of the element with the namespace
                xElement.Name = xNamespace + xElement.Name.LocalName;
            }

            doc.Validate(schemas, (o,e) =>
            {
                System.Diagnostics.Debug.WriteLine(string.Format("{0}", e.Message));
            });

            //restore stream position
            bufferStream.Seek(0, SeekOrigin.Begin);
            #endregion
            #endif

            var t = new WPFTranscription();
            Transcription.Deserialize(bufferStream, t);
            t.IsOnline = t.Elements.ContainsKey("Online") && t.Elements["Online"] == "True";
            t.ClearUndo();
            return t;
        }
Exemple #6
0
        new public static WPFTranscription Deserialize(Stream stream)
        {
            //on some remote data storage this can be more effective than lot of small direct reads by XMLTextReader
            #region copy stream to internal buffer

            byte[] bfr  = new byte[32 * 1024];
            int    read = 0;

            int          initsize = 500 * 1024;
            MemoryStream bufferStream;
            try
            {
                initsize = (int)stream.Length;
            }finally
            {
                bufferStream = new MemoryStream(initsize);
            }

            while ((read = stream.Read(bfr, 0, bfr.Length)) > 0)
            {
                bufferStream.Write(bfr, 0, read);
            }

            bufferStream.Seek(0, SeekOrigin.Begin);

            #endregion

#if DEBUG
            #region validation

            XmlSchemaSet schemas    = new XmlSchemaSet();
            XNamespace   xNamespace = XNamespace.Get("http://www.ite.tul.cz/TRSXSchema3.xsd");
            using (var s = File.Open(FilePaths.TrsxSchemaPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                schemas.Add(null, XmlReader.Create(s));

            XDocument doc = XDocument.Load(bufferStream);

            foreach (XElement xElement in doc.Descendants())
            {
                // First make sure that the xmlns-attribute is changed
                xElement.SetAttributeValue("xmlns", xNamespace.NamespaceName);
                // Then also prefix the name of the element with the namespace
                xElement.Name = xNamespace + xElement.Name.LocalName;
            }


            doc.Validate(schemas, (o, e) =>
            {
                System.Diagnostics.Debug.WriteLine(string.Format("{0}", e.Message));
            });

            //restore stream position
            bufferStream.Seek(0, SeekOrigin.Begin);
            #endregion
#endif

            var t = new WPFTranscription();
            t.BeginUpdate();
            Transcription.Deserialize(bufferStream, t);
            t.IsOnline = t.Elements.ContainsKey("Online") && t.Elements["Online"] == "True";
            t.EndUpdate();
            t.ClearUndo();
            t.Saved = true;
            return(t);
        }
Exemple #7
0
        public WPFTranscription ExecuteImport(string sourcefile = null)
        {
            if (sourcefile == null)
            {
                OpenFileDialog opf = new OpenFileDialog();
                opf.CheckFileExists = true;
                opf.CheckPathExists = true;
                opf.Filter = _mask;

                if (opf.ShowDialog() == true)
                    sourcefile = opf.FileName;
            }

            if (File.Exists(sourcefile))
            {
                try
                {
                    if (Isassembly)
                    {
                        using (var f = File.OpenRead(sourcefile))
                        {
                            var imp = new WPFTranscription();
                            if (!_importDelegate.Invoke(f, imp))
                                throw new Exception();

                            imp.FileName = sourcefile;

                            return imp;
                        }
                    }
                    else
                    {
                        string inputfile = sourcefile;
                        string tempFolder = FilePaths.TempDirectory;
                        string tempFile = System.IO.Path.Combine(tempFolder, System.IO.Path.GetRandomFileName()) + ".trsx";

                        ProcessStartInfo psi = new ProcessStartInfo();
                        psi.FileName = Path.Combine(FilePaths.GetReadPath(FilePaths.PluginsPath), _fileName);
                        psi.Arguments = string.Format(_parameters, "\"" + inputfile + "\"", "\"" + tempFile + "\"", "\"" + tempFolder + "\"");

                        Process p = new Process();
                        p.StartInfo = psi;

                        p.Start();
                        p.WaitForExit();

                        var data = WPFTranscription.Deserialize(tempFile);
                        return data;

                    }
                }
                catch
                {
                    MessageBox.Show(Properties.Strings.MessageBoxImportError, Properties.Strings.MessageBoxErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            return null;
        }
Exemple #8
0
        private void LoadTranscription(WPFTranscription trans)
        {
            Transcription = trans;
            Transcription.Saved = true;

            TryLoadAudioFile();
            TryLoadVideoFile();
            InitWindowAfterTranscriptionLoad();
        }
Exemple #9
0
        public async Task OpenTranscription(bool useOpenDialog, string fileName, bool listing = false)
        {
            try
            {
                if (!await TrySaveUnsavedChanges())
                    return;//cancel


                if (Transcription == null)
                    Transcription = new WPFTranscription();

                bool loadedsucessfuly = false;

                if (listing)
                {
                    loadedsucessfuly = TryLoadTranscription(fileName, listing);
                }
                else if (useOpenDialog)
                {
                    Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();

                    fileDialog.Title = Properties.Strings.FileDialogLoadTranscriptionTitle;
                    fileDialog.Filter = Properties.Strings.FileDialogLoadTranscriptionFilter;
                    fileDialog.RestoreDirectory = true;

                    if (fileDialog.ShowDialog() == true)
                    {
                        loadedsucessfuly = TryLoadTranscription(fileDialog.FileName);
                    }
                    else
                    {
                        return; //cancel loading
                    }
                }
                else
                {
                    loadedsucessfuly = TryLoadTranscription(fileName);
                }

                waveform1.CaretPosition = TimeSpan.Zero;

                if (!loadedsucessfuly)
                {
                    MessageBox.Show(Properties.Strings.MessageBoxCannotLoadTranscription, Properties.Strings.MessageBoxCannotLoadTranscription, MessageBoxButton.OK, MessageBoxImage.Information);
                    await NewTranscription();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(Properties.Strings.MessageBoxOpenTranscriptionError + ex.Message + ":" + fileName, Properties.Strings.MessageBoxErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #10
0
        public async Task<bool> NewTranscription()
        {
            if (!await TrySaveUnsavedChanges())
                return false;

            var source = new WPFTranscription();
            source.BeginUpdate(false);
            var c = new TranscriptionChapter(Properties.Strings.DefaultChapterText);
            var s = new TranscriptionSection(Properties.Strings.DefaultSectionText);
            var p = new TranscriptionParagraph();
            p.Add(new TranscriptionPhrase());
            c.Add(s);
            s.Add(p);
            source.Add(c);
            Transcription = source;
            SynchronizeSpeakers();
            VirtualizingListBox.ActiveTransctiption = p;

            TranscriptionList.Clear();
            source.ClearUndo();
            source.EndUpdate();

            Transcription.Saved = true;
            return true;
        }
 public static void OnSubtitlesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     WPFTranscription data = (WPFTranscription)e.NewValue;
     SubtitlesVizualizer vis = (SubtitlesVizualizer)d;
     WPFTranscription olddata = e.OldValue as WPFTranscription;
 }
Exemple #12
0
        private WPFTranscription ImportTranscription(string filepath = null)
        {
            string[] masks     = _ImportPlugins.Select(p => p.Mask).ToArray();
            string[] filetypes = masks.SelectMany(m => m.Split('|').Where((p, i) => i % 2 == 1).SelectMany(ex => ex.Split(';'))).Distinct().ToArray();

            string         allfilesMask = string.Format(Properties.Strings.FileDialogLoadImportFilter, string.Join(";", filetypes));
            OpenFileDialog opf          = new OpenFileDialog();

            opf.CheckFileExists = true;
            opf.CheckPathExists = true;
            opf.Filter          = string.Join("|", new[] { allfilesMask }.Concat(masks));
            opf.Title           = Properties.Strings.FileDialogLoadImportTitle;
            bool filedialogopened = false;

            if (filepath != null)
            {
                opf.FilterIndex  = 1;
                filedialogopened = true;
                opf.FileName     = filepath;
            }
            else
            {
                filedialogopened = opf.ShowDialog() == true;
            }

            WPFTranscription trans = null;

            if (filedialogopened)
            {
                if (opf.FilterIndex == 1) //all files
                {
                    var plugins = _ImportPlugins.Where(
                        p => p.Mask.Split('|')
                        .Where((s, i) => i % 2 == 1)
                        .Any(s => Regex.IsMatch(System.IO.Path.GetExtension(opf.FileName), string.Join("|", s.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(r => r.Replace("*", "").Replace(".", "\\.").Replace('?', '.') + "$"))))).ToArray();

                    if (plugins.Length != 1)
                    {
                        PickOneDialog pd = new PickOneDialog(plugins.Select(p => p.Name).ToList(), Properties.Strings.ImportSelectImportPlugin);
                        if (pd.ShowDialog() == true)
                        {
                            trans = plugins[pd.SelectedIndex].ExecuteImport(opf.FileName);
                        }
                    }
                    else
                    {
                        trans = plugins[0].ExecuteImport(opf.FileName);
                    }
                }
                else
                {
                    trans = _ImportPlugins[opf.FilterIndex - 2].ExecuteImport(opf.FileName);
                }

                if (trans != null)
                {
                    trans.FileName += ".trsx";
                }
            }

            return(trans);
        }
Exemple #13
0
        private void LoadSubtitlesData(WPFTranscription data)
        {
            if (data == null)
                return;
            Transcription = data;
            //load audio if possible
            if (!string.IsNullOrEmpty(Transcription.MediaURI))
            {
                FileInfo fiA = new FileInfo(Transcription.MediaURI);
                string pAudioFile = null;
                if (fiA.Exists)
                {
                    pAudioFile = fiA.FullName;
                }
                else if (System.IO.Path.IsPathRooted(Transcription.MediaURI))
                {
                    tbAudioFile.Text = Transcription.MediaURI;
                }
                else
                {
                    FileInfo fi = new FileInfo(Transcription.FileName);
                    pAudioFile = fi.Directory.FullName + "\\" + Transcription.MediaURI;
                }

                if (pAudioFile != null && pAudioFile.Split(new string[] { ":\\" }, StringSplitOptions.None).Length == 2)
                {
                    FileInfo fi2 = new FileInfo(pAudioFile);
                    if (fi2.Exists)
                    {
                        LoadAudio(pAudioFile);
                    }
                    else
                    {
                        tbAudioFile.Text = Transcription.MediaURI;
                    }
                }
            }

            this.Title = Const.APP_NAME + " [" + data.FileName + "]";


        }
Exemple #14
0
        public WPFTranscription ExecuteImport(string sourcefile = null)
        {
            if (sourcefile == null)
            {
                OpenFileDialog opf = new OpenFileDialog();
                opf.CheckFileExists = true;
                opf.CheckPathExists = true;
                opf.Filter          = _mask;

                if (opf.ShowDialog() == true)
                {
                    sourcefile = opf.FileName;
                }
            }

            if (File.Exists(sourcefile))
            {
                try
                {
                    if (Isassembly)
                    {
                        using (var f = File.OpenRead(sourcefile))
                        {
                            var imp = new WPFTranscription();
                            if (!_importDelegate.Invoke(f, imp))
                            {
                                throw new Exception();
                            }

                            imp.FileName = sourcefile;

                            return(imp);
                        }
                    }
                    else
                    {
                        string inputfile  = sourcefile;
                        string tempFolder = FilePaths.TempDirectory;
                        string tempFile   = System.IO.Path.Combine(tempFolder, System.IO.Path.GetRandomFileName()) + ".trsx";


                        ProcessStartInfo psi = new ProcessStartInfo();
                        psi.FileName  = Path.Combine(FilePaths.GetReadPath(FilePaths.PluginsPath), _fileName);
                        psi.Arguments = string.Format(_parameters, "\"" + inputfile + "\"", "\"" + tempFile + "\"", "\"" + tempFolder + "\"");

                        Process p = new Process();
                        p.StartInfo = psi;

                        p.Start();
                        p.WaitForExit();

                        var data = WPFTranscription.Deserialize(tempFile);
                        return(data);
                    }
                }
                catch
                {
                    MessageBox.Show(Properties.Strings.MessageBoxImportError, Properties.Strings.MessageBoxErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            return(null);
        }
Exemple #15
0
        public SpeakerSynchronizer(WPFTranscription Transcription, AdvancedSpeakerCollection SpeakersDatabase)
            : this()
        {
            this._transcription = Transcription;
            this._speakersDatabase = SpeakersDatabase;

            _pairs = _transcription.Speakers
                .OrderBy(s => s.Surname)
                .ThenBy(s => s.FirstName)
                .ThenBy(s => s.MiddleName)
                .Select(s => new SpeakerPair { Speaker1 = new SpeakerContainer(s) })
                .ToList();

            //Join speakers from document with speakers from localDB by fullname and order pairs
            var first = _pairs.Join(_speakersDatabase, p => p.Speaker1.Speaker.FullName.ToLower(), s => s.FullName.ToLower(), (sp, s) => new { document = sp, local = s })
                .Distinct()
                .OrderBy(s => s.local.Surname)
                .ThenBy(s => s.local.FirstName)
                .ThenBy(s => s.local.MiddleName);

            //get all speakers from local DB that was not joined
            var other = _speakersDatabase.Except(first.Select(s => s.local).ToArray())
                .OrderBy(s => s.Surname)
                .ThenBy(s => s.FirstName)
                .ThenBy(s => s.MiddleName);

            //concat all speakers from local DB but ordered to match remaining speakers in document.
            listlocal.ItemsSource = first.Select(s => s.local).Concat(other).ToList();

            //add pairs with order matching to listlocal and concat speakers without matching name in local DB
            listdocument.ItemsSource = _pairs = first.Select(s => s.document)
                                                        .OrderBy(s => s.Speaker1.SurName)
                                                        .ThenBy(s => s.Speaker1.FirstName)
                                                        .ThenBy(s => s.Speaker1.MiddleName)
                                                        .Concat(_pairs.Except(first.Select(s => s.document))).ToList();
        }