/// ------------------------------------------------------------------------------------ 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; } }
/// <overloads> /// Returns the absolute path to a predefined or specified XML session description file. /// </overloads> /// <summary> /// Returns the absolute path to a predefined XML session description file.</summary> /// <param name="type"> /// A <see cref="SessionFileType"/> value indicating the predefined XML session description /// file whose path to return.</param> /// <returns> /// A <see cref="RootedPath"/> wrapping the absolute path to the predefined XML session /// description file of the specified <paramref name="type"/>.</returns> /// <exception cref="InvalidEnumArgumentException"> /// <paramref name="type"/> specifies an invalid <see cref="SessionFileType"/> value. /// </exception> /// <remarks> /// <b>GetSessionFile</b> always returns a file path below <see cref="UserFolder"/>. Please /// refer to <see cref="SessionFileType"/> for details.</remarks> public static RootedPath GetSessionFile(SessionFileType type) { switch (type) { case SessionFileType.Auto: return(GetSessionFile("AutoSave.xml.gz")); case SessionFileType.Computer: return(GetSessionFile("ComputerSave.xml.gz")); case SessionFileType.Debug: return(CreateUserPath("Session.Debug.xml.gz")); case SessionFileType.Email: return(GetSessionFile("EmailSave.xml.gz")); default: ThrowHelper.ThrowInvalidEnumArgumentException( "type", (int)type, typeof(SessionFileType)); return(null); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// can be used whether the project exists already, or not /// </summary> /// ------------------------------------------------------------------------------------ public Project(string desiredOrExistingSettingsFilePath, ElementRepository <Session> .Factory sessionsRepoFactory, SessionFileType sessionFileType) { _sessionsRepoFactory = sessionsRepoFactory; _sessionFileType = sessionFileType; SettingsFilePath = desiredOrExistingSettingsFilePath; Name = Path.GetFileNameWithoutExtension(desiredOrExistingSettingsFilePath); var projectDirectory = Path.GetDirectoryName(desiredOrExistingSettingsFilePath); var saveNeeded = false; if (File.Exists(desiredOrExistingSettingsFilePath)) { RenameEventsToSessions(projectDirectory); Load(); } else { var parentDirectoryPath = Path.GetDirectoryName(projectDirectory); if (parentDirectoryPath != null) { if (!Directory.Exists(parentDirectoryPath)) { Directory.CreateDirectory(parentDirectoryPath); } if (!Directory.Exists(projectDirectory)) { Directory.CreateDirectory(projectDirectory); } } Title = Name; saveNeeded = true; } if (TranscriptionFont == null) { TranscriptionFont = Program.DialogFont; } if (FreeTranslationFont == null) { FreeTranslationFont = Program.DialogFont; } if (AutoSegmenterMinimumSegmentLengthInMilliseconds < Settings.Default.MinimumSegmentLengthInMilliseconds || AutoSegmenterMaximumSegmentLengthInMilliseconds <= 0 || AutoSegmenterMinimumSegmentLengthInMilliseconds >= AutoSegmenterMaximumSegmentLengthInMilliseconds || AutoSegmenterPreferrerdPauseLengthInMilliseconds <= 0 || AutoSegmenterPreferrerdPauseLengthInMilliseconds > AutoSegmenterMaximumSegmentLengthInMilliseconds || AutoSegmenterOptimumLengthClampingFactor <= 0) { saveNeeded = AutoSegmenterMinimumSegmentLengthInMilliseconds != 0 || AutoSegmenterMaximumSegmentLengthInMilliseconds != 0 || AutoSegmenterPreferrerdPauseLengthInMilliseconds != 0 || !AutoSegmenterOptimumLengthClampingFactor.Equals(0) || saveNeeded; AutoSegmenterMinimumSegmentLengthInMilliseconds = Settings.Default.DefaultAutoSegmenterMinimumSegmentLengthInMilliseconds; AutoSegmenterMaximumSegmentLengthInMilliseconds = Settings.Default.DefaultAutoSegmenterMaximumSegmentLengthInMilliseconds; AutoSegmenterPreferrerdPauseLengthInMilliseconds = Settings.Default.DefaultAutoSegmenterPreferrerdPauseLengthInMilliseconds; AutoSegmenterOptimumLengthClampingFactor = Settings.Default.DefaultAutoSegmenterOptimumLengthClampingFactor; } if (saveNeeded) { Save(); } }