Example #1
0
        public WcfResponse Fetch(CriteriaRequest request)
        {
            Csla.Server.DataPortal portal     = new Csla.Server.DataPortal();
            Exception               error     = null;
            DataPortalResult        result    = null;
            WcfResponse             response  = null;
            ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter();

            try
            {
                request = ConvertRequest(request);
                DataPortalContext context = new DataPortalContext(
                    formatter.Deserialize(request.Principal) as IPrincipal,
                    true,
                    request.ClientCulture,
                    request.ClientUICulture,
                    formatter.Deserialize(request.ClientContext) as ContextDictionary,
                    formatter.Deserialize(request.GlobalContext) as ContextDictionary);
                result   = portal.Fetch(Type.GetType(request.TypeName), formatter.Deserialize(request.CriteriaData), context);
                response = new WcfResponse(
                    formatter.Serialize(result.ReturnObject),
                    formatter.Serialize(error),
                    formatter.Serialize(Csla.ApplicationContext.GlobalContext));
            }
            catch (Exception ex)
            {
                error    = ex;
                response = new WcfResponse(
                    null,
                    formatter.Serialize(error),
                    formatter.Serialize(Csla.ApplicationContext.GlobalContext));
            }
            return(ConvertResponse(response));
        }
Example #2
0
        private DataPortalResult GetResult(ISerializationFormatter formatter, WcfResponse response)
        {
            response = ConvertResponse(response);
            object            result        = formatter.Deserialize(response.ObjectData);
            ContextDictionary globalContext = (ContextDictionary)formatter.Deserialize(response.GlobalContext);
            DataPortalResult  returnValue   = new DataPortalResult(result, globalContext);

            return(returnValue);
        }
Example #3
0
        public object Deserialize(Type expectedType, IDeserializationContext context)
        {
            try
            {
                _logger.LogInformation("Deserialising: {name}", expectedType?.Name ?? "{null expetced type}");
                var size = context.StreamReader.ReadLong();

                _logger.LogInformation("Size {size}", size);
                if (size == 0)
                {
                    return(null);
                }

                using (var memoryStream = new MemoryStream((int)size))
                {
                    var bytes = context.StreamReader.ReadBytes((int)size);
                    memoryStream.Write(bytes, 0, bytes.Length);
                    memoryStream.Position = 0;
                    // memoryStream.Seek(0, SeekOrigin.Begin);
                    var deserialised = _cslaSerializarionFormatter.Deserialize(memoryStream);
                    return(deserialised);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Could not deserialise.");
                throw;
            }
        }
Example #4
0
        /// <summary>
        /// Called by <see cref="DataPortal" /> to create a
        /// new 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>
        public DataPortalResult Create(Type objectType, object criteria, DataPortalContext context)
        {
            ChannelFactory <IExtendableWcfPortalForDotNet> cf = GetChannelFactory();
            IExtendableWcfPortalForDotNet svr = GetProxy(cf);
            WcfResponse             response  = null;
            ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter();

            try
            {
                response =
                    svr.Create(GetRequest(formatter, objectType, criteria, context));
                if (cf != null)
                {
                    cf.Close();
                }
            }
            catch
            {
                cf.Abort();
                throw;
            }
            DataPortalResult result = GetResult(formatter, response);
            Exception        error  = (Exception)formatter.Deserialize(response.Error);

            if (error != null)
            {
                throw error;
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// Clones an object.
        /// </summary>
        /// <param name="obj">The object to clone.</param>
        /// <remarks>
        /// <para>The object to be cloned must be serializable.</para>
        /// <para>The serialization is performed using the formatter
        /// specified in ApplicationContext.</para>
        /// <para>The default is to use the MobileFormatter.</para>
        /// </remarks>
        public object Clone(object obj)
        {
            using var buffer = new MemoryStream();
            ISerializationFormatter formatter =
                SerializationFormatterFactory.GetFormatter(ApplicationContext);

            formatter.Serialize(buffer, obj);
            buffer.Position = 0;
            return(formatter.Deserialize(buffer));
        }
 /// <summary>
 /// Clones an object.
 /// </summary>
 /// <param name="obj">The object to clone.</param>
 /// <remarks>
 /// <para>The object to be cloned must be serializable.</para>
 /// <para>The serialization is performed using the formatter
 /// specified in the application's configuration file
 /// using the CslaSerializationFormatter key.</para>
 /// <para>The default is to use the
 /// <see cref="System.Runtime.Serialization.Formatters.Binary.BinaryFormatter" />
 /// </para>. You may also choose to use the Microsoft .NET 3.0
 /// <see cref="System.Runtime.Serialization.NetDataContractSerializer">
 /// NetDataContractSerializer</see> provided as part of WCF.
 /// </remarks>
 public static object Clone(object obj)
 {
     using (MemoryStream buffer = new MemoryStream())
     {
         ISerializationFormatter formatter =
             SerializationFormatterFactory.GetFormatter();
         formatter.Serialize(buffer, obj);
         buffer.Position = 0;
         object temp = formatter.Deserialize(buffer);
         return(temp);
     }
 }
    public void Execute(string command)
    {
        if (command == null)
        {
            throw new ArgumentNullException("command");
        }
        var  request     = _formatter.Deserialize <CommandRequest>(command);
        Type handlerType = typeof(ICommandHandler <>)
                           .MakeGenericType(request.Command.GetType());
        dynamic handler = _container.GetInstance(handlerType);

        handler.Handle((dynamic)(request.Command));
    }
 public static object Deserialize(this ISerializationFormatter formatter, byte[] objectData)
 {
     if (objectData != null)
     {
         using (MemoryStream stream = new MemoryStream(objectData))
         {
             return(formatter.Deserialize(stream));
         }
     }
     else
     {
         return(null);
     }
 }
Example #9
0
 private DataPortalResult GetResult(ISerializationFormatter formatter, WcfResponse response)
 {
   response = ConvertResponse(response);
   object result = formatter.Deserialize(response.ObjectData);
   ContextDictionary globalContext = (ContextDictionary)formatter.Deserialize(response.GlobalContext);
   DataPortalResult returnValue = new DataPortalResult(result, globalContext);
   return returnValue;
 }
        protected internal void UndoChanges(int parentEditLevel)
        {
            UndoingChanges();

            // if we are a child object we might be asked to
            // undo below the level of stacked states,
            // so just do nothing in that case
            if (EditLevel > 0)
            {
                if (this.EditLevel - 1 != parentEditLevel)
                {
                    throw new UndoException(string.Format(Resources.EditLevelMismatchException, "UndoChanges"));
                }

                HybridDictionary state;
                using (MemoryStream buffer = new MemoryStream(_stateStack.Pop()))
                {
                    buffer.Position = 0;
                    ISerializationFormatter formatter =
                        SerializationFormatterFactory.GetFormatter();
                    state = (HybridDictionary)formatter.Deserialize(buffer);
                }

                Type currentType = this.GetType();

                do
                {
                    var currentTypeName = currentType.FullName;

                    // get the list of fields in this type
                    List <DynamicMemberHandle> handlers = UndoableHandler.GetCachedFieldHandlers(currentType);
                    foreach (var h in handlers)
                    {
                        // the field is undoable, so restore its value
                        var value = h.DynamicMemberGet(this);

                        if (typeof(Csla.Core.IUndoableObject).IsAssignableFrom(h.MemberType))
                        {
                            // this is a child object
                            // see if the previous value was empty
                            //if (state.Contains(h.MemberName))
                            if (state.Contains(GetFieldName(currentTypeName, h.MemberName)))
                            {
                                // previous value was empty - restore to empty
                                h.DynamicMemberSet(this, null);
                            }
                            else
                            {
                                // make sure the variable has a value
                                if (value != null)
                                {
                                    // this is a child object, cascade the call.
                                    ((Core.IUndoableObject)value).UndoChanges(this.EditLevel,
                                                                              BindingEdit);
                                }
                            }
                        }
                        else
                        {
                            // this is a regular field, restore its value
                            h.DynamicMemberSet(this, state[GetFieldName(currentTypeName, h.MemberName)]);
                            //h.DynamicMemberSet(this, state[h.MemberName]);
                        }
                    }

                    currentType = currentType.BaseType;
                } while (currentType != typeof(UndoableBase));
            }
            UndoChangesComplete();
        }