예제 #1
0
파일: PLiftMaker.cs 프로젝트: bbriggs/wesay
		//private string MakePLiftTempFile(IEnumerable<LexEntry> entries, ViewTemplate template, IFindEntries finder)
		//{
		//    string path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
		//    LiftExporter exporter = new LiftExporter(path);
		//    exporter.SetUpForPresentationLiftExport(template, finder);
		//    foreach (LexEntry entry in entries)
		//    {
		//        exporter.Add(entry);
		//    }
		//    exporter.End();
		//    return path;
		//}

		public string MakePLiftTempFile(LexEntryRepository lexEntryRepository, ViewTemplate template)
		{
			string path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
			PLiftExporter exporter = new PLiftExporter(path, lexEntryRepository, template);
			ResultSet<LexEntry> recordTokens =
					lexEntryRepository.GetAllEntriesSortedByHeadword(template.HeadwordWritingSystem);
			foreach (RecordToken<LexEntry> token in recordTokens)
			{
				int homographNumber = 0;
				if ((bool) token["HasHomograph"])
				{
					homographNumber = (int) token["HomographNumber"];
				}
				exporter.Add(token.RealObject, homographNumber);
			}

			exporter.End();
			return path;
		}
예제 #2
0
		private string GetHtmlForEntriesCore(IEnumerable<string> entryIds)
		{
			try
			{
				Logger.WriteMinorEvent("GetHtmlForEntries()");
				StringBuilder builder = new StringBuilder();
				PLiftExporter exporter = new PLiftExporter(builder,
														   true,
														   _lexEntryRepository,
														   _project.DefaultPrintingTemplate);

				foreach (string entryId in entryIds)
				{
					LexEntry entry = _lexEntryRepository.GetLexEntryWithMatchingId(entryId);
					if (entry == null)
					{
						builder.AppendFormat("Error: entry '{0}' not found.", entryId);
					}
					else
					{
						exporter.Add(entry);
					}
				}
				exporter.End();
				return _articleMaker.GetHtmlFragment(builder.ToString());
			}
			catch (Exception e)
			{
				Logger.WriteEvent("Error from dictionary services, GetHtmlForEntries: " + e.Message);
				Debug.Fail(e.Message);
			}
			return StringCatalog.Get("~Program Error",
									 "This is what we call it when something goes wrong but it's the computer's fault, not the user's.");
		}