private void OnSaveSetting(object sender, ExecutedRoutedEventArgs e) { BindingGroup.CommitEdit(); var saveSettingCommand = (ICommand)(DataContext as dynamic).SaveSettingCommand; saveSettingCommand.Execute(e.Parameter); }
public void TestItemBindingGroup() { var lb = ListBox(); var group = new BindingGroup(); lb.ItemBindingGroup(group).ItemBindingGroup.Should().Be(group); }
public AddJourneyWithLiftsControl() { BindingGroup = new BindingGroup(); CommandBindings.Add(new CommandBinding(SettingsCommands.LoadSettingCommand, OnLoadSetting)); CommandBindings.Add(new CommandBinding(SettingsCommands.SaveSettingCommand, OnSaveSetting)); CommandBindings.Add(new CommandBinding(SettingsCommands.RemoveSettingCommand, OnRemoveSetting)); }
// Token: 0x060046ED RID: 18157 RVA: 0x00141CEC File Offset: 0x0013FEEC internal void BuildVisualTree() { if (this.NeedsVisualTree) { DataGridColumn column = this.Column; if (column != null) { DataGridRow rowOwner = this.RowOwner; if (rowOwner != null) { BindingGroup bindingGroup = rowOwner.BindingGroup; if (bindingGroup != null) { this.RemoveBindingExpressions(bindingGroup, base.Content as DependencyObject); } } FrameworkElement frameworkElement = column.BuildVisualTree(this.IsEditing, this.RowDataItem, this); FrameworkElement frameworkElement2 = base.Content as FrameworkElement; if (frameworkElement2 != null && frameworkElement2 != frameworkElement) { ContentPresenter contentPresenter = frameworkElement2 as ContentPresenter; if (contentPresenter == null) { frameworkElement2.SetValue(FrameworkElement.DataContextProperty, BindingExpressionBase.DisconnectedItem); } else { contentPresenter.Content = BindingExpressionBase.DisconnectedItem; } } base.Content = frameworkElement; } } }
/// <summary> /// Tells the row owner about this element. /// </summary> public override void OnApplyTemplate() { // If a new template has just been generated then // be sure to clear any stale ItemsHost references if (InternalItemsHost != null && !this.IsAncestorOf(InternalItemsHost)) { InternalItemsHost = null; } #if BindingGroups if (ItemBindingGroup == null) { ItemBindingGroup = new BindingGroup(); } #endif base.OnApplyTemplate(); DataGridRow owningRow = DataGridRowOwner; if (owningRow != null) { owningRow.CellsPresenter = this; Item = owningRow.Item; } // At the time that a Row is prepared we can't [....] because the CellsPresenter isn't created yet. // Doing it here ensures that the CellsPresenter is in the visual tree. SyncProperties(false); }
internal static void UpdateTarget(FrameworkElement element) { BindingGroup bindingGroup = element.BindingGroup; DataGridCell cell = (element != null) ? element.Parent as DataGridCell : null; if (bindingGroup != null && cell != null) { Collection <BindingExpressionBase> expressions = bindingGroup.BindingExpressions; BindingExpressionBase[] bindingExpressionsCopy = new BindingExpressionBase[expressions.Count]; expressions.CopyTo(bindingExpressionsCopy, 0); for (int i = 0; i < bindingExpressionsCopy.Length; i++) { // Check the binding's target element - it might have been GC'd // (this can happen when column-virtualization is enabled, see Dev11 131232). // If so, fetching TargetElement will detach the binding and remove it // from the binding group's collection. This side-effect is why we // loop through a copy of the original collection, and don't rely // on i to be a valid index into the original collection. BindingExpressionBase beb = bindingExpressionsCopy[i]; DependencyObject targetElement = beb.TargetElement; if (targetElement != null && VisualTreeHelper.IsAncestorOf(cell, targetElement, typeof(DataGridCell))) { beb.UpdateTarget(); } } } }
private void Unesi(object sender, RoutedEventArgs e) { if (BindingGroup.CommitEdit()) { foreach (clsSirovina os in sirovine) { if (os.sifra == sifra) { MessageBox.Show("Sirovina sa tom sifrom VEĆ postoji!"); return; } if (os.naziv == naziv) { MessageBox.Show("Sirovina sa tim nazivom VEĆ postoji!"); return; } } //MessageBox.Show("Sirovina sa tim imenom ili sifrom NE postoji!"); //na ovaj način kažemo da je unos urađen i da je sve ok DialogResult = true; Close(); } else { MessageBox.Show("Došlo je do greške prilikom unosa podataka u edit poljima!"); } //if (BindingGroup.CommitEdit()) //{ // DialogResult = true; // Close(); //} }
private void treeViewFeeds_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { this.ViewModel.CurrentItem = e.NewValue as FeedViewModel; BindingGroup.BeginEdit(); IsEditing = false; }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { BindingGroup group = (BindingGroup)value; List <string> errors = new List <string>(); foreach (var item in group.Items) { IDataErrorInfo info = item as IDataErrorInfo; if (info != null) { if (!string.IsNullOrEmpty(info.Error)) { errors.Add(info.Error); } } else { var results = VAB.Validation.Validate(item);//, VAB.ValidationSpecificationSource.All); if (!results.IsValid) { errors.AddRange(results.Select(r => r.Message)); } } } if (errors.Count > 0) { return(new ValidationResult(false, string.Join("; ", errors))); } return(ValidationResult.ValidResult); }
private static HelpInfo CreateHelpInfo(BindingGroup bindingGroup) { var helpCmd = bindingGroup.PropertyBag.HelpCmd(); var helpUrl = bindingGroup.PropertyBag.HelpUrl(); return(new HelpInfo(helpCmd, helpUrl)); }
private GroupBindingModel CreateGroupBindingModel(BindingGroup groupBinding) { GroupTypes grpCtrl = GroupTypes.Display; // determine the type of group binding if (groupBinding.Control != null) { grpCtrl = groupBinding.Control.GroupType; } GroupBindingModel gbm = null; // create the group binding model type switch (grpCtrl) { case GroupTypes.Display: gbm = new DisplayGroupBindingModel(); break; case GroupTypes.Options: gbm = new OptionsGroupBindingModel(); break; } return(gbm); }
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo) { if (_checkEnbled == null || _checkEnbled.IsEnabled == true) { if (value == null || value == DBNull.Value || value.GetType() == typeof(string) && string.IsNullOrEmpty(value.ToString())) { return(new ValidationResult(false, string.IsNullOrWhiteSpace(ErrorMessage) ? "Значение не может быть пустым" : ErrorMessage)); } else if (!string.IsNullOrWhiteSpace(ValidationProperty)) { BindingGroup bg = value as BindingGroup; if (bg != null) { if (bg.Items[0] is DataRowView && (bg.Items[0] as DataRowView).Row.RowState == DataRowState.Deleted) { return(ValidationResult.ValidResult); } var val = TypeDescriptor.GetProperties(bg.Items[0])[ValidationProperty].GetValue(bg.Items[0]); //DataRowView val = bg.Items[0] as DataRowView; if (val == null || val == DBNull.Value || val.GetType() == typeof(string) && string.IsNullOrEmpty(val.ToString())) { return(new ValidationResult(false, string.IsNullOrWhiteSpace(ErrorMessage) ? "Значение не может быть пустым" : ErrorMessage)); } else { return(ValidationResult.ValidResult); } } } } return(ValidationResult.ValidResult); }
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo) { BindingGroup bindingGroup = (BindingGroup)value; if (bindingGroup.Items.Count > 0) { SourcePostgres.Model.PgStyleLayerM layerStyle = (SourcePostgres.Model.PgStyleLayerM)bindingGroup.Items[0]; String fontName = (String)bindingGroup.GetValue(layerStyle, "FontName"); if (String.IsNullOrWhiteSpace(fontName)) { return(new ValidationResult(false, "Не задан шрифт точечных объектов")); } object penWidthObj = bindingGroup.GetValue(layerStyle, "PenWidth"); int penWidth = -1; try { penWidth = Convert.ToInt32(penWidthObj); } catch (Exception ex) { String mes = "Ошибка в значении толщины линий: \n" + ex.Message; return(new ValidationResult(false, mes)); } return(ValidationResult.ValidResult); } else { return(new ValidationResult(false, "Не выбран объект для отображения")); } }
/// <summary> /// Tells the row owner about this element. /// </summary> public override void OnApplyTemplate() { // If a new template has just been generated then // be sure to clear any stale ItemsHost references if (InternalItemsHost != null && !this.IsAncestorOf(InternalItemsHost)) { InternalItemsHost = null; } #if BindingGroups if (ItemBindingGroup == null) { ItemBindingGroup = new BindingGroup(); } #endif base.OnApplyTemplate(); DataGridRow owningRow = DataGridRowOwner; if (owningRow != null) { owningRow.CellsPresenter = this; Item = owningRow.Item; } // At the time that a Row is prepared we can't Sync because the CellsPresenter isn't created yet. // Doing it here ensures that the CellsPresenter is in the visual tree. SyncProperties(false); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { try { if (value == null) { return(new ValidationResult(false, "You must enter a non-empty value")); } if (value is BindingGroup) //Since our XAML has ValidationStep="UpdatedValue" />, then our value is now of type BindingExpression, not the normal string that we expected. { BindingGroup bg = value as BindingGroup; //CiresonTimerActivity ta = bg.Owner. StackPanel sp = bg.Owner as StackPanel; CiresonTimerActivityViewModel taViewModel = sp.DataContext as CiresonTimerActivityViewModel; string strError = null; if (taViewModel.HasValidDateInfoEntered(out strError)) { return(ValidationResult.ValidResult); } else { return(new ValidationResult(false, strError)); } } return(new ValidationResult(false, "Was not expecting this obejct here...")); } catch { return(new ValidationResult(false, "You must make a selection and enter a value")); } }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { try { BindingGroup bindingGroup = (BindingGroup)value; MyListItem eli = (MyListItem)bindingGroup.Items[0]; int reamin = Convert.ToInt32(bindingGroup.GetValue(eli, "Remain")); int num = Convert.ToInt32(bindingGroup.GetValue(eli, "Num")); if (num < 0) { return(new ValidationResult(false, "输入的数字不合法")); } if (num > reamin) { return(new ValidationResult(false, "租赁数量超过剩余数量")); } else { return(new ValidationResult(true, null)); } } catch (Exception ex) { return(new ValidationResult(false, ex.Message)); } }
private void RemoveBindingExpressions(BindingGroup bindingGroup, DependencyObject element) { // Walk the logical tree looking for BindingBindingExpressions. // If it is found in the BindingGroup's BindingExpression list we will remove it. // We only search the logical tree for perf reasons, so some visual children could be skipped. This // should be ok for all the stock columns, and will be something that a custom column would need to be // aware of. if (element != null) { var bindingExpressions = bindingGroup.BindingExpressions; var localValueEnumerator = element.GetLocalValueEnumerator(); while (localValueEnumerator.MoveNext()) { var bindingExpression = localValueEnumerator.Current.Value as BindingExpression; if (bindingExpression != null) { for (int i = 0; i < bindingExpressions.Count; i++) { if (object.ReferenceEquals(bindingExpression, bindingExpressions[i])) { bindingExpressions.RemoveAt(i--); } } } } // Recursively remove BindingExpressions from child elements. foreach (object child in LogicalTreeHelper.GetChildren(element)) { RemoveBindingExpressions(bindingGroup, child as DependencyObject); } } }
public virtual void OnRemove(BindingGroup bindings) { if(IsMaster) DoValueChanged(null, null, true, false); else UpdateValue(new BindingInfo(null, null, true, false)); }
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo) { BindingGroup bg = value as BindingGroup; Customer cust = bg.Items[0] as Customer; if (cust == null) { return(new ValidationResult(false, "Customer is not the source object")); } Region region = (Region)bg.GetValue(cust, "Location"); ServiceRep rep = bg.GetValue(cust, "ServiceRepresentative") as ServiceRep; string customerName = bg.GetValue(cust, "Name") as string; if (region == rep.Area) { return(ValidationResult.ValidResult); } else { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} must be assigned a sales representative that serves the {1} region. \n ", customerName, region); return(new ValidationResult(false, sb.ToString())); } }
public virtual void OnAdd(BindingGroup bindings) { if(IsMaster) DoValueChanged(); else UpdateValueByBindings(); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { BindingGroup bindingGroup = (BindingGroup)value; if (bindingGroup.Items.Count > 0) { object obj = bindingGroup.Items[0]; PgM.PgTableBaseM tableM = obj as PgM.PgTableBaseM; String schemeName = (String)bindingGroup.GetValue(tableM, "SchemeName"); String baseName = (String)bindingGroup.GetValue(tableM, "Name"); String systemName = (String)bindingGroup.GetValue(tableM, "Text"); AbsM.EGeomType geomType = (AbsM.EGeomType)((EnumWrapper)(bindingGroup.GetValue(tableM, "GeomType"))).Value; if (String.IsNullOrEmpty(schemeName)) { return(new ValidationResult(false, "Схема не должна быть пустой")); } if (String.IsNullOrEmpty(baseName)) { return(new ValidationResult(false, "Название таблицы в базе не должно быть пустым")); } if (String.IsNullOrEmpty(systemName)) { return(new ValidationResult(false, "Название таблицы в системе не должно быть пустым")); } if (tableM.IsLayer && geomType == AbsM.EGeomType.None) { return(new ValidationResult(false, "Слой карты должен иметь тип геометрии")); } } return(ValidationResult.ValidResult); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { BindingGroup group = (BindingGroup)value; StringBuilder error = null; foreach (var item in group.Items) { IDataErrorInfo info = item as IDataErrorInfo; if (info != null) { if (!string.IsNullOrEmpty(info.Error)) { if (error == null) { error = new StringBuilder(); } error.Append((error.Length != 0 ? ", " : "") + info.Error); } } } if (error != null) { return(new ValidationResult(false, error.ToString())); } return(ValidationResult.ValidResult); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { BindingGroup group = (BindingGroup)value; StringBuilder error = null; foreach (var item in group.Items) { // aggregate errors IDataErrorInfo info = item as IDataErrorInfo; if (info != null) { if (!string.IsNullOrEmpty(info.Error)) { if (error == null) { error = new StringBuilder(); } error.Append((error.Length != 0 ? ", " : "") + info.Error); } } } BaseVM baseVM = GetBaseVM(group); if (error != null) { baseVM.SetStatusMessage(error.ToString(), true); return(new ValidationResult(false, error.ToString())); } baseVM.SetStatusMessage("", false); return(ValidationResult.ValidResult); }
private void Izmeni(object sender, RoutedEventArgs e) { BindingGroup.CommitEdit(); MessageBox.Show("USPESNO STE IZMENILI KONTAKT!"); MainWindow.izmenio = true; this.Close(); }
private void OkButton_Click(object sender, RoutedEventArgs e) { if (!BindingGroup.CommitEdit()) { return; } Timeline.Filters.Clear(); Timeline.Tag = ""; if (listRadio.IsChecked ?? false) { Timeline.Type = TimelineType.List; Timeline.Tag = (string)lists.SelectedValue; } if (searchRadio.IsChecked ?? false) { Timeline.Type = TimelineType.Search; Timeline.Tag = search.Text; } if (filterRadio.IsChecked ?? false) { Timeline.Type = TimelineType.User; Timeline.Filters.AddRange(filters); } DialogResult = true; }
internal void NewValueAvailable(bool dependencySourcesChanged, bool initialValue, bool isASubPropertyChange) { SetStatus(PW.Status); BindingExpression parent = ParentBindingExpression; // this method is called when the last item in the path is replaced. // BindingGroup also wants to know about this. BindingGroup bindingGroup = parent.BindingGroup; if (bindingGroup != null) { bindingGroup.UpdateTable(parent); } if (dependencySourcesChanged) { ReplaceDependencySources(); } // if there's a revised value (i.e. not during initialization // and shutdown), transfer it. if (!initialValue && Status != BindingStatusInternal.AsyncRequestPending) { parent.ScheduleTransfer(isASubPropertyChange); } }
internal static bool ValidateWithoutUpdate(FrameworkElement element) { bool result = true; BindingGroup bindingGroup = element.BindingGroup; DataGridCell cell = (element != null) ? element.Parent as DataGridCell : null; if (bindingGroup != null && cell != null) { Collection <BindingExpressionBase> expressions = bindingGroup.BindingExpressions; BindingExpressionBase[] bindingExpressionsCopy = new BindingExpressionBase[expressions.Count]; expressions.CopyTo(bindingExpressionsCopy, 0); for (int i = 0; i < bindingExpressionsCopy.Length; i++) { // Check the binding's target element - it might have been GC'd // (this can happen when column-virtualization is enabled, for e.g. // ArgumentNullException when calling VisualTreeHelper.IsAncestor // during DataGrid edit) // If so, fetching TargetElement will detach the binding and remove it // from the binding group's collection. This side-effect is why we // loop through a copy of the original collection, and don't rely // on i to be a valid index into the original collection. BindingExpressionBase beb = bindingExpressionsCopy[i]; if (BindingExpressionBelongsToElement <DataGridCell>(beb, cell)) { result = beb.ValidateWithoutUpdate() && result; } } } return(result); }
private void CancelButton_Click(object sender, RoutedEventArgs e) { filters.CancelEdit(); BindingGroup.CancelEdit(); Timeline.Name = _title; DialogResult = false; }
private void RemoveBindingExpressions(BindingGroup bindingGroup, DependencyObject element) { if (element == null) { return; // no content, hence no bindings to remove } var bindingExpressions = bindingGroup.BindingExpressions; BindingExpressionBase[] bindingExpressionsCopy = new BindingExpressionBase[bindingExpressions.Count]; bindingExpressions.CopyTo(bindingExpressionsCopy, 0); for (int i = 0; i < bindingExpressionsCopy.Length; i++) { // Check the binding's target element - it might have been GC'd // (this can happen when column-virtualization is enabled). // If so, fetching TargetElement will detach the binding and remove it // from the binding group's collection. This side-effect is why we // loop through a copy of the original collection, and don't rely // on i to be a valid index into the original collection. if (DataGridHelper.BindingExpressionBelongsToElement <DataGridCell>(bindingExpressionsCopy[i], this)) { bindingExpressions.Remove(bindingExpressionsCopy[i]); } } }
// Ensure that an item over $100 is available for at least 7 days. public override ValidationResult Validate(object value, CultureInfo cultureInfo) { BindingGroup bg = value as BindingGroup; // Get the source object. PurchaseItem item = bg.Items[0] as PurchaseItem; object doubleValue; object dateTimeValue; // Get the proposed values for Price and OfferExpires. bool priceResult = bg.TryGetValue(item, "Price", out doubleValue); bool dateResult = bg.TryGetValue(item, "OfferExpires", out dateTimeValue); if (!priceResult || !dateResult) { return(new ValidationResult(false, "Properties not found")); } double price = (double)doubleValue; DateTime offerExpires = (DateTime)dateTimeValue; // Check that an item over $100 is available for at least 7 days. if (price > 100) { if (offerExpires < DateTime.Today + new TimeSpan(7, 0, 0, 0)) { return(new ValidationResult(false, "Items over $100 must be available for at least 7 days.")); } } return(ValidationResult.ValidResult); }
private static object OnCoerceIsLookup(DependencyObject target, object baseValue) { var lookup = target as ICrudLookupMode; if (lookup != null && (bool)baseValue) { var uc = target as UIElement; if (uc != null) { uc.AddHandler(Validation.ErrorEvent, new EventHandler <ValidationErrorEventArgs>(ValidationErrorEventHandler)); BindingGroup bg = new BindingGroup(); lookup.LookupControl.BindingGroup = bg; uc.SetValue(Validation.ErrorTemplateProperty, null); } lookup.LookupControl.TemplateApplied -= LookupControl_TemplateApplied; lookup.LookupControl.TemplateApplied += LookupControl_TemplateApplied; lookup.LookupControl.Dispatcher.BeginInvoke(new Action(() => { var style = GetLookupStyle(target) ?? lookup.LookupControl.TryFindResource("Lookup") as Style; if (style != null && style != lookup.LookupControl.Style) { lookup.LookupControl.SetValue(FrameworkElement.StyleProperty, style); } }), System.Windows.Threading.DispatcherPriority.Background); } return(baseValue); }
void saveCustomer_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; FrameworkElement container = (FrameworkElement)customerList.ContainerFromElement(btn); // If the user is trying to change an items, when another item has an error, // display a message and cancel the currently edited item. if (bindingGroupInError != null && bindingGroupInError != container.BindingGroup) { MessageBox.Show("Please correct the data in error before changing another customer"); container.BindingGroup.CancelEdit(); return; } if (container.BindingGroup.ValidateWithoutUpdate()) { container.BindingGroup.UpdateSources(); bindingGroupInError = null; MessageBox.Show("Item Saved"); } else { bindingGroupInError = container.BindingGroup; } }
private void SetupValidationRules() { BindingGroup group = new BindingGroup(); group.ValidationRules.Add(new FilterValidation(this.Model)); this.txtFilterText.BindingGroup = group; }
/// <summary> /// Tells the row owner about this element. /// </summary> public override void OnApplyTemplate() { #if BindingGroups if (ItemBindingGroup == null) { ItemBindingGroup = new BindingGroup(); } #endif base.OnApplyTemplate(); DataGridRow owningRow = DataGridRowOwner; if (owningRow != null) { owningRow.CellsPresenter = this; Item = owningRow.Item; } // At the time that a Row is prepared we can't [....] because the CellsPresenter isn't created yet. // Doing it here ensures that the CellsPresenter is in the visual tree. SyncProperties(false); }
/// <summary> /// Applies a Grouping on a given Variable to the Binder Groups from a previous Grouping /// </summary> /// <param name="context">Evaluation Context</param> /// <param name="groups">Binder Group to subgroup</param> /// <returns></returns> public override List<BindingGroup> Apply(SparqlEvaluationContext context, List<BindingGroup> groups) { List<BindingGroup> outgroups = new List<BindingGroup>(); foreach (BindingGroup group in groups) { Dictionary<INode, BindingGroup> subgroups = new Dictionary<INode, BindingGroup>(); BindingGroup error = new BindingGroup(); BindingGroup nulls = new BindingGroup(); foreach (int id in group.BindingIDs) { try { INode value = this._expr.Value(context, id); if (value != null) { if (!subgroups.ContainsKey(value)) { subgroups.Add(value, new BindingGroup(group)); if (this.AssignVariable != null) { subgroups[value].AddAssignment(this.AssignVariable, value); } } subgroups[value].Add(id); } else { nulls.Add(id); } } catch (RdfQueryException) { error.Add(id); } } //Build the List of Groups //Null and Error Group are included if required foreach (BindingGroup g in subgroups.Values) { outgroups.Add(g); } if (error.BindingIDs.Any()) { outgroups.Add(error); if (this.AssignVariable != null) error.AddAssignment(this.AssignVariable, null); error = new BindingGroup(); } if (nulls.BindingIDs.Any()) { outgroups.Add(nulls); if (this.AssignVariable != null) nulls.AddAssignment(this.AssignVariable, null); nulls = new BindingGroup(); } } if (this._child == null) { return outgroups; } else { return this._child.Apply(context, outgroups); } }
/// <summary> /// Applies a Grouping on a given Variable to the Binder /// </summary> /// <param name="context">Evaluation Context</param> /// <returns></returns> public override List<BindingGroup> Apply(SparqlEvaluationContext context) { Dictionary<INode, BindingGroup> groups = new Dictionary<INode, BindingGroup>(); BindingGroup nulls = new BindingGroup(); foreach (int id in context.Binder.BindingIDs) { INode value = context.Binder.Value(this._name, id); if (value != null) { if (!groups.ContainsKey(value)) { groups.Add(value, new BindingGroup()); if (this.AssignVariable != null) { groups[value].AddAssignment(this.AssignVariable, value); } } groups[value].Add(id); } else { nulls.Add(id); } } List<BindingGroup> outGroups = (from g in groups.Values select g).ToList(); if (nulls.Any()) { outGroups.Add(nulls); if (this.AssignVariable != null) nulls.AddAssignment(this.AssignVariable, null); } if (this._child == null) { return outGroups; } else { return this._child.Apply(context, outGroups); } }
/// <summary> /// Applies a Grouping on a given Variable to the Binder Groups from a previous Grouping /// </summary> /// <param name="context">Evaluation Context</param> /// <param name="groups">Binder Group to subgroup</param> /// <returns></returns> public override List<BindingGroup> Apply(SparqlEvaluationContext context, List<BindingGroup> groups) { List<BindingGroup> outgroups = new List<BindingGroup>(); BindingGroup nulls = new BindingGroup(); foreach (BindingGroup group in groups) { Dictionary<INode, BindingGroup> subgroups = new Dictionary<INode, BindingGroup>(); foreach (int id in group.BindingIDs) { INode value = context.Binder.Value(this._name, id); if (value != null) { if (!subgroups.ContainsKey(value)) { subgroups.Add(value, new BindingGroup(group)); if (this.AssignVariable != null) { subgroups[value].AddAssignment(this.AssignVariable, value); } } subgroups[value].Add(id); } else { nulls.Add(id); } } foreach (BindingGroup g in subgroups.Values) { outgroups.Add(g); } if (nulls.Any()) { outgroups.Add(nulls); if (this.AssignVariable != null) nulls.AddAssignment(this.AssignVariable, null); nulls = new BindingGroup(); } } if (this._child == null) { return outgroups; } else { return this._child.Apply(context, outgroups); } }
/// <summary> /// Applies a Grouping on a given Expression to the Binder /// </summary> /// <param name="context">Evaluation Context</param> /// <returns></returns> public override List<BindingGroup> Apply(SparqlEvaluationContext context) { Dictionary<INode, BindingGroup> groups = new Dictionary<INode, BindingGroup>(); BindingGroup error = new BindingGroup(); BindingGroup nulls = new BindingGroup(); foreach (int id in context.Binder.BindingIDs) { try { INode value = this._expr.Value(context, id); if (value != null) { if (!groups.ContainsKey(value)) { groups.Add(value, new BindingGroup()); if (this.AssignVariable != null) { groups[value].AddAssignment(this.AssignVariable, value); } } groups[value].Add(id); } else { nulls.Add(id); } } catch (RdfQueryException) { error.Add(id); } } //Build the List of Groups //Null and Error Group are included if required List<BindingGroup> parentGroups = (from g in groups.Values select g).ToList(); if (error.BindingIDs.Any()) { parentGroups.Add(error); if (this.AssignVariable != null) error.AddAssignment(this.AssignVariable, null); } if (nulls.BindingIDs.Any()) { parentGroups.Add(nulls); if (this.AssignVariable != null) nulls.AddAssignment(this.AssignVariable, null); } if (this._child != null) { return this._child.Apply(context, parentGroups); } else { return parentGroups; } }
public BindingGroup GetGroupForColumn(DataColumn column) { RowColumnBinding row_col_binding; if(column_bindings.TryGetValue(column, out row_col_binding)) return row_col_binding.Bindings; row_col_binding = new RowColumnBinding(column, row); BindingGroup grp = new BindingGroup(column.DataType); grp.Add(row_col_binding); column_bindings[column] = row_col_binding; return grp; }