Пример #1
0
 public int Execute2(SourcePawn.IPluginFunction function, int[] @params, out int result)
 {
     var handle = GCHandle.Alloc(@params, GCHandleType.Pinned);
     var ret = Execute2(function, handle.AddrOfPinnedObject(), (uint)@params.Length, out result);
     handle.Free();
     return ret;
 }
Пример #2
0
 public int CallFunction2(SourcePawn.IPluginContext ctx, int[] @params, out int result)
 {
     var handle = GCHandle.Alloc(@params, GCHandleType.Pinned);
     var ret = CallFunction2(ctx, handle.AddrOfPinnedObject(), (uint)@params.Length, out result);
     handle.Free();
     return ret;
 }
Пример #3
0
        /// <summary>
        /// Use this method to retrieve related objects of the certain <typeparam name="T"></typeparam> type. The method
        /// returns a cursor which contains pawns in storage as well as pawns currently sitting in the BLS memory
        /// </summary>
        /// <param name="filter">Optional filter to apply to the result set; the filter will be applied to both the im-memory
        /// and in-storage data</param>
        /// <param name="sortDir"></param>
        /// <param name="includeSoftDeleted">If set to true, the method ignores soft-delete flag if one is available on the
        /// pawn model. Set to false by default</param>
        /// <param name="batchSize">Controls the size of the batch of each incremental retrieval of pawns from storage. Defaults to 200 objects</param>
        /// <param name="sortProperty"></param>
        /// <returns>Cursor containing the result set</returns>
        /// <exception cref="InvalidOperationException"></exception>
        public StorageCursor <T> Find(
            Expression <Func <T, bool> > filter = null,
            Expression <Func <T, IComparable> > sortProperty = null,
            Sort sortDir            = Sort.Asc,
            bool includeSoftDeleted = false,
            int batchSize           = 200)
        {
            Connection[] connections = SourcePawn.SystemRef.ToConnect
                                       .Where(c => c.From == SourcePawn)
                                       .ToArray();

            BlGraphContainer container = SourcePawn.SystemRef.Graph.CompiledCollections
                                         .FirstOrDefault(c => c.BlContainerName == typeof(T).Name);

            if (container == null)
            {
                throw new InvalidOperationException("collection not found");
            }

            string id            = SourcePawn.GetId();
            string relationName  = SourcePawn.SystemRef.Graph.GetStorageRelationName(this);
            string containerName = SourcePawn.SystemRef.Graph.GetStorageContainerNameForPawn(SourcePawn);

            if (filter == null)
            {
                var filterExpression = SourcePawn.SystemRef
                                       .ApplySoftDeleteFilterIfApplicable(includeSoftDeleted, null, new T());

                List <T> connectedPawns = connections.Select(c => (T)c.To).ToList();

                // if there is no id, the pawn has not been saved yet so there only return in-memory relations
                if (string.IsNullOrEmpty(id))
                {
                    return(new StorageCursor <T>().AttachInMemoryPawns(connectedPawns).InjectBls(SourcePawn.SystemRef));
                }

                // otherwise, also check the storage

                string sort = SourcePawn.SystemRef.ResolveSortExpression(sortProperty);

                var cursorFromStorage =
                    SourcePawn.SystemRef.StorageProvider.GetByRelation <T>(id, relationName, containerName, filterExpression, sort, sortDir, batchSize);
                return(cursorFromStorage.AttachInMemoryPawns(connectedPawns).InjectBls(SourcePawn.SystemRef));
            }

            // the rest of the code assumes the filter is not null
            if (string.IsNullOrEmpty(id))
            {
                List <T> foundRelations = connections.Select(c => (T)c.To).ToList();
                List <T> connectedPawns = foundRelations.Where(filter.Compile()).ToList();
                return(new StorageCursor <T>().AttachInMemoryPawns(connectedPawns).InjectBls(SourcePawn.SystemRef));
            }
            else
            {
                List <T>           foundRelations          = connections.Select(c => (T)c.To).ToList();
                List <T>           connectedPawns          = foundRelations.Where(filter.Compile()).ToList();
                BlBinaryExpression storageFilterExpression = SourcePawn.SystemRef.ResolveFilterExpression(filter);

                storageFilterExpression = SourcePawn.SystemRef
                                          .ApplySoftDeleteFilterIfApplicable(includeSoftDeleted, storageFilterExpression, new T());

                string sort = SourcePawn.SystemRef.ResolveSortExpression(sortProperty);

                StorageCursor <T> cursorFromStorage =
                    SourcePawn.SystemRef.StorageProvider.GetByRelation <T>(id, relationName, containerName, storageFilterExpression, sort, sortDir, batchSize);
                return(cursorFromStorage.AttachInMemoryPawns(connectedPawns).InjectBls(SourcePawn.SystemRef));
            }
        }
Пример #4
0
 public int Execute2(SourcePawn.IPluginFunction function, int[] @params)
 {
     int result;
     return Execute2 (function, @params, out result);
 }
Пример #5
0
 public int CallFunction2(SourcePawn.IPluginContext ctx, int[] @params)
 {
     int result;
     return CallFunction2 (ctx, @params, out result);
 }
Пример #6
0
 public int CallFunction2(SourcePawn.IPluginContext ctx, out int result, params object[] @params)
 {
     return CallFunction2 (ctx, ObjectParams(@params), out result);
 }