Exemple #1
0
        public async Task <UploadResult> UploadDataset(string filename, string datasetName)
        {
            var postResult = UploadPost(filename).Result;

            if (!postResult.Successful)
            {
                return(null);
            }

            var verifyResult = UploadVerify(postResult.Properties.Location).Result;

            if (!verifyResult.Successful)
            {
                return(null);
            }

            var upload = new DatasetUpload()
            {
                Name                = datasetName,
                UploadFormatType    = verifyResult.UploadFormatType,
                Columns             = verifyResult.Columns,
                FlatDSUpdateOptions = verifyResult.FlatDSUpdateOptions,
                FileProperty        = postResult.Properties
            };

            var result = UploadSubmit(upload).Result;

            while (UploadStatus(result.Id).Result.Status == "in progress")
            {
                await Task.Delay(5000);
            }

            return(await UploadStatus(result.Id));
        }
Exemple #2
0
 public Task <UploadResult> UploadSubmit(DatasetUpload upload)
 {
     return(ApiPost <UploadResult>("/api/1.0/upload/save", upload));
 }
Exemple #3
0
        public static void Upload(string fileName, string datasetName)
        {
            if (!File.Exists(fileName))
            {
                Console.WriteLine("Path {0} does not refer to a valid file", fileName);
                return;
            }

            var client = string.IsNullOrEmpty(token) ? new Knoema.Client(host, clientId, clientSecret) : new Knoema.Client(host, token);

            Console.WriteLine("Beginning upload process");

            Console.WriteLine("\nFile upload started");

            var postResult = client.UploadPost(fileName).Result;

            if (postResult.Successful)
            {
                Console.WriteLine("File uploaded successfully");
            }
            else
            {
                Console.WriteLine("Found following error during file upload: {0}", postResult.Error);
                return;
            }

            Console.WriteLine("\nFile verification started");

            var verifyResult = client.UploadVerify(postResult.Properties.Location).Result;

            if (verifyResult.Successful)
            {
                Console.WriteLine("File verified successfully");
            }
            else
            {
                Console.WriteLine("Found following error(s) during file verification: {0}", string.Join(",", verifyResult.ErrorList.ToArray()));
                return;
            }

            Console.WriteLine("\nProcessing file for upload");

            var dsUpload = new DatasetUpload()
            {
                Name                = datasetName,
                UploadFormatType    = verifyResult.UploadFormatType,
                Columns             = verifyResult.Columns,
                FlatDSUpdateOptions = verifyResult.FlatDSUpdateOptions,
                FileProperty        = postResult.Properties
            };

            if (verifyResult.MetadataDetails != null)
            {
                dsUpload.Description = verifyResult.MetadataDetails.Description;
                dsUpload.Source      = verifyResult.MetadataDetails.Source;
                dsUpload.Url         = verifyResult.MetadataDetails.DatasetRef;
                dsUpload.PubDate     = verifyResult.MetadataDetails.PublicationDate;
                dsUpload.AccessedOn  = verifyResult.MetadataDetails.AccessedOn;
            }

            var submitResult = client.UploadSubmit(dsUpload).Result;

            UploadResult uploadResult = null;
            var          isPending    = false;
            var          isProcessing = false;

            while (true)
            {
                uploadResult = client.UploadStatus(submitResult.Id).Result;
                if (string.Equals(uploadResult.Status, "pending"))
                {
                    if (isPending)
                    {
                        Console.Write(".");
                    }
                    else
                    {
                        Console.Write("File is queued for processing");
                        isPending = true;
                    }
                    System.Threading.Thread.Sleep(5000);                     //wait for 5 secs before polling for status again
                }
                else if (string.Equals(uploadResult.Status, "processing"))
                {
                    if (isProcessing)
                    {
                        Console.Write(".");
                    }
                    else
                    {
                        Console.Write("\nFile processing has started");
                        isProcessing = true;
                    }
                    System.Threading.Thread.Sleep(5000);                     //wait for 5 secs before polling for status again
                }
                else
                {
                    break;
                }
            }

            if (string.Equals(uploadResult.Status, "successful", StringComparison.InvariantCultureIgnoreCase))
            {
                Console.WriteLine("\nFile uploaded sucessfully");
                Console.WriteLine("You can access it url: {0}", uploadResult.Url);
            }
            else             //failed
            {
                Console.WriteLine("\nFound following error(s) while uploading file: {0}", string.Join(",", uploadResult.Errors.ToArray()));
                return;
            }

            Console.WriteLine("\nFinished upload process\n");
        }