Exemple #1
0
 /// <summary></summary>
 public override void FixtureTeardown()
 {
     base.FixtureTeardown();
     if (myCache != null)
     {
         ProjectLockingService.UnlockCurrentProject(myCache);
         File.Copy(SavedTestFile, TestFile, true);
     }
 }
        /// <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);
        }
Exemple #4
0
        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);
        }