コード例 #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="WelcomeToFieldWorksDlg"/> class.
		/// </summary>
		/// <param name="helpTopicProvider">Help topic provider</param>
		/// <param name="appAbbrev">Standard application abbreviation.</param>
		/// <param name="exception">Exception that was thrown if the previously requested
		/// project could not be opened.</param>
		/// <param name="showReportingRow">True (usually only on the first run) when we want to show the first-time warning about
		/// sending google analytics information</param>
		/// ------------------------------------------------------------------------------------
		public WelcomeToFieldWorksDlg(IHelpTopicProvider helpTopicProvider, string appAbbrev, StartupException exception, bool showReportingRow)
		{
			m_appAbbrev = appAbbrev;
			InitializeComponent();
			AccessibleName = GetType().Name;
			var fullAppName = AppIsFlex ? Properties.Resources.kstidFLEx : Properties.Resources.kstidTE;
			SetCheckboxText = fullAppName;  // Setter uses the app name in a format string.

			if (exception == null || !exception.ReportToUser)
			{
				Text = fullAppName;
				Logger.WriteEvent("Opening 'Welcome to FieldWorks' dialog");
			}
			else
			{
				m_helpTopic = "khtpUnableToOpenProject";
				Text = Properties.Resources.kstidUnableToOpenProjectCaption;
				m_lblProjectLoadError.Text = exception.Message;
				Logger.WriteEvent("Opening 'Unable to Open Project' dialog");
			}

			if (!showReportingRow)
			{
				reportingInfoLayout.Visible = false;
			}

			m_helpTopicProvider = helpTopicProvider;
			helpProvider = new HelpProvider();
			helpProvider.HelpNamespace = FwDirectoryFinder.CodeDirectory + m_helpTopicProvider.GetHelpString("UserHelpFile");
			helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(m_helpTopic));
			helpProvider.SetHelpNavigator(this, HelpNavigator.Topic);
			receiveButton.Enabled =
				ClientServerServices.Current.Local.DefaultBackendType != FDOBackendProviderType.kDb4oClientServer &&
					FLExBridgeHelper.IsFlexBridgeInstalled();
		}
コード例 #2
0
ファイル: FieldWorks.cs プロジェクト: sillsdev/FieldWorks
		/// <summary>
		/// Returns true if valid command-line args created this projectId.
		/// Returns false with no exception if no -db arg was given.
		/// Returns false with exception if invalid args were given.
		/// </summary>
		/// <param name="projId"></param>
		/// <param name="exception"></param>
		/// <returns></returns>
		private static bool TryCommandLineOption(ProjectId projId, out StartupException exception)
		{
			exception = null;
			if (string.IsNullOrEmpty(projId.Name))
				return false;
			var ex = projId.GetExceptionIfInvalid();
			if (ex is StartupException)
			{
				exception = (StartupException) ex;
				return false; // Invalid command-line arguments supplied.
			}
			if (ex == null)
				return true; // If valid command-line arguments are supplied, we go with that.
			throw ex; // Something totally unexpected happened, don't suppress it.
		}
コード例 #3
0
ファイル: FieldWorks.cs プロジェクト: sillsdev/FieldWorks
		private static ProjectId ShowWelcomeDialog(FwAppArgs args, FwApp startingApp, ProjectId lastProjectId, StartupException exception)
		{
			CloseSplashScreen();

			var helpTopicProvider = startingApp as IHelpTopicProvider;

			// Use the last edited project as the base guess for which project we'll open.
			var projectToTry = lastProjectId;

			// Continue to ask for an option until one is selected.
			s_fWaitingForUserOrOtherFw = true;
			do
			{
				if (exception != null)
				{
					if (projectToTry != null)
						Logger.WriteEvent("Problem opening " + projectToTry.UiName + ".");
					Logger.WriteError(exception);
				}

				// Put this here (i.e. inside the do loop) so any exceptions
				// will be logged before terminating.
				if (s_noUserInterface)
					return null;

				// If we changed our projectToTry below and we're coming through again,
				// reset our projectId.
				projectToTry = lastProjectId;

				using (WelcomeToFieldWorksDlg dlg = new WelcomeToFieldWorksDlg(helpTopicProvider, args.AppAbbrev, exception, s_noPreviousReportingSettings))
				{
					if (exception != null)
					{
						dlg.ShowErrorLabelHideLink();
					}
					else
					{
						if (projectToTry != null && projectToTry.IsValid)
						{
							dlg.ProjectLinkUiName = projectToTry.Name;
							dlg.SetFirstOrLastProjectText(false);
						}
						else
						{
							var sampleProjId = GetSampleProjectId(startingApp);
							if (sampleProjId != null)
							{
								dlg.ProjectLinkUiName = sampleProjId.Name;
								dlg.SetFirstOrLastProjectText(true);
								// LT-13943 - forgot to set this variable, which made it not be able to open
								// the sample db.
								projectToTry = new ProjectId(startingApp.SampleDatabase, null);
							}
							else // user didn't install Sena 3!
							{
								projectToTry = null;
							}
						}
						if (projectToTry != null)
							dlg.ShowLinkHideErrorLabel();
						else
							dlg.ShowErrorLabelHideLink();
					}
					bool gotAutoOpenSetting = false;
					if (startingApp.RegistrySettings != null) // may be null if disposed after canceled restore.
					{
					dlg.OpenLastProjectCheckboxIsChecked = GetAutoOpenRegistrySetting(startingApp);
						gotAutoOpenSetting = true;
					}
					dlg.StartPosition = FormStartPosition.CenterScreen;
					dlg.ShowDialog();
					exception = null;
					// We get the app each time through the loop because a failed Restore operation can dispose it.
					var app = GetOrCreateApplication(args);
					if (gotAutoOpenSetting)
					app.RegistrySettings.AutoOpenLastEditedProject = dlg.OpenLastProjectCheckboxIsChecked;
					switch (dlg.DlgResult)
					{
						case WelcomeToFieldWorksDlg.ButtonPress.New:
							projectToTry = CreateNewProject(dlg, app, helpTopicProvider);
							Debug.Assert(projectToTry == null || projectToTry.IsValid);
							break;
						case WelcomeToFieldWorksDlg.ButtonPress.Open:
							projectToTry = ChooseLangProject(null, helpTopicProvider);
							try
							{
								if (projectToTry != null)
									projectToTry.AssertValid();
							}
							catch (StartupException e)
							{
								exception = e;
							}
							break;
						case WelcomeToFieldWorksDlg.ButtonPress.Link:
							// LT-13943 - this guard keeps the projectToTry from getting blasted by a null when it has
							// a useful projectId (like the initial sample db the first time FLEx is run).
							if (lastProjectId != null && !lastProjectId.Equals(projectToTry))
								projectToTry = lastProjectId; // just making sure!
							Debug.Assert(projectToTry.IsValid);
							break;
						case WelcomeToFieldWorksDlg.ButtonPress.Restore:
							s_allowFinalShutdown = false;
							RestoreProject(null, app);
							s_allowFinalShutdown = true;
							projectToTry = s_projectId; // Restore probably used this process
							break;
						case WelcomeToFieldWorksDlg.ButtonPress.Exit:
							return null; // Should cause the FW process to exit later
						case WelcomeToFieldWorksDlg.ButtonPress.Receive:
							if (!FwNewLangProject.CheckProjectDirectory(null, helpTopicProvider))
								break;
							ObtainedProjectType obtainedProjectType;
							projectToTry = null; // If the user cancels the send/receive, this null will result in a return to the welcome dialog.
							// Hard to say what Form.ActiveForm is here. The splash and welcome dlgs are both gone.
							var projectDataPathname = ObtainProjectMethod.ObtainProjectFromAnySource(Form.ActiveForm,
								helpTopicProvider, out obtainedProjectType);
							if (!string.IsNullOrEmpty(projectDataPathname))
							{
								projectToTry = new ProjectId(FDOBackendProviderType.kXML, projectDataPathname, null);
								var activeWindow = startingApp.ActiveMainWindow;
								if (activeWindow != null)
								{
									((IFwMainWnd)activeWindow).Mediator.PropertyTable.SetProperty("LastBridgeUsed",
										obtainedProjectType == ObtainedProjectType.Lift ? "LiftBridge" : "FLExBridge",
										PropertyTable.SettingsGroup.LocalSettings);
								}
							}
							break;
						case WelcomeToFieldWorksDlg.ButtonPress.Import:
							projectToTry = CreateNewProject(dlg, app, helpTopicProvider);
							if (projectToTry != null)
							{
							var projectLaunched = LaunchProject(args, ref projectToTry);
								if (projectLaunched)
							{
								s_projectId = projectToTry; // Window is open on this project, we must not try to initialize it again.
								var mainWindow = Form.ActiveForm;
									if (mainWindow is IxWindow)
								{
										((IxWindow) mainWindow).Mediator.SendMessage("SFMImport", null);
								}
								else
								{
									return null;
								}
							}
							else
							{
								return null;
							}
							}
							break;
					}
				}
			}
			while (projectToTry == null || !projectToTry.IsValid);

			Logger.WriteEvent("Project selected in Welcome dialog: " + projectToTry);

			s_fWaitingForUserOrOtherFw = false;
			return projectToTry;
		}
コード例 #4
0
ファイル: FieldWorks.cs プロジェクト: sillsdev/FieldWorks
		private static ProjectId DetermineProject(FwAppArgs args)
		{
			// Get project information from one of four places, in this order of preference:
			// 1. Command-line arguments
			// 2. Sample DB (if this is the first time this app has been run)
			// 3. Registry (if last startup was successful)
			// 4. Ask the user
			//
			// Except that with the new Welcome dialog, 2 through 4 are lumped into the Welcome dialog
			// functionality. If the user checks the "...always open the last edited project..." checkbox,
			// we will try to do that and only show the dialog if we fail.
			// If we try to use command-line arguments and it fails, we will use the Welcome dialog
			// to help the user figure out what to do next.
			var projId = new ProjectId(args.DatabaseType, args.Database, args.Server);
			StartupException projectOpenError;
			if (TryCommandLineOption(projId, out projectOpenError))
				return projId;

			// If this app hasn't been run before, ask user about opening sample DB.
			var app = GetOrCreateApplication(args);
			if (app.RegistrySettings.FirstTimeAppHasBeenRun)
				return ShowWelcomeDialog(args, app, null, projectOpenError);

			// Valid project information was not passed on the command-line, so try looking in
			// the registry for the last-run project.
			var previousStartupStatus = GetPreviousStartupStatus(app);
			var latestProject = app.RegistrySettings.LatestProject;
			if ((String.IsNullOrEmpty(projId.Name) || projectOpenError != null) &&
				previousStartupStatus != StartupStatus.Failed && !String.IsNullOrEmpty(latestProject))
			{
				// User didn't specify a project or gave bad command-line args,
				// so set projId to the last successfully opened project.
				projId = GetBestGuessProjectId(latestProject, app.RegistrySettings.LatestServer);
			}
			else if (previousStartupStatus == StartupStatus.Failed && !string.IsNullOrEmpty(latestProject))
			{
				// The previous project failed to open, so notify the user.
				projectOpenError = new StartupException(String.Format(
					Properties.Resources.kstidUnableToOpenLastProject, app.ApplicationName,
					latestProject));
			}

			var fOpenLastEditedProject = GetAutoOpenRegistrySetting(app);

			if (fOpenLastEditedProject && projId.IsValid && projectOpenError == null
				&& previousStartupStatus == StartupStatus.Successful)
				return projId;

			// No valid command line args, not the first time we've run the program,
			// and we aren't set to auto-open the last project, so give user options to open/create a project.
			return ShowWelcomeDialog(args, app, projId, projectOpenError);
		}