static void Main(string[] args) { var delay = TimeSpan.FromSeconds(.002); using (var server = Server.Create("StreamInsightTest")) { var applicaiton = server.CreateApplication("StreamInsightDemo"); var input = applicaiton.DefineObservable((DateTimeOffset? _) => CsvReader.Read("sample.csv").RateLimit(delay, Scheduler.ThreadPool)); var inputStream = input.ToPointStreamable(x => x, AdvanceTimeSettings.UnorderedStartTime(TimeSpan.FromSeconds(15))); var query = from x in inputStream.TumblingWindow(TimeSpan.FromSeconds(10)) select new Payload { X = x.Avg(p => p.X), Y = x.Avg(p => p.Y) }; var output = applicaiton.DefineObserver((DateTimeOffset? hwm, int offset) => CsvWriter.Write("output.csv", true)); query.Bind(output).Run(); Console.ReadLine(); } }
public static void Go() { var delay = TimeSpan.FromSeconds(.002); var metaConfig = new SqlCeMetadataProviderConfiguration { DataSource = "metadata.db", CreateDataSourceIfMissing = true }; // Set up checkpointing. This needs a location to place the log files. var chkConfig = new CheckpointConfiguration { LogPath = "log", CreateLogPathIfMissing = true }; using (var server = Server.Create("Default", metaConfig, chkConfig)) { string appName = "CheckpointingDemo"; string procName = "myProc"; Application app; if (!server.Applications.TryGetValue(appName, out app)) { app = server.CreateApplication(appName); } CepProcess proc; if (app.Processes.TryGetValue(procName, out proc)) { Console.WriteLine("Resuming process..."); proc.Resume(); } else { Console.WriteLine("Creating process..."); // Without replay: //var csvIn = app.DefineEnumerable(() => XYCsvReader.Read("sample.csv").RateLimit(delay)); // With replay: var csvIn = app.DefineObservable((DateTimeOffset? hwm) => XYCsvReader.Read("sample.csv", hwm).RateLimit(delay, Scheduler.ThreadPool)); var csvStream = csvIn.ToPointStreamable(x => x, AdvanceTimeSettings.UnorderedStartTime(TimeSpan.FromSeconds(15))); var q = from x in csvStream.TumblingWindow(TimeSpan.FromMinutes(1)) select new XYPayload { X = x.Avg(p => p.X), Y = x.Avg(p => p.Y) }; // Without de-duplication: //var csvOut = app.DefineObserver(() => XYCsvWriter.Write("results.csv", true)); // With de-duplication: var csvOut = app.DefineObserver((DateTimeOffset? hwm, int offset) => XYCsvWriter.Write("output.csv", true, hwm, offset)); proc = q.Bind(csvOut).RunCheckpointable(procName); } using (CheckpointLoop(server, app.CheckpointableProcesses[procName], TimeSpan.FromSeconds(1))) { Console.WriteLine("Started checkpointing... Press enter to shut down normally..."); Console.ReadLine(); } Console.WriteLine("Deleting process and exiting."); app.Processes[procName].Delete(); } }