private static Playback InitPlayback(Settings settings) { Playback playback; try { playback = new Playback((int)settings.PLAYBACK_DEV_OUT); if (playback.OutDevNumber < 0 || playback.OutDevNumber > playback.OutputsCount) { ProgramOutput.Error("Cannot initialize playback, invalid output device index. Index must be between 0 and {1}.", playback.OutputsCount); return(null); } } catch (Exception ex) { ProgramOutput.Error("Cannot initialize playback audio output, error: {0}", ex.Message); return(null); } MasterContainer.AddService <Playback>(playback); ProgramOutput.Info("Playback initialized, output set to: device index = {0} - ({1}).", playback.OutDevNumber, playback.OutName); return(playback); }
private static RsaCrpyter InitCrypter(Settings settings) { RsaCrpyter crypter = null; string keyFile = settings.KEYS_FILE; if (File.Exists(keyFile)) { string xml = null; try { ProgramOutput.Info("Loading RSA key pair from file {0}...", keyFile); xml = File.ReadAllText(keyFile); } catch { ProgramOutput.Error("Error accessing RSA key file {0}. Please check permissions to this file.", keyFile); Console.ReadKey(true); return(null); } try { crypter = new RsaCrpyter(xml); } catch { ProgramOutput.Error("Error parsing RSA key file {0}. Maybe the file is corrupted or invalid format. Please delete the file to generate new RSA key pair.", keyFile); Console.ReadKey(true); return(null); } } else { ProgramOutput.Info("Generating new RSA key pair into file {0}...", keyFile); crypter = new RsaCrpyter(); string xml = crypter.GetFullXmlConfig(); try { File.WriteAllText(keyFile, xml); } catch { ProgramOutput.Error("Error accessing RSA key file {0}. Please check permissions to this file.", keyFile); Console.ReadKey(true); return(null); } } MasterContainer.AddService <RsaCrpyter>(crypter); ProgramOutput.Info("RSA crypto module successfuly initialized."); return(crypter); }
private static BroadcastScheduler InitScheduler(Settings settins, IBroadcastDatabase db, FileStore store, Playback playback) { BroadcastScheduler scheduler; try { scheduler = new BroadcastScheduler(db, store, playback, (int)settins.SCHEDULER_CHECK_INTERVAL); } catch { ProgramOutput.Error("Cannot initialize scheduler. Please check the scheduler parameters in config file."); return(null); } MasterContainer.AddService <BroadcastScheduler>(scheduler); return(scheduler); }
private static IAuthorizator InitAuthorizator(Settings settings) { // Init LDAP authorizator var authorizator = InitLdap(settings, delegate(LdapCredentials creds) { #if DEBUG var auth = new DummyAuthorizator(); #else var auth = new LdapAuthorizator(creds); auth.Connect(); #endif return(auth); }); var authorizatorCache = new AuthorizatorCache(authorizator, (int)settings.SECURITY_CACHE_EXPIRATION); MasterContainer.AddService <IAuthorizator>(authorizatorCache); // Load LDAP permission binding from def file var permissionCfgFile = Properties.Settings.Default.LDAP_PERMISSION_DEF_FILE; string[] permissionCfg; try { permissionCfg = File.ReadAllLines(permissionCfgFile); } catch (Exception ex) { ProgramOutput.Error("Cannot process LDAP permission binding file {0}, because of following reason:\r\n{1}", permissionCfgFile, ex.Message); return(null); } try { PermissionAttributeEditor.AddAttribFromConfig(permissionCfg, LdapAuthorizator.LDAP_GROUP_ATTRIBUTE, (groupName) => groupName.ToString()); } catch { ProgramOutput.Error("Cannot process LDAP permission binding file {0}. Invalid syntax."); return(null); } ProgramOutput.Error("Authorizator initialized, LDAP connection to {0} up.", authorizator.ConnectedServer); return(authorizatorCache); }
private static FileStore InitFileStore(Settings settings) { string path = settings.FILE_STORE_ROOT; FileStore store; try { store = new FileStore(path); } catch (UnauthorizedAccessException) { ProgramOutput.Error("Cannot init audio file store at location {0}. Permission denied.", path); return(null); } catch { ProgramOutput.Error("Cannot init audio file store at location {0}. Please check that the path is valid.", path); return(null); } MasterContainer.AddService <FileStore>(store); ProgramOutput.Info("Audio file store set to location: {0}.", store.PathRoot); return(store); }
private static T InitLdap <T>(Settings settings, Func <LdapCredentials, T> init) where T : class { var creds = new LdapCredentials(settings.LDAP_USERNAME, settings.LDAP_PASSWORD, settings.LDAP_DOMAIN, settings.LDAP_OU); try { return(init(creds)); } catch (System.DirectoryServices.AccountManagement.PrincipalServerDownException ex) { ProgramOutput.Error("LDAP server could not be contacted. Please ensure that machine DNS settings and DNS server is propely configured to reach domain controller. Also make sure that server is on the network.", ex); return(null); } catch (System.Security.Authentication.AuthenticationException ex) { ProgramOutput.Error("Connection to LDAP server failed, because of invalid credentials. Please check config file.", ex); return(null); } catch (Exception ex) { ProgramOutput.Error("Cannot init LDAP connection.", ex); return(null); } }
private static void LogIncident(Request request, Exception ex) { string message = (ex == null) ? request.ToString() : string.Format("{0}: {1}", (request != null) ? request.ToString() : "", ex.Message); ProgramOutput.Error(message); }