public void AddPowerGraphAction(PowerType powerType, DateTime startTime, DateTime endTime, string graphName) { if (powerType == null) { throw new Exception("Please choose the category"); } if (TimeHandler.DataTooBig(startTime, endTime, powerType.Interval)) { return; } startTime = TimeHandler.ConvertToLocalTime(startTime); endTime = TimeHandler.ConvertToLocalTime(endTime); try { TimeHandler.IsTimeValid(startTime, endTime); IsPlotNameValid(graphName); var series_task = Task.Run(() => Fingrid.Get(powerType, startTime, endTime)); try { series_task.Wait(); var series = series_task.Result; series.Name = graphName + " (" + powerType.Source + ")"; DataPlot.Data.Add(series); } catch (AggregateException e) { Console.WriteLine("Cannot add data to plot"); foreach (var ex in e.InnerExceptions) { Console.WriteLine(ex.Message); } throw new Exception("Cannot add data to plot"); } } catch (Exception e) { throw e; } }