Пример #1
0
    private async Task<DataPortalResult> InvokeMethod(string factoryTypeName, DataPortalOperations operation, string methodName, Type objectType, DataPortalContext context, bool isSync)
    {
      object factory = FactoryLoader.GetFactory(factoryTypeName);
      var eventArgs = new DataPortalEventArgs(context, objectType, null, operation);

      Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "Invoke", eventArgs);
      object result = null;
      try
      {
        Utilities.ThrowIfAsyncMethodOnSyncClient(isSync, factory, methodName);

        result = await Csla.Reflection.MethodCaller.CallMethodTryAsync(factory, methodName).ConfigureAwait(false);
        var error = result as Exception;
        if (error != null)
          throw error;

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

        Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "InvokeComplete", eventArgs);
      }
      catch (Exception ex)
      {
        Csla.Reflection.MethodCaller.CallMethodIfImplemented(
          factory, "InvokeError", new DataPortalEventArgs(context, objectType, null, operation, ex));
        throw;
      }
      return new DataPortalResult(result);
    }
Пример #2
0
    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);
      }
    }
Пример #3
0
    private async Task<DataPortalResult> InvokeMethod(string factoryTypeName, DataPortalOperations operation, string methodName, Type objectType, DataPortalContext context)
    {
      object factory = FactoryLoader.GetFactory(factoryTypeName);
      var eventArgs = new DataPortalEventArgs(context, objectType, null, operation);

      Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "Invoke", eventArgs);
      object result = null;
      try
      {
        result = await Csla.Reflection.MethodCaller.CallMethodTryAsync(factory, methodName);
        var error = result as Exception;
        if (error != null)
          throw error;
        Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "InvokeComplete", eventArgs);
      }
      catch (Exception ex)
      {
        Csla.Reflection.MethodCaller.CallMethodIfImplemented(
          factory, "InvokeError", new DataPortalEventArgs(context, objectType, null, operation, ex));
        throw;
      }
      return new DataPortalResult(result);
    }
Пример #4
0
 protected override void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs eva)
 {
     base.DataPortal_OnDataPortalInvokeComplete(eva);
 }
Пример #5
0
        protected override void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            Csla.ApplicationContext.GlobalContext["dpinvokecomplete"] = ApplicationContext.GlobalContext["global"];
#pragma warning restore CS0618 // Type or member is obsolete
        }
Пример #6
0
 private void OnDataPortalInvokeComplete(DataPortalEventArgs e)
 {
     Csla.ApplicationContext.GlobalContext["ClientInvokeComplete"] = ApplicationContext.GlobalContext["global"];
 }
Пример #7
0
    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);
      }
    }
Пример #8
0
 private void ClientPortal_DataPortalInvokeComplete(DataPortalEventArgs obj)
 {
     TestResults.Add("dpinvokecomplete", "true");
 }
Пример #9
0
        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);
            }
        }
Пример #10
0
 protected virtual void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
 {
 }
Пример #11
0
    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);
      }
    }
Пример #12
0
 private void ClientPortal_DataPortalInvokeComplete(DataPortalEventArgs obj)
 {
     ApplicationContext.GlobalContext["dpinvokecomplete"] = true;
 }
Пример #13
0
 protected override void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
 {
     TestResults.Reinitialise();
     TestResults.Add("OnDataPortalException", "Called");
     Console.WriteLine("OnDataPortalException called");
 }
Пример #14
0
 protected override void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
 {
     Csla.ApplicationContext.GlobalContext.Clear();
     Csla.ApplicationContext.GlobalContext.Add("OnDataPortalException", "Called");
     Console.WriteLine("OnDataPortalException called");
 }
Пример #15
0
 protected override void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
 {
     TestResults.Add("serverinvokecomplete", "true");
 }
 /// <summary>
 /// Called by the server-side DataPortal if an exception
 /// occurs during data access.
 /// </summary>
 /// <param name="e">The DataPortalContext object passed to the DataPortal.</param>
 /// <param name="ex">The Exception thrown during data access.</param>
 protected override void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
 {
     Trace.TraceError("DataPortalException object:{0}, operation:{1}, exception:{2}", e.ObjectType, e.Operation, ex);
     base.DataPortal_OnDataPortalException(e, ex);
 }
 /// <summary>
 /// Called by the server-side DataPortal after calling the
 /// requested DataPortal_xyz method.
 /// </summary>
 /// <param name="e">The DataPortalContext object passed to the DataPortal.</param>
 protected override void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
 {
     Trace.TraceInformation("DataPortalInvokeCompleted object:{0}, operation:{1}", e.ObjectType, e.Operation);
     base.DataPortal_OnDataPortalInvokeComplete(e);
 }
Пример #18
0
 protected override void Child_OnDataPortalException(DataPortalEventArgs eva, Exception ex)
 {
     base.DataPortal_OnDataPortalException(eva, ex);
 }
Пример #19
0
        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);
            }
        }
Пример #20
0
 protected override void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
 {
     Csla.ApplicationContext.GlobalContext["dpinvokecomplete"] = ApplicationContext.GlobalContext["global"];
 }
Пример #21
0
 protected override void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
 {
     Csla.ApplicationContext.GlobalContext["serverinvoke"] = true;
 }
Пример #22
0
        /// <summary>
        /// Get an existing business object.
        /// </summary>
        /// <param name="objectType">Type of business object to retrieve.</param>
        /// <param name="parameters">
        /// Criteria parameters passed from caller.
        /// </param>
        public object Fetch(Type objectType, params object[] parameters)
        {
            LateBoundObject   obj    = null;
            IDataPortalTarget target = null;
            var eventArgs            = new DataPortalEventArgs(null, objectType, DataPortalOperations.Fetch);

            try
            {
                // create an instance of the business object
                obj = new LateBoundObject(objectType);

                target = obj.Instance as IDataPortalTarget;

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

                // tell the business object to fetch its data
                obj.CallMethod("Child_Fetch", parameters);

                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.Fetch " + Properties.Resources.FailedOnServer, ex, bo);
            }
        }
Пример #23
0
 protected virtual void DataPortal_OnDataPortalException(DataPortalEventArgs e, Exception ex)
 {
 }
Пример #24
0
        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);
                }

                Utilities.ThrowIfAsyncMethodOnSyncClient(isSync, target, "DataPortal_Delete", criteria);

                // 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);
            }
        }
Пример #25
0
 protected override void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
 {
 }
Пример #26
0
 private void ClientPortal_DataPortalInvokeComplete(DataPortalEventArgs obj)
 {
     ApplicationContext.GlobalContext["dpinvokecomplete"] = true;
 }
Пример #27
0
        public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
        {
            LateBoundObject   obj    = null;
            IDataPortalTarget target = null;
            var eventArgs            = new DataPortalEventArgs(context, objectType, DataPortalOperations.Fetch);

            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.MarkOld();
                }
                else
                {
                    obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);
                    obj.CallMethodIfImplemented("MarkOld");
                }

                // tell the business object to fetch its data
                if (criteria is int)
                {
                    obj.CallMethod("DataPortal_Fetch");
                }
                else
                {
                    obj.CallMethod("DataPortal_Fetch", 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
                    {
                        obj.CallMethodIfImplemented(
                            "DataPortal_OnDataPortalException",
                            eventArgs, ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                object outval = null;
                if (obj != null)
                {
                    outval = obj.Instance;
                }
                throw new DataPortalException(
                          "DataPortal.Fetch " + Resources.FailedOnServer,
                          ex, new DataPortalResult(outval));
            }
        }
Пример #28
0
    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);
      }
    }
Пример #29
0
        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(ApplicationContext.DataPortalActivator.CreateInstance(objectType));
                ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance);

                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").ConfigureAwait(false);
                }
                else
                {
                    await obj.CallMethodTryAsync("DataPortal_Create", 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.Create " + Resources.FailedOnServer,
                          new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Create", ex),
                          outval);
            }
            finally
            {
                ApplicationContext.DataPortalActivator.FinalizeInstance(obj.Instance);
            }
        }
Пример #30
0
        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);
              }
        }
Пример #31
0
 protected override void DataPortal_OnDataPortalInvokeComplete(DataPortalEventArgs e)
 {
     TestResults.Add("dpinvokecomplete", TestResults.GetResult("global"));
 }