public SaveChanges_ViewModel(ILogger Logger_, INavigationService NavigationService_) { if (!IsInDesignMode) { Logger = Logger_; NavigationService = NavigationService_; CommandDispatcher = new MvxCommand<string>(CmdDispatcher); } if (IsInDesignMode) { LearningItem li1 = new LearningItem { Name = "Mazzy" }; LearningItem li2 = new LearningItem { Name = "Futurama" }; Changes = new ObservableCollection<Entity> { new Entity { HardReference = li1, Obj = new WeakReference<Base>(li1), Order = 1, State = Entity.EntityState.Added, Type = li1.GetType() }, new Entity { HardReference = li2, Obj = new WeakReference<Base>(li2), Order = 2, State = Entity.EntityState.Added, Type = li1.GetType() } }; } }
public async Task HandleAsync(AddWordCommand command) { var item = new LearningItem(command.Word, command.AcceptedAnswers); _context.LearningItems.Add(item); await _context.SaveChangesAsync(); }
public async Task <bool> UpdateItem(long UserId, LearningItem Item) { var dbItem = await _context.LearningItems.Include(x => x.LearningSet).Where(x => x.Id == Item.Id).FirstOrDefaultAsync(); var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == UserId); if (dbItem != null && user != null && UserId == dbItem.LearningSet.Author.Id) { if (dbItem.LearningSet.Author == user) { dbItem.CorrectSentence = Item.CorrectSentence; dbItem.Description = Item.Description; dbItem.SentenceWithGaps = Item.SentenceWithGaps; dbItem.Item = Item.Item; await _context.SaveChangesAsync(); return(true); } else { return(false); } } return(false); }
static async Task <List <LearningItem> > CreateLearningItems(int count) { var timer = new Stopwatch(); Console.WriteLine("Creating learning items"); timer.Start(); var learningItems = new List <LearningItem>(); using (var db = new MyDbContext()) { for (var i = 0; i < count; i++) { var learningItem = new LearningItem { Name = $"LearningItem{i}" }; db.LearningItems.Add(learningItem); learningItems.Add(learningItem); } await db.SaveChangesAsync(); } timer.Stop(); Console.WriteLine($"Created {count} learningItems in {timer.Elapsed.TotalSeconds} secs"); return(learningItems); }
public LearningItem getLearningItem(int frequency) { LearningItem item = new LearningItem(); item.Maxfrequency = frequency; item.soundName = "Tay"; item.letter = "f"; item.counter = 0; return(item); }
public IFolder LearningItemCacheFolder(LearningItem li) { IFolder LiFolder = LearningItemFolder(li); IFolder cacheFolder = LiFolder.GetFolderAsync(Constants.Folders.Cache).Result; if (cacheFolder == null) { cacheFolder = LiFolder.CreateFolderAsync(Constants.Folders.Cache,CreationCollisionOption.OpenIfExists).Result; } return cacheFolder; }
public async Task <IActionResult> UpdateStudyItem([FromBody] LearningItem model) { var itemToUpdate = await _context.LearningItems.FindAsync(model.LearningItemID); itemToUpdate.RecallScore = model.RecallScore; itemToUpdate.LastReviewed = DateTime.UtcNow; await TryUpdateModelAsync <LearningItem>(itemToUpdate); _repository.SaveAll(); return(NoContent()); }
public async Task <IActionResult> UpdateItem(long userId, LearningItem Item) { var result = await _repository.UpdateItem(userId, Item); if (result) { return(Ok()); } else { return(NoContent()); } }
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]; } }
/// <summary> /// класс темы для конвертации /// xslt /// </summary> /// <param name="_item">тема курса</param> /// <param name="_tlFactory">фабрика инструментов</param> /// <exception cref="ArgumentNullException"></exception> public ItemThemeForXSLT(LearningItem _item,ToolsFactory _tlFactory ) { if (_item == null || _tlFactory==null) throw new ArgumentNullException(); item = _item; if (item.childs == null) throw new ArgumentNullException("Отсутствуют кадры в теме "+item.identifier); number++; IdInTheme = number; FileName = "theme" + IdInTheme; initSteps(_tlFactory); }
override public void OnNavigationOpenPage(ParametersOfForms param_) { AddNewLearningItemWizard_parameters Params = (AddNewLearningItemWizard_parameters)param_; LearningItem = Params.LearningItem; UpdateButtonState(); // Default values if (!LearningItem.isFirstStartCompleted) { LearningItem.CollectPhrases = true; LearningItem.UnderstandingTest = true; LearningItem.ShowNewWords = true; LearningItem.TestingUnderstandingNewWords = true; } }
public static TestItem Create(LearningItem learningItem) { var item = learningItem.Item; double complexity = 0; if (item.TotalRepeatsCount > 0) { if (item.CorrectAnswersCount == 0) { complexity = 1; } else if (item.CorrectAnswersCount == item.TotalRepeatsCount) { complexity = 0.1; } else { complexity = Math.Round(1 - (double)item.CorrectAnswersCount / item.TotalRepeatsCount, 2); } } var testItem = new TestItem { Item = learningItem.LearningMode == LearningMode.Primary ? item.Translation : item.Original, AnswerMask = learningItem.LearningMode == LearningMode.Primary ? GenerateMask(item.Original) : GenerateMask(item.Translation), AnswerFirstLetter = learningItem.LearningMode == LearningMode.Primary ? item.Original[0] : item.Translation[0], Definition = item.Definition, Type = item.Type, IsStarred = item.IsStarred, IsLearned = item.IsLearned, Complexity = complexity, CorrectAnswersToCompletionCount = item.CorrectAnswersToCompletionCount }; return(testItem); }
public LearningItemSettings_ViewModel( INavigationService NavigationService_, IDialogService DialogService_) { if (!IsInDesignMode) { NavigationService = NavigationService_; CommandDispatcher = new MvxCommand<string>(CmdDispatcher); } TestingUnderstandingNewWords_VM = new VisualElement_Model(); if (IsInDesignMode) { LearningItem = new LearningItem(); LearningItem.ShowNewWords = true; } }
public static void Shuffle(List <LearningItem> list) { var n = list.Count; while (n > 1) { n--; var k = Rand.Next(n + 1); LearningItem value = list[k]; list[k] = list[n]; list[n] = value; } for (var i = 0; i < list.Count; i++) { list[i].NumberInSequence = i; } }
public ReferencesToWord_ViewModel( ILogger Logger_, INavigationService NavigationService_, EFDbContext EFDbContext_, IDialogService DialogService_, ILocalization Tx_ ) { if (!IsInDesignMode) { Logger = Logger_; NavigationService = NavigationService_; EFDbContext =EFDbContext_; DialogService = DialogService_; Tx = Tx_; CommandDispatcher = new MvxCommand<string>(CmdDispatcher); References = new ObservableCollection<ReferenceToWordOfDictionary>(); } ClearButton = new ButtonModel(); if (IsInDesignMode) { Word = new WordOfDictionary { word_of_dictionary = "I'm" }; LearningItem li1 = new LearningItem { Name = "Mazzy collection" }; LearningItem li2 = new LearningItem { Name = "Futurama season 1" }; Subtitles st1 = new Subtitles { Name = "English - Russian" }; Subtitles st2 = new Subtitles { Name = "English - Ukraine" }; References = new ObservableCollection<ReferenceToWordOfDictionary>() { new ReferenceToWordOfDictionary {LearningItem = li1, Subtitles = st1,SubtitleItem = new SubtitleItem { Text = "I'm Mazzy"},WordOfSubtitleItem = new WordOfSubtitleItem { word = "I'm"} }, new ReferenceToWordOfDictionary {LearningItem = li1, Subtitles = st1, SubtitleItem = new SubtitleItem { Text = "I am princess Sylvia" } ,WordOfSubtitleItem = new WordOfSubtitleItem { word = "I am"}}, new ReferenceToWordOfDictionary {LearningItem = li2, Subtitles = st2, SubtitleItem = new SubtitleItem { Text = "I'm Nibbler" } ,WordOfSubtitleItem = new WordOfSubtitleItem { word = "I'm"}} }; } }
private static List <LearningItem> ConvertItemsToLearningItems(List <Item> items, double secondaryModeProbability) { var result = new List <LearningItem>(); for (int i = 0; i < items.Count; i++) { var learningItem = new LearningItem { Item = items[i], LearningMode = Rand.NextDouble() >= secondaryModeProbability ? LearningMode.Primary : LearningMode.Secondary, NumberInSequence = i, }; result.Add(learningItem); } return(result); }
/// <summary> /// класс темы для конвертации /// xslt /// </summary> /// <param name="_item">тема курса</param> /// <param name="_tlFactory">фабрика инструментов</param> /// <exception cref="ArgumentNullException"></exception> public ItemThemeForXSLT(LearningItem _item, ToolsFactory _tlFactory) { if (_item == null || _tlFactory == null) { throw new ArgumentNullException(); } item = _item; if (item.childs == null) { throw new ArgumentNullException("Отсутствуют кадры в теме " + item.identifier); } number++; IdInTheme = number; FileName = "theme" + IdInTheme; initSteps(_tlFactory); }
public Publish_ViewModel_WPF( ILogger Logger_, INavigationService NavigationService_, IDialogService DialogService_, IPublish iPublish_) { if (!IsInDesignModeNet()) { Logger = Logger_; NavigationService = NavigationService_; DialogService = DialogService_; iPublish = iPublish_; CommandDispatcher = new MvxCommand<string>(CmdDispatcher); } else { LearningItem = new LearningItem { Name = "Futurama" }; } }
public async Task <bool> AddNewItem(long UserId, long LearningSetId, LearningItem Item) { var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == UserId); var lSet = await _context.LearningSets.FirstOrDefaultAsync(u => u.Id == LearningSetId); if (user != null && lSet != null && lSet.Author.Id == UserId) { var itm = new LearningItem() { Item = Item.Item, SentenceWithGaps = Item.SentenceWithGaps, CorrectSentence = Item.CorrectSentence, Description = Item.Description, LearningSet = lSet }; _context.LearningItems.Add(itm); await _context.SaveChangesAsync(); return(true); } return(false); }
public AddNewLearningItemWizard_ViewModel(ILogger Logger_, INavigationService NavigationService_, IDialogService DialogService_) : base () { PanelCount = 4; if (!IsInDesignMode) { Logger = Logger_; NavigationService = NavigationService_; DialogService = DialogService_; } CommandDispatcher = new MvxCommand<string>(CmdDispatcher); if (IsInDesignMode) { SelectedIndex = 2; UpdateButtonState(); LearningItem = new LearningItem(); } }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var dictionary = await _context.Dictionaries.FindAsync(request.DictionaryId); if (dictionary == null) { throw new RestException(HttpStatusCode.NotFound, ErrorType.DictionaryNotFound); } var item = await _context.Items.FindAsync(request.ItemId); if (item == null) { throw new RestException(HttpStatusCode.NotFound, ErrorType.ItemNotFound); } if (item.Type == ItemType.Word) { dictionary.WordsCount--; } else { dictionary.PhrasesCount--; } if (item.IsLearned) { if (item.Type == ItemType.Word) { dictionary.LearnedWordsCount--; } else { dictionary.LearnedPhrasesCount--; } } _context.Items.Remove(item); var learningList = await _context.LearningLists.Where(l => l.DictionaryId == request.DictionaryId) .FirstOrDefaultAsync(); if (learningList != null) { learningList = await _context.LearningLists.Where(l => l.Id == learningList.Id) .Include(l => l.LearningItems).FirstOrDefaultAsync(); LearningItem currentItem = null; foreach (var i in learningList.LearningItems) { if (i.ItemId == request.ItemId) { currentItem = i; } } if (currentItem != null) { foreach (var i in learningList.LearningItems) { if (i.NumberInSequence > currentItem.NumberInSequence) { i.NumberInSequence--; } } if (currentItem.NumberInSequence <= learningList.CompletedItemsCount && learningList.CompletedItemsCount > 0) { learningList.CompletedItemsCount--; } learningList.Size--; _context.LearningItems.Remove(currentItem); } } var success = await _context.SaveChangesAsync() > 0; if (success) { return(Unit.Value); } throw new RestException(HttpStatusCode.InternalServerError, ErrorType.SavingChangesError); }
override public void OnNavigationOpenPage(ParametersOfForms param_) { DictionaryEditor_parameters param = (DictionaryEditor_parameters)param_; LearningItem = param.LearningItem; }
APIResult AttachFile(LearningItem LearningItem,string file) { APIResult res; pb.IsIndeterminate = false; pb.Text = Tx.T("Publish.Messages.UploadData") + " " + Path.GetFileName(file); pb.Minimum = 0;pb.Value = 0;pb.Maximum = 100; WebAPI_LearningItems.WebClient.UploadProgressChanged += WebClient_UploadProgressChanged; ; res = WebAPI_LearningItems.AttachFile(LearningItem.id.guid, file).Result; WebAPI_LearningItems.WebClient.UploadProgressChanged -= WebClient_UploadProgressChanged; if (!res.Result) { string title = string.Format(Tx.T("Publish.Messages.UploadError"),Path.GetFileName(file)); throw new Exception(res.Message).Init(title); } return res; }
string CreateDatFile(LearningItem LearningItem) { pb.IsIndeterminate = true; pb.Text = Tx.T("Publish.Messages.SaveLearningItemIntofile"); string LearningItemFile = Path.Combine(FileService.GetPathToLearningItem(LearningItem), Constants.Store.LearningItemFileName); DBBulkOperations.ExportLearningItem(LearningItemFile, LearningItem.id, false); return LearningItemFile; }
public static string GetPathToLearningItem(LearningItem LearningItem) { return GetPathToLearningItem(LearningItem.id); }
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; }
public void StartVideo(LearningItem learningItem,int position = -1) { if (string.IsNullOrEmpty(learningItem.VideoFileName)) return; string path = PortablePath.Combine(FolderService.LearningItemFolder(learningItem).Path,learningItem.VideoFileName); Open(path); if(position != -1) { Position = position; } SetAudioTrack(learningItem.AudioTrack); Play(); }
public static void ProcessItemAnswer(Dictionary dictionary, LearningList list, LearningItem learningItem, bool isAnswerCorrect) { var item = learningItem.Item; item.TotalRepeatsCount++; if (isAnswerCorrect) { item.CorrectAnswersCount++; if (item.IsLearned) { item.LastLearnedRepeatDate = DateTime.Now; item.LearnedRepeatsCount++; return; } if (item.CorrectAnswersToCompletionCount != list.CorrectAnswersToItemCompletion && list.TimesCompleted != 1) { item.CorrectAnswersToCompletionCount++; } if (item.CorrectAnswersToCompletionCount == list.CorrectAnswersToItemCompletion) { if (item.IsStarred) { dictionary.StarredItemsCount--; } item.IsLearned = true; item.IsStarred = false; item.GoesForNextDay = false; item.LastLearnedRepeatDate = DateTime.Now; item.LearnedRepeatsCount++; if (item.Type == ItemType.Word) { dictionary.LearnedWordsCount++; } else { dictionary.LearnedPhrasesCount++; } } } else { item.GoesForNextDay = true; item.IsLearned = false; item.LastLearnedRepeatDate = null; item.LearnedRepeatsCount = 0; if (list.IsHardModeEnabled) { item.CorrectAnswersToCompletionCount = 0; } else { item.CorrectAnswersToCompletionCount--; } } }
public override async void CmdDispatcher(string command) { switch (command) { case "Download": await NavigationService.NavigateForward(Views.Download, new Download_parameters()); break; case "Create": LearningItem newitem = new LearningItem(); await NavigationService.NavigateForward(Views.EditLearningItem, new EditLearningItem_parameters { CreateNewItem = true }); break; case "Backup": await NavigationService.NavigateForward(Views.Backup); break; case "CreateInitialDatapack": //Disk_Operations io = new Disk_Operations(); //io.CreateInitialDatapack(); throw new NotImplementedException(); break; case "Debug": break; case "Setting": NavigationService.OpenDialog(Views.AppSettings); break; case "OpenDictionariesList": NavigationService.NavigateForward(Views.DictionariesList, new DictionariesList_parameters()); break; case "OpenLogForm": NavigationService.NavigateForward(Views.LoggerForm, new LoggerForm_parameters()); break; default: SystemMessage.Show("Unknown command "+command); break; } }
private async void Delete(LearningItem LearingItem_) { bool res = await DialogService.Ask(Tx.T("MainWindow.Messages.ReallyDelete")); if (res) { //Disk_Operations io = new Disk_Operations(); //io.DeleteLearningItem(LearingItem_); throw new NotImplementedException(); } }
public async void GetRef_LearningItem(string url, LearningItem li) { IFolder cacheFolder = folderService.LearningItemCacheFolder(li); }
override public void OnNavigationOpenPage(ParametersOfForms param_) { EditLearningItem_parameters param = (EditLearningItem_parameters)param_; if (param.CreateNewItem) { LearningItem = new LearningItem(); EFDbContext.Context.AddNewItemToDBContext(LearningItem); } else { LearningItem = param.LearningItem; } Task.Run(()=> { try { Player.StartVideo(LearningItem); Player.Pause(); } catch (Exception ex) { if (ex.IsFatal()) throw; } }); LearningItem.PropertyChanged += LearningItem_PropertyChanged; }
public void AddNewLearningItem(LearningItem LearningItem_) { LearningItems.Add(LearningItem_); }
override async public void OnNavigationOpenPage(ParametersOfForms param_) { WordsTranslation_parameters param = (WordsTranslation_parameters)param_; WordsCollection = param.WordsCollection; SubItem = param.SubtitleItem; LearningItem = param.LearningItem; mode = param.Mode; if (mode == WordsTranslation_parameters.ViewMode.Undefined) throw new NotImplementedException(); if (WordsCollection.Count > 0) { SetCurrentWord(WordsCollection[0]); } else { await DialogService.Message(Tx.T("WordsTranslation.Messages.NoElementForTraining")); NavigationService.NavigateBack(); } }
string CreateArchive(LearningItem LearningItem) { pb.IsIndeterminate = true; pb.Text = Tx.T("Publish.Messages.Archive"); string li_path = FileService.GetPathToLearningItem(LearningItem); string li_id = LearningItem.id.ToString(); string archiveDirectory = Path.Combine(FileService.GetPathToTempFolder(), li_id); if (!Directory.Exists(archiveDirectory)) Directory.CreateDirectory(archiveDirectory); string archiveFile = ""; archiveFile = Path.Combine(archiveDirectory,Constants.Store.LearningItemDatFileName); if (File.Exists(archiveFile)) File.Delete(archiveFile); using (ZipFile zip = new ZipFile()) { //zip.AddDirectory(FileService.GetPathToLearningItem(LearningItem),LearningItem.id.ToString()); // Main db file zip.AddFile(Path.Combine(li_path, Constants.Store.LearningItemFileName),li_id); // Cover string _cover = Path.Combine(li_path, LearningItem.CoverFile); if (File.Exists(_cover)) { zip.AddFile(_cover,li_id); } // Add dictionaries zip.AddDirectoryByName(Constants.Folders.Dictionaries); foreach(Subtitles subt in LearningItem.SubtitleCollection) { if(subt.Dictionary != null) { string CurrentDictFolder = Constants.Folders.Dictionaries + @"/" + subt.Dictionary.id.ToString(); zip.AddDirectoryByName(CurrentDictFolder); zip.AddDirectory(FileService.GetPathToDictionaryFolder(subt.Dictionary),CurrentDictFolder); } } zip.Save(archiveFile); } return archiveFile; }
public IFolder LearningItemFolder(LearningItem li) { return LearningItemsFolder.CreateFolderAsync(li.id.ToString(),CreationCollisionOption.OpenIfExists).Result; }
public void PublishLearningItem(LearningItem LearningItem,bool UploadVideo) { APIResult res; pb = new ProgressBar_Model {}; pb.Title = string.Format(Tx.T("Publish.Messages.Publishing"), LearningItem.Name); App.AddLongTaskProgressBar(pb); try { // Testing rights InteractiveAuthenticationAsUser(); if (!HasRight(UserRights.Collection.Publish)) { string msg = Tx.T("Publish.Messages.NoRightForPublish"); throw new Exception(msg); } // Create a dat file string DatFile = CreateDatFile(LearningItem); // Create an archive string ArchiveFile; try { ArchiveFile = CreateArchive(LearningItem); } finally { File.Delete(DatFile); } // Create a Store item StoreItem si = new StoreItem { id = LearningItem.id.guid, Name = LearningItem.Name, Description = LearningItem.Description, YoutubeURL = LearningItem.YoutubeURL, CoverFile = LearningItem.CoverFile, VideoFileName = FileService.GetFileNameWithoutPath(LearningItem.VideoFileName), VideoFileSize = FileService.GetFileSize(LearningItem.VideoFileName), Version = LearningItem.Version }; StoreItem r = WebAPI_LearningItems.GetById(si.id).Result; if (r != null) { // update res = WebAPI_LearningItems.Update(si).Result; } else { // create res = WebAPI_LearningItems.Create(si).Result; } if (!res.Result) { FileService.DeleteFile(ArchiveFile); throw new Exception(res.Message).Init(Tx.T("Publish.Messages.CantCreateStoreItem"), res.FullMessage); } // Upload an archive try { AttachFile(LearningItem, ArchiveFile); } finally { FileService.DeleteFile(ArchiveFile); } // Upload a cover string pathtocover = Path.Combine(FileService.GetPathToLearningItem(LearningItem),LearningItem.CoverFile); if (FileService.FileExists(pathtocover)) { AttachFile(LearningItem, pathtocover); } // Upload a video if (UploadVideo) { if (!string.IsNullOrEmpty(LearningItem.VideoFileName)) { AttachFile(LearningItem, LearningItem.VideoFileName); } } LearningItem.Version++; EFDbContext.SaveChgs(); } finally { App.RemoveLongTaskProgressBar(pb); } }
private async void CmdDispatcher_LearningItemsList(LearningItem li,string cmd) { switch (cmd){ case "Edit": await NavigationService.NavigateForward(Views.EditLearningItem, new EditLearningItem_parameters { LearningItem = li }); break; case "Open": await NavigationService.NavigateForward(Views.PlayerWindow, new PlayerWindow_parameters { LearningItem = li }); break; case "Delete": bool res = await DialogService.Ask(string.Format(Tx.T("MainWindow.Messages.ReallyDelete"),li.Name)); if (res) { //SQL_XML_Operations.DeleteLearningItem(li); } break; default: SystemMessage.Show("Unknown command in CmdDispatcher_LearningItemsList"); break; } }