// NOTE: this method of writing data will buffer the added items in the // sessions class and send all items when the FlushData method is called public string StoreData2() { Connect(); // create data to store DateTime now = DateTime.Now; Dictionary <string, int> tagIds = GetTagIds(); foreach (KeyValuePair <string, int> pair in tagIds) { string tagName = pair.Key; int id = pair.Value; // add tvq data for (int i = 0; i < 500; i++) { TVQ tvq = new TVQ(); tvq.id = id; tvq.timestamp = now.AddTicks(i); tvq.value = i % 100; tvq.quality = StandardQualities.Good; _session.AddTVQ(tvq); } // add property data Property highScale = new Property(); highScale.id = id; highScale.description = null; highScale.timestamp = now; highScale.name = StandardPropertyNames.ScaleHigh; highScale.value = 100; highScale.quality = StandardQualities.Good; _session.AddProperty(highScale); // add property data Property lowScale = new Property(); lowScale.id = id; lowScale.description = null; lowScale.timestamp = now; lowScale.name = StandardPropertyNames.ScaleLow; lowScale.value = 0; lowScale.quality = StandardQualities.Good; _session.AddProperty(lowScale); // add property data Property sampleInterval = new Property(); sampleInterval.id = id; sampleInterval.description = null; sampleInterval.timestamp = now; sampleInterval.name = StandardPropertyNames.SampleInterval; sampleInterval.value = TimeSpan.FromSeconds(1); sampleInterval.quality = StandardQualities.Good; _session.AddProperty(sampleInterval); // add annotation Annotation annotation = new Annotation(); annotation.id = id; annotation.timestamp = now; //annotation.createdAt = now; // only necessary if creation time differs from annotation timestamp annotation.user = "******"; annotation.value = "Example Annotation"; _session.AddAnnotation(annotation); } int storedTVQs; int storedProperties; int storedAnnotations; return(_session.FlushData(out storedTVQs, out storedProperties, out storedAnnotations)); }
public string StoreData() { Connect(); List <TVQ> tvqsList = new List <TVQ>(); List <Property> propertiesList = new List <Property>(); List <Annotation> annotationsList = new List <Annotation>(); // create data to store DateTime now = DateTime.Now; string sessionId = GetSessionId(); Dictionary <string, int> tagIds = GetTagIds(); foreach (KeyValuePair <string, int> pair in tagIds) { string tagName = pair.Key; int id = pair.Value; // add tvq data for (int i = 0; i < 500; i++) { TVQ tvq = new TVQ(); tvq.id = id; tvq.timestamp = now.AddTicks(i); tvq.value = i % 100; tvq.quality = StandardQualities.Good; tvqsList.Add(tvq); } // add property data Property highScale = new Property(); highScale.id = id; highScale.description = null; highScale.timestamp = now; highScale.name = StandardPropertyNames.ScaleHigh; highScale.value = 100; highScale.quality = StandardQualities.Good; propertiesList.Add(highScale); // add property data Property lowScale = new Property(); lowScale.id = id; lowScale.description = null; lowScale.timestamp = now; lowScale.name = StandardPropertyNames.ScaleLow; lowScale.value = 0; lowScale.quality = StandardQualities.Good; propertiesList.Add(lowScale); // add property data Property sampleInterval = new Property(); sampleInterval.id = id; sampleInterval.description = null; sampleInterval.timestamp = now; sampleInterval.name = StandardPropertyNames.SampleInterval; sampleInterval.value = TimeSpan.FromSeconds(1); sampleInterval.quality = StandardQualities.Good; propertiesList.Add(sampleInterval); // add annotation Annotation annotation = new Annotation(); annotation.id = id; annotation.timestamp = now; //annotation.createdAt = now; // only necessary if creation time differs from annotation timestamp annotation.user = "******"; annotation.value = "Example Annotation"; annotationsList.Add(annotation); } int tvqsStored; int propertiesStored; int annotationsStored; TVQ[] tvqs = tvqsList.ToArray(); Property[] properties = propertiesList.ToArray(); Annotation[] annotations = annotationsList.ToArray(); // send only tvqs in this call //string result = SAF_HelperClass.StoreData(client, sessionId, tvqs, out tvqsStored); // send only properties in this call //string result = SAF_HelperClass.StoreData(client, sessionId, properties, out propertiesStored); // send only annotations in this call //string result = SAF_HelperClass.StoreData(client, sessionId, annotations, out annotationsStored); // send tvqs, properties, and annotations in this call string result = HelperClass.StoreData(_client, sessionId, tvqs, properties, annotations, out tvqsStored, out propertiesStored, out annotationsStored); return(result); }
public string StoreData() { Connect(); List <TVQ> tvqsList = new List <TVQ>(); List <Property> propertiesList = new List <Property>(); List <Annotation> annotationsList = new List <Annotation>(); // create data to store DateTime now = DateTime.Now; string sessionId = GetSessionId(); Dictionary <string, int> tagIds = GetTagIds(); foreach (KeyValuePair <string, int> pair in tagIds) { string tagName = pair.Key; int id = pair.Value; // add tvq data for (int i = 0; i < 500; i++) { TVQ tvq = new TVQ(); tvq.id = id; tvq.timestamp = now.AddTicks(i); tvq.value = i % 100; tvq.quality = 0xC0; tvqsList.Add(tvq); } // add property data Property highScale = new Property(); highScale.id = id; highScale.description = null; highScale.timestamp = now; highScale.name = "Default High Scale"; highScale.value = 100; highScale.quality = 0xC0; propertiesList.Add(highScale); // add property data Property lowScale = new Property(); lowScale.id = id; lowScale.description = null; lowScale.timestamp = now; lowScale.name = "Default Low Scale"; lowScale.value = 0; lowScale.quality = 0xC0; propertiesList.Add(lowScale); // add annotation Annotation annotation = new Annotation(); annotation.id = id; annotation.timestamp = now; //annotation.createdAt = now; // only necessary if creation time differs from annotation timestamp annotation.user = "******"; annotation.value = "Example Annotation"; annotationsList.Add(annotation); } bool failed; TVQ[] tvqs = tvqsList.ToArray(); Property[] properties = propertiesList.ToArray(); Annotation[] annotations = annotationsList.ToArray(); string result = _client.StoreData(out failed, sessionId, tvqs, properties, annotations); if (failed) { // handle error string error = result; } return(result); }