Esempio n. 1
0
        public void SaveToXml()
        {
            //
            // should be called only once to create defaul data.
            //
            DbConnectData data = new DbConnectData()
            {
                DbName   = "pvpnetthing",
                Password = "******",
                UserName = "******"
            };

            StreamWriter  file   = null;
            XmlSerializer writer = new XmlSerializer(data.GetType());

            try
            {
                file = new StreamWriter("dbConnect.xml");
                writer.Serialize(file, data);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }
                ;
            }
        }
Esempio n. 2
0
        public DbConnectData GetData()
        {
            StreamReader  file   = null;
            DbConnectData data   = new DbConnectData();
            XmlSerializer writer = new XmlSerializer(typeof(DbConnectData));

            if (!File.Exists("dbConnect.xml"))
            {
                return(data);
            }

            try
            {
                file = new StreamReader("dbConnect.xml");
                data = (DbConnectData)writer.Deserialize(file);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }
            }

            return(data);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            // Get our database connect data, will eventually be hard coded or accessed via a web API
            DbConnectData data = DbConnectData.FromFile("DBConfig.txt.local");

            // Create and init that database
            PgDatabase database = new PgDatabase();

            database.Init(data);

            // Assign the database connection to the DA
            DataAccess.Database = database;

            // Make our winforms view manager and assign it to the view manager
            ViewManager.Implementation = new WinformViewManager();
            // Reflection load all our views
            ViewManager.Implementation.ReflectLoadViews();

            // Create our auth handler
            Auth.Implementation = new NerdAuth();
            Auth.User           = null;

            // Reflection load our rules and actions
            LogicManager.LoadRules();
            LogicManager.LoadActions();

            // Run the application, starting at the Login form
            ViewManager.Run("Login");
        }
Esempio n. 4
0
        /// <summary>
        /// Handles initializing the database conenction
        /// </summary>
        /// <param name="connectData"></param>
        public void Init(DbConnectData connectData)
        {
            // Build the connection from the connection data
            NpgsqlConnectionStringBuilder builder = new NpgsqlConnectionStringBuilder();

            builder.Username = connectData.Username;
            builder.Password = connectData.Password;
            builder.Port     = connectData.Port == -1 ? builder.Port : connectData.Port;
            builder.Host     = Dns.GetHostEntry(connectData.Host).AddressList[0].ToString();
            builder.Database = connectData.Database;

            // Create and open our connection
            myDatabaseConnection = new NpgsqlConnection(builder);
            myDatabaseConnection.Open();

            // We haven't failed yet! :D
            LastFailReason = null;

            // Sleep until the connection has been opened
            while ((ConnectionObject as NpgsqlConnection).State != System.Data.ConnectionState.Open)
            {
                Thread.Sleep(1);
            }
        }