コード例 #1
0
        private void SaveAndDisposeProject()
        {
            try
            {
                if (Project != null)
                {
                    Project.Save();
                }

                Settings.Default.Save();
                if (_projectSettingsControl != null)
                {
                    _projectSettingsControl.Dispose();
                }
                if (Project != null)
                {
                    _project.Dispose();
                }
            }
            catch (Exception error)
            {
                //would make it impossible to quit. e.Cancel = true;
                ErrorReport.NotifyUserOfProblem(error.Message);
            }
            Project = null;
        }
コード例 #2
0
ファイル: WeSayApp.cs プロジェクト: sillsdev/wesay
        private static WeSayWordsProject InitializeProject(string liftPath)
        {
            var project = new WeSayWordsProject();

            liftPath = DetermineActualLiftPath(liftPath);
            if (liftPath == null)
            {
                MessageBox.Show(StringCatalog.Get("Welcome to WeSay.\r\nThe Configuration Tool will now open so that you can make a new project or choose an existing one."), StringCatalog.Get("No Default Project", "The label on the message box which the user sees if WeSay can't figure out what project to open."), MessageBoxButtons.OK, MessageBoxIcon.Information);
                RunConfigTool();
                return(null);
            }

            liftPath = project.UpdateFileStructure(liftPath);

            if (project.LoadFromLiftLexiconPath(liftPath))
            {
                Settings.Default.PreviousLiftPath = liftPath;
            }
            else
            {
                return(null);
            }

            try
            {
                project.MigrateConfigurationXmlIfNeeded();
            }
            catch
            {
                ErrorReport.NotifyUserOfProblem(
                    "WeSay was unable to migrate the WeSay configuration file for the new version of WeSay. This may cause WeSay to not function properly. Try opening the project in the WeSay Configuration Tool to fix this.");
            }

            return(project);
        }
コード例 #3
0
 public void CreateDefaultProject()
 {
     new WeSayWordsProject();
     WeSayWordsProject.CreateEmptyProjectFiles(Path);
     WeSayWordsProject.Project.LoadFromProjectDirectoryPath(Path);
     WeSayWordsProject.Project.Save();
 }
コード例 #4
0
 public void Setup()
 {
     WeSayProjectTestHelper.InitializeForTests();
     _destinationZip    = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".zip");
     _sourceProjectPath = BasilProject.GetPretendProjectDirectory();
     _backupMaker       = new BackupMaker();
     _filesToBackup     = WeSayWordsProject.GetFilesBelongingToProject(_sourceProjectPath);
 }
コード例 #5
0
        public WeSayWordsProject CreateLoadedProject()
        {
            var p = new WeSayWordsProject();

            p.LoadFromLiftLexiconPath(PathToLiftFile);

            return(p);
        }
コード例 #6
0
ファイル: TabbedFormTests.cs プロジェクト: sillsdev/wesay
        public void TestFixtureSetUp()
        {
            _project = new WeSayWordsProject();
            _project.UiOptions.Language = "en";
            _project.LoadFromProjectDirectoryPath(BasilProject.GetPretendProjectDirectory());

            _project.Tasks = new List <ITask>();
        }
コード例 #7
0
        public static WeSayWordsProject InitializeForTests()
        {
            WeSayWordsProject project = new WeSayWordsProject();

            try
            {
                File.Delete(WeSayWordsProject.PathToPretendLiftFile);
            }
            catch (Exception) { }
            DirectoryInfo projectDirectory   = Directory.CreateDirectory(Path.GetDirectoryName(WeSayWordsProject.PathToPretendLiftFile));
            string        pathToLdmlWsFolder = BasilProject.GetPathToLdmlWritingSystemsFolder(projectDirectory.FullName);

            if (File.Exists(WeSayWordsProject.PathToPretendWritingSystemPrefs))
            {
                File.Delete(WeSayWordsProject.PathToPretendWritingSystemPrefs);
            }

            if (Directory.Exists(pathToLdmlWsFolder))
            {
                Directory.Delete(pathToLdmlWsFolder, true);
            }

            Palaso.Lift.Utilities.CreateEmptyLiftFile(WeSayWordsProject.PathToPretendLiftFile, "InitializeForTests()", true);

            //setup writing systems
            Directory.CreateDirectory(pathToLdmlWsFolder);
            IWritingSystemRepository wsc = LdmlInFolderWritingSystemRepository.Initialize(
                pathToLdmlWsFolder,
                OnMigrationHandler,
                OnWritingSystemLoadProblem,
                WritingSystemCompatibility.Flex7V0Compatible
                );

            IWritingSystemDefinition _ws1 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.VernacularIdForTest);

            _ws1.DefaultFontName = "Arial";
            _ws1.DefaultFontSize = 30;
            wsc.Set(_ws1);
            IWritingSystemDefinition _ws2 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.AnalysisIdForTest);

            _ws2.DefaultFontName = new Font(FontFamily.GenericSansSerif, 12).Name;
            _ws2.DefaultFontSize = new Font(FontFamily.GenericSansSerif, 12).Size;
            wsc.Set(_ws2);
            IWritingSystemDefinition _ws3 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.OtherIdForTest);

            _ws3.DefaultFontName = "Arial";
            _ws3.DefaultFontSize = 15;
            wsc.Set(_ws3);


            wsc.Save();

            project.SetupProjectDirForTests(WeSayWordsProject.PathToPretendLiftFile);
            project.BackupMaker = null;            //don't bother. Modern tests which might want to check backup won't be using this old approach anyways.
            return(project);
        }
コード例 #8
0
		public void UpdateFileStructure_LiftByItself_DoesNothing()
		{
			using (TemporaryFolder f = new TemporaryFolder("OpeningLiftFile_MissingConfigFile_GivesMessage"))
			{
				using(TempLiftFile lift = new TempLiftFile(f, "", "0.12"))
				{
					using(WeSayWordsProject p = new WeSayWordsProject())
					{
						Assert.AreEqual(lift.Path,p.UpdateFileStructure(lift.Path));
					}
				}
			}
		}
コード例 #9
0
 private static void CreateNewProject(string directoryPath)
 {
     try
     {
         WeSayWordsProject.CreateEmptyProjectFiles(directoryPath);
     }
     catch (Exception e)
     {
         ErrorReport.NotifyUserOfProblem(
             "WeSay was not able to create a project there. \r\n" + e.Message);
         return;
     }
 }
コード例 #10
0
        public void Setup()
        {
            _projectDir = new ProjectDirectorySetupForTesting("");
            _project    = _projectDir.CreateLoadedProject();
            _project.WritingSystems.Set(WritingSystemDefinition.Parse("fr"));
            _repo  = _project.GetLexEntryRepository();
            _entry = _repo.CreateItem();
            _entry.LexicalForm.SetAlternative("qaa-x-qaa", "apple");


            _project.DefaultPrintingTemplate.GetField(LexSense.WellKnownProperties.Definition).WritingSystemIds.Add("fr");
            _project.DefaultPrintingTemplate.GetField(LexExampleSentence.WellKnownProperties.Translation).WritingSystemIds.Add("fr");

            _project.DefaultPrintingTemplate.GetField(LexEntry.WellKnownProperties.CrossReference).Enabled = true;
        }
コード例 #11
0
ファイル: OdfTransformerTests.cs プロジェクト: sillsdev/wesay
            public EnvironmentForTest()
            {
                ErrorReport.IsOkToInteractWithUser = false;
                const string xmlOfEntries = @" <entry id='foo1'>
						<lexical-unit><form lang='qaa-x-qaa'><text>hello</text></form></lexical-unit>
					</entry>"                    ;

                _testProject = new ProjectDirectorySetupForTesting(xmlOfEntries);
                _project     = _testProject.CreateLoadedProject();
                _projectInfo = _project.GetProjectInfoForAddin();

                string sourceTemplateDir = Path.Combine(_projectInfo.PathToApplicationRootDirectory, String.Format("..{0}..{0}templates", Path.DirectorySeparatorChar));

                TestUtilities.DeleteFolderThatMayBeInUse(OutputTemplateDir);
                CopyFolder(sourceTemplateDir, OutputTemplateDir);
            }
コード例 #12
0
 public void ReadListFile_NonExistantSemanticDomainFile_Throws()
 {
     using (var projectDirectory = new TemporaryFolder())
     {
         if (File.Exists(Path.Combine(BasilProject.GetPretendProjectDirectory(), "SemDom.xml")))
         {
             File.Delete(Path.Combine(BasilProject.GetPretendProjectDirectory(), "SemDom.xml"));
         }
         //setting up a minimal WeSay project with a config file that contains an id for a nonexistent writing system
         var project       = new WeSayWordsProject();
         var localizedList = new LocalizedListParser();
         localizedList.ApplicationCommonDirectory = BasilProject.GetPretendProjectDirectory();
         localizedList.PathToWeSaySpecificFilesDirectoryInProject = projectDirectory.Path;
         localizedList.SemanticDomainWs = "en";
         Assert.Throws <ApplicationException>(() => localizedList.ReadListFile());
     }
 }
コード例 #13
0
ファイル: SampleTaskBuilder.cs プロジェクト: sillsdev/wesay
        public SampleTaskBuilder(WeSayWordsProject project, ICurrentWorkTask currentWorkTask, IRecordListManager recordListManager)
        {
            _picoContext = CreateContainer();
            _picoContext.RegisterComponentInstance("Project", project);
            _picoContext.RegisterComponentInstance("Current Task Provider", currentWorkTask);
            _picoContext.RegisterComponentInstance("Record List Manager", recordListManager);

            string[]     analysisWritingSystemIds   = new string[] { project.WritingSystems.AnalysisWritingSystemDefaultId };
            string[]     vernacularWritingSystemIds = new string[] { project.WritingSystems.VernacularWritingSystemDefaultId };
            ViewTemplate viewTemplate = new ViewTemplate();

            viewTemplate.Add(new Field(Field.FieldNames.EntryLexicalForm.ToString(), vernacularWritingSystemIds));
            viewTemplate.Add(new Field(Field.FieldNames.SenseGloss.ToString(), analysisWritingSystemIds));
            viewTemplate.Add(new Field(Field.FieldNames.ExampleSentence.ToString(), vernacularWritingSystemIds));
            viewTemplate.Add(new Field(Field.FieldNames.ExampleTranslation.ToString(), analysisWritingSystemIds));
            _picoContext.RegisterComponentInstance("Default Field Inventory", viewTemplate);
        }
コード例 #14
0
 public void ParseSemDomXMLFile()
 {
     using (var projectDirectory = new TemporaryFolder())
     {
         //setting up a minimal WeSay project with a config file that contains an id for a nonexistent writing system
         var project       = new WeSayWordsProject();
         var localizedList = new LocalizedListParser();
         localizedList.ApplicationCommonDirectory = WeSayWordsProject.Project.ApplicationTestDirectory;
         localizedList.PathToWeSaySpecificFilesDirectoryInProject = projectDirectory.Path;
         localizedList.SemanticDomainWs = "en";
         Assert.AreEqual(106, localizedList.ReadListFile());
         Assert.AreEqual(106, localizedList.Keys.Count);
         Assert.AreEqual(106, localizedList.QuestionDictionary.Count);
         Assert.AreEqual(9, localizedList.QuestionDictionary[localizedList.Keys[1]].Count);
         Assert.AreEqual("(1) What words are used to refer to the sky? (sky, firmament, canopy, vault)",
                         localizedList.QuestionDictionary[localizedList.Keys[1]][0]);
     }
 }
コード例 #15
0
 public void ParseLocalizedListXMLFile()
 {
     using (var projectDirectory = new TemporaryFolder())
     {
         //setting up a minimal WeSay project with a config file that contains an id for a nonexistent writing system
         var project       = new WeSayWordsProject();
         var localizedList = new LocalizedListParser();
         localizedList.ApplicationCommonDirectory = WeSayWordsProject.Project.ApplicationTestDirectory;
         localizedList.PathToWeSaySpecificFilesDirectoryInProject = projectDirectory.Path;
         localizedList.SemanticDomainWs = "fr";
         Assert.AreEqual(1792, localizedList.ReadListFile());
         Assert.AreEqual(1792, localizedList.Keys.Count);
         Assert.AreEqual(1792, localizedList.QuestionDictionary.Count);
         Assert.AreEqual(9, localizedList.QuestionDictionary[localizedList.Keys[1]].Count);
         Assert.AreEqual("(1) Quels sont les mots ou expressions qui font référence au ciel ? (ciel, firmament, céleste, voûte céleste, l’azur (poétique))",
                         localizedList.QuestionDictionary[localizedList.Keys[1]][0]);
     }
 }
コード例 #16
0
        public ProjectDirectorySetupForTesting(string xmlOfEntries, string liftVersion)
        {
            _testFolder        = new TemporaryFolder("WeSayProjectTest");
            _projectRootFolder = new TemporaryFolder(_testFolder, ProjectFolder);
            WeSayWordsProject.CreateEmptyProjectFiles(_projectRootFolder.Path, ProjectName);

            //overwrite the blank lift file
            string liftContents =
                string.Format(
                    "<?xml version='1.0' encoding='utf-8'?><lift version='{0}'>{1}</lift>",
                    liftVersion,
                    xmlOfEntries);

            File.WriteAllText(PathToLiftFile, liftContents);

            // liftSynchronizerAdjunct requires some lift-ranges file
            File.WriteAllText(Path.ChangeExtension(PathToLiftFile, "lift-ranges"), @"<?xml version='1.0' encoding='utf-8'?>
<lift-ranges/>");
        }
コード例 #17
0
        public void Setup()
        {
            string entriesXml =
                @"<entry id='foo1'><lexical-unit><form lang='qaa-x-qaa'><text>fooOne</text></form></lexical-unit></entry>
								<entry id='foo2'><lexical-unit><form lang='qaa-x-qaa'><text>fooTwo</text></form></lexical-unit></entry>
								<entry id='foo3'><lexical-unit><form lang='qaa-x-qaa'><text>fooThree</text></form></lexical-unit></entry>"                                ;

            _projectDirectory = new ProjectDirectorySetupForTesting(entriesXml);

            _project = new WeSayWordsProject();
            _project.LoadFromLiftLexiconPath(_projectDirectory.PathToLiftFile);
            _tabbedForm    = new TabbedForm(new NullStatusBarController());
            _project.Tasks = new List <ITask>();
            _dashboardTask = new MockTask("Dashboard", "The control center.", true);
            _project.Tasks.Add(_dashboardTask);
            _dictionaryTask = new MockDictionaryTask("Dictionary blah blah", "The whole lexicon.", true);
            _project.Tasks.Add(_dictionaryTask);

            _tabbedForm.InitializeTasks(_project.Tasks);
        }
コード例 #18
0
ファイル: FullUIAppTests.cs プロジェクト: bbriggs/wesay
		public override void Setup()
		{
			base.Setup();
			this.tabbedForm = new TabbedForm();
			this.tabbedForm.Show();
			string name = new Finder().Name(this.tabbedForm);
			_mainWindowTester = new FormTester(name);


			_project = new WeSayWordsProject();
			_project.StringCatalogSelector = "en";
			_project.LoadFromProjectDirectoryPath(WeSayWordsProject.GetPretendProjectDirectory());
			_project.Tasks = new List<ITask>();
			_project.Tasks.Add(new MockTask("Dashboard", "The control center.", true));


			_lexEntryRepository = new InMemoryRecordListManager();
			LexEntry entry = new LexEntry();
			_lexEntryRepository.Get<LexEntry>().Add(entry);
			_project.Tasks.Add(new WeSay.LexicalTools.EntryDetailTask(_lexEntryRepository));

		}
コード例 #19
0
ファイル: FullUIAppTests.cs プロジェクト: sillsdev/wesay
		public override void Setup()
		{
			base.Setup();
			this.tabbedForm = new TabbedForm();
			this.tabbedForm.Show();
			string name = new Finder().Name(this.tabbedForm);
			_mainWindowTester = new FormTester(name);


			_project = new WeSayWordsProject();
			_project.UiOptions.Language = "en";
			_project.LoadFromProjectDirectoryPath(WeSayWordsProject.GetPretendProjectDirectory());
			_project.Tasks = new List<ITask>();
			_project.Tasks.Add(new MockTask("Dashboard", "The control center.", true));


			_lexEntryRepository = new InMemoryRecordListManager();
			LexEntry entry = new LexEntry();
			_lexEntryRepository.Get<LexEntry>().Add(entry);
			_project.Tasks.Add(new WeSay.LexicalTools.EntryDetailTask(_lexEntryRepository));

		}
コード例 #20
0
ファイル: WeSayApp.cs プロジェクト: sillsdev/wesay
        public void Run()
        {
            DisplaySettings.Default.SkinName = Settings.Default.SkinName;

            using (_project = InitializeProject(_commandLineArguments.liftPath))
            {
                if (_project == null)
                {
                    return;
                }


                if (!GrabTokenForThisProject(_project.PathToLiftFile))
                {
                    return;
                }

                LexEntryRepository repository;
                try
                {
                    repository = GetLexEntryRepository();
                }
                catch (LiftFormatException)
                {
                    return;                             //couldn't load, and we've already told the user
                }
                WireUpChorusEvents();
                StartUserInterface();

                //do a last backup before exiting
                Logger.WriteEvent("App Exiting Normally.");
            }
            _project.BackupNow();

            Logger.ShutDown();
            Settings.Default.Save();
        }
コード例 #21
0
        static int Main(string[] args)
        {
            var options = new Options();
            var isValid = CommandLine.Parser.Default.ParseArgumentsStrict(args, options);

            if (isValid)
            {
                if (options.ShowHelp)
                {
                    Console.WriteLine(options.GetUsage());
                    return(0);
                }
                if (!File.Exists(options.InputFile))
                {
                    Console.WriteLine("Input lift wordlist {0} does not exist", options.InputFile);
                    return(1);
                }

                if ((options.OutputFile != "Wordlist.json") && File.Exists(options.OutputFile))
                {
                    Console.WriteLine("The file {0} already exists.", options.OutputFile);
                    return(1);
                }
                if (options.Verbose)
                {
                    Console.WriteLine("Input file: {0}", options.InputFile);
                    Console.WriteLine("Output file: {0}", options.OutputFile);
                }
            }
            else
            {
                // Display the default usage information
                Console.WriteLine("command line parsing failed");
                Console.WriteLine(options.GetUsage());
                return(1);
            }

            List <LexEntry> _words;

            _words = new List <LexEntry>();

            using (ProjectDirectorySetupForTesting p = new ProjectDirectorySetupForTesting("<entry id='foo1'><lexical-unit><form lang='qaa-x-qaa'><text>fooOne</text></form></lexical-unit></entry>"))
            {
                WeSayWordsProject project = p.CreateLoadedProject();

                using (var reader = new Palaso.DictionaryServices.Lift.LiftReader(new NullProgressState(),
                                                                                  WeSayWordsProject.Project.GetSemanticDomainsList(),
                                                                                  WeSayWordsProject.Project.GetIdsOfSingleOptionFields()))
                    using (var m = new MemoryDataMapper <LexEntry>())
                    {
                        reader.Read(options.InputFile, m);
                        _words.AddRange(from RepositoryId repositoryId in m.GetAllItems() select m.GetItem(repositoryId));
                    }
                foreach (var word in _words)
                {
                    foreach (var sense in word.Senses)
                    {
                        // copy all definition forms to gloss then delete definition form
                        foreach (var form in sense.Definition.Forms)
                        {
                            sense.Gloss.SetAlternative(form.WritingSystemId, form.Form);
                            sense.Definition.SetAlternative(form.WritingSystemId, null);
                        }
                    }
                }

                using (StreamWriter file = new StreamWriter(options.OutputFile))
                {
                    using (JsonWriter writer = new JsonTextWriter(file))
                    {
                        writer.WriteStartArray();
                        foreach (LexEntry word in _words)
                        {
                            writer.WriteStartObject();

                            writer.WritePropertyName("lexicalid");
                            LanguageForm idform    = word.LexicalForm.Find("en");
                            string       lexicalid = (idform == null ? word.LexicalForm.GetFirstAlternative() : idform.Form);
                            writer.WriteValue(lexicalid);

                            foreach (var sense in word.Senses)
                            {
                                foreach (var form in sense.Gloss.Forms)
                                {
                                    writer.WritePropertyName(form.WritingSystemId);
                                    writer.WriteValue(form.Form);
                                }
                            }

                            writer.WriteEndObject();
                        }
                        writer.WriteEndArray();
                    }
                }
            }
            return(0);
        }
コード例 #22
0
		public void DefaultConfigFile_DoesntNeedMigrating()
		{
			WeSayWordsProject p = new WeSayWordsProject();
			XPathDocument defaultConfig = new XPathDocument(WeSayWordsProject.PathToDefaultConfig);
			using (TempFile f = new TempFile())
			{
				bool migrated = WeSayWordsProject.MigrateConfigurationXmlIfNeeded(defaultConfig, f.Path);
				Assert.IsFalse(migrated, "The default config file should never need migrating");
			}
		}
コード例 #23
0
//
        /// <summary>
        /// Will create whatever files are needed for wesay to use a valid lift folder, based on what it finds.
        /// </summary>
//        public static void PrepareLiftFolderForWeSay(string pathToLiftFolder)
//        {
//            using (var project = new WeSayWordsProject())
//            {
//                project.LoadFromProjectDirectoryPath(pathToLiftFolder);
//                var creator = new ProjectFromLiftFolderCreator(project.PathToLiftFile, project.DefaultViewTemplate, project.WritingSystems);
//
//                creator.SetWritingSystemsForFields();
//                project.Save();
//            }
//
//        }


        /// <summary>
        /// Will create whatever files are needed for wesay to use a valid lift folder, based on what it finds.
        /// </summary>
        public static void PrepareLiftFolderForWeSay(WeSayWordsProject project)
        {
            var creator = new ProjectFromLiftFolderCreator(project.PathToLiftFile, project.DefaultViewTemplate, project.WritingSystems);

            creator.SetWritingSystemsForFields();
        }
コード例 #24
0
		private static void TryLoading(string lexiconPath, string experimentDir)
		{
			try
			{
				WeSayWordsProject p = new WeSayWordsProject();
				lexiconPath = p.UpdateFileStructure(lexiconPath);

				p.LoadFromLiftLexiconPath(lexiconPath);
			}
			finally
			{
				Directory.Delete(experimentDir, true);
			}
		}
コード例 #25
0
		public void PathProvidedAsSimpleFileName_GetsConverted()
		{
			using (ProjectDirectorySetupForTesting dir = new ProjectDirectorySetupForTesting("<entry id='foo1'><lexical-unit><form lang='v'><text>fooOne</text></form></lexical-unit></entry>"))
			{
				string oldWorkingDir= System.Environment.CurrentDirectory;
				try
				{
					using (WeSayWordsProject project = new WeSayWordsProject())
					{
						System.Environment.CurrentDirectory = dir.PathToDirectory;
						project.LoadFromLiftLexiconPath(Path.GetFileName(dir.PathToLiftFile));

						Assert.AreEqual(dir.PathToLiftFile, project.PathToLiftFile);
					}
				}
				finally
				{
					System.Environment.CurrentDirectory = oldWorkingDir;
				}

			}
		}
コード例 #26
0
		public void UpdateFileStructure_LiftByItselfAtRoot_DoesNothing()
		{
			string path = @"C:\unittest.lift"; //this is at the root ON PURPOSE
			File.CreateText(path).Close();
			using (TempFile.TrackExisting(path))
			{
					using (WeSayWordsProject p = new WeSayWordsProject())
					{
						Assert.AreEqual(path, p.UpdateFileStructure(path));
					}
				}
		}
コード例 #27
0
 public void SetupFixture()
 {
     Palaso.UI.WindowsForms.Keyboarding.KeyboardController.Initialize();
     _project = WeSayProjectTestHelper.InitializeForTests();
 }
コード例 #28
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>true if the project was sucessfully opend</returns>
        public bool OpenProject(string path)
        {
            Logger.WriteEvent("OpenProject(" + path + ")");
            //System.Configuration.ConfigurationManager.AppSettings["LastConfigFilePath"] = path;

            //strip off any trailing '\'
            if (path[path.Length - 1] == Path.DirectorySeparatorChar ||
                path[path.Length - 1] == Path.AltDirectorySeparatorChar)
            {
                path = path.Substring(0, path.Length - 1);
            }

            try
            {
                Project = new WeSayWordsProject();

                //just open the accompanying lift file.
                path = path.Replace(".WeSayConfig", ".lift");

                if (path.Contains(".lift"))
                {
                    path = Project.UpdateFileStructure(path);
                    if (!Project.LoadFromLiftLexiconPath(path))
                    {
                        Project = null;
                        return(false);
                    }
                }
                //                else if (path.Contains(".WeSayConfig"))
                //                {
                //                    this.Project.LoadFromConfigFilePath(path);
                //                }
                else if (Directory.Exists(path))
                {
                    Project.LoadFromProjectDirectoryPath(path);
                    if (_project.Container == null)
                    {
                        // There must not have been a .lift file in the given path.
                        // This has already been reported with an error dialog box.
                        _project.Dispose();
                        Project = null;
                        return(false);
                    }
                }
                else
                {
                    throw new ApplicationException(path +
                                                   " is not named as a .lift file or .WeSayConfig file.");
                }
                if (_disableBackupAndChorusStuffForTests)
                {
                    _project.BackupMaker = null;
                }
            }
            catch (ConfigurationFileTooNewException e)
            {
                Project = null;
                ErrorReport.NotifyUserOfProblem(e.Message);
                return(false);
            }
            catch (Exception e)
            {
                Project = null;
                ErrorReport.NotifyUserOfProblem(e, "WeSay was not able to open that project." + e.Message);
                return(false);
            }

            SetupProjectControls(BuildInnerContainerForThisProject());
            Settings.Default.MruConfigFilePaths.AddNewPath(Project.PathToConfigFile);
            return(true);
        }
コード例 #29
0
		public WeSayWordsProject CreateLoadedProject()
		{

			WeSayWordsProject p = new WeSayWordsProject();
			p.LoadFromLiftLexiconPath(PathToLiftFile);


			return p;
		}
コード例 #30
0
ファイル: ConfigurationWindow.cs プロジェクト: sillsdev/wesay
        /// <summary>
        ///
        /// </summary>
        /// <returns>true if the project was sucessfully opened</returns>
        public bool OpenProject(string path, bool newClone = false)
        {
            Logger.WriteEvent("OpenProject(" + path + ")");
            //System.Configuration.ConfigurationManager.AppSettings["LastConfigFilePath"] = path;

            //strip off any trailing '\'
            if (path[path.Length - 1] == Path.DirectorySeparatorChar ||
                path[path.Length - 1] == Path.AltDirectorySeparatorChar)
            {
                path = path.Substring(0, path.Length - 1);
            }

            string fullPath = Path.GetFullPath(path);
            // file to indicate to WeSayWordsProject not to do copy from gloss to definition WS-472
            string newlycreatedfromFLExPath = Path.Combine(fullPath, ".newlycreatedfromFLEx");

            try
            {
                Project = new WeSayWordsProject();

                // if there is no .WeSayConfig file and it is new from chorus and the lift file was produced by FLEx
                // then the project is new from FLEx and should be gloss meaning field by default
                if (newClone && !path.Contains(".WeSayConfig"))
                {
                    string[] liftPaths = Directory.GetFiles(fullPath, "*.lift");
                    string   liftPath  = liftPaths != null && liftPaths.Length > 0 ? liftPaths.First() : "";
                    if (Directory.GetFiles(fullPath, "*.WeSayConfig").Length == 0 && Project.CreatedByFLEx(liftPath))
                    {
                        File.Create(newlycreatedfromFLExPath).Dispose();
                    }
                }

                //just open the accompanying lift file.
                path = path.Replace(".WeSayConfig", ".lift");

                if (path.Contains(".lift"))
                {
                    path = Project.UpdateFileStructure(path);

                    if (!Project.LoadFromLiftLexiconPath(path))
                    {
                        Project = null;
                        return(false);
                    }
                }
                //                else if (path.Contains(".WeSayConfig"))
                //                {
                //                    this.Project.LoadFromConfigFilePath(path);
                //                }
                else if (Directory.Exists(path))
                {
                    Project.LoadFromProjectDirectoryPath(path);
                    if (_project.Container == null)
                    {
                        // There must not have been a .lift file in the given path.
                        // This has already been reported with an error dialog box.
                        _project.Dispose();
                        Project = null;
                        return(false);
                    }
                }
                else
                {
                    throw new ApplicationException(path +
                                                   " is not named as a .lift file or .WeSayConfig file.");
                }
                if (_disableBackupAndChorusStuffForTests)
                {
                    _project.BackupMaker = null;
                }
            }
            catch (ConfigurationFileTooNewException e)
            {
                Project = null;
                ErrorReport.NotifyUserOfProblem(e.Message);
                return(false);
            }
            catch (Exception e)
            {
                Project = null;
                ErrorReport.NotifyUserOfProblem(e, "WeSay was not able to open that project." + e.Message);
                return(false);
            }

            if (File.Exists(newlycreatedfromFLExPath))
            {
                Hide();
                SetupProjectControls(BuildInnerContainerForThisProject());
                _project.MakeMeaningFieldChange("definition", "gloss");
                _project.Save();
                SetupProjectControls(BuildInnerContainerForThisProject());                 // reload to get meaning field change in gui
                File.Delete(newlycreatedfromFLExPath);
                Show();
            }
            else
            {
                SetupProjectControls(BuildInnerContainerForThisProject());
            }
            Settings.Default.MruConfigFilePaths.AddNewPath(Project.PathToConfigFile);
            return(true);
        }