示例#1
0
        private Guid FindExistingTimeSeries(string name, Guid uniqueId)
        {
            var timeSeries = TimeSeriesDescriptions
                             .FirstOrDefault(ts => ts.UniqueId == uniqueId);

            if (timeSeries != null)
            {
                return(timeSeries.UniqueId);
            }

            throw new ExpectedException($"{uniqueId:N} is not a known {name} time-series.");
        }
示例#2
0
        private TimeSeries FindOrCreateTimeSeries(
            string name,
            string identifierOrUniqueId,
            string defaultLocation,
            string defaultLabel,
            Func <string, TimeSeries> createFactory = null)
        {
            identifierOrUniqueId = identifierOrUniqueId ?? string.Empty;

            if (Guid.TryParse(identifierOrUniqueId, out var uniqueId))
            {
                return(GetTimeSeries(FindExistingTimeSeries(name, uniqueId)));
            }

            var inferredLabel = !identifierOrUniqueId.Contains(".") && !string.IsNullOrEmpty(defaultLabel)
                ? $".{defaultLabel}"
                : null;

            var inferredLocation = !identifierOrUniqueId.Contains("@") && !string.IsNullOrEmpty(defaultLocation)
                ? $"@{defaultLocation}"
                : null;

            var identifier = $"{identifierOrUniqueId}{inferredLabel}{inferredLocation}";

            var timeSeries = TimeSeriesDescriptions
                             .FirstOrDefault(ts =>
                                             ts.Identifier.Equals(identifier, StringComparison.InvariantCultureIgnoreCase));

            if (timeSeries != null)
            {
                return(GetTimeSeries(timeSeries.UniqueId));
            }

            if (Context.CreateMissingTimeSeries && createFactory != null)
            {
                return(createFactory(identifier));
            }

            throw new ExpectedException($"'{identifier}' is not a known {name} time-series.");
        }