public async Task <List <DataPoint> > FetchData(DateTime startTime, DateTime endTime) { List <DataPoint> dataPoints = new List <DataPoint>(); // using data layer for fetching data ConfigurationManagerJSON configManager = new ConfigurationManagerJSON(); configManager.Initialize(); HistoryDataAdapter adapter = new HistoryDataAdapter(configManager); List <int> measIds = new List <int> { MeasId }; Dictionary <object, List <PMUDataStructure> > res = await adapter.GetDataAsync(startTime, endTime, measIds, true, false, 25); // check if result has one key since we queried for only one key if (res.Keys.Count == 1) { // todo check the measId also List <PMUDataStructure> dataResults = res.Values.ElementAt(0); for (int resIter = 0; resIter < dataResults.Count; resIter++) { DateTime dataTime = dataResults[resIter].TimeStamp; // convert the time from utc to local dataTime = DateTime.SpecifyKind((TimeZoneInfo.ConvertTime(dataTime, TimeZoneInfo.Utc, TimeZoneInfo.Local)), DateTimeKind.Local); DataPoint dataPoint = new DataPoint(DateTimeAxis.ToDouble(dataTime), dataResults[resIter].Value[0]); dataPoints.Add(dataPoint); } // Create dataPoints based on the fetch strategy and max Resolution dataPoints = FetchHelper.GetDataPointsWithGivenMaxSampleInterval(dataPoints, MaxResolution, SamplingStrategy, DateTimeAxis.ToDouble(startTime)); } return(dataPoints); }
public async Task GetDataAsyncTest() { try { ConfigurationManagerJSON config = new ConfigurationManagerJSON(); PspDataAdapter dataAdapter = new PspDataAdapter { ConfigurationManager = config }; string measLabel = "gujarat_thermal_mu"; DateTime fromTime = DateTime.Now.AddDays(-10); DateTime toTime = DateTime.Now.AddDays(-1); Dictionary <string, List <DataPoint> > result = await dataAdapter.GetDataAsync(fromTime, toTime, measLabel); if (result[measLabel].Count == 0) { Assert.Fail("No data was returned"); } else { if (!result[measLabel][0].Time.Day.Equals(fromTime.Day)) { Assert.Fail("Start data point date was not the requested one"); } if (!result[measLabel].Last().Time.Day.Equals(toTime.Day)) { Assert.Fail("End data point date was not the requested one"); } } } catch (Exception e) { Assert.Fail($"PSP Data adapter get async data failed by throwing error - {e.Message}"); } }
public void HistoryDataAdapterTest() { ConfigurationManagerJSON configuration; HistoryDataAdapter adapter; //constructor creation test try { configuration = new ConfigurationManagerJSON(); adapter = new HistoryDataAdapter(configuration); } catch (Exception) { Assert.Fail("PMU History Data adapter initialization by constructor failed"); } // initialization after construction test try { configuration = new ConfigurationManagerJSON(); adapter = new HistoryDataAdapter(); adapter.Initialize(configuration); } catch (Exception) { Assert.Fail("PMU History Data adapter initialization after construction failed"); } }
private void FetchAndPopulatePMUMeasurements() { // get the label objects from psp data layer ConfigurationManagerJSON configManager = new ConfigurationManagerJSON(); configManager.Initialize(); HistoryDataAdapter adapter = new HistoryDataAdapter(configManager); measXml = adapter.GetMeasXml(); // Bind the tree view with xml //SetTreeViewElements(measXml); SetMeasDataTable(); SaveMeasXml(); }
public void SaveTest() { try { // partial json also accepted as default values are taken for absent props ConfigurationManagerJSON configuration = new ConfigurationManagerJSON(); configuration.Save(); } catch (Exception) { Assert.Fail("Test failed as saving code thrown error"); } Assert.AreEqual(1, 1); }
public string GetSecurityHeader(ConfigurationManagerJSON config) { Random r = new Random(); DateTime created = DateTime.Now; string createdStr = created.ToString("yyyy-MM-ddTHH:mm:ss.fff") + "+05:30"; string nonce = Convert.ToBase64String(Encoding.ASCII.GetBytes(SHA1Encrypt(created + r.Next().ToString()))); string securityHeaderStr = "<wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + $"<wsse:UsernameToken wsu:Id = \"UsernameToken-329D41BF01D5F8E66114867472731424\">" + $"<wsse:Username>{config.UserName}</wsse:Username>" + $"<wsse:Password Type = \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">{config.Password}</wsse:Password>" + $"<wsse:Nonce EncodingType = \"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">{nonce}</wsse:Nonce>" + $"<wsu:Created>{createdStr}</wsu:Created>" + "</wsse:UsernameToken>" + "</wsse:Security>"; return(securityHeaderStr); }
private async void PopulatePspLabelsAsync() { // get the label objects from psp data layer ConfigurationManagerJSON configManager = new ConfigurationManagerJSON(); configManager.Initialize(); PspDataAdapter adapter = new PspDataAdapter { ConfigurationManager = configManager }; List <PspLabelApiItem> results = await adapter.GetMeasurementLabelsAsync(); // Bind the list view with psp label items lvMeasurements.ItemsSource = results; CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvMeasurements.ItemsSource); view.Filter = MeasurementsFilter; }
public XDocument GetMeasTree(ConfigurationManagerJSON config) { string res = ""; XDocument doc = new XDocument(); string securityHeaderStr = GetSecurityHeader(config); string bodyStr = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:dat=\"http://www.eterra.com/public/services/data/dataTypes\">" + $"<soap:Header>{securityHeaderStr}</soap:Header>" + "<soap:Body>" + "<dat:DiscoverServerRequest>?</dat:DiscoverServerRequest>" + "</soap:Body>" + "</soap:Envelope>"; var request = (HttpWebRequest)WebRequest.Create($"https://{config.Host}:{config.Port}/eterra-ws/HistoricalDataProvider"); request.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; var data = Encoding.ASCII.GetBytes(bodyStr); request.Method = "POST"; request.ContentType = "application/soap+xml; charset=\"utf-8\""; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var response = (HttpWebResponse)request.GetResponse(); res = new StreamReader(response.GetResponseStream()).ReadToEnd(); //Console.WriteLine(res); try { // extract xml from the 6th line in the response text res = res.Split('\n')[5]; doc = XDocument.Parse(res); } catch (Exception e) { Console.WriteLine($"Error in xml parsing. {e.Message}"); } return(doc); }
public void Initialize(ConfigurationManagerJSON configuration) { _Configuration = configuration; ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate; _endpointBehavior = new PhasorPointEndpointBehavior(); }
public HistoryDataAdapter(ConfigurationManagerJSON configuration) { _Configuration = configuration; ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate; _endpointBehavior = new PhasorPointEndpointBehavior(); }