public AppSettingEdit_ViewModel_WPF(
            ILogger Logger_, 
            INavigationService NavigationService_, 
            IDialogService DialogService_,
            EFDbConnect EFDbConnect_)
        {

            if (!IsInDesignModeNet())
            {
                Logger = Logger_;
                NavigationService = NavigationService_;
                DialogService = DialogService_;
                EFDbConnect = EFDbConnect_;

                Languages = new ObservableCollection<Language>(EFDbConnect.Table<Language>().ToList()); 
                LearningWordStrategies = new ObservableCollection<LearningWordStrategy>(EFDbConnect.Table<LearningWordStrategy>().ToList());

                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);
            }

            if (IsInDesignModeNet())
            {
                Languages = new ObservableCollection<Language>();
                Languages.Add(new Language() {Code="en",Name="English"});
                Languages.Add(new Language() {Code="ru",Name="Русский"});
                Languages.Add(new Language() {Code="ua",Name="Українська мова"});

                Languages[0].DictionariesCollection.Add(new Dictionary {Name="First dictionary" });
                Languages[0].DictionariesCollection.Add(new Dictionary {Name="Ordinary dict" });
                Languages[0].DictionariesCollection.Add(new Dictionary {Name="My dictionary" });

                CurrentLanguage = Languages[0];
            }

        }
        public void ExportImportTest()
        {
            EFDbConnect EFDbConnectDemoBase = CreateDemoBase("Save_test.db");

            ILogger ILoggerMock = Mock.Of<ILogger>();

            // Export
            DiskOperation ExportIO = new DiskOperation(ILoggerMock,new SQLitePlatformWin32(),EFDbConnectDemoBase);
            string exportpath = PathToDb("export.db");
            ExportIO.ExportLearningItem(exportpath, EFDbConnectDemoBase.Table<LearningItem>().Where(x=>x.Name == "First").First().id , false);

            EFDbConnect dbConnect = new EFDbConnect(new SQLitePlatformWin32(), exportpath,false);
            QuantityTest(dbConnect);
            dbConnect.Close();
            EFDbConnectDemoBase.Close();

            // Import to empty db
            EFDbConnect DestConnect = RecreateDB("dest.db");
            DiskOperation ImportIO = new DiskOperation(ILoggerMock,new SQLitePlatformWin32(),DestConnect);
            ImportIO.ImportLearningItem(exportpath, false);
            QuantityTest(DestConnect);

            // Update
            DestConnect.Delete(DestConnect.Table<Subtitles>().First());
            DestConnect.Delete(DestConnect.Table<AudioTrack>().First());
            DestConnect.Delete(DestConnect.Table<TranslationOfWord>().First());
            Assert.IsTrue(DestConnect.Table<Subtitles>().Count() == 1);
            Assert.IsTrue(DestConnect.Table<AudioTrack>().Count() == 1);
            Assert.IsTrue(DestConnect.Table<TranslationOfWord>().Count() == 1);
            ImportIO.ImportLearningItem(exportpath, false);
            QuantityTest(DestConnect);

            DestConnect.Close();

        }
        public DictionariesList_ViewModel(
            ILogger Logger_, 
            INavigationService NavigationService_, 
            IDialogService DialogService_,
            EFDbConnect EFDbConnect
            ) : base ()
        {
            NavigationService = NavigationService_;

            if (IsInDesignModeNet())
            {
                Dictionaries = new ObservableCollection<Dictionary>();

                Dictionary dic1 = new Dictionary { Name = "First" };
                Dictionaries.Add(dic1);

                Dictionary dic2 = new Dictionary { Name = "Second" };
                Dictionaries.Add(dic2);
            }
            else
            {
                List<Dictionary> dcts = EFDbContext.Context.Query(new QueryBuilder<Dictionary>(EFDbConnect));
                Dictionaries = new ObservableCollection<Dictionary>(dcts);
                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);
                OpenDictionary_Command = new MvxCommand<Dictionary>(OpenDictionary);
            }
        }
Exemple #4
0
        public EFDbContext ConnectToDb(string basename) {
            EFDbConnect con = new  EFDbConnect(new SQLitePlatformWin32(), PathToDb(basename),true);

            MvxSimpleIoCContainer.Initialize();
            Mvx.RegisterSingleton<EFDbConnect>(() => con);

            return new EFDbContext(con);
        }
 public DictionariesList_ViewModel_WPF(
     ILogger Logger_, 
     INavigationService NavigationService_, 
     IDialogService DialogService_,
     EFDbConnect EFDbConnect
     ) : base (Logger_,NavigationService_,DialogService_,EFDbConnect)
 {
 }
 public DictionaryWindow_ViewModel_WPF(
     ILogger Logger_, 
     INavigationService NavigationService_, 
     IDialogService DialogService_,
     IAudioAPI AudioAPI_,
     EFDbConnect EFDbConnect
     ) : base (Logger_,NavigationService_,DialogService_,AudioAPI_,EFDbConnect)
 {
 }
        public EditLearningItem_ViewModel_WPF(
            IDialogServiceExtended DialogService_, 
            IPlayer Player_,
            INavigationService NavigationService_,
            AppSetting AppSetting_,
            EFDbConnect EFDbConnect_)
        {
            
            if (!IsInDesignModeNet())
            {
                DialogService = DialogService_;
                Player = Player_;
                NavigationService = NavigationService_;
                AppSetting = AppSetting_;
                EFDbConnect = EFDbConnect_;

                Languages = new ObservableCollection<Language>(EFDbConnect.Table<Language>().ToList());

                // Commands
                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);

            }

            PlayerVisibility = Visibility.Visible;
            DownloadVideoButton = new ButtonModel();

            if (IsInDesignModeNet())
            {
                LearningItem = new LearningItem();
                LearningItem.Name = "Mazzy in Gondoland";
                
                LearningItem.VideoFileName = "C:\\Users\\Public\\Videos\\Sample Videos\\Mazzy.mkv";

                LearningItem.SubtitleCollection = new SynchronizedObservableCollection<Subtitles>();

                LearningItem.SubtitleCollection.Add(new Subtitles           {
                    Name = "English-Russian"
                });

                LearningItem.SubtitleCollection.Add(new Subtitles
                {
                    Name = "English-Ukraine"
                });

                //CurrentSubtitles = LearningItem.SubtitleCollection[0];
                
            }

           
        }
 bool QuantityTest(EFDbConnect dbConnect)
 {
     Assert.IsTrue(dbConnect.Table<LearningItem>().Count() == 1);
     Assert.IsTrue(dbConnect.Table<Subtitles>().Count() == 2);
     Assert.IsTrue(dbConnect.Table<SubtitleItem>().Count() == 4);
     Assert.IsTrue(dbConnect.Table<WordOfSubtitleItem>().Count() == 2);
     Assert.IsTrue(dbConnect.Table<WordOfDictionary>().Count() == 2);
     Assert.IsTrue(dbConnect.Table<TranslationOfWord>().Count() == 2);
     Assert.IsTrue(dbConnect.Table<Dictionary>().Count() == 1);
     Assert.IsTrue(dbConnect.Table<AudioTrack>().Count() == 2);
     Assert.IsTrue(dbConnect.Table<FrequencyDictionary>().Count() == 1);
     Assert.IsTrue(dbConnect.Table<FrequencyDictionary.Item>().Count() == 2);
     return true;
 }
        public InitialWizard_ViewModel_WPF(
            ILogger Logger_, 
            INavigationService NavigationService_, 
            IDialogServiceExtended DialogService_,
            AppSetting AppSettings_,
            EFDbConnect EFDbConnect_,
            ObservableCollection<Language> languages_
            ) : base ()
        {

            PanelCount = 1;

            if (!IsInDesignMode)
            {
                Logger = Logger_;
                NavigationService = NavigationService_;
                DialogService = DialogService_;
                AppSettings = AppSettings_;
                EFDbConnect = EFDbConnect_;
                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);

                //List<Language> lst = EFDbConnect.Table<Language>().ToList();
                //Languages = new ObservableCollection<Language>(lst);
                Languages = languages_;

                // Default values
                TargetLanguage = Languages.FirstOrDefault(x=>x.Code == "en");
                NativeLanguage = Languages.FirstOrDefault(x=>x.Code == System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag.Substring(0,2).ToLower());

                LearningWordStrategy strat = EFDbContext.Context.FirstOrDefault<LearningWordStrategy>();
                AppSettings.LearningWordStrategy = strat;

            }

            Drives = FileService.GetFixedDrivesList();
            if (Drives.Count > 0)
            {
                DriveForData = Drives.OrderByDescending(x => x.AvailableFreeSpace).FirstOrDefault();
            }

            if (IsInDesignMode)
            {
                SelectedIndex = 2;
                UpdateButtonState();
            }


        }
        public void ExportTest()
        {
            EFDbConnect EFDbConnectDemoBase = CreateDemoBase("Save_test.db");

            ILogger ILoggerMock = Mock.Of<ILogger>();
            DiskOperation diskop = new DiskOperation(ILoggerMock,new SQLitePlatformWin32(),EFDbConnectDemoBase);
            string path = PathToDb("upload.db");
            diskop.ExportLearningItem(path, EFDbConnectDemoBase.Table<LearningItem>().Where(x=>x.Name == "First").First().id , true);

            EFDbConnect dbConnect = new EFDbConnect(new SQLitePlatformWin32(), path,false);

            Assert.IsTrue(dbConnect.Table<LearningItem>().Count() == 1);
            Assert.IsTrue(dbConnect.Table<Subtitles>().Count() == 2);
            Assert.IsTrue(dbConnect.Table<SubtitleItem>().Count() == 4);
            Assert.IsTrue(dbConnect.Table<SubtitleItem.Word>().Count() == 2);
            Assert.IsTrue(dbConnect.Table<WordOfDictionary>().Count() == 2);
            Assert.IsTrue(dbConnect.Table<TranslationOfWord>().Count() == 2);
            Assert.IsTrue(dbConnect.Table<Dictionary>().Count() == 1);
            Assert.IsTrue(dbConnect.Table<AudioTrack>().Count() == 2);
            Assert.IsTrue(dbConnect.Table<FrequencyDictionary>().Count() == 1);
            Assert.IsTrue(dbConnect.Table<FrequencyDictionary.Item>().Count() == 2);
            dbConnect.Close();

        }
        EFDbConnect CreateDemoBase(string db_name)
        {
            string path = PathToDb(db_name);
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            ILogger ILoggerMock = Mock.Of<ILogger>();
            ISQLitePlatform platf = new SQLitePlatformWin32();
            EFDbConnect EFDbConnect = new EFDbConnect(platf, path);

            EFDbContext ctx = new EFDbContext(EFDbConnect);

            LearningItem li1 = new LearningItem();
            li1.Name = "First";
            ctx.AddNewItemToDBContext(li1);
            LearningItem li2 = new LearningItem();
            li2.Name = "Second";
            ctx.AddNewItemToDBContext(li2);


            // Audio tracks
            AudioTrack at1 = new AudioTrack();
            li1.AudioTracks.Add(at1);

            AudioTrack at2 = new AudioTrack();
            li1.AudioTracks.Add(at2);

            AudioTrack at3 = new AudioTrack();
            li2.AudioTracks.Add(at3);

            // Frequency dictionary
            FrequencyDictionary fd1 = new FrequencyDictionary();
            FrequencyDictionary fd2 = new FrequencyDictionary();

            FrequencyDictionary.Item fdi1 = new FrequencyDictionary.Item();
            fd1.Items.Add(fdi1);
            FrequencyDictionary.Item fdi2 = new FrequencyDictionary.Item();
            fd1.Items.Add(fdi2);

            FrequencyDictionary.Item fdi3 = new FrequencyDictionary.Item();
            fd2.Items.Add(fdi3);
            FrequencyDictionary.Item fdi4 = new FrequencyDictionary.Item();
            fd2.Items.Add(fdi4);

            // Languages
            Language lang1 = new Language();
            lang1.FrequencyDictionary = fd1;

            Language lang2 = new Language();
            lang2.FrequencyDictionary = fd2;

            Subtitles sub1 = new Subtitles();
            li1.SubtitleCollection.Add(sub1);
            sub1.SecondaryLanguage = lang1;

            Subtitles sub2 = new Subtitles();
            li1.SubtitleCollection.Add(sub2);


            SubtitleItem si1 = new SubtitleItem();
            sub1.Items.Add(si1);
            SubtitleItem si2 = new SubtitleItem();
            sub1.Items.Add(si2);

            SubtitleItem si3 = new SubtitleItem();
            sub2.Items.Add(si3);
            SubtitleItem si4 = new SubtitleItem();
            sub2.Items.Add(si4);

            Subtitles sub3 = new Subtitles();
            li2.SubtitleCollection.Add(sub3);
            sub3.SecondaryLanguage = lang2;

            SubtitleItem si5 = new SubtitleItem();
            sub3.Items.Add(si5);


            WordOfSubtitleItem sw1 = new WordOfSubtitleItem();
            si1.WordsCollection.Add(sw1); 

            WordOfSubtitleItem sw2 = new WordOfSubtitleItem();
            si1.WordsCollection.Add(sw2); 

            WordOfSubtitleItem sw3 = new WordOfSubtitleItem();
            si5.WordsCollection.Add(sw3);



            // Dictionary
            Dictionary dic1 = new Dictionary();
            ctx.AddNewItemToDBContext(dic1);

            WordOfDictionary wd1 = new WordOfDictionary();
            dic1.Words.Add(wd1);

            TranslationOfWord tw1 = new TranslationOfWord();
            wd1.translations.Add(tw1);
            
            TranslationOfWord tw2 = new TranslationOfWord();
            wd1.translations.Add(tw2);

            WordOfDictionary wd2 = new WordOfDictionary();
            dic1.Words.Add(wd2);
            sw1.word_of_dictionary = wd1;
            sw2.word_of_dictionary = wd2;

            Dictionary dic2 = new Dictionary();
            ctx.AddNewItemToDBContext(dic2);
            WordOfDictionary wd3 = new WordOfDictionary();
            dic1.Words.Add(wd3);
            WordOfDictionary wd4 = new WordOfDictionary();
            dic1.Words.Add(wd4);
            sw3.word_of_dictionary = wd3;

            
            
            
            ctx.SaveChanges();

            return EFDbConnect;
        }
 private EFDbConnect  ConnectToDb(string basename) {
     EFDbConnect con = new  EFDbConnect(new SQLitePlatformWin32(), PathToDb(basename));
     return con;
 }
        public Dictionary_ViewModel(
            ILogger Logger_, 
            INavigationService NavigationService_, 
            IDialogService DialogService_,
            IAudioAPI AudioAPI_,
            EFDbConnect EFDbConnect_)
        {
            if (!IsInDesignMode)
            {
                Logger = Logger_;
                NavigationService = NavigationService_;
                DialogService = DialogService_;
                EFDbConnect = EFDbConnect_;
                AudioAPI = AudioAPI_;

                Languages = new ObservableCollection<Language>(EFDbConnect.Table<Language>().ToList());

                SpeechItem_Command = new MvxCommand<WordOfDictionary>(SpeechItem_Cmd);
                CommandDispatcher = new MvxCommand<string>(CommandDispatcher_); 
            }

            ViewModeDataGrid = VisualState.Collapsed;
            ViewModeList = VisualState.Collapsed;
            currentMode = ViewModes.List;
            SpeechPartsCollection =  new ObservableCollection<SpeechParts>(Enumeration.GetAll<SpeechParts>());
            ViewModesCollection = new ObservableCollection<ViewModes>(Enumeration.GetAll<ViewModes>());

            if (IsInDesignMode)
            {
                currentMode = ViewModes.DataGrid;

                Dictionary = new Dictionary();

                Dictionary.Words.Add(new WordOfDictionary {
                    word_of_dictionary = "Hello",
                    translation_as_string = "Привет",
                    transcription = "hello",
                    RepetitionPersent = 25,
                    SpeechPart = SpeechParts.Noun
                });

                Dictionary.Words.Add(new WordOfDictionary {
                    word_of_dictionary ="day",
                    translation_as_string = "день",
                    transcription ="day",
                    RepetitionPersent = 80,
                    SpeechPart =  SpeechParts.Noun
                });

                Dictionary.Words.Add(new WordOfDictionary {
                    word_of_dictionary ="I am",
                    translation_as_string = "я являюсь ...",
                    transcription ="...",
                    Forms = "I'm",
                    RepetitionPersent = 80,
                    SpeechPart =  SpeechParts.Noun
                });

            }

        }