public MainWindow()
        {
            var splitters = new char[] { ':' };
            var storage   = IsolatedStorageFile.GetUserStoreForDomain();

            try {
                using (var stream = new IsolatedStorageFileStream(FileName, FileMode.Open, storage))
                    using (var reader = new StreamReader(stream)) {
                        while (!reader.EndOfStream)
                        {
                            var keyValue = reader.ReadLine().Split(splitters);
                            Application.Current.Properties[keyValue[0]]
                                = double.TryParse(keyValue[1], out var number)
                              ? number
                              : (object)keyValue[1];
                        }
                    }
            } catch (FileNotFoundException) { }

            InitializeComponent();

            _context = (MainWindowContext)DataContext;
            _context.PropertyChanged += (_, e) => {
                if (e.PropertyName == nameof(MainWindowContext.State) &&
                    _context.State == MainWindowContext.ConnectionState.Disconnected)
                {
                    MainTab.Dispatch(it => (it.SelectedContent as ITabControl)?.OnLeave());
                }
            };
            SerialPortCombo.Items.Add(AutoSelectString);
            SerialPortCombo.SelectedIndex = 0;
        }
Пример #2
0
        public static async Task Handle(
            MainWindowContext context,
            CancellationTokenSource connecting
            )
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try {
                try {
                    var dictionary = Application.Current.Properties;
                    foreach (string key in dictionary.Keys)
                    {
                        var parameter = Methods.Parameters[key];
                        if (parameter != null)
                        {
                            parameter.Value = (double)dictionary[key];
                        }
                    }
                } catch (Exception exception) {
                    context.ErrorInfo = exception.Message;
                }

                while (!connecting.IsCancellationRequested)
                {
                    context.ConnectedTime = Format("0.0", stopwatch.ElapsedMilliseconds / 1000.0);
                    try {
                        context.ChassisState            = Methods.State;
                        var(_, _, x, y, theta, _, _, _) = Methods.Odometry;
                        context.Odometry = string.Format(
                            CultureInfo.InvariantCulture,
                            "{0}, {1}, {2}°",
                            Format("0.##", x),
                            Format("0.##", y),
                            Format("0.#", theta.ToDegree()));
                    } catch (Exception exception) {
                        context.ErrorInfo = exception.Message;
                    }
                    await Task.Delay(99, connecting.Token).ConfigureAwait(false);
                }
            } catch (Exception exception) {
                context.ErrorInfo = exception.Message;
            } finally {
                Methods.ShutdownSafety();
                context.State = MainWindowContext.ConnectionState.Disconnected;
            }
        }