public void GetExpirationDate_Valid_ReturnsCorrectDate(string input, int year, int month, int day) { var result = CollectionSettingsApi.GetExpirationDate(input); Assert.That(result.Year, Is.EqualTo(year)); Assert.That(result.Month, Is.EqualTo(month)); Assert.That(result.Day, Is.EqualTo(day)); }
private void OnLoad(object sender, EventArgs e) { _countryText.Text = _collectionSettings.Country; _provinceText.Text = _collectionSettings.Province; _districtText.Text = _collectionSettings.District; _bloomCollectionName.Text = _collectionSettings.CollectionName; _brand = _collectionSettings.BrandingProjectKey; _subscriptionCode = _collectionSettings.SubscriptionCode; // Set the branding as an (incomplete) code if we are running with a legacy branding if (CollectionSettingsApi.LegacyBrandingName != null && string.IsNullOrEmpty(_subscriptionCode)) { _subscriptionCode = CollectionSettingsApi.LegacyBrandingName; } CollectionSettingsApi.SetSubscriptionCode(_subscriptionCode, IsSubscriptionCodeKnown(), GetEnterpriseStatus()); _loaded = true; Logger.WriteEvent("Entered Settings Dialog"); }
/// <summary> /// Return true if the part of the subscription code that identifies the branding is one we know about. /// Either the branding files must exist or the expiration date must be set, even if expired. /// This allows new, not yet implemented, subscriptions/brandings to be recognized as valid, and expired /// subscriptions to be flagged as such but not treated as totally invalid. /// </summary> bool IsSubscriptionCodeKnown() { return(BrandingProject.HaveFilesForBranding(_brand) || CollectionSettingsApi.GetExpirationDate(_subscriptionCode) != DateTime.MinValue); }
/// ------------------------------------------------------------------------------------ public void Load() { try { // Previously was SIL.IO.RobustIO.LoadXElement(SettingsFilePath). However, we had problems with this // using some non-roman collection names...specifically, one involving the Northern Pashto // localization of 'books' (┌й╪к╪з╪и┘И┘Ж┘З)...see BL-5416. It seems that somewhere in the // implementation of Linq.XElement.Load() the path is converted to a URL and then back // to a path and something changes in that process so that a valid path passed to Load() // raises an invalid path exception. Reading the file directly and then parsing the string // works around this problem. var settingsContent = RobustFile.ReadAllText(SettingsFilePath, Encoding.UTF8); var nameMigrations = new[] { new[] { "LanguageName", "Language1Name" }, new[] { "IsShellLibrary", "IsSourceCollection" }, new[] { "National1Iso639Code", "Language2Iso639Code" }, new[] { "National2Iso639Code", "Language3Iso639Code" }, new[] { "IsShellMakingProject", "IsSourceCollection" }, new[] { "Local Community", "Local-Community" } // migrate for 4.4 }; foreach (var fromTo in nameMigrations) { settingsContent = settingsContent.Replace(fromTo[0], fromTo[1]); } var xml = XElement.Parse(settingsContent); // The default if we don't find one is the arbitrary ID generated when we initialized // the variable (at its declaration). CollectionId = ReadString(xml, "CollectionId", CollectionId); Language1.ReadFromXml(xml, true, "en"); Language2.ReadFromXml(xml, true, "self"); Language3.ReadFromXml(xml, true, Language2.Iso639Code); SignLanguageIso639Code = ReadString(xml, "SignLanguageIso639Code", /* old name */ ReadString(xml, "SignLanguageIso639Code", "")); XMatterPackName = ReadString(xml, "XMatterPack", "Factory"); var style = ReadString(xml, "PageNumberStyle", "Decimal"); //for historical (and maybe future?) reasons, we collect the page number style as one of the //CSS counter number styles PageNumberStyle = CssNumberStylesToCultureOrDigits.Keys.Contains(style) ? style : "Decimal"; OneTimeCheckVersionNumber = ReadInteger(xml, "OneTimeCheckVersionNumber", 0); BrandingProjectKey = ReadString(xml, "BrandingProjectName", "Default"); SubscriptionCode = ReadString(xml, "SubscriptionCode", null); if (BrandingProjectKey != "Default" && BrandingProjectKey != "Local-Community" && !Program.RunningHarvesterMode) { // Validate branding, so things can't be circumvented by just typing something random into settings var expirationDate = CollectionSettingsApi.GetExpirationDate(SubscriptionCode); if (expirationDate < DateTime.Now) // no longer require branding files to exist yet { InvalidBranding = BrandingProjectKey; BrandingProjectKey = "Default"; // keep the code, but don't use it as active branding. } } SignLanguageName = ReadString(xml, "SignLanguageName", GetSignLanguageName_NoCache()); Country = ReadString(xml, "Country", ""); Province = ReadString(xml, "Province", ""); District = ReadString(xml, "District", ""); AllowNewBooks = ReadBoolean(xml, "AllowNewBooks", true); IsSourceCollection = ReadBoolean(xml, "IsSourceCollection", false); string audioRecordingModeStr = ReadString(xml, "AudioRecordingMode", "Unknown"); TalkingBookApi.AudioRecordingMode parsedAudioRecordingMode; if (!Enum.TryParse(audioRecordingModeStr, out parsedAudioRecordingMode)) { parsedAudioRecordingMode = TalkingBookApi.AudioRecordingMode.Unknown; } AudioRecordingMode = parsedAudioRecordingMode; AudioRecordingTrimEndMilliseconds = ReadInteger(xml, "AudioRecordingTrimEndMilliseconds", kDefaultAudioRecordingTrimEndMilliseconds); Administrators = ReadString(xml, "Administrators", "") .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); var defaultTags = ReadString(xml, "DefaultBookTags", "").Split(','); var defaultBookshelfTag = defaultTags.Where(t => t.StartsWith("bookshelf:")).FirstOrDefault(); DefaultBookshelf = defaultBookshelfTag == null ? "" : defaultBookshelfTag.Substring("bookshelf:".Length); var bulkPublishSettingsFromXml = BulkBloomPubPublishSettings.LoadFromXElement(xml); if (bulkPublishSettingsFromXml != null) { BulkPublishBloomPubSettings = bulkPublishSettingsFromXml; } } catch (Exception) { string settingsContents; try { settingsContents = RobustFile.ReadAllText(SettingsFilePath); } catch (Exception error) { settingsContents = error.Message; } Logger.WriteEvent("Contents of " + SettingsFilePath + ": /r/n" + settingsContents); // We used to notify the user of a problem here. // But now we decided it is better to catch at a higher level, at OpenProjectWindow(), else we have two different // error UI dialogs for the same problem. See BL-9916. throw; } try { string oldcustomCollectionStylesPath = FolderPath.CombineForPath("collection.css"); if (RobustFile.Exists(oldcustomCollectionStylesPath)) { string newcustomCollectionStylesPath = FolderPath.CombineForPath("customCollectionStyles.css"); RobustFile.Move(oldcustomCollectionStylesPath, newcustomCollectionStylesPath); } } catch (Exception) { //ah well, we tried, no big deal, only a couple of beta testers used this old name } // Check if we need to do a one time check (perhaps migrate to a new Settings value) if (OneTimeCheckVersionNumber < kCurrentOneTimeCheckVersionNumber) { DoOneTimeCheck(); } SetAnalyticsProperties(); }
/// ------------------------------------------------------------------------------------ public void Load() { try { // Previously was SIL.IO.RobustIO.LoadXElement(SettingsFilePath). However, we had problems with this // using some non-roman collection names...specifically, one involving the Northern Pashti // localization of 'books' (┌й╪к╪з╪и┘И┘Ж┘З)...see BL-5416. It seems that somewhere in the // implementation of Linq.XElement.Load() the path is converted to a URL and then back // to a path and something changes in that process so that a valid path passed to Load() // raises an invalid path exception. Reading the file directly and then parsing the string // works around this problem. var settingsContent = RobustFile.ReadAllText(SettingsFilePath, Encoding.UTF8); var nameMigrations = new[] { new[] { "LanguageName", "Language1Name" }, new[] { "IsShellLibrary", "IsSourceCollection" }, new[] { "National1Iso639Code", "Language2Iso639Code" }, new[] { "National2Iso639Code", "Language3Iso639Code" }, new[] { "IsShellMakingProject", "IsSourceCollection" }, new[] { "Local Community", "Local-Community" } // migrate for 4.4 }; foreach (var fromTo in nameMigrations) { settingsContent = settingsContent.Replace(fromTo[0], fromTo[1]); } var xml = XElement.Parse(settingsContent); Language1.ReadFromXml(xml, true, "en"); Language2.ReadFromXml(xml, true, "self"); Language3.ReadFromXml(xml, true, Language2.Iso639Code); SignLanguageIso639Code = ReadString(xml, "SignLanguageIso639Code", /* old name */ ReadString(xml, "SignLanguageIso639Code", "")); XMatterPackName = ReadString(xml, "XMatterPack", "Factory"); var style = ReadString(xml, "PageNumberStyle", "Decimal"); //for historical (and maybe future?) reasons, we collect the page number style as one of the //CSS counter number styles PageNumberStyle = CssNumberStylesToCultureOrDigits.Keys.Contains(style) ? style : "Decimal"; OneTimeCheckVersionNumber = ReadInteger(xml, "OneTimeCheckVersionNumber", 0); BrandingProjectKey = ReadString(xml, "BrandingProjectName", "Default"); SubscriptionCode = ReadString(xml, "SubscriptionCode", null); if (BrandingProjectKey != "Default" && BrandingProjectKey != "Local-Community" && !Program.RunningHarvesterMode) { // Validate branding, so things can't be circumvented by just typing something into settings var expirationDate = CollectionSettingsApi.GetExpirationDate(SubscriptionCode); if (expirationDate < DateTime.Now || BrandingProject.GetProjectChoices().All(bp => bp.Key != BrandingProjectKey)) { InvalidBranding = BrandingProjectKey; BrandingProjectKey = "Default"; // keep the code, but don't use it as active branding. } } SignLanguageName = ReadString(xml, "SignLanguageName", GetSignLanguageName_NoCache()); Country = ReadString(xml, "Country", ""); Province = ReadString(xml, "Province", ""); District = ReadString(xml, "District", ""); AllowNewBooks = ReadBoolean(xml, "AllowNewBooks", true); IsSourceCollection = ReadBoolean(xml, "IsSourceCollection", false); string audioRecordingModeStr = ReadString(xml, "AudioRecordingMode", "Unknown"); TalkingBookApi.AudioRecordingMode parsedAudioRecordingMode; if (!Enum.TryParse(audioRecordingModeStr, out parsedAudioRecordingMode)) { parsedAudioRecordingMode = TalkingBookApi.AudioRecordingMode.Unknown; } AudioRecordingMode = parsedAudioRecordingMode; AudioRecordingTrimEndMilliseconds = ReadInteger(xml, "AudioRecordingTrimEndMilliseconds", kDefaultAudioRecordingTrimEndMilliseconds); } catch (Exception e) { string settingsContents = ""; try { settingsContents = RobustFile.ReadAllText(SettingsFilePath); } catch (Exception error) { settingsContents = error.Message; } Logger.WriteEvent("Contents of " + SettingsFilePath + ": /r/n" + settingsContents); SIL.Reporting.ErrorReport.NotifyUserOfProblem(e, "There was an error reading the file {0}. Please report this error to the developers. To get access to your books, you should make a new collection, then copy your book folders from this broken collection into the new one, then run Bloom again.", SettingsFilePath); throw; } try { string oldcustomCollectionStylesPath = FolderPath.CombineForPath("collection.css"); if (RobustFile.Exists(oldcustomCollectionStylesPath)) { string newcustomCollectionStylesPath = FolderPath.CombineForPath("customCollectionStyles.css"); RobustFile.Move(oldcustomCollectionStylesPath, newcustomCollectionStylesPath); } } catch (Exception) { //ah well, we tried, no big deal, only a couple of beta testers used this old name } // Check if we need to do a one time check (perhaps migrate to a new Settings value) if (OneTimeCheckVersionNumber < kCurrentOneTimeCheckVersionNumber) { DoOneTimeCheck(); } SetAnalyticsProperties(); }
public void SummaryHtmlGetsFlavorVariablesFilledIn(string fullEnterpriseCode, string expectedFolderName, string expectedFlavor) { var result = CollectionSettingsApi.GetSummaryHtml(fullEnterpriseCode); Assert.That(result, Contains.Substring(expectedFlavor)); }
[TestCase("Acme-003506-", true)] // No digits in part 3 is OK, even though part 3 won't parse public void SubscriptionAppearsIncomplete(string input, bool incomplete) { var result = CollectionSettingsApi.SubscriptionCodeLooksIncomplete(input); Assert.That(result, Is.EqualTo(incomplete)); }
[TestCase("Somevery long fake thing-361769-19523")] // Too many digits in part 3 public void GetExpirationDate_InValid_ReturnsMinDate(string input) { var result = CollectionSettingsApi.GetExpirationDate(input); Assert.That(result, Is.EqualTo(DateTime.MinValue)); }