Пример #1
0
        private void MenuItem_NewSpeaker(object sender, RoutedEventArgs e)
        {
            Speaker sp;

            if (_speakerProvider.IsOnline)
            {
                sp = new ApiSynchronizedSpeaker("-----", "-----", Speaker.Sexes.X)
                {
                    IsSaved      = false,
                    DataBaseType = DBType.Api,
                }
            }
            ;
            else
            {
                sp = new Speaker("-----", "-----", Speaker.Sexes.X, null)
                {
                    DataBaseType = DBType.User
                }
            };;

            NewSpeaker = sp;

            SpeakerProvider.AddTempSpeaker(sp);

            var ss = SpeakerProvider.GetContainerForSpeaker(sp);

            SpeakersBox.SelectedValue = ss;
            ss.New     = true;
            ss.Changed = true;
            SpeakersBox.ScrollIntoView(SpeakersBox.SelectedItem);
        }
Пример #2
0
        private async Task <bool> TrySaveSpeaker(SpeakerContainer spk)
        {
            if (NewSpeaker == spk.Speaker)
            {
                if (await TestName(spk))
                {
                    bool reselect = spk == SpeakersBox.SelectedItem;
                    using (SpeakerProvider.DeferRefresh())
                    {
                        spk.ApplyChanges();
                        SpeakerProvider.DeleteSpeaker(spk.Speaker);
                        if (spk.IsOnline)
                        {
                            SpeakerProvider.AddOnlineSpeaker((ApiSynchronizedSpeaker)spk.Speaker);
                        }
                        else
                        {
                            SpeakerProvider.AddLocalSpeaker(spk.Speaker);
                        }

                        NewSpeaker = null;
                    }
                    if (reselect)
                    {
                        var ss = SpeakerProvider.GetContainerForSpeaker(spk.Speaker);
                        SpeakersBox.SelectedValue = ss;
                    }
                }
                else
                {
                    return(false); //do not apply or save - name is invalid
                }
            }

            spk.ApplyChanges();
            if (spk.IsOnline)
            {
                using (var wc = new WaitCursor())
                {
                    ApiSynchronizedSpeaker ss = spk.Speaker as ApiSynchronizedSpeaker;
                    if (ss == null)
                    {
                        return(false);
                    }
                    if (ss.IsSaved)
                    {
                        return(await _transcription.Api.UpdateSpeaker(ss));
                    }
                    else
                    {
                        return(await _transcription.Api.AddSpeaker(ss));
                    }
                }
            }

            return(true);;
        }
        /// <summary>
        /// Find speaker from user (or online) database to speaker from file.
        /// </summary>
        /// <param name="s"></param>
        /// <returns>speaker or null when user (or online) database not contain Speaker that can be automatically synchronized</returns>
        public Speaker SynchronizeSpeaker(Speaker s)
        {
            if (s.DataBaseType == DBType.Api)
            {
                var ss = new ApiSynchronizedSpeaker(s);
                if (_slist.ContainsKey(s.DBID))
                {
                    if (_slist[s.DBID].Synchronized < s.Synchronized)
                    {
                        _slist[s.DBID] = s;
                    }
                }
                else
                {
                    _slist[s.DBID] = s;
                }

                return(ss);
            }
            else if (s.DataBaseType == DBType.User && s.DBID != null)//some user created it manually
            {
                Speaker ls;

                if (_slist.TryGetValue(s.DBID, out ls))
                {
                    if (_slist[s.DBID].Synchronized < s.Synchronized)
                    {
                        this._Speakers.Remove(_slist[s.DBID]);
                        ls = _slist[s.DBID] = s;
                        this._Speakers.Add(ls);
                    }

                    return(ls);
                }
                else
                {
                    _slist[s.DBID] = s;
                }
            }

            return(null);//old format or export from some tool do not synchronize automatically
        }
Пример #4
0
        /// <summary>
        /// Find speaker from user (or online) database to speaker from file.
        /// </summary>
        /// <param name="s"></param>
        /// <returns>speaker or null when user (or online) database not contain Speaker that can be automatically synchronized</returns>
        public Speaker SynchronizeSpeaker(Speaker s)
        {
            if (s.DataBaseType == DBType.Api)
            {
                var ss = new ApiSynchronizedSpeaker(s);
                if (_slist.ContainsKey(s.DBID))
                {
                    if (_slist[s.DBID].Synchronized < s.Synchronized)
                        _slist[s.DBID] = s;
                }
                else
                    _slist[s.DBID] = s;

                return ss;
            }
            else if (s.DataBaseType == DBType.User && s.DBID != null)//some user created it manually
            {
                Speaker ls;

                if (_slist.TryGetValue(s.DBID, out ls))
                {

                    if (_slist[s.DBID].Synchronized < s.Synchronized)
                    {
                        this._Speakers.Remove(_slist[s.DBID]);
                        ls = _slist[s.DBID] = s;
                        this._Speakers.Add(ls);
                    }

                    return ls;
                }
                else
                    _slist[s.DBID] = s;
            }

            return null;//old format or export from some tool do not synchronize automatically
        }
Пример #5
0
 internal void AddOnlineSpeaker(ApiSynchronizedSpeaker sp)
 {
     _online.Add(sp);
     _allSpeakers.Add(new SpeakerContainer(_document, sp));
     Refresh();
 }
Пример #6
0
        private void MenuItem_NewSpeaker(object sender, RoutedEventArgs e)
        {

            Speaker sp;

            if (_speakerProvider.IsOnline)
                sp = new ApiSynchronizedSpeaker("-----", "-----", Speaker.Sexes.X)
                {
                    IsSaved = false,
                    DataBaseType = DBType.Api,
                };
            else
                sp = new Speaker("-----", "-----", Speaker.Sexes.X, null) { DataBaseType = DBType.User }; ;

            NewSpeaker = sp;

            SpeakerProvider.AddTempSpeaker(sp);

            var ss = SpeakerProvider.GetContainerForSpeaker(sp);

            SpeakersBox.SelectedValue = ss;
            ss.New = true;
            ss.Changed = true;
            SpeakersBox.ScrollIntoView(SpeakersBox.SelectedItem);
        }