コード例 #1
0
        /// <summary>
        /// Puts a number of changed objects into the database. The resultant objects are sent back to the client.
        /// </summary>
        /// <param name="version">Current version of generated Zetbox.Objects assembly</param>
        /// <param name="msgArray">a streamable list of <see cref="IPersistenceObject"/>s</param>
        /// <param name="notificationRequests">A list of objects the client wants to be notified about, if they change.</param>
        /// <returns>a streamable list of <see cref="IPersistenceObject"/>s</returns>
        public byte[] SetObjects(Guid version, byte[] msgArray, ObjectNotificationRequest[] notificationRequests)
        {
            using (Logging.Facade.DebugTraceMethodCall("SetObjects"))
            {
                DebugLogIdentity();
                int resultCount = 0;
                var ticks       = _perfCounter.IncrementSetObjects();
                try
                {
                    if (msgArray == null)
                    {
                        throw new ArgumentNullException("msgArray");
                    }
                    MemoryStream msg = new MemoryStream(msgArray);

                    msg.Seek(0, SeekOrigin.Begin);

                    using (IZetboxContext ctx = _ctxFactory())
                    {
                        var objects = ReadObjects(msg, ctx);

                        // Set Operation
                        var changedObjects = _sohFactory
                                             .GetServerObjectSetHandler()
                                             .SetObjects(version, ctx, objects, notificationRequests ?? new ObjectNotificationRequest[0])
                                             .Cast <IStreamable>();
                        resultCount = objects.Count;
                        return(SendObjects(changedObjects, true).ToArray());
                    }
                }
                catch (Exception ex)
                {
                    Helper.ThrowFaultException(ex);
                    // Never called, Handle errors throws an Exception
                    return(null);
                }
                finally
                {
                    _perfCounter.DecrementSetObjects(resultCount, ticks);
                }
            }
        }
コード例 #2
0
        public IEnumerable <IPersistenceObject> SetObjects(IZetboxContext ctx, IEnumerable <IPersistenceObject> objects, IEnumerable <ObjectNotificationRequest> notficationRequests)
        {
            var ticks = _perfCounter.IncrementSetObjects();

            try
            {
                IEnumerable <IPersistenceObject> result = null;
                // Serialize
                using (var ms = new MemoryStream())
                    using (var sw = _writerFactory(new BinaryWriter(ms)))
                    {
                        SendObjects(objects, sw);
                        byte[] bytes = null;
                        var    _ms   = ms.ToArray();
                        var    _nReq = notficationRequests.ToArray();

                        MakeRequest(() =>
                        {
                            bytes = _service.SetObjects(ZetboxGeneratedVersionAttribute.Current, _ms, _nReq);
                        });

                        using (var sr = _readerFactory(new BinaryReader(new MemoryStream(bytes))))
                        {
                            // merge auxiliary objects into primary set objects result
                            List <IStreamable> auxObjects;
                            var receivedObjects = ReceiveObjects(ctx, sr, out auxObjects);
                            result = receivedObjects.Concat(auxObjects).Cast <IPersistenceObject>();
                        }
                    }

                return(result);
            }
            finally
            {
                _perfCounter.DecrementSetObjects(objects.Count(), ticks);
            }
        }