/// ------------------------------------------------------------------------------------
 private void SetFilesToArchive(ArchivingDlgViewModel model)
 {
     foreach (var kvp in _filesToAdd)
     {
         model.AddFileGroup(kvp.Key, kvp.Value.Item1, kvp.Value.Item2);
     }
 }
Beispiel #2
0
        /// ------------------------------------------------------------------------------------
        public void SetFilesToArchive(ArchivingDlgViewModel model)
        {
            model.AddFileGroup(string.Empty, GetSessionFilesToArchive(model.GetType()), AddingSessionFilesProgressMsg);

            var fmt = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.AddingContributorFilesProgressMsg", "Adding Files for Contributor '{0}'");

            foreach (var person in GetParticipantFilesToArchive(model.GetType()))
            {
                model.AddFileGroup(person.Key, person.Value, string.Format(fmt, person.Key));
            }
        }
		/// <summary />
		public IMDIArchivingDlg(ArchivingDlgViewModel model, string localizationManagerId, Font programDialogFont, FormSettings settings) 
			: base(model, localizationManagerId, programDialogFont, settings)
		{
			// DO NOT SHOW THE LAUNCH OPTION AT THIS TIME
			model.PathToProgramToLaunch = null;

			InitializeNewControls();

			// get the saved IMDI program value
			GetSavedValues();

			// set control properties
			SetControlProperties();
		}
Beispiel #4
0
        /// <summary />
        public IMDIArchivingDlg(ArchivingDlgViewModel model, string localizationManagerId, Font programDialogFont, FormSettings settings)
            : base(model, localizationManagerId, programDialogFont, settings)
        {
            // DO NOT SHOW THE LAUNCH OPTION AT THIS TIME
            model.PathToProgramToLaunch = null;

            InitializeNewControls();

            // get the saved IMDI program value
            GetSavedValues();

            // set control properties
            SetControlProperties();
        }
Beispiel #5
0
        internal static void SetIMDIMetadataToArchive(IIMDIArchivable element, ArchivingDlgViewModel model)
        {
            var project = element as Project;

            if (project != null)
            {
                AddIMDIProjectData(project, model);

                foreach (var session in project.GetAllSessions())
                {
                    AddIMDISession(session, model);
                }
            }
            else
            {
                AddIMDISession((Session)element, model);
            }
        }
Beispiel #6
0
        internal static ArchivingActor InitializeActor(ArchivingDlgViewModel model, Person person, DateTime sessionDateTime, string role)
        {
            // is this person protected
            var protect = bool.Parse(person.MetaDataFile.GetStringValue("privacyProtection", "false"));

            // display message if the birth year is not valid
            var birthYear = person.MetaDataFile.GetStringValue("birthYear", string.Empty).Trim();
            var age       = 0;

            if (!birthYear.IsValidBirthYear() || string.IsNullOrEmpty(birthYear))
            {
                var msg = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.InvalidBirthYearMsg",
                                                        "The Birth Year for {0} should be a 4 digit number. It is used to calculate the age for the IMDI export.");
                model.AdditionalMessages[string.Format(msg, person.Id)] = ArchivingDlgViewModel.MessageType.Warning;
            }
            else
            {
                age = string.IsNullOrEmpty(birthYear) ? 0 : sessionDateTime.Year - int.Parse(birthYear);
                if (age < 2 || age > 130)
                {
                    var msg = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.InvalidAgeMsg",
                                                            "The age for {0} must be between 2 and 130");
                    model.AdditionalMessages[string.Format(msg, person.Id)] = ArchivingDlgViewModel.MessageType.Warning;
                }
            }

            var actor = new ArchivingActor
            {
                FullName   = person.Id,
                Name       = person.MetaDataFile.GetStringValue(PersonFileType.kCode, person.Id),
                Code       = person.MetaDataFile.GetStringValue(PersonFileType.kCode, null),
                BirthDate  = birthYear,
                Age        = age > 0 ? age.ToString() : "Unspecified",
                Gender     = person.MetaDataFile.GetStringValue(PersonFileType.kGender, null),
                Education  = person.MetaDataFile.GetStringValue(PersonFileType.kEducation, null),
                Occupation = person.MetaDataFile.GetStringValue(PersonFileType.kPrimaryOccupation, null),
                Anonymize  = protect,
                Role       = role,
            };

            return(actor);
        }
Beispiel #7
0
        /// ------------------------------------------------------------------------------------
        static internal bool FileCopySpecialHandler(ArchivingDlgViewModel model, string source, string dest)
        {
            if (!source.EndsWith(AnnotationFileHelper.kAnnotationsEafFileSuffix))
            {
                return(false);
            }

            // Fix EAF file to refer to modified name.
            AnnotationFileHelper annotationFileHelper = AnnotationFileHelper.Load(source);

            var mediaFileName = annotationFileHelper.MediaFileName;

            if (mediaFileName != null)
            {
                var normalizedName = model.NormalizeFilename(string.Empty, mediaFileName);
                if (normalizedName != mediaFileName)
                {
                    annotationFileHelper.SetMediaFile(normalizedName);
                    annotationFileHelper.Root.Save(dest);
                    return(true);
                }
            }
            return(false);
        }
Beispiel #8
0
        /// ------------------------------------------------------------------------------------
        public void SetFilesToArchive(ArchivingDlgViewModel model)
        {
            Dictionary <string, HashSet <string> > contributorFiles = new Dictionary <string, HashSet <string> >();
            Type archiveType = model.GetType();

            foreach (var session in GetAllSessions())
            {
                model.AddFileGroup(session.Id, session.GetSessionFilesToArchive(archiveType), session.AddingSessionFilesProgressMsg);
                foreach (var person in session.GetParticipantFilesToArchive(model.GetType()))
                {
                    if (!contributorFiles.ContainsKey(person.Key))
                    {
                        contributorFiles.Add(person.Key, new HashSet <string>());
                    }

                    foreach (var file in person.Value)
                    {
                        contributorFiles[person.Key].Add(file);
                    }
                }

                IArchivingSession s = model.AddSession(session.Id);
                s.Location.Address = session.MetaDataFile.GetStringValue(SessionFileType.kLocationFieldName, string.Empty);
                s.Title            = session.Title;
            }

            // project description documents
            var docsPath = Path.Combine(FolderPath, ProjectDescriptionDocsScreen.kFolderName);

            if (Directory.Exists(docsPath))
            {
                var files = Directory.GetFiles(docsPath, "*.*", SearchOption.TopDirectoryOnly);

                // the directory exists and contains files
                if (files.Length > 0)
                {
                    model.AddFileGroup(ProjectDescriptionDocsScreen.kArchiveSessionName, files,
                                       LocalizationManager.GetString("DialogBoxes.ArchivingDlg.AddingProjectDescriptionDocumentsToIMDIArchiveProgressMsg",
                                                                     "Adding Project Description Documents..."));
                }
            }

            // other project documents
            docsPath = Path.Combine(FolderPath, ProjectOtherDocsScreen.kFolderName);
            if (Directory.Exists(docsPath))
            {
                var files = Directory.GetFiles(docsPath, "*.*", SearchOption.TopDirectoryOnly);

                // the directory exists and contains files
                if (files.Length > 0)
                {
                    model.AddFileGroup(ProjectOtherDocsScreen.kArchiveSessionName, files,
                                       LocalizationManager.GetString("DialogBoxes.ArchivingDlg.AddingOtherProjectDocumentsToIMDIArchiveProgressMsg",
                                                                     "Adding Other Project Documents..."));
                }
            }

            foreach (var key in contributorFiles.Keys)
            {
                model.AddFileGroup("\n" + key, contributorFiles[key],
                                   LocalizationManager.GetString("DialogBoxes.ArchivingDlg.AddingContributorFilesToIMDIArchiveProgressMsg",
                                                                 "Adding Files for Contributors..."));
            }
        }
Beispiel #9
0
        /// ------------------------------------------------------------------------------------
        private void DisplayInitialArchiveSummary(IDictionary <string, Tuple <IEnumerable <string>, string> > fileLists, ArchivingDlgViewModel model)
        {
            foreach (var message in model.AdditionalMessages)
            {
                model.DisplayMessage(message.Key + "\n", message.Value);
            }

            if (fileLists.Count > 1)
            {
                model.DisplayMessage(LocalizationManager.GetString("DialogBoxes.ArchivingDlg.PrearchivingStatusMsg1",
                                                                   "The following session and contributor files will be added to your archive."), ArchivingDlgViewModel.MessageType.Normal);
            }
            else
            {
                model.DisplayMessage(LocalizationManager.GetString("DialogBoxes.ArchivingDlg.NoContributorsForSessionMsg",
                                                                   "There are no contributors for this session."), ArchivingDlgViewModel.MessageType.Warning);

                model.DisplayMessage(LocalizationManager.GetString("DialogBoxes.ArchivingDlg.PrearchivingStatusMsg2",
                                                                   "The following session files will be added to your archive."), ArchivingDlgViewModel.MessageType.Progress);
            }

            var fmt = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.ArchivingProgressMsg", "     {0}: {1}",
                                                    "The first parameter is 'Session' or 'Contributor'. The second parameter is the session or contributor name.");

            foreach (var kvp in fileLists)
            {
                var element = (kvp.Key.StartsWith("\n") ?
                               LocalizationManager.GetString("DialogBoxes.ArchivingDlg.ContributorElementName", "Contributor") :
                               LocalizationManager.GetString("DialogBoxes.ArchivingDlg.SessionElementName", "Session"));

                model.DisplayMessage(string.Format(fmt, element, (kvp.Key.StartsWith("\n") ? kvp.Key.Substring(1) : kvp.Key)),
                                     ArchivingDlgViewModel.MessageType.Progress);

                foreach (var file in kvp.Value.Item1)
                {
                    model.DisplayMessage(Path.GetFileName(file), ArchivingDlgViewModel.MessageType.Bullet);
                }
            }
        }
Beispiel #10
0
        private static void AddDocumentsSession(string sessionName, string[] sourceFiles, ArchivingDlgViewModel model)
        {
            // create IMDI session
            var imdiSession = model.AddSession(sessionName);

            imdiSession.Title = sessionName;

            foreach (var file in sourceFiles)
            {
                imdiSession.AddFile(CreateArchivingFile(file));
            }
        }
Beispiel #11
0
        internal static void AddIMDIProjectData(Project saymoreProject, ArchivingDlgViewModel model)
        {
            var package = (IMDIPackage)model.ArchivingPackage;

            // location
            package.Location = new ArchivingLocation
            {
                Address   = saymoreProject.Location,
                Region    = saymoreProject.Region,
                Country   = saymoreProject.Country,
                Continent = saymoreProject.Continent
            };

            // description
            package.AddDescription(new LanguageString(saymoreProject.ProjectDescription, null));

            // content type
            package.ContentType = null;

            // funding project
            package.FundingProject = new ArchivingProject
            {
                Title = saymoreProject.FundingProjectTitle,
                Name  = saymoreProject.FundingProjectTitle
            };

            // author
            package.Author = saymoreProject.ContactPerson;

            // applications
            package.Applications = null;

            // access date
            package.Access.DateAvailable = saymoreProject.DateAvailable;

            // access owner
            package.Access.Owner = saymoreProject.RightsHolder;

            // publisher
            package.Publisher = saymoreProject.Depositor;

            // subject language
            if (!string.IsNullOrEmpty(saymoreProject.VernacularISO3CodeAndName))
            {
                ParseLanguage(saymoreProject.VernacularISO3CodeAndName, package);
            }

            // analysis language
            if (!string.IsNullOrEmpty(saymoreProject.AnalysisISO3CodeAndName))
            {
                ParseLanguage(saymoreProject.AnalysisISO3CodeAndName, package);
            }

            // project description documents
            var docsPath = Path.Combine(saymoreProject.FolderPath, ProjectDescriptionDocsScreen.kFolderName);

            if (Directory.Exists(docsPath))
            {
                var files = Directory.GetFiles(docsPath, "*.*", SearchOption.TopDirectoryOnly);

                // the directory exists and contains files
                if (files.Length > 0)
                {
                    AddDocumentsSession(ProjectDescriptionDocsScreen.kArchiveSessionName, files, model);
                }
            }

            // other project documents
            docsPath = Path.Combine(saymoreProject.FolderPath, ProjectOtherDocsScreen.kFolderName);
            if (Directory.Exists(docsPath))
            {
                var files = Directory.GetFiles(docsPath, "*.*", SearchOption.TopDirectoryOnly);

                // the directory exists and contains files
                if (files.Length > 0)
                {
                    AddDocumentsSession(ProjectOtherDocsScreen.kArchiveSessionName, files, model);
                }
            }
        }
Beispiel #12
0
        internal static void AddIMDISession(Session saymoreSession, ArchivingDlgViewModel model)
        {
            var sessionFile = saymoreSession.MetaDataFile;

            if (Project == null)
            {
                Project = Program.CurrentProject;
            }
            var analysisLanguage = (Project != null) ? Project.AnalysisISO3CodeAndName : AnalysisLanguage();

            if (analysisLanguage.Contains(":"))
            {
                analysisLanguage = analysisLanguage.Split(':')[0];
            }
            // In case of things like pt-PT; no-op if no hyphen
            analysisLanguage = analysisLanguage.Split('-')[0];
            analysisLanguage = ForceIso639ThreeChar(analysisLanguage);

            // create IMDI session
            var imdiSession = model.AddSession(saymoreSession.Id);

            imdiSession.Title = saymoreSession.Title;

            // session location
            var address   = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Address", null);
            var region    = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Region", null);
            var country   = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Country", null);
            var continent = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Continent", null);

            if (string.IsNullOrEmpty(address))
            {
                address = saymoreSession.MetaDataFile.GetStringValue("location", null);
            }

            imdiSession.Location = new ArchivingLocation {
                Address = address, Region = region, Country = country, Continent = continent
            };

            // session description (synopsis)
            var stringVal = saymoreSession.MetaDataFile.GetStringValue("synopsis", null);

            if (!string.IsNullOrEmpty(stringVal))
            {
                imdiSession.AddDescription(new LanguageString {
                    Value = stringVal
                });
            }

            // session date
            stringVal = saymoreSession.MetaDataFile.GetStringValue("date", null);
            var sessionDateTime = DateTime.MinValue;

            if (!string.IsNullOrEmpty(stringVal))
            {
                sessionDateTime = DateTime.Parse(stringVal);
                imdiSession.SetDate(sessionDateTime.ToISO8601TimeFormatDateOnlyString());
            }

            // session languages
            if (Project != null)
            {
                var vernacularLanguage = ParseLanguage(ForceIso639ThreeChar(Project.VernacularISO3CodeAndName), null);
                if (vernacularLanguage != null)
                {
                    imdiSession.AddContentLanguage(vernacularLanguage, new LanguageString("Content Language", analysisLanguage));
                }
            }
            imdiSession.AddContentLanguage(new ArchivingLanguage(analysisLanguage), new LanguageString("Working Language", analysisLanguage));

            // session situation
            stringVal = saymoreSession.MetaDataFile.GetStringValue("situation", null);
            if (!string.IsNullOrEmpty(stringVal))
            {
                imdiSession.AddContentKeyValuePair("Situation", stringVal);
            }

            imdiSession.Genre         = GetFieldValue(sessionFile, "genre");
            imdiSession.SubGenre      = GetFieldValue(sessionFile, "additional_Sub-Genre");
            imdiSession.AccessCode    = GetFieldValue(sessionFile, "access");
            imdiSession.Interactivity = GetFieldValue(sessionFile, "additional_Interactivity");
            imdiSession.Involvement   = GetFieldValue(sessionFile, "additional_Involvement");
            imdiSession.PlanningType  = GetFieldValue(sessionFile, "additional_Planning_Type");
            imdiSession.SocialContext = GetFieldValue(sessionFile, "additional_Social_Context");
            imdiSession.Task          = GetFieldValue(sessionFile, "additional_Task");

            imdiSession.AddContentDescription(new LanguageString {
                Value = GetFieldValue(sessionFile, "notes"), Iso3LanguageId = analysisLanguage
            });

            // custom session fields (the custom prefix is used internally)
            foreach (var item in saymoreSession.MetaDataFile.GetCustomFields())
            {
                var fieldId = item.FieldId.Substring(XmlFileSerializer.kCustomFieldIdPrefix.Length);
                if (fieldId == "ELAR Topic")
                {
                    imdiSession.AddContentKeyValuePair(fieldId.Substring(5), item.ValueAsString);
                }
                else if (fieldId == "ELAR Keyword")
                {
                    fieldId = fieldId.Substring(5);
                    foreach (var kw in item.ValueAsString.Split(','))
                    {
                        imdiSession.AddContentKeyValuePair(fieldId, kw.Trim());
                    }
                }
                else
                {
                    imdiSession.AddContentKeyValuePair(fieldId, item.ValueAsString);
                }
            }

            // actors
            var actors  = new ArchivingActorCollection();
            var persons = saymoreSession.GetAllPersonsInSession();
            var allParticipantsWithRoles = saymoreSession.MetaDataFile.MetaDataFieldValues.Count > 0?
                                           (from p in saymoreSession.MetaDataFile.GetStringValue(SessionFileType.kParticipantsFieldName, string.Empty).Split(FieldInstance.kDefaultMultiValueDelimiter)
                                            where p.Trim() != string.Empty
                                            select p.Trim()).ToList()
                                : new List <string>();

            foreach (var person in persons)
            {
                var actor = InitializeActor(model, person, sessionDateTime, GetRole(person.Id, actors, allParticipantsWithRoles));

                // do this to get the ISO3 codes for the languages because they are not in saymore
                var language = GetOneLanguage(ForceIso639ThreeChar(person.MetaDataFile.GetStringValue("primaryLanguage", null)));
                if (language != null)
                {
                    actor.PrimaryLanguage = language;
                }
                language = GetOneLanguage(ForceIso639ThreeChar(person.MetaDataFile.GetStringValue("mothersLanguage", null)));
                if (language != null)
                {
                    actor.MotherTongueLanguage = language;
                }

                // otherLanguage0 - otherLanguage3
                for (var i = 0; i < 4; i++)
                {
                    var languageKey = person.MetaDataFile.GetStringValue("otherLanguage" + i, null);
                    if (string.IsNullOrEmpty(languageKey))
                    {
                        continue;
                    }
                    language = GetOneLanguage(ForceIso639ThreeChar(languageKey));
                    if (language == null)
                    {
                        continue;
                    }
                    actor.Iso3Languages.Add(language);
                }

                // ethnic group
                var ethnicGroup = person.MetaDataFile.GetStringValue("ethnicGroup", null);
                if (ethnicGroup != null)
                {
                    actor.EthnicGroup = ethnicGroup;
                }

                // custom person fields
                foreach (var item in person.MetaDataFile.GetCustomFields())
                {
                    actor.AddKeyValuePair(item.FieldId.Substring(XmlFileSerializer.kCustomFieldIdPrefix.Length), item.ValueAsString);
                }

                // actor files
                var actorFiles = Directory.GetFiles(person.FolderPath)
                                 .Where(f => IncludeFileInArchive(f, typeof(IMDIArchivingDlgViewModel), Settings.Default.PersonFileExtension));
                foreach (var file in actorFiles)
                {
                    actor.Files.Add(CreateArchivingFile(file));
                }

                // add actor to imdi session
                actors.Add(actor);
                imdiSession.AddActor(actor);

                // actor contact address
                var actorAddress = person.MetaDataFile.GetStringValue("howToContact", null);
                if (actorAddress != null)
                {
                    imdiSession.AddActorContact(actor, new ArchivingContact
                    {
                        Address = actorAddress
                    });
                }

                // Description (notes)
                var notes = (from metaDataFieldValue in person.MetaDataFile.MetaDataFieldValues
                             where metaDataFieldValue.FieldId == "notes"
                             select metaDataFieldValue.ValueAsString).FirstOrDefault();
                if (!string.IsNullOrEmpty(notes))
                {
                    imdiSession.AddActorDescription(actor, new LanguageString {
                        Value = notes, Iso3LanguageId = analysisLanguage
                    });
                }
            }

            // get contributors
            foreach (var contributor in saymoreSession.GetAllContributorsInSession())
            {
                var actr = actors.FirstOrDefault(a => a.Name == contributor.Name);
                if (actr != null)
                {
                    continue;
                }
                var msg = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.PersonNotParticipating",
                                                        "{0} is listed as a contributor but not a participant in {1} session.");
                model.AdditionalMessages[string.Format(msg, contributor.Name, saymoreSession.Id)] =
                    ArchivingDlgViewModel.MessageType.Error;
                imdiSession.AddActor(contributor);
            }

            // session files
            var files = saymoreSession.GetSessionFilesToArchive(model.GetType());

            foreach (var file in files)
            {
                if (file.EndsWith(Settings.Default.MetadataFileExtension, StringComparison.InvariantCulture))
                {
                    continue;
                }
                imdiSession.AddFile(CreateArchivingFile(file));
                var info = saymoreSession.GetComponentFiles()
                           .FirstOrDefault(componentFile => componentFile.PathToAnnotatedFile == file);
                if (info == null)
                {
                    continue;
                }
                var notes = (from infoValue in info.MetaDataFieldValues
                             where infoValue.FieldId == "notes"
                             select infoValue.ValueAsString).FirstOrDefault();
                if (!string.IsNullOrEmpty(notes))
                {
                    imdiSession.AddFileDescription(file, new LanguageString {
                        Value = notes, Iso3LanguageId = analysisLanguage
                    });
                }
                if (!info.FileType.IsAudioOrVideo)
                {
                    continue;
                }
                var duration = (from infoValue in info.MetaDataFieldValues
                                where infoValue.FieldId == "Duration"
                                select infoValue.ValueAsString).FirstOrDefault();
                if (!string.IsNullOrEmpty(duration))
                {
                    imdiSession.AddMediaFileTimes(file, "00:00:00", duration);
                }
                var device = (from infoValue in info.MetaDataFieldValues
                              where infoValue.FieldId == "Device"
                              select infoValue.ValueAsString).FirstOrDefault();
                if (!string.IsNullOrEmpty(device))
                {
                    imdiSession.AddFileKeyValuePair(file, "RecordingEquipment", device);
                }
                var microphone = (from infoValue in info.MetaDataFieldValues
                                  where infoValue.FieldId == "Microphone"
                                  select infoValue.ValueAsString).FirstOrDefault();
                if (!string.IsNullOrEmpty(microphone))
                {
                    imdiSession.AddFileKeyValuePair(file, "RecordingEquipment", microphone);
                }
            }
        }
		// We now accept languages not in the Arbil list
		//[Test]
		//public void SetAbstract_BogusLanguage_ThrowsException()
		//{
		//    _model.Initialize();
		//    Dictionary<string, string> descriptions = new Dictionary<string, string>();
		//    descriptions["eng"] = "Story about a frog";
		//    descriptions["frn"] = "L'histoire d'une grenouille";
		//    Assert.Throws(typeof (ArgumentException), () => _model.SetAbstract(descriptions));
		//}

		#endregion

		#region Helper methods
		/// ------------------------------------------------------------------------------------
		private void SetFilesToArchive(ArchivingDlgViewModel model)
		{
			if (_filesToAdd == null)
				return;
			foreach (var kvp in _filesToAdd)
				model.AddFileGroup(kvp.Key, kvp.Value.Item1, kvp.Value.Item2);
		}
Beispiel #14
0
        private static void AddIMDIProjectData(Project saymoreProject, ArchivingDlgViewModel model)
        {
            var package = (IMDIPackage)model.ArchivingPackage;

            // location
            package.Location = new ArchivingLocation
            {
                Address   = saymoreProject.Location,
                Region    = saymoreProject.Region,
                Country   = saymoreProject.Country,
                Continent = saymoreProject.Continent
            };

            // description
            package.AddDescription(new LanguageString(saymoreProject.ProjectDescription, null));

            // content type
            package.ContentType = null;

            // funding project
            package.FundingProject = new ArchivingProject
            {
                Title = saymoreProject.FundingProjectTitle,
                Name  = saymoreProject.FundingProjectTitle
            };

            // athor
            package.Author = saymoreProject.ContactPerson;

            // applications
            package.Applications = null;

            // access date
            package.Access.DateAvailable = saymoreProject.DateAvailable;

            // access owner
            package.Access.Owner = saymoreProject.RightsHolder;

            // publisher
            package.Publisher = saymoreProject.Depositor;

            // subject language
            if (!string.IsNullOrEmpty(saymoreProject.VernacularISO3CodeAndName))
            {
                var parts = saymoreProject.VernacularISO3CodeAndName.SplitTrimmed(':').ToArray();
                if (parts.Length == 2)
                {
                    var language = LanguageList.FindByISO3Code(parts[0]);

                    // SP-765:  Allow codes from Ethnologue that are not in the Arbil list
                    if ((language == null) || (string.IsNullOrEmpty(language.EnglishName)))
                    {
                        package.ContentIso3Languages.Add(new ArchivingLanguage(parts[0], parts[1], parts[1]));
                    }
                    else
                    {
                        package.ContentIso3Languages.Add(new ArchivingLanguage(language.Iso3Code, parts[1], language.EnglishName));
                    }
                }
            }

            // project description documents
            var docsPath = Path.Combine(saymoreProject.FolderPath, ProjectDescriptionDocsScreen.kFolderName);

            if (Directory.Exists(docsPath))
            {
                var files = Directory.GetFiles(docsPath, "*.*", SearchOption.TopDirectoryOnly);

                // the directory exists and contains files
                if (files.Length > 0)
                {
                    AddDocumentsSession(ProjectDescriptionDocsScreen.kArchiveSessionName, files, model);
                }
            }

            // other project documents
            docsPath = Path.Combine(saymoreProject.FolderPath, ProjectOtherDocsScreen.kFolderName);
            if (Directory.Exists(docsPath))
            {
                var files = Directory.GetFiles(docsPath, "*.*", SearchOption.TopDirectoryOnly);

                // the directory exists and contains files
                if (files.Length > 0)
                {
                    AddDocumentsSession(ProjectOtherDocsScreen.kArchiveSessionName, files, model);
                }
            }
        }
Beispiel #15
0
        private static void AddIMDISession(Session saymoreSession, ArchivingDlgViewModel model)
        {
            var sessionFile = saymoreSession.MetaDataFile;

            // create IMDI session
            var imdiSession = model.AddSession(saymoreSession.Id);

            imdiSession.Title = saymoreSession.Title;

            // session location
            var address   = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Address", null);
            var region    = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Region", null);
            var country   = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Country", null);
            var continent = saymoreSession.MetaDataFile.GetStringValue("additional_Location_Continent", null);

            if (string.IsNullOrEmpty(address))
            {
                address = saymoreSession.MetaDataFile.GetStringValue("location", null);
            }

            imdiSession.Location = new ArchivingLocation {
                Address = address, Region = region, Country = country, Continent = continent
            };

            // session description (synopsis)
            var stringVal = saymoreSession.MetaDataFile.GetStringValue("synopsis", null);

            if (!string.IsNullOrEmpty(stringVal))
            {
                imdiSession.AddDescription(new LanguageString {
                    Value = stringVal
                });
            }

            // session date
            stringVal = saymoreSession.MetaDataFile.GetStringValue("date", null);
            if (!string.IsNullOrEmpty(stringVal))
            {
                imdiSession.SetDate(DateTime.Parse(stringVal).ToISO8601TimeFormatDateOnlyString());
            }

            // session situation
            stringVal = saymoreSession.MetaDataFile.GetStringValue("situation", null);
            if (!string.IsNullOrEmpty(stringVal))
            {
                imdiSession.AddKeyValuePair("Situation", stringVal);
            }

            imdiSession.Genre         = GetFieldValue(sessionFile, "genre");
            imdiSession.SubGenre      = GetFieldValue(sessionFile, "additional_Sub-Genre");
            imdiSession.AccessCode    = GetFieldValue(sessionFile, "access");
            imdiSession.Interactivity = GetFieldValue(sessionFile, "additional_Interactivity");
            imdiSession.Involvement   = GetFieldValue(sessionFile, "additional_Involvement");
            imdiSession.PlanningType  = GetFieldValue(sessionFile, "additional_Planning_Type");
            imdiSession.SocialContext = GetFieldValue(sessionFile, "additional_Social_Context");
            imdiSession.Task          = GetFieldValue(sessionFile, "additional_Task");

            // custom session fields
            foreach (var item in saymoreSession.MetaDataFile.GetCustomFields())
            {
                imdiSession.AddKeyValuePair(item.FieldId, item.ValueAsString);
            }

            // actors
            var actors  = new ArchivingActorCollection();
            var persons = saymoreSession.GetAllPersonsInSession();

            foreach (var person in persons)
            {
                // is this person protected
                var protect = bool.Parse(person.MetaDataFile.GetStringValue("privacyProtection", "false"));

                // display message if the birth year is not valid
                var birthYear = person.MetaDataFile.GetStringValue("birthYear", string.Empty).Trim();
                if (!birthYear.IsValidBirthYear())
                {
                    var msg = LocalizationManager.GetString("DialogBoxes.ArchivingDlg.InvalidBirthYearMsg",
                                                            "The Birth Year for {0} should be either blank or a 4 digit number.");
                    model.AdditionalMessages[string.Format(msg, person.Id)] = ArchivingDlgViewModel.MessageType.Warning;
                }

                ArchivingActor actor = new ArchivingActor
                {
                    FullName   = person.Id,
                    Name       = person.MetaDataFile.GetStringValue(PersonFileType.kCode, person.Id),
                    BirthDate  = birthYear,
                    Gender     = person.MetaDataFile.GetStringValue(PersonFileType.kGender, null),
                    Education  = person.MetaDataFile.GetStringValue(PersonFileType.kEducation, null),
                    Occupation = person.MetaDataFile.GetStringValue(PersonFileType.kPrimaryOccupation, null),
                    Anonymize  = protect,
                    Role       = "Participant"
                };

                // do this to get the ISO3 codes for the languages because they are not in saymore
                var language = LanguageList.FindByEnglishName(person.MetaDataFile.GetStringValue("primaryLanguage", null));
                if (language != null)
                {
                    actor.PrimaryLanguage = new ArchivingLanguage(language.Iso3Code, language.EnglishName);
                }

                language = LanguageList.FindByEnglishName(person.MetaDataFile.GetStringValue("mothersLanguage", null));
                if (language != null)
                {
                    actor.MotherTongueLanguage = new ArchivingLanguage(language.Iso3Code, language.EnglishName);
                }

                // otherLanguage0 - otherLanguage3
                for (var i = 0; i < 4; i++)
                {
                    language = LanguageList.FindByEnglishName(person.MetaDataFile.GetStringValue("otherLanguage" + i, null));
                    if (language != null)
                    {
                        actor.Iso3Languages.Add(new ArchivingLanguage(language.Iso3Code, language.EnglishName));
                    }
                }

                // custom person fields
                foreach (var item in person.MetaDataFile.GetCustomFields())
                {
                    actor.AddKeyValuePair(item.FieldId, item.ValueAsString);
                }

                // actor files
                var actorFiles = Directory.GetFiles(person.FolderPath)
                                 .Where(f => IncludeFileInArchive(f, typeof(IMDIArchivingDlgViewModel), Settings.Default.PersonFileExtension));
                foreach (var file in actorFiles)
                {
                    actor.Files.Add(CreateArchivingFile(file));
                }

                // add actor to imdi session
                actors.Add(actor);
            }

            // get contributors
            foreach (var contributor in saymoreSession.GetAllContributorsInSession())
            {
                var actr = actors.FirstOrDefault(a => a.Name == contributor.Name);
                if (actr == null)
                {
                    actors.Add(contributor);
                }
                else
                {
                    if (actr.Role == "Participant")
                    {
                        actr.Role = contributor.Role;
                    }
                    else
                    {
                        if (!actr.Role.Contains(contributor.Role))
                        {
                            actr.Role += ", " + contributor.Role;
                        }
                    }
                }
            }

            // add actors to imdi session
            foreach (var actr in actors)
            {
                imdiSession.AddActor(actr);
            }

            // session files
            var files = saymoreSession.GetSessionFilesToArchive(model.GetType());

            foreach (var file in files)
            {
                imdiSession.AddFile(CreateArchivingFile(file));
            }
        }