/// <summary> /// Read location values from the specified text into this point. /// </summary> /// <param name="text">text with location</param> /// <exception cref="ArgumentNullException">null text</exception> public void Read(string text) { if (text == null) { throw new ArgumentNullException(nameof(text)); } Match m = _pointRegex.Match(text); if (!m.Success) { throw new ArgumentException(LocalizedStrings.Format( Properties.Resources.InvalidTokenPoint, text)); } Y = int.Parse(m.Groups["y"].Value, CultureInfo.InvariantCulture); X = int.Parse(m.Groups["x"].Value, CultureInfo.InvariantCulture); // at, run if (m.Groups["at"].Length > 0) { At = short.Parse(m.Groups["at"].Value, CultureInfo.InvariantCulture); Run = m.Groups["run"].Length > 0 ? short.Parse(m.Groups["run"].Value, CultureInfo.InvariantCulture) : (short)1; } else { At = Run = 0; } }
//@@hack: workaround for main view code behind /// <summary> /// Determines whether this instance can close. This is meant to be called by the view /// code behind when testing if a document can close (OnDocumentClosing). /// </summary> /// <returns>true if can close</returns> public bool CanClose() { if (!IsDirty()) { return(true); } MessageBoxAction prompt = new MessageBoxAction { Caption = App.APP_NAME, Text = LocalizedStrings.Format(StringResources.DiscardDocumentChangesPrompt, DisplayName), Button = MessageBoxButton.YesNo, Image = MessageBoxImage.Question }; bool bResult = true; prompt.Completed += (sender, e) => { bResult = prompt.Result == MessageBoxResult.Yes; }; prompt.Execute(null); return(bResult); }
/// <summary> /// Called to check whether or not this instance can close. /// </summary> /// <param name="callback">The implementor calls this action with the result /// of the close check.</param> public override void CanClose(Action <bool> callback) { // if forcing (@@hack) or not dirty it's OK to close if ((_bIsForcedClosing) || (!IsDirty())) { callback(true); return; } //eif // else prompt user MessageBoxAction prompt = new MessageBoxAction { Caption = App.APP_NAME, Text = LocalizedStrings.Format(StringResources.DiscardDocumentChangesPrompt, DisplayName), Button = MessageBoxButton.YesNo, Image = MessageBoxImage.Question }; prompt.Completed += (sender, e) => { callback(prompt.Result == MessageBoxResult.Yes); }; prompt.Execute(null); }
/// <summary> /// Initializes a new instance of the <see cref="ThesaurusEntry"/> class. /// </summary> /// <param name="id">The identifier.</param> /// <param name="value">The value.</param> /// <exception cref="ArgumentNullException">id or value</exception> /// <exception cref="ArgumentException">invalid ID</exception> public ThesaurusEntry(string id, string value) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (!Regex.IsMatch(id, @"^[a-zA-Z0-9_\-\.]+$")) { throw new ArgumentException(LocalizedStrings.Format( Properties.Resources.InvalidTagId, id)); } Id = id; Value = value ?? throw new ArgumentNullException(nameof(value)); }
/// <summary> /// Validate this profile. /// </summary> /// <remarks> /// These conditions are checked: /// <list type="bullet"> /// <item> /// <description>there must be at least 1 facet definition;</description> /// </item> /// <item> /// <description>there must be at least 1 part definition inside /// each facet definition;</description> /// </item> /// <item> /// <description>if a facet definition contains a part definition /// referring to a layer (=with a role ID starting with /// <see cref="PartBase.FR_PREFIX"/>), the same facet must have a part /// with role ID = <see cref="PartBase.BASE_TEXT_ROLE_ID"/>, representing /// its base text;</description> /// </item> /// <item> /// <description>in each facet, there cannot be more than 1 part /// definition with role ID = <see cref="PartBase.BASE_TEXT_ROLE_ID"/>. /// </description> /// </item> /// </list> /// </remarks> /// <returns> /// An error message if the profile is not valid; else, null. /// </returns> public string Validate() { // at least 1 facet if (Facets == null || Facets.Length == 0) { return(Properties.Resources.NoFacetInProfile); } // at least 1 part per facet FacetDefinition emptyFacet = Array.Find( Facets, f => f.PartDefinitions.Count == 0); if (emptyFacet != null) { return(LocalizedStrings.Format( Properties.Resources.NoPartInFacet, emptyFacet.Id)); } // layers imply a single base text part foreach (FacetDefinition facet in Facets) { // any layers? if (facet.PartDefinitions.Any(def => def.RoleId?.StartsWith( PartBase.FR_PREFIX, StringComparison.Ordinal) == true)) { // there must be a base text int count = facet.PartDefinitions.Count( def => def.RoleId == PartBase.BASE_TEXT_ROLE_ID); if (count == 0) { return(LocalizedStrings.Format( Properties.Resources.LayerPartsWithoutBaseText, facet.Id)); } if (count > 1) { return(LocalizedStrings.Format( Properties.Resources.MultipleBaseTexts, facet.Id)); } } } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="Thesaurus"/> class. /// </summary> /// <param name="id">The identifier.</param> /// <exception cref="ArgumentNullException">id</exception> public Thesaurus(string id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (!Regex.IsMatch(id, @"^[a-zA-Z0-9_\-\.]+\@[a-z]{2,3}$")) { throw new ArgumentException(LocalizedStrings.Format( Properties.Resources.InvalidTagSetId, id)); } Id = id; _entries = new Dictionary <string, ThesaurusEntry>(); _sortedIds = new List <string>(); }