예제 #1
0
        protected string CreateFileToOpen(ProjectInfo projectInfo,
                                          bool linkToUserCss)
        {
            LexEntryRepository lexEntryRepository = projectInfo.ServiceProvider.GetService(typeof(LexEntryRepository)) as LexEntryRepository;
            var pliftPath = Path.Combine(projectInfo.PathToExportDirectory, projectInfo.Name + ".plift");


            var maker = new PLiftMaker();

            maker.MakePLiftTempFile(pliftPath, lexEntryRepository,
                                    projectInfo.ServiceProvider.GetService(typeof(ViewTemplate)) as
                                    ViewTemplate, LiftWriter.ByteOrderStyle.NoBOM);


            var pathToOutput = Path.Combine(projectInfo.PathToExportDirectory,
                                            projectInfo.Name + ".html");

            if (File.Exists(pathToOutput))
            {
                File.Delete(pathToOutput);
            }

            var htmWriter = new FLExCompatibleXhtmlWriter(linkToUserCss, ((WeSay.Project.WeSayWordsProject)projectInfo.Project).DefaultViewTemplate);

            SetupLetterGroups(projectInfo, htmWriter);

            using (var reader = new StreamReader(pliftPath))
            {
                using (var file = new StreamWriter(pathToOutput, false, new UTF8Encoding(false)))
                {
                    htmWriter.Write(reader, file);
                }
            }
            return(pathToOutput);
        }
예제 #2
0
        /// <summary>
        /// Some people need new sections for groups of letters, like "ng" or "th". This gives it to them
        /// if they've made a file, one group per line, named "letterGroups.txt" sitting in the export folder.
        /// In the future, this should be part of our writing systems.
        /// </summary>
        /// <param name="projectInfo"></param>
        /// <param name="htmWriter"></param>
        private static void SetupLetterGroups(ProjectInfo projectInfo, FLExCompatibleXhtmlWriter htmWriter)
        {
            string letterGroupFilePath = string.Empty;

            try
            {
                //NB: if the name of this is changed, change it in Chorus too, or it will stop propagating
                letterGroupFilePath = Path.Combine(projectInfo.PathToExportDirectory, "multigraphs.txt");

                if (File.Exists(letterGroupFilePath))
                {
                    htmWriter.Grouper = new MultigraphParser(File.ReadAllLines(letterGroupFilePath));
                }
            }
            catch (Exception e)
            {
                ErrorReport.NotifyUserOfProblem(e,
                                                "There was a problem setting up the letter groups. Check the file {0}",
                                                letterGroupFilePath);
            }
        }
예제 #3
0
        private string GetXhtmlContents(IList <LexEntry> entries)
        {
            if (entries != null)
            {
                entries.ForEach(e => _repo.SaveItem(e));
            }


            var pliftbuilder = new StringBuilder();

            using (var pexp = new PLiftExporter(pliftbuilder, false, _repo, _project.DefaultPrintingTemplate))
            {
                ResultSet <LexEntry> recordTokens =
                    _repo.GetAllEntriesSortedByHeadword(_project.DefaultPrintingTemplate.HeadwordWritingSystems[0]);


                foreach (RecordToken <LexEntry> token in recordTokens)
                {
                    pexp.Add(token.RealObject);
                }
                pexp.End();
            }
            var builder = new StringBuilder();

            using (var w = new StringWriter(builder))
            {
                var x = new FLExCompatibleXhtmlWriter();

                //  try
                {
                    x.Write(new StringReader(pliftbuilder.ToString()), w);
                }
//                catch(Exception e)
//                {
//                    Console.WriteLine(pliftbuilder.ToString());
//                    throw e;
//                }
            }
            return(builder.ToString());
        }