Exemplo n.º 1
0
        /// <summary>
        /// Validates the data object and all its properties and child objects recursively.
        /// </summary>
        /// <param name="force">True to validate regardless of
        /// whether or not it has been already validated.</param>
        public virtual void Validate(bool force)
        {
            foreach (DataProperty p in properties.Values) p.Validate(force);
            foreach (IDataObject obj in childObjects.Values) obj.Validate(force);

            if (force) ResetValidation();
            if (validationErrorList != null) return;

            validationErrorList = new ErrorList();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Resets validation status to not validated on the object
 /// by setting the validation error list to null.
 /// </summary>
 public void ResetValidation()
 {
     validationErrorList = null;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets all validation errors from the data object, all its properties and child objects recursively.
 /// </summary>
 /// <returns>Validation errors from the data object, all its properties and child objects.</returns>
 public ErrorList GetValidationErrors()
 {
     ErrorList errLst = new ErrorList();
     if (validationErrorList != null) errLst.MergeWith(validationErrorList);
     foreach (DataProperty p in properties.Values) errLst.MergeWith(p.ValidationErrors);
     foreach (IDataObject obj in childObjects.Values) errLst.MergeWith(obj.GetValidationErrors());
     return errLst;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Resets validation status to not validated on the object
 /// by setting the validation error list to null.
 /// </summary>
 public void ResetValidation()
 {
     validationErrorList = null;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Merges the current list with another error list.
 /// </summary>
 /// <param name="otherList">Another error list to merge the current list with.</param>
 public void MergeWith(ErrorList otherList)
 {
     if (otherList != null) errors.AddRange(otherList.Errors);
 }
 protected override void LoadData()
 {
     ISalesOrderService svcSalesOrder = DI.Resolve<ISalesOrderService>();
     ErrorList errorList = new ErrorList();
     try
     {
         SalesOrder_ReadOutput outRead;
         using (TimeTracker.ServiceCall)
             outRead = svcSalesOrder.Read((int)obj.SalesOrderIdProperty.TransportValue);
         obj.FromDataContract(outRead);
     }
     catch(Exception ex)
     {
         errorList.MergeWith(ErrorList.FromException(ex));
     }
     try
     {
         IEnumerable<SalesOrderDetail_ReadListOutput> outDetail_ReadList;
         using (TimeTracker.ServiceCall)
             outDetail_ReadList = svcSalesOrder.Detail_ReadList((int)obj.SalesOrderIdProperty.TransportValue);
         obj.DetailList.FromDataContract(outDetail_ReadList);
     }
     catch(Exception ex)
     {
         errorList.MergeWith(ErrorList.FromException(ex));
     }
     if (svcSalesOrder is IDisposable) ((IDisposable)svcSalesOrder).Dispose();
     errors.List.DataSource = errorList.Errors;
     errors.List.DataBind();
     Page.DataBind();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Retrieves the error list from the specified exception if possible,
        /// otherwise constructs a new error list with the exception as the error message.
        /// </summary>
        /// <param name="ex">Exception to retrieve the error list from.</param>
        /// <returns>An error list retrieved from the exception.</returns>
        public static ErrorList FromException(Exception ex)
        {
            FaultException<ErrorList> fex = ex as FaultException<ErrorList>;
            if (fex != null) return fex.Detail;

            WebException webEx = ex as WebException;
            webEx = webEx ?? ex.InnerException as WebException;
            if (webEx != null && webEx.Response != null && webEx.Response.GetResponseStream() != null)
            {
                try
                {
                    return (ErrorList)new DataContractSerializer(typeof(ErrorList)).ReadObject(
                        webEx.Response.GetResponseStream());
                }
                catch (Exception) {}
            }

            // use the server side exception if applicable
            FaultException<ExceptionDetail> fexd = ex as FaultException<ExceptionDetail>;

            ErrorList err = new ErrorList();
            err.Add(new ErrorMessage("EXCEPTION", fexd != null ? fexd.Detail.ToString() : ex.ToString()));
            return err;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Constructs a new exception from the current list of errors
 /// </summary>
 /// <param name="message">Excetpion message</param>
 /// <param name="errors">The current list of errors</param>
 public ErrorAbortException(String message, ErrorList errors) : base(message)
 {
     Errors = errors;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Resets the validation status of the property to be non-validated by setting the list of validation errors to null.
 /// Fires the validation property change event as well. The validation status is reset automatically
 /// whenever the property value changes and can also be reset manually if the validation depends on external factors that have changed.
 /// </summary>
 public void ResetValidation()
 {
     validationErrorList = null;
     FirePropertyChange(new PropertyChangeEventArgs(PropertyChange.Validation, null, null));
 }
Exemplo n.º 10
0
        /// <summary>
        /// Validates the property and fires a validation property change event.
        /// </summary>
        /// <param name="force">True to validate regardless of whether or not it has been already validated.</param>
        public virtual void Validate(bool force)
        {
            if (force) ResetValidation();
            if (validationErrorList != null) return;

            validationErrorList = new ErrorList();

            if (Validator != null && Editable)
            {
                IList lst = InternalValue as IList;
                if (lst != null && lst.Count > 0)
                    foreach (object val in lst) Validator(this, val);
                else Validator(this, InternalValue);
            }
            FirePropertyChange(new PropertyChangeEventArgs(PropertyChange.Validation, null, null));
        }
Exemplo n.º 11
0
 /// <summary>
 /// Resets the validation status of the property to be non-validated by setting the list of validation errors to null.
 /// Fires the validation property change event as well. The validation status is reset automatically
 /// whenever the property value changes and can also be reset manually if the validation depends on external factors that have changed.
 /// </summary>
 public void ResetValidation()
 {
     validationErrorList = null;
     FirePropertyChange(new PropertyChangeEventArgs(PropertyChange.Validation, null, null));
 }