Exemple #1
0
        public DirectoryWatcher(String _dir, ClientServerConnection _client)
        {
            client = _client;
            dir    = _dir;

            start();
            //      listen();
        }
Exemple #2
0
        public ClientSetup()
        {
            ClientServerConnection.LogHandlers.Add(new ClientServerConnection.LoggingHandlerDelegate(logToConsole));

            // set up the defaults
            account            = new ClientAccount();
            account.ServerName = "localhost";
            account.ServerPort = Common.DefaultCommunicationPort;
            account.User       = "******";
            account.Password   = "******";

            configDir = ClientServerConnection.DefaultConfigDir;

            Console.WriteLine("Welcome to the Mybox client setup wizard");

            gatherInput();

            account.Directory = Common.EndDirWithSlash(account.Directory);
            configDir         = Common.EndDirWithSlash(configDir);

            // attach the account to the server to get the user
            ClientServerConnection client = new ClientServerConnection();

            Console.WriteLine("client initialized. trying coonection...");

            client.StartGetAccountMode(account);

            // data directory
            if (!Common.CreateLocalDirectory(account.Directory))
            {
                Console.WriteLine("Data directory could not be created: " + account.Directory);
                Common.ExitError();
            }

            // config directory
            if (!Common.CreateLocalDirectory(configDir))
            {
                Console.WriteLine("Config directory could not be created: " + configDir);
                Common.ExitError();
            }

            try {
                ClientServerConnection.SetConfigDir(configDir);
            } catch (Exception) {
                // toss config file not found exception since it is expected for a new setup
            }

            if (!saveConfig())
            {
                Console.WriteLine("Unable to save config file");
            }
            else
            {
                Console.WriteLine("Setup finished successfully");
            }
        }
Exemple #3
0
        private void gatherInput()
        {
            String input = null;

            Console.Write("Configuration directory [" + configDir + "]: ");
            input = Console.ReadLine();
            if (input != String.Empty)
            {
                configDir = input;
            }

            Console.Write("Data directory [" + account.Directory + "]: ");
            input = Console.ReadLine();
            if (input != String.Empty)
            {
                account.Directory = input;
            }

            Console.Write("Server [" + account.ServerName + "]: ");
            input = Console.ReadLine();
            if (input != String.Empty)
            {
                account.ServerName = input;
            }

            Console.Write("Server port [" + account.ServerPort + "]: ");
            input = Console.ReadLine();
            if (input != String.Empty)
            {
                account.ServerPort = int.Parse(input); //catch
            }
            // attempt to connect to the server to see if it is up
            Socket socket = ClientServerConnection.ConnectSocket(account.ServerName, account.ServerPort);

            if (socket == null)
            {
                Console.WriteLine("Unable to contact server");
                Common.ExitError();
            }

            Console.Write("User [" + account.User + "]: ");
            input = Console.ReadLine();
            if (input != String.Empty)
            {
                account.User = input;
            }

            Console.Write("Password [" + account.Password + "]: "); // TODO: bullet out console entry
            input = Console.ReadLine();

            if (input != String.Empty)
            {
                account.Password = input;
            }
        }
Exemple #4
0
    private void doWork()
    {
        mybox.ClientServerConnection.LogHandlers.Add(new mybox.ClientServerConnection.LoggingHandlerDelegate(logToFile));
        mybox.ClientServerConnection.LogHandlers.Add(new mybox.ClientServerConnection.LoggingHandlerDelegate(logToTextView));

        try {
            mybox.ClientServerConnection.SetConfigDir(mybox.ClientServerConnection.DefaultConfigDir); // quits if it fails
            client = new mybox.ClientServerConnection();

            client.LoadConfig(mybox.ClientServerConnection.ConfigFile);
            labelAccount.Text = "Account: " + client.Account.User;
            client.Start();
        } catch (Exception ec) {
            logToFile("Error: " + ec.Message);
            logToTextView("Error: " + ec.Message);
        }
    }
Exemple #5
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try {
                // only load the config, if it has not been loaded once already
                if (clientServerConnection == null || clientServerConnection.Account.User == null || clientServerConnection.Account.User == string.Empty)
                {
                    ClientServerConnection.SetConfigDir(ClientServerConnection.DefaultConfigDir); // quits if it fails
                    clientServerConnection = new ClientServerConnection();
                    clientServerConnection.LoadConfig(ClientServerConnection.ConfigFile);
                    labelAccount.Text = "Account: " + clientServerConnection.Account.User;
                }

                clientServerConnection.Start();
            } catch (Exception ex) {
                logToFile("Error: " + ex.Message);
//        logToTextBoxThreadSafe("Error: " + ex.Message);
                setStatus(ClientStatus.ERROR);
            }
        }
Exemple #6
0
        public Client(String configDir)
        {
            ClientServerConnection.LogHandlers.Add(new ClientServerConnection.LoggingHandlerDelegate(logToConsole));
            ClientServerConnection.LogHandlers.Add(new ClientServerConnection.LoggingHandlerDelegate(logToFile));
            ClientServerConnection.StatusHandler = setStatus;

            try {
                ClientServerConnection.SetConfigDir(configDir);
                ClientServerConnection client = new ClientServerConnection();
                client.LoadConfig(ClientServerConnection.ConfigFile);
                client.Start();
            }
            catch (Exception e) {
                logToConsole("Error: " + e.Message);
                logToFile("Error: " + e.Message);
#if DEBUG
                Console.WriteLine("Press any key to quit...");
                Console.ReadKey(true);
#endif
            }
        }