Ejemplo n.º 1
0
        public TagDataRawDto AddTagDataRaw(AddTagDataRawInput input)
        {
            TagDataName revised = new TagDataName
            {

                TagId = input.Id,
                TagName = input.Name,
                Timestamp = input.Timestamp,
                Value = input.Value,
                Quality = input.Quality
            };
            TagDataRaw data = _tagManager.InsertOrUpdateDataByName(revised);
            TagDataRawDto output = data.MapTo<TagDataRawDto>();

            return output;
        }
Ejemplo n.º 2
0
        public TagDataRaw InsertOrUpdateDataByName(TagDataName input)
        {
            // Transform the "TagDataName" input into "TagDataRaw" format, then call InsertOrUpdateData() to do the work.
            // The most important point is to get/validate the tag information.
            TagDataRaw data = null;
            Tag tag = null;

            if (input.TagId.HasValue)
                tag = _tagRepository.FirstOrDefault(input.TagId.Value);
            else if( !string.IsNullOrEmpty(input.TagName) )
                tag = _tagRepository.FirstOrDefault(t => t.Name == input.TagName);

            if (tag != null)
            {
                // Insert or update the data
                data = new TagDataRaw
                {
                    TenantId = tag.TenantId,
                    TagId = tag.Id,
                    Timestamp = input.Timestamp.HasValue ? input.Timestamp.Value : DateTime.Now,
                    Value = input.Value,
                    Quality = input.Quality.HasValue ? input.Quality.Value : TagDataQuality.Good
                };
                data = InsertOrUpdateData(tag, data);

                // Now update the working table
                UpdateTagDataWorkingTable(tag, data.Timestamp, data.Timestamp);
            }
            return data;
        }