コード例 #1
0
        public async Task <BatchRequest> AddToCurrentBatchAsync(ODataQuery <TModel> query)
        {
            // We always refresh the EntityInfo object accordingly to the current query
            EntityInfo = EntityManager.GetClassInfo <TModel>(typeof(TModel), null, this.Parent, query.Fields.ToArray());

            var batchParent = Parent;

            // In case a model can be used from different contexts (e.g. ContentType can be used from Web, but also from List)
            // it's required to let the entity know this context so that it can provide the correct information when requested
            if (batchParent != null)
            {
                // Replicate the parent object in order to keep original collection as is
                batchParent       = EntityManager.ReplicateParentHierarchy(batchParent, PnPContext);
                EntityInfo.Target = batchParent.GetType();
            }

            // and its concrete instance
            var concreteEntity = EntityManager.GetEntityConcreteInstance(typeof(TModel), batchParent);

            // Ensure the passed model has a PnPContext set
            if (concreteEntity is IDataModelWithContext d && d.PnPContext == null)
            {
                d.PnPContext = PnPContext;
            }

            // Get the parent (container) entity info
            var parentEntityInfo = EntityManager.Instance.GetStaticClassInfo(batchParent.GetType());
            // and cast it to the IDataModelMappingHandler interface
            var parentEntityWithMappingHandlers = (IDataModelMappingHandler)batchParent;

            // Build the needed API call
            ApiCallRequest apiCallRequest = await QueryClient.BuildGetAPICallAsync <TModel>(concreteEntity as BaseDataModel <TModel>, EntityInfo, query, default, false, true).ConfigureAwait(false);
コード例 #2
0
        public async Task <IList> EnsureSiteAssetsLibraryBatchAsync(Batch batch, params Expression <Func <IList, object> >[] selectors)
        {
            var assetLibrary = CreateNew() as List;

            var apiCall    = BuildEnsureSiteAssetsLibraryApiCall();
            var entityInfo = EntityManager.GetClassInfo(assetLibrary.GetType(), assetLibrary, expressions: selectors);
            var query      = await QueryClient.BuildGetAPICallAsync(assetLibrary, entityInfo, apiCall).ConfigureAwait(false);

            await assetLibrary.RequestBatchAsync(batch, new ApiCall(query.ApiCall.Request, ApiType.SPORest), HttpMethod.Post).ConfigureAwait(false);

            return(assetLibrary);
        }
コード例 #3
0
ファイル: QueryTests.cs プロジェクト: MondayCoffee/pnpcore
        private async Task <List <string> > GetAPICallTestAsync <TModel, TModelInterface>(Tuple <TModel, EntityInfo, Expression <Func <TModelInterface, object> >[]> input)
        {
            List <string> requests = new List <string>();

            // Run the basic query generation
            var apiCallRequest = await QueryClient.BuildGetAPICallAsync(input.Item1 as BaseDataModel <TModelInterface>, input.Item2, default);

            requests.Add(CleanRequestUrl((input.Item1 as IDataModelWithContext).PnPContext, apiCallRequest.ApiCall.Request));

            // Run the extra query generation (used to handle non expandable queries via a single batch)
            if (apiCallRequest.ApiCall.Type == ApiType.Graph || apiCallRequest.ApiCall.Type == ApiType.GraphBeta)
            {
                var nonExpandableRequests = await GetNonExpandableTestAsync(input);

                requests.AddRange(nonExpandableRequests);
            }

            return(requests);
        }
コード例 #4
0
#pragma warning restore CA1801  // Review unused parameters
#pragma warning restore IDE0051 // Remove unused private members
#pragma warning restore IDE0060 // Remove unused parameter

        #endregion

        #region Internal base methods for model specific extension methods

        internal static async Task <T> BaseGetAsync <T>(
            IQueryable <T> source,
            ApiCall apiCall,
            params Expression <Func <T, object> >[] selectors)
        {
            // Instantiate a new concrete entity
            var concreteEntity = (source as IManageableCollection <T>).CreateNew();

            // Grab entity information using the provided selectors
            var entityInfo = EntityManager.GetClassInfo(concreteEntity.GetType(), (concreteEntity as BaseDataModel <T>), expressions: selectors);

            // Build the default get query but pass in our given API call as override
            var query = await QueryClient.BuildGetAPICallAsync(concreteEntity as BaseDataModel <T>, entityInfo, apiCall).ConfigureAwait(false);

            // Trigger the get request
            await(concreteEntity as BaseDataModel <T>).RequestAsync(query.ApiCall, HttpMethod.Get, "Get").ConfigureAwait(false);

            // Add/update the result in the parent collection
            (source as IManageableCollection <T>).AddOrUpdate(concreteEntity, i => ((IDataModelWithKey)i).Key.Equals((concreteEntity as IDataModelWithKey).Key));

            return(concreteEntity);
        }