Example #1
0
        /// ------------------------------------------------------------------------------------
        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;
            }
        }