예제 #1
0
            private void LogPublishedDate <T>(object sender, T e) where T : DataUpdateEventArgs
            {
                var publishedDate = pipeline
                                    .GetElement <DeviceDetectionHashEngine>()
                                    .DataFiles
                                    .Single()
                                    .DataPublishedDateTime;

                if (e is DataUpdateCompleteArgs completeArgs)
                {
                    Console.WriteLine($"Update completed. Status {completeArgs.Status}");
                    // Set the event wait handler once the update is completed.
                    ewh.Set();
                }
                else
                {
                    Console.WriteLine($"Update started for {e.DataFile.DataFilePath}");
                }

                Console.WriteLine($"Data file published date: {publishedDate}");
            }
예제 #2
0
 TElement IPipeline.GetElement <TElement>()
 {
     return(_pipeline.GetElement <TElement>());
 }
예제 #3
0
            public void Run(string originalDataFile, string licenseKey)
            {
                // Copy the original data file to another location as we do not
                // want to preserve the original for other examples.
                File.Copy(originalDataFile, dataFile, true);

                // Create an event wait handler to wait for the update complete
                //event so that the example runs during the update process.
                ewh = new EventWaitHandle(false, EventResetMode.AutoReset);

                FileInfo f = new FileInfo(dataFile);

                Console.WriteLine($"Using data file at '{f.FullName}'");

                // Construct our own data update service so we can monitor update events.
                var loggerFactory     = new LoggerFactory();
                var httpClient        = new HttpClient();
                var dataUpdateService = new DataUpdateService(loggerFactory.CreateLogger <DataUpdateService>(), httpClient);

                // Bind a method to the CheckForUpdateComplete event and
                // the CheckForUpdateStarted event which
                // prints the published date of the data file.
                dataUpdateService.CheckForUpdateComplete += LogPublishedDate;
                dataUpdateService.CheckForUpdateStarted  += LogPublishedDate;

                // Build a new Pipeline to use an on-premise Hash engine and
                // configure automatic updates.
                pipeline = new DeviceDetectionPipelineBuilder(loggerFactory, httpClient, dataUpdateService)
                           // Use the On-Premise engine (aka Hash engine) and pass in
                           // the path to the data file, your license key and whether
                           // to use a temporary file.
                           // A license key is required otherwise automatic updates will
                           // remain disabled.
                           .UseOnPremise(dataFile, licenseKey, true)
                           // Enable automatic updates.
                           .SetAutoUpdate(true)
                           // Watch the data file on disk and refresh the engine
                           // as soon as that file is updated.
                           .SetDataFileSystemWatcher(true)
                           // Disable update on startup
                           .SetDataUpdateOnStartUp(false)
                           // Set the frequency in seconds that the pipeline should
                           // check for updates to data files. A recommended
                           // polling interval in a production environment is
                           // around 30 minutes or 1800 seconds.
                           .SetUpdatePollingInterval(30)
                           // Set the max ammount of time in seconds that should be
                           // added to the polling interval. This is useful in datacenter
                           // applications where mulitple instances may be polling for
                           // updates at the same time. A recommended ammount in production
                           // environments is 600 seconds.
                           .SetUpdateRandomisationMax(10)
                           .Build();

                // Get the published date of the data file from the Hash engine
                // after building the pipeline.
                var publishedDate = pipeline
                                    .GetElement <DeviceDetectionHashEngine>()
                                    .DataFiles
                                    .Single()
                                    .DataPublishedDateTime;

                Console.WriteLine($"Initial data file published date: {publishedDate}");

                Console.WriteLine($"The pipeline has now been set up to poll for updates every {updatePollingInterval} seconds, " +
                                  $"a random ammount of time up to {pollingIntervalRandomisation} seconds will be added.");

                // Wait for the update complete event.
                ewh.WaitOne();
            }