/// <summary></summary> public override void FixtureTeardown() { base.FixtureTeardown(); if (myCache != null) { ProjectLockingService.UnlockCurrentProject(myCache); File.Copy(SavedTestFile, TestFile, true); } }
public bool OnFLExBridge(object commandObject) { _mediator.PropertyTable.SetProperty("LastBridgeUsed", "FLExBridge", PropertyTable.SettingsGroup.LocalSettings); if (IsDb4oProject) { var dlg = new Db4oSendReceiveDialog(); if (dlg.ShowDialog() == DialogResult.Abort) { // User clicked on link _mediator.SendMessage("FileProjectSharingLocation", null); } return(true); } if (ChangeProjectNameIfNeeded()) { return(true); } string url; var projectFolder = Cache.ProjectId.ProjectFolder; var savedState = PrepareToDetectConflicts(projectFolder); string dummy; var fullProjectFileName = Path.Combine(projectFolder, Cache.ProjectId.Name + FwFileExtensions.ksFwDataXmlFileExtension); bool dataChanged; var success = FLExBridgeHelper.LaunchFieldworksBridge(fullProjectFileName, Environment.UserName, FLExBridgeHelper.SendReceive, null, out dataChanged, out dummy); if (!success) { ReportDuplicateBridge(); ProjectLockingService.LockCurrentProject(Cache); return(true); } if (dataChanged) { var fixer = new FwDataFixer(Cache.ProjectId.Path, new StatusBarProgressHandler(null, null), logger); fixer.FixErrorsAndSave(); bool conflictOccurred = DetectConflicts(projectFolder, savedState); var app = (LexTextApp)_mediator.PropertyTable.GetValue("App"); var newAppWindow = RefreshCacheWindowAndAll(app, fullProjectFileName); if (conflictOccurred) { //send a message for the reopened instance to display the conflict report, we have been disposed by now newAppWindow.Mediator.SendMessage("ShowConflictReport", null); } } else //Re-lock project if we aren't trying to close the app { ProjectLockingService.LockCurrentProject(Cache); } return(true); }
private void btnOk_Click(Object sender, EventArgs e) { if (radioRestore.Checked) { textBoxProjectName.Text = textBoxProjectName.Text.Trim(); if (!DoRestore()) { return; } } else { m_selectedItem = (LanguageProjectInfo)listBox.SelectedItem; if (!m_fdoCacheCache.Contains(m_selectedItem.ToString()) && ProjectLockingService.IsProjectLocked(m_selectedItem.FullName)) { MessageBox.Show(this, Strings.ksProjectOpen, Strings.ksErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } DialogResult = DialogResult.OK; Close(); }
/// <summary> /// Create a new Fieldworks project and import a lift file into it. Return the .fwdata path. /// </summary> private static string CreateProjectFromLift(Form parent, IHelpTopicProvider helpTopicProvider, string liftPath) { string projectPath; FdoCache cache; var anthroListFile = CallPickAnthroList(helpTopicProvider); using (var progressDlg = new ProgressDialogWithTask(parent)) { progressDlg.Title = FwControls.ksCreatingLiftProject; var cacheReceiver = new FdoCache[1]; // a clumsy way of handling an out parameter, consistent with RunTask projectPath = (string)progressDlg.RunTask(true, CreateProjectTask, new object[] { liftPath, parent, anthroListFile, cacheReceiver }); cache = cacheReceiver[0]; } CallImportObtainedLexicon(cache, liftPath, parent); ProjectLockingService.UnlockCurrentProject(cache); // finish all saves and completely write the file so we can proceed to open it cache.Dispose(); return(projectPath); }
/// <summary> /// Create a new Fieldworks project and import a lift file into it. Return the .fwdata path. /// </summary> /// <param name="liftPath"></param> public string CreateProjectFromLift(string liftPath) { var projectName = Path.GetFileNameWithoutExtension(liftPath); var parentFolder = Path.GetDirectoryName(liftPath); string flexFolderName = Path.Combine(DirectoryFinder.ProjectsDirectory, projectName); if (!Directory.Exists(flexFolderName)) { throw new ArgumentException("The lift file is not in a folder within the corresponding Project folder"); } string projectPath; FdoCache cache; using (var helper = new ThreadHelper()) using (var progressDlg = new ProgressDialogWithTask(this, helper)) { progressDlg.ProgressBarStyle = ProgressBarStyle.Continuous; progressDlg.Title = FwCoreDlgs.ksCreatingLiftProject; var cacheReceiver = new FdoCache[1]; // a clumsy way of handling an out parameter, consistent with RunTask projectPath = (string)progressDlg.RunTask(true, CreateProjectTask, new object[] { liftPath, projectName, helper, cacheReceiver }); cache = cacheReceiver[0]; } // this is a horrible way to invoke this, but current project organization does not allow us to reference // the LexEdDll project, nor is there any straightforward way to move the code we need into some project we can // reference, or any obviously suitable project to move it to without creating other References loops. // One nasty reflection call seems less technical debt than creating an otherwise unnecessary project. // (It puts up its own progress dialog.) ReflectionHelper.CallStaticMethod(@"LexEdDll.dll", @"SIL.FieldWorks.XWorks.LexEd.FLExBridgeListener", @"ImportObtainedLexicon", cache, liftPath, this); ProjectLockingService.UnlockCurrentProject(cache); // finish all saves and completely write the file so we can proceed to open it cache.Dispose(); return(projectPath); }
private bool ChangeProjectNameIfNeeded() { ProjectLockingService.UnlockCurrentProject(Cache); // Enhance GJM: When Hg is upgraded to work with non-Ascii filenames, this section can be removed. if (Unicode.CheckForNonAsciiCharacters(Cache.ProjectId.Name)) { var revisedProjName = Unicode.RemoveNonAsciiCharsFromString(Cache.ProjectId.Name); if (revisedProjName == string.Empty) { return(true); // The whole pre-existing project name is non-Ascii characters! } if (DisplayNonAsciiWarning(revisedProjName) == DialogResult.Cancel) { return(true); } // Rename Project var projectFolder = RevisedProjectFolder(Cache.ProjectId.ProjectFolder, revisedProjName); if (CheckForExistingFileName(projectFolder, revisedProjName)) { return(true); } var app = (LexTextApp)_mediator.PropertyTable.GetValue("App"); if (app.FwManager.RenameProject(revisedProjName, app)) { // Continuing straight on from here renames the db on disk, but not in the cache, apparently // Try a more indirect approach... var fullProjectFileName = Path.Combine(projectFolder, revisedProjName + FwFileExtensions.ksFwDataXmlFileExtension); var tempWindow = RefreshCacheWindowAndAll(app, fullProjectFileName); tempWindow.Mediator.SendMessageDefered("FLExBridge", null); // to hopefully come back here after resetting things } return(true); } return(false); }