/** * Storage * The one and the only final constructor for the Storage entity, * in order to create new instance use the create method. * If any failure ( connection, authorization ) occur the PlanckDBException will be thrown * @param dbProperties * @throws PlanckDBException */ private Storage(DBProperties dbProperties) { ValidateProperties(dbProperties); DependencyInjectorFactory dependencyInjectorFactory = new DependencyInjectorFactory(); dependencyInjectorFactory.RegisterClass(typeof(Registry), typeof(Registry)); dependencyInjectorFactory.RegisterClass(typeof(Core), typeof(VersionCore)); dependencyInjectorFactory.RegisterClass(typeof(SchemaAdapter), typeof(SchemaAdapter)); dependencyInjectorFactory.RegisterClass(typeof(CommandQueue), typeof(CommandQueue)); dependencyInjectorFactory.RegisterClass(typeof(SchemaImpl), typeof(SchemaImpl)); dependencyInjectorFactory.RegisterClass(typeof(Schema), typeof(SchemaImpl)); dependencyInjectorFactory.RegisterClass(typeof(TcpConversationPuller), typeof(TcpConversationPuller)); dependencyInjectorFactory.RegisterClass(typeof(DistributionManager), typeof(DistributionManagerImpl)); dependencyInjectorFactory.RegisterClass(typeof(DBProperties), typeof(DBProperties)); dependencyInjectorFactory.RegisterClass(typeof(CoreManager), typeof(CoreManager)); dependencyInjectorFactory.RegisterClass(typeof(CommandExecutor), typeof(CommandExecutor)); dependencyInjectorFactory.RegisterClass(typeof(MulticastConnectionHolder), typeof(DistributionManagerImpl)); dependencyInjectorFactory.RegisterClass(typeof(BroadcastTcpConnectionHolder), typeof(DistributionManagerImpl)); dependencyInjectorFactory.RegisterClass(typeof(UdpConnectionHolder), typeof(DistributionManagerImpl)); dependencyInjectorFactory.RegisterClass(typeof(TcpConnectionHolder), typeof(DistributionManagerImpl)); dependencyInjectorFactory.RegisterClass(typeof(AtomicContainer), typeof(AtomicContainer)); dependencyInjectorFactory.RegisterClass(typeof(TransactionalTemporaryIdProvider), typeof(TransactionalTemporaryIdProvider)); dependencyInjectorFactory.RegisterClass(typeof(CommandBuilder), typeof(CommandBuilder)); coreManager = (CoreManager)dependencyInjectorFactory.CreateInstance(typeof(CoreManager), dbProperties); coreManager.Activate(); }
public static DBProperties createProperties() { Dictionary<string, string> dictionary = new Dictionary<string, string>(); foreach (var row in File.ReadAllLines("conf.properties")) { if (!row.StartsWith("#") && ! (row.Length==0)) { dictionary.Add(row.Split('=')[0], string.Join("=", row.Split('=').Skip(1).ToArray())); } } DBProperties dbProperties = new DBProperties(); dbProperties.setIp(dictionary["ip"]); dbProperties.setPort(Int32.Parse(dictionary["port"])); dbProperties.setUseMulticast(Boolean.Parse(dictionary["useMulticast"])); dbProperties.setMulticastIp(dictionary["multicastIp"]); dbProperties.setMulticastPort(Int32.Parse(dictionary["multicastPort"])); dbProperties.setUseUDP(Boolean.Parse(dictionary["useUDP"])); dbProperties.setNetworkInterface(dictionary["networkInterface"]); dbProperties.setNumberOfUDPConnections(Int32.Parse(dictionary["numberOfUDPConnections"])); dbProperties.setFirstUDPPortNumber(Int32.Parse(dictionary["firstUDPPortNumber"])); dbProperties.setUserName(dictionary["userName"]); dbProperties.setPassword(dictionary["password"]); return dbProperties; }
public static Storage Create(DBProperties properties) { return new Storage(properties); }
private void ValidateProperties(DBProperties dbProperties) { String userName = dbProperties.GetUserName(); String password = dbProperties.GetPassword(); String ip = dbProperties.GetIp(); int port = dbProperties.GetPort(); if (userName == null) { throw new PlanckDBException(CommandStatus.userNameIsNull); } if (password == null) { throw new PlanckDBException(CommandStatus.passwordIsNull); } if (ip == null) { throw new PlanckDBException(CommandStatus.ipIsNull); } if (port < 0) { throw new PlanckDBException(CommandStatus.notValidPortNumber); } }
private void connectToSchemaWithWrongPassword() { try { DBProperties properties = new DBProperties(); properties.setPassword(""); Storage storage = Storage.Create(properties); storage.LoginToSchema("blabal"); } catch (Exception e) { PlanckDBException exception = (PlanckDBException)e; CommandStatus status = exception.GetStatus(); if (status == CommandStatus.failToAuthenticateUser) { Console.WriteLine("OK"); } else { Console.WriteLine("FAIL"); } } }