public static void MapBrokenRules(ModelStateDictionary modelState, Csla.Core.BusinessBase businessObject) { foreach (var brokenRule in businessObject.BrokenRulesCollection) { modelState.AddModelError(brokenRule.Property, brokenRule.Description); } }
private static void CanExecuteRemove(object target, CanExecuteRoutedEventArgs e) { bool result = false; CslaDataProviderCommandManager ctl = target as CslaDataProviderCommandManager; if (ctl != null && ctl.Provider != null) { if (ctl.Provider.Data != null) { Csla.Core.BusinessBase bb = e.Parameter as Csla.Core.BusinessBase; IBindingList list; if (bb != null) { list = bb.Parent as IBindingList; } else { list = ctl.Provider.Data as IBindingList; } if (list != null) { result = list.AllowRemove; if (result && !Csla.Rules.BusinessRules.HasPermission(Rules.AuthorizationActions.EditObject, ctl.Provider.Data)) { result = false; } } } } e.CanExecute = result; }
/// <summary> /// Removes an item from the list if the object /// implements IBindingList and AllowRemove is true. /// </summary> /// <param name="sender">Object invoking this method.</param> /// <param name="e"> /// ExecuteEventArgs, where MethodParameter contains /// the item to be removed from the list. /// </param> public void RemoveItem(object sender, ExecuteEventArgs e) { var item = e.MethodParameter; // only do something if the object implements // IBindingList IBindingList list; Csla.Core.BusinessBase bb = item as Csla.Core.BusinessBase; if (bb != null) { list = bb.Parent as IBindingList; } else { list = this.Data as IBindingList; } if (list != null && list.AllowRemove) { list.Remove(item); } }
private void ApplyAuthorizationRules(Control control) { foreach (Binding binding in control.DataBindings) { // get the BindingSource if appropriate if (binding.DataSource is BindingSource) { BindingSource bs = (BindingSource)binding.DataSource; // get the object property name string propertyName = binding.BindingMemberInfo.BindingField; // get the BusinessObject if appropriate if (bs.DataSource is Csla.Core.BusinessBase) { Csla.Core.BusinessBase ds = (Csla.Core.BusinessBase)bs.DataSource; ApplyReadRules( control, binding, ds.CanReadProperty(propertyName)); ApplyWriteRules( control, binding, ds.CanWriteProperty(propertyName)); } else if (bs.DataSource is Csla.Core.IReadOnlyObject) { Csla.Core.IReadOnlyObject ds = (Csla.Core.IReadOnlyObject)bs.DataSource; ApplyReadRules( control, binding, ds.CanReadProperty(propertyName)); } } } }
public void Reg(Csla.Core.BusinessBase obj) { obj.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(obj_PropertyChanged); }
private void GetWarnInfoList() { _infoList.Clear(); _warningList.Clear(); _errorList.Clear(); BindingSource bs = (BindingSource)DataSource; if (bs == null) { return; } if (bs.Position == -1) { return; } // we can only deal with CSLA BusinessBase objects if (bs.Current is Csla.Core.BusinessBase) { // get the BusinessBase object Csla.Core.BusinessBase bb = bs.Current as Csla.Core.BusinessBase; if (bb != null) { foreach (Csla.Validation.BrokenRule br in bb.BrokenRulesCollection) { switch (br.Severity) { case Csla.Validation.RuleSeverity.Error: if (_errorList.ContainsKey(br.Property)) { _errorList[br.Property] = String.Concat(_errorList[br.Property], Environment.NewLine, br.Description); } else { _errorList.Add(br.Property, br.Description); } break; case Csla.Validation.RuleSeverity.Warning: if (_warningList.ContainsKey(br.Property)) { _warningList[br.Property] = String.Concat(_warningList[br.Property], Environment.NewLine, br.Description); } else { _warningList.Add(br.Property, br.Description); } break; default: // consider it an Info if (_infoList.ContainsKey(br.Property)) { _infoList[br.Property] = String.Concat(_infoList[br.Property], Environment.NewLine, br.Description); } else { _infoList.Add(br.Property, br.Description); } break; } } } } }
public string GetBrokenRules(Csla.Core.BusinessBase obj) { return(String.Format("Object is not valid.\n\n{0}", obj.BrokenRulesCollection)); }
internal new IDisposable BypassPropertyChecks(Csla.Core.BusinessBase target) { return(base.BypassPropertyChecks(target)); }
/// <summary> /// By wrapping this property inside Using block /// you can set property values on /// <paramref name="businessObject">business object</paramref> /// without raising PropertyChanged events /// and checking user rights. /// </summary> /// <param name="businessObject"> /// Object on with you would like to set property values /// </param> /// <returns> /// An instance of IDisposable object that allows /// bypassing of normal authorization checks during /// property setting. /// </returns> protected IDisposable BypassPropertyChecks(Csla.Core.BusinessBase businessObject) { return(businessObject.BypassPropertyChecks); }
private void ProcessControl(Control control) { foreach (Binding binding in control.DataBindings) { // get the Binding if appropriate if (binding.DataSource == this.DataSource) { BindingSource bs = (BindingSource)binding.DataSource; // we can only deal with CSLA BusinessBase objects if (bs.Current is Csla.Core.BusinessBase) { // get the BusinessBase object Csla.Core.BusinessBase bb = bs.Current as Csla.Core.BusinessBase; if (bb != null) { // get the object property name string propertyName = binding.BindingMemberInfo.BindingField; //The errors are taking care of themselves in the base //ErrorProvider - all we need to worry about are the //Warnings and Information messages StringBuilder warn = new StringBuilder(); StringBuilder info = new StringBuilder(); bool bError = false; bool bWarn = false; foreach (Csla.Validation.BrokenRule br in bb.BrokenRulesCollection) { if (br.Property == propertyName) { if (this._visibleWarning == true && br.Severity == Csla.Validation.RuleSeverity.Warning) { warn.AppendLine(br.Description); bWarn = true; } else if (this._visibleInformation == true && br.Severity == Csla.Validation.RuleSeverity.Information) { info.AppendLine(br.Description); } else if (bError == false && br.Severity == Csla.Validation.RuleSeverity.Error) { bError = true; } } } int offsetInformation = this._offsetInformation; int offsetWarning = this._offsetWarning; // Set / fix offsets if (bError == false && bWarn == false) { offsetInformation = 0; } else if (bError == true && bWarn == false) { offsetInformation = this._offsetInformation - this._offsetWarning; } else if (bError == false && bWarn == true) { offsetInformation = this._offsetInformation - this._offsetWarning; offsetWarning = 0; } if (this._visibleWarning == true && warn.Length > 0) { this.errorProviderWarn.SetError(binding.Control, warn.ToString().Substring(0, warn.ToString().Length - 2)); this.errorProviderWarn.SetIconPadding(binding.Control, base.GetIconPadding(binding.Control) + offsetWarning); this.errorProviderWarn.SetIconAlignment(binding.Control, base.GetIconAlignment(binding.Control)); } else { this.errorProviderWarn.SetError(binding.Control, string.Empty); } if (this._visibleInformation == true && info.Length > 0) { this.errorProviderInfo.SetError(binding.Control, info.ToString().Substring(0, info.ToString().Length - 2)); this.errorProviderInfo.SetIconPadding(binding.Control, base.GetIconPadding(binding.Control) + offsetInformation); this.errorProviderInfo.SetIconAlignment(binding.Control, base.GetIconAlignment(binding.Control)); } else { this.errorProviderInfo.SetError(binding.Control, string.Empty); } } } } } }