예제 #1
0
        public string StoreData()
        {
            Connect();

            List <TVQ>        tvqs        = new List <TVQ>();
            List <Property>   properties  = new List <Property>();
            List <Annotation> annotations = new List <Annotation>();

            // 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 < 5; i++)
                {
                    TVQ tvq = new TVQ();
                    tvq.id        = id;
                    tvq.timestamp = now.AddTicks(i);
                    tvq.value     = i % 100;
                    tvq.quality   = StandardQualities.Good;
                    tvqs.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;
                properties.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;
                properties.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;
                properties.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";
                annotations.Add(annotation);
            }

            // send only tvqs in this call
            //string result = session.StoreTVQs(tvqs.ToArray());

            // send only properties in this call
            //string result = session.StoreProperties(properties.ToArray());

            // send only annotations in this call
            //string result = session.StoreAnnotations(annotations.ToArray());

            // send tvqs, properties, and annotations in this call
            string result = _session.StoreData(tvqs.ToArray(), properties.ToArray(), annotations.ToArray());

            return(result);
        }