Esempio n. 1
0
        public async Task GetResultAsync()
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            var nickname = await GetNicknameAsync();

            string bucketKey = nickname.ToLower() + BucketKey;

            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = oauth.access_token;

            // If old result exists remove it
            string destFile = ResultDest + ResultFile;

            if (File.Exists(destFile))
            {
                File.Delete(destFile);
            }

            // Make sure the local result directory exists before we copy the result over

            if (!Directory.Exists(ResultDest))
            {
                Directory.CreateDirectory(ResultDest);
            }

            try
            {
                Stream stream = (Stream)await objects.GetObjectAsync(bucketKey, "result.zip");

                using (FileStream fileStream = new FileStream(destFile, FileMode.CreateNew))
                {
                    stream.CopyTo(fileStream);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error uploading data set: " + e.Message);
            }
        }
Esempio n. 2
0
        public async Task RunWorkItemAsync()
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            var nickname = await GetNicknameAsync();

            string bucketKey = nickname.ToLower() + BucketKey;

            // create work item
            var wi = new WorkItem
            {
                ActivityId = await GetFullActivityId(),
                Arguments  = GetWorkItemArgs(bucketKey, ObjectName, ParamFile, ResultFile, oauth.access_token)
            };

            // run WI and wait for completion
            var status = await Client.CreateWorkItemAsync(wi);

            Console.WriteLine($"Created WI {status.Id}");
            while (status.Status == Status.Pending || status.Status == Status.Inprogress)
            {
                Console.Write(".");
                Thread.Sleep(2000);
                status = await Client.GetWorkitemStatusAsync(status.Id);
            }

            Console.WriteLine();
            Console.WriteLine($"WI {status.Id} completed with {status.Status}");
            Console.WriteLine();

            // dump report
            var client = new HttpClient();
            var report = await client.GetStringAsync(status.ReportUrl);

            var oldColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.Write(report);
            Console.ForegroundColor = oldColor;
            Console.WriteLine();
        }
Esempio n. 3
0
        public async Task UploadDataSetAsync()
        {
            dynamic oauth = await OAuthController.GetInternalAsync();

            var nickname = await GetNicknameAsync();

            string bucketKey = nickname.ToLower() + BucketKey;

            BucketsApi buckets = new BucketsApi();

            buckets.Configuration.AccessToken = oauth.access_token;
            try
            {
                var     postBuckets = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Persistent);
                dynamic result      = buckets.CreateBucket(postBuckets);
                //Console.WriteLine("bucket: " + result.ToString());
            }
            catch (Exception)
            {
                // Most likely bucket already exists, we'll just skip this error and catch any real errors on upload
            }

            ObjectsApi objects = new ObjectsApi();

            objects.Configuration.AccessToken = oauth.access_token;
            var objectName    = ObjectName;                 // string | URL-encoded object name
            var contentLength = 56;                         // int? | Indicates the size of the request body.

            System.IO.Stream body = File.OpenRead(DataSet); /// path / to / file.txt;  // System.IO.Stream |

            try
            {
                var result = objects.UploadObject(bucketKey, objectName, contentLength, body);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error uploading data set: " + e.Message);
            }
        }