예제 #1
0
        protected FunctionBase(ILogger logger)
        {
            _logger       = logger;
            _functionName = typeof(T).Name;

            Log = new FunctionLog(logger, _functionName);
        }
        public static async Task Run(
            [QueueTrigger(QueueConstants.AzureMLJobQueueName, Connection = QueueConstants.QueueConnectionStringName)] string jobId,
            ExecutionContext executionContext,
            TraceWriter logger
            )
        {
            logger.Info($"{FunctionName} Execution begun at {DateTime.Now}");
            IConfiguration webConfiguration = new WebConfiguration(executionContext);
            var            log = new FunctionLog(logger, executionContext.InvocationId);

            var objectLogger = (webConfiguration.UseObjectLogger) ? new BlobObjectLogger(webConfiguration, log) : null;

            using (var kernel = new KernelFactory().GetKernel(
                       log,
                       webConfiguration,
                       objectLogger
                       ))
            {
                var processor = kernel.Get <IScheduledAzureMLProcessor>();
                var result    = await processor.CheckAzureMLAndPostProcess(jobId);

                if (!result.LastJobStatus.IsTerminalState())
                {
                    var queue = CreateQueue();

                    // Job is not finished.  Put it back on the queue to try again.
                    var message = new CloudQueueMessage(jobId);
                    queue.AddMessage(message, null, webConfiguration.AzureMlRetryTimeDelay);
                }
            }

            logger.Info($"{FunctionName} completed at {DateTime.Now}");
        }
예제 #3
0
        static void Main(string[] args)
        {
            FunctionLog functionLog = new FunctionLog("../../test.simion.log.functions");

            foreach (Function f in functionLog.Functions)
            {
                Console.WriteLine("Function #" + f.Id + " (" + f.Name + "): " + f.Samples.Count + " samples)");
            }
        }
        public static FunctionLog CreateFunctionLog(ResultsAndCertificationDbContext _dbContext, string name, DateTime startDate, DateTime?endDate, FunctionStatus status, string message, bool addToDbContext = true)
        {
            var functionLog = new FunctionLog
            {
                Name      = name,
                StartDate = startDate,
                EndDate   = endDate,
                Status    = status,
                Message   = message,
                CreatedBy = "Test User"
            };

            if (addToDbContext)
            {
                _dbContext.Add(functionLog);
            }
            return(functionLog);
        }
        public static async Task ProcessRedditPost(
            [QueueTrigger(QueueConstants.RedditPostQueueName, Connection = QueueConstants.QueueConnectionStringName)] SocialGistPostId socialGistPost,
            TraceWriter log,
            ExecutionContext executionContext
            )
        {
            log.Info($"{FunctionName} Execution begun at {DateTime.Now}");

            var config       = new WebConfiguration(executionContext);
            var logger       = new FunctionLog(log, executionContext.InvocationId);
            var objectLogger = (config.UseObjectLogger) ? new BlobObjectLogger(config, logger) : null;

            using (var kernel = new KernelFactory().GetKernel(logger, config, objectLogger))
            {
                var processor  = kernel.Get <IThreadProcessor>();
                var socialGist = kernel.Get <ISocialGist>();
                socialGist.ResultLimitPerPage      = config.ResultLimitPerPage;
                socialGist.MaximumResultsPerSearch = config.MaximumResultsPerSearch;

                await processor.Process(socialGistPost);
            }

            log.Info($"{FunctionName} completed at {DateTime.Now}");
        }
예제 #6
0
        public override void Given()
        {
            CreateMapper();

            _functionLog = SeedFunctionLog();

            CommonServiceLogger         = new Logger <CommonService>(new NullLoggerFactory());
            TlLookupRepositoryLogger    = new Logger <GenericRepository <TlLookup> >(new NullLoggerFactory());
            TlLookupRepository          = new GenericRepository <TlLookup>(TlLookupRepositoryLogger, DbContext);
            FunctionLogRepositoryLogger = new Logger <GenericRepository <FunctionLog> >(new NullLoggerFactory());
            FunctionLogRepository       = new GenericRepository <FunctionLog>(FunctionLogRepositoryLogger, DbContext);
            CommonRepository            = new CommonRepository(DbContext);
            CommonService = new CommonService(CommonServiceLogger, CommonMapper, TlLookupRepository, FunctionLogRepository, CommonRepository);

            _functionLogDetails = new FunctionLogDetails
            {
                Id          = _functionLog.Id,
                Name        = _functionLog.Name,
                StartDate   = _functionLog.StartDate,
                EndDate     = DateTime.UtcNow,
                Status      = FunctionStatus.Processed,
                PerformedBy = "Test User"
            };
        }
        public static async Task Run(
            [TimerTrigger(ScheduledAzureMLFrequencyName, RunOnStartup = WebServiceRunConstants.RunAmlOnStartup)] TimerInfo timer, // Every half hour
            [Queue(QueueConstants.AzureMLJobQueueName, Connection = QueueConstants.QueueConnectionStringName)] ICollector <string> queueCollector,
            ExecutionContext executionContext,
            TraceWriter logger
            )
        {
            logger.Info($"{FunctionName} Execution begun at {DateTime.Now}");
            IConfiguration webConfiguration = new WebConfiguration(executionContext);
            var            log = new FunctionLog(logger, executionContext.InvocationId);

            var objectLogger = (webConfiguration.UseObjectLogger) ? new BlobObjectLogger(webConfiguration, log) : null;

            using (var kernel = new KernelFactory().GetKernel(
                       log,
                       webConfiguration,
                       objectLogger
                       ))
            {
                var processor = kernel.Get <IScheduledAzureMLProcessor>();
                var result    = await processor.RunAzureMLProcessing();

                // If result is null then there is not any data to run through AzureML and no AML job was started.
                if (result != null)
                {
                    queueCollector.Add(result.JobId);
                    log.Verbose($"AzureML Web Service called; JobId=[{result.JobId}]");
                }
                else
                {
                    log.Verbose("No data to run through AzureML; no AML job started.");
                }
            }

            logger.Info($"{FunctionName} completed at {DateTime.Now}");
        }
예제 #8
0
        public static void Run(
            [QueueTrigger(QueueConstants.RedditSearchQueueName, Connection = QueueConstants.QueueConnectionStringName)] string processMessage,
            ExecutionContext executionContext,
            TraceWriter logger
            )
        {
            logger.Info($"{FunctionName} Execution begun at {DateTime.Now}");
            IConfiguration webConfiguration = new WebConfiguration(executionContext);
            var            log = new FunctionLog(logger, executionContext.InvocationId);

            var objectLogger = (webConfiguration.UseObjectLogger) ? new BlobObjectLogger(webConfiguration, log) : null;

            using (var kernel = new KernelFactory().GetKernel(
                       log,
                       webConfiguration,
                       objectLogger
                       ))
            {
                var socialGist = kernel.Get <ISocialGist>();
                var telemetry  = kernel.Get <ITelemetryClient>();
                socialGist.ResultLimitPerPage      = webConfiguration.ResultLimitPerPage;
                socialGist.MaximumResultsPerSearch = webConfiguration.MaximumResultsPerSearch;

                SortedSet <SocialGistPostId> threadMatches = null;
                using (var sgQueryTelemetry =
                           telemetry.StartTrackDependency("Execute Search", null, "SocialGistPostSearch"))
                {
                    threadMatches = socialGist.MatchesForQuery(
                        webConfiguration.QueryTerms,
                        webConfiguration.QuerySortOrder,
                        null
                        ).Result;

                    sgQueryTelemetry.IsSuccess = true;
                }

                logger.Info(
                    $"Returned [{threadMatches.Count}] posts from search terms [{webConfiguration.QueryTerms}]");

                using (var queueCollectorTelemetry =
                           telemetry.StartTrackDependency("Enqueue Results", null, "SocialGistPostSearch"))
                {
                    var timeDelay = webConfiguration.SearchToThreadTimeDelay;
                    var queue     = CreateQueue();

                    queue.CreateIfNotExists();

                    QueueRequestOptions queueRequestOptions = new QueueRequestOptions()
                    {
                        MaximumExecutionTime = TimeSpan.FromMinutes(1)
                    };

                    var q = new HashSet <int>();

                    // Write to the queue.  By default this will use will utilize however many threads the underlying scheduler provides.
                    // See https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.paralleloptions.maxdegreeofparallelism?view=netframework-4.7.1#System_Threading_Tasks_ParallelOptions_MaxDegreeOfParallelism
                    Parallel.ForEach <SocialGistPostId, CloudQueue>(
                        threadMatches,
                        CreateQueue,
                        (item, loopState, innerQueue) =>
                    {
                        q.Add(Thread.CurrentThread.ManagedThreadId);
                        var messageContent = JsonConvert.SerializeObject(item);
                        var message        = new CloudQueueMessage(messageContent);
                        innerQueue.AddMessage(message, options: queueRequestOptions,
                                              initialVisibilityDelay: timeDelay);
                        return(innerQueue);
                    },
                        (finalResult) => { }
                        );

                    queueCollectorTelemetry.Properties.Add("Total Number of Threads Used", q.Count.ToString());
                    queueCollectorTelemetry.IsSuccess = true;
                }

                var metric = new MetricTelemetry()
                {
                    Name       = "Unique posts returned by search",
                    Sum        = threadMatches.Count,
                    Timestamp  = DateTime.Now,
                    Properties =
                    {
                        { "QueryTerms", webConfiguration.QueryTerms },
                    }
                };
                telemetry.TrackMetric(metric);
            }

            logger.Info($"{FunctionName} completed at {DateTime.Now}");
        }
        public static FunctionLog CreateFunctionLog(ResultsAndCertificationDbContext _dbContext, FunctionLog functionLog, bool addToDbContext = true)
        {
            if (functionLog == null)
            {
                functionLog = new FunctionLogBuilder().Build();
            }

            if (addToDbContext)
            {
                _dbContext.Add(functionLog);
            }
            return(functionLog);
        }
예제 #10
0
        public async Task <ActionResult> ApproveFunction(TimeSheetInputModel inputModel)
        {
            var loggedInUser     = HttpContext.User;
            var loggedInUserName = loggedInUser.Identity.Name;

            var update = (from x in context.TimeSheet
                          where x.FunctionId.Equals(inputModel.FunctionId) &&
                          x.UserId.Equals(inputModel.UserId) && x.TimeSheetNumber.Equals(inputModel.TimeSheetNumber)
                          select x);
            var userApprove = (from x in context.UserSspm where x.Username.Equals(loggedInUserName) select x).SingleOrDefault();

            foreach (Models.TimeSheet TUpdate in update)
            {
                TUpdate.ActionId = "Z";
                TUpdate.Approve1 = userApprove.UserId;
            }
            await context.SaveChangesAsync();

            try
            {
                var addLog = (from x in context.TimeSheet
                              where x.FunctionId.Equals(inputModel.FunctionId) &&
                              x.UserId.Equals(inputModel.UserId) && x.TimeSheetNumber.Equals(inputModel.TimeSheetNumber)
                              select x).FirstOrDefault();
                var stat = "";
                var AP1  = "";
                if (addLog.ActionId.Equals("Z"))
                {
                    stat = "F";
                    AP1  = userApprove.UserId;
                }
                else
                {
                    stat = "P";
                }
                FunctionLog ord = new FunctionLog
                {
                    ProjectNumber  = addLog.ProjectNumber,
                    FunctionLogId  = addLog.TimeSheetId,
                    FunctionId     = addLog.FunctionId,
                    FunctionStart  = addLog.TimeSheetStart,
                    FunctionEnd    = addLog.TimeSheetEnd,
                    FunctionNumber = addLog.TimeSheetNumber,
                    StatusId       = stat,
                    TaskId         = addLog.TaskId,
                    Approve1       = AP1,
                };

                context.FunctionLog.Add(ord);
                await context.SaveChangesAsync();

                try
                {
                    var update2 = (from x in context.FunctionLog
                                   where x.FunctionId.Equals(inputModel.FunctionId) &&
                                   x.FunctionNumber.Equals(inputModel.TimeSheetNumber)
                                   select x);
                    var ip = (from x in context.TimeSheet
                              where x.FunctionId.Equals(inputModel.FunctionId) &&
                              x.TimeSheetNumber.Equals(inputModel.TimeSheetNumber)
                              select x).FirstOrDefault();
                    if (ip.ActionId.Equals("Z"))
                    {
                        var checkss = (from x in context.FunctionLog where x.FunctionNumber.Equals("100000") select x).FirstOrDefault();

                        DateTime alstat = (DateTime)checkss.ActualStart;
                        DateTime alend  = (DateTime)addLog.TimeSheetEnd;

                        foreach (Models.FunctionLog FUpdate in update2)
                        {
                            FUpdate.StatusId    = "F";
                            FUpdate.ActualStart = checkss.ActualStart;
                            FUpdate.ActualEnd   = addLog.TimeSheetEnd;
                            FUpdate.Variant     = (int)alend.Subtract(alstat).TotalDays;
                        }
                        await context.SaveChangesAsync();

                        try
                        {
                            var check1 = (from x in context.FunctionLog
                                          where x.FunctionId.Equals(addLog.FunctionId) && x.StatusId.Equals("F") &&
                                          x.ProjectNumber.Equals(inputModel.ProjectNumber) && x.TaskId.Equals(inputModel.TaskId)
                                          select x).FirstOrDefault();
                            var update3 = (from x in context.Function
                                           where x.FunctionId.Equals(inputModel.FunctionId) && x.TaskId.Equals(inputModel.TaskId) && x.ProjectNumber.Equals(inputModel.ProjectNumber)
                                           select x);
                            DateTime afstat = (DateTime)check1.ActualStart;
                            DateTime afend  = (DateTime)check1.ActualEnd;


                            foreach (Models.Function FUpdate in update3)
                            {
                                FUpdate.ActualStart = check1.ActualStart;
                                FUpdate.ActualEnd   = check1.ActualEnd;
                                FUpdate.Variant     = (int)afend.Subtract(afstat).TotalDays;
                            }
                            await context.SaveChangesAsync();



                            var AllTask   = (from x in context.Function where x.TaskId.Equals(check1.TaskId) select x).Count();
                            var CheckTask = (from x in context.FunctionLog where x.TaskId.Equals(check1.TaskId) && x.StatusId.Equals("F") select x).Count();



                            if (AllTask == CheckTask)
                            {
                                var update4 = (from x in context.Task
                                               where x.TaskId.Equals(addLog.TaskId)
                                               select x);
                                var at = (from x in context.Task
                                          where x.TaskId.Equals(addLog.TaskId)
                                          select x).FirstOrDefault();
                                DateTime atstat = (DateTime)at.ActualStart;
                                DateTime atend  = (DateTime)check1.ActualEnd;
                                foreach (Models.Task FUpdate in update4)
                                {
                                    FUpdate.ActualEnd = check1.ActualEnd;
                                    FUpdate.Variant   = (int)atend.Subtract(atstat).TotalDays;
                                }
                                await context.SaveChangesAsync();

                                var AllProject   = (from x in context.Task where x.TaskId.Equals(check1.TaskId) select x).Count();
                                var CheckProject = (from x in context.FunctionLog where x.TaskId.Equals(check1.TaskId) && x.StatusId.Equals("F") && x.ProjectNumber.Equals(check1.ProjectNumber) && x.TaskId.Equals(check1.TaskId) select x).Count();
                                if (AllProject == CheckProject)
                                {
                                    var update5 = (from x in context.Project
                                                   where x.ProjectNumber.Equals(inputModel.ProjectNumber)
                                                   select x);
                                    var ap = (from x in context.Project
                                              where x.ProjectNumber.Equals(inputModel.ProjectNumber)
                                              select x).FirstOrDefault();
                                    DateTime apstat = (DateTime)ap.ActualStart;
                                    DateTime apend  = (DateTime)check1.ActualEnd;
                                    foreach (Models.Project FUpdate in update5)
                                    {
                                        FUpdate.ActualEnd = check1.ActualEnd;
                                        FUpdate.Variant   = (int)apend.Subtract(apstat).TotalDays;
                                    }
                                    await context.SaveChangesAsync();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                    else
                    {
                        var c = (from x in context.TimeSheet where x.FunctionId.Equals(inputModel.FunctionId) && x.TaskId.Equals(inputModel.TaskId) select x).Count();
                        if (c == 1)
                        {
                            foreach (Models.FunctionLog FUpdate in update2)
                            {
                                FUpdate.ActualStart = addLog.TimeSheetStart;
                            }
                            await context.SaveChangesAsync();

                            var c4 = (from x in context.Function where x.FunctionId.Equals(inputModel.FunctionId) && x.TaskId.Equals(inputModel.TaskId) select x).Count();
                            if (c == 1)
                            {
                                var update3 = (from x in context.Function
                                               where x.FunctionId.Equals(inputModel.FunctionId) && x.TaskId.Equals(inputModel.TaskId) && x.ProjectNumber.Equals(inputModel.ProjectNumber)
                                               select x);
                                foreach (Models.Function FUpdate in update3)
                                {
                                    FUpdate.ActualStart = addLog.TimeSheetStart;
                                }
                                await context.SaveChangesAsync();
                            }
                            var c2 = (from x in context.TimeSheet where x.TaskId.Equals(addLog.TaskId) select x).Count();
                            if (c2 == 1)
                            {
                                var update4 = (from x in context.Task
                                               where x.TaskId.Equals(addLog.TaskId) && x.ProjectNumber.Equals(inputModel.ProjectNumber)
                                               select x);
                                foreach (Models.Task FUpdate in update4)
                                {
                                    FUpdate.ActualStart = addLog.TimeSheetStart;
                                }
                                await context.SaveChangesAsync();

                                var c3 = (from x in context.TimeSheet where x.ProjectNumber.Equals(addLog.ProjectNumber) select x).Count();
                                if (c2 == 1)
                                {
                                    var update5 = (from x in context.Project
                                                   where x.ProjectNumber.Equals(addLog.ProjectNumber)
                                                   select x);
                                    foreach (Models.Project FUpdate in update5)
                                    {
                                        FUpdate.ActualStart = addLog.TimeSheetStart;
                                    }
                                    await context.SaveChangesAsync();
                                }
                            }
                        }
                        var checkss = (from x in context.FunctionLog where x.FunctionNumber.Equals("100000") && x.FunctionId.Equals(addLog.FunctionId) && x.ProjectNumber.Equals(inputModel.ProjectNumber) && x.TaskId.Equals(inputModel.TaskId) select x).FirstOrDefault();

                        foreach (Models.FunctionLog FUpdate in update2)
                        {
                            FUpdate.StatusId    = "P";
                            FUpdate.ActualStart = checkss.ActualStart;
                        }
                        await context.SaveChangesAsync();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(RedirectToAction("TimeSheet", "TimeSheet", new RouteValueDictionary(
                                        new { Controller = "TimeSheet", Action = "TimeSheet", id = inputModel.ProjectNumber })));
        }