Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public IPersisterResult UpdateFunction(UpdatingEventArgs parameter)
        {
            lock (customDAO)
            {
                object objectToUpdate = customDAO.FindBy(parameter.SourceType, parameter.Key, LockMode.Upgrade);
                Dictionary<string, object> dic = parameter.Values.Keys.Cast<object>().ToDictionary(current => current.ToString(), current => parameter.Values[current]);

                ITransactionProvider tr = customDAO.GetTransactionProvider();

                try
                {
                    tr.BeginTransaction("UpdateFunction", IsolationLevel.ReadCommitted);

                    var metadata = customDAO.GetPersistentClassInfo(objectToUpdate.GetType());

                    metadata.SetPropertyValues(objectToUpdate, dic, EntityMode.Poco);

                    tr.CommitTransaction();

                    return new PersisterResult(parameter.SourceType, 1);
                }
                catch (Exception ex)
                {
                    tr.RollbackTransaction(ex);
                    return new PersisterResult(parameter.SourceType, new ExecutionQueryException("Error on executing the update function.", "UpdateFunction", ex));
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void CustomDataSource_Updating(object sender, UpdatingEventArgs e)
 {
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="keys"></param>
        /// <param name="values"></param>
        /// <param name="oldValues"></param>
        /// <returns></returns>
        protected override int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
        {
            if (owner.UpdateFunction == null)
                throw new DelegateNotFoundException("UpdateFunction", "The update function doesn't implemented.");

            if (owner.IdentifierFunction == null)
                throw new DelegateNotFoundException("IdentifierFunction", "The identifier function doesn't implemented.");

            var eventArg = new UpdatingEventArgs(owner.SourceType, owner.IdentifierFunction.Invoke(keys), values, oldValues);
            owner.OnUpdating(eventArg);

            if (eventArg.Cancel)
                return 0;

            var updateActionEvent = new ActionEventArgs<UpdatingEventArgs, IPersisterResult>(eventArg, owner.UpdateFunction);

            var result = updateActionEvent.Execute();
            if (result.QueryException != null)
            {
                owner.OnExecutionQueryError(new QueryResultEventArgs(result));
                return -1;
            }

            owner.OnUpdated(EventArgs.Empty);
            OnDataSourceViewChanged(EventArgs.Empty);
            return 1;
        }
 internal void OnUpdating(UpdatingEventArgs e)
 {
     if (Updating != null) Updating(this, e);
 }