public override void Run() { var cs = RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"); var credentials = RoleEnvironment.GetConfigurationSettingValue("BasicAuthCredentials"); var url = RoleEnvironment.GetConfigurationSettingValue("SolrPublicUrl"); var logger = new SyncJobsLogger(cs); logger.CreateTableIfNotExists(); ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policy) => true; while (true) { DataImport(url, logger, credentials); int interval = 60; if (RoleEnvironment.GetConfigurationSettingValue("PollingIntervalInMinutes") != null) { int.TryParse(RoleEnvironment.GetConfigurationSettingValue("PollingIntervalInMinutes"), out interval); } Thread.Sleep(TimeSpan.FromMinutes(interval)); } }
public static void DataImport(string url, SyncJobsLogger logger, string credentials) { var address = url + "dataimport?command=delta-import"; try { var webClient = new WebClient(); if (!string.IsNullOrWhiteSpace(credentials)) { var usernameAndPassword = credentials.Split(';'); webClient.Credentials = new NetworkCredential(usernameAndPassword[0], usernameAndPassword[1]); } var description = webClient.DownloadString(address); logger.SaveJob(true, description, address); } catch (Exception ex) { logger.SaveJob(false, ex.ToString(), address); } }