Beispiel #1
0
        public async System.Threading.Tasks.Task <IActionResult> Index(
            System.Collections.Generic.IList <IFormFile> files)
        {
            UploaderController.s_progress = 0;
            long totalBytes = files.Sum(f => f.Length);

            foreach (IFormFile source in files)
            {
                string filename = ContentDispositionHeaderValue
                                  .Parse(source.ContentDisposition).FileName.Value.Trim('"');

                filename = this.EnsureCorrectFilename(filename);

                byte[] buffer = new byte[16 * 1024];

                using (System.IO.FileStream output = System.IO.File.Create(
                           this.GetPathAndFilename(filename)
                           ))
                {
                    using (System.IO.Stream input = source.OpenReadStream())
                    {
                        long totalReadBytes = 0;
                        int  readBytes;

                        while ((readBytes = input.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            await output.WriteAsync(buffer, 0, readBytes);

                            totalReadBytes += readBytes;
                            UploaderController.s_progress = (int)((float)totalReadBytes
                                                                  / (float)totalBytes * 100.0);

                            // It is only to make the process slower
                            await System.Threading.Tasks.Task.Delay(10);
                        } // Whend
                    }     // End Using input
                }         // End Using output
            }             // Next source

            return(this.Content("success"));
        }
        public void Receive(System.Collections.Generic.IList <SharedHealthState.StepCountEntry> list, System.Collections.Generic.IList <Stateless.Change> changeset)
        {
            var button = FindViewById <Button> (Resource.Id.stepsButton);

            button.Text = string.Format("Steps: {0}", list.Sum(s => s.Count));
        }