void TranslatingAllWords()
        {

            ProgressBar_Model pb = new ProgressBar_Model();
            pb.Text = Tx.T("SubtitleEditor.Messages.Processing.TranslatingWordsOfDictionary");
            pb.Minimum = 0;
            pb.Maximum = Subtitles.Items.Count;
            pb.Value = pb.Minimum;

            App.AddLongTaskProgressBar(pb);

            int cnt = 0;
            string errors = "";
            foreach (SubtitleItem item in Subtitles.Items)
            {
                TranslationAllWordsInSubtitleItem(item, errors);

                pb.Value = ++cnt;
                if (pb.IsCanceled) break;
            }
            if(errors != "")
            {
                DialogService.Message(Tx.T("SubtitleEditor.Messages.TranslateAllWordsError")+Environment.NewLine+errors);
            }
            App.RemoveLongTaskProgressBar(pb);

        }
        public override async void CmdDispatcher(string command)
        {
            string filename;

            switch (command)
            {
                case "AddVideoFile":
                    AddVideoFile_Cmd();
                    break;

                case "AddCover":
                    AddCover_Cmd();
                    break;

                case "Save":
                case "SaveAndClose":
                    //Save();
                    if(command=="SaveAndClose") NavigationService.NavigateBack();
                    break;

                case "Backup":
                    //Save();
                    NavigationService.NavigateForward(Views.Backup,new Backup_parameters() {mode = Backup_parameters.Mode.LearningItem,learningitem = LearningItem});
                    break;

                case "Cancel":
                    //Save();
                    NavigationService.NavigateBack();
                    break;

                case "OpenMainSetting":
                    NavigationService.NavigateForward(Views.AppSettings,new AppSettings_parameters());
                    break;

                case "DownloadYoutubeVideo":
                    DownloadVideoButton.IsEnabled = false;
                    var VideoInfos = YoutubeDownloader.GetVideoInfo(LearningItem.YoutubeURL);
                    if(VideoInfos.Count == 0)
                    {
                        await DialogService.Message(Tx.T("EditLearningItem.Messages.CantGetYoutubeVideoInfo"));
                        DownloadVideoButton.IsEnabled = true;
                        return;
                    }
                    VideoInfo vinf = VideoInfos.OrderByDescending(x => x.Resolution).FirstOrDefault();
                    if(vinf == null)
                    {
                        await DialogService.Message("Cannot found youtube video info");
                        return;
                    }
                    YoutubeDownloader.Info inf = YoutubeDownloader.GetInfo(vinf);
                    LearningItem.VideoFileName = Path.Combine(FileService.GetPathToLearningItem(LearningItem), inf.VideoFileName);

                    await Task.Run(() =>
                    {
                        ProgressBar_Model pb = null;
                        try
                        {
                            pb = new ProgressBar_Model();
                            App.AddLongTaskProgressBar(pb);
                            YoutubeDownloader.Download(VideoInfos, vinf, FileService.GetPathToLearningItem(LearningItem),pb);
                        }
                        catch(Exception ex)
                        {
                            Dispatcher.RequestMainThreadAction(new Action(() => NavigationService.OpenDialog(Views.ExceptionForm, new ExceptionForm_parameters { ex = ex, title = Tx.T("EditLearningItem.Messages.CantGetYoutubeVideo") })));
                        }
                        finally
                        {
                            App.RemoveLongTaskProgressBar(pb);
                        }
                    }
                        
                        
                    );
                    if (inf.isExternalAudio)
                    {
                        if(LearningItem.AudioTracks.Count == 0)
                        {
                            AudioTrack at = new AudioTrack();
                            at.isExternal = true;
                            at.ExternalFile = Path.GetFileName(inf.AudioFileName);
                            LearningItem.AudioTracks.Add(at);
                        }
                    }
                    if (string.IsNullOrEmpty(LearningItem.Name)) LearningItem.Name = vinf.Title;
                    EFDbContext.SaveChgs();
                    if (LearningItem.AudioTrack == null && LearningItem.AudioTracks.Count > 0) LearningItem.AudioTrack = LearningItem.AudioTracks[0];
                    EFDbContext.SaveChgs();
                    DownloadVideoButton.IsEnabled = true;
                    break;
                    /*
                case "EditSubtitles":
                    Player.Pause();
                    NavigationService.NavigateForward(ViewModelLocator.SubtitleEditor,new SubtitleEditor_parameters() { LearningItem = LearningItem });
                    break;
                    */

                case "ExportToFile":
                case "ExportToFileWithoutPrivateData":
                    filename = DialogService.SaveFile("xml (*.xml)|*.xml");
                    if (filename == null) return;
                    //SQL_XML_Operations.SaveLearningItem(filename,LearningItem,!(command=="ExportToFileWithoutPrivateData"));
                    //if (res != SQL_XML_IO_statuses.Ok) await DialogService.Message(Tx.T("EditLearningItem.Messages.UnknownSaveError"));
                    break;

                case "LoadFromFile":
                    filename = DialogService.OpenFile("","xml (*.xml)|*.xml");
                    Guid guid;
                   // SQL_XML_Operations.LoadLearningItem(filename,out guid);
                   /*
                    if (res != SQL_XML_IO_statuses.Ok)
                    {
                        switch (res)
                        {
                            case SQL_XML_IO_statuses.GUIDdoestMatches:
                                await DialogService.Message(Tx.T("EditLearningItem.Messages.GuidDoesntMatches"));
                                break;
                            default:
                                throw new NotImplementedException();
                        }
                    }
                    */
                    break;

                case "AddExternalSubtitles":
                    filename = DialogService.OpenFile("", "srt (*.srt)|*.srt");
                    if (filename == null) return;

                    Subtitles sub = SRTparser.LoadSRTfile(filename);
                    LearningItem.SubtitleCollection.Add(sub);
                    //Save();
                    break;

                case "Publish":
                    NavigationService.OpenDialog(Views.Publish,new Publish_parameters { LearningItem = LearningItem });                   
                    break;

                case "Pause":
                    if (Player.IsPlaying)
                    {
                        Player.Pause();
                    }
                    else
                    {
                        Player.Play();
                    }
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
        void ApplyAllRules()
        {

            ProgressBar_Model pb = new ProgressBar_Model();
            pb.Text = Tx.T("SubtitleEditor.Messages.Processing.ApplyAllRules");
            pb.Minimum = 0;
            pb.Maximum = Subtitles.PrimaryLanguage.ProcessingWordsRules.Count;
            pb.Value = pb.Minimum;

            App.AddLongTaskProgressBar(pb);

            int cnt = 0;
            foreach (ProcessingWordsRules item in Subtitles.PrimaryLanguage.ProcessingWordsRules)
            {
                ApplyRuleToAll(item);

                pb.Value = ++cnt;
                if (pb.IsCanceled) break;

            }
            App.RemoveLongTaskProgressBar(pb);
        }
        void TranslateAllSubtitles()
        {
            ProgressBar_Model pb = new ProgressBar_Model
            {
                Text = Tx.T("SubtitleEditor.Messages.Processing.TranslateAllSubtitles"),
                Minimum = 0,
                Maximum = Subtitles.PrimaryLanguage.ProcessingWordsRules.Count
            };
            pb.Value = pb.Minimum;

            App.AddLongTaskProgressBar(pb);

            int cnt = 0;
            foreach (SubtitleItem elm in Subtitles.Items)
            {
                TranslateSubtitles(elm);

                pb.Value = ++cnt;
                if (pb.IsCanceled) break;
            }

            App.RemoveLongTaskProgressBar(pb);
        }
        void DeleteWords()
        {
            ProgressBar_Model pb = new ProgressBar_Model();
            pb.Text = Tx.T("SubtitleEditor.Messages.Processing.DeleteWords");
            pb.IsIndeterminate = false;
            pb.Maximum = Subtitles.Items.Count();
            pb.Minimum = 0;

            App.AddLongTaskProgressBar(pb);

            foreach(SubtitleItem item in Subtitles.Items)
            {
                if (item.WordsCollection == null) continue;
                EFDbContext.Context.DeleteRange(item.WordsCollection);
                pb.Value++;
                if (pb.IsCanceled) break;
            }
            //List<WordOfSubtitleItem> delete = Subtitles.Items.Where(item => item.WordsCollection != null).SelectMany(item => item.WordsCollection).Distinct().ToList();
            //EFDbContext.Context.DeleteRange<WordOfSubtitleItem>(delete);

            App.RemoveLongTaskProgressBar(pb);
        }
        void SplitOnWords()
        {

            ProgressBar_Model pb = new ProgressBar_Model();
            pb.Text = Tx.T("SubtitleEditor.Messages.Processing.SplitOnWords");
            pb.Minimum = 0;
            pb.Maximum = Subtitles.Items.Count;
            pb.Value = pb.Minimum;

            App.AddLongTaskProgressBar(pb);
            int cnt = 0;

            Subtitles.IsThereDictionary = true;

            // create a new words
            int loccnt = 0;
            foreach (SubtitleItem item in Subtitles.Items.OrderBy(x=>x.TimeStart))
            {
                SplitPhraseOnWords(item); 

                pb.Value = ++cnt;
                if (pb.IsCanceled) break;

                loccnt++;
                if (loccnt == 25)
                {
                    EFDbContext.SaveChgs();
                    loccnt = 0;
                }

            }

            EFDbContext.SaveChgs();
            App.RemoveLongTaskProgressBar(pb);
            
        }
        async Task CheckUpdate()
        {
            try
            {
                Variables vrb = MainWebAPI.GetVariables(AppSettings.id.guid.ToString()).Result;
                Version actualver = new Version(vrb.CurrentVersionWPFApplication);
                Version curver = Assembly.GetExecutingAssembly().GetName().Version; 
                if (actualver > curver)
                {
                    bool res = false;
                    res = await DialogService.Ask(string.Format(Tx.T("Common.Phrases.Update"), new string[] { actualver.ToString(), curver.ToString() }));
                    if (res)
                    {

                        ProgressBar_Model pb = new ProgressBar_Model {IsIndeterminate = false,Minimum=0,Maximum=100,Value=0};
                        pb.Text = string.Format(Tx.T("Common.Phrases.Update.Download"), actualver);
                        //pb.Title = string.Format(Tx.T("Common.Phrases.Update.Download"), actualver);
                        App.AddLongTaskProgressBar(pb);

                        WebClient wc = new WebClient();

                        wc.DownloadProgressChanged += (object sender, System.Net.DownloadProgressChangedEventArgs e)=>
                            Dispatcher.RequestMainThreadAction(new Action(() =>pb.Value = e.ProgressPercentage));

                        string filename = Path.Combine(Path.GetTempPath(), Constants.Files.SetupFileName);
                        string url = UriHelper.Combine(new string[] {Constants.Store.StoreAddress,Constants.Store.StoreLearningItemPath,Constants.Files.SetupFileName });

                        tmpsetupfile = filename;

                        wc.DownloadFileCompleted += Wc_DownloadFileCompleted;    
                        wc.DownloadFileAsync(new Uri(url), filename);
                    
                    }
                }
            }
            catch (Exception ex)
            {
                logger.WriteExeption(this, ex, "CheckUpdate is failed");
            }
        }