/// <summary> /// Fetch user data asynchronously /// </summary> /// <param name="idPatient"></param> /// <returns></returns> private async Task InitializePatient(int idPatient) { IsLoading = true; await Task.Run(() => { try { SelectedPatient = _patientBM.GetPatient(idPatient); ObservableCollection <ServicePatientReference.Observation> list = new ObservableCollection <ServicePatientReference.Observation>(); List <int> weightList = new List <int>(); List <int> pressureList = new List <int>(); List <string> dateList = new List <string>(); foreach (ServicePatientReference.Observation observation in SelectedPatient.Observations) { list.Add(observation); weightList.Add(observation.Weight); pressureList.Add(observation.BloodPressure); dateList.Add(observation.Date.ToString()); } DispatchService.Invoke(() => { ObservationsList = list; UpdateGraph(weightList, pressureList, dateList); }); } catch (Exception e) { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.GET_PATIENT_OBSERVATION)); } finally { IsLoading = false; } }); }
private async void Connect() { IsLoadingSession = true; await Task.Run(() => { try { bool connect = _loginBM.Connect(Login, Password); if (connect) { DispatchService.Invoke(() => PageMediator.Notify("Change_MainWindow_UC", EUserControl.MAIN, Login)); } else { Message = "Wrong username or password"; } } catch (System.Exception e) { if (e is CustomServerException) { DispatchService.Invoke(() => ShowRetryWindow()); } } finally { IsLoadingSession = false; } }); }
private void OnDeviceInitialized() { try { DispatchService.Invoke(() => { StarterViewModels.Clear(); for (int i = 1; i <= 3; i++) { if ((_model as IRuntimeDevice).StartersOnDevice.Any((starter => starter.StarterNumber == i))) { StarterViewModels.Add(_starterViewModelFactory.CreateStarterViewModel( (_model as IRuntimeDevice).StartersOnDevice.First( (starter => starter.StarterNumber == i)))); } else { StarterViewModels.Add(new StarterViewModel()); } } _outgoingLinesViewModel = _outgoingLinesViewModelFactory.CreateOutgoingLinesViewModel(Model); RaisePropertyChanged(nameof(OutgoingLinesViewModel)); _customItemsViewModel = _customItemsViewModelFactory.CreateCustomItemsViewModel((_model as IRuntimeDevice).DeviceCustomItems); }); } catch (Exception e) { Console.WriteLine(e); throw; } }
public MainWindowViewModel() { this.ClearSearchCommand = new DelegateCommand(() => Keyword = string.Empty); this.LoadSettingCommand = new DelegateCommand(() => LoadSetting()); this.SaveSettingCommand = new DelegateCommand(() => SaveSetting()); this.TextBoxEnterKeyEventCommand = new DelegateCommand <string>(async(keyword) => await Task.Run(async() => { if (string.IsNullOrEmpty(keyword)) { return; } Result result = await GetResult(keyword); DispatchService.Invoke(() => { Meanings.Clear(); ScrollToTop?.Invoke(); if (result != null && result?.Meanings?.Count > 0) { Meanings.AddRange(result.Meanings); } else { meanings.Add(new Meaning { Word = $"未找到 (´;ω;`)" }); } }); })); }
/// <summary> /// Add asynchronously a patient /// </summary> /// <returns></returns> private async Task AddPatient() { await Task.Run(() => { try { if (!Name.IsNullOrWhiteSpace() && !Firstname.IsNullOrWhiteSpace() && Birthday != null) { Patient patient = new Patient() { Name = Name, Firstname = Firstname, Birthday = Birthday, Observations = new List <Observation>().ToArray() }; if (_patientBM.AddPatient(patient)) { DispatchService.Invoke(() => PageMediator.Notify("Change_Main_UC", EUserControl.MAIN_PATIENTS, _currentLogin)); } else { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_PATIENT)); } } else { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.MISSING_FIELDS)); } } catch (Exception) { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_PATIENT)); } }); }
/// <summary> /// Fetch charts data asynchronously /// </summary> /// <param name="idPatient"></param> /// <returns></returns> private async Task FetchChartData(int idPatient) { IsLoading = true; await Task.Run(() => { try { ServicePatientReference.Patient _selectedPatient = _patientBM.GetPatient(idPatient); List <Observation> observations = _selectedPatient.Observations.OrderBy(x => x.Date).ToList(); List <int> weightList = observations.Select(x => x.Weight).ToList(); List <int> pressureList = observations.Select(x => x.BloodPressure).ToList(); List <string> dateList = observations.Select(x => x.Date.ToString()).ToList(); DispatchService.Invoke(() => UpdateGraph(weightList, pressureList, dateList)); } catch { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.GETSINGLE_PATIENT)); } finally { IsLoading = false; } }); }
/// <summary> /// Run async task to delete patient /// </summary> private async Task DeletePatient() { await Task.Run(() => { try { if (SelectedPatient != null) { bool isDeleted = _patientBM.DeletePatient(SelectedPatient.Id); if (isDeleted) { DispatchService.Invoke(() => { PatientList.Remove(SelectedPatient); SelectedPatient = null; }); } else DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.DELETE_PATIENT)); } } catch (Exception) { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.DELETE_PATIENT)); } }); }
public void ProceedCommand(object sender, RepeaterEventArgs e) { if (e.Type == ActionTypes.Login) { if (e.Result) { DispatchService.Invoke(() => { _logicClient.Login = Login; var communicatorWindow = new CommunicatorWindow(); var communicatorViewModel = new CommunicatorViewModel(_logicClient); communicatorViewModel.OnRequestClose += (s, ee) => communicatorWindow.Close(); communicatorWindow.DataContext = communicatorViewModel; communicatorWindow.Show(); communicatorViewModel.Inicialize(); if (OnRequestClose != null) { OnRequestClose(this, new EventArgs()); } }); } else { Result = "Niepoprawne hało lub login"; } } }
private void SensorsService_SensorChanged(object sender, Measure e) { this.CurrentMeasure = e; DispatchService.Invoke(() => Measures.Add(e)); }
private void _DroneUpdateService_StatusUpdateReceivedFromDrone(DroneState newState) { DispatchService.Invoke(() => { if (_DroneStateHistory != null) { _DroneStateHistory.Add(new DroneStateViewModel(newState)); } }); // todo: add to list, thread safe }
private void AddNetwork(Network network) { DispatchService.Invoke(() => { Networks.Add(network); if (!IsNetworkSelected) { Network = Networks.FirstOrDefault(); } }); }
private void ExecuteProcessNumberSieveCommand() { // reset display LoadNumbers(); // disable process button DispatchService.Invoke(() => IsNotBusy = false); // perform sieve in background thread DispatchService.Background(() => { const int interval = 100; var max = _numbers.Count + 1; for (var i = 2; i <= max; i++) { // delay System.Threading.Thread.Sleep(interval); // adjust for collection starting at 2 var index = i - 2; var number = i; // See if i is prime. if (!PrimeNumberService.IsPrimeNumber(number)) { continue; } // mark as prime _numbers[index].IsPrime = true; _numbers[index].DisplayColor = ColorService.PrimeColor; // Knock out multiples of number var backgroundColor = ColorService.GetNextColor(); for (var j = number * number; j <= max; j += number) { _numbers[j - 2].IsPrime = false; _numbers[j - 2].Model.DisplayColor = backgroundColor; // delay System.Threading.Thread.Sleep(interval); } } // re-enable button DispatchService.Invoke(() => IsNotBusy = true); }); }
private void CheckAckFail() { if (_deviceViewModel == null) { return; } if (_deviceViewModel.StateWidget == WidgetState.Repair) { DispatchService.Invoke((() => { _assotiatedBorder.Visibility = Visibility.Visible; _assotiatedBorder.Background = Brushes.Orange; return; })); } if (_defectAcknowledgingService.IsFailNeedsAcknowledge()) { if (_borderColorAnimation == null) { DispatchService.Invoke((() => { _assotiatedBorder.Visibility = Visibility.Visible; if (_borderColorAnimation == null) { _borderColorAnimation = new ColorAnimation(); _borderColorAnimation.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500)); _borderColorAnimation.To = Colors.Silver; _borderColorAnimation.From = Colors.Red; _borderColorAnimation.AutoReverse = true; _borderColorAnimation.RepeatBehavior = RepeatBehavior.Forever; _assotiatedBorder.Background = new SolidColorBrush(); _assotiatedBorder.Background.BeginAnimation(SolidColorBrush.ColorProperty, _borderColorAnimation); _soundNotificationsService.SetNotificationSource(_deviceViewModel); } return; })); } } else { DispatchService.Invoke((() => { _borderColorAnimation = null; _soundNotificationsService.ReleaseNotificationSource(_deviceViewModel); })); } }
private void SensorsService_SensorChanged(object sender, Models.Measure e) { Trace.WriteLine(e.Value); // error // Measures.Add(e); // thread-safe DispatchService.Invoke(() => { this.Measures.Add(e); }); CurrentMeasure = e; }
private void CheckStateWidget() { if (_deviceViewModel == null) { return; } CheckAckFail(); if (!_defectAcknowledgingService.IsFailNeedsAcknowledge()) { DispatchService.Invoke((() => { switch (_deviceViewModel.StateWidget) { case WidgetState.Norm: _assotiatedBorder.Visibility = Visibility.Collapsed; break; case WidgetState.NoConnection: _assotiatedBorder.Visibility = Visibility.Visible; _assotiatedBorder.Background = Brushes.Silver; break; case WidgetState.Crash: _assotiatedBorder.Visibility = Visibility.Visible; _assotiatedBorder.Background = Brushes.Red; break; case WidgetState.Repair: _assotiatedBorder.Visibility = Visibility.Visible; _assotiatedBorder.Background = Brushes.Orange; break; } })); } else { if (_deviceViewModel.StateWidget == WidgetState.NoConnection) { DispatchService.Invoke((() => { _assotiatedBorder.Visibility = Visibility.Visible; _assotiatedBorder.Background = Brushes.Silver; })); } } }
private void GetAllUsers() { IEnumerable <string> users = History.Select(m => m.Sender); users = users.Union(History.Select(m => m.Recipient)); users = users.Where(u => u != _logicClient.Login); DispatchService.Invoke(() => { UserList.Clear(); foreach (string user in users) { UserList.Add(new User { Login = user }); } }); }
/// <summary> /// Add new observation /// </summary> /// <param name="param"></param> public async void OnObservationAdd(object param) { await Task.Run(() => { try { ServiceObservationReference.Observation observation = (ServiceObservationReference.Observation)param; _observationBM.AddObservation(_idPatient, observation); DispatchService.Invoke(() => { IsAddView = false; InitializePatient(_idPatient); }); } catch (Exception e) { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_PATIENT_OBSERVATION)); } }); }
public void ProceedCommand(object sender, RepeaterEventArgs e) { if (e.Type == ActionTypes.Message) { if (e.Result) { var message = (MessageReq)e.Data; if (message.Login == Recipeint) { DispatchService.Invoke(() => { var messageModel = new MessageModel { DateTimeDelivery = message.SendTime.ToString("yy-MM-dd hh:mm"), Message = message.Message, Sender = message.Login, Image = GetImageFromAttach(message.Attachment) }; Messages.Add(messageModel); }); } } } else if (e.Type == ActionTypes.UserWriting) { if (e.Result) { var notification = (ActivityNotification)e.Data; if (notification.Sender == Recipeint) { Task.Factory.StartNew(() => { DispatchService.Invoke( () => { UserWriting = notification.IsWriting ? "Użytkownik pisze..." : ""; }); Thread.Sleep(3000); DispatchService.Invoke(() => { UserWriting = ""; }); }); } } } }
/// <summary> /// Fetch asynchronously the patients /// </summary> /// <returns></returns> private async Task InitializePatient() { IsLoading = true; await Task.Run(() => { try { PatientList = new ObservableCollection<Patient>(_patientBM.GetListPatient()); ShowPatientsGrid = PatientList.Count != 0; } catch (Exception) { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.GETALL_PATIENT)); } finally { IsLoading = false; } }); }
/// <summary> /// Fetch asynchronously the users /// </summary> /// <returns></returns> private async Task InitializeUsers() { IsLoading = true; await Task.Run(() => { try { UserList = new ObservableCollection <User>(_sessionBM.GetListUser()); ShowUsersGrid = UserList.Count != 0; } catch (Exception) { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.GETALL_USER)); } finally { IsLoading = false; } }); }
/// <summary> /// Add new user if fields are corrects /// </summary> private async Task AddUser() { await Task.Run(() => { try { if (!Name.IsNullOrWhiteSpace() && !Firstname.IsNullOrWhiteSpace() && !Password.IsNullOrWhiteSpace() && !Login.IsNullOrWhiteSpace() && !Role.IsNullOrWhiteSpace()) { User user = new User() { Name = Name, Firstname = Firstname, Pwd = Password, Login = Login, Role = Role, Picture = Image, Connected = false }; if (_sessionBM.AddUser(user)) { DispatchService.Invoke(() => PageMediator.Notify("Change_Main_UC", EUserControl.MAIN_USERS, _currentLogin)); } else { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_USER)); } } else { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.MISSING_FIELDS)); } } catch (Exception e) { if (e is CustomLargePictureException) { DispatchService.Invoke(() => ShowPictureExceptionWindow()); } DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.ADD_USER)); } }); }
private async Task AddErrorInList(Exception exception, string requestName) { await Task.Run((() => { StringBuilder sb = new StringBuilder(); if (exception is SocketException) { sb.Append(requestName); sb.Append(" | "); sb.Append(DateTime.Now.ToString()); sb.Append(" | "); sb.Append(((SocketException)exception).SocketErrorCode.ToString()); sb.Append(" | "); sb.Append(((SocketException)exception).ErrorCode.ToString()); sb.Append(" | "); //TODO: think what to do with long messages, and think what to present as message sb.Append(((SocketException)exception).Message.ToString().Split(' ').Last()); } else { sb.Append(requestName); sb.Append(" | "); sb.Append(DateTime.Now.ToString()); sb.Append(" | "); sb.Append(" | "); sb.Append((exception).Message.ToString()); } DispatchService.Invoke((() => { if (ConnectionExceptionList.Count == 100) { ConnectionExceptionList.RemoveAt(99); } ConnectionExceptionList.Insert(0, sb.ToString()); })); })); }
public void SetChosenTracks(List <int> chosenAudioTracks, Title selectedTitle) { DispatchService.Invoke(() => { int previousIndex = this.TargetStreamIndex; this.targetStreams.Clear(); this.targetStreams.Add(new TargetStreamViewModel { Text = CommonRes.All }); int shownStreams = Math.Max(previousIndex, chosenAudioTracks.Count); for (int i = 0; i < shownStreams; i++) { string details = null; if (i < chosenAudioTracks.Count && selectedTitle != null) { details = selectedTitle.AudioTracks[chosenAudioTracks[i] - 1].NoTrackDisplay; } this.targetStreams.Add( new TargetStreamViewModel { Text = string.Format(CommonRes.StreamChoice, (i + 1)), TrackDetails = details }); } // Set to -1, then back to real index in order to force a refresh on the ComboBox this.targetStreamIndex = -1; this.RaisePropertyChanged(() => this.TargetStreamIndex); this.targetStreamIndex = previousIndex; this.RaisePropertyChanged(() => this.TargetStreamIndex); }); }
/// <summary> /// Initialize patient infos /// </summary> /// <param name="idPatient"></param> /// <returns></returns> private async Task InitializePatient(int idPatient) { IsLoading = true; await Task.Run(() => { try { SelectedPatient = _patientBM.GetPatient(idPatient); if (SelectedPatient.Observations != null) { ObservationsNb = SelectedPatient.Observations.Length; } } catch { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.GETSINGLE_PATIENT)); } finally { IsLoading = false; } }); }
/// <summary> /// Run async task to delete user /// </summary> private async Task DeleteUser() { await Task.Run(() => { try { if (SelectedUser != null) { bool isDeleted = _sessionBM.DeleteUser(SelectedUser.Login); if (isDeleted) { DispatchService.Invoke(() => { UserList.Remove(SelectedUser); SelectedUser = null; }); } } } catch (Exception) { DispatchService.Invoke(() => ShowServerExceptionWindow(ErrorDescription.DELETE_USER)); } }); }
public void SearchFile2(CancellationToken cancellationToken, string name, string path, List <Prohibited_words> str_words) { cancellationToken.ThrowIfCancellationRequested(); string[] path_file = null; if (list_file != null) { try { string[] path_Directories = Directory.GetDirectories(name); foreach (var y in path_Directories) { cancellationToken.ThrowIfCancellationRequested(); if (path_Directories != null) { SearchFile2(cancellationToken, y, path, str_words); } path_file = Directory.GetFiles(y, path); foreach (var i in path_file) { cancellationToken.ThrowIfCancellationRequested(); DispatchService.Invoke(() => { if (str_words != null) { if (i.Contains(".txt")) { using (StreamReader objReader = new StreamReader(i)) { Reports temp_report = new Reports(); string new_file = ""; string sLine = ""; while (sLine != null) { cancellationToken.ThrowIfCancellationRequested(); sLine = objReader.ReadLine(); if (sLine != null) { foreach (var temp_words in str_words) { if (sLine.Contains(temp_words.word)) { temp_report.Words.Add(temp_words.word); this.list_file.Add(new FileInfo(i)); this.OnPropertyChanged(nameof(List_file)); } } } } if (temp_report.Words.Count > 0) { my_Reports.Add(temp_report); } } } } else { cancellationToken.ThrowIfCancellationRequested(); this.list_file.Add(new FileInfo(i)); this.OnPropertyChanged(nameof(List_file)); } }); } } } catch (Exception s) { System.Windows.MessageBox.Show(s.Message); } } }
void DataReceived(IAsyncResult ar) { AsyncObject obj = (AsyncObject)ar.AsyncState; if (!mSock.Connected) { MessageBox.Show("Server is now ShutDown!"); return; } try { //int received = obj.WorkingSocket.EndReceive(ar); //if (received <= 0) //{ // obj.WorkingSocket.Close(); // return; //} // UTF8 인코더를 사용하여 바이트 배열을 문자열로 변환한다. string text = Encoding.UTF8.GetString(obj.Buffer); // 0x01 기준으로 짜른다. // tokens[0] - 보낸 사람 IP // tokens[1] - 보낸 메세지 string[] tokens = text.Split('/'); string tag = tokens[0]; if (tag.Equals("<LOG>")) // 로그인 { string flag = tokens[1]; if (flag.Equals("true")) { DispatchService.Invoke(() => { ((App)Application.Current).StartMainWindow(); }); } else { MessageBox.Show("Login Failed.....TT"); ((App)Application.Current).CloseSocket(); } } else if (tag.Equals("<REG>")) // 회원가입 { string flag = tokens[1]; if (flag.Equals("true")) { Window s = new SuccessMsgBox("회원가입 성공"); DispatchService.Invoke(() => { ((App)Application.Current).StartMainWindow(); }); s.Show(); } else { MessageBox.Show("Register Failed.....TT"); Window x = new FalseMsgBox("Fail!"); DispatchService.Invoke(() => //너무 많은 UI 어쩌구저쩌구 SPA? STA 나와서 invoke 처리 2019-09-19 다민 { x.Show(); }); } ((App)Application.Current).CloseSocket(); } else if (tag.Equals("<ICF>")) // ID 체크 { string flag = tokens[1]; if (flag.Equals("true")) { MessageBox.Show("ID Check Sucess! in view"); DispatchService.Invoke(() => { ((App)Application.Current).StartMainWindow(); }); } else { MessageBox.Show("ID Check Failed.....TT"); } } else if (tag.Equals("<FRR>")) { if (tokens[1] == "true") { MessageBox.Show("hi"); } else { MessageBox.Show("false"); } } /*else if (tag.Equals("<FRR>")) // 친구추가 * { * if (MessageBoxResult.Yes == //친구 요청 받으면 * MessageBox.Show(tokens[1] + tokens[3], "친구 요청", MessageBoxButton.YesNo)) * { * OnSendData("<FRA>", tokens[1] + "/" + tokens[2]+ "/Yes/"); * } * else * { * OnSendData("<FRA>", tokens[1] + "/" + tokens[2] + "/No/"); * } * DispatchService.Invoke(() => * { * ((App)Application.Current).StartMainWindow(); * }); * } * else if (tag.Equals("<FRA>")) // 친구 feedback * { * MessageBox.Show(tokens[2] + tokens[3]); * DispatchService.Invoke(() => * { * ((App)Application.Current).StartMainWindow(); * }); * } */ else if (tag.Equals("<MSG>")) // 메세지 { database sqlite = new database(); sqlite.ChattingCreate(tokens[1], tokens[2], tokens[3], tokens[4]); DispatchService.Invoke(() => { ((App)Application.Current).AddChat(false, tokens[4]); }); } else if (tag.Equals("<FIN>")) { closeSock(); } // 텍스트박스에 추가해준다. // 비동기식으로 작업하기 때문에 폼의 UI 스레드에서 작업을 해줘야 한다. // 따라서 대리자를 통해 처리한다. //^^^^^^^^ // 클라이언트에선 데이터를 전달해줄 필요가 없으므로 바로 수신 대기한다. // 데이터를 받은 후엔 다시 버퍼를 비워주고 같은 방법으로 수신을 대기한다. obj.ClearBuffer(); // 수신 대기 obj.WorkingSocket.BeginReceive(obj.Buffer, 0, 4096, 0, DataReceived, obj); } catch (Exception e) { MessageBox.Show(e.ToString()); obj.WorkingSocket.Close(); return; } }
/// <summary> /// Start up /// </summary> /// <param name="e">arguments</param> protected override async void OnStartup(StartupEventArgs e) { #region Catch All Unhandled Exceptions // Following code found on stackoverflow.com // http://stackoverflow.com/questions/10202987/in-c-sharp-how-to-collect-stack-trace-of-program-crash AppDomain currentDomain = default; currentDomain = AppDomain.CurrentDomain; // Handler for unhandled exceptions. currentDomain.UnhandledException += GlobalUnhandledExceptionHandler; // Handler for exceptions in thread behind forms. Current.DispatcherUnhandledException += GlobalThreadExceptionHandler; #endregion #region Create LocalApplication Folders. if (!Directory.Exists(MyCommons.LogFileFolderPath)) { Directory.CreateDirectory(MyCommons.LogFileFolderPath); } if (!Directory.Exists(MyCommons.CrashFileFolderPath)) { Directory.CreateDirectory(MyCommons.CrashFileFolderPath); } #endregion #region Error Logging. //// Trace is empty. //MyCommons.isTraceEmpty = true; //// Add textwriter for console. //TextWriterTraceListener consoleOut = // new TextWriterTraceListener(System.Console.Out); //Debug.Listeners.Add(consoleOut); //TextWriterTraceListener fileOut = // new TextWriterTraceListener(MyCommons.CrashFileNameWithPath);//File.CreateText(MyCommons.CrashFileNameWithPath)); //Debug.Listeners.Add(fileOut); // Set the Trace to track errors. // moving all tracing to the ErrorHandler module. // ErrorHandler.Tracer(); #endregion #region Application Starts Here. base.OnStartup(e); //// Verify none of the Omicron modules running, //// without it unexpected behaviors would occur. DispatchService.Invoke(() => { IStartProcessInterface spi = new ProcessFiles(); spi.KillOmicronProcesses(); }); ViewFactory factory = new ViewFactory(); ViewInfrastructure infrastructure = factory.Create(); infrastructure.View.DataContext = infrastructure.ViewModel; #if DEBUG MyCommons.MyViewModel.ReplaceWithTextBoxText = MyResources.Strings_Debug_TextBoxReplace; MyCommons.MyViewModel.FindWhatTextBoxText = MyResources.Strings_Debug_TextBoxFind; #endif MyCommons.MyViewModel.FileSideCoverText = MyResources.Strings_FormStartTest; MyCommons.MyViewModel.ModuleSideCoverText = MyResources.Strings_FormStartModuleTest; MyCommons.MyViewModel.Editable = true; // check for the updates await Task.Run(async() => { // log application update message Debug.WriteLine("Checking for updates", "Informative"); // await for application update await CheckForUpdates(); }); infrastructure.View.Show(); #endregion }
public override void DispatchToUI(Action action) { DispatchService.Invoke(action); }
public void ProceedCommand(object sender, RepeaterEventArgs e) { if (e.Type == ActionTypes.ContactList) { if (e.Result) { var users = (List <User>)e.Data; DispatchService.Invoke(() => { Contacts.Clear(); users.ForEach(u => { var contactViewModel = new ContactViewModel(new ContactModel { Login = u.Login, Status = u.Status, StatusImageUri = getStatusImage(u.Status) }); Contacts.Add(contactViewModel); }); }); } } else if (e.Type == ActionTypes.Message) { if (e.Result) { var messageReq = (MessageReq)e.Data; if (!ConversationWindows.Any(cmv => cmv.Recipeint == messageReq.Login)) { DispatchService.Invoke(() => { var conversationWindow = new ConversationWindow(); var conversationViewModel = new ConversationViewModel(_logicClient); conversationViewModel.OnRequestClose += (s, ee) => { conversationWindow.Close(); DeleteFromConversationList(conversationViewModel.Recipeint); }; var messageModel = new MessageModel { DateTimeDelivery = messageReq.SendTime.ToString("yy-MM-dd hh:dd"), Message = messageReq.Message, Sender = messageReq.Login, Image = GetImageFromAttach(messageReq.Attachment) }; conversationViewModel.Initialize(messageReq.Login); conversationViewModel.AddMessage(messageModel); conversationWindow.DataContext = conversationViewModel; conversationWindow.Show(); ConversationWindows.Add(conversationViewModel); }); } } } else if (e.Type == ActionTypes.PresenceNotification) { var presenceNotification = (PresenceStatusNotification)e.Data; ContactViewModel contact = Contacts.SingleOrDefault(c => c.Login == presenceNotification.Login); if (contact != null) { contact.Status = presenceNotification.PresenceStatus; contact.StatusImageUri = getStatusImage(presenceNotification.PresenceStatus); } } }