示例#1
0
        private void btnDisconnectAuto_Click(object sender, EventArgs e)
        {
            try
            {
//				if (_loggerTask != null)
//					_tokenSource.Cancel();

                _syncProcessor.Dispose();
                _syncProcessor = null;

                _commandHandler.Kill();
                _commandHandler.Dispose();
                _commandHandler = null;

                _tcpCommunication.Dispose();
                _tcpCommunication = null;

                _myFsWatcher.Dispose();
                _myFsWatcher = null;

                SwitchAutoUiState(false);
                Logger.WriteDisconnectLine();
            }
            catch (Exception ex)
            {
                SwitchAutoUiState(false);
                MessageBox.Show(ex.Message, @"Disconnect");
            }
        }
示例#2
0
 /// <summary>
 /// Stops the driver by unhooking any event handlers and releasing any used resources.
 /// </summary>
 public override void StopDriver()
 {
     // TODO: Add any necessary cleanup logic here.
     if (_tcp != null)
     {
         _tcp.Dispose();
         _tcp = null;
     }
 }
        private async void ManageUserLogin()
        {
            try
            {
                var changedFilesList      = new ThreadSafeList <CustomFileHash>();
                var commandResponseBuffer = new BufferBlock <byte[]>();

                var tcpClient = EstablishTcpCommunication();
                _tcpCommunication = new TcpCommunication(tcpClient, commandResponseBuffer, changedFilesList);


                var connectionBytes = Encoding.UTF8.GetBytes(_loginViewModel.UserName + ":" + _loginViewModel.UserPassword + ":");
                _tcpCommunication.SendCommand(connectionBytes, 0, connectionBytes.Length);
                await _tcpCommunication.CommandResponseBuffer.OutputAvailableAsync();

                var response = _tcpCommunication.CommandResponseBuffer.Receive();
                var message  = Encoding.UTF8.GetString(response).Split(':');
                if (message[0].Equals("Error"))
                {
                    _tcpCommunication.Dispose();
                    Messenger.Default.Send(new LoginFailedMsg());
                    MessageBox.Show(message[1], @"Datele de autentificare sunt invalide.", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    RaisePropertyChanged(() => ConnectedUserName);
                    Logger.InitLogger(Helper.TraceEnabled);
                    Logger.WriteInitialSyncBreakLine();

                    _commandHandler = new CommandHandler(_tcpCommunication);
                    var filesForInitialSync = await DetermineFilesForInitialSync();

                    _syncProcessor = new SyncProcessor(_commandHandler, changedFilesList);
                    filesForInitialSync.ForEach(_syncProcessor.AddChangedFile);

                    SetupLayout(UiState.LoggedIn);

                    Messenger.Default.Send(new LoginSuccededMsg());

                    await _syncProcessor.ChangedFileManager();

                    Logger.WriteSyncBreakLine();
                    changedFilesList.OnAdd += changedFilesList_OnAdd;
                    _myFsWatcher            = new MyFsWatcher(Helper.SyncLocation, _syncProcessor);
                }
            }
            catch (FormatException ex)
            {
                LoginVisibility = Visibility.Visible;
                Messenger.Default.Send(new LoginFailedMsg());

                var str = "Message: " + ex.Message +
                          "\nSource: " + ex.Source +
                          "\nStackTrace: " + ex.StackTrace;
                MessageBox.Show(str, @"Sincronizator de fișiere - Excepție de formatare");
            }
            catch (SocketException ex)
            {
                LoginVisibility = Visibility.Visible;
                Messenger.Default.Send(new LoginFailedMsg());

                var str = "Message: " + ex.Message +
                          "\nSource: " + ex.Source +
                          "\nStackTrace: " + ex.StackTrace;
                MessageBox.Show(str, @"Sincronizator de fișiere - Excepție de socket");
            }
            catch (Exception ex)
            {
                LoginVisibility = Visibility.Visible;
                Messenger.Default.Send(new LoginFailedMsg());

                var str = "Message: " + ex.Message +
                          "\nSource: " + ex.Source +
                          "\nException Type: " + ex.GetType() +
                          "\nStackTrace: " + ex.StackTrace;
                MessageBox.Show(str, @"Sincronizator de fișiere - Excepție");
            }
        }
示例#4
0
        private async void btnConnectAuto_Click(object sender, EventArgs e)
        {
            try
            {
                Context.InAutoMode = true;

                if (Helper.TraceEnabled)
                {
                    Logger.InitLogger(true);
                    _loggerTask = Task.Factory.StartNew(LoggerAction);
                }
                else
                {
                    Logger.InitLogger();
                    _loggerTask = null;
                }


                var changedFilesList      = new ThreadSafeList <CustomFileHash>();
                var commandResponseBuffer = new BufferBlock <byte[]>();

                var tcpClient = new TcpClient(txtHostAuto.Text, Int32.Parse(txtPortAuto.Text));
                _tcpCommunication = new TcpCommunication(tcpClient, commandResponseBuffer, changedFilesList);


                var connectionBytes = Encoding.UTF8.GetBytes(txtUsername.Text + ":" + txtUserpassword.Text + ":");
                _tcpCommunication.SendCommand(connectionBytes, 0, connectionBytes.Length);
                await _tcpCommunication.CommandResponseBuffer.OutputAvailableAsync();

                var response = _tcpCommunication.CommandResponseBuffer.Receive();
                var message  = Encoding.UTF8.GetString(response).Split(':');
                if (message[0].Equals("Error"))
                {
                    MessageBox.Show(message[1], @"Invalid user or password");
                    _tcpCommunication.Dispose();
                }
                else
                {
                    SwitchAutoUiState(UiConnectedState);
                    Context.CurrentUser = txtUsername.Text;
                    _commandHandler     = new CommandHandler(_tcpCommunication);

                    Logger.WriteInitialSyncBreakLine();
                    var filesForInitialSync = await DetermineFilesForInitialSync();

                    _syncProcessor = new SyncProcessor(_commandHandler, changedFilesList);
                    filesForInitialSync.ForEach(_syncProcessor.AddChangedFile);
                    await _syncProcessor.ChangedFileManager();

                    Logger.WriteSyncBreakLine();
                    changedFilesList.OnAdd += changedFilesList_OnAdd;
                    _myFsWatcher            = new MyFsWatcher(txtDefaultFolderAuto.Text, _syncProcessor);
                }
            }
            catch (FormatException fex)
            {
                var str = "Message: " + fex.Message +
                          "\nSource: " + fex.Source +
                          "\nStackTrace: " + fex.StackTrace;
                MessageBox.Show(str, @"Syncroniser - FormatException");
                SwitchAutoUiState(false);
                MessageBox.Show(fex.Message);
            }
            catch (Exception ex)
            {
                var str = "Message: " + ex.Message +
                          "\nSource: " + ex.Source +
                          "\nStackTrace: " + ex.StackTrace;
                MessageBox.Show(str, @"Syncroniser - Exception");
                SwitchAutoUiState(false);
                MessageBox.Show(ex.Message);
            }
        }