Example #1
0
        public ServiceFactory(IStorage storage, ITelegramBotClient client, ILogger logger)
        {
            this.storage = storage;
            this.logger  = logger;

            userServiceFactory = new UserServiceFactory(storage, logger);
            var metricFactory = new MetricsFactory(Settings.Instance.Env, Settings.Logger);
            var metricService = metricFactory.Create();

            senderFactory = new SenderFactory(client, metricService);
            parserService = new CommandHandlerFactory();

            stateFactory   = new StateFactory(logger);
            contextFactory = new ContextFactory(storage, userServiceFactory, stateFactory, this);
        }
Example #2
0
        public async Task TestMetricsSending()
        {
            var metricsRoot = MetricsFactory.CreateMetrics("net.tcp://0.0.0.0:2003", TimeSpan.FromSeconds(10),
                                                           "SA3",
                                                           "Photon",
                                                           "1_0_0");

            metricsRoot.Measure.Histogram.Update(
                new HistogramOptions {
                Name = "fx", MeasurementUnit = Unit.Bytes
            }, 10);

            metricsRoot.Measure.Histogram.Update(
                new HistogramOptions {
                Name = "fx", MeasurementUnit = Unit.Bytes
            }, new MetricTags("tagName", "tagValue"), 10);

            var reporter = metricsRoot.Reporters.OfType <GraphiteReporter>().Single();
            await reporter.FlushAsync(metricsRoot.Snapshot.Get());
        }
 public PerfomanceMetricAttribute(MetricTypes metricType, string methodName, string tag) : base()
 {
     MetricsFactory.CreateMetric(metricType, methodName, tag);
 }
 public OperationMetricAttribute(string className, string tag = null, [CallerMemberName] string methodName = null) : base()
 {
     MetricsFactory.CreateMetric(className, methodName, tag);
 }
Example #5
0
        private static async Task <int> Main(string[] args)
        {
            Console.WriteLine("App starting, press Ctrl+C to cancel.");
            Console.CancelKeyPress += Console_CancelKeyPress;

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .CreateLogger();

            DeviceConfiguration config = DeviceConfigReader.GetDeviceConfig();

            if (!config.Validate(out string error))
            {
                Log.Error("Device config could not be loaded; {error}", error);
                return(-1);
            }

            Console.WriteLine();

            Console.Write("Renew IoT hub connection periodically (y/n)? ");
            ConsoleKeyInfo key = Console.ReadKey();

            Console.WriteLine();
            Console.WriteLine();

            bool renewHubConnection = key.Key == ConsoleKey.Y;

            Console.WriteLine();

            CancellationToken cancelToken = cancellationTokenSource.Token;

            IMetricsRoot metrics = MetricsFactory.Create();

            var deviceHubClient = new DeviceHubClient(config, metrics);
            await deviceHubClient.EnsureHubConnectionAsync(DispatchDirectCall, cancelToken);

            var         tasksModule = new TasksModule(deviceHubClient, metrics);
            List <Task> tasks       = tasksModule.GetTasks(cancelToken).ToList();

            if (renewHubConnection)
            {
                const int intervalMinutes = 5;
                Log.Information(
                    "IoT hub connection will be recreated every {interval} minutes regardless of status",
                    intervalMinutes);
                tasks.Add(deviceHubClient.RenewClientAsync(cancelToken, intervalMinutes));
            }
            else
            {
                Log.Information("IoT hub connection will not be periodically recreated");
            }

            try
            {
                await Task.WhenAll(tasks);
            }
            catch (TaskCanceledException)
            {
                Log.Information("App run cancelled");
            }
            catch (AggregateException)
            {
                Log.Information("Error running tasks");
            }

            return(0);
        }