public async Task <IActionResult> CreateTag([FromBody] TagSettings tag, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); // 400
            }

            try {
                var result = await _historian.CreateTag(User, tag, cancellationToken).ConfigureAwait(false);

                return(CreatedAtRoute("GetTagById", new { id = result.Id }, result.ToTagDefinitionExtendedDto())); // 201
            }
            catch (ArgumentException) {
                return(BadRequest()); // 400
            }
            catch (OperationCanceledException) {
                return(StatusCode(204)); // 204
            }
            catch (SecurityException) {
                return(Forbid()); // 403
            }
            catch (NotSupportedException) {
                return(BadRequest()); // 400
            }
            catch (NotImplementedException) {
                return(BadRequest()); // 400
            }
        }
Exemple #2
0
        protected override async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            while (!_historian.Historian.IsInitialized)
            {
                await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();
            }

            var identity = GetSystemIdentity();
            var start    = DateTime.UtcNow.AddDays(-1);

            var runningStateSet = await _historian.GetStateSet(identity, "Running_States", cancellationToken).ConfigureAwait(false);

            if (runningStateSet == null)
            {
                var settings = new StateSetSettings()
                {
                    Name        = "Running_States",
                    Description = "State set for Aika running state tag",
                    States      = new[] { new StateSetItem("Running", 1), new StateSetItem("Stopped", 0) }
                };
                runningStateSet = await _historian.CreateStateSet(identity, settings, cancellationToken).ConfigureAwait(false);
            }
            var runningStateStopped = runningStateSet["Stopped"];
            var runningStateRunning = runningStateSet["Running"];

            var tags = await _historian.GetTags(identity, new[] { "Sinusoid", "Running_State" }, cancellationToken).ConfigureAwait(false);

            double sinusoidWaveFunc(double time)
            {
                double period = TimeSpan.FromHours(12).Ticks;

                return(50f * (Math.Sin(2 * Math.PI * (1 / period) * (time % period))));
            };

            TagValue snapshot;
            var      sinusoid = tags.Values.FirstOrDefault(x => x.Name.Equals("Sinusoid", StringComparison.OrdinalIgnoreCase));

            if (sinusoid == null)
            {
                sinusoid = await _historian.CreateTag(identity,
                                                      new TagSettings()
                {
                    Name                    = "Sinusoid",
                    Description             = $"12 hour sinusoid wave (starting at {start:dd-MMM-yy HH:mm:ss} UTC), with exception and compression filtering",
                    DataType                = TagDataType.FloatingPoint,
                    ExceptionFilterSettings = new TagValueFilterSettingsUpdate()
                    {
                        IsEnabled  = true,
                        LimitType  = TagValueFilterDeviationType.Absolute,
                        Limit      = 0.1,
                        WindowSize = TimeSpan.FromDays(1)
                    },
                    CompressionFilterSettings = new TagValueFilterSettingsUpdate()
                    {
                        IsEnabled  = true,
                        LimitType  = TagValueFilterDeviationType.Absolute,
                        Limit      = 0.15,
                        WindowSize = TimeSpan.FromDays(1)
                    }
                },