예제 #1
0
        public async Task ExecuteAsync(string localhost, CancellationToken Token = default)
        {
            while (!Token.IsCancellationRequested)
            {
                if (serviceInstance == null)
                {
                    if (!localhost.IsEmpty())
                    {
                        await new HttpClient().GetStringAsync($"{localhost}{BasicConfig.HttpReportsServerRegister}");
                    }

                    await Task.Delay(TimeSpan.FromSeconds(1), Token);
                }
                else
                {
                    _logger.LogInformation($"HttpReportsBackgroundService Execute IP:{serviceInstance.LocalIP} Port:{serviceInstance.LocalPort}");

                    IPerformance performance = await _performanceService.GetPerformance(serviceInstance.LocalIP + ":" + serviceInstance.LocalPort);

                    if (performance != null)
                    {
                        await _storage.AddPerformanceAsync(performance);
                    }

                    await Task.Delay(TimeSpan.FromSeconds(10), Token);
                }
            }
        }
예제 #2
0
        public static Penalization Build(IPerformance announced, IPerformance realized, IRules rules)
        {
            double announcedValue = rules.PrimaryComponent.Get(announced) ?? 0;
            double realizedValue  = rules.PrimaryComponent.Get(realized) ?? 0;

            if (announcedValue <= realizedValue)
            {
                return(null);
            }
            var penalization = new Penalization
            {
                IsShortPerformance = true,
                ShortReason        = "",
                PenalizationId     = "Short",
                Reason             = "Short performance",
                Performance        = new Performance(),
                CardResult         = CardResult.Yellow
            };
            var penalty = rules.ShortCalculation.Evaluate(new CalculationVariables(null, announced, realized));

            if (penalty != null)
            {
                penalty = Math.Round(penalty.Value, 4);
            }
            rules.PenalizationsTarget.Modify(penalization.Performance, penalty);
            return(penalization);
        }
예제 #3
0
        private void RunTests(IPerformance performanceTest, string testName)
        {
            try
            {
                Output += string.Format("Starting performance test for {0}", testName) + Environment.NewLine;

                _watch.Start();

                performanceTest.Registration();

                Output += string.Format("IOC Registration Time for {0} tests: {1} ms", NumberOfTests, _watch.Elapsed.Milliseconds.ToString()) + Environment.NewLine;

                _watch.Restart();

                performanceTest.Resolve();

                Output += string.Format("IOC Resolution Time for {0} tests: {1} ms", NumberOfTests, _watch.Elapsed.Milliseconds.ToString()) + Environment.NewLine;
            }
            finally
            {
                _watch.Stop();

                Output += string.Format("Ending performance test {0}", testName) + Environment.NewLine;
                Output += Environment.NewLine;
            }
        }
예제 #4
0
 public Ticket(IPerformance performance, TicketType type)
 {
     this.Performance = performance;
     this.Price       = this.CalculatePrice();
     this.status      = TicketStatus.Unsold;
     this.Type        = type;
 }
 protected Ticket(IPerformance performance, TicketType type)
 {
     this.Performance = performance;
     this.Price = this.CalculatePrice();
     this.status = TicketStatus.Unsold;
     this.Type = type;
 }
예제 #6
0
 private bool IsSatisfiedBy(IPerformance performance)
 {
     return
         (performance.Duration == null &&
          performance.Distance == null &&
          performance.Depth == null &&
          performance.Points == null);
 }
예제 #7
0
 public void SetPerformance(bool isRun, IPerformance perfmon)
 {
     if (model != null)
     {
         model.IsAlive = isRun;
         model.SetPerformance(perfmon);
     }
 }
예제 #8
0
        private T Extract(IPerformance performance)
        {
            if (performance == null)
            {
                return(default(T));
            }
            T?extracted = extractor(performance);

            return(extracted == null ? default(T) : extracted.Value);
        }
예제 #9
0
        public static double GetPoints(IPerformance performance, ICalculation calculation)
        {
            var points = calculation.Evaluate(new CalculationVariables(null, null, performance));

            if (points == null)
            {
                return(0);
            }
            return(Math.Round(points.Value, 4));
        }
 public async Task WritePerformanceAsync(IPerformance performance)
 {
     try
     {
         var reply = await _client.WritePerformanceAsync(performance as HttpReports.Collector.Grpc.Performance);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "ReportsTransport Error ");
     }
 }
예제 #11
0
 /// <summary>
 /// Delete the performance category if we need to.
 /// </summary>
 /// <param name="performance"></param>
 private static void CreatePerformance(IPerformance performance)
 {
     if (!performance.DeleteStartUp)
     {
         return;
     }
     if (PerformanceCounterCategory.Exists(performance.CategoryName))
     {
         PerformanceCounterCategory.Delete(performance.CategoryName);
     }
 }
        private decimal TicketsTotalPrice(IPerformance performance)
        {
            decimal totalPrice  = 0;
            var     soldTickets = performance.Tickets.Where(x => x.Status == TicketStatus.Sold);

            foreach (var ticket in soldTickets)
            {
                totalPrice += ticket.Price;
            }

            return(totalPrice);
        }
        public BookingsStagesAnalysis(ICompanyDBRepository _compDbRepo, IThirdpartyDBrepository _tpRepo, IPerformance _perfRepo)
        {
            compDbRepo = _compDbRepo;
            tpRepo     = _tpRepo;
            perfRepo   = _perfRepo;



            // used by the select in the view
            compSpec.DptsList["All"]     = compSpec.DptsList.SelectMany(kvp => kvp.Value).ToList();
            compSpec.bookingTypes["All"] = compSpec.bookingTypes.SelectMany(kvp => kvp.Value).ToList();
        }
예제 #14
0
        public async Task WritePerformanceAsync(IPerformance performance)
        {
            try
            {
                HttpContent content = new StringContent(System.Text.Json.JsonSerializer.Serialize(performance as Performance), System.Text.Encoding.UTF8, "application/json");

                var response = await _httpClientFactory.CreateClient(BasicConfig.HttpReportsHttpClient).PostAsync(_options.CollectorAddress, content);
            }
            catch (Exception ex)
            {
                //TODO ReTry?
                _logger.LogError(ex, "ReportsTransport Error");
            }
        }
예제 #15
0
        public SqlitePersisterWords(IPerformance performance, IWordsParts wordsParts, int maxNumCharactersPerWords, ILogger logger)
        {
            // the maximum word len
            _maxNumCharactersPerWords = maxNumCharactersPerWords;

            // the words parts interfaces
            _wordsParts = wordsParts ?? throw new ArgumentNullException(nameof(wordsParts));

            // save the logger
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            // create the counter,
            _counterAddOrUpdate = new SqlPerformanceCounter(performance, "Database: Add Or Update word", _logger);
        }
        private string PrintPerformanceReport(IPerformance performance)
        {
            // <name>: <tickets_sold> ticket(s), total: $<total_price>
            // Venue: <venue_name> (<venue_location>)
            // Start time: <start_time>
            var report = new List <string>();

            report.Add(string.Format("{0}: {1} ticket(s), total: ${2}",
                                     performance.Name, GetTicketsSold(performance).Count, TicketsTotalPrice(performance)));
            report.Add(string.Format("Venue: <venue_name> (<venue_location>)",
                                     performance.Venue.Name, performance.Venue.Location));
            report.Add(string.Format("Start time: {0}", performance.StartTime));

            return(string.Join(Environment.NewLine, report));
        }
예제 #17
0
        public double?Get(IPerformance performance)
        {
            switch (data)
            {
            case 1: return(performance.Distance);

            case 2: return(performance.Depth);

            case 3: return(performance.DurationSeconds());

            case 4: return(performance.Points);

            default: return(null);
            }
        }
예제 #18
0
        public async Task <bool> AddPerformanceAsync(IPerformance performance)
        {
            performance.Id = MD5_16(Guid.NewGuid().ToString());

            string sql = $@"Insert Into ""{Prefix}Performance"" (Id,Service,Instance,GCGen0,GCGen1,GCGen2,HeapMemory,ProcessCPU,ProcessMemory,ThreadCount,PendingThreadCount,CreateTime)
             Values (@Id,@Service,@Instance,@GCGen0,@GCGen1,@GCGen2,@HeapMemory,@ProcessCPU,@ProcessMemory,@ThreadCount,@PendingThreadCount,@CreateTime)";

            TraceLogSql(sql);

            return(await LoggingSqlOperation(async connection => (

                                                 await connection.ExecuteAsync(sql, performance)

                                                 ) > 0));
        }
예제 #19
0
        private void Fill(IPerformance performance, IDataReader dataReader, string prefix = "")
        {
            var sqlDataReader = dataReader as SqlDataReader;

            performance.PerformanceID = sqlDataReader.GetSafe <int>("PerformanceID");
            performance.EventName     = sqlDataReader.GetSafe <string>($"{prefix}EventName");
            performance.Description   = sqlDataReader.GetSafe <string>($"{prefix}Description");
            performance.EventUrl      = sqlDataReader.GetSafe <string>($"{prefix}EventUrl");
            performance.StartDate     = sqlDataReader.GetSafe <DateTime>($"{prefix}StartDate");
            performance.StartTime     = sqlDataReader.GetSafe <TimeSpan>($"{prefix}StartTime");
            performance.StartTime2    = sqlDataReader.GetSafe <TimeSpan>($"{prefix}StartTime2");
            //performance.WorkshopTime = (TimeSpan)item("WorkshopTime");
            //performance.WorkshopTime2 = (TimeSpan)item("WorkshopTime2");
            performance.IsDeleted = sqlDataReader.GetSafe <bool>($"{prefix}IsDeleted");
            performance.VenueID   = sqlDataReader.GetSafe <int>($"{prefix}VenueID");
        }
예제 #20
0
        public async Task <bool> AddPerformanceAsync(IPerformance performance)
        {
            performance.Id = MD5_16(Guid.NewGuid().ToString());

            string sql = $@"Insert Into Performance 
            (Id,Service,Instance,GCGen0,GCGen1,GCGen2,HeapMemory,ProcessCPU,ProcessMemory,ThreadCount,PendingThreadCount,CreateTime)
             Values (:Id,:Service,:Instance,:GCGen0,:GCGen1,:GCGen2,:HeapMemory,:ProcessCPU,:ProcessMemory,:ThreadCount,:PendingThreadCount, to_date('{performance.CreateTime:yyyy-MM-dd HH:mm:ss}','YYYY-MM-DD hh24:mi:ss') )";

            TraceLogSql(sql);

            return(await LoggingSqlOperation(async _ => (

                                                 await _.ExecuteAsync(sql, performance)

                                                 ) > 0));
        }
예제 #21
0
        public async Task <bool> AddPerformanceAsync(IPerformance performance)
        {
            performance.Id = MD5_16(Guid.NewGuid().ToString());

            string sql = $@"Insert Into MonitorJob 
            (Id,Service,Instance,GCGen0,GCGen1,GCGen2,HeapMemory,ProcessCPU,ProcessMemory,ThreadCount,PendingThreadCount,CreateTime)
             Values (:Id,:Service,:Instance,:GCGen0,:GCGen1,:GCGen2,:HeapMemory,:ProcessCPU,:ProcessMemory,:ThreadCount,:PendingThreadCount,:CreateTime)";

            TraceLogSql(sql);

            return(await LoggingSqlOperation(async connection => (

                                                 await connection.ExecuteAsync(sql, performance)

                                                 ) > 0));
        }
예제 #22
0
        public async Task <bool> AddPerformanceAsync(IPerformance performance)
        {
            performance.Id = MD5_16(Guid.NewGuid().ToString());

            string sql = $@"Insert Into [Performance] 
            ([Id],[Service],[Instance],[GCGen0],[GCGen1],[GCGen2],[HeapMemory],[ProcessCPU],[ProcessMemory],[ThreadCount],[PendingThreadCount],[CreateTime])
             Values (@Id,@Service,@Instance,@GCGen0,@GCGen1,@GCGen2,@HeapMemory,@ProcessCPU,@ProcessMemory,@ThreadCount,@PendingThreadCount,@CreateTime)";

            TraceLogSql(sql);

            return(await LoggingSqlOperation(async connection => (

                                                 await connection.ExecuteAsync(sql, performance)

                                                 ) > 0));
        }
예제 #23
0
        public Processor(
            IList <IFileParser> fileParsers,
            IProcessors processorsConfig,
            ITimers timersConfig,
            IMaintenance maintenanceConfig,
            IParser parser,
            IPersister persister,
            ILogger logger,
            IDirectory directory,
            IPerformance performance
            )
        {
            // save the logger
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            const string directoryCounterName = "Processor: Average time processing Directories";
            const string fileCounterName      = "Processor: Average time processing Files";
            const string parserCounterName    = "Processor: Average time parsing files/folders";

            // Create the various processors, they will not start doing anything just yet
            // or at least, they shouldn't
            var directoriesCounter = new ProcessorPerformanceCounter(performance, directoryCounterName, logger);
            var filesCounter       = new ProcessorPerformanceCounter(performance, fileCounterName, logger);
            var parserCounter      = new ProcessorPerformanceCounter(performance, parserCounterName, logger);

            _eventTimer = new ProcessorTimer(
                new List <IProcessor>
            {
                new Folders(directoriesCounter, processorsConfig.UpdatesFolderPerEvent, persister, logger, directory, timersConfig.EventsMaxWaitTransactionMs),
                new Files(filesCounter, processorsConfig.UpdatesFilesPerEvent, fileParsers, processorsConfig.IgnoreFiles, persister, logger, directory, timersConfig.EventsMaxWaitTransactionMs)
            },
                _logger, processorsConfig.EventsProcessorMs);

            _maintenanceTimer = new ProcessorTimer(
                new List <IProcessor>
            {
                new Maintenance(maintenanceConfig.Active, parser, persister, logger)
            },
                _logger, (int)TimeSpan.FromMinutes(processorsConfig.MaintenanceProcessorMinutes).TotalMilliseconds);

            _parserTimer = new ProcessorTimer(
                new List <IProcessor>
            {
                new Parser(parserCounter, parser, logger)
            },
                _logger, (int)TimeSpan.FromMinutes(processorsConfig.ParserProcessorMinutes).TotalMilliseconds);
        }
        public async Task ExecuteAsync(CancellationToken Token = default)
        {
            while (!Token.IsCancellationRequested)
            {
                Uri uri = new Uri(_options.Urls);

                _logger.LogInformation($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} BackgroundService Execute... ");

                IPerformance performance = await _performanceService.GetPerformance(uri.Host + ":" + uri.Port);

                if (performance != null)
                {
                    await _transport.WritePerformanceAsync(performance);
                }

                await Task.Delay(TimeSpan.FromSeconds(10), Token);
            }
        }
        public async Task ExecuteAsync(CancellationToken Token = default)
        {
            while (!Token.IsCancellationRequested)
            {
                Uri uri = new Uri(_options.Urls);

                IPerformance p = await _performanceService.GetPerformance(uri.Host + ":" + uri.Port);

                _logger.LogInformation($"HttpReports.CLR CPU:{p.ProcessCPU} Memory:{p.ProcessMemory} ThreadCount:{p.ThreadCount}  CG0:{p.GCGen0}  GC1:{p.GCGen1} GC2:{p.GCGen2}  ");

                if (p != null)
                {
                    await _transport.Transport(p);
                }

                await Task.Delay(TimeSpan.FromSeconds(10), Token);
            }
        }
예제 #26
0
        private static TestResult DoPerformanceTests(string testCase, IPerformance performance, int count, bool singleton)
        {
            switch (testCase)
            {
                case TestCaseName.A:
                    performance.DoTestA(1, singleton);
                    return performance.DoTestA(count, singleton);

                case TestCaseName.B:
                    performance.DoTestB(1, singleton);
                    return performance.DoTestB(count, singleton);

                case TestCaseName.C:
                    performance.DoTestC(1, singleton);
                    return performance.DoTestC(count, singleton);

                default:
                    throw new InvalidOperationException();
            }
        }
예제 #27
0
        public SqlitePersister(IPerformance performance, IList <IFileParser> parsers, ILogger logger,
                               ConfigSqliteDatabase config,
                               int maxNumCharactersPerWords,
                               int maxNumCharactersPerParts
                               )
        {
            // save the logger
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            // performance
            _performance = performance ?? throw new ArgumentNullException(nameof(performance));

            // the configuration
            _config = config ?? throw new ArgumentNullException(nameof(config));

            // create the configuration table.
            Config = new SqlitePersisterConfig();

            // create the counters
            Counts = new SqlitePersisterCounts(logger);

            // word parts
            WordsParts = new SqlitePersisterWordsParts(logger);

            // create the words
            Words = new SqlitePersisterWords(performance, WordsParts, maxNumCharactersPerWords, logger);

            // file words.
            FilesWords = new SqlitePersisterFilesWords(Words, logger);

            // create the files / Folders.
            Folders = new SqlitePersisterFolders(Counts, parsers, logger);

            // the parts
            Parts = new SqlitePersisterParts(maxNumCharactersPerParts);

            // the query
            Query = new SqlitePersisterQuery(maxNumCharactersPerParts, logger);
        }
        private void RunTests(IPerformance performanceTest, string testName)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
            GC.WaitForPendingFinalizers();

            try
            {
                Output += string.Format("Starting performance test for {0}", testName) + Environment.NewLine;

                _watch.Start();

                performanceTest.Registration();

                Output += string.Format("Avg. IOC Registration Time for {0} tests: {1} ms", NumberOfTests, ((double)_watch.Elapsed.Milliseconds / (double)NumberOfTests).ToString()) + Environment.NewLine;

                _watch.Restart();

                performanceTest.FirstResolve();

                Output += string.Format("IOC First Resolution Time: {0} ms", _watch.Elapsed.Milliseconds.ToString()) + Environment.NewLine;

                _watch.Restart();

                performanceTest.Resolve();


                Output += string.Format("Total IOC Resolution Time for {0} tests: {1} ms", NumberOfTests, _watch.Elapsed.Milliseconds) + Environment.NewLine;
                Output += string.Format("Avg. IOC Resolution Time for {0} tests: {1} ms", NumberOfTests, ((double)_watch.Elapsed.Milliseconds / (double)NumberOfTests).ToString()) + Environment.NewLine;
            }
            finally
            {
                _watch.Stop();

                Output += string.Format("Ending performance test {0}", testName) + Environment.NewLine;
                Output += Environment.NewLine;
            }
        }
예제 #29
0
        public async Task Transport(IPerformance performance)
        {
            await Retry(async() => {
                try
                {
                    HttpContent content = new StringContent(HttpUtility.HtmlEncode(JsonConvert.SerializeObject(performance)), System.Text.Encoding.UTF8, "application/json");

                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                    content.Headers.Add(BasicConfig.TransportType, typeof(IPerformance).Name);

                    var client = _httpClientFactory.CreateClient(BasicConfig.HttpReportsHttpClient);

                    var response = await _httpClientFactory.CreateClient(BasicConfig.HttpReportsHttpClient).PostAsync(_options.CollectorAddress + BasicConfig.TransportPath.Substring(1), content);

                    return(true);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "HttpReportsTransport IPerformance Error:" + ex.ToString());
                    return(false);
                }
            });
        }
        private decimal GetTotalTicketsPrice(IPerformance performance)
        {
            var soldTickets = performance.Tickets.Where(x => x.Status == TicketStatus.Sold);
            decimal totalPrice = soldTickets.Sum(ticket => ticket.Price);

            return totalPrice;
        }
예제 #31
0
        public Task Transport(IPerformance performance)
        {
            _PerformanceCollection.Flush(performance);

            return(Task.CompletedTask);
        }
 public RegularTicket(IPerformance performance)
     : base(performance, TicketType.Regular)
 {
 }
예제 #33
0
 public VIPticket(IPerformance performance)
     : base(performance, TicketType.VIP)
 {
 }
예제 #34
0
 public StudentTicket(IPerformance performance)
     : base(performance, TicketType.Student)
 {
 }
예제 #35
0
 public StudentTicket(IPerformance performancee)
     : base(performancee, TicketType.Student)
 {
 }
예제 #36
0
 protected void InsertPerformance(IPerformance performance)
 {
     this.performances.Add(performance);
 }
예제 #37
0
 public StudentTicket(IPerformance performance) 
     : base(performance, TicketType.Student)
 {
     this.Price = performance.BasePrice * TicketDiscount;
 }
 private int GetSoldTickets(IPerformance performance)
 {
     var tickets = performance.Tickets.Count(x => x.Status == TicketStatus.Sold);
     return tickets;
 }
예제 #39
0
파일: VipTicket.cs 프로젝트: nok32/SoftUni
 public VipTicket(IPerformance performance) 
     : base(performance, TicketType.VIP)
 {
     this.Price = performance.BasePrice * TicketDiscount;
 }
예제 #40
0
파일: VipTicket.cs 프로젝트: unbelt/SoftUni
 public VipTicket(IPerformance performance)
     : base(performance, TicketType.VIP)
 {
 }