/// <summary> /// Shows the grade confirmation dialog. /// </summary> /// <param name="title">The title.</param> /// <param name="maininstruction">The maininstruction.</param> /// <param name="content">The content.</param> /// <param name="expandedinfo">The expandedinfo.</param> /// <param name="promoteIsFirst">if set to <c>true</c> [promote is first].</param> /// <param name="cardbox">The cardbox.</param> /// <param name="boxcount">The boxcount.</param> /// <returns>The dialog result (promote).</returns> /// <remarks>Documented by Dev02, 2008-02-05</remarks> public static bool ShowGradeDialog(string title, string maininstruction, string content, string expandedinfo, bool promoteIsFirst, int cardbox, int boxcount) { int box = cardbox; if (box == 0) { box = 1; //Pool: card goes box 0 --> box 2 } box = (box < (boxcount - 1)) ? ++box : box; EmulatedTaskDialog dialog = new EmulatedTaskDialog(); dialog.Title = title; dialog.MainInstruction = maininstruction; dialog.Content = content; dialog.Buttons = MLifter.Controls.TaskDialogButtons.None; dialog.CommandButtons = promoteIsFirst ? String.Format(Resources.CONFIRM_DEMOTE_BUTTON_PROMOTE, box) + "|" + Resources.CONFIRM_DEMOTE_BUTTON_DEMOTE : Resources.CONFIRM_DEMOTE_BUTTON_DEMOTE + "|" + string.Format(Resources.CONFIRM_DEMOTE_BUTTON_PROMOTE, box); dialog.MainIcon = MLifter.Controls.TaskDialogIcons.Question; dialog.MainImages = promoteIsFirst ? new Image[] { Resources.promoteCard, Resources.demoteCard } : new Image[] { Resources.demoteCard, Resources.promoteCard }; dialog.HoverImages = dialog.MainImages; dialog.CenterImages = true; dialog.BuildForm(); DialogResult dialogResult = dialog.ShowDialog(); bool result = promoteIsFirst ? dialog.CommandButtonClickedIndex == 0 : dialog.CommandButtonClickedIndex == 1; return(result); }
/// <summary> /// Shows the grade confirmation dialog. /// </summary> /// <param name="title">The title.</param> /// <param name="maininstruction">The maininstruction.</param> /// <param name="content">The content.</param> /// <param name="expandedinfo">The expandedinfo.</param> /// <param name="promoteIsFirst">if set to <c>true</c> [promote is first].</param> /// <param name="cardbox">The cardbox.</param> /// <param name="boxcount">The boxcount.</param> /// <returns>The dialog result (promote).</returns> /// <remarks>Documented by Dev02, 2008-02-05</remarks> public static bool ShowGradeDialog(string title, string maininstruction, string content, string expandedinfo, bool promoteIsFirst, int cardbox, int boxcount) { int box = cardbox; if (box == 0) box = 1; //Pool: card goes box 0 --> box 2 box = (box < (boxcount - 1)) ? ++box : box; EmulatedTaskDialog dialog = new EmulatedTaskDialog(); dialog.Title = title; dialog.MainInstruction = maininstruction; dialog.Content = content; dialog.Buttons = MLifter.Controls.TaskDialogButtons.None; dialog.CommandButtons = promoteIsFirst ? String.Format(Resources.CONFIRM_DEMOTE_BUTTON_PROMOTE, box) + "|" + Resources.CONFIRM_DEMOTE_BUTTON_DEMOTE : Resources.CONFIRM_DEMOTE_BUTTON_DEMOTE + "|" + string.Format(Resources.CONFIRM_DEMOTE_BUTTON_PROMOTE, box); dialog.MainIcon = MLifter.Controls.TaskDialogIcons.Question; dialog.MainImages = promoteIsFirst ? new Image[] { Resources.promoteCard, Resources.demoteCard } : new Image[] { Resources.demoteCard, Resources.promoteCard }; dialog.HoverImages = dialog.MainImages; dialog.CenterImages = true; dialog.BuildForm(); DialogResult dialogResult = dialog.ShowDialog(); bool result = promoteIsFirst ? dialog.CommandButtonClickedIndex == 0 : dialog.CommandButtonClickedIndex == 1; return result; }
/// <summary> /// Handles the Click event of the buttonOK control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev03, 2008-12-22</remarks> private void buttonOK_Click(object sender, EventArgs e) { #region NON FEED if (!FeedIsVisible) { foreach (ListViewItem item in listViewLearningModules.SelectedItems) { if (item is LearningModuleListViewItem) { lmItem = item as LearningModuleListViewItem; break; } } if (lmItem != null) { try { LearningModulesIndexEntry entry = lmItem.LearningModule; if (!entry.IsVerified || !entry.IsAccessible) return; #region PgSQL if (entry.Connection is PostgreSqlConnectionStringBuilder) { string serverUri = (entry.Connection as PostgreSqlConnectionStringBuilder).SyncURI; string path = Tools.GetFullSyncPath(entry.DisplayName + MLifter.DAL.Helper.SyncedEmbeddedDbExtension, SyncedLearningModulePath, entry.ConnectionName, entry.UserName); bool createNew = (entry.SyncedPath == string.Empty); ConnectionStringStruct css = entry.ConnectionString; switch ((entry.Connection as PostgreSqlConnectionStringBuilder).SyncType) { case SyncType.NotSynchronized: entry.SyncedPath = string.Empty; entry.ConnectionString = css; break; case SyncType.HalfSynchronizedWithDbAccess: Sync(serverUri, entry.ConnectionString.LmId, entry.UserId, ref path, entry.ConnectionString.ProtectedLm, entry.ConnectionString.Password, createNew, false, (SyncStatusReportingDelegate)SyncStatusUpdate); DownloadExtensionFiles(entry, path); entry.SyncedPath = Tools.GetSyncedPath(path, SyncedLearningModulePath, entry.ConnectionName, entry.UserName); css.SyncType = SyncType.HalfSynchronizedWithDbAccess; css.ServerUser = entry.User; entry.ConnectionString = css; break; case SyncType.HalfSynchronizedWithoutDbAccess: Sync(serverUri, entry.ConnectionString.LmId, entry.UserId, ref path, entry.ConnectionString.ProtectedLm, entry.ConnectionString.Password, createNew, false, (SyncStatusReportingDelegate)SyncStatusUpdate); DownloadExtensionFiles(entry, path); entry.SyncedPath = Tools.GetSyncedPath(path, SyncedLearningModulePath, entry.ConnectionName, entry.UserName); css.SyncType = SyncType.HalfSynchronizedWithoutDbAccess; css.LearningModuleFolder = (entry.Connection as PostgreSqlConnectionStringBuilder).MediaURI; entry.ConnectionString = css; entry.User.Logout(); break; case SyncType.FullSynchronized: if (entry.User == null) break; Sync(serverUri, entry.ConnectionString.LmId, entry.UserId, ref path, entry.ConnectionString.ProtectedLm, entry.ConnectionString.Password, createNew, false, (SyncStatusReportingDelegate)SyncStatusUpdate); DownloadMediaContent(entry, path); DownloadExtensionFiles(entry, path); entry.SyncedPath = Tools.GetSyncedPath(path, SyncedLearningModulePath, entry.ConnectionName, entry.UserName); css.SyncType = SyncType.FullSynchronized; css.LearningModuleFolder = (entry.Connection as PostgreSqlConnectionStringBuilder).MediaURI; entry.ConnectionString = css; SyncedModulesIndex.Add(entry.Connection, entry); SyncedModulesIndex.Dump(Path.Combine(SyncedLearningModulePath, Settings.Default.SyncedModulesFile)); entry.User.Logout(); break; default: throw new NotImplementedException(); } lmIndex.DumpIndexCache(lmIndex.CacheFile); } #endregion #region WEB else if (entry.Connection is WebConnectionStringBuilder) { string serverUri = (entry.Connection as WebConnectionStringBuilder).SyncURI; string path = Tools.GetFullSyncPath(entry.DisplayName + MLifter.DAL.Helper.SyncedEmbeddedDbExtension, SyncedLearningModulePath, entry.ConnectionName, entry.UserName); bool createNew = (entry.SyncedPath == string.Empty); ConnectionStringStruct css = entry.ConnectionString; switch ((entry.Connection as WebConnectionStringBuilder).SyncType) { case SyncType.HalfSynchronizedWithoutDbAccess: Sync(serverUri, entry.ConnectionString.LmId, entry.UserId, ref path, entry.ConnectionString.ProtectedLm, entry.ConnectionString.Password, createNew, false, (SyncStatusReportingDelegate)SyncStatusUpdate); DownloadExtensionFiles(entry, path); entry.SyncedPath = Tools.GetSyncedPath(path, SyncedLearningModulePath, entry.ConnectionName, entry.UserName); css.SyncType = SyncType.HalfSynchronizedWithoutDbAccess; css.ServerUser = entry.User; css.LearningModuleFolder = (entry.Connection as WebConnectionStringBuilder).MediaURI; entry.ConnectionString = css; break; case SyncType.FullSynchronized: if (entry.User == null) break; Sync(serverUri, entry.ConnectionString.LmId, entry.UserId, ref path, entry.ConnectionString.ProtectedLm, entry.ConnectionString.Password, createNew, false, (SyncStatusReportingDelegate)SyncStatusUpdate); DownloadMediaContent(entry, path); DownloadExtensionFiles(entry, path); entry.SyncedPath = Tools.GetSyncedPath(path, SyncedLearningModulePath, entry.ConnectionName, entry.UserName); css.SyncType = SyncType.FullSynchronized; css.ServerUser = entry.User; css.LearningModuleFolder = (entry.Connection as WebConnectionStringBuilder).MediaURI; entry.ConnectionString = css; SyncedModulesIndex.Add(entry.Connection, entry); SyncedModulesIndex.Dump(Path.Combine(SyncedLearningModulePath, Settings.Default.SyncedModulesFile)); break; case SyncType.NotSynchronized: case SyncType.HalfSynchronizedWithDbAccess: default: throw new NotImplementedException(); } lmIndex.DumpIndexCache(lmIndex.CacheFile); } #endregion OnLearningModuleSelected(new LearningModuleSelectedEventArgs(entry)); } catch (NotEnoughtDiskSpaceException) { TaskDialog.MessageBox(Resources.TASK_DIALOG_DISK_FULL_TITLE, Resources.TASK_DIALOG_DISK_FULL_CAPTION, Resources.TASK_DIALOG_DISK_FULL_TEXT, TaskDialogButtons.OK, TaskDialogIcons.Error); } catch (SynchronizationFailedException exp) { Trace.WriteLine(exp.ToString()); TaskDialog.MessageBox(Resources.LEARNING_MODULES_PAGE_SYNC_FAILED_TITLE, Resources.LEARNING_MODULES_PAGE_SYNC_FAILED_MAIN, Resources.LEARNING_MODULES_PAGE_SYNC_FAILED_CONTENT, exp.ToString(), string.Empty, string.Empty, TaskDialogButtons.OK, TaskDialogIcons.Error, TaskDialogIcons.Error); } } } #endregion else { if (listViewFeed.SelectedIndices.Count == 0) return; ModuleInfo info = (ModuleInfo)listViewFeed.SelectedItems[0].Tag; string remoteFile = info.DownloadUrl; string folder = LearningModulesIndex.ConnectionsHandler.ConnectionStrings.Find(c => c.IsDefault).ConnectionString; string localFile = Path.Combine(folder, Methods.GetValidFileName(info.Title + DAL.Helper.EmbeddedDbExtension, String.Empty)); if (File.Exists(localFile)) { EmulatedTaskDialog dialog = new EmulatedTaskDialog(); dialog.Owner = ParentForm; dialog.StartPosition = FormStartPosition.CenterParent; dialog.Title = Resources.LEARNING_MODULES_PAGE_DOWNLOAD_EXISTS_CAPTION; dialog.MainInstruction = Resources.LEARNING_MODULES_PAGE_DOWNLOAD_EXISTS_HEADER; dialog.Content = Resources.LEARNING_MODULES_PAGE_DOWNLOAD_EXISTS_TEXT; dialog.CommandButtons = String.Format("{0}|{1}|{2}", Resources.LEARNING_MODULES_PAGE_DOWNLOAD_EXISTS_OPEN, Resources.LEARNING_MODULES_PAGE_DOWNLOAD_EXISTS_OVERWRITE, Resources.LEARNING_MODULES_PAGE_DOWNLOAD_EXISTS_RENAME); dialog.Buttons = TaskDialogButtons.Cancel; dialog.MainIcon = TaskDialogIcons.Question; dialog.MainImages = new Image[] { Resources.document_open_big, Resources.document_save, Resources.document_save_as }; dialog.HoverImages = new Image[] { Resources.document_open_big, Resources.document_save, Resources.document_save_as }; dialog.CenterImages = true; dialog.BuildForm(); if (dialog.ShowDialog() == DialogResult.Cancel) return; switch (dialog.CommandButtonClickedIndex) { case 0: LearningModulesIndexEntry entry = new LearningModulesIndexEntry(new ConnectionStringStruct(DatabaseType.MsSqlCe, localFile)); OnLearningModuleSelected(new LearningModuleSelectedEventArgs(entry)); return; case 1: lmIndex.EndLearningModulesScan(); disposeAndDisconnectLMs(); File.Delete(localFile); break; case 2: default: int cnt = 1; while (File.Exists(localFile)) localFile = Path.Combine(folder, Methods.GetValidFileName(info.Title + "_" + cnt++ + DAL.Helper.EmbeddedDbExtension, String.Empty)); break; } } info.DownloadUrl = localFile; listViewFeed.SelectedItems[0].Tag = info; WebClient webClient = new WebClient(); webClient.DownloadProgressChanged += (s, args) => { UpdateStatusMessage(String.Format(Resources.LEARNING_MODULES_PAGE_DOWNLOAD_PROGRESS, Methods.GetFileSize(args.BytesReceived), Methods.GetFileSize(args.TotalBytesToReceive)), args.ProgressPercentage); }; webClient.DownloadFileCompleted += (s, args) => { HideStatusMessage(); OnLearningModuleSelected(new LearningModuleSelectedEventArgs(new LearningModulesIndexEntry( new ConnectionStringStruct(DatabaseType.MsSqlCe, localFile)))); }; ShowStatusMessage(message: Resources.LEARNING_MODULES_PAGE_DOWNLOAD_START); webClient.DownloadFileAsync(new Uri(remoteFile), localFile); } }
/// <summary> /// Imports the config file. /// </summary> /// <param name="file">The file.</param> /// <returns>[true] if success.</returns> /// <remarks>Documented by Dev03, 2009-03-11</remarks> private bool ImportConfigFile(string file) { EmulatedTaskDialog dialog = new EmulatedTaskDialog(); dialog.Owner = ParentForm; dialog.StartPosition = FormStartPosition.CenterParent; dialog.Title = Resources.DRAG_CFG_DIALOG_TITLE; dialog.MainInstruction = Resources.DRAG_CFG_DIALOG_MAIN; dialog.Content = Resources.DRAG_CFG_DIALOG_CONTENT; dialog.CommandButtons = Resources.DRAG_CFG_DIALOG_BUTTONS; dialog.Buttons = TaskDialogButtons.None; dialog.MainIcon = TaskDialogIcons.Question; dialog.MainImages = new Image[] { Resources.applications_system, Resources.process_stop }; dialog.HoverImages = new Image[] { Resources.applications_system, Resources.process_stop }; dialog.CenterImages = true; dialog.BuildForm(); DialogResult dialogResult = dialog.ShowDialog(); switch (dialog.CommandButtonClickedIndex) { //Import case 0: int successfulImportedConnections = 0; try { successfulImportedConnections = ConnectionStringHandler.ImportConfigFile(file, GeneralConfigurationPath, UserConfigurationPath); } catch (InvalidConfigFileException) { TaskDialog.MessageBox(Resources.DRAG_INVALID_CFG_FILE_TITLE, Resources.DRAG_INVALID_CFG_FILE_MAININSTRUCTION, Resources.DRAG_INVALID_CFG_FILE_CONTENT, TaskDialogButtons.OK, TaskDialogIcons.Error); return false; } catch (Exception exc) { TaskDialog.MessageBox(Resources.DRAG_CFG_GENERAL_ERROR_TITLE, Resources.DRAG_CFG_GENERAL_ERROR_MAININSTRUCTION, exc.Message, exc.ToString(), string.Empty, string.Empty, TaskDialogButtons.OK, TaskDialogIcons.Error, TaskDialogIcons.Error); return false; } if (successfulImportedConnections <= 0) TaskDialog.MessageBox(Resources.DRAG_CFG_SUCCESS_TITLE, Resources.DRAG_CFG_SUCCESS_MAIN_NOTHING_IMPORTED, Resources.DRAG_CFG_SUCCESS_MAIN_NOTHING_IMPORTED_DETAIL, TaskDialogButtons.OK, TaskDialogIcons.Information); else if (successfulImportedConnections == 1) TaskDialog.MessageBox(Resources.DRAG_CFG_SUCCESS_TITLE, Resources.DRAG_CFG_SUCCESS_MAIN, Resources.DRAG_CFG_SUCCESS_CONTENT_SING, TaskDialogButtons.OK, TaskDialogIcons.Information); else TaskDialog.MessageBox(Resources.DRAG_CFG_SUCCESS_TITLE, Resources.DRAG_CFG_SUCCESS_MAIN, string.Format(Resources.DRAG_CFG_SUCCESS_CONTENT_PLUR, successfulImportedConnections), TaskDialogButtons.OK, TaskDialogIcons.Information); return (successfulImportedConnections > 0); //Cancel case 1: default: return false; } }