Esempio n. 1
0
        private static void AddRowsWithPartialSuccess(SmartsheetClient smartsheet, long sheetId, Cell[] cellsToAdd)
        {
            Row row0 = new Row.AddRowBuilder(true, null, null, null, null).SetCells(cellsToAdd).Build();
            Row row1 = new Row.AddRowBuilder(true, null, null, null, null).SetCells(cellsToAdd).Build();
            BulkItemRowResult rows = smartsheet.SheetResources.RowResources.AddRowsAllowPartialSuccess(sheetId, new Row[] { row0, row1 });

            Assert.IsTrue(rows.Result.Count == 2);
        }
        /// <summary>
        /// <para>Inserts one or more rows into the Sheet specified in the URL with allowPartialSuccess.</para>
        ///
        /// <para>It mirrors to the following Smartsheet REST API method: POST /sheets/{sheetId}/rows?allowPartialSuccess=true</para>
        /// <remarks>If multiple rows are specified in the request, all rows must be inserted at the same location
        /// (i.e. the toTop, toBottom, parentId, siblingId, and above attributes must be the same for all rows in the request).</remarks>
        /// </summary>
        /// <param name="sheetId"> the sheet Id </param>
        /// <param name="rows"> one or more rows </param>
        /// <returns> the list of created Rows </returns>
        /// <exception cref="System.InvalidOperationException"> if any argument is null or empty string </exception>
        /// <exception cref="InvalidRequestException"> if there is any problem with the REST API request </exception>
        /// <exception cref="AuthorizationException"> if there is any problem with  the REST API authorization (access token) </exception>
        /// <exception cref="ResourceNotFoundException"> if the resource cannot be found </exception>
        /// <exception cref="ServiceUnavailableException"> if the REST API service is not available (possibly due to rate limiting) </exception>
        /// <exception cref="SmartsheetException"> if there is any other error during the operation </exception>
        public virtual BulkItemRowResult AddRowsAllowPartialSuccess(long sheetId, IEnumerable <Row> rows)
        {
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("allowPartialSuccess", "true");

            foreach (Row row in rows)
            {
                row.Id = null;
            }

            HttpRequest request = null;

            try
            {
                request = CreateHttpRequest(new Uri(this.Smartsheet.BaseURI, QueryUtil.GenerateUrl("sheets/" + sheetId + "/rows", parameters)), HttpMethod.POST);
            }
            catch (Exception e)
            {
                throw new SmartsheetException(e);
            }

            request.Entity = serializeToEntity <IEnumerable <Row> >(rows);

            HttpResponse response = this.Smartsheet.HttpClient.Request(request);

            BulkItemRowResult bulkItemResult = null;

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
                bulkItemResult = this.Smartsheet.JsonSerializer.deserialize <BulkItemRowResult>(response.Entity.GetContent());
                break;

            default:
                HandleError(response);
                break;
            }

            Smartsheet.HttpClient.ReleaseConnection();

            return(bulkItemResult);
        }