Пример #1
0
        /// <summary>
        /// Creates a StreamInsight server object using the in-process (hosted DLL) model.
        /// </summary>
        /// <param name="instanceName">Name of the StreamInsight instance</param>
        /// <param name="persistMetadata">True to persis metadata in SQL Server CE.</param>
        /// <param name="managementServiceUri">Uri of the management service. May be null.</param>
        /// <returns>The created StreamInsight server object</returns>
        /// <remarks>
        /// See http://msdn.microsoft.com/en-us/library/ff518487.aspx for information on
        /// setting security for the WCF management service url.
        /// </remarks>
        private static Server CreateServer(string instanceName, bool persistMetadata, Uri managementServiceUri)
        {
            Server server = null;

            if (persistMetadata) {
                //Create the metadata configuration.
                //Use the assembly name for the sdf.
                SqlCeMetadataProviderConfiguration metadataProviderConfiguration = new SqlCeMetadataProviderConfiguration() {
                    CreateDataSourceIfMissing = true,
                    DataSource = System.Reflection.Assembly.GetEntryAssembly().GetName().Name + ".sdf"
                };

                server = Server.Create(instanceName, metadataProviderConfiguration);
            } else {
                server = Server.Create(instanceName);
            }

            if (managementServiceUri != null) {
                //NOTE: You may get an exception her if you do not have the required permissions.
                try {
                    _managementServiceHost = new ServiceHost(server.CreateManagementService());
                    _managementServiceHost.AddServiceEndpoint(typeof(IManagementService), new WSHttpBinding(SecurityMode.Message), managementServiceUri);
                    _managementServiceHost.Open();
                } catch (Exception ex) {
                    //TODO: Continue or throw exception when management service cannot be created?
                    Console.WriteLine("Failed to open management service: ");
                    Console.WriteLine(ex.GetType().Name + ":" + ex.Message);
                }
            }
            return server;
        }
Пример #2
0
        /// <summary>
        /// Creates a StreamInsight server object using the in-process (hosted DLL) model.
        /// </summary>
        /// <param name="instanceName">Name of the StreamInsight instance</param>
        /// <param name="persistMetadata">True to persis metadata in SQL Server CE.</param>
        /// <param name="managementServiceUri">Uri of the management service. May be null.</param>
        /// <returns>The created StreamInsight server object</returns>
        /// <remarks>
        /// See http://msdn.microsoft.com/en-us/library/ff518487.aspx for information on
        /// setting security for the WCF management service url.
        /// </remarks>
        private static Server CreateServer(string instanceName, bool persistMetadata, Uri managementServiceUri)
        {
            Server server = null;

            if (persistMetadata)
            {
                //Create the metadata configuration.
                //Use the assembly name for the sdf.
                SqlCeMetadataProviderConfiguration metadataProviderConfiguration = new SqlCeMetadataProviderConfiguration()
                {
                    CreateDataSourceIfMissing = true,
                    DataSource = System.Reflection.Assembly.GetEntryAssembly().GetName().Name + ".sdf"
                };

                server = Server.Create(instanceName, metadataProviderConfiguration);
            }
            else
            {
                server = Server.Create(instanceName);
            }

            if (managementServiceUri != null)
            {
                //NOTE: You may get an exception her if you do not have the required permissions.
                try {
                    _managementServiceHost = new ServiceHost(server.CreateManagementService());
                    _managementServiceHost.AddServiceEndpoint(typeof(IManagementService), new WSHttpBinding(SecurityMode.Message), managementServiceUri);
                    _managementServiceHost.Open();
                } catch (Exception ex) {
                    //TODO: Continue or throw exception when management service cannot be created?
                    Console.WriteLine("Failed to open management service: ");
                    Console.WriteLine(ex.GetType().Name + ":" + ex.Message);
                }
            }
            return(server);
        }
Пример #3
0
        /// <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. ***");
        }
Пример #4
0
        /// <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. ***");
        }
Пример #5
0
        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();
            }
        }