public static ServiceConnector GetInstance()
        {
            if (_instance == null)
            {
                var settings           = UserSettingsLoader.GetInstance().Settings;
                var serverAddress      = settings.ServerAddress;
                var serverAddressItems = settings.ServerAddressItems;
                _instance = new ServiceConnector(serverAddress, serverAddressItems);
            }

            return(_instance);
        }
示例#2
0
        public MainView()
        {
            this.InitializeComponent();

            this._viewModel = (MainViewModel)this.DataContext;

            EventbusManager.Register <MainView, MainMessage>(this.EventBusReceivedMessage);
            var settings = UserSettingsLoader.GetInstance().Settings;

            this._viewModel.Username         = settings.Username;
            this._viewModel.Interval         = settings.Interval;
            this._viewModel.HostAddressItems = settings.ServerAddressItems;
            this._viewModel.HostAddress      = settings.ServerAddress;
        }
示例#3
0
        public MainWindow()
        {
            this.InitializeComponent();



            this.Prepare();

            var setting = UserSettingsLoader.GetInstance().Load();

            this.LoadApplicationSize(setting);
            this.LoadApplicationWindowState(setting);
            this.LoadApplicationStartLocation(setting);
        }
示例#4
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            var usl = UserSettingsLoader.GetInstance();

            var file = usl.Load();

            file.ApplicationPositionX = (int)this.Left;
            file.ApplicationPositionY = (int)this.Top;
            file.SizeX = (int)this.Width;
            file.SizeY = (int)this.Height;
            file.ApplicationWindowState = this.WindowState.ToString();

            usl.Save(file);
        }
示例#5
0
        private void ButtonAccept_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this._viewModel.Username))
            {
                MessageBox.Show("username must be set.");
                return;
            }

            if (string.IsNullOrEmpty(this._viewModel.HostAddress))
            {
                MessageBox.Show("host address must be set.");
                return;
            }

            var service = ServiceConnector.GetInstance();

            service.SetAddress(this._viewModel.HostAddress);

            if (service.TrySetUsername(this._viewModel.Username, out var userItem))
            {
                EventbusManager.OpenView <UserlistView>(0);
                EventbusManager.Send <MainWindow, UpdateCommandMessage>(new UpdateCommandMessage(userItem), 0);
                EventbusManager.Send <MenuView, UpdateCommandMessage>(new UpdateCommandMessage(ViewOpen.Userlist), 0);

                if (!this._viewModel.HostAddressItems.Any(a => a.Equals(this._viewModel.HostAddress)))
                {
                    this._viewModel.HostAddressItems = this._viewModel.HostAddressItems.Append(this._viewModel.HostAddress);
                }

                var settings = new SettingsFile
                {
                    Username           = this._viewModel.Username,
                    Interval           = this._viewModel.Interval,
                    ServerAddress      = this._viewModel.HostAddress,
                    ServerAddressItems = this._viewModel.HostAddressItems
                };
                UserSettingsLoader.GetInstance().Save(settings);

                MessengerManager.GetInstance().Start(this._viewModel.Interval);
                return;
            }

            MessageBox.Show($"Can not use username: {this._viewModel.Username}");
        }
示例#6
0
        public Landkreise LoadData(out Action <bool> saveIf, bool loadForceFromInternet = false)
        {
            saveIf = null;
            var filename = HelperExtension.CreateFilename();

            if (!UserSettingsLoader.GetInstance().Load().LoadRkiDataByApplicationStart&&
                !loadForceFromInternet)
            {
                filename = GetLastLoadedData();
            }

            if (!string.IsNullOrEmpty(filename) && File.Exists(filename))
            {
                var reload = this.LoadLocalOrReloadOnlineFromRki(filename);
                if (reload != null)
                {
                    return(reload);
                }
            }

            if (string.IsNullOrEmpty(filename))
            {
                return(new Landkreise
                {
                    Date = DateTime.MinValue,
                    Districts = new List <Landkreis>()
                });
            }

            var result = this.ConvertToLandkreise(this.LoadActualData());

            if (result == null)
            {
                return(null);
            }

            result.Districts.InsertGermanyIfNotList(result.Date);

            if (filename != HelperExtension.CreateFilename())
            {
                return(result);
            }

            if (!File.Exists(filename))
            {
                this.SaveToFile(result, filename);
            }
            else
            {
                if (IsDifferent(filename, result))
                {
                    saveIf = canSave =>
                    {
                        if (!canSave)
                        {
                            return;
                        }
                        this.SaveToFile(result, filename);
                    };
                }
            }

            return(result);
        }
示例#7
0
        public override void OnApplyTemplate()
        {
            var setting = UserSettingsLoader.GetInstance().Load();

            this._viewModel.LoadRkiDataByApplicationStart = setting.LoadRkiDataByApplicationStart;
        }