/// <summary>
        /// Updates the specified PrinterShare using PATCH.
        /// </summary>
        /// <param name="printerShareToUpdate">The PrinterShare to update.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <exception cref="ClientException">Thrown when an object returned in a response is used for updating an object in Microsoft Graph.</exception>
        /// <returns>The updated PrinterShare.</returns>
        public async System.Threading.Tasks.Task <PrinterShare> UpdateAsync(PrinterShare printerShareToUpdate, CancellationToken cancellationToken)
        {
            if (printerShareToUpdate.AdditionalData != null)
            {
                if (printerShareToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    printerShareToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, printerShareToUpdate.GetType().Name)
                    });
                }
            }
            if (printerShareToUpdate.AdditionalData != null)
            {
                if (printerShareToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    printerShareToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, printerShareToUpdate.GetType().Name)
                    });
                }
            }
            this.ContentType = "application/json";
            this.Method      = "PATCH";
            var updatedEntity = await this.SendAsync <PrinterShare>(printerShareToUpdate, cancellationToken).ConfigureAwait(false);

            return(updatedEntity);
        }
        /// <summary>
        /// Creates the specified PrinterShare using POST.
        /// </summary>
        /// <param name="printerShareToCreate">The PrinterShare to create.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>The created PrinterShare.</returns>
        public async System.Threading.Tasks.Task <PrinterShare> CreateAsync(PrinterShare printerShareToCreate, CancellationToken cancellationToken)
        {
            this.ContentType = "application/json";
            this.Method      = "POST";
            var newEntity = await this.SendAsync <PrinterShare>(printerShareToCreate, cancellationToken).ConfigureAwait(false);

            return(newEntity);
        }
コード例 #3
0
        /// <summary>
        /// Adds the specified PrinterShare to the collection via POST.
        /// </summary>
        /// <param name="printerShare">The PrinterShare to add.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>The task to await.</returns>
        public System.Threading.Tasks.Task AddAsync(PrinterShare printerShare, CancellationToken cancellationToken)
        {
            this.ContentType = "application/json";
            this.Method      = "POST";

            if (string.IsNullOrEmpty(printerShare.Id))
            {
                throw new ServiceException(new Error {
                    Code = "invalidRequest", Message = "ID is required to add a reference."
                });
            }

            var requestBody = new ReferenceRequestBody {
                ODataId = string.Format("{0}/print/shares/{1}", this.Client.BaseUrl, printerShare.Id)
            };

            return(this.SendAsync(requestBody, cancellationToken));
        }
コード例 #4
0
        /// <summary>
        /// Initializes any collection properties after deserialization, like next requests for paging.
        /// </summary>
        /// <param name="printerShareToInitialize">The <see cref="PrinterShare"/> with the collection properties to initialize.</param>
        private void InitializeCollectionProperties(PrinterShare printerShareToInitialize)
        {
            if (printerShareToInitialize != null && printerShareToInitialize.AdditionalData != null)
            {
                if (printerShareToInitialize.AllowedUsers != null && printerShareToInitialize.AllowedUsers.CurrentPage != null)
                {
                    printerShareToInitialize.AllowedUsers.AdditionalData = printerShareToInitialize.AdditionalData;

                    object nextPageLink;
                    printerShareToInitialize.AdditionalData.TryGetValue("*****@*****.**", out nextPageLink);
                    var nextPageLinkString = nextPageLink as string;

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        printerShareToInitialize.AllowedUsers.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }

                if (printerShareToInitialize.AllowedGroups != null && printerShareToInitialize.AllowedGroups.CurrentPage != null)
                {
                    printerShareToInitialize.AllowedGroups.AdditionalData = printerShareToInitialize.AdditionalData;

                    object nextPageLink;
                    printerShareToInitialize.AdditionalData.TryGetValue("*****@*****.**", out nextPageLink);
                    var nextPageLinkString = nextPageLink as string;

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        printerShareToInitialize.AllowedGroups.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }
            }
        }
 /// <summary>
 /// Adds the specified PrinterShare to the collection via POST.
 /// </summary>
 /// <param name="printerShare">The PrinterShare to add.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
 /// <returns>The created PrinterShare.</returns>
 public System.Threading.Tasks.Task <PrinterShare> AddAsync(PrinterShare printerShare, CancellationToken cancellationToken)
 {
     this.ContentType = "application/json";
     this.Method      = "POST";
     return(this.SendAsync <PrinterShare>(printerShare, cancellationToken));
 }
 /// <summary>
 /// Adds the specified PrinterShare to the collection via POST.
 /// </summary>
 /// <param name="printerShare">The PrinterShare to add.</param>
 /// <returns>The created PrinterShare.</returns>
 public System.Threading.Tasks.Task <PrinterShare> AddAsync(PrinterShare printerShare)
 {
     return(this.AddAsync(printerShare, CancellationToken.None));
 }
 /// <summary>
 /// Updates the specified PrinterShare using PATCH.
 /// </summary>
 /// <param name="printerShareToUpdate">The PrinterShare to update.</param>
 /// <returns>The updated PrinterShare.</returns>
 public System.Threading.Tasks.Task <PrinterShare> UpdateAsync(PrinterShare printerShareToUpdate)
 {
     return(this.UpdateAsync(printerShareToUpdate, CancellationToken.None));
 }