public WinServiceHostBase(string serviceName, IEnumerable <IRuntimeService> services, IAbstractLogger logger) { _logger = logger; WinServiceName = ServiceName = serviceName; _services = services; _stateMachine = StateMachine <RuntimeServiceState> .Create().SetName(serviceName).UseLogger(logger).UseStateDef(new RuntimeServiceStateDef()) .TransitionTable(RuntimeServiceState.Stopped) .AddTrans(RuntimeServiceState.Started, start) .AddTrans(RuntimeServiceState.Closed, close) .Build() .TransitionTable(RuntimeServiceState.Started) .AddTrans(RuntimeServiceState.Stopped, stop) .AddTrans(RuntimeServiceState.Suspended, suspend) .Build() .TransitionTable(RuntimeServiceState.Suspended) .AddTrans(RuntimeServiceState.Stopped, close) .AddTrans(RuntimeServiceState.Started, resume) .Build() .Build(); _stateMachine.StateChanging += stateChangingHndl; _stateMachine.StateChanged += stateChangedHandler; }
public ServerMonitor(int monitorPeriodMS, T monitorActivity, IAbstractLogger logger, params IMonitorable <T>[] controlables) { _monitorPeriodMS = monitorPeriodMS; _monitorActivity = monitorActivity; _logger = logger; _controlables = controlables; }
public MailServerSender(IAbstractLogger logger, int maxRetry, int retryTimeSeconds, int maxParallelMessages, ISmtpClientFactory clifac) { _maxRetry = maxRetry; _retryTimeSeconds = retryTimeSeconds; _maxParallelMessages = maxParallelMessages; _clifac = clifac; _logger = logger; _cancelSrc = new CancellationTokenSource(); _token = _cancelSrc.Token; }
public MainForm(IAbstractLogger logger) { _logger = logger; InitializeComponent(); treeDirs.Sorted = true; treeDirs.TreeViewNodeSorter = new TreeNodeDirectoryComparer(); lstCurDir.Sorting = SortOrder.Ascending; lstCurDir.ListViewItemSorter = new ListViewDirectoryComparer(true); }
private void ButtonBuildExtremums_Click(object sender, RoutedEventArgs e) { InputData inData = new InputData(); inData.LoadFromDirectory(symbolChooser.SelectedItemPath, null); IAbstractLogger logger = (LoggerMessage as IAbstractLogger); int tp = Int32.Parse(TextBoxTP.Text); int startTime = Int32.Parse(TextBoxStartTradeHour.Text); int endTime = Int32.Parse(TextBoxEndTradeHour.Text); logger.AddLog("syn" + " = {" + Analyse(inData, tp, startTime, endTime).ToString() + "};", IAbstractLoggerMessageType.General); }
private void ButtonCombine_Click(object sender, RoutedEventArgs e) { List <InputData> listInputData = new List <InputData>(); foreach (SymbolChooser.SymbolViewItem svi in symbolChooser.SymbolViewItems) { InputData inData = new InputData(); inData.LoadFromDirectory(svi.FullPath, null); listInputData.Add(inData); } QuotesBuilder quotesBuilder = new QuotesBuilder(listInputData, TickHistory.tickInOneMinute); List <PartialQuote> listPartialQuotes = new List <PartialQuote>(); listPartialQuotes.Add(new PartialQuote("EURUSD", 0.5)); listPartialQuotes.Add(new PartialQuote("GBPUSD", 0.5)); InputData inputData = quotesBuilder.BuildForPeriod(listPartialQuotes); IAbstractLogger logger = (LoggerMessage as IAbstractLogger); int tp = Int32.Parse(TextBoxTP.Text); logger.AddLog("syn" + " = {" + Analyse(inputData, tp, 0, 0).ToString() + "};", IAbstractLoggerMessageType.General); foreach (InputData currInputData in listInputData) { logger.AddLog(currInputData.Symbol + " = {" + Analyse(currInputData, tp, 0, 0).ToString() + "};", IAbstractLoggerMessageType.General); } //StringBuilder builder = new StringBuilder(); //int max = inputData.Data.Max(p => p.OpenAsk); //int min = inputData.Data.Min(p => p.OpenAsk); //builder.AppendLine("Max for syntetic = " + (max - QuotesBuilder.StartValue).ToString()); //builder.AppendLine("Min for syntetic = " + (QuotesBuilder.StartValue - min).ToString()); //foreach (InputData currInputData in listInputData) //{ // builder.AppendLine(string.Format("Max for {0} = {1}", currInputData.Symbol, // currInputData.Data.Max(p => p.OpenAsk) - currInputData.Data.First().OpenAsk)); // builder.AppendLine(string.Format("Min for {0} = {1}", currInputData.Symbol, // currInputData.Data.Min(p => p.OpenAsk) - currInputData.Data.First().OpenAsk)); //} //logger.AddLog(builder.ToString(), IAbstractLoggerMessageType.General); int k = 9; }
private void ButtonCalculateTimeForPips_Click(object sender, RoutedEventArgs e) { IAbstractLogger logger = (LoggerMessage as IAbstractLogger); logger.AddLog("Start CalculateTimeForPips"); foreach (SymbolChooser.SymbolViewItem svi in symbolChooser.SymbolViewItems) { string stringSide = "buy"; double value = Analysis.ResetTimeAnalysis.CalculateTimeOfOnePips(svi.FullPath, svi.Symbol, Analysis.ResetTimeAnalysis.SideAnalyser.Buy); logger.AddLog(string.Format("{0} {1} = {2}", svi.Symbol, stringSide, value)); stringSide = "sell"; value = Analysis.ResetTimeAnalysis.CalculateTimeOfOnePips(svi.FullPath, svi.Symbol, Analysis.ResetTimeAnalysis.SideAnalyser.Sell); logger.AddLog(string.Format("{0} {1} = {2}", svi.Symbol, stringSide, value)); } logger.AddLog("Finished CalculateTimeForPips"); }
bool _donotStartService; //используется командами, которые предусматривают иные действия, чем запуск сервиса public WinServiceHostBootstrap(string serviceName, IAbstractLogger logger) { if (logger == null) { throw new ArgumentException("Logger is not specified)"); } _logger = logger; ServiceName = serviceName; RegisterCommandSwitch("reg", "Registering service", (x) => { _donotStartService = true; registerWinService(true); }); RegisterCommandSwitch("service", "Registering service", (x) => { _donotStartService = true; registerWinService(true); }); RegisterCommandSwitch("regserver", "Registering service", (x) => { _donotStartService = true; registerWinService(true); }); RegisterCommandSwitch("unreg", "Unregistering service", (x) => { _donotStartService = true; registerWinService(false); }); RegisterCommandSwitch("unregserver", "Unregistering service", (x) => { _donotStartService = true; registerWinService(false); }); RegisterCommandSwitch("test", "Starting as a console application", (x) => _testMode = true); }
public StateMachine(string name, IAbstractLogger logger, StateDef <TState> stateDef, Dictionary <TState, TransitionDef <TState>[]> transitionMap, bool logTransitions = true) { if (logger == null) { throw new ArgumentNullException("logger"); } _logger = logger; _stateTransitions = new Dictionary <TState, TransitionDef <TState>[]>(); _logTransitions = logTransitions; foreach (var kv in transitionMap) { TransitionDef <TState>[] tmp = (TransitionDef <TState>[])kv.Value.Clone(); Array.Sort <TransitionDef <TState> >(tmp); _stateTransitions.Add(kv.Key, tmp); } _state = stateDef; Name = name; }
public RuntimeServiceBase(string serviceName, int order, IAbstractLogger logger) { _logger = logger; StartingOrder = order; _stateMachine = StateMachine <RuntimeServiceState> .Create().SetName(serviceName).UseLogger(logger).UseStateDef(new RuntimeServiceStateDef()) .TransitionTable(RuntimeServiceState.Stopped) .AddTrans(RuntimeServiceState.Started, Starting) .AddTrans(RuntimeServiceState.Closed, Closing) .Build() .TransitionTable(RuntimeServiceState.Started) .AddTrans(RuntimeServiceState.Stopped, Stopping) .AddTrans(RuntimeServiceState.Suspended, Suspending) .Build() .TransitionTable(RuntimeServiceState.Suspended) .AddTrans(RuntimeServiceState.Stopped, Closing) .AddTrans(RuntimeServiceState.Started, Resuming) .Build() .Build(); }
public SingleThreadSequentialExecuter(String name, IAbstractLogger logger) { Name = name; _logger = logger; createThread(); }
static public void RunCalculatePortfolio2(string pathString, PortfolioCalculationType portType, IAbstractLogger logger) { double initialDeposit = Double.Parse(ConfigurationManager.AppSettings["InitialDeposit"]); double reliability = Double.Parse(ConfigurationManager.AppSettings["Reliability"]); int loss = Int32.Parse(ConfigurationManager.AppSettings["Loss"]); double minVolume = Double.Parse(ConfigurationManager.AppSettings["MinVolume"]); double minMarginLevel = Double.Parse(ConfigurationManager.AppSettings["MinMarginLevel"]); PortfolioRawData portRawData = new PortfolioRawData(); foreach (string path in Directory.GetDirectories(pathString)) { logger.AddLog(string.Format("Loading {0}", path), IAbstractLoggerMessageType.General); SymbolResult input = SymbolResult.Load(path); foreach (TestResult currTestResult in input.testResults) { try { string testResultName = Path.GetFileName(path) + "_" + currTestResult.Name; logger.AddLog(string.Format("Analyzing {0}", testResultName), IAbstractLoggerMessageType.General); PairAdapter adapter = new PairAdapter(testResultName, currTestResult, "TP", "OpenOrderShift"); portRawData.AddPortfolioRawItems(adapter.ProcessAndFill()); } catch (ArgumentException exc) { logger.AddLog("Exception: " + exc.Message, IAbstractLoggerMessageType.Error); } } } logger.AddLog(string.Format("Calculating Portfolio"), IAbstractLoggerMessageType.General); double[,] equity, margin; // portRawData.AddInversePortfolioRawItem(); portRawData.FillArraysForScienceStyleGuys(out equity, out margin); Mathematics.Portfolio theBestPortfolio = null; int iterationsNumber = 100; double lossResult = 0; for (int iteration = 1; iteration < iterationsNumber; ++iteration) { double calculatedLoss = loss * iteration / iterationsNumber; Mathematics.Portfolio portfolio; switch (portType) { case PortfolioCalculationType.CalculateLinearFast: portfolio = Mathematics.Portfolio.CalculateLinearFast(equity, margin, initialDeposit, reliability, calculatedLoss, minMarginLevel, minVolume); break; case PortfolioCalculationType.CalculateLinearFastWithoutCorrelation: Mathematics.PortfolioInput pInput = new Mathematics.PortfolioInput(); pInput.Equity = equity; pInput.Reliability = reliability; pInput.MaximumLoss = calculatedLoss; pInput.InitialDeposit = initialDeposit; pInput.MarginLevelThreshold = minMarginLevel; pInput.Margin = margin; pInput.MinimumCoefficientValue = minVolume; portfolio = Mathematics.Portfolio.CalculateLinearFastWithoutCorrelation(pInput); break; default: throw new ApplicationException("Not supported PortfolioCalculationType"); } if (portfolio.Coefficients.Count(p => p > 0) < 5) { continue; } if (null == theBestPortfolio) { theBestPortfolio = portfolio; lossResult = calculatedLoss; } else if (theBestPortfolio.Profit < portfolio.Profit) { theBestPortfolio = portfolio; lossResult = calculatedLoss; } } logger.AddLog(string.Format("Writing portfolio to file"), IAbstractLoggerMessageType.General); using (StreamWriter stream = new StreamWriter(Path.Combine(pathString, "portfolio.txt"))) { double[] coefficients = theBestPortfolio.Coefficients; int i = 0; foreach (PortfolioRawItem currPortfolioRawItem in portRawData.portfolioRawItems) { stream.WriteLine("[Symbol = {0}; {1}] = {2}", currPortfolioRawItem.Symbol, currPortfolioRawItem.StrategyParameter.ToString(';'), coefficients[i++]); } stream.WriteLine("daily profit = {0}", theBestPortfolio.Profit); stream.WriteLine("When = {0}", theBestPortfolio.When); stream.WriteLine("Loss = {0}", lossResult); } }
public CustomUserAuthenticator(IAbstractLogger logger) { _logger = logger; }
public MainForm(IAbstractLogger logger) { _logger = logger; InitializeComponent(); }
public ThreadPoolSequentialExecuter(IAbstractLogger logger, string name = null) { _logger = logger; Name = string.IsNullOrEmpty(name) ? "Unnamed":name; _tmPostoned = new Timer(processPostponed, null, 2 * CommandPostponeTimeMS, CommandPostponeTimeMS); }
public StateMachineBuilder <TState> UseLogger(IAbstractLogger logger) { _logger = logger; return(this); }