/// <summary> /// Our main routine. Reads in command line arguments indicating the name of the instance and app, /// as well as where to read and write data; starts up an instance w/ checkpointing enabled; and /// (re)starts a set of queries on that instance. /// </summary> /// <param name="args"> /// The command line arguments. We read: /// - The name of the instance to use. /// - The name of the app to use. /// - The input CSV file to read. /// - A path to write data under. /// </param> private static void Main(string[] args) { string instanceName = ConfigurationManager.AppSettings["instanceName"]; string appName = ConfigurationManager.AppSettings["appName"]; string targetPath = ConfigurationManager.AppSettings["targetPath"]; string dataFile = ConfigurationManager.AppSettings["dataFile"]; TimeSpan eventDelay = TimeSpan.Parse(ConfigurationManager.AppSettings["eventDelay"]); // Create the target path if needed. try { if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } } catch (Exception e) { throw new ArgumentException("Failed to create output path.", e); } // Set up the metadata configuration to use SQL CE. This is required to use checkpointing. var metaConfig = new SqlCeMetadataProviderConfiguration { DataSource = Path.Combine(targetPath, MetadataFileName), CreateDataSourceIfMissing = true }; // Set up resiliency. This needs a location to place the log files. var resConfig = new CheckpointConfiguration { LogPath = Path.Combine(targetPath, LogSubdirectoryName), CreateLogPathIfMissing = true }; try { // Create the server. using (Server server = Server.Create(instanceName, metaConfig, resConfig)) { // Create the host (primarily so that we can use the debugger.) //using (ServiceHost host = CreateWebService(server)) { // Create an AppManager to manage our application. using (AppManager appMgr = new AppManager(server, appName)) { // A dictionary of the queries we care about. These will be started or restarted as // needed by the Start() routine. var queries = new Dictionary<string, QueryCreator> { { "passthrough", (app, name, desc) => CreatePassthroughQuery(app, name, desc, dataFile, targetPath, eventDelay) }, { "aggregation", (app, name, desc) => CreateAggregationQuery(app, name, desc, dataFile, targetPath, eventDelay) }, { "buckets", (app, name, desc) => CreateBucketQuery(app, name, desc, dataFile, targetPath, eventDelay) }, }; foreach (var name in queries.Keys) { if (!appMgr.ContainsQuery(name)) { Util.Log("Main", "Adding query '" + name + "'"); appMgr.RunQuery(name, name, queries[name]); } else { Util.Log("Main", "Query '" + name + "' already in app."); } } appMgr.BeginCheckpointing(); // Stay alive until the user tells us to stop. Console.WriteLine("*** Press <enter> to end. ***"); Console.ReadLine(); appMgr.StopCheckpointing(); } } Console.WriteLine("*** Disposing server. ***"); } } catch (Exception e) { Console.WriteLine(e.ToString()); Console.ReadLine(); } Console.WriteLine("*** Exiting. ***"); }
/// <summary> /// Our main routine. Reads in command line arguments indicating the name of the instance and app, /// as well as where to read and write data; starts up an instance w/ checkpointing enabled; and /// (re)starts a set of queries on that instance. /// </summary> /// <param name="args"> /// The command line arguments. We read: /// - The name of the instance to use. /// - The name of the app to use. /// - The input CSV file to read. /// - A path to write data under. /// </param> private static void Main(string[] args) { string instanceName = ConfigurationManager.AppSettings["instanceName"]; string appName = ConfigurationManager.AppSettings["appName"]; string targetPath = ConfigurationManager.AppSettings["targetPath"]; string dataFile = ConfigurationManager.AppSettings["dataFile"]; TimeSpan eventDelay = TimeSpan.Parse(ConfigurationManager.AppSettings["eventDelay"]); // Create the target path if needed. try { if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } } catch (Exception e) { throw new ArgumentException("Failed to create output path.", e); } // Set up the metadata configuration to use SQL CE. This is required to use checkpointing. var metaConfig = new SqlCeMetadataProviderConfiguration { DataSource = Path.Combine(targetPath, MetadataFileName), CreateDataSourceIfMissing = true }; // Set up resiliency. This needs a location to place the log files. var resConfig = new CheckpointConfiguration { LogPath = Path.Combine(targetPath, LogSubdirectoryName), CreateLogPathIfMissing = true }; try { // Create the server. using (Server server = Server.Create(instanceName, metaConfig, resConfig)) { // Create the host (primarily so that we can use the debugger.) //using (ServiceHost host = CreateWebService(server)) { // Create an AppManager to manage our application. using (AppManager appMgr = new AppManager(server, appName)) { // A dictionary of the queries we care about. These will be started or restarted as // needed by the Start() routine. var queries = new Dictionary <string, QueryCreator> { { "passthrough", (app, name, desc) => CreatePassthroughQuery(app, name, desc, dataFile, targetPath, eventDelay) }, { "aggregation", (app, name, desc) => CreateAggregationQuery(app, name, desc, dataFile, targetPath, eventDelay) }, { "buckets", (app, name, desc) => CreateBucketQuery(app, name, desc, dataFile, targetPath, eventDelay) }, }; foreach (var name in queries.Keys) { if (!appMgr.ContainsQuery(name)) { Util.Log("Main", "Adding query '" + name + "'"); appMgr.RunQuery(name, name, queries[name]); } else { Util.Log("Main", "Query '" + name + "' already in app."); } } appMgr.BeginCheckpointing(); // Stay alive until the user tells us to stop. Console.WriteLine("*** Press <enter> to end. ***"); Console.ReadLine(); appMgr.StopCheckpointing(); } } Console.WriteLine("*** Disposing server. ***"); } } catch (Exception e) { Console.WriteLine(e.ToString()); Console.ReadLine(); } Console.WriteLine("*** Exiting. ***"); }