Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
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..."));
            }
        }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
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));
            }
        }