Ejemplo n.º 1
0
        public async static Task ProcessedImagesTrigger([QueueTrigger(QueueNames.Seen)]CloudQueueMessage message, CancellationToken cancellationToken)
        {
            var connectionFactory = new StorageConnectionFactory(CloudConfigurationManager.GetSetting("storageAccountConnection"));
            var factory = new LoggerFactory();
            factory.AddConsole();
            factory.AddEventLog();

            var logger = factory.CreateLogger("ToprakWebjobs");
            var imageRepository = new ImageRepository(connectionFactory, logger);
            var queueRepository = new QueueRepository(connectionFactory, logger);
            IResultsRepository resultsRepository = new ResultsRepository(CloudConfigurationManager.GetSetting("Database"), logger);

            var envelope = TutanakDataEnvelope.GorulmusTutanakMesajiFactory(message.AsString);
            envelope.TutanakData.Image = (new Uri(envelope.TutanakData.Image)).Segments[2];

            await resultsRepository.RecordResult(envelope);

            var imageSeen = envelope.TutanakData;

            var results = (await resultsRepository.GetTutanakResultsAsync(imageSeen.Image)).ToList();

            var compareProperties =
                typeof(GorulmusTutanakMesaji).GetProperties()
                    .Where(p => p.GetCustomAttributes(false).All(a => a.GetType() != typeof(NoCompareAttribute)))
                    .OrderBy(p => p.Name)
                    .Select(p => p.Name);

            var resultHashGroups =
                results.Select(
                    r =>
                    compareProperties.Select(p => r.GetType().GetProperty(p).GetValue(r)).Aggregate((i, j) => $"{i},{j}"))
                    .GroupBy(h => h)
                    .Select(g => g.Count())
                    .OrderByDescending(c => c).ToList();

            var sameReadLimit = Convert.ToInt32(CloudConfigurationManager.GetSetting("SameReadLimit"));

            if (resultHashGroups.Any() && resultHashGroups.Max() >= sameReadLimit)
            {
                await imageRepository.TransferToProcessed(imageSeen.Image, cancellationToken);
                await resultsRepository.RecordReadSuccessResult(envelope);
            } else 
            {
                await
                    queueRepository.AddMessageAsync(
                        QueueNames.ToBeProcessed,
                        new CloudQueueMessage(imageRepository.GetUnprocessedUri(imageSeen.Image).AbsoluteUri),
                        cancellationToken);
            }
        }
Ejemplo n.º 2
0
        // This function will get triggered/executed when a new message is written 
        // on an Azure Queue called queue.
        public async static Task NewImagesTrigger([QueueTrigger(QueueNames.NewImages)]CloudQueueMessage message, CancellationToken cancellationToken)
        {
            var connectionFactory = new StorageConnectionFactory(CloudConfigurationManager.GetSetting("storageAccountConnection"));
            var factory = new LoggerFactory();
            factory.AddConsole();
            factory.AddEventLog();

            var logger = factory.CreateLogger("ToprakWebjobs");

            var imageManager = new ImageManagerService(connectionFactory, logger);

            await imageManager.AddToCirculation(true, cancellationToken);

        }
Ejemplo n.º 3
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage

        public static void Main()
        {
            var connectionFactory = new StorageConnectionFactory(CloudConfigurationManager.GetSetting("storageAccountConnection"));
            var factory = new LoggerFactory();
            factory.AddConsole();
            factory.AddEventLog();
            var logger = factory.CreateLogger("ToprakWebjobs");

            AppDomain.CurrentDomain.UnhandledException +=
                (sender, args) => { logger.LogCritical(args.ExceptionObject.ToString()); };
        
            var host = new JobHost();
            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
Ejemplo n.º 4
0
        public Program()
        {
            // a DI based application would get ILoggerFactory injected instead
            var factory = new LoggerFactory();

            // getting the logger immediately using the class's name is conventional
            _logger = factory.CreateLogger(typeof(Program).FullName);

            // providers may be added to an ILoggerFactory at any time, existing ILoggers are updated
            #if !DNXCORE50
            factory.AddNLog(new global::NLog.LogFactory());
            factory.AddEventLog();
            #endif
            factory.AddConsole();
            factory.AddConsole((category, logLevel) => logLevel >= LogLevel.Critical && category.Equals(typeof(Program).FullName));
        }
Ejemplo n.º 5
0
        protected override void Load(ContainerBuilder builder)
        {
            builder.Register(
                c =>
                    {
                        var factory = new LoggerFactory();
                        factory.AddEventLog();
                        return factory.CreateLogger("ToprakWeb");
                    }).As<ILogger>().InstancePerLifetimeScope();

            var connectionString = this.config["Data:ImageRepository:ConnectionString"];
            var databaseConnectionString = this.config["Data:Database:ConnectionString"];

            builder.Register(
                c =>
                connectionString == "Dev"
                    ? new StorageConnectionFactory()
                    : new StorageConnectionFactory(connectionString))
                .As<IStorageConnectionFactory>()
                .InstancePerLifetimeScope();

            builder.Register(c => new QueueRepository(c.Resolve<IStorageConnectionFactory>(), c.Resolve<ILogger>()))
                .As<IQueueRepository>()
                .InstancePerLifetimeScope();

            builder.Register(c => new ImageRepository(c.Resolve<IStorageConnectionFactory>(), c.Resolve<ILogger>()))
                .As<IImageRepository>()
                .InstancePerLifetimeScope();


            builder.Register(c => new ImageManagerService(c.Resolve<IQueueRepository>(), c.Resolve<IImageRepository>(), c.Resolve<ILogger>()))
                .As<IImageManagerService>()
                .InstancePerLifetimeScope();

            builder.Register(c => new ResultsRepository.ResultsRepository(databaseConnectionString, c.Resolve<ILogger>()))
                .As<IResultsRepository>()
                .InstancePerLifetimeScope();
        }