示例#1
0
        private Property CreateProperty(IZetboxContext ctx, int unique)
        {
            var result = ctx.Create <IntProperty>();

            result.Module = ctx.FindPersistenceObject <Module>(_moduleGuid);
            result.Name   = "property" + unique;
            result.ValueModelDescriptor = ctx.FindPersistenceObject <ViewModelDescriptor>(_valueDescGuid);
            return(result);
        }
示例#2
0
        public IEnumerable <T> FetchRelation <T>(IZetboxContext ctx, Guid relationId, RelationEndRole role, IDataObject parent, out List <IStreamable> auxObjects)
            where T : class, IRelationEntry
        {
            // TODO: could be implemented in generated properties
            if (parent.ObjectState == DataObjectState.New)
            {
                auxObjects = new List <IStreamable>();
                return(new List <T>());
            }

            Relation rel = ctx.FindPersistenceObject <Relation>(relationId);

            IEnumerable <T>    result        = null;
            List <IStreamable> tmpAuxObjects = null;

            var handler = _memoryFactory
                          .GetServerCollectionHandler(
                _backingStore,
                _iftFactory(rel.A.Type.GetDataType()),
                _iftFactory(rel.B.Type.GetDataType()),
                role);
            var objects = handler
                          .GetCollectionEntries(ZetboxGeneratedVersionAttribute.Current, _backingStore, relationId, role, parent.ID)
                          .Cast <IStreamable>();
            var bytes = SendObjects(objects, true).ToArray();

            using (MemoryStream s = new MemoryStream(bytes))
                using (var sr = new ZetboxStreamReader(_map, new BinaryReader(s)))
                {
                    result = ReceiveObjects(ctx, sr, out tmpAuxObjects).Cast <T>();
                }

            auxObjects = tmpAuxObjects;
            return(result);
        }
示例#3
0
        private SavedListConfiguration GetSavedConfig(IZetboxContext ctx)
        {
            var config = ctx.GetQuery <SavedListConfiguration>()
                         .Where(i => i.Type.ExportGuid == Parent.DataType.ExportGuid) // Parent.DataType might be from FrozenContext
                         .Where(i => i.Owner == this.CurrentIdentity)
                         .FirstOrDefault();

            if (config == null)
            {
                config       = ctx.Create <SavedListConfiguration>();
                config.Owner = ctx.Find <Identity>(CurrentIdentity.ID);
                config.Type  = ctx.FindPersistenceObject <ObjectClass>(Parent.DataType.ExportGuid); // Parent.DataType might be from FrozenContext
            }
            return(config);
        }
示例#4
0
        /// <summary>
        /// Fetches a list of CollectionEntry objects of the Relation
        /// <paramref name="relId"/> which are owned by the object with the
        /// ID <paramref name="parentObjID"/> in the role <paramref name="serializableRole"/>.
        /// </summary>
        /// <param name="version">Current version of generated Zetbox.Objects assembly</param>
        /// <param name="relId">the requested Relation</param>
        /// <param name="serializableRole">the parent role (1 == A, 2 == B)</param>
        /// <param name="parentObjID">the ID of the parent object</param>
        /// <returns>the requested collection entries</returns>
        public byte[] FetchRelation(Guid version, Guid relId, int serializableRole, int parentObjID)
        {
            using (Logging.Facade.DebugTraceMethodCallFormat("FetchRelation", "relId = [{0}], role = [{1}], parentObjID = [{2}]", relId, serializableRole, parentObjID))
            {
                try
                {
                    DebugLogIdentity();

                    using (IZetboxContext ctx = _ctxFactory())
                    {
                        var endRole = (RelationEndRole)serializableRole;
                        // TODO: Use FrozenContext
                        Relation rel         = ctx.FindPersistenceObject <Relation>(relId);
                        var      ifTypeA     = _iftFactory(rel.A.Type.GetDataType());
                        var      ifTypeB     = _iftFactory(rel.B.Type.GetDataType());
                        var      ifType      = endRole == RelationEndRole.A ? ifTypeA : ifTypeB;
                        int      resultCount = 0;
                        var      ticks       = _perfCounter.IncrementFetchRelation(ifType);
                        try
                        {
                            var lst = _sohFactory
                                      .GetServerCollectionHandler(
                                ctx,
                                ifTypeA,
                                ifTypeB,
                                endRole)
                                      .GetCollectionEntries(version, ctx, relId, endRole, parentObjID);
                            resultCount = lst.Count();
                            return(SendObjects(lst.Cast <IStreamable>(), true).ToArray());
                        }
                        finally
                        {
                            _perfCounter.DecrementFetchRelation(ifType, resultCount, ticks);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Helper.ThrowFaultException(ex);
                    // Never called, Handle errors throws an Exception
                    return(null);
                }
            }
        }
示例#5
0
        public IEnumerable <IRelationEntry> GetCollectionEntries(
            Guid version,
            IZetboxContext ctx,
            Guid relId, RelationEndRole endRole,
            int parentId)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }
            ZetboxGeneratedVersionAttribute.Check(version);

            var rel = ctx.FindPersistenceObject <Relation>(relId);
            //var relEnd = rel.GetEndFromRole(endRole);
            //var relOtherEnd = rel.GetOtherEnd(relEnd);
            var parent = ctx.Find(ctx.GetImplementationType(typeof(TParent)).ToInterfaceType(), parentId);
            var ceType = ctx.ToImplementationType(rel.GetEntryInterfaceType()).Type;

            var method = this.GetType().GetMethod("GetCollectionEntriesInternal", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            return((IEnumerable <IRelationEntry>)method
                   .MakeGenericMethod(ceType)
                   .Invoke(this, new object[] { parent, rel, endRole }));
        }
 private SavedListConfiguration GetSavedConfig(IZetboxContext ctx)
 {
     var config = ctx.GetQuery<SavedListConfiguration>()
         .Where(i => i.Type.ExportGuid == Parent.DataType.ExportGuid) // Parent.DataType might be from FrozenContext
         .Where(i => i.Owner.ID == this.CurrentPrincipal.ID)
         .FirstOrDefault();
     if (config == null)
     {
         config = ctx.Create<SavedListConfiguration>();
         config.Owner = ctx.Find<Identity>(CurrentPrincipal.ID);
         config.Type = ctx.FindPersistenceObject<ObjectClass>(Parent.DataType.ExportGuid);  // Parent.DataType might be from FrozenContext
     }
     return config;
 }
示例#7
0
文件: Program.cs 项目: daszat/zetbox
        private void ReloadStaging(IZetboxContext ctx)
        {
            using (Log.InfoTraceMethodCall("reloading staging"))
            {
                // TODO: use named objects
                var mp = ctx.FindPersistenceObject<MigrationProject>(MigrationProjectGUID);

                if (mp == null)
                {
                    throw new InvalidOperationException("Migrationsprojekt not found");
                }

                foreach (var stage in mp.StagingDatabases)
                {
                    ReloadStaging(stage);
                }
                Logging.MailNotification.Info("Staging Load finished");
            }
        }
示例#8
0
文件: Program.cs 项目: daszat/zetbox
        private void Prepare(IZetboxContext ctx)
        {
            var connectionString = Config.Server.GetConnectionString(Helper.ZetboxConnectionStringKey);
            dst = OpenProvider(ApplicationScope, connectionString.SchemaProvider, connectionString.ConnectionString);

            // TODO: use named objects
            var stage = ctx.FindPersistenceObject<StagingDatabase>(StagingDatabaseGUID);
            var connectionStringStage = Config.Server.GetConnectionString(stage.ConnectionStringKey);
            source = OpenProvider(ApplicationScope, connectionStringStage.SchemaProvider, connectionStringStage.ConnectionString);

            executor = ApplicationScope.Resolve<TaskFactory>().Invoke(source, dst);

            tables = stage.SourceTables.Where(t => t.DestinationObjectClass != null).ToDictionary(t => t.Name);

            // Prepare Staging Structure
            source.ExecuteSqlResource(this.GetType(), "$safeprojectname$.Scripts.CreateStagingAggregationDatabase.sql");
        }
示例#9
0
        internal static void ApplyObjectChanges(IZetboxContext ctx, IEnumerable <ObjectNotificationRequest> notificationRequests, List <BaseServerPersistenceObject> objects, Dictionary <IPersistenceObject, IPersistenceObject> entityObjects)
        {
            Logging.Log.InfoFormat(
                "ApplyObjectChanges for {0} objects and {1} notification requests called.",
                objects.Count(),
                notificationRequests.Sum(req => req.IDs.Length));

            // First of all, attach new Objects
            foreach (var obj in objects.Where(o => o.ClientObjectState == DataObjectState.New))
            {
                ctx.Internals().AttachAsNew(obj);
                entityObjects[obj] = obj;
            }

            var concurrencyFailed = new List <IDataObject>();

            // then apply changes
            foreach (var obj in objects.Where(o => o.ClientObjectState == DataObjectState.Modified))
            {
                var ctxObj = ctx.FindPersistenceObject(ctx.GetInterfaceType(obj), obj.ID);
                ((BasePersistenceObject)ctxObj).RecordNotifications();
                // optimistic concurrency
                if (obj is Zetbox.App.Base.IChangedBy)
                {
                    var orig = (Zetbox.App.Base.IChangedBy)ctxObj;
                    var send = (Zetbox.App.Base.IChangedBy)obj;
                    if (Math.Abs((orig.ChangedOn - send.ChangedOn).Ticks) > 15) // postgres is only accurate down to µs (1/1000th ms), but DateTime is accurate down to 1/10th µs. Rounding errors cause invalid concurrency failures.
                    {
                        concurrencyFailed.Add((IDataObject)obj);
                    }
                }
                ctxObj.ApplyChangesFrom(obj);
                entityObjects[ctxObj] = ctxObj;
            }

            if (concurrencyFailed.Count > 0)
            {
                throw new ConcurrencyException(concurrencyFailed);
            }

            // then update references
            foreach (var obj in objects.Where(o => o.ClientObjectState != DataObjectState.Deleted))
            {
                var ctxObj = ctx.FindPersistenceObject(ctx.GetInterfaceType(obj), obj.ID);
                ((BasePersistenceObject)ctxObj).RecordNotifications();
                ctxObj.ReloadReferences();
                entityObjects[ctxObj] = ctxObj;
            }

            // then delete objects
            foreach (var obj in objects.Where(o => o.ClientObjectState == DataObjectState.Deleted))
            {
                var ctxObj = ctx.FindPersistenceObject(ctx.GetInterfaceType(obj), obj.ID);
                ctx.Delete(ctxObj);
            }

            // Playback notifications
            foreach (var obj in entityObjects.Keys.Cast <BasePersistenceObject>())
            {
                obj.PlaybackNotifications();
            }
        }