Beispiel #1
0
        private async Task StartShutdownProcess()
        {
            try
            {
                Logger.Log(LogLevel.Debug, "Starting shutdown process");

                if (WindowState == WindowState.Maximized)
                {
                    // Use the RestoreBounds as the current values will be 0, 0 and the size of the screen
                    ChannelSession.AppSettings.Top         = RestoreBounds.Top;
                    ChannelSession.AppSettings.Left        = RestoreBounds.Left;
                    ChannelSession.AppSettings.Height      = RestoreBounds.Height;
                    ChannelSession.AppSettings.Width       = RestoreBounds.Width;
                    ChannelSession.AppSettings.IsMaximized = true;
                }
                else
                {
                    ChannelSession.AppSettings.Top         = this.Top;
                    ChannelSession.AppSettings.Left        = this.Left;
                    ChannelSession.AppSettings.Height      = this.Height;
                    ChannelSession.AppSettings.Width       = this.Width;
                    ChannelSession.AppSettings.IsMaximized = false;
                }

                Properties.Settings.Default.Save();

                this.ShuttingDownGrid.Visibility = Visibility.Visible;
                this.MainMenu.Visibility         = Visibility.Collapsed;

                await ChannelSession.Services.Settings.Save(ChannelSession.Settings);

                await ChannelSession.AppSettings.Save();

                await ChannelSession.Close();

                this.shutdownComplete = true;

                Logger.Log(LogLevel.Debug, "Shutdown process complete");
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            this.Close();
            if (this.restartApplication)
            {
                ProcessHelper.LaunchProgram(Application.ResourceAssembly.Location);
            }
        }
Beispiel #2
0
        private async Task StartShutdownProcess()
        {
            this.ShuttingDownGrid.Visibility = Visibility.Visible;
            this.MainMenu.Visibility         = Visibility.Collapsed;

            if (!string.IsNullOrEmpty(this.RestoredSettingsFilePath))
            {
                string settingsFilePath = ChannelSession.Services.Settings.GetFilePath(ChannelSession.Settings);
                string settingsFolder   = Path.GetDirectoryName(settingsFilePath);
                using (ZipArchive zipFile = ZipFile.Open(this.RestoredSettingsFilePath, ZipArchiveMode.Read))
                {
                    foreach (ZipArchiveEntry entry in zipFile.Entries)
                    {
                        string filePath = Path.Combine(settingsFolder, entry.Name);
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                    }
                    zipFile.ExtractToDirectory(settingsFolder);
                }
            }
            else
            {
                for (int i = 0; i < 5 && !await ChannelSession.Services.Settings.SaveAndValidate(ChannelSession.Settings); i++)
                {
                    await Task.Delay(1000);
                }
            }

            App.AppSettings.Save();

            await ChannelSession.Close();

            this.shutdownComplete = true;

            this.Close();
            if (this.restartApplication)
            {
                Process.Start(Application.ResourceAssembly.Location);
            }
        }
Beispiel #4
0
        private async Task StartShutdownProcess()
        {
            if (WindowState == WindowState.Maximized)
            {
                // Use the RestoreBounds as the current values will be 0, 0 and the size of the screen
                App.AppSettings.Top         = RestoreBounds.Top;
                App.AppSettings.Left        = RestoreBounds.Left;
                App.AppSettings.Height      = RestoreBounds.Height;
                App.AppSettings.Width       = RestoreBounds.Width;
                App.AppSettings.IsMaximized = true;
            }
            else
            {
                App.AppSettings.Top         = this.Top;
                App.AppSettings.Left        = this.Left;
                App.AppSettings.Height      = this.Height;
                App.AppSettings.Width       = this.Width;
                App.AppSettings.IsMaximized = false;
            }

            Properties.Settings.Default.Save();

            this.ShuttingDownGrid.Visibility = Visibility.Visible;
            this.MainMenu.Visibility         = Visibility.Collapsed;

            if (!string.IsNullOrEmpty(this.RestoredSettingsFilePath))
            {
                string settingsFilePath = ChannelSession.Services.Settings.GetFilePath(ChannelSession.Settings);
                string settingsFolder   = Path.GetDirectoryName(settingsFilePath);
                using (ZipArchive zipFile = ZipFile.Open(this.RestoredSettingsFilePath, ZipArchiveMode.Read))
                {
                    foreach (ZipArchiveEntry entry in zipFile.Entries)
                    {
                        string filePath = Path.Combine(settingsFolder, entry.Name);
                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                    }
                    zipFile.ExtractToDirectory(settingsFolder);
                }
            }
            else
            {
                for (int i = 0; i < 5 && !await ChannelSession.Services.Settings.SaveAndValidate(ChannelSession.Settings); i++)
                {
                    await Task.Delay(1000);
                }
            }

            App.AppSettings.Save();

            await ChannelSession.Close();

            this.shutdownComplete = true;

            this.Close();
            if (this.restartApplication)
            {
                Process.Start(Application.ResourceAssembly.Location);
            }
        }
        private void Arrange()
        {
            var random = new Random();

            _localChannelNumber       = (uint)random.Next(0, int.MaxValue);
            _localWindowSize          = (uint)random.Next(2000, 3000);
            _localPacketSize          = (uint)random.Next(1000, 2000);
            _remoteChannelNumber      = (uint)random.Next(0, int.MaxValue);
            _remoteWindowSize         = (uint)random.Next(0, int.MaxValue);
            _remotePacketSize         = (uint)random.Next(100, 200);
            _sessionSemaphore         = new SemaphoreLight(1);
            _channelClosedRegister    = new List <ChannelEventArgs>();
            _channelExceptionRegister = new List <ExceptionEventArgs>();

            _sessionMock        = new Mock <ISession>(MockBehavior.Strict);
            _connectionInfoMock = new Mock <IConnectionInfo>(MockBehavior.Strict);

            var sequence = new MockSequence();

            _sessionMock.InSequence(sequence).Setup(p => p.ConnectionInfo).Returns(_connectionInfoMock.Object);
            _connectionInfoMock.InSequence(sequence).Setup(p => p.RetryAttempts).Returns(1);
            _sessionMock.Setup(p => p.SessionSemaphore).Returns(_sessionSemaphore);
            _sessionMock.InSequence(sequence)
            .Setup(
                p =>
                p.SendMessage(
                    It.Is <ChannelOpenMessage>(
                        m =>
                        m.LocalChannelNumber == _localChannelNumber &&
                        m.InitialWindowSize == _localWindowSize && m.MaximumPacketSize == _localPacketSize &&
                        m.Info is SessionChannelOpenInfo)));
            _sessionMock.InSequence(sequence)
            .Setup(p => p.WaitOnHandle(It.IsNotNull <WaitHandle>()))
            .Callback <WaitHandle>(
                w =>
            {
                _sessionMock.Raise(
                    s => s.ChannelOpenConfirmationReceived += null,
                    new MessageEventArgs <ChannelOpenConfirmationMessage>(
                        new ChannelOpenConfirmationMessage(
                            _localChannelNumber,
                            _remoteWindowSize,
                            _remotePacketSize,
                            _remoteChannelNumber)));
                w.WaitOne();
            });
            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
            _sessionMock.InSequence(sequence)
            .Setup(p => p.TrySendMessage(It.Is <ChannelEofMessage>(m => m.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
            _sessionMock.InSequence(sequence).Setup(p => p.IsConnected).Returns(true);
            _sessionMock.InSequence(sequence)
            .Setup(p => p.TrySendMessage(It.Is <ChannelCloseMessage>(m => m.LocalChannelNumber == _remoteChannelNumber))).Returns(true);
            _sessionMock.InSequence(sequence)
            .Setup(p => p.WaitOnHandle(It.IsNotNull <WaitHandle>()))
            .Callback <WaitHandle>(
                w =>
            {
                _sessionMock.Raise(
                    s => s.ChannelCloseReceived += null,
                    new MessageEventArgs <ChannelCloseMessage>(new ChannelCloseMessage(_localChannelNumber)));
                w.WaitOne();
            });

            _channel            = new ChannelSession(_sessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
            _channel.Closed    += (sender, args) => _channelClosedRegister.Add(args);
            _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
            _channel.Open();
            _channel.Close();
        }
 protected virtual void Act()
 {
     _channel.Close();
 }