예제 #1
0
        private void TestParseAllTrees()
        {
            //Arrange
            Script tester = new Script();

            foreach (string file in Directory.EnumerateFiles("national_focus", "*.txt"))
            {
                string contents = File.ReadAllText(file);
                //Act
                FocusGridModel           model     = FocusTreeParser.CreateTreeFromScript(file, contents);
                FociGridContainer        container = new FociGridContainer(model);
                List <FociGridContainer> list      = new List <FociGridContainer> {
                    container
                };
                Dictionary <string, string> files = FocusTreeParser.ParseAllTrees(list);
                string filecontent = files.FirstOrDefault().Value;
                string fileName    = files.FirstOrDefault().Key;
                //Assert
                Assert.IsNotNull(model);
                Assert.IsTrue(model.FociList.Any());
                Assert.IsNotNull(fileName);
                Assert.IsNotNull(filecontent);
                tester.Analyse(filecontent);
                Assert.IsFalse(tester.Logger.hasErrors());
            }
        }
예제 #2
0
        public void ExportProject(string paramFilename)
        {
            string path = paramFilename + FOCUS_TREE_PATH;

            Directory.CreateDirectory(path);
            //For each parsed focus trees
            foreach (KeyValuePair <string, string> item in
                     FocusTreeParser.ParseAllTrees(fociContainerList))
            {
                using (TextWriter tw = new StreamWriter(path + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
            path = paramFilename + LOCALISATION_PATH;
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            LocalisationContainer loct = null;

            //For each parsed localisation files
            foreach (KeyValuePair <string, string> item in
                     LocalisationParser.ParseEverything(localisationList))
            {
                //localisationList.IndexOf(loct, 0);
                //fork
                //fixed localization files save in UTF-8 with BOM format
                loct = localisationList[0];
                using (Stream stream = File.OpenWrite(path + item.Key + "_" + loct.LanguageName + ".yml")) //save in file name eg.'test_l_english.yml'
                    using (TextWriter tw = new StreamWriter(stream, new UTF8Encoding(true)))
                    {
                        tw.Write(item.Value);
                    }
            }
            path = paramFilename + EVENTS_PATH;
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            //For each parsed event file
            foreach (KeyValuePair <string, string> item in
                     EventParser.ParseAllEvents(eventList))
            {
                //using (TextWriter tw = new StreamWriter(path + item.Key + ".txt"))
                //fork need to be UTF-8 with BOM
                using (TextWriter tw = new StreamWriter(path + item.Key + ".txt", false, new UTF8Encoding(true)))
                {
                    tw.Write(item.Value);
                }
            }
            //For each parsed script file
            foreach (KeyValuePair <string, string> item in
                     ScriptParser.ParseEverything(scriptList))
            {
                using (TextWriter tw = new StreamWriter(paramFilename + "\\" + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
        }
예제 #3
0
        public void ExportProject(string paramFilename)
        {
            string path = paramFilename + FOCUS_TREE_PATH;

            Directory.CreateDirectory(path);
            //For each parsed focus trees
            foreach (KeyValuePair <string, string> item in
                     FocusTreeParser.ParseAllTrees(fociContainerList))
            {
                using (TextWriter tw = new StreamWriter(path + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
            path = paramFilename + LOCALISATION_PATH;
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            //For each parsed localisation files
            foreach (KeyValuePair <string, string> item in
                     LocalisationParser.ParseEverything(localisationList))
            {
                using (Stream stream = File.OpenWrite(path + item.Key + ".yml"))
                    using (TextWriter tw = new StreamWriter(stream, new UTF8Encoding()))
                    {
                        tw.Write(item.Value);
                    }
            }
            path = paramFilename + EVENTS_PATH;
            Directory.CreateDirectory(Path.GetDirectoryName(path));
            //For each parsed event file
            foreach (KeyValuePair <string, string> item in
                     EventParser.ParseAllEvents(eventList))
            {
                using (TextWriter tw = new StreamWriter(path + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
            //For each parsed script file
            foreach (KeyValuePair <string, string> item in
                     ScriptParser.ParseEverything(scriptList))
            {
                using (TextWriter tw = new StreamWriter(paramFilename + "\\" + item.Key + ".txt"))
                {
                    tw.Write(item.Value);
                }
            }
        }
        public void ExportProject()
        {
            var dialog = new CommonOpenFileDialog();
            ResourceDictionary resourceLocalization = new ResourceDictionary();

            resourceLocalization.Source = new Uri(Configurator.getLanguageFile(), UriKind.Relative);
            dialog.Title                     = resourceLocalization["Project_Export"] as string;
            dialog.IsFolderPicker            = true;
            dialog.InitialDirectory          = "C:";
            dialog.AddToMostRecentlyUsedList = false;
            dialog.AllowNonFileSystemItems   = false;
            dialog.DefaultDirectory          = "C:";
            dialog.EnsureFileExists          = true;
            dialog.EnsurePathExists          = true;
            dialog.EnsureReadOnly            = false;
            dialog.EnsureValidNames          = true;
            dialog.Multiselect               = false;
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                //For each parsed focus trees
                foreach (KeyValuePair <string, string> item in
                         FocusTreeParser.ParseAllTrees(project.fociContainerList))
                {
                    using (TextWriter tw = new StreamWriter(dialog.FileName + "\\" + item.Key + ".txt"))
                    {
                        tw.Write(item.Value);
                    }
                }
                //For each parsed localisation files
                foreach (KeyValuePair <string, string> item in
                         LocalisationParser.ParseEverything(project.localisationList))
                {
                    using (TextWriter tw = new StreamWriter(dialog.FileName + "\\" + item.Key + ".yaml"))
                    {
                        tw.Write(item.Value);
                    }
                }
                //TODO: For each parsed event
            }
        }
예제 #5
0
        private void TestTreeToScript(FocusGridModel model)
        {
            //Arrange
            FociGridContainer        container = new FociGridContainer(model);
            List <FociGridContainer> list      = new List <FociGridContainer> {
                container
            };
            Script tester = new Script();
            //Act
            Dictionary <string, string> files = FocusTreeParser.ParseAllTrees(list);
            string filecontent = files.FirstOrDefault().Value;
            string fileName    = files.FirstOrDefault().Key;

            //Assert
            Assert.IsNotNull(filecontent);
            Assert.IsNotNull(fileName);
            Assert.AreEqual(fileName, "usa_focus");
            //Test if we can process the script
            tester.Analyse(filecontent);
            Assert.IsFalse(tester.Logger.hasErrors());
            Assert.IsNotNull(tester.FindAssignation("tag"));
        }