private void CheckConfig() { _hasConfig = (txtApiKey.Text.Length > 0 && txtSiteUrl.Text.Length > 0); if (_hasConfig) { OrgApiCalls.ApiKey = txtApiKey.Text; OrgApiCalls.SiteUrl = txtSiteUrl.Text; _siteConfig = OrgApiCalls.GetSiteConfig(); txtDomainName.Text = _siteConfig.OnPremDomainName; txtSiteID.Text = _siteConfig.Id; ADTools.ADDomainName = _siteConfig.OnPremDomainName; txtSiteType.Text = _siteConfig.SiteType.ToString(); SaveConfig(); lstRemoteDomainList.Items.Clear(); lstRemoteDomainList.Items.AddRange(_siteConfig.SiteDomains.ToArray()); CheckDomainsToUpns(); } else { MessageBox.Show("Please configure your API Key and Site URL before confirming your config.", "Need Config", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } }
static void Main(string[] args) { var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _scriptFolderPath = args.Where(a => a.StartsWith("-scriptPath")).FirstOrDefault(); if (_scriptFolderPath != null) { _scriptFolderPath = _scriptFolderPath.Split(':')[1]; } else { _scriptFolderPath = Path.GetFullPath(string.Format("{0}\\Scripts", dir)); } ServiceName = Assembly.GetCallingAssembly().GetCustomAttribute <AssemblyTitleAttribute>().Title; ConsoleLogSource = String.Format("{0}-console", ServiceName); ServiceUtil.AssemblyName = AssemblyName; ServiceUtil.ServiceName = ServiceName; PrintLogo(); if (args.Any(a => a == "-debug")) { _isDebug = true; } var sUrl = ConfigurationManager.AppSettings["SiteUrl"]; var sDebugUrl = ConfigurationManager.AppSettings["DebugSiteUrl"]; _timerIntervalMinutes = Convert.ToInt16(ConfigurationManager.AppSettings["TimerIntervalMinutes"]); OrgApiCalls.ApiKey = ConfigurationManager.AppSettings["ApiKey"]; OrgApiCalls.SiteUrl = (_isDebug) ? sDebugUrl : sUrl; ConsoleLogSource = Utils.SetupLog(ConsoleLogSource); try { RemoteSite siteConfig = null; try { siteConfig = OrgApiCalls.GetSiteConfig(); } catch (Exception) { WriteConsoleStatus("Failed retrieving site status"); } if (siteConfig == null) { throw new Exception("Unable to retrieve site configuration, exiting"); } var scriptConfig = GetJsonConfig(siteConfig, OrgApiCalls.SiteUrl); File.WriteAllText(Path.Combine(_scriptFolderPath, "SyncVars.json"), scriptConfig); ADTools.ADDomainName = siteConfig.OnPremDomainName; relay = new SigRClient(OrgApiCalls.SiteUrl, OrgApiCalls.ApiKey, "SiteHub", true); relay.StatusUpdate += Relay_StatusUpdate; relay.ErrorEvent += Relay_ErrorEvent; relay.PingEvent += Relay_PingEvent; InitTimers(siteConfig); relay.FireScriptEvent += Relay_FireScriptEvent; if (Environment.UserInteractive) { RunConsole(siteConfig, args); } else { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new SiteListenerService(relay, timer) }; ServiceBase.Run(ServicesToRun); } } catch (Exception ex) { var msg = Utils.GetFormattedException(ex); Utils.AddLogEntry(ConsoleLogSource, msg, EventLogEntryType.Error); } }