private static async Task UploadItemsFromCsvAsync(string filePath)
        {
            if (_currentConnection == null)
            {
                Output.WriteLine(Output.Warning, "No connection selected. Please create a new connection or select an existing connection.");
                return;
            }

            var records = CsvDataLoader.LoadDataFromCsv(filePath);

            foreach (var part in records)
            {
                var newItem = new ExternalItem
                {
                    Id      = part.PartNumber.ToString(),
                    Content = new ExternalItemContent
                    {
                        // Need to set to null, service returns 400
                        // if @odata.type property is sent
                        ODataType = null,
                        Type      = ExternalItemContentType.Text,
                        Value     = part.Description
                    },
                    Acl = new List <Acl>
                    {
                        new Acl {
                            AccessType     = AccessType.Grant,
                            Type           = AclType.Everyone,
                            Value          = _tenantId,
                            IdentitySource = "Azure Active Directory"
                        }
                    },
                    Properties = part.AsExternalItemProperties()
                };

                try
                {
                    Output.Write(Output.Info, $"Uploading part number {part.PartNumber}...");
                    await _graphHelper.AddOrUpdateItem(_currentConnection.Id, newItem);

                    Output.WriteLine(Output.Success, "DONE");
                }
                catch (ServiceException serviceException)
                {
                    Output.WriteLine(Output.Error, "FAILED");
                    Output.WriteLine(Output.Error, $"{serviceException.StatusCode} error adding or updating part {part.PartNumber}");
                    Output.WriteLine(Output.Error, serviceException.Message);
                }
            }
        }
Beispiel #2
0
        private static async Task UploadItemsFromCsvAsync(string filePath)
        {
            var records = CsvDataLoader.LoadDataFromCsv(filePath);

            foreach (var part in records)
            {
                var newItem = new ExternalItem
                {
                    Id      = part.RowID.ToString(),
                    Content = new PayloadContent
                    {
                        Value = "<html>" + part.FileName + "</html>"
                    },
                    Acl = new List <Acl>
                    {
                        new Acl {
                            AccessType = "grant",
                            Type       = "everyone",
                            Value      = _tenantId
                        }
                    },
                    Properties = part
                };

                try
                {
                    Output.Write(Output.Info, $"Uploading part number {part.RowID}...");
                    await _graphHelper.AddOrUpdateItem(_currentConnection.Id, newItem);

                    Output.WriteLine(Output.Success, "DONE");
                }
                catch (ServiceException serviceException)
                {
                    Output.WriteLine(Output.Error, "FAILED");
                    Output.WriteLine(Output.Error, $"{serviceException.StatusCode} error adding or updating part {part.RowID}");
                    Output.WriteLine(Output.Error, serviceException.Message);
                }
            }
        }