private void WaitForServerToBeAvailable(PIConnection connection) { var isConnected = false; while (!isConnected) { isConnected = connection.Connect(); if (!isConnected) { _logger.InfoFormat("Could not connect to the server, waiting 5s to try to reconnect."); Thread.Sleep(TimeSpan.FromSeconds(5)); } if (_cancellationTokenSource.Token.IsCancellationRequested) { _logger.InfoFormat("Cancellation requested, exiting WaitForServerToBeAvailable"); return; } } }
private static void Main(string[] args) { TextWriter writer = Console.Out; try { var options = new CommandLineOptions(); if (Parser.Default.ParseArguments(args, options)) { if (args.Length <= 1) { Console.Write(options.GetUsage()); } if (options.Run != null && ValidateRunOptions(options.Run)) { _logger.Info("Option Run starting, will run the data replay continuously as a command line application."); var replayer = new Replayer(); replayer.RunFromCommandLine(options.Run[0], options.Run[1]); } if (options.deleteHistory != null && ValidateDeleteHistoryOptions(options.deleteHistory)) { _logger.Info("Delete History Option Selected, will deleted the specified data."); _logger.Info("This operation cannot be reversed, are you sure you want to delete the data you specified? Press Y to continue..."); var keyInfo = Console.ReadKey(); if (keyInfo.KeyChar != 'Y') { _logger.Info("Operation canceled"); } // getting the tags var piConnection = new PIConnection(options.deleteHistory[0]); piConnection.Connect(); var pointsProvider = new PIPointsProvider(options.deleteHistory[3], piConnection.GetPiServer()); foreach (var piPoint in pointsProvider.Points) { var st = AFTime.Parse(options.deleteHistory[1]); var et = AFTime.Parse(options.deleteHistory[2]); _logger.InfoFormat("Deleting history for tag: {0} between {1:G} and {2:G}", piPoint.Name, st.LocalTime, et.LocalTime); PIHelpers.DeleteValues(piPoint, st, et, options.ForceUpdateValuesMethod); } } } else { options.GetUsage(); } } catch (Exception ex) { Console.SetOut(writer); Console.WriteLine("Error: " + ex); } }