public IActionResult Modify([FromBody] int watts, Guid fileId)
        {
            try{
                TSSTool.AveragePower = watts;
                var NewFilePath = Path.Combine(
                    Directory.GetCurrentDirectory(), "wwwroot", "Downloads",
                    "" + fileId.ToString() + ".fit");
                // var averagePowerMissingFTP = tss*36/ElapsedTimeLogger.Instance.ElapsedTime; //need to multiply by FTP^2 and then take the square root of that

                Boolean DecodeResult;
                Boolean result = false;

                DecodeResult = TSSTool.GetInstance().EncodeFile(
                    new FileStream(Path.Combine(
                                       Directory.GetCurrentDirectory(), "wwwroot", "Uploads",
                                       fileId.ToString()), FileMode.Open),
                    new FileStream(NewFilePath, FileMode.Create, FileAccess.ReadWrite));
                result = DecodeResult;

                return(Ok(new { result, fileId }));
            }
            catch (Exception ex) {
                var originalMessage = ex.Message;

                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(BadRequest($"{originalMessage} | {ex.Message}"));
            }
        }
Example #2
0
        public void TestDecodeWithFile()
        {
            TSSTool    tool    = TSSTool.GetInstance();
            FileStream FitFile = new FileStream("../../../Assets/TestFile-KG.fit", FileMode.Open);

            Assert.True(tool.DecodeFile(FitFile));
            FitFile.Dispose();
        }
Example #3
0
        public void TestDecodeWithFileSavesElapsedTime()
        {
            TSSTool    tool    = TSSTool.GetInstance();
            FileStream FitFile = new FileStream("../../../Assets/TestFile-KG.fit", FileMode.Open);

            Assert.True(tool.DecodeFile(FitFile));
            Assert.InRange <int>(ElapsedTimeLogger.Instance.ElapsedTime, 1, int.MaxValue);
            FitFile.Dispose();
        }
Example #4
0
        public void TestDecodeWithFileSavesHeartRate()
        {
            TSSTool    tool    = TSSTool.GetInstance();
            FileStream FitFile = new FileStream("../../../Assets/TestFile-KG.fit", FileMode.Open);

            Assert.True(tool.DecodeFile(FitFile));
            Assert.NotEmpty(HeartRateLogger.Instance.HeartRates);
            FitFile.Dispose();
        }
        public async Task <IActionResult> Upload()
        {
            try{
                var form = await Request.ReadFormAsync();

                var file = form.Files.First();
                if (file == null)
                {
                    return(null);
                }
                long size = file.Length;
                Console.WriteLine("***File Upload***");
                Console.WriteLine(file.FileName);

                var  FilePath = "";
                Guid FileId   = Guid.NewGuid();

                FilePath = Path.Combine(
                    Directory.GetCurrentDirectory(), "wwwroot", "Uploads",
                    FileId.ToString());


                Boolean DecodeResult;
                Boolean result      = false;
                int     ElapsedTime = 0;

                if (size > 0)
                {
                    using (var stream = new FileStream(FilePath, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                    DecodeResult = TSSTool.GetInstance().DecodeFile(new FileStream(FilePath, FileMode.Open));
                    ElapsedTime  = ElapsedTimeLogger.Instance.ElapsedTime;
                    result       = DecodeResult;
                }

                return(Ok(new { size, FileId, result, ElapsedTime }));
            }
            catch (Exception ex) {
                var originalMessage = ex.Message;

                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(BadRequest($"{originalMessage} | {ex.Message}"));
            }
        }
Example #6
0
        public async Task <IActionResult> Upload()
        {
            try{
                var form = await Request.ReadFormAsync();

                var file = form.Files.First();
                if (file == null)
                {
                    return(null);
                }
                long size     = file.Length;
                var  FilePath = "";

                //In test mode gotta access it based on the /bin/debug/ run location..
                if (Convert.ToBoolean(Environment.GetEnvironmentVariable("TestMode")))
                {
                    FilePath = "../../../Uploads/" + file.FileName;
                }
                else
                {
                    FilePath = "Uploads/" + file.FileName;
                }


                Boolean DecodeResult;
                Boolean result = false;

                if (size > 0)
                {
                    using (var stream = new FileStream(FilePath, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                    DecodeResult = TSSTool.GetInstance().DecodeFile(new FileStream(FilePath, FileMode.Open));
                    result       = DecodeResult;
                }

                return(Ok(new { size, FilePath, result }));
            }
            catch (Exception ex) {
                var originalMessage = ex.Message;

                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                return(BadRequest($"{originalMessage} | {ex.Message}"));
            }
        }
Example #7
0
 public void TestInit()
 {
     Assert.NotNull(TSSTool.GetInstance());
 }