Example #1
0
 internal void CopyRequestModules(TransientObject modelInstance)
 {
     if (modelInstance is IDataModelWithContext modelWithContext && modelWithContext.PnPContext != null && modelWithContext.PnPContext.RequestModules?.Count > 0)
     {
         RequestModules = new List <IRequestModule>(modelWithContext.PnPContext.RequestModules);
     }
 }
Example #2
0
 public HomeController(TransientObject transientObject1, TransientObject transientObject2, ScopedObject scopedObject1, ScopedObject scopedObject2, SingletonObject singletonObject1, SingletonObject singletonObject2)
 {
     this.transientObject1 = transientObject1;
     this.transientObject2 = transientObject2;
     this.scopedObject1    = scopedObject1;
     this.scopedObject2    = scopedObject2;
     this.singletonObject1 = singletonObject1;
     this.singletonObject2 = singletonObject2;
 }
Example #3
0
        internal async static Task <string> ParseApiCallAsync(TransientObject pnpObject, string apiCall)
        {
            // No tokens, so nothing to do parse
            if (!apiCall.Contains("{"))
            {
                return(apiCall);
            }

            // Parse api call to replace tokens
            return(await ParseApiRequestAsync(pnpObject as IMetadataExtensible, apiCall).ConfigureAwait(false));
        }
Example #4
0
        /// <summary>
        /// Add a new request to this <see cref="Batch"/>
        /// </summary>
        /// <param name="model">Entity object on for which this request was meant</param>
        /// <param name="entityInfo">Info about the entity object</param>
        /// <param name="method">Type of http method (GET/PATCH/POST/...)</param>
        /// <param name="apiCall">Rest/Graph call</param>
        /// <param name="backupApiCall">Backup rest api call, will be used in case we encounter a mixed batch</param>
        /// <param name="fromJsonCasting">Delegate for json type parsing</param>
        /// <param name="postMappingJson">Delegate for post mapping</param>
        /// <param name="operationName">Name of the operation, used for telemetry purposes</param>
        /// <returns>The id to created batch request</returns>
        internal Guid Add(TransientObject model, EntityInfo entityInfo, HttpMethod method, ApiCall apiCall, ApiCall backupApiCall, Func <FromJson, object> fromJsonCasting, Action <string> postMappingJson, string operationName)
        {
            // Copy the request modules list as it will get cleared at context level
            List <IRequestModule> requestModulesToUse = null;
            var requestModules = (model as IDataModelWithContext).PnPContext.RequestModules;

            if (requestModules != null)
            {
                requestModulesToUse = new List <IRequestModule>(requestModules);
            }

            return(Add(model, entityInfo, method, apiCall, backupApiCall, fromJsonCasting, postMappingJson, operationName, requestModulesToUse));
        }
Example #5
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="modelInstance">Entity object on for which this request was meant</param>
 /// <param name="entityInfo">Info about the entity object</param>
 /// <param name="method">Type of http method (GET/PATCH/POST/...)</param>
 /// <param name="apiCall">Rest call to execute</param>
 /// <param name="backupApiCall">Backup rest api call, will be used in case we encounter a mixed batch</param>
 /// <param name="fromJsonCasting">Delegate for json type parsing</param>
 /// <param name="postMappingJson">Delegate for post mapping</param>
 /// <param name="operationName">Name of the operation, used for telemetry purposes</param>
 /// <param name="order">Order of the request in the list of requests</param>
 internal BatchRequest(TransientObject modelInstance, EntityInfo entityInfo, HttpMethod method, ApiCall apiCall, ApiCall backupApiCall, Func <FromJson, object> fromJsonCasting, Action <string> postMappingJson, string operationName, int order)
 {
     Id              = Guid.NewGuid();
     Model           = modelInstance;
     EntityInfo      = entityInfo;
     Method          = method;
     ApiCall         = apiCall;
     BackupApiCall   = backupApiCall;
     FromJsonCasting = fromJsonCasting;
     PostMappingJson = postMappingJson;
     OperationName   = operationName;
     Order           = order;
     ExecutionNeeded = true;
 }
Example #6
0
        /// <summary>
        /// Add a new request to this <see cref="Batch"/>
        /// </summary>
        /// <param name="model">Entity object on for which this request was meant</param>
        /// <param name="entityInfo">Info about the entity object</param>
        /// <param name="method">Type of http method (GET/PATCH/POST/...)</param>
        /// <param name="apiCall">Rest/Graph call</param>
        /// <param name="backupApiCall">Backup rest api call, will be used in case we encounter a mixed batch</param>
        /// <param name="fromJsonCasting">Delegate for json type parsing</param>
        /// <param name="postMappingJson">Delegate for post mapping</param>
        /// <param name="operationName">Name of the operation, used for telemetry purposes</param>
        /// <returns>The id to created batch request</returns>
        internal Guid Add(TransientObject model, EntityInfo entityInfo, HttpMethod method, ApiCall apiCall, ApiCall backupApiCall, Func <FromJson, object> fromJsonCasting, Action <string> postMappingJson, string operationName)
        {
            var lastAddedRequest = GetLastRequest();
            int order            = 0;

            if (lastAddedRequest != null)
            {
                order = lastAddedRequest.Order + 1;
            }

            var batchRequest = new BatchRequest(model, entityInfo, method, apiCall, backupApiCall, fromJsonCasting, postMappingJson, operationName, order);

            Requests.Add(order, batchRequest);

            return(batchRequest.Id);
        }