コード例 #1
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");
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: jonocodes/mybox
        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
            }
        }