Exemplo n.º 1
0
        /// <summary>
        /// This class is used to place type information on the wire. Since the wire protocol is Provider independent, 
        /// only interface types are stored. Usually this is used to declare the type of the following IPersistenceObject.
        /// </summary>
        /// <remarks>
        /// Since the <see cref="InterfaceType.Factory"/> cannot be serialiezed, this class cannot provide full dehydration.
        /// Use <see cref="GetSystemType"/> and your own factory to retrieve <see cref="InterfaceType"/>.</remarks>
        /// <param name="ifType">System.Type to serialize</param>
        /// <param name="iftFactory"></param>
        internal SerializableType(InterfaceType ifType, InterfaceType.Factory iftFactory)
        {
            var type = ifType.Type;

            if (type.IsGenericType)
            {
                Type genericType = type.GetGenericTypeDefinition();
                TypeName = genericType.FullName;
                AssemblyQualifiedName = genericType.AssemblyQualifiedName;

                GenericTypeParameter = type.GetGenericArguments()
                    .Select(t => new SerializableType(iftFactory(t), iftFactory))
                    .ToArray();
            }
            else
            {
                TypeName = type.FullName;
                AssemblyQualifiedName = type.AssemblyQualifiedName;
                GenericTypeParameter = new SerializableType[] { };
            }

            // This is null if the Type is e.g. a Generic Parameter - not supported
            if (string.IsNullOrEmpty(AssemblyQualifiedName))
                throw new NotSupportedException("AssemblyQualifiedName must not be null or empty - maybe this Type is a Generic Parameter or something similarily strange.");
        }
Exemplo n.º 2
0
        public List<JavaScriptObjectMoniker> GetList(SerializableType type)
        {
            if (type == null) { throw new ArgumentNullException("type"); }

            throw new NotImplementedException();
            //try
            //{
            //    return ZetboxContextManagerModule.ZetboxContext.GetQuery(ZetboxContextManagerModule.IftFactory(type.GetSystemType()))
            //        .Select(i => new JavaScriptObjectMoniker(ZetboxContextManagerModule.ZetboxContext, i)).ToList();
            //}
            //catch (Exception ex)
            //{
            //    throw new FaultException(ex.Message);
            //}
        }
Exemplo n.º 3
0
        public byte[] InvokeServerMethod(Guid version, SerializableType type, int ID, string method, SerializableType[] parameterTypes, byte[] parameterArray, byte[] changedObjectsArray, ObjectNotificationRequest[] notificationRequests, out byte[] retChangedObjects)
        {
            using (Logging.Facade.DebugTraceMethodCallFormat("InvokeServerMethod:" + method, "method={0}, ID={1}", method, ID))
            {
                if (type == null)
                    throw new ArgumentNullException("type");
                if (string.IsNullOrEmpty(method))
                    throw new ArgumentNullException("method");
                if (parameterTypes == null)
                    throw new ArgumentNullException("parameterTypes");
                if (parameterArray == null)
                    throw new ArgumentNullException("parameterArray");
                if (changedObjectsArray == null)
                    throw new ArgumentNullException("changedObjectsArray");

                _perfCounter.IncrementServerMethodInvocation();
                retChangedObjects = null;

                try
                {
                    DebugLogIdentity();

                    using (IZetboxContext ctx = _ctxFactory())
                    {
                        var parameter = new MemoryStream(parameterArray);
                        parameter.Seek(0, SeekOrigin.Begin);
                        List<object> parameterList = new List<object>();
                        using (var parameterReader = _readerFactory.Invoke(new BinaryReader(parameter)))
                        {
                            foreach (var t in parameterTypes)
                            {
                                object val;
                                var systemType = t.GetSystemType();
                                parameterReader.Read(out val,
                                    systemType.IsICompoundObject() // IDataObjects are serialized as proxy, only ICompoundObject are serialized directoy
                                        ? ctx.ToImplementationType(ctx.GetInterfaceType(systemType)).Type
                                        : systemType);
                                parameterList.Add(val);
                            }
                        }

                        var changedObjects = new MemoryStream(changedObjectsArray);
                        changedObjects.Seek(0, SeekOrigin.Begin);

                        var readObjects = ReadObjects(changedObjects, ctx);

                        // Context is ready, translate IDataObjectParameter
                        for(int i=0;i<parameterList.Count;i++)
                        {
                            var p = parameterList[i] as ZetboxStreamReader.IDataObjectProxy;
                            if(p != null)
                            {
                                parameterList[i] = ctx.Find(_iftFactory(p.Type.GetSystemType()), p.ID);
                            }
                        }

                        IEnumerable<IPersistenceObject> changedObjectsList;
                        var result = _sohFactory
                            .GetServerObjectHandler(_iftFactory(type.GetSystemType()))
                            .InvokeServerMethod(version, ctx, ID, method,
                                parameterTypes.Select(t => t.GetSystemType()),
                                parameterList,
                                readObjects,
                                notificationRequests ?? new ObjectNotificationRequest[0],
                                out changedObjectsList);

                        retChangedObjects = SendObjects(changedObjectsList.Cast<IStreamable>(), true).ToArray();

                        if (Logging.Facade.IsDebugEnabled && result != null)
                        {
                            Logging.Facade.DebugFormat("Serializing method result type is '{0}'", result.GetType().FullName);
                        }

                        if (result != null && result.GetType() == typeof(string))
                        {
                            Logging.Facade.Debug("Serializing method result as string");
                            // string is also a IEnumerable, but FindElementTypes returns nothing
                            MemoryStream resultStream = new MemoryStream();
                            new BinaryFormatter().Serialize(resultStream, result);
                            return resultStream.ToArray();
                        }
                        else if (result != null && result.GetType().IsIStreamable())
                        {
                            Logging.Facade.Debug("Serializing method result as IStreamable");
                            IStreamable resultObj = (IStreamable)result;
                            return SendObjects(new IStreamable[] { resultObj }, true).ToArray();
                        }
                        else if (result != null && result.GetType().IsIEnumerable() && result.GetType().FindElementTypes().Any(t => t.IsIStreamable()))
                        {
                            Logging.Facade.Debug("Serializing method result as IEnumerable<IStreamable>");
                            var lst = ((IEnumerable)result).AsQueryable().Cast<IStreamable>().Take(Zetbox.API.Helper.MAXLISTCOUNT);
                            return SendObjects(lst, true).ToArray();
                        }
                        else if (result != null)
                        {
                            Logging.Facade.Debug("Serializing method result as object with BinaryFormatter");
                            MemoryStream resultStream = new MemoryStream();
                            new BinaryFormatter().Serialize(resultStream, result);
                            return resultStream.ToArray();
                        }
                        else
                        {
                            Logging.Facade.Debug("Serializing empty method");
                            return new byte[] { };
                        }
                    }
                }
                catch (Exception ex)
                {
                    Helper.ThrowFaultException(ex);
                    // Never called, Handle errors throws an Exception
                    return null;
                }
            }
        }
Exemplo n.º 4
0
        public byte[] GetListOf(Guid version, SerializableType type, int ID, string property)
        {
            using (Logging.Facade.DebugTraceMethodCallFormat("GetListOf", "type={0}", type))
            {
                DebugLogIdentity();
                try
                {
                    if (type == null) { throw new ArgumentNullException("type"); }

                    using (var ctx = _ctxFactory())
                    {
                        var ifType = _iftFactory(type.GetSystemType());
                        int resultCount = 0;
                        var ticks = _perfCounter.IncrementGetListOf(ifType);
                        try
                        {
                            IEnumerable<IStreamable> lst = _sohFactory
                                .GetServerObjectHandler(ifType)
                                .GetListOf(version, ctx, ID, property);
                            resultCount = lst.Count();
                            return SendObjects(lst, false /*true*/).ToArray();
                        }
                        finally
                        {
                            _perfCounter.DecrementGetListOf(ifType, resultCount, ticks);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Helper.ThrowFaultException(ex);
                    // Never called, Handle errors throws an Exception
                    return null;
                }
            }
        }
Exemplo n.º 5
0
 internal SerializableType(string typeName, string assemblyQualifiedName, SerializableType[] genericTypeParameter)
 {
     TypeName = typeName;
     AssemblyQualifiedName = assemblyQualifiedName;
     GenericTypeParameter = genericTypeParameter;
 }
Exemplo n.º 6
0
 private void Init(DataObjectViewModel m)
 {
     ID = m.ID;
     Type = m.GetInterfaceType().ToSerializableType();
     Text = m.Name;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Deserialize a SerializableType.
 /// </summary>
 /// <param name="type">Destination Value.</param>
 public void Read(out SerializableType type)
 {
     type = ReadSerializableType();
 }
Exemplo n.º 8
0
 /// <summary>
 /// Returns a list of objects from the datastore, matching the specified filters.
 /// </summary>
 /// <param name="version">Current version of generated Zetbox.Objects assembly</param>
 /// <param name="type">Type of Objects</param>
 /// <param name="maxListCount">Max. ammount of objects</param>
 /// <param name="eagerLoadLists">If true list properties will be eager loaded</param>
 /// <param name="filter">Serializable linq expression used a filter</param>
 /// <param name="orderBy">List of derializable linq expressions used as orderby</param>
 /// <returns>the found objects</returns>
 public byte[] GetList(Guid version, SerializableType type, int maxListCount, bool eagerLoadLists, SerializableExpression[] filter, OrderByContract[] orderBy)
 {
     using (Logging.Facade.DebugTraceMethodCallFormat("GetList", "type={0}", type))
     {
         DebugLogIdentity();
         try
         {
             if (type == null) { throw new ArgumentNullException("type"); }
             var ifType = _iftFactory(type.GetSystemType());
             int resultCount = 0;
             var ticks = _perfCounter.IncrementGetList(ifType);
             try
             {
                 using (IZetboxContext ctx = _ctxFactory())
                 {
                     var filterExpresstions = filter != null ? filter.Select(f => SerializableExpression.ToExpression(f)).ToList() : null;
                     IEnumerable<IStreamable> lst = _sohFactory
                         .GetServerObjectHandler(ifType)
                         .GetList(version, ctx, maxListCount,
                             filterExpresstions,
                             orderBy != null ? orderBy.Select(o => new OrderBy(o.Type, SerializableExpression.ToExpression(o.Expression))).ToList() : null);
                     resultCount = lst.Count();
                     return SendObjects(lst, eagerLoadLists).ToArray();
                 }
             }
             finally
             {
                 _perfCounter.DecrementGetList(ifType, resultCount, ticks);
             }
         }
         catch (Exception ex)
         {
             Helper.ThrowFaultException(ex);
             // Never called, Handle errors throws an Exception
             return null;
         }
     }
 }