public Download_ViewModel(
            INavigationService NavigationService_,
            IDialogService DialogService_,
            AppSetting AppSetting_,
            IStore Store_,
            ILocalization Loc_,
            ILogger logger_) : base()
        {

            if (!IsInDesignMode)
            {
                NavigationService = NavigationService_;
                DialogService = DialogService_;
                AppSettings = AppSetting_;
                Store = Store_;
                Tx = Loc_;
                logger = logger_;

                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);
                Command_DownloadStoreItem = new MvxCommand<StoreItemExt>((x)=>CmdDispatcher_StoreItem(x,"Download"));
            }
            
            StoreItems = new SynchronizedObservableCollection<StoreItemExt>();
            
            if (IsInDesignMode)
            {

                StoreItemExt item;

                item = new StoreItemExt { Name = "South Park" };
                item.DownloadButton.State1 = true;
                StoreItems.Add(item);

                item = new StoreItemExt { Name = "Chuggington" };
                item.DownloadButton.State2 = true;
                StoreItems.Add(item);

                item = new StoreItemExt { Name = "Futurama" };
                item.DownloadButton.State3 = true;
                StoreItems.Add(item);

            }
            

        }
 private void CmdDispatcher_StoreItem(StoreItemExt storeitem,string cmd)
 {
     switch (cmd)
     {
         case "Download":
             Task.Run(new Action(()=> 
             {
                 try
                 {
                     Store.DownloadStoreItem(storeitem);
                 }
                 catch (Exception ex)
                 {
                     if (ex.IsFatal()) throw;
                     Dispatcher.RequestMainThreadAction(new Action(() => NavigationService.OpenDialog(Views.ExceptionForm, new ExceptionForm_parameters{ ex = ex })));
                     return;
                 }
                 Dispatcher.RequestMainThreadAction(new Action(() => DialogService.Message(string.Format(Tx.T("IStore.DownloadStoreItem.Messages.Success"),storeitem.Name))));
             }));
             break;
         default:
             SystemMessage.Show("Unknown command "+cmd);
             break;
     }
 }
Exemplo n.º 3
0
        public void DownloadStoreItem(StoreItemExt StoreItem)
        {

            pb = new ProgressBar_Model {};
            pb.Title = string.Format(Tx.T("IStore.DownloadStoreItem.Messages.Download"), StoreItem.Name);
            App.AddLongTaskProgressBar(pb);

            try
            {
                // download dat file
                string tempDatFile = Path.Combine(FileService.GetPathToTempFolder(), "LearningItem."+ StoreItem.id.ToString()+".dat");
                string DatFileUrl = WebAPI_LearningItems.GetPathToDatFile(StoreItem.id);
                DownloadFile(DatFileUrl, tempDatFile);

                UUID li_id = new UUID(StoreItem.id);
                // install dat file
                try
                {
                    InstallLearningItem(li_id,tempDatFile,pb);
                }
                finally
                {
                    FileService.DeleteFile(tempDatFile);
                }

                LearningItem li = EFDbContext.Context.Find<LearningItem>(li_id);
                if (AppSetting.LearningItems.Any(x=>x.id == li_id))
                {
                    li.RefreshFromDB();
                }
                else
                {
                    AppSetting.LearningItems.Add(li);
                }
                li.AppSetting = AppSetting;

                // download video file
                YoutubeDownloader.Info vinf =  DownloadVideo(StoreItem);

                li.VideoFileName = vinf.VideoFileName;
                foreach(AudioTrack at in li.AudioTracks)
                {
                    if (vinf.isExternalAudio)
                    {
                        at.ExternalFile = vinf.AudioFileName;
                        at.isExternal = vinf.isExternalAudio;
                    }
                }

                if (!AppSetting.LearningItems.Contains(li)) AppSetting.LearningItems.Add(li);
                EFDbContext.SaveChgs();

                StoreItem.LearningItem = li;
                StoreItem.UpdateDownloadButtonStatus();
            }
            finally
            {
                App.RemoveLongTaskProgressBar(pb);
            }
         
        }
Exemplo n.º 4
0
        YoutubeDownloader.Info DownloadVideo(StoreItemExt storeitem)
        {
            //bool IsCopyVideo = false;
            //string VideoFilePath;
            string LearningItemFolder = FileService.GetPathToLearningItem(new UUID(storeitem.id));
            //string CoverURL = "";

            // Is need to download video
            // it does not work because video file name can be changed
            /*
            if (!string.IsNullOrEmpty(storeitem.VideoFileName))
            {
                VideoFilePath = Path.Combine(LearningItemFolder,storeitem.VideoFileName);
                if (!FileService.FileExists(VideoFilePath))
                {
                    IsCopyVideo = true;
                } else
                {
                    IsCopyVideo = storeitem.VideoFileSize != FileService.GetFileSize(VideoFilePath);
                }
            }
            */

            // Youtube download
            YoutubeDownloader.Info inf = null;
            //if (IsCopyVideo)
            //{
                if (!string.IsNullOrEmpty(storeitem.YoutubeURL))
                {
                    var VideoInfos = YoutubeDownloader.GetVideoInfo(storeitem.YoutubeURL);
                    var vi = VideoInfos.OrderByDescending(x => x.Resolution).FirstOrDefault();
                    if (vi != null)
                    {
                        inf = YoutubeDownloader.GetInfo(vi);
                        YoutubeDownloader.Download(VideoInfos, vi, LearningItemFolder,pb);

                        return YoutubeDownloader.GetInfo(vi);

                    }
                   
                }
            return null;

            //}

        }