Example #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Prepares the selected files to be uploaded to REAP using RAMP.
		/// </summary>
		/// <param name="owner">RAMP dialog owner</param>
		/// <param name="dialogFont">RAMP dialog font (for localization and consistency)</param>
		/// <param name="localizationDialogIcon"></param>
		/// <param name="filesToArchive"></param>
		/// <param name="mediator"></param>
		/// <param name="thisapp"></param>
		/// <param name="cache"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public bool ArchiveNow(Form owner, Font dialogFont, Icon localizationDialogIcon,
			IEnumerable<string> filesToArchive, Mediator mediator, FwApp thisapp, FdoCache cache)
		{
			var viProvider = new VersionInfoProvider(Assembly.LoadFile(thisapp.ProductExecutableFile), false);
			var wsMgr = cache.ServiceLocator.GetInstance<IWritingSystemManager>();
			var appName = thisapp.ApplicationName;
			var title = cache.LanguageProject.ShortName;
			var uiLocale = wsMgr.Get(cache.DefaultUserWs).IcuLocale;
			var projectId = cache.LanguageProject.ShortName;

			var model = new RampArchivingDlgViewModel(Application.ProductName, title, projectId, /*appSpecificArchivalProcessInfo:*/ string.Empty, SetFilesToArchive(filesToArchive), GetFileDescription);

			// image files should be labeled as Graphic rather than Photograph (the default).
			model.ImagesArePhotographs = false;

			// show the count of media files, not the duration
			model.ShowRecordingCountNotLength = true;

			// set the general description, in each available language
			IMultiString descr = cache.LanguageProject.Description;
			var descriptions = new Dictionary<string, string>();
			foreach (int wsid in descr.AvailableWritingSystemIds)
			{
				var descrText = descr.get_String(wsid).Text;
				if ((!string.IsNullOrEmpty(descrText)) && (descrText != "***"))
					descriptions[wsMgr.Get(wsid).GetIso3Code()] = descrText;
			}

			if (descriptions.Count > 0)
				model.SetDescription(descriptions);

			AddMetsPairs(model, viProvider.ShortNumericAppVersion, cache);

			const string localizationMgrId = "Archiving";

			if (s_localizationMgr == null)
			{
				s_localizationMgr = LocalizationManager.Create(
					uiLocale,
					localizationMgrId, viProvider.ProductName, viProvider.NumericAppVersion,
					FwDirectoryFinder.GetCodeSubDirectory("ArchivingLocalizations"),
					Path.Combine(Application.CompanyName, appName),
					localizationDialogIcon, "*****@*****.**", "SIL.Archiving");
			}
			else
			{
				LocalizationManager.SetUILanguage(uiLocale, true);
			}

			// create the dialog
			using (var dlg = new ArchivingDlg(model, localizationMgrId, dialogFont, new FormSettings()))
			using (var reportingAdapter = new PalasoErrorReportingAdapter(dlg, mediator))
			{
				ErrorReport.SetErrorReporter(reportingAdapter);
				dlg.ShowDialog(owner);
				ErrorReport.SetErrorReporter(null);
			}

			return true;
		}
Example #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets required and optional information that describes the files being submitted in
		/// the RAMP package. METS = Metadata Encoding & Transmission Standard
		/// (see http://www.loc.gov/METS/).
		/// </summary>
		/// <param name="model">Object provided by SIL.Archiving for setting application
		/// specific archiving information.</param>
		/// <param name="fieldWorksVersion">Fieldworks version to display.</param>
		/// <param name="cache"></param>
		/// <returns>A list of JSON encoded pairs that describe the information in the RAMP
		/// package.</returns>
		/// ------------------------------------------------------------------------------------
		private void AddMetsPairs(RampArchivingDlgViewModel model, string fieldWorksVersion, FdoCache cache)
		{
			IWritingSystemManager wsManager = cache.ServiceLocator.GetInstance<IWritingSystemManager>();
			var wsDefaultVern = wsManager.Get(cache.DefaultVernWs);
			var vernIso3Code = wsDefaultVern.GetIso3Code();

			model.SetScholarlyWorkType(ScholarlyWorkType.PrimaryData);

			// use year range for CreationDate if possible
			GetCreateDateRange(cache);
			var yearStart = m_earliest.Year;
			var yearEnd = m_latest.Year;

			if (yearEnd > yearStart)
				model.SetCreationDate(yearStart, yearEnd);
			else
				model.SetCreationDate(m_earliest);

			model.SetModifiedDate(cache.LangProject.DateModified);

			if (!string.IsNullOrEmpty(vernIso3Code))
				model.SetSubjectLanguage(vernIso3Code, wsDefaultVern.LanguageName);

			var contentLanguages = new List<ArchivingLanguage>();
			var softwareRequirements = new HashSet<string>();
			bool fWsUsesKeyman = false;

			softwareRequirements.Add(string.Format("FieldWorks Language Explorer, Version {0} or later", fieldWorksVersion));

			foreach (var ws in cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Union(
				cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems).Union(
				cache.ServiceLocator.WritingSystems.CurrentPronunciationWritingSystems))
			{
				var iso3Code = ws.GetIso3Code();

				if (!string.IsNullOrEmpty(iso3Code))
					contentLanguages.Add(new ArchivingLanguage(iso3Code, ws.LanguageSubtag.Name));

				if (!string.IsNullOrEmpty(ws.DefaultFontName))
					softwareRequirements.Add(ws.DefaultFontName);

				fWsUsesKeyman |= !string.IsNullOrEmpty(ws.Keyboard);
			}

			if (fWsUsesKeyman)
				softwareRequirements.Add("Keyman");

			model.SetContentLanguages(contentLanguages);
			model.SetSoftwareRequirements(softwareRequirements);

			SilDomain domains = SilDomain.Linguistics;
			var cNotebookRecords = cache.LangProject.ResearchNotebookOA.AllRecords.Count();
			if (cNotebookRecords > 0)
			{
				domains |= SilDomain.Anthropology;
				domains |= SilDomain.Anth_Ethnography; // Data notebook data is considered a (partial) ethnography.
			}

			var cLexicalEntries = cache.LangProject.LexDbOA.Entries.Count();
			if (cLexicalEntries > 0)
				domains |= SilDomain.Ling_Lexicon;

			// Determine if there are any interlinearized texts
			if (cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>().AllInstances().Any(a => a.OccurrencesInTexts.Any() &&
				a.GetAgentOpinion(cache.LangProject.DefaultUserAgent) == Opinions.approves))
				domains |= SilDomain.Ling_InterlinearizedText;

			var cTexts = cache.LangProject.Texts.Count();
			if (cTexts > 0)
				domains |= SilDomain.Ling_Text;

			/* TODO: If files to include in archive includes a Lift file, set the correct schema */
			//if (filesToArchive.Contains( FwFileExtensions.ksLexiconInterchangeFormat )
			//	model.SetSchemaConformance("LIFT");

			/* TODO: If files to include in archive includes a grammar sketch, set the correct subdomain */
			//if (filesToArchive.Contains(...)
			//	domains |= SilDomain.Ling_GrammaticalDescription;

			model.SetDomains(domains);

			// get the information for DatasetExtent
			var datasetExtent = new StringBuilder();
			const string delimiter = "; ";

			if (cNotebookRecords > 0)
				datasetExtent.AppendLineFormat("{0} Notebook record{1}", new object[] { cNotebookRecords, (cNotebookRecords == 1) ? "" : "s" }, delimiter);

			if (cLexicalEntries > 0)
				datasetExtent.AppendLineFormat("{0} Lexical entr{1}", new object[] { cLexicalEntries, (cLexicalEntries == 1) ? "y" : "ies" }, delimiter);

			if (cTexts > 0)
				datasetExtent.AppendLineFormat("{0} Text{1}", new object[] { cTexts, (cTexts == 1) ? "" : "s" }, delimiter);

			if (datasetExtent.Length > 0)
				model.SetDatasetExtent(datasetExtent + ".");
		}