public void Generate(IGeneratorSettings generatorSettings) { if (String.IsNullOrWhiteSpace(this.txtPassword.Text)) { MessageBox.Show(base.ParentForm, "Provide a source password to be processed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } IEntropyCalculator entropyCalculator = CalculatorFactory.Create <IEntropyCalculator>(); IStrengthCalculator strengthCalculator = CalculatorFactory.Create <IStrengthCalculator>(); ISecurityCalculator securityCalculator = CalculatorFactory.Create <ISecurityCalculator>(); String password = this.txtPassword.Text; Double entropy = entropyCalculator.Calculate(password); Strength strength = strengthCalculator.Calculate(entropy); Scenario scenario = this.cmbScenario.SelectedValue as Scenario; // Don't change this order. this.cntEntropy.Strength = strength; this.cntEntropy.Entropy = entropy; this.cntEntropy.Percent = strengthCalculator.ToPercent(entropy); this.cntEntropy.Summary = strengthCalculator.ToSummary(strength); if (entropy > 0d) { Duration duration = securityCalculator.Calculate(scenario, entropy); this.cntDuration.SetDuration(duration); } }
public C(A pA, B pB, CalculatorFactory pCalcFactory) { _pA = pA; _pB = pB; _pCalcFactory = pCalcFactory; var calculator = _pCalcFactory.Create(); }
private static void Run(bool useProxy) { ICalculate theCalculator = CalculatorFactory.Create(useProxy); for (int i = 0; i < 1000; i++) { int x = _generator.Next(0, Coordinate.XMax) + 1; int y = _generator.Next(0, Coordinate.YMax) + 1; Coordinate c = new Coordinate(x, y); Console.WriteLine($"Result of calculation #{i:000}, using ({x},{y}) : {theCalculator.Calculate(c)} {CacheReport(useProxy)}"); } }
static void Main(string[] args) { var factory = new CalculatorFactory(); var calculator = factory.Create(Algorithm.Arctan2); // http://www.findlatitudeandlongitude.com/ var origin = new Coordinate(43.089325, -87.87406); var destination = new Coordinate(43.060109, -87.883759); var distance1 = calculator.Calculate(origin, destination); calculator = factory.Create(Algorithm.Haversine); var distance2 = calculator.Calculate(origin, destination); calculator = factory.Create(Algorithm.LawOfCosines); var distance3 = calculator.Calculate(origin, destination); System.Console.WriteLine("arctan2:\t{0}", distance1.Meters); System.Console.WriteLine("haversine:\t{0}", distance2.Meters); System.Console.WriteLine("law of cosines:\t{0}", distance3.Meters); System.Console.ReadLine(); }
protected override async Task FinalizeJob(ScheduledJob job) { foreach (var indicator in _indicators) { var indicatorResults = await GetIntermediateResults(job.JobId, indicator.IndicatorId); var calculator = _calculatorFactory.Create(indicator); indicatorResults = calculator.Combine(indicatorResults); await _globalIndicatorService.Save(new GlobalIndicator { SectorId = 0, IndicatorId = indicator.IndicatorId, Values = indicatorResults, StartDate = indicatorResults.Last().Date, EndDate = indicatorResults.First().Date, CalculatedSuccessful = true, CompanyCount = Total, LastCalculated = DateTime.UtcNow }); await ClearIntermediateResults(job.JobId, indicator.IndicatorId); } }
public ExtendedGeneratorControl() : base() { this.InitializeComponent(); this.lstPasswords.Items.Clear(); this.entropyCalculator = CalculatorFactory.Create <IEntropyCalculator>(); this.strengthCalculator = CalculatorFactory.Create <IStrengthCalculator>(); StandardContextMenu contextMenu = StandardContextMenu.Create(this.OnContextMenuItemClick); contextMenu.Opening += this.OnContextMenuOpening; this.numLength.ContextMenuStrip = contextMenu; this.numAmount.ContextMenuStrip = contextMenu; this.lstPasswords.ContextMenuStrip = contextMenu; }
private void CalculateDestructionPercent(string happeningId, string personId) { var happening = QueryModelRepository.Dashboard.Happenings[happeningId]; var attendee = happening.Attendees.First(MatchAttendee(personId)); var person = attendee.Person; if (person.HappeningsQuit.Contains(happeningId)) { attendee.DestructionPercent = 100; return; } if (person.HappeningsCompleted.Contains(happeningId)) { attendee.DestructionPercent = 0; return; } var currentDistance = happening.Checkpoints.SelectMany( m => m.Visits.Where(MatchVisit(personId)), (checkpoint, visit) => checkpoint.DistanceFromStart).DefaultIfEmpty(0).Max(); var speed = this.calculator.Calculate(happening.Checkpoints.OrderBy(a => 1), personId); var destructionCalculator = CalculatorFactory.Create( new PersonData { DestructedInPrevious = person.QuitLastTime, Attended = person.HappeningsAttended.Count, Destructed = person.HappeningsQuit.Count }); attendee.DestructionPercent = destructionCalculator.Calculate( new WalkingData { LastAverageSpeedChange = (decimal)speed.LastAverageSpeedChangePercent, CurrentDistance = currentDistance }); }
private static void CalculateRentTest() { Write("Podaj imię: "); string firstName = ReadLine(); Write("Podaj nazwisko: "); string lastName = ReadLine(); var rentee = new Man(); rentee.FirstName = firstName; rentee.LastName = lastName; Product item = new CrossCountrySki { Id = 1, PricePerHour = 50, Name = "Fisher", Size = 150, }; var rent = new Rent(rentee, item) { Id = 1, }; // zwrot Thread.Sleep(TimeSpan.FromSeconds(1)); rent.Return(); ICalculatorFactory calculatorFactory = new CalculatorFactory(); ICostCalculator calculator = calculatorFactory.Create(rent); rent.Cost = calculator.Calculate(rent); }
public void Start() { var log = new Logger(); try { var indicators = _indicatorService.GetGlobalIndicators(); var findRequest = new FindCompaniesForJobRequest() { JobId = Guid.NewGuid().ToString(), MaxRecordCount = 10, SectorId = 0 }; var companies = _companyService.FindCompaniesForJob(findRequest); var sectorResult = new GlobalIndicatorResults(0); while (companies != null && companies.Any()) { foreach (var company in companies) { foreach (var indicator in indicators) { var result = CalculateIndicators(company, indicator); sectorResult.Add(result, indicator, company.Ticker); } log.Info($"Processed {company.Ticker}"); } _companyService.CompleteJob(new CompleteJobRequest { JobId = findRequest.JobId, Tickers = companies.Select(c => c.Ticker).ToList() }); companies = null; // _companyService.FindCompaniesForJob(findRequest); } var indicatorResults = sectorResult.IndicatorResults.Select(i => i.Value).ToList(); if (indicatorResults.Any()) { var tickers = indicatorResults.First().Select(r => r.Ticker).ToList(); foreach (var indicatorResult in indicatorResults) { var calculator = _processorFactory.Create(indicatorResult.Indicator); var result = calculator.Merge(indicatorResult); _globalIndicatorService.Save(new GlobalIndicator { SectorId = 0, //sector.SectorId, IndicatorId = indicatorResult.Indicator.IndicatorId, Values = result, StartDate = result.Last().Date, EndDate = result.First().Date, CalculatedSuccessful = true, CompanyCount = tickers.Count, LastCalculated = DateTime.UtcNow }).GetAwaiter().GetResult(); } } } catch (Exception ex) { log.Error("FindCompaniesForJob", ex); } }
public CalculatorProxy() { _cache = new Cache(); _calculator = CalculatorFactory.Create(false); }
public void Create_TypeOfIDisposable_ThrowsNotSupportedException() { Assert.That(() => CalculatorFactory.Create <IDisposable>(), Throws.InstanceOf <NotSupportedException>()); }
public void Create_TypeOfISecurityCalculator_ResultIsInstanceOfSecurityCalculator() { Object actual = CalculatorFactory.Create <ISecurityCalculator>(); Assert.That(actual, Is.InstanceOf <SecurityCalculator>()); }
public void Create_TypeOfIEntropyCalculator_ResultIsInstanceOfEntropyCalculator() { Object actual = CalculatorFactory.Create <IEntropyCalculator>(); Assert.That(actual, Is.InstanceOf <EntropyCalculator>()); }