private void OnAddCategoryClicked(object sender, System.Windows.RoutedEventArgs e) { // Lets validate again, just because. if (!IsInputValid) { return; } if (CategoryCreated != null) { try { var source = TryGetSourceUri(m_textboxCategoryUrl.Text); var filteringCategory = new FilteringCategory(m_engine); filteringCategory.RuleSource = source; filteringCategory.CategoryName = m_textboxCategoryName.Text; CategoryCreated(this, new FilteringCategoryCreatedArgs(filteringCategory)); } catch (ArgumentException ae) { // Attempt to notify user of error MetroDialogSettings mds = new MetroDialogSettings(); mds.AffirmativeButtonText = "Ok"; MetroWindow parentWindow = this.TryFindParent <MetroWindow>(); if (parentWindow != null) { DialogManager.ShowMessageAsync(parentWindow, "Error", "Error creating new filtering category.", MessageDialogStyle.Affirmative, mds); } } Reset(); } }
/// <summary> /// /// </summary> /// <param name="category"></param> /// <exception cref="ArgumentException"> /// </exception> public CategorizedFilteredRequestsViewModel(FilteringCategory category) { m_category = category; if (m_category == null) { throw new ArgumentException("Expected valid FilteringCategory instance."); } }
/// <summary> /// Constructs a new FilteringCategoryCreatedArgs instance. /// </summary> /// <param name="category"> /// The newly created FilteringCategory. /// </param> /// <exception cref="ArgumentException"> /// In the event that the supplied category parameter is null, will throw ArgumentException. /// </exception> public FilteringCategoryCreatedArgs(FilteringCategory category) { Category = category; if (Category == null) { throw new ArgumentException("Expected valid instance of FilteringCategory"); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JObject jo = JObject.Load(reader); var cat = new FilteringCategory(m_engine); cat.CategoryName = jo["CategoryName"].ToObject <string>(); cat.RuleSource = jo["RuleSource"].ToObject <Uri>(); cat.TotalDataBlocked = ByteSize.FromBytes(jo["TotalDataBlocked"]["Bytes"].ToObject <double>()); cat.TotalRequestsBlocked = jo["TotalRequestsBlocked"].ToObject <ulong>(); cat.Enabled = jo["Enabled"].ToObject <bool>(); return(cat); }