Ejemplo n.º 1
0
        public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
        {
            _log = log;
            LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            LoadConfiguration();

            if (string.IsNullOrEmpty(Settings.OpenWeatherKey))
            {
                LogInformation("No OpenWeather API Key provided, function will generate random data");
            }

            // Set up OMF Ingress Service
            _omfIngressService = ConfigureOcsOmf(Settings.OcsUri, Settings.OcsTenantId, Settings.OcsNamespaceId, Settings.OcsClientId, Settings.OcsClientSecret);

            // Send OMF Type message
            SendOmfMessage(_omfIngressService, OmfMessageCreator.CreateTypeMessage(typeof(CurrentWeather)));

            // Prepare OMF containers
            var typeId     = ClrToOmfTypeConverter.Convert(typeof(CurrentWeather)).Id;
            var containers = new List <OmfContainer>();
            var data       = new List <OmfDataContainer>();

            var queries = Settings.OpenWeatherQueries.Split('|');

            foreach (var query in queries)
            {
                if (!string.IsNullOrEmpty(Settings.OpenWeatherKey))
                {
                    // Get Current Weather Data
                    var response = JsonConvert.DeserializeObject <JObject>(HttpGet($"{Settings.OpenWeatherUri}?q={query}&appid={Settings.OpenWeatherKey}"));

                    // Parse data into OMF messages
                    var value    = new CurrentWeather(response);
                    var streamId = $"OpenWeather_Current_{value.Name}";
                    containers.Add(new OmfContainer(streamId, typeId));
                    var omfValue = (OmfObjectValue)ClrToOmfValueConverter.Convert(value);
                    data.Add(new OmfDataContainer(streamId, new List <OmfObjectValue>()
                    {
                        omfValue
                    }));
                }
                else
                {
                    // No key provided, generate random data
                    containers.Add(new OmfContainer(query, typeId));
                    var value    = new CurrentWeather(query);
                    var omfValue = (OmfObjectValue)ClrToOmfValueConverter.Convert(value);
                    data.Add(new OmfDataContainer(query, new List <OmfObjectValue>()
                    {
                        omfValue
                    }));
                }
            }

            SendOmfMessage(_omfIngressService, new OmfContainerMessage(containers));
            LogInformation($"Sent {containers.Count} containers");
            SendOmfMessage(_omfIngressService, new OmfDataMessage(data));
            LogInformation($"Sent {data.Count} data messages");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends OMF type message for a type
        /// </summary>
        /// <param name="type">OMF type to be sent</param>
        internal void SendOmfType(Type type)
        {
            OmfTypeMessage msg = OmfMessageCreator.CreateTypeMessage(type);

            SendOmfMessage(msg);
            msg.ActionType     = ActionType.Delete;
            _typeDeleteMessage = msg;
        }
Ejemplo n.º 3
0
        public async Task SendValueAsync(string streamId, DataPointType value)
        {
            // Send DataPointType values
            OmfDataMessage dataMessage = OmfMessageCreator.CreateDataMessage(streamId, value);

            await SendOmfMessageAsync(dataMessage);

            Console.WriteLine($"Sent data point: Time: {value.Timestamp}, Value: {value.Value}");
        }
Ejemplo n.º 4
0
        public async Task DeleteStreamAsync(string streamId)
        {
            // Delete container
            Console.WriteLine($"Deleting Container with Id {streamId}");
            Console.WriteLine();
            OmfContainerMessage containerMessage = OmfMessageCreator.CreateContainerMessage(streamId, typeof(DataPointType));

            containerMessage.ActionType = ActionType.Delete;
            await SendOmfMessageAsync(containerMessage);
        }
Ejemplo n.º 5
0
        public async Task DeleteDataPointTypeAsync()
        {
            // Delete type
            Console.WriteLine($"Deleting Type with Id {typeof(DataPointType).Name}");
            Console.WriteLine();
            OmfTypeMessage typeMessage = OmfMessageCreator.CreateTypeMessage(typeof(DataPointType));

            typeMessage.ActionType = ActionType.Delete;
            await SendOmfMessageAsync(typeMessage);
        }
Ejemplo n.º 6
0
        public async Task CreateDataPointTypeAsync()
        {
            // Create a DataPointType
            Console.WriteLine($"Creating Type with Id {typeof(DataPointType).Name}");
            Console.WriteLine();

            OmfTypeMessage typeMessage = OmfMessageCreator.CreateTypeMessage(typeof(DataPointType));

            await SendOmfMessageAsync(typeMessage);
        }
Ejemplo n.º 7
0
        public async Task CreateStreamAsync(string streamId)
        {
            // Create container
            Console.WriteLine($"Creating Container with Id {streamId}");
            Console.WriteLine();

            OmfContainerMessage containerMessage = OmfMessageCreator.CreateContainerMessage(streamId, typeof(DataPointType));

            await SendOmfMessageAsync(containerMessage).ConfigureAwait(false);
        }
Ejemplo n.º 8
0
        public async Task SendValueAsync(string streamId, DataPointType value)
        {
            if (value == null)
            {
                throw new ArgumentException("Value cannot be null.", nameof(value));
            }

            // Send DataPointType values
            OmfDataMessage dataMessage = OmfMessageCreator.CreateDataMessage(streamId, value);

            await SendOmfMessageAsync(dataMessage).ConfigureAwait(false);

            Console.WriteLine($"Sent data point: Time: {value.Timestamp}, Value: {value.Value}");
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Sends OMF data messages for a dictionary of OMF data keyed by the stream ID to the configured OMF endpoints
 /// </summary>
 /// <typeparam name="T">OMF type of the OMF data to be sent</typeparam>
 /// <param name="data">Dictionary of OMF data keyed by the stream ID</param>
 internal void SendOmfData <T>(Dictionary <string, IEnumerable <T> > data)
 {
     SendOmfMessage(OmfMessageCreator.CreateDataMessage(data));
 }