/// ------------------------------------------------------------------------------------ /// <summary> /// Use this for creating new or existing elements /// </summary> /// <param name="parentElementFolder">E.g. "c:/MyProject/Sessions"</param> /// <param name="id">e.g. "ETR007"</param> /// <param name="idChangedNotificationReceiver"></param> /// <param name="componentFileFactory"></param> /// <param name="xmlFileSerializer">used to load/save</param> /// <param name="fileType"></param> /// <param name="prjElementComponentFileFactory"></param> /// <param name="componentRoles"></param> /// ------------------------------------------------------------------------------------ protected ProjectElement(string parentElementFolder, string id, Action <ProjectElement, string, string> idChangedNotificationReceiver, FileType fileType, Func <ProjectElement, string, ComponentFile> componentFileFactory, XmlFileSerializer xmlFileSerializer, ProjectElementComponentFile.Factory prjElementComponentFileFactory, IEnumerable <ComponentRole> componentRoles) { _componentFileFactory = componentFileFactory; ComponentRoles = componentRoles; RequireThat.Directory(parentElementFolder).Exists(); StageCompletedControlValues = (ComponentRoles == null ? new Dictionary <string, StageCompleteType>() : ComponentRoles.ToDictionary(r => r.Id, r => StageCompleteType.Auto)); ParentFolderPath = parentElementFolder; _id = id ?? GetNewDefaultElementName(); IdChangedNotificationReceiver = idChangedNotificationReceiver; MetaDataFile = prjElementComponentFileFactory(this, fileType, xmlFileSerializer, RootElementName); if (File.Exists(SettingsFilePath)) { Load(); } else { Directory.CreateDirectory(FolderPath); Save(); } }
/// ------------------------------------------------------------------------------------ public Session(string parentElementFolder, string id, Action <ProjectElement, string, string> idChangedNotificationReceiver, SessionFileType sessionFileType, Func <ProjectElement, string, ComponentFile> componentFileFactory, XmlFileSerializer xmlFileSerializer, ProjectElementComponentFile.Factory prjElementComponentFileFactory, IEnumerable <ComponentRole> componentRoles, PersonInformant personInformant, Project project) : base(parentElementFolder, id, idChangedNotificationReceiver, sessionFileType, componentFileFactory, xmlFileSerializer, prjElementComponentFileFactory, componentRoles) { _personInformant = personInformant; // ReSharper disable DoNotCallOverridableMethodsInConstructor // Using a 1-minute fudge factor is a bit of a kludge, but when a session is created from an // existing media file, it already has an ID, and there's no other way to tell it's "new". if (project != null && (id == null || MetaDataFile.GetCreateDate().AddMinutes(1) > DateTime.Now) && MetaDataFile.GetStringValue(SessionFileType.kCountryFieldName, null) == null && MetaDataFile.GetStringValue(SessionFileType.kRegionFieldName, null) == null && MetaDataFile.GetStringValue(SessionFileType.kContinentFieldName, null) == null && MetaDataFile.GetStringValue(SessionFileType.kAddressFieldName, null) == null) { // SP-876: Project Data not displayed in new sessions until after a restart. Program.SaveProjectMetadata(); if (!string.IsNullOrEmpty(project.Country)) { MetaDataFile.TrySetStringValue(SessionFileType.kCountryFieldName, project.Country); } if (!string.IsNullOrEmpty(project.Region)) { MetaDataFile.TrySetStringValue(SessionFileType.kRegionFieldName, project.Region); } if (!string.IsNullOrEmpty(project.Continent)) { MetaDataFile.TrySetStringValue(SessionFileType.kContinentFieldName, project.Continent); } if (!string.IsNullOrEmpty(project.Location)) { MetaDataFile.TrySetStringValue(SessionFileType.kAddressFieldName, project.Location); } } if (string.IsNullOrEmpty(MetaDataFile.GetStringValue(SessionFileType.kGenreFieldName, null))) { if (MetaDataFile.TrySetStringValue(SessionFileType.kGenreFieldName, GenreDefinition.UnknownType.Name)) { MetaDataFile.Save(); } } // ReSharper restore DoNotCallOverridableMethodsInConstructor if (_personInformant != null) { _personInformant.PersonNameChanged += HandlePersonsNameChanged; _personInformant.PersonUiIdChanged += HandlePersonsUiIdChanged; } }
/// ------------------------------------------------------------------------------------ private Session CreateSession(IEnumerable <string> participants, Project project = null, Action <Mock <ProjectElementComponentFile> > additionalSetup = null) { ProjectElementComponentFile.Factory factory = (parentElement, fileType, fileSerializer, rootElementName) => { var file = new Mock <ProjectElementComponentFile>(); file.Setup(f => f.Save()); //file.Setup( // f => f.GetStringValue(SessionFileType.kParticipantsFieldName, string.Empty)). // Returns(participants.Count() > 0 ? participants.Aggregate((a, b) => a + ";" + b) : string.Empty // ); var contributions = new Mock <ContributionCollection>(MockBehavior.Strict); foreach (var p in participants) { contributions.Object.Add(new Contribution(p, new Role("par", "Participant", null))); } file.Setup(f => f.GetValue(SessionFileType.kContributionsFieldName, null)).Returns(contributions.Object); if (additionalSetup != null) { additionalSetup(file); _mockedSessionMetaDataFile = file; } return(file.Object); }; Func <ProjectElement, string, ComponentFile> componentFactory = (parentElement, path) => { var file = new Mock <ComponentFile>(); //person.Setup(p => p.GetInformedConsentComponentFile()).Returns((ComponentFile)null); file.Setup(p => p.Save()); return(file.Object); }; var personInformant = new Mock <PersonInformant>(); foreach (var participant in participants) { personInformant.Setup(i => i.GetHasInformedConsent(participant)).Returns(participant.Contains("Consent")); } var componentRoles = new List <ComponentRole>(); componentRoles.Add(new ComponentRole(null, ComponentRole.kConsentComponentRoleId, null, ComponentRole.MeasurementTypes.None, null, null, Color.Empty, Color.Empty)); componentRoles.Add(new ComponentRole(null, ComponentRole.kSourceComponentRoleId, null, ComponentRole.MeasurementTypes.Time, FileSystemUtils.GetIsAudioVideo, ComponentRole.kElementIdToken + ComponentRole.kFileSuffixSeparator + "Source", Color.Empty, Color.Empty)); return(new Session(_parentFolder.Path, "dummyId", null, new SessionFileType(() => null, () => null, () => null), componentFactory, new XmlFileSerializer(null), factory, componentRoles, personInformant.Object, project)); //ComponentFile.CreateMinimalComponentFileForTests }
/// ------------------------------------------------------------------------------------ public Person(string parentElementFolder, string id, Action <ProjectElement, string, string> idChangedNotificationReceiver, PersonFileType personFileType, Func <ProjectElement, string, ComponentFile> componentFileFactory, XmlFileSerializer xmlFileSerializer, ProjectElementComponentFile.Factory prjElementComponentFileFactory, IEnumerable <ComponentRole> componentRoles) : base(parentElementFolder, id, idChangedNotificationReceiver, personFileType, componentFileFactory, xmlFileSerializer, prjElementComponentFileFactory, componentRoles) { }