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");
        }
Exemple #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;
        }
        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);
        }
        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);
        }