public void AddDataNarrowFormatCsv() { var rnd = new System.Random(); var randomNumber = System.Convert.ToString(rnd.Next(1, 10000)); var time = new Time(); time.Zone = "GMT"; time.Identifier = "time"; time.Format = "YYYY-MM-DD HH:mm:ss"; var Signal = new Signal(); Signal.SignalIdentifier = "signal"; Signal.ValueIdentifier = "value"; var Field = new Field(); Field.Signal = Signal; Field.Time = time; var datasource = new Datasource(); datasource.Type = "PI"; datasource.Host = "https://test.piserver.com/piwebapi"; datasource.ElementTemplateName = "SampleElementTempalte"; var ds = new DatastreamRequest(); ds.Name = "TestDSPI" + randomNumber; ds.Field = Field; ds.DataSource = datasource; Datastream datastream = new Datastream(); try { datastream = _falkonry.CreateDatastream(ds); _datastreams.Add(datastream); Assert.AreEqual(ds.Name, datastream.Name); Assert.AreNotEqual(null, datastream.Id); Assert.AreEqual(ds.Field.Time.Format, datastream.Field.Time.Format); Assert.AreEqual(ds.Field.Time.Identifier, datastream.Field.Time.Identifier); Assert.AreEqual(ds.DataSource.Type, datastream.DataSource.Type); Assert.AreEqual(ds.Name, datastream.Field.EntityName); var data = "time,signal,value\n" + "2016-05-05 12:00:00,current,12.4\n2016-03-01 01:01:01,vibration,20.4"; var options = new SortedDictionary <string, string>(); options.Add("streaming", "false"); options.Add("hasMoreData", "false"); var inputstatus = _falkonry.AddInput(datastream.Id, data, options); //check data status CheckStatus(inputstatus.Id); } catch (System.Exception exception) { Assert.AreEqual(null, exception.Message, "Cannot add data"); } }
void OnCollisionEnter(Collision col) { Datastream stream = Datastream.cur; if (Datastream.enableFirewall) { damage = Mathf.CeilToInt((float)damage * 0.1f); } Datastream.healthAmount -= damage; stream.EmitCorruptionParticles(transform.position, damage / 10f); gameObject.SetActive(false); OnDeath(); SplitterEnemySplit split = GetComponent <SplitterEnemySplit>(); if (split) { for (int i = 0; i < split.spawnPos.Length; i++) { EnemyManager.cur.OnEnemyDeath(); } } }
/// <summary> /// Returns an aray of bytes from the specified offset /// </summary> /// <param name="Offset">Start offset</param> /// <param name="Length">Number of bytes to return</param> /// <returns></returns> public byte[] GetBytes(long Offset, int Length) { byte[] data = new byte[Length]; Datastream.Seek(Offset, SeekOrigin.Begin); Datastream.Read(data, 0, Length); return(data); }
// Cannot add historical input data(csv format) to Datastream with time identifier missing public void AddDataCsvMissingTimeIdentifier() { var rnd = new System.Random(); var randomNumber = System.Convert.ToString(rnd.Next(1, 10000)); var time = new Time(); time.Zone = "GMT"; time.Identifier = "timestamp"; time.Format = "iso_8601"; var Field = new Field(); Field.Time = time; Field.EntityIdentifier = "signal"; var datasource = new Datasource(); datasource.Type = "PI"; datasource.Host = "https://test.piserver.com/piwebapi"; datasource.ElementTemplateName = "SampleElementTempalte"; var ds = new DatastreamRequest(); ds.Name = "Test " + randomNumber; ds.Field = Field; ds.DataSource = datasource; Datastream datastream = new Datastream(); try { datastream = _falkonry.CreateDatastream(ds); _datastreams.Add(datastream); Assert.AreEqual(ds.Name, datastream.Name); Assert.AreNotEqual(null, datastream.Id); Assert.AreEqual(ds.Field.Time.Format, datastream.Field.Time.Format); Assert.AreEqual(ds.Field.Time.Identifier, datastream.Field.Time.Identifier); Assert.AreEqual(ds.DataSource.Type, datastream.DataSource.Type); var data = "timestamp,signal,value\n" + "2016-05-05 12:00:00,current,12.4\n2016-03-01 01:01:01,vibration,20.4"; SortedDictionary <string, string> options = new SortedDictionary <string, string>(); options.Add("timeZone", "GMT"); options.Add("timeFormat", "YYYY-MM-DD HH:mm:ss"); options.Add("fileFormat", "csv"); options.Add("streaming", "false"); options.Add("hasMoreData", "false"); options.Add("signalIdentifier", "signal"); options.Add("valueIdentifier", "value"); var inputstatus = _falkonry.AddInput(datastream.Id, data, options); Assert.AreEqual(true, false, "No error message for missing time identifier"); } catch (System.Exception exception) { Assert.AreEqual(exception.Message, "Missing time identifier.", "Incorrect error message for missing time identifier"); } }
/* * Adds Historical data to an existing datastream. */ /// <summary> /// Adds Historical data to an existing datastream. /// </summary> /// <exception cref="System.ArgumentNullException">Thrown when one parameter is missing /// in the function call.</exception> /// <exception cref="FalkonryClient.Service.FalkonryException">Thrown when there is a request timeout.</exception> /// <exception cref="System.Exception">Thrown when any other error causes /// the program to not add historical data.</exception> /// <param name="datastreamId">A String that contains the ID of existing datastream /// in which the historical data is supposed to be added.</param> /// <param name="stream">A byte array received from file-adapter's GetStream() method.</param> /// <param name="fileType">A String that specifies the file type i.e CSV/JSON.</param> public void IngestDataFromFile(String datastreamId, byte[] stream, String fileType) { if (fileType == null || datastreamId == null || stream == null) { throw new ArgumentNullException(nameof(fileType)); } int i; Datastream datastream = falkonry.GetDatastream(datastreamId); var options = new SortedDictionary <string, string>(); var inputStatus = new InputStatus(); options.Add("streaming", "false"); options.Add("hasMoreData", "false"); options.Add("timeIdentifier", datastream.Field.Time.Identifier.ToString()); options.Add("timeZone", datastream.Field.Time.Zone.ToString()); options.Add("timeFormat", datastream.Field.Time.Format.ToString()); options.Add("entityIdentifier", datastream.Field.EntityIdentifier.ToString()); options.Add("fileFormat", fileType); // TODO: Uncomment these 2 lines out for Narrow Datastream Format. //options.Add("signalIdentifier", datastream.Field.Signal.SignalIdentifier.ToString()); //options.Add("valueIdentifier", datastream.Field.Signal.ValueIdentifier.ToString()); // TODO: Uncomment this line out for Batch Datastream Format. //options.Add("batchIdentifier", datastream.Field.BatchIdentifier.ToString()); for (i = 0; i < 3; i++) { try { inputStatus = falkonry.AddInputStream(datastreamId, stream, options); if (CheckStatus(inputStatus.Id) == 1) { break; } } catch (FalkonryClient.Service.FalkonryException e) { log.Error(e.GetBaseException() + "\n"); Console.ReadKey(); Environment.Exit(1); } catch (Exception ex) { log.WarnFormat(ex.StackTrace + " \n" + ex.Message + "\n" + "Retry Attempt: {0}", i + 1); } } if (i == 3) { log.Error("Cannot add data to the datastream!"); Console.ReadKey(); Environment.Exit(1); } }
XmlNode MakeDatastreamXML(Datastream ds, XmlDocument doc) { XmlElement nDS = doc.CreateElement ("data", doc.DocumentElement.NamespaceURI); nDS.SetAttribute ("id", ds.id); nDS.AppendChild (UtilSimpleTextNode (doc, "current_value", ds.currentValue)); foreach (String tag in ds.tags) { nDS.AppendChild (UtilSimpleTextNode (doc, "tag", tag)); } return nDS; }
public List <EntityMeta> GetEntityMeta(Datastream datastream) { try { return(_falkonryService.GetEntityMeta(datastream)); } catch (Exception) { throw; } }
// Get EntityMeta public List <EntityMeta> GetEntityMeta(Datastream datastream) { try { var response = _http.Get("/datastream/" + datastream.Id + "/entityMeta"); return(JsonConvert.DeserializeObject <List <EntityMeta> >(response)); } catch (Exception) { throw; } }
/// <summary> /// This method exports the facts from a particular assessment to a file. /// </summary> /// <param name="datastreamId">A String that contains the ID of existing datastream /// from which the facts are exported.</param> /// <param name="assessmentId">A String that contains the ID of existing assessment /// from which the facts are exported.</param> public void ExportFacts(String datastreamId, String assessmentId) { Datastream datastream = falkonry.GetDatastream(datastreamId); String path = "..\\examples\\bin\\Debug\\facts"; String fileName = datastream.Name + "_" + DateTime.Now.ToString().Replace(":", "-") + ".json"; StreamWriter sw = File.CreateText(Path.Combine(path, fileName)); var options = new SortedDictionary <string, string>(); options.Add("responseFormat", "application/json"); var factsData = falkonry.getFacts(assessmentId, options); sw.Write(factsData.Response); sw.Close(); log.Info("Facts export successful"); }
/* * Adding live data to an existing datastream. (As a String) */ /// <summary> /// Adding live data to an existing datastream. /// </summary> /// <exception cref="System.ArgumentNullException">Thrown when one parameter is missing /// in the function call.</exception> /// <exception cref="FalkonryClient.Service.FalkonryException">Generally thrown when a 100 second timeout /// is met.</exception> /// <exception cref="System.Exception">Thrown when any other error causes /// the program to not add live data.</exception> /// <param name="datastreamId">A String that contains the ID of existing datastream /// in which the live data is supposed to be ingested.</param> /// <param name="stream">A String received from file-adapter's GetData() method.</param> /// <param name="fileType">A String that specifies the file type i.e CSV/JSON.</param> public void IngestData(String datastreamId, String stream, String fileType) { if (fileType == null || datastreamId == null || stream == null) { throw new ArgumentNullException(nameof(fileType)); } Datastream datastream = falkonry.GetDatastream(datastreamId); var options = new SortedDictionary <string, string>(); var inputStatus = new InputStatus(); options.Add("streaming", "true"); options.Add("hasMoreData", "false"); options.Add("timeIdentifier", datastream.Field.Time.Identifier.ToString()); options.Add("timeZone", datastream.Field.Time.Zone.ToString()); options.Add("timeFormat", datastream.Field.Time.Format.ToString()); options.Add("entityIdentifier", datastream.Field.EntityIdentifier.ToString()); options.Add("fileFormat", fileType); // TODO: Uncomment these 2 lines out for Narrow Datastream Format. //options.Add("signalIdentifier", datastream.Field.Signal.SignalIdentifier.ToString()); //options.Add("valueIdentifier", datastream.Field.Signal.ValueIdentifier.ToString()); // TODO: Uncomment this line out for Batch Datastream Format. //options.Add("batchIdentifier", datastream.Field.BatchIdentifier.ToString()); try { inputStatus = falkonry.AddInput(datastreamId, stream, options); log.Info(inputStatus.Status + " - " + inputStatus.Message + "\n"); } catch (FalkonryClient.Service.FalkonryException e) { log.Error(e.GetBaseException() + "\n"); Console.ReadKey(); Environment.Exit(1); } catch (Exception ex) { log.Error(ex.GetBaseException() + "\n"); Console.ReadKey(); Environment.Exit(1); } }
public void TestGolomb() { var data = new Datastream(); for (var i = 0U; i < 1000; ++i) { data.Add(i); } var last = UInt32.MaxValue; for (var m = 1U; m < 1000; ++m) { var g = new GolombCodec(); g.Options &= ~GolombCodec.OptionFlags.Optimize; g.Parameter = m; var bs = g.CompressToStream(data, Header.HeaderFlags.None); var len = bs.Length; var dir = len < last ? -1 : len == last ? 0 : 1; WriteLine($"{m,3}: {bs.Length} {dir}"); last = len; } }
public void GetDatastreamByIdTest() { var time = new Time(); time.Zone = "GMT"; time.Identifier = "Time"; time.Format = "iso_8601"; var datasource = new Datasource(); datasource.Type = "STANDALONE"; var rnd = new System.Random(); var randomNumber = System.Convert.ToString(rnd.Next(1, 10000)); var ds = new DatastreamRequest(); ds.Name = "TestDS" + randomNumber; var Field = new Field(); Field.Time = time; ds.Field = Field; ds.DataSource = datasource; try { var datastream = _falkonry.CreateDatastream(ds); _datastreams.Add(datastream); Assert.AreEqual(ds.Name, datastream.Name); Assert.AreNotEqual(null, datastream.Id); // get datastream by id Datastream datastreamFetched = _falkonry.GetDatastream(datastream.Id); Assert.AreEqual(ds.Name, datastreamFetched.Name); Assert.AreNotEqual(null, datastreamFetched.Id); } catch (System.Exception exception) { Assert.AreEqual(exception.Message, null, "Error retrieving datastream by id"); } }
/* * Creates a new datastream on the Merlin. */ /// <summary> /// Creates a new datastream on the Merlin. /// </summary> /// <returns> /// The ID of the datastream created. /// </returns> public String CreateDataStream() { String datastreamName = "C#_TEST_7"; String timeZone = "GMT"; String timeIdentifier = "time"; String timeFormat = "millis"; String PrecisionFormat = "millis"; String entityIdentifier = "entity"; time.Format = timeFormat; time.Zone = timeZone; time.Identifier = timeIdentifier; ds.TimePrecision = PrecisionFormat; dataSource.Type = "PI"; ds.DataSource = dataSource; ds.Name = datastreamName; ds.Field = field; ds.Field.Time = time; ds.Field.Signal = signal; ds.Field.EntityIdentifier = entityIdentifier; // ### USE THIS IF YOUR DATA IS IN NARROW FORMAT ### // TODO: Uncomment these 2 lines out for Narrow Datastream Format. //String signalIdentifier = "signal"; //String valueIdentifier = "value"; //ds.Field.Signal.SignalIdentifier = signalIdentifier; //ds.Field.Signal.ValueIdentifier = valueIdentifier; // ### USE THIS IF YOU HAVE BATCH DATA ### // TODO: Uncomment this line out for Batch window type. //String batchIdentifier = "batch_id"; //ds.Field.BatchIdentifier = batchIdentifier; Datastream datastream = falkonry.CreateDatastream(ds); log.InfoFormat("New Datastream with id {0} created. \n", datastream.Id); return(datastream.Id); }
//TODO: handle parse exceptions (missing attrs, nodes, unexpected types (e.g. non-integer env id, bad timestamp, etc) //TODO: split datastream parsing so we can do that without an env. public Environment Parse(XmlDocument doc, XmlNamespaceManager nsman) { Environment e = new Environment (); XmlNode nEnv = doc.SelectSingleNode ("ns:eeml/ns:environment", nsman); if (nEnv == null) { throw new MissingNodeException ("eeml/environment"); } e.id = UtilAttribOrFail (nEnv, "id", "environment"); e.title = UtilSingleTextNodeContentOr (nEnv, "ns:title", nsman, ""); e.website = UtilSingleTextNodeContentOr (nEnv, "ns:website", nsman, ""); e.feed = UtilSingleTextNodeContentOr (nEnv, "ns:feed", nsman, ""); e.description = UtilSingleTextNodeContentOr (nEnv, "ns:description", nsman, ""); e.isPrivate = UtilSingleTextNodeContentOr (nEnv, "ns:private", nsman, ""); e.status = UtilSingleTextNodeContentOr (nEnv, "ns:status", nsman, ""); // TODO: bail on missing status? foreach (XmlNode tagNode in nEnv.SelectNodes ("ns:tag", nsman)) { e.tags.Add (tagNode.InnerText); } //parse the location XmlNode nLoc = nEnv.SelectSingleNode ("ns:location", nsman); if (nLoc != null) { Location loc = new Location (); loc.name = UtilSingleTextNodeContentOr (nLoc, "ns:name", nsman, ""); loc.latitude = UtilSingleTextNodeContentOr (nLoc, "ns:lat", nsman, ""); loc.longitude = UtilSingleTextNodeContentOr (nLoc, "ns:lon", nsman, ""); loc.elevation = UtilSingleTextNodeContentOr (nLoc, "ns:ele", nsman, ""); loc.domain = UtilAttribOr (nLoc, "domain", ""); loc.exposure = UtilAttribOr (nLoc, "exposure", ""); loc.disposition = UtilAttribOr (nLoc, "disposition", ""); e.location = loc; } //Loop through any datastreams foreach (XmlNode nDS in nEnv.SelectNodes ("ns:data", nsman)) { Datastream ds = new Datastream (); ds.id = UtilAttribOrFail (nDS, "id", "data"); XmlNode nDSCurrentVal = nDS.SelectSingleNode ("ns:current_value", nsman); if (nDSCurrentVal != null) { ds.currentValue = nDSCurrentVal.InnerText; ds.currentValueTimestamp = UtilAttribOr (nDSCurrentVal, "at", ""); //TODO: parse timestamp? } ds.minValue = UtilSingleTextNodeContentOr (nDS, "ns:min_value", nsman, ""); ds.maxValue = UtilSingleTextNodeContentOr (nDS, "ns:max_value", nsman, ""); foreach (XmlNode tagNode in nDS.SelectNodes ("ns:tag", nsman)) { ds.tags.Add (tagNode.InnerText); } //Loop through any datapoints in the current datastream foreach (XmlNode nDP in nDS.SelectNodes ("ns:datapoints/ns:value", nsman)) { //Warning: potentially too much object instantiation, with long histories. //Perhaps tuples better, or a matrix. DataPoint dp = new DataPoint (); dp.value = nDP.InnerText; dp.timestamp = UtilAttribOrFail (nDP, "at", "value"); ds.dataPoints.Add (dp); } e.datastreams.Add (ds); } return e; }
public void CannotAddDataMissingBatch() { var rnd = new System.Random(); var randomNumber = System.Convert.ToString(rnd.Next(1, 10000)); var ds = new DatastreamRequest(); var time = new Time(); time.Zone = "GMT"; time.Identifier = "time"; time.Format = "iso_8601"; ds.Name = "TestDSCSV" + randomNumber; var Field = new Field(); Field.EntityIdentifier = "Unit"; Field.BatchIdentifier = "batch"; Field.Time = time; ds.Field = Field; var datasource = new Datasource(); datasource.Type = "PI"; datasource.Host = "https://test.piserver.com/piwebapi"; datasource.ElementTemplateName = "SampleElementTempalte"; ds.DataSource = datasource; // Input List var inputList = new List <Input>(); var currents = new Input(); currents.Name = "current"; currents.ValueType = new ValueType(); currents.EventType = new EventType(); currents.ValueType.Type = "Numeric"; currents.EventType.Type = "Samples"; inputList.Add(currents); var vibration = new Input(); vibration.Name = "vibration"; vibration.ValueType = new ValueType(); vibration.EventType = new EventType(); vibration.ValueType.Type = "Numeric"; vibration.EventType.Type = "Samples"; inputList.Add(vibration); var state = new Input(); state.Name = "state"; state.ValueType = new ValueType(); state.EventType = new EventType(); state.ValueType.Type = "Categorical"; state.EventType.Type = "Samples"; inputList.Add(state); ds.InputList = inputList; Datastream datastream = new Datastream(); try { datastream = _falkonry.CreateDatastream(ds); _datastreams.Add(datastream); Assert.AreEqual(ds.Name, datastream.Name); Assert.AreNotEqual(null, datastream.Id); Assert.AreEqual(ds.Field.Time.Format, datastream.Field.Time.Format); Assert.AreEqual(ds.Field.Time.Identifier, datastream.Field.Time.Identifier); Assert.AreEqual(ds.DataSource.Type, datastream.DataSource.Type); var data = "time,Unit,current,vibration,state,batch_changed\n 2016-05-05T12:00:00.000Z,Unit1,12.4,3.4,On,batch1"; var options = new SortedDictionary <string, string>(); options.Add("timeIdentifier", "time"); options.Add("timeFormat", "iso_8601"); options.Add("timeZone", time.Zone); options.Add("streaming", "false"); options.Add("hasMoreData", "false"); options.Add("entityIdentifier", "Unit"); var inputstatus = _falkonry.AddInput(datastream.Id, data, options); Assert.AreEqual(true, false, "No exception in case of missing entity Identifier"); } catch (System.Exception exception) { Assert.AreEqual(exception.Message, "Missing batch identifier", "Incorrect error message for missing entity identifier"); } }
public ObjDigital GetStructureForPid(string pid, string originalTimestamp, bool loadVersions) { XmlDocument metsDoc; XmlDocument dcDoc; XmlNamespaceManager nameSpaceManager; XmlNamespaceManager dcNameSpaceManager; string versionTimestamp = null; try { versionTimestamp = manager.getDatastream(pid, "METS", originalTimestamp).createDate; MIMETypedStream stream = service.getDatastreamDissemination(pid, "METS", originalTimestamp); metsDoc = GetXmlFromStream(stream); nameSpaceManager = new XmlNamespaceManager(metsDoc.NameTable); nameSpaceManager.AddNamespace("mets", "http://www.loc.gov/METS/"); nameSpaceManager.AddNamespace("xlink", "http://www.w3.org/TR/xlink/"); // Temos de pedir o DC mais próximo da versão mais actualizada do METS (logo passamos o versionTimestamp) MIMETypedStream dcStream = service.getDatastreamDissemination(pid, "DC", versionTimestamp); dcDoc = GetXmlFromStream(dcStream); dcNameSpaceManager = new XmlNamespaceManager(dcDoc.NameTable); dcNameSpaceManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); dcNameSpaceManager.AddNamespace("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/"); dcNameSpaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); } catch (Exception ex) { throw new Exception("Datastreams METS e/ou DC inválidos para o objecto " + pid + ".", ex); } try { XmlNode structMap = metsDoc.SelectSingleNode("mets:mets/mets:structMap", nameSpaceManager); XmlNode mainDiv = structMap.SelectSingleNode("mets:div", nameSpaceManager); XmlNode recordID = metsDoc.SelectSingleNode("mets:mets/mets:metsHdr/mets:altRecordID", nameSpaceManager); string type; try { type = structMap.Attributes["TYPE"].Value.ToString().ToUpper(); } catch { type = "PHYSICAL"; } ObjDigital newDocumentType = null; if (type == "LOGICAL") { newDocumentType = new ObjDigComposto(); newDocumentType.state = State.unchanged; newDocumentType.serverState = GetState(pid); ObjDigSimples[] parts = new ObjDigSimples[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count]; foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager)) { // Ler objecto directamente XmlNode fptr = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager); ObjDigSimples objSimples = GetStructureForPid(fptr.Attributes["FILEID"].Value, originalTimestamp, true) as ObjDigSimples; parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = objSimples; } ((ObjDigComposto)newDocumentType).objSimples.AddRange(parts); } else { newDocumentType = new ObjDigSimples(); newDocumentType.state = State.unchanged; newDocumentType.serverState = GetState(pid); Anexo[] parts = new Anexo[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count]; foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager)) { XmlNode fptr = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager); Anexo anexo = new Anexo(); anexo.pid = pid; anexo.dataStreamID = fptr.Attributes["FILEID"].Value; anexo.mimeType = subDiv.Attributes["TYPE"].Value; parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = anexo; try { Datastream data = manager.getDatastream(pid, anexo.dataStreamID, null); anexo.url = data.location; anexo.checksum = data.checksum; } catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("URL de datastream " + anexo.dataStreamID + " no objecto " + pid + " não foi encontrado.", ex); } } ((ObjDigSimples)newDocumentType).nextDatastreamId = service.listDatastreams(pid, null).Count(ds => ds.ID.Contains("IMG")) + 1; ((ObjDigSimples)newDocumentType).fich_associados.AddRange(parts); if (loadVersions) { ((ObjDigSimples)newDocumentType).historico.AddRange(GetHistoric(pid)); } } newDocumentType.pid = pid; newDocumentType.version = versionTimestamp; newDocumentType.titulo = mainDiv.Attributes["LABEL"].Value; if (mainDiv.Attributes["TYPE"] != null) { newDocumentType.tipologia = mainDiv.Attributes["TYPE"].Value; } if (recordID != null) // há objetos que não têm gisa_id { newDocumentType.gisa_id = recordID.InnerText; } else { newDocumentType.gisa_id = ""; } XmlNodeList assuntos = dcDoc.SelectNodes("oai_dc:dc/dc:subject", dcNameSpaceManager); if (assuntos.Count > 0) { List <string> listAssuntos = new List <string>(); foreach (XmlNode node in assuntos) { listAssuntos.Add(node.InnerText); } newDocumentType.assuntos = listAssuntos; } return(newDocumentType); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("Erro ao analisar objecto " + pid + ".", ex); } }
public void AddDataWideFormatJsonBatch() { var rnd = new System.Random(); var randomNumber = System.Convert.ToString(rnd.Next(1, 10000)); var time = new Time(); time.Zone = "GMT"; time.Identifier = "time"; time.Format = "YYYY-MM-DD HH:mm:ss"; var Field = new Field(); Field.Time = time; Field.BatchIdentifier = "batch"; var datasource = new Datasource(); datasource.Type = "PI"; datasource.Host = "https://test.piserver.com/piwebapi"; datasource.ElementTemplateName = "SampleElementTempalte"; var ds = new DatastreamRequest(); ds.Name = "TestDSJSON" + randomNumber; ds.Field = Field; ds.DataSource = datasource; // Input List var inputList = new List <Input>(); var currents = new Input(); currents.Name = "current"; currents.ValueType = new ValueType(); currents.EventType = new EventType(); currents.ValueType.Type = "Numeric"; currents.EventType.Type = "Samples"; inputList.Add(currents); var vibration = new Input(); vibration.Name = "vibration"; vibration.ValueType = new ValueType(); vibration.EventType = new EventType(); vibration.ValueType.Type = "Numeric"; vibration.EventType.Type = "Samples"; inputList.Add(vibration); var state = new Input(); state.Name = "state"; state.ValueType = new ValueType(); state.EventType = new EventType(); state.ValueType.Type = "Categorical"; state.EventType.Type = "Samples"; inputList.Add(state); ds.InputList = inputList; Datastream datastream = new Datastream(); try { datastream = _falkonry.CreateDatastream(ds); _datastreams.Add(datastream); Assert.AreEqual(ds.Name, datastream.Name); Assert.AreNotEqual(null, datastream.Id); Assert.AreEqual(ds.Field.Time.Format, datastream.Field.Time.Format); Assert.AreEqual(ds.Field.Time.Identifier, datastream.Field.Time.Identifier); Assert.AreEqual(ds.DataSource.Type, datastream.DataSource.Type); Assert.AreEqual(ds.Name, datastream.Field.EntityName); var data = "{\"time\" :\"2016-03-01 01:01:01\", \"current\" : 12.4, \"vibration\" : 3.4, \"state\" : \"On\", \"batch\" : \"batch1\"}"; var options = new SortedDictionary <string, string>(); options.Add("streaming", "false"); options.Add("hasMoreData", "false"); var inputstatus = _falkonry.AddInput(datastream.Id, data, options); //check data status CheckStatus(inputstatus.Id); } catch (System.Exception exception) { Assert.AreEqual(exception.Message, null, "Cannot add data"); } }
void Start() { cur = this; }
//Esta funcion realiza una parser del objeto JSON al objeto ClienteXively //Esto permite manipular los metadatos de los sensores via código. //Posteriormente como el objeto se almacena en disco como json, se puede recuperar //directamente con el API json public FeedXively ParserJSON(JObject jsonresults) { try { //Variable en la cual obtendremos los metadatos del feed recuperado FeedXively tempFeed = new FeedXively(); //Obtenemos las propiedades de ubicación del feed en el sistema tempFeed.pathfeed = rutaDocumentos + (string)jsonresults["id"] + ".json"; //Obtener el url del feed //Uri url = new Uri((string)jsonresults["feed"]); tempFeed.feed.feed = jsonresults["feed"].ToString(); //Obtener el id del feed y demás metadatos obligatorios tempFeed.feed.id = jsonresults["id"].ToString(); tempFeed.feed.created = (string)jsonresults["created"]; //Uri urlcreator = new Uri((string)jsonresults["creator"]); tempFeed.feed.creator = jsonresults["creator"].ToString(); tempFeed.feed.Private = Convert.ToBoolean((string)jsonresults["private"]); //Obtner los metadatos no obligatorios if (!(jsonresults["auto_feed_url"] == null)) { tempFeed.feed.feed = jsonresults["auto_feed_url"].ToString(); } if (!(jsonresults["description"] == null)) { tempFeed.feed.description = (string)jsonresults["description"]; } if (!(jsonresults["title"] == null)) { tempFeed.feed.title = (string)jsonresults["title"]; } if (!(jsonresults["updated"] == null)) { tempFeed.feed.updated = (string)jsonresults["updated"]; } if (!(jsonresults["website"] == null)) { //Uri urlwebsite = new Uri((string)jsonresults["website"]); tempFeed.feed.website = jsonresults["website"].ToString(); } if (!(jsonresults["tags"] == null)) { //Almacena los tags de todo el feed List <string> tempst = JsonConvert.DeserializeObject <List <string> >(jsonresults["tags"].ToString()); tempFeed.feed.tags = new string[tempst.Count]; int j = 0; foreach (string temps in tempst) { tempFeed.feed.tags[j] = temps; j++; } } if (!(jsonresults["location"] == null)) { tempFeed.feed.location = new Location(); if (!(jsonresults["location"]["name"] == null)) { tempFeed.feed.location.name = (string)jsonresults["location"]["name"]; } if (!(jsonresults["location"]["lat"] == null)) { tempFeed.feed.location.lat = (string)jsonresults["location"]["lat"]; } if (!(jsonresults["location"]["lon"] == null)) { tempFeed.feed.location.lon = (string)jsonresults["location"]["lon"]; } if (!(jsonresults["location"]["ele"] == null)) { tempFeed.feed.location.ele = (string)jsonresults["location"]["ele"]; } if (!(jsonresults["location"]["exposure"] == null)) { tempFeed.feed.location.exposure = (Exposure)Enum.Parse(typeof(Exposure), (string)jsonresults["location"]["exposure"]); } if (!(jsonresults["location"]["disposition"] == null)) { tempFeed.feed.location.disposition = (Disposition)Enum.Parse(typeof(Disposition), (string)jsonresults["location"]["disposition"]); } if (!(jsonresults["location"]["domain"] == null)) { tempFeed.feed.location.domain = (Domain)Enum.Parse(typeof(Domain), (string)jsonresults["location"]["domain"]); } } tempFeed.feed.status = (Status)Enum.Parse(typeof(Status), (string)jsonresults["status"]); //En caso de traer el summary estos objetos son nulos if (!(jsonresults["datastreams"] == null)) { //Datastream dtfeed = new Datastream(); tempFeed.feed.datastreams = new Datastream[jsonresults["datastreams"].Count()]; int dtscount = 0; foreach (JObject obj3 in jsonresults["datastreams"]) { Datastream dtfeed = new Datastream(); dtfeed.id = (string)obj3["id"]; if (!(obj3["at"] == null)) { dtfeed.at = (string)obj3["at"]; } //Si hay un valor actual, tambien hay min_value y max_value if (!(obj3["current_value"] == null)) { dtfeed.current_value = (string)obj3["current_value"]; dtfeed.max_value = (string)obj3["max_value"]; dtfeed.min_value = (string)obj3["min_value"]; } if (!(obj3["tags"] == null)) { List <string> tempstr = JsonConvert.DeserializeObject <List <string> >(obj3["tags"].ToString()); dtfeed.tags = new string[tempstr.Count]; int i = 0; foreach (string temps in tempstr) { dtfeed.tags[i] = temps; i++; } } Unit unidad = new Unit(); if (!(obj3["unit"] == null)) { if (!(obj3["unit"]["symbol"] == null)) { unidad.symbol = (string)obj3["unit"]["symbol"]; } if (!(obj3["unit"]["label"] == null)) { unidad.label = (string)obj3["unit"]["label"]; } if (!(obj3["unit"]["unitType"] == null)) { unidad.unitType = (IFCClassification)Enum.Parse(typeof(IFCClassification), (string)obj3["unit"]["unitType"]); } } dtfeed.unit = unidad; //Almacenando Datapoints if (!(obj3["datapoints"] == null)) { dtfeed.datapoints = new Datapoint[obj3["datapoints"].Count()]; int dtpcount = 0; foreach (JObject obj4 in obj3["datapoints"]) { Datapoint dtp = new Datapoint(); if (!(obj4["at"] == null)) { dtp.at = (string)obj4["at"]; dtp.value = (string)obj4["value"]; } dtfeed.datapoints[dtpcount] = dtp; dtpcount++; } } //Agregamos el datastream a la lista de datastream del feed tempFeed.feed.datastreams[dtscount] = dtfeed; dtscount++; } } return(tempFeed); } catch (Exception ex) { throw new System.ArgumentException("Parameter cannot be null: " + ex.ToString(), "original"); } }
static void Main() { Console.WriteLine("Sample console app for SensorThings API client"); var server = "http://scratchpad.sensorup.com/OGCSensorThings/v1.0/"; var client = new SensorThingsClient(server); Console.WriteLine("Create observation for datastream 18"); var datastream = new Datastream { Id = "263" }; var observation = new Observation { Datastream = datastream, PhenomenonTime = new DateTimeRange(DateTime.UtcNow), Result = 100 }; // do not create observations for now _ = client.CreateObservation(observation).Result; Console.WriteLine("Retrieve all paged datastreams..."); var response = client.GetDatastreamCollection().Result; var page = response.Result; var pagenumber = 1; while (page != null) { Console.WriteLine("---------------------------------------"); WritePage(response.Result); var pageResponse = page.GetNextPage().Result; page = pageResponse?.Result; pagenumber++; } Console.WriteLine("End retrieving datastreams..."); Console.WriteLine("Number of pages: " + pagenumber); var datastreamResponse = client.GetDatastream("263").Result; datastream = datastreamResponse.Result; var observationsResponse = datastream.GetObservations(client).Result; var observations = observationsResponse.Result; Console.WriteLine("Number if observations: " + observations.Count); Console.WriteLine("Sample with locations"); var locationsResponse = client.GetLocationCollection().Result; var locations = locationsResponse.Result; // Get location without using GeoJSON.NET (works only for points) var firstlocation = locations.Items[0]; var feature = (JObject)firstlocation.Feature; var lon = feature.First.First.First.Value <double>(); var lat = feature.First.First.Last.Value <double>(); Console.WriteLine($"Location: {lon},{lat}"); // if using GeoJSON.NET use something like: // var p = JsonConvert.DeserializeObject<Point>(feature.ToString()); // var ipoint = (GeographicPosition)p.Coordinates; // Console.WriteLine("Location: " + ipoint.Longitude + ", " + ipoint.Latitude); Console.WriteLine("Program ends... Press a key to continue."); Console.ReadKey(); }
// Post EntityMeta public List <EntityMeta> PostEntityMeta(List <EntityMetaRequest> entityMetaRequest, Datastream datastream) { try { var data = JsonConvert.SerializeObject(entityMetaRequest, Formatting.Indented, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() }); var response = _http.Post("/datastream/" + datastream.Id + "/entityMeta", data); return(JsonConvert.DeserializeObject <List <EntityMeta> >(response)); } catch (Exception) { throw; } }
/// <summary> /// This method adds facts to an existing datastream. /// </summary> /// <exception cref="System.ArgumentNullException">Thrown when one parameter is missing /// in the function call.</exception> /// <exception cref="FalkonryClient.Service.FalkonryException">Thrown when there is a request timeout.</exception> /// <exception cref="System.Exception">Thrown when any other error causes /// <param name="datastreamId">A String that contains the ID of existing datastream /// in which the facts are supposed to be added.</param> /// <param name="assessmentId">A String that contains the ID of the assessment /// in which the facts are supposed to be added.</param> /// <param name="stream">A byte array received from file-adapter's GetStream() method.</param> /// <param name="fileType">A String that specifies the file type i.e CSV/JSON.</param> public void IngestFactsFromFile(String datastreamId, String assessmentId, byte[] stream, String fileType) { if (fileType == null || datastreamId == null || stream == null || assessmentId == null) { throw new ArgumentNullException(nameof(fileType)); } int i; Datastream datastream = falkonry.GetDatastream(datastreamId); var options = new SortedDictionary <string, string>(); var inputStatus = new InputStatus(); // TODO: Change the name of the start time identifier according to your data. options.Add("startTimeIdentifier", "time"); // TODO: Change the name of the end time identifier according to your data. options.Add("endTimeIdentifier", "end"); // TODO: Change the value of the time format according to your data. options.Add("timeFormat", datastream.Field.Time.Format.ToString()); // TODO: Change the value of the time zone according to your data. options.Add("timeZone", datastream.Field.Time.Zone.ToString()); // TODO: Change the name of the entity identifier according to your data. options.Add("entityIdentifier", datastream.Field.EntityIdentifier.ToString()); // TODO: Change the name of the value identifier according to your data. options.Add("valueIdentifier", "value"); // TODO: Uncomment this line if your facts data has any keyword identifier. //options.Add("keywordIdentifier", "Tag"); for (i = 0; i < 3; i++) { try { inputStatus = falkonry.AddFactsStream(assessmentId, stream, options); if (CheckStatus(inputStatus.Id) == 1) { break; } } catch (FalkonryClient.Service.FalkonryException e) { log.Error(e.GetBaseException() + "\n"); Console.ReadKey(); Environment.Exit(1); } catch (Exception ex) { log.WarnFormat(ex.Message + "\n" + "Retry Attempt: {0}", i + 1); } } if (i == 3) { log.Error("Cannot add facts to the datastream!"); Console.ReadKey(); Environment.Exit(1); } }
/* * This method is just an example to show how our ADK manages * multiple data files in a particular folder. It reads all * the files and passes each one of them as a stream to an existing * datastream. */ /// <summary> /// This method is just an example to show how our ADK manages /// multiple data files in a particular folder. It reads all the files /// and passes each one of them as a stream to an existing datastream. /// </summary> /// <exception cref="System.ArgumentNullException">Thrown when one parameter is missing /// in the function call.</exception> /// <exception cref="FalkonryClient.Service.FalkonryException">Thrown when there is a request timeout.</exception> /// <exception cref="System.Exception">Thrown when any other error causes /// the program to not add historical data.</exception> /// <param name="datastreamId">A String that contains the ID of existing datastream /// in which the historical data is supposed to be added.</param> /// <param name="folderPath">Complete folder path where the data files /// are stored</param> public void IngestDataFromFolder(String datastreamId, String folderPath) { if (datastreamId == null || folderPath == null) { throw new ArgumentNullException(nameof(datastreamId)); } String fileType; int i; FileAdapter fileAdapter = new FileAdapter(); Datastream datastream = falkonry.GetDatastream(datastreamId); var options = new SortedDictionary <string, string>(); var inputStatus = new InputStatus(); options.Add("streaming", "false"); options.Add("hasMoreData", "true"); options.Add("timeIdentifier", datastream.Field.Time.Identifier.ToString()); options.Add("timeZone", datastream.Field.Time.Zone.ToString()); options.Add("timeFormat", datastream.Field.Time.Format.ToString()); options.Add("entityIdentifier", datastream.Field.EntityIdentifier.ToString()); options.Add("fileFormat", "csv"); // TODO: Uncomment these 2 lines out for Narrow Datastream Format. //options.Add("signalIdentifier", datastream.Field.Signal.SignalIdentifier.ToString()); //options.Add("valueIdentifier", datastream.Field.Signal.ValueIdentifier.ToString()); // TODO: Uncomment this line out for Batch Datastream Format. //options.Add("batchIdentifier", datastream.Field.BatchIdentifier.ToString()); String[] Files = Directory.GetFiles(folderPath + "\\", "*.csv"); String[] Files2 = Directory.GetFiles(folderPath + "\\", "*.json"); Files = Files.Concat(Files2).ToArray(); var fileCount = Files.Length; foreach (String file in Files) { byte[] stream = fileAdapter.GetStream(file); fileType = System.IO.Path.GetExtension(file).ToString().Substring(1, System.IO.Path.GetExtension(file).ToString().Length - 1); options["fileFormat"] = fileType; if (fileCount == 1) { options["hasMoreData"] = "false"; } fileCount--; for (i = 0; i < 3; i++) { try { inputStatus = falkonry.AddInputStream(datastreamId, stream, options); if (CheckStatus(inputStatus.Id) == 1) { break; } } catch (FalkonryClient.Service.FalkonryException e) { log.Error(e.GetBaseException() + "\n"); Console.ReadKey(); Environment.Exit(1); } catch (Exception ex) { log.WarnFormat(ex.Message + "\n" + "Retry Attempt: {0}", i + 1); } } if (i == 3) { log.Error("Cannot add data to the datastream!"); Console.ReadKey(); Environment.Exit(1); } } }
public List <EntityMeta> PostEntityMeta(List <EntityMetaRequest> entityMetaRequest, Datastream datastream) { try { return(_falkonryService.PostEntityMeta(entityMetaRequest, datastream)); } catch (Exception) { throw; } }