public string SaveHarResult([FromBody] HarResultJsonDto json)
 {
     //var jsonSerializer = new JavaScriptSerializer();
     //var harResult = jsonSerializer.Deserialize<HarResultJsonDto>(json);
     try
     {
         HarManager manager = new HarManager();
         return(manager.SaveHarResult(json).ToString());
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Esempio n. 2
0
        public Guid SaveHarResult(HarResultJsonDto harResult)
        {
            using (var context = new RemoteWebHostingContext())
            {
                HarData harData = new HarData();
                //TODO Zach: Fix the default Date Times
                HarResult harRes = new HarResult
                {
                    Dns       = harResult.Dns,
                    Ip        = harResult.Ip,
                    NodeId    = Guid.Parse(harResult.NodeId),
                    NodeName  = harResult.NodeName,
                    Ping      = harResult.Ping,
                    TestTime  = DateTimeOffset.UtcNow,//harResult.TestTime,
                    TotalSize = harResult.TotalSize,
                    TotalTime = harResult.TotalTime,
                    HarData   = harData,
                    CreatedOn = DateTimeOffset.UtcNow
                };
                if (harResult.GeoTo != null)
                {
                    harRes.To = new Geo
                    {
                        Latitude  = harResult.GeoTo.Latitude,
                        Longitude = harResult.GeoTo.Longitude
                    };
                }
                if (harResult.GeoFrom != null)
                {
                    harRes.From = new Geo
                    {
                        Latitude  = harResult.GeoFrom.Latitude,
                        Longitude = harResult.GeoFrom.Longitude
                    };
                }

                context.HarResults.Add(harRes);
                context.HarDatas.Add(harData);
                context.SaveChanges();
                return(harData.Id);
            }
        }