示例#1
0
        public async void CreatePDFCourse(string CourseID, string cmi)
        {
            Courses courses = new Courses();

            courses.CreateCourseRecord(CourseID, cmi, true);

            closePopup();
            var action = await Application.Current.MainPage.DisplayAlert("Finished", "Would you like to launch the course?", "Yes", "No");

            //DisplayAlert("Finished", "Course had successfully been download.", "OK");
            // Debug.WriteLine("action " + action);
            if (action)
            {
                string test = await Courses.openCourse(CourseID, Application.Current.MainPage.Navigation);
            }


            App.Currentdownload.IsVisible = false;

            App.Currentdownload.Spinner.IsVisible      = false;
            App.Currentdownload.LaunchButton.IsVisible = true;
            App.Currentdownload.BtnLabel.Text          = "Open";
            App.Currentdownload.BtnLabel.IsVisible     = true;
        }
示例#2
0
        public async void Unzip(string CourseID, string cmi)
        {
            string localFolder     = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            string pathToNewFolder = Path.Combine(localFolder, "CoursePackage.zip");
            string newFolder       = Path.Combine(localFolder, "Courses/" + CourseID);
            string pathToNewFile   = Path.Combine(pathToNewFolder, Path.GetFileName("CoursePackage.zip"));

            ZipFile    zf = null;
            FileStream fs = File.OpenRead(pathToNewFolder);

            zf = new ZipFile(fs);

            foreach (ZipEntry zipEntry in zf)
            {
                String entryFileName = zipEntry.Name;
                // to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
                // Optionally match entrynames against a selection list here to skip as desired.
                // The unpacked length is available in the zipEntry.Size property.

                byte[] buffer    = new byte[4096];  // 4K is optimum
                Stream zipStream = zf.GetInputStream(zipEntry);

                // Manipulate the output filename here as desired.
                String fullZipToPath = Path.Combine(newFolder, entryFileName);
                string directoryName = Path.GetDirectoryName(fullZipToPath);
                if (directoryName.Length > 0)
                {
                    Directory.CreateDirectory(directoryName);
                }

                // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
                // of the file, but does not waste memory.
                // The "using" will close the stream even if an exception occurs.
                try
                {
                    using (FileStream streamWriter = File.Create(fullZipToPath))
                    {
                        StreamUtils.Copy(zipStream, streamWriter, buffer);
                    }
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                }
            }


            File.Delete(pathToNewFolder);
            Courses courses = new Courses();

            courses.CreateCourseRecord(CourseID, cmi, false);

            closePopup();
            var action = await Application.Current.MainPage.DisplayAlert("Finished", "Would you like to launch the course?", "Yes", "No");

            //DisplayAlert("Finished", "Course had successfully been download.", "OK");
            // Debug.WriteLine("action " + action);
            if (action)
            {
                string test = await Courses.openCourse(CourseID, Application.Current.MainPage.Navigation);
            }


            App.Currentdownload.IsVisible = false;

            App.Currentdownload.Spinner.IsVisible      = false;
            App.Currentdownload.LaunchButton.IsVisible = true;
            App.Currentdownload.BtnLabel.Text          = "Open";
            App.Currentdownload.BtnLabel.IsVisible     = true;
        }