public static async Task<bool> LoadFrom ( ObservableCollection<RecentData> datas ) { try { StorageFile sf = await ApplicationData.Current.LocalFolder.GetFileAsync ( "data.dat" ); FileRandomAccessStream stream = await sf.OpenAsync ( FileAccessMode.Read ) as FileRandomAccessStream; DataReader dr = new DataReader ( stream ); dr.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; dr.ByteOrder = ByteOrder.LittleEndian; await dr.LoadAsync ( ( uint ) stream.Size ); int len = dr.ReadInt32 (); for ( int i = 0; i < len; i++ ) { RecentData data = new RecentData (); uint srclen = dr.ReadUInt32 (); data.Source = dr.ReadString ( srclen ); data.SourceIndex = dr.ReadInt32 (); data.TargetIndex = dr.ReadInt32 (); datas.Add ( data ); } stream.Dispose (); } catch { return false; } return true; }
private void btnTranslate_Click ( object sender, RoutedEventArgs e ) { btnTranslate.IsEnabled = false; prgProcess.Visibility = Windows.UI.Xaml.Visibility.Visible; Translator.TranslateEnded += () => { RecentData recentData = new RecentData (); recentData.Source = txtSource.Text; recentData.SourceIndex = cmbSource.SelectedIndex; recentData.TargetIndex = cmbDest.SelectedIndex; var ee = from b in recentList where b.Equals ( recentData ) select b; bool bb = false; foreach ( var a in ee ) bb = true; if ( !bb ) { recentList.Add ( recentData ); DataManager.SaveTo ( recentList ); } Retrans (); }; try { Translator.Translate ( ( LangTransRT.Language ) ( cmbSource.SelectedIndex + 1 ), ( LangTransRT.Language ) ( cmbDest.SelectedIndex + 1 ), txtSource.Text ); } catch { Task<MessageBoxResult> mr = MessageBox.ShowAsync ( "번역에 실패했습니다!", "랑트랜스", MessageBoxButton.OK ); Retrans (); } }