Example #1
0
        public void Initialize_PrimitiveCriteria_NoExceptionRaised()
        {
            // Arrange
            bool executed = false;
            PrimitiveCriteria       criteria           = new PrimitiveCriteria(1);
            ApplicationContext      applicationContext = _testDIContext.CreateTestApplicationContext();
            RevalidatingInterceptor sut  = new RevalidatingInterceptor(applicationContext);
            InterceptArgs           args = new InterceptArgs()
            {
                ObjectType = typeof(Root),
                Operation  = DataPortalOperations.Update,
                Parameter  = criteria,
                IsSync     = true
            };

            applicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
            applicationContext.LocalContext["__logicalExecutionLocation"] = ApplicationContext.LogicalExecutionLocations.Server;

            // Act
            sut.Initialize(args);
            executed = true;

            // Assert
            Assert.IsTrue(executed);
        }
Example #2
0
        /// <summary>
        /// Called by <see cref="DataPortal" /> to delete a
        /// business object.
        /// </summary>
        /// <param name="objectType">Type of business object to create.</param>
        /// <param name="criteria">Criteria object describing business object.</param>
        /// <param name="context">
        /// <see cref="Server.DataPortalContext" /> object passed to the server.
        /// </param>
        /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
        public async Task <DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
        {
            if (isSync)
            {
                throw new NotSupportedException("isSync == true");
            }

            InitializeRabbitMQ();
            DataPortalResult result;

            try
            {
                var request = GetBaseCriteriaRequest();
                request.TypeName = AssemblyNameTranslator.GetAssemblyQualifiedName(objectType.AssemblyQualifiedName);
                if (!(criteria is IMobileObject))
                {
                    criteria = new PrimitiveCriteria(criteria);
                }
                request.CriteriaData = MobileFormatter.Serialize(criteria);
                request = ConvertRequest(request);

                var serialized = MobileFormatter.Serialize(request);

                serialized = await CallDataPortalServer(serialized, "delete");

                var response = (Server.Hosts.HttpChannel.HttpResponse)MobileFormatter.Deserialize(serialized);
                response = ConvertResponse(response);
                var globalContext = (ContextDictionary)MobileFormatter.Deserialize(response.GlobalContext);
                if (response != null && response.ErrorData == null)
                {
                    var obj = MobileFormatter.Deserialize(response.ObjectData);
                    result = new DataPortalResult(obj, null, globalContext);
                }
                else if (response != null && response.ErrorData != null)
                {
                    var ex = new DataPortalException(response.ErrorData);
                    result = new DataPortalResult(null, ex, globalContext);
                }
                else
                {
                    throw new DataPortalException("null response", null);
                }
            }
            catch (Exception ex)
            {
                result = new DataPortalResult(null, ex, null);
            }
            if (result.Error != null)
            {
                throw result.Error;
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// Called by <see cref="DataPortal" /> to load an
        /// existing business object.
        /// </summary>
        /// <param name="objectType">Type of business object to create.</param>
        /// <param name="criteria">Criteria object describing business object.</param>
        /// <param name="context">
        /// <see cref="Server.DataPortalContext" /> object passed to the server.
        /// </param>
        /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
        public async Task <DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
        {
            DataPortalResult result;

            try
            {
                var request = GetBaseCriteriaRequest();
                request.TypeName = AssemblyNameTranslator.GetAssemblyQualifiedName(objectType.AssemblyQualifiedName);
                if (!(criteria is IMobileObject))
                {
                    criteria = new PrimitiveCriteria(criteria);
                }
                request.CriteriaData = SerializationFormatterFactory.GetFormatter().Serialize(criteria);
                request = ConvertRequest(request);

                var serialized = SerializationFormatterFactory.GetFormatter().Serialize(request);

                serialized = await CallDataPortalServer(serialized, "fetch", GetRoutingToken(objectType), isSync);

                var response = (Csla.Server.Hosts.HttpChannel.HttpResponse)SerializationFormatterFactory.GetFormatter().Deserialize(serialized);
                response = ConvertResponse(response);
                var globalContext = (ContextDictionary)SerializationFormatterFactory.GetFormatter().Deserialize(response.GlobalContext);
                if (response != null && response.ErrorData == null)
                {
                    var obj = SerializationFormatterFactory.GetFormatter().Deserialize(response.ObjectData);
                    result = new DataPortalResult(obj, null, globalContext);
                }
                else if (response != null && response.ErrorData != null)
                {
                    var ex = new DataPortalException(response.ErrorData);
                    result = new DataPortalResult(null, ex, globalContext);
                }
                else
                {
                    throw new DataPortalException("null response", null);
                }
            }
            catch (Exception ex)
            {
                result = new DataPortalResult(null, ex, null);
            }
            if (result.Error != null)
            {
                throw result.Error;
            }
            return(result);
        }