/************* Learning Path Cards ************* * * *****************************************************/ public async Task <bool> buildObjectiveCard(Objective obj, StackLayout container, string lpid, int count) { Grid layout; // overall card layout // // objective title // Label objectiveTitle = new Label { Margin = new Thickness(0, 0, 0, 0), Text = obj.Name, VerticalOptions = LayoutOptions.FillAndExpand, VerticalTextAlignment = TextAlignment.Center, HeightRequest = 40, Style = (Style)Application.Current.Resources["headerStyle"] }; // container for the content in the card layout = new Grid { HorizontalOptions = LayoutOptions.FillAndExpand, WidthRequest = Constants.deviceWidth, Margin = new Thickness(0, 10, 0, 0) }; layout.Padding = new Thickness(16, 0, 16, 0); layout.RowDefinitions.Add(new RowDefinition { Height = 40 }); layout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); layout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); layout.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); StackLayout cardBody = new StackLayout { Padding = new Thickness(0, 0, 0, 0), Margin = new Thickness(0), ClassId = "course_" + obj.id, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, IsVisible = (count > 1) ? false : true, Opacity = (count > 1) ? 0 : 100 }; // used to expand accordion AccordionButton AcBtn = new AccordionButton { Image = "chevron_down.png", Padding = new Thickness(0, 0, 0, 0), Margin = new Thickness(0, 0, 0, 0), WidthRequest = 20, HeightRequest = 20, BackgroundColor = Color.Transparent, BorderColor = Color.Transparent }; AcBtn.ContentFrame = cardBody; AcBtn.FrameOpen = false; AcBtn.Clicked += AcBtn_Clicked; StackLayout frameContainer = new StackLayout(); foreach (Activity act in obj.Activities.Activity) { // chart for each activity in the objective ChartView chartView = null; float perc_complete = 0; float perc_incomplete = 0; Models.Record courseRecord = await App.Database.GetCourseByID(act.CourseID); if (courseRecord == null) { Models.Record rec = new Models.Record(); rec.CourseID = act.CourseID; // find the course name rec.CourseName = act.Name; rec.Version = "1"; rec.CourseDescription = ""; rec.CompletionStatus = "Not Started"; rec.SuccessStatus = ""; rec.Score = ""; rec.Deleted = "false"; rec.Downloaded = false; rec.DueDate = ""; rec.LP = lpid; rec.Objective = obj.id; rec.CMI = ""; App.LocalFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); await App.Database.SaveItemAsync(rec); perc_complete = (rec.CompletionStatus.ToLower() == "completed") ? 100 : (rec.CompletionStatus.ToLower() != "not started") ? 50 : 0; perc_incomplete = (rec.CompletionStatus.ToLower() == "completed") ? 0 : (rec.CompletionStatus.ToLower() != "not started") ? 50 : 100; } else if (String.IsNullOrEmpty(courseRecord.Objective) || String.IsNullOrEmpty(courseRecord.LP)) { courseRecord.Objective = obj.id; courseRecord.LP = lpid; await App.Database.SaveItemAsync(courseRecord); } if (courseRecord != null) { if (courseRecord.ProgressMeasure != null && courseRecord.ProgressMeasure != "") { perc_complete = float.Parse(courseRecord.ProgressMeasure) * 100; perc_incomplete = 100 - perc_complete; } else { perc_complete = (courseRecord.CompletionStatus.ToLower() == "completed") ? 100 : (courseRecord.CompletionStatus.ToLower() == "unknown" || courseRecord.CompletionStatus.ToLower() == "attempted") ? 50 : 0; perc_incomplete = (courseRecord.CompletionStatus.ToLower() == "not started") ? 100 : (courseRecord.CompletionStatus.ToLower() == "completed") ? 100 : 50; } } Doughnut doughnut = new Doughnut(); Grid doughnutGrid = doughnut.CompletionChart("complete", perc_complete, perc_incomplete); //***************************************************** Grid activityContainer = new Grid { Padding = new Thickness(5, 0, 5, 0), ClassId = "course_" + act.id }; activityContainer.RowDefinitions.Add(new RowDefinition { Height = 50 }); activityContainer.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); activityContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); activityContainer.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); Label coursetitle = new Label { Text = act.Name, Style = (Style)Application.Current.Resources["subHeaderStyle"], VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.FillAndExpand }; ActivityIndicator spinner = new ActivityIndicator { IsVisible = false, Style = (Style)Application.Current.Resources["spinnerStyle"], HeightRequest = 20 }; Label lbl = new Label() { Text = (courseRecord == null || courseRecord.Downloaded == false) ? "download" : (courseRecord.CompletionStatus.ToLower() == "completed") ? "review" : (courseRecord.CMI == "") ? "open" : "resume", HorizontalOptions = LayoutOptions.Center }; // Create the two buttons that get swapped // DownloadImageButton launchBtn = BuildImageLaunch(act.CourseID, courseRecord, null, lbl); DownloadImageButton downloadBtn = BuildImageDownload(act.CourseID, courseRecord, spinner, lbl); launchBtn.HorizontalOptions = LayoutOptions.Center; downloadBtn.HorizontalOptions = LayoutOptions.Center; launchBtn.VerticalOptions = LayoutOptions.EndAndExpand; downloadBtn.VerticalOptions = LayoutOptions.EndAndExpand; // Button Grid Grid btnGrid = new Grid() { HorizontalOptions = LayoutOptions.CenterAndExpand, VerticalOptions = LayoutOptions.EndAndExpand }; btnGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50) }); btnGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(20) }); btnGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(80) }); btnGrid.Children.Add(launchBtn, 0, 0); btnGrid.Children.Add(downloadBtn, 0, 0); btnGrid.Children.Add(spinner, 0, 0); btnGrid.Children.Add(lbl, 0, 1); Courses c = new Courses(); downloadBtn.VerticalOptions = LayoutOptions.EndAndExpand; downloadBtn.Clicked += c.DownloadClicked; launchBtn.Clicked += c.launchCourse; launchBtn.VerticalOptions = LayoutOptions.EndAndExpand; downloadBtn.LaunchButton = launchBtn; downloadBtn.CourseID = act.CourseID; // add the image CachedImage marquee = BuildMarquee(act.CourseID, false); marquee.HorizontalOptions = LayoutOptions.StartAndExpand; activityContainer.Children.Add(coursetitle, 0, 0); // activityContainer.Children.Add(chartView, 1, 0); activityContainer.Children.Add(doughnutGrid, 1, 0); Grid.SetColumnSpan(coursetitle, 2); activityContainer.Children.Add(marquee, 0, 1); activityContainer.Children.Add(btnGrid, 1, 1); frameContainer.Children.Add(activityContainer); } cardBody.Children.Add(frameContainer); layout.Children.Add(objectiveTitle, 0, 0); layout.Children.Add(AcBtn, 1, 0); layout.Children.Add(cardBody, 0, 1); Grid.SetColumnSpan(cardBody, 2); container.Children.Add(layout); return(true); }
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; }
public async Task <Models.LPDBRecord> getMap(string id) { Courses m = new Courses(); return(await m.GetActivityMap(id)); }