コード例 #1
0
ファイル: SimpleDataPortal.cs プロジェクト: nschonni/csla-svn
    public async Task<DataPortalResult> Create(
      Type objectType, object criteria, DataPortalContext context, bool isSync)
    {
      LateBoundObject obj = null;
      IDataPortalTarget target = null;
      var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Create);
      try
      {
        // create an instance of the business object.
        obj = new LateBoundObject(objectType);

        target = obj.Instance as IDataPortalTarget;

        if (target != null)
        {
          target.DataPortal_OnDataPortalInvoke(eventArgs);
          target.MarkNew();
        }
        else
        {
          obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);
          obj.CallMethodIfImplemented("MarkNew");
        }

        // tell the business object to create its data
        if (criteria is EmptyCriteria)
          await obj.CallMethodTryAsync("DataPortal_Create");
        else
          await obj.CallMethodTryAsync("DataPortal_Create", criteria);

        if (target != null)
          target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
        else
          obj.CallMethodIfImplemented(
            "DataPortal_OnDataPortalInvokeComplete", eventArgs);

        // return the populated business object as a result
        return new DataPortalResult(obj.Instance);
      }
      catch (Exception ex)
      {
        try
        {
          if (target != null)
            target.DataPortal_OnDataPortalException(eventArgs, ex);
          else if (obj != null)
            obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex);
        }
        catch
        {
          // ignore exceptions from the exception handler
        }
        object outval = null;
        if (obj != null) outval = obj.Instance;
        throw DataPortal.NewDataPortalException(
              "DataPortal.Create " + Resources.FailedOnServer,
              new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Create", ex),
              outval);
      }
    }
コード例 #2
0
ファイル: ChildDataPortal.cs プロジェクト: Jaans/csla
        private object Create(System.Type objectType, bool hasParameters, params object[] parameters)
        {
            LateBoundObject obj = null;
              IDataPortalTarget target = null;
              var eventArgs = new DataPortalEventArgs(null, objectType, parameters, DataPortalOperations.Create);
              try
              {
            // create an instance of the business object
            obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType));
            ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance);

            target = obj.Instance as IDataPortalTarget;

            if (target != null)
            {
              target.Child_OnDataPortalInvoke(eventArgs);
              target.MarkAsChild();
              target.MarkNew();
            }
            else
            {
              obj.CallMethodIfImplemented("Child_OnDataPortalInvoke",
            eventArgs);
              obj.CallMethodIfImplemented("MarkAsChild");
              obj.CallMethodIfImplemented("MarkNew");
            }

            // tell the business object to create its data
            if (hasParameters)
              obj.CallMethod("Child_Create", parameters);
            else
              obj.CallMethod("Child_Create");

            if (target != null)
              target.Child_OnDataPortalInvokeComplete(eventArgs);
            else
              obj.CallMethodIfImplemented("Child_OnDataPortalInvokeComplete",
            eventArgs);

            // return the populated business object as a result
            return obj.Instance;

              }
              catch (Exception ex)
              {
            try
            {
              if (target != null)
            target.Child_OnDataPortalException(eventArgs, ex);
              else if (obj != null)
            obj.CallMethodIfImplemented("Child_OnDataPortalException",
              eventArgs, ex);
            }
            catch
            {
              // ignore exceptions from the exception handler
            }
            object bo = null;
            if (obj != null)
              bo = obj.Instance;
            throw new Csla.DataPortalException(
              "ChildDataPortal.Create " + Properties.Resources.FailedOnServer, ex, bo);
              }
              finally
              {
            ApplicationContext.DataPortalActivator.FinalizeInstance(obj.Instance);
              }
        }
コード例 #3
0
ファイル: ChildDataPortal.cs プロジェクト: Jaans/csla
        private void Update(object obj, bool hasParameters, params object[] parameters)
        {
            if (obj == null)
            return;

              var busObj = obj as Core.BusinessBase;
              if (busObj != null && busObj.IsDirty == false)
              {
            // if the object isn't dirty, then just exit
            return;
              }

              var operation = DataPortalOperations.Update;
              Type objectType = obj.GetType();
              IDataPortalTarget target = obj as IDataPortalTarget;
              LateBoundObject lb = new LateBoundObject(obj);
              ApplicationContext.DataPortalActivator.InitializeInstance(lb.Instance);

              try
              {
            if (target != null)
              target.Child_OnDataPortalInvoke(
            new DataPortalEventArgs(null, objectType, obj, operation));
            else
              lb.CallMethodIfImplemented("Child_OnDataPortalInvoke",
            new DataPortalEventArgs(null, objectType, obj, operation));

            // tell the business object to update itself
            if (busObj != null)
            {
              if (busObj.IsDeleted)
              {
            if (!busObj.IsNew)
            {
              // tell the object to delete itself
              if (hasParameters)
                lb.CallMethod("Child_DeleteSelf", parameters);
              else
                lb.CallMethod("Child_DeleteSelf");
            }
            if (target != null)
              target.MarkNew();
            else
              lb.CallMethodIfImplemented("MarkNew");

              }
              else
              {
            if (busObj.IsNew)
            {
              // tell the object to insert itself
              if (hasParameters)
                lb.CallMethod("Child_Insert", parameters);
              else
              {
                lb.CallMethod("Child_Insert");
              }

            }
            else
            {
              // tell the object to update itself
              if (hasParameters)
                lb.CallMethod("Child_Update", parameters);
              else
              {
                lb.CallMethod("Child_Update");
              }
            }
            if (target != null)
              target.MarkOld();
            else
              lb.CallMethodIfImplemented("MarkOld");
              }

            }
            else if (obj is Core.ICommandObject)
            {
              // tell the object to update itself
              if (hasParameters)
            lb.CallMethod("Child_Execute", parameters);
              else
            lb.CallMethod("Child_Execute");
              operation = DataPortalOperations.Execute;

            }
            else
            {
              // this is an updatable collection or some other
              // non-BusinessBase type of object
              // tell the object to update itself
              if (hasParameters)
            lb.CallMethod("Child_Update", parameters);
              else
            lb.CallMethod("Child_Update");
              if (target != null)
            target.MarkOld();
              else
            lb.CallMethodIfImplemented("MarkOld");
            }

            if (target != null)
              target.Child_OnDataPortalInvokeComplete(
            new DataPortalEventArgs(null, objectType, obj, operation));
            else
              lb.CallMethodIfImplemented("Child_OnDataPortalInvokeComplete",
            new DataPortalEventArgs(null, objectType, obj, operation));

              }
              catch (Exception ex)
              {
            try
            {
              if (target != null)
            target.Child_OnDataPortalException(
              new DataPortalEventArgs(null, objectType, obj, operation), ex);
              else if (lb != null)
            lb.CallMethodIfImplemented("Child_OnDataPortalException",
              new DataPortalEventArgs(null, objectType, obj, operation), ex);
            }
            catch
            {
              // ignore exceptions from the exception handler
            }
            throw new Csla.DataPortalException(
              "ChildDataPortal.Update " + Properties.Resources.FailedOnServer, ex, obj);
              }
              finally
              {
            ApplicationContext.DataPortalActivator.FinalizeInstance(lb.Instance);
              }
        }
コード例 #4
0
ファイル: SimpleDataPortal.cs プロジェクト: RodrigoGT/csla
    public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
    {
      LateBoundObject obj = null;
      IDataPortalTarget target = null;
      var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Delete);
      try
      {
        // create an instance of the business objet
        obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType));
        ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance);

        target = obj.Instance as IDataPortalTarget;

        if (target != null)
          target.DataPortal_OnDataPortalInvoke(eventArgs);
        else
          obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);

        // tell the business object to delete itself
        await obj.CallMethodTryAsync("DataPortal_Delete", criteria).ConfigureAwait(false);

        var busy = obj.Instance as Csla.Core.ITrackStatus;
        if (busy != null && busy.IsBusy)
          throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name));

        if (target != null)
          target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
        else
          obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete", eventArgs);

        return new DataPortalResult();
      }
      catch (Exception ex)
      {
        try
        {
          if (target != null)
            target.DataPortal_OnDataPortalException(eventArgs, ex);
          else if (obj != null)
            obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex);
        }
        catch
        {
          // ignore exceptions from the exception handler
        }
        throw DataPortal.NewDataPortalException(
              "DataPortal.Delete " + Resources.FailedOnServer,
              new DataPortalExceptionHandler().InspectException(objectType, obj, null, "DataPortal.Delete", ex),
              null);
      }
      finally
      {
        object reference = null;
        if (obj != null)
          reference = obj.Instance;
        ApplicationContext.DataPortalActivator.FinalizeInstance(reference);
      }
    }
コード例 #5
0
ファイル: SimpleDataPortal.cs プロジェクト: RodrigoGT/csla
    public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
    {
      DataPortalOperations operation = DataPortalOperations.Update;
      Type objectType = obj.GetType();
      var target = obj as IDataPortalTarget;
      LateBoundObject lb = new LateBoundObject(obj);
      ApplicationContext.DataPortalActivator.InitializeInstance(lb.Instance);
      try
      {
        if (target != null)
          target.DataPortal_OnDataPortalInvoke(
            new DataPortalEventArgs(context, objectType, obj, operation));
        else
          lb.CallMethodIfImplemented(
            "DataPortal_OnDataPortalInvoke",
            new DataPortalEventArgs(context, objectType, obj, operation));

        // tell the business object to update itself
        var busObj = obj as Core.BusinessBase;
        if (busObj != null)
        {
          if (busObj.IsDeleted)
          {
            if (!busObj.IsNew)
            {
              // tell the object to delete itself
              await lb.CallMethodTryAsync("DataPortal_DeleteSelf").ConfigureAwait(false);
            }
            if (target != null)
              target.MarkNew();
            else
              lb.CallMethodIfImplemented("MarkNew");
          }
          else
          {
            if (busObj.IsNew)
            {
              // tell the object to insert itself
              await lb.CallMethodTryAsync("DataPortal_Insert").ConfigureAwait(false);
            }
            else
            {
              // tell the object to update itself
              await lb.CallMethodTryAsync("DataPortal_Update").ConfigureAwait(false);
            }
            if (target != null)
              target.MarkOld();
            else
              lb.CallMethodIfImplemented("MarkOld");
          }
        }
        else if (obj is Core.ICommandObject)
        {
          operation = DataPortalOperations.Execute;
          // tell the object to update itself
          await lb.CallMethodTryAsync("DataPortal_Execute").ConfigureAwait(false);
        }
        else
        {
          // this is an updatable collection or some other
          // non-BusinessBase type of object
          // tell the object to update itself
          await lb.CallMethodTryAsync("DataPortal_Update").ConfigureAwait(false);
          if (target != null)
            target.MarkOld();
          else
            lb.CallMethodIfImplemented("MarkOld");
        }

        var busy = busObj as Csla.Core.ITrackStatus;
        if (busy != null && busy.IsBusy)
          throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name));

        if (target != null)
          target.DataPortal_OnDataPortalInvokeComplete(
            new DataPortalEventArgs(context, objectType, obj, operation));
        else
          lb.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete",
            new DataPortalEventArgs(context, objectType, obj, operation));

        return new DataPortalResult(obj);
      }
      catch (Exception ex)
      {
        try
        {
          if (target != null)
            target.DataPortal_OnDataPortalException(
              new DataPortalEventArgs(context, objectType, obj, operation), ex);
          else
            lb.CallMethodIfImplemented("DataPortal_OnDataPortalException", new DataPortalEventArgs(context, objectType, obj, operation), ex);
        }
        catch
        {
          // ignore exceptions from the exception handler
        }
        throw DataPortal.NewDataPortalException(
              "DataPortal.Update " + Resources.FailedOnServer,
              new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex),
              obj);
      }
      finally
      {
        object reference = null;
        if (lb != null)
          reference = lb.Instance;
        ApplicationContext.DataPortalActivator.FinalizeInstance(reference);
      }
    }
コード例 #6
0
ファイル: SimpleDataPortal.cs プロジェクト: BiYiTuan/csla
    public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
    {
      LateBoundObject obj = null;
      IDataPortalTarget target = null;
      var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Fetch);
      try
      {
        // create an instance of the business object.
        obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType));
        ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance);

        target = obj.Instance as IDataPortalTarget;

        if (target != null)
        {
          target.DataPortal_OnDataPortalInvoke(eventArgs);
          target.MarkOld();
        }
        else
        {
          obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);
          obj.CallMethodIfImplemented("MarkOld");
        }

        // tell the business object to fetch its data
        if (criteria is EmptyCriteria)
          await obj.CallMethodTryAsync("DataPortal_Fetch").ConfigureAwait(false);
        else
          await obj.CallMethodTryAsync("DataPortal_Fetch", criteria).ConfigureAwait(false);

        var busy = obj.Instance as Csla.Core.ITrackStatus;
        if (busy != null && busy.IsBusy)
          throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name));

        if (target != null)
          target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
        else
          obj.CallMethodIfImplemented(
            "DataPortal_OnDataPortalInvokeComplete",
            eventArgs);

        // return the populated business object as a result
        return new DataPortalResult(obj.Instance);
      }
      catch (Exception ex)
      {
        try
        {
          if (target != null)
            target.DataPortal_OnDataPortalException(eventArgs, ex);
          else if (obj != null)
            obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex);
        }
        catch
        {
          // ignore exceptions from the exception handler
        }
        object outval = null;
        if (obj != null) outval = obj.Instance;
        throw DataPortal.NewDataPortalException(
              "DataPortal.Fetch " + Resources.FailedOnServer,
              new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Fetch", ex),
              outval);
      }
      finally
      {
        ApplicationContext.DataPortalActivator.FinalizeInstance(obj.Instance);
      }
    }
コード例 #7
0
ファイル: SimpleDataPortal.cs プロジェクト: nschonni/csla-svn
    public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
    {
      LateBoundObject obj = null;
      IDataPortalTarget target = null;
      var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Delete);
      try
      {
        // create an instance of the business objet
        obj = new LateBoundObject(objectType);

        target = obj.Instance as IDataPortalTarget;

        if (target != null)
          target.DataPortal_OnDataPortalInvoke(eventArgs);
        else
          obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);

        // tell the business object to delete itself
        await obj.CallMethodTryAsync("DataPortal_Delete", criteria);

        if (target != null)
          target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
        else
          obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete", eventArgs);

        return new DataPortalResult();
      }
      catch (Exception ex)
      {
        try
        {
          if (target != null)
            target.DataPortal_OnDataPortalException(eventArgs, ex);
          else if (obj != null)
            obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex);
        }
        catch
        {
          // ignore exceptions from the exception handler
        }
        throw DataPortal.NewDataPortalException(
              "DataPortal.Delete " + Resources.FailedOnServer,
              new DataPortalExceptionHandler().InspectException(objectType, obj, null, "DataPortal.Delete", ex),
              null);
      }
    }
コード例 #8
0
ファイル: SimpleDataPortal.cs プロジェクト: nschonni/csla-svn
    public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
    {
      DataPortalOperations operation = DataPortalOperations.Update;
      Type objectType = obj.GetType();
      var target = obj as IDataPortalTarget;
      LateBoundObject lb = new LateBoundObject(obj);
      try
      {
        if (target != null)
          target.DataPortal_OnDataPortalInvoke(
            new DataPortalEventArgs(context, objectType, obj, operation));
        else
          lb.CallMethodIfImplemented(
            "DataPortal_OnDataPortalInvoke",
            new DataPortalEventArgs(context, objectType, obj, operation));

        // tell the business object to update itself
        var busObj = obj as Core.BusinessBase;
        if (busObj != null)
        {
          if (busObj.IsDeleted)
          {
            if (!busObj.IsNew)
            {
              // tell the object to delete itself
              await lb.CallMethodTryAsync("DataPortal_DeleteSelf");
            }
            if (target != null)
              target.MarkNew();
            else
              lb.CallMethodIfImplemented("MarkNew");
          }
          else
          {
            if (busObj.IsNew)
            {
              // tell the object to insert itself
              await lb.CallMethodTryAsync("DataPortal_Insert");
            }
            else
            {
              // tell the object to update itself
              await lb.CallMethodTryAsync("DataPortal_Update");
            }
            if (target != null)
              target.MarkOld();
            else
              lb.CallMethodIfImplemented("MarkOld");
          }
        }
        else if (obj is Core.ICommandObject)
        {
          operation = DataPortalOperations.Execute;
          // tell the object to update itself
          await lb.CallMethodTryAsync("DataPortal_Execute");
        }
        else
        {
          // this is an updatable collection or some other
          // non-BusinessBase type of object
          // tell the object to update itself
          await lb.CallMethodTryAsync("DataPortal_Update");
          if (target != null)
            target.MarkOld();
          else
            lb.CallMethodIfImplemented("MarkOld");
        }

        if (target != null)
          target.DataPortal_OnDataPortalInvokeComplete(
            new DataPortalEventArgs(context, objectType, obj, operation));
        else
          lb.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete",
            new DataPortalEventArgs(context, objectType, obj, operation));

        return new DataPortalResult(obj);
      }
      catch (Exception ex)
      {
        try
        {
          if (target != null)
            target.DataPortal_OnDataPortalException(
              new DataPortalEventArgs(context, objectType, obj, operation), ex);
          else
            lb.CallMethodIfImplemented("DataPortal_OnDataPortalException", new DataPortalEventArgs(context, objectType, obj, operation), ex);
        }
        catch
        {
          // ignore exceptions from the exception handler
        }
        throw DataPortal.NewDataPortalException(
              "DataPortal.Update " + Resources.FailedOnServer,
              new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex),
              obj);
      }
    }