public Dropdowns GenerateDropDowns() { var result = new Dropdowns(); if (Session[DropDownsSessionKey] != null) { result = (Dropdowns)Session[DropDownsSessionKey]; } else { var exercises = GetExercises(); var domains = exercises.Select(exercise => exercise.Domain).Distinct().OrderBy(x => x); var exerciseIds = exercises.Select(exercise => exercise.ExerciseId).Distinct().OrderBy(x => x); var learningObjectives = exercises.Select(exercise => exercise.LearningObjective).Distinct().OrderBy(x => x); var subjects = exercises.Select(exercise => exercise.Subject).Distinct().OrderBy(x => x); var users = exercises.Select(exercise => exercise.UserId).Distinct().OrderBy(x => x); result = new Dropdowns { Domains = domains, ExerciseIds = exerciseIds, LearningObjectives = learningObjectives, Subjects = subjects, Users = users }; } return(result); }
/// <summary> /// Closes the dropdowns. /// </summary> public void CloseDropdowns() { foreach (Control control in Dropdowns) { control.Parent = null; } Dropdowns.Clear(); }
public Conf_Emu_Details(Emulator item) { emulator = item; InitializeComponent(); ddlPlatform.DataSource = Dropdowns.GetDefinedSystems(); ddlPlatform.ValueMember = "Value"; ddlPlatform.DisplayMember = "Text"; }
static ScraperSearchParams() { platformIdLookup = new Dictionary <string, string>(); foreach (System.Data.DataRow row in Dropdowns.GetSystems().Rows) { string platformId = row[0].ToString(); if (platformId != "-1") { platformIdLookup[row[1].ToString()] = platformId; } } }
public frmAddEditDocActionTree(string category, Dropdowns item, MethodType methodType) { InitializeComponent(); this.category = category; this.item = item; this.methodType = methodType; txtParent.Properties.DataSource = new BindingList <Dropdowns>(new UnitOfWork().DropdownsRepo.Get()); detail(); addNewInit(); }
/// <summary> /// Shows the dropdown. /// </summary> /// <param name="control">The control.</param> /// <param name="stack">if set to <c>true</c> [stack].</param> public void ShowDropdown(Control control, bool stack) { if (DesignMode) { return; } if (control == null) { return; } if (!stack) { CloseDropdowns(); } if (Dropdowns.Contains(control)) { return; } if (Dropdowns.Count > 0) { int index = 0; bool found = false; for (int i = 0; i < Dropdowns.Count; i++) { if (Dropdowns[i].Owner == control.Owner) { index = i; found = true; break; } } if (found) { for (int i = Dropdowns.Count - 1; i >= index; i--) { Dropdowns[i].Parent = null; Dropdowns.RemoveAt(i); } } } control.Parent = this; Dropdowns.Add(control); }
void add(Dropdowns item) { try { UnitOfWork unitOfWork = new UnitOfWork(); item.Value = txtValue.Text; item.Order = txtOrder.EditValue?.ToInt(); unitOfWork.DropdownsRepo.Insert(item); unitOfWork.Save(); } catch (Exception e) { MessageBox.Show(e.Message, e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Updates this instance. /// </summary> public new void Update() { if (!DesignMode) { ProcessDragDrop(); if (Gui.GetButton(0) == ButtonState.Up) { EndDragDrop(); } } int pressed = -1; int down = -1; for (int i = 0; i < Gui.Buttons.Length; i++) { if (Gui.GetButton(i) == ButtonState.Press) { pressed = i; } if (Gui.GetButton(i) == ButtonState.Down) { down = i; } } if (pressed == -1) { if (TooltipControl != null) { TooltipControl.Visible = false; } hot = GetControlAt(Gui.MousePosition.x, Gui.MousePosition.y); if (TooltipControl != null) { TooltipControl.Visible = true; } if (!DesignMode && hot != null && ModalQueue.Count > 0) { Control check = ModalQueue[ModalQueue.Count - 1]; bool found = check == hot || hot.IsChildOf(check); if (!found && Dropdowns.Count > 0) { for (int i = Dropdowns.Count - 1; i >= 0; i--) { if (Dropdowns[i].Contains(hot)) { found = true; break; } } } if (!found && hot.Owner != null) { found = hot.Owner.IsChildOf(check); } if (!found) { hot = this; } } if (hot != HotControl) { if (HotControl != null) { HotControl.OnMouseLeave(); } if (hot != null) { CurrentCursor = hot.Cursor; hot.OnMouseEnter(); } HotControl = hot; } } else if (pressed > 1) { hot = null; } for (int i = 0; i < Gui.Buttons.Length; i++) { if (Gui.GetButton(i) == ButtonState.Up) { if (MouseDownControl != null) { MouseDownControl.OnMouseUp(i); break; } } } if (!DesignMode && down > -1) { if (ModalQueue.Count == 0) { Window w = GetWindowAt(Gui.MousePosition.x, Gui.MousePosition.y); if (w != null && w != window && w.Dock == DockStyle.None) { w.BringToFront(); w.Focus(); window = w; } } if (hot != null) { if (hot.AllowFocus) { FocusedControl = hot; } else if (!hot.PreventFocusChange) { FocusedControl = null; } } else { FocusedControl = null; } //if(OnClick != null) // OnClick(hot); if (Dropdowns.Count > 0) { if (hot == null) { CloseDropdowns(); } else { for (int i = Dropdowns.Count - 1; i >= 0; i--) { if (hot != Dropdowns[i]) { if (!Dropdowns[i].Contains(hot)) { Dropdowns[i].Parent = null; Dropdowns.RemoveAt(i); } else { break; } } else { break; } } } } } if (!DesignMode) { if (hot != null) { hot.DoEvents(); } DoKeyEvents(); if (FocusedControl != null) { FocusedControl.DoKeyEvents(); } if (IsDragging) { SetTooltip(dropTarget); } else { SetTooltip((down > -1 || pressed > -1) ? null : hot); } } PerformUpdate(); PerformLayout(); PerformLateUpdate(); foreach (KeyData data in Gui.KeyBuffer) { if (data.Pressed && data.Key == Keys.TAB) { if (Gui.ShiftPressed) { TabPrevious(); } else { TabNext(); } } } }
public override void update() { int SelectedSystem = -2; string SelectedSystemStr = null; if (ddlPlatform.Items.Count > 0) { try { SelectedSystem = Convert.ToInt32(ddlPlatform.SelectedValue.ToString()); //get currently selected emulators SelectedSystemStr = ddlPlatform.Text; } catch { } } ddlPlatform.SelectedIndexChanged -= new EventHandler(this.ddlPlatform_SelectedIndexChanged); ddlPlatform.DataSource = Dropdowns.GetDefinedSystems(); //refresh list of emulators, do this after getting currently selected emulator as 'SelectedValue' is reset ddlPlatform.ValueMember = "Value"; ddlPlatform.DisplayMember = "Text"; if (SelectedSystemStr != null) { int index = ddlPlatform.FindStringExact(SelectedSystemStr); if (index > -1) { ddlPlatform.SelectedIndex = index; //re-select current emulator } else { SelectedSystem = -2; //current emulator has been deleted, set to all emulators } } ddlPlatform.SelectedIndexChanged += new EventHandler(this.ddlPlatform_SelectedIndexChanged); dataGridView1.CellValueChanged -= new DataGridViewCellEventHandler(dataGridView1_CellValueChanged); dataGridView1.Rows.Clear(); //Emulator games if (SelectedSystem == -2) { foreach (Game game in DB.Instance.GetGames()) { addGameRow(game); } } else { Emulator currentEmulator = DB.Instance.GetEmulator(SelectedSystem); foreach (Game game in DB.Instance.GetGames(currentEmulator)) { addGameRow(game); } } /* * foreach (Emulator emu in DB.getEmulators()) * { * foreach (Game game in DB.getGames(emu.PathToRoms, emu, System.IO.SearchOption.AllDirectories, true)) * { * addGameRow(game); * } * } */ dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged); base.update(); }
//Asyncronously download metadata for all or new roms in DB public void StartImport(bool onlyNew) { Logger.LogInfo("Background import starting..."); Stop(); Game[] games = DB.Instance.GetGames(); if (stopWorker) { return; } List <Game> gamesToUpdate = new List <Game>(); if (onlyNew) { foreach (Game item in games) { if (item.Yearmade == 0) //assume new games are any where year is 0 { gamesToUpdate.Add(item); } } } else { gamesToUpdate.AddRange(games); } Logger.LogInfo("Found {0} games to update", gamesToUpdate.Count); if (gamesToUpdate.Count == 0) //no items to update { Logger.LogInfo("Background import finished"); return; } //try and load a valid scraper Assembly asm = Assembly.GetExecutingAssembly(); string script = ""; using (StreamReader sr = new StreamReader(asm.GetManifestResourceStream("myEmulators.Scripts.Mobygames.xml"))) { script = sr.ReadToEnd(); } ScriptableScraper scraper = new ScriptableScraper(script, false); if (!scraper.LoadSuccessful) { Logger.LogError("Error loading scraper"); scraper = null; return; //problem with scraper, stop import } System.Data.DataTable dt = Dropdowns.GetSystems(); //get a list of systems to match against parent emulator if (workingAnimation != null) { workingAnimation.Visible = true; } workerThread = new Thread(new ThreadStart(delegate() { EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 85L); ImageCodecInfo jpegCodec = ImageCodecInfo.GetImageEncoders()[1]; EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = qualityParam; Bitmap gameArt = null; bool aborted = false; //split into groups of 3 to allow partial update of gui int groups = (int)Math.Ceiling(gamesToUpdate.Count / 3.0); List <Game>[] gameGroups = new List <Game> [groups]; for (int x = 0; x < groups; x++) //add items to a group { List <Game> gameGroup = new List <Game>(); if (x == groups - 1) //last group may contain less than 3 items { for (int y = 3 * x; y < gamesToUpdate.Count; y++) { gameGroup.Add(gamesToUpdate[y]); } } else { int y = 3 * x; gameGroup.AddRange(new Game[] { gamesToUpdate[y], gamesToUpdate[y + 1], gamesToUpdate[y + 2] }); } gameGroups[x] = gameGroup; } if (stopWorker) { return; } try { foreach (List <Game> gameGroup in gameGroups) { //partial results List <Game> gamesToReturn = new List <Game>(); foreach (Game item in gameGroup) { if (stopWorker) { return; } string SavePath = ThumbsHandler.Instance.thumb_games + @"\" + item.ParentEmulator.Title + @"\" + item.GameID.ToString(); if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } string searchString = StripRomCodes(item.Title); string searchSystem = ""; Dictionary <string, string> paramList = new Dictionary <string, string>(); paramList["search.title"] = searchString; //try and match emulator title against predefined systems to narrow search foreach (System.Data.DataRow row in dt.Rows) { if ((row[1] as string).ToLower() == item.ParentEmulator.Title.ToLower() || (item.ParentEmulator.isPc() && row[1] as string == "Windows")) { //Console match paramList["search.system"] = row[0] as string; searchSystem = row[1] as string; break; } } if (stopWorker) { return; } //get matches and choose best result based on search settings List <ScraperResult> results = Conf_Scraper.getSearchResults(scraper, paramList); int possibleTitleMatches = 0; int possibleSystemMatches = 0; string titleSiteId = ""; string systemSiteId = ""; bool isExact = false; foreach (ScraperResult result in results) { if (stopWorker) { return; } if (result.Title == searchString && result.System == searchSystem) { //exact match break and get details isExact = true; possibleTitleMatches = 1; titleSiteId = result.SiteId; break; } else if (result.Title == searchString) { if (possibleTitleMatches == 0) { titleSiteId = result.SiteId; } possibleTitleMatches++; } else if (result.System == searchSystem) { if (possibleSystemMatches == 0) { systemSiteId = result.SiteId; } possibleSystemMatches++; } } bool importTop = Options.Instance.GetBoolOption("importtop"); bool importExact = Options.Instance.GetBoolOption("importexact"); string matchSiteId = ""; if (possibleTitleMatches == 1 && (isExact || !importExact)) { matchSiteId = titleSiteId; } else if (possibleSystemMatches == 1 && !importExact) { matchSiteId = systemSiteId; } else if (results.Count > 0 && importTop) { matchSiteId = results[0].SiteId; } if (matchSiteId == "") //no match, skip { continue; } //get game details paramList = new Dictionary <string, string>(); paramList["game.site_id"] = matchSiteId; if (stopWorker) { return; } ScraperGame scraperGame = Conf_Scraper.getGame(scraper, paramList); item.Title = scraperGame.Title; item.Description = StripTags(scraperGame.Description); item.Company = scraperGame.Company; try { item.Yearmade = Convert.ToInt32(scraperGame.Year); } catch { item.Yearmade = 0; } try { item.Grade = Convert.ToInt32(Math.Round((Convert.ToDouble(scraperGame.Grade, System.Globalization.CultureInfo.InvariantCulture) * 2), 0)); } catch { item.Grade = 0; } try { item.Genre = scraperGame.Genre.Split('|')[1]; } catch { item.Genre = ""; } item.Save(); if (stopWorker) { return; } double thumbDimensions = 0; if (Options.Instance.GetBoolOption("resizethumbs")) { thumbDimensions = ImageHandler.Instance.GetCaseAspect(item.ParentEmulator.Title); //the aspect ratio used to resize thumbs } //get covers List <string> thumbs = Conf_Scraper.getCoverUrls(scraper, paramList); //getCoverUrls handles image match logic and will return max of 2 results if (thumbs[0] != "") //front cover { try { gameArt = ImageHandler.Instance.BitmapFromWeb(thumbs[0]); if (Options.Instance.GetBoolOption("resizethumbs")) //resize image if necessary { using (Image resizedThumb = ImageHandler.Instance.resizeImage(gameArt, thumbDimensions)) { resizedThumb.Save(SavePath + @"\BoxFront.jpg", jpegCodec, encoderParams); } } else { gameArt.Save(SavePath + @"\BoxFront.jpg", jpegCodec, encoderParams); } } catch { } finally { if (gameArt != null) { gameArt.Dispose(); gameArt = null; } } } if (thumbs[1] != "") //back cover { try { gameArt = ImageHandler.Instance.BitmapFromWeb(thumbs[1]); if (Options.Instance.GetBoolOption("resizethumbs")) { using (Image resizedThumb = ImageHandler.Instance.resizeImage(gameArt, thumbDimensions)) { resizedThumb.Save(SavePath + @"\BoxBack.jpg", jpegCodec, encoderParams); } } else { gameArt.Save(SavePath + @"\BoxBack.jpg", jpegCodec, encoderParams); } } catch { } finally { if (gameArt != null) { gameArt.Dispose(); gameArt = null; } } } if (stopWorker) { return; } //get screens thumbs = Conf_Scraper.getScreenUrls(scraper, paramList); if (thumbs[0] != "") //title screenshot { try { gameArt = ImageHandler.Instance.BitmapFromWeb(thumbs[0]); gameArt.Save(SavePath + @"\TitleScreenshot.jpg", jpegCodec, encoderParams); } catch { } finally { if (gameArt != null) { gameArt.Dispose(); gameArt = null; } } } if (thumbs[1] != "") //ingame screenshot { try { gameArt = ImageHandler.Instance.BitmapFromWeb(thumbs[1]); gameArt.Save(SavePath + @"\IngameScreenshot.jpg", jpegCodec, encoderParams); } catch { } finally { if (gameArt != null) { gameArt.Dispose(); gameArt = null; } } } gamesToReturn.Add(item); } //Update DB and GUI MediaPortal.GUI.Library.GUIWindowManager.SendThreadMessage(new MediaPortal.GUI.Library.GUIMessage() { TargetWindowId = 2497, SendToTargetWindow = true, Object = gamesToReturn }); } } catch (ThreadAbortException) { Thread.ResetAbort(); aborted = true; } finally { object msgObject = aborted ? ScraperState.Aborted : ScraperState.Finished; //send finished message to GUI MediaPortal.GUI.Library.GUIWindowManager.SendThreadMessage(new MediaPortal.GUI.Library.GUIMessage() { TargetWindowId = 2497, SendToTargetWindow = true, Object = msgObject }); try { gameArt.Dispose(); } catch { } } } )); workerThread.Start(); }
public JsonResult GetSummary(DateTime date) { var dropdowns = new Dropdowns(); var allExercises = new List <Exercise>(); var tasks = new List <Task <int> >(); int correct = 0; Task dropdownTask = Task.Run(() => { dropdowns = GenerateDropDowns(); }); Task allexerciseTask = Task.Run(() => { allExercises = ExercisesByDate(date).ToList(); }); dropdownTask.Wait(); allexerciseTask.Wait(); var result = new ExerciseSummary(); Task domainTask = Task.Run(() => { List <KeyValuePair <string, int> > domains = new List <KeyValuePair <string, int> >(); if (dropdowns.Domains.Any()) { dropdowns.Domains.ToList().ForEach(domain => { domains.Add(new KeyValuePair <string, int>(domain, allExercises.Count(ae => ae.Domain.ToLower() == domain.ToLower()))); }); } result.Domains = domains; }); Task learningObjectiveTask = Task.Run(() => { List <KeyValuePair <string, int> > learningObjectives = new List <KeyValuePair <string, int> >(); if (dropdowns.LearningObjectives.Any()) { dropdowns.LearningObjectives.ToList().ForEach(learningObjective => { learningObjectives.Add(new KeyValuePair <string, int>(learningObjective, allExercises.Count(ae => ae.LearningObjective.ToLower().Replace(" ", "").Contains(learningObjective.ToLower().Replace(" ", ""))))); }); } result.LearningObjectives = learningObjectives; }); Task subjectsTask = Task.Run(() => { List <KeyValuePair <string, int> > subjects = new List <KeyValuePair <string, int> >(); if (dropdowns.Subjects.Any()) { dropdowns.Subjects.ToList().ForEach(subject => { subjects.Add(new KeyValuePair <string, int>(subject, allExercises.Count(ae => ae.Subject.ToLower() == subject.ToLower()))); }); } result.Subjects = subjects; }); Task correctTask = Task.Run(() => { correct = allExercises.AsParallel().Count(exercise => exercise.Correct > 0); }); Task submittedTimeTask = Task.Run(() => { List <KeyValuePair <string, int> > submittedTimes = new List <KeyValuePair <string, int> >(); allExercises.ForEach(exercise => { var hour = exercise.SubmitDateTime.Hour; var minute = exercise.SubmitDateTime.Minute; string minuteString = minute < 10 ? $"0{minute}" : $"{minute}"; string time = $"{hour}:{minuteString}"; if (!submittedTimes.Any(t => t.Key == time)) { submittedTimes.Add(new KeyValuePair <string, int>(time, 1)); } else { var value = submittedTimes.Where(t => t.Key == time).FirstOrDefault().Value; submittedTimes.Remove(new KeyValuePair <string, int>(time, value)); submittedTimes.Add(new KeyValuePair <string, int>(time, value + 1)); } }); result.SubmittedDateRanges = submittedTimes; }); domainTask.Wait(); learningObjectiveTask.Wait(); subjectsTask.Wait(); correctTask.Wait(); submittedTimeTask.Wait(); result.ExerciseCount = allExercises.Count(); result.CorrectCount = correct; result.StudentCount = allExercises.Select(exercise => exercise.UserId).Distinct().Count(); return(Json(result, JsonRequestBehavior.AllowGet)); }