private async Task CreateThumbnails() { Boolean _requestThumbnailUpdate = false; int _count = 1; foreach (Album _album in Albums) { if (await _album.CreateThumbnails(Id, this)) { _requestThumbnailUpdate = true; } ProgressUpdate(_res.GetString("CreatingThumb") + " " + _count + " " + _res.GetString("Of") + " " + Albums.Count + "...", 100 * _count / Albums.Count); _count++; } if (_requestThumbnailUpdate) { List <String> _pictureThumbList = new List <string>(); foreach (Album _album in Albums) { foreach (String _path in _album.Summary.PicturesThumb) { _pictureThumbList.Add(_path); } } Summary.PicturesThumb = TripSummary.GetRandomList(_pictureThumbList); } }
public static async Task <Trip> LoadFromSummary(TripSummary _tripSummary) { StorageFile _file; if (_tripSummary.Sample) { _file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///appdata/" + _tripSummary.PathThumb + ".trip")); } else { _file = await ApplicationData.Current.LocalFolder.GetFileAsync(_tripSummary.Id + ".trip"); } Trip _trip = Serialization.DeserializeFromXmlFile <Trip>(_file.Path); if (_trip.Summary.DataCoherent()) { return(_trip); } else #if DEBUG { throw new FormatException(); } #else { return(new Trip()); } #endif }
public async override Task <Boolean> DeleteContent(TripSummary _summary) { try { String _path = LocalSettings.LoadStorageValue <String>(LOCAL_OAUTH_TOKEN_REFRESH); StorageFolder _rootGT, _rootTrip; try { _rootGT = await StorageFolder.GetFolderFromPathAsync(_path); } catch { // device not available, return error return(false); } try { _rootTrip = await _rootGT.GetFolderAsync(_summary.FolderTopName); } catch { // device available, folder already deleted return(true); } await DeleteRecursive(_rootTrip); return(true); } catch (Exception e) { Debug.WriteLine(e.Message); return(false); } }
public Trip() { Id = RandomNum(0).ToString(); Albums = new List <Album>(); Itineraries = new List <Itinerary>(); Summary = new TripSummary(); _res = ResourceLoader.GetForCurrentView(); }
public void UpdateAll(TripSummary tripSummary) { Update(tripSummary.SyncDropbox); Update(tripSummary.SyncUsb); #if STEP2 Update(tripSummary.SyncGooglePlus); Update(tripSummary.SyncFacebook); #endif }
private async void gridDisp_Drop(object sender, DragEventArgs e) { TripDescUserControl _tripDescSrc; TripDescUserControl _tripDescDest; if (e.OriginalSource is FrameworkElement) { FrameworkElement _temp = e.OriginalSource as FrameworkElement; if (_temp.DataContext is TripDescUserControl) { _tripDescDest = _temp.DataContext as TripDescUserControl; } else { return; } } else { return; } if (_listTripDesc.Count >= _itemIndexDelete) { _tripDescSrc = _listTripDesc[_itemIndexDelete]; } else { return; } _importInProgress = true; imageTrash.Visibility = Visibility.Collapsed; ringImport.IsActive = true; _app.AppSettings.LearnDone("TOPIC_DRAG_DELETE"); if (await TripSummary.Merge(_tripDescSrc, _tripDescDest, this)) { await DeleteTrip(_tripDescSrc, true); } ProgressFinished(""); _importInProgress = false; }
public static async Task <Boolean> DeleteFiles(String _tripName, List <TripSummary> _listSummary, Boolean _save) { if (_listSummary == null) { _listSummary = await TripSummary.Load(); } try { foreach (TripSummary _summary in _listSummary) { if (_summary.Id.Equals(_tripName)) { _listSummary.Remove(_summary); break; } } if (_save) { await TripSummary.Save(_listSummary); } StorageFile fileDelete = await ApplicationData.Current.LocalFolder.GetFileAsync(_tripName + ".trip"); await fileDelete.DeleteAsync(StorageDeleteOption.PermanentDelete); StorageFolder folderDelete = await ApplicationData.Current.LocalFolder.GetFolderAsync(_tripName); await folderDelete.DeleteAsync(StorageDeleteOption.PermanentDelete); return(true); } catch (Exception e) { Debug.WriteLine(e.Message); return(false); } }
public override Task <Boolean> DeleteContent(TripSummary _summary) { return(null); }
private async Task <Boolean> synchronizeAlbum(Album _album, String _pathTrip, TripSummary _summary) { String _pathAlbum = "/" + _pathTrip + "/" + _album.PathAlbum; ResponseContainer _folderDesc = null; ProgressUpdate(Res.GetString("SynchroAlbum") + " \"" + _album.Summary.Name + "\"", 0); //list top-folder String _request = API_METADATA + "/sandbox/" + _pathAlbum + "?access_token=" + Token + "&hash=" + _album.Hash; HttpResponseMessage _response = await SendRequest(_request); if (_response != null) { if (_response.StatusCode == HttpStatusCode.OK) { _folderDesc = await Serialization.DeserializeHttpToJson <ResponseContainer>(_response.Content) as ResponseContainer; } else if (_response.StatusCode == HttpStatusCode.NotFound) { _folderDesc = await CreateFolder(_pathTrip + "/" + _album.PathAlbum); } } if (_folderDesc != null) { Boolean _status = true; if ((_folderDesc.contents != null) && (_folderDesc.contents.Count() != 0)) { //check if all dropbox pictures are synchronized with local pictures, delete if not in local folder foreach (ResponseElement _element in _folderDesc.contents) { if (_element.is_dir) { _status &= await Delete(_element.path); } else { Boolean _found = false; foreach (Picture _picture in _album.Pictures) { if (_pathAlbum + "/" + _picture.Name + _picture.Extension == _element.path) { _found = true; } } if (!_found) { _status &= await Delete(_element.path); } } } if (!_status || CancelInProgress()) { return(false); } } //check if all local pictures are synchronized with dropbox pictures int _countParts = 0; foreach (Picture _picture in _album.Pictures) { Boolean _found = false; if (_folderDesc.contents != null) { foreach (ResponseElement _element in _folderDesc.contents) { if (_pathAlbum + "/" + _picture.Name + _picture.Extension == _element.path) { _found = true; } } } if (!_found) { UploadOperation _newUpload = await synchronizePicture(_picture, _pathAlbum, _countParts ++, _summary); if (_newUpload != null) { UploadList.Add(_newUpload); } } if (CancelInProgress()) { return(false); } } return(true); } return(false); }
private async Task <Boolean> synchronizePicture(Picture _picture, StorageFolder _folderAlbum, int _index, TripSummary _summary) { StorageFile _file = null; try { if (_summary.Sample) { _file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///appdata/" + _summary.PathThumb + "/" + _summary.PicturesThumb[_index % 4])); } else { _file = await StorageFile.GetFileFromPathAsync(_picture.GetPath()); } // compress to jpeg: 0 (no compression) -> 3 (high) if (Compression == SynchroManager.ComprLevel.Medium) { _file = await Picture.CompressAndSaveFileAsync(_file.Path, ApplicationData.Current.LocalFolder.Path, _file.Name, 1920, false); } else if (Compression == SynchroManager.ComprLevel.High) { _file = await Picture.CompressAndSaveFileAsync(_file.Path, ApplicationData.Current.LocalFolder.Path, _file.Name, 1024, false); } StorageFile _fileCopy = await _file.CopyAsync(_folderAlbum, _file.Name, NameCollisionOption.ReplaceExisting); if ((_fileCopy != null) && (Compression == SynchroManager.ComprLevel.Medium) || (Compression == SynchroManager.ComprLevel.High)) { await _file.DeleteAsync(); } } catch (Exception e) { Debug.WriteLine(e.Message); return(false); } return(true); }
private async Task loadUserTrip() { _listSummary = await TripSummary.Load(); _tripNumberUser = _listSummary.Count; StorageFile _fileCountries = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///appdata/CountryDefinition.desc")); _listCountriesStandard = Serialization.DeserializeFromXmlFile <List <Country> >(_fileCountries.Path); if (_tripNumberUser == 0) { if (_app.AppSettings.LearnInProgress("TOPIC_SAMPLE_A")) { StorageFile _fileSample = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///appdata/SampleA.desc")); TripSummary _sample = Serialization.DeserializeFromXmlFile <TripSummary>(_fileSample.Path); _listSummary.Add(_sample); } if (_app.AppSettings.LearnInProgress("TOPIC_SAMPLE_B")) { StorageFile _fileSample = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///appdata/SampleB.desc")); TripSummary _sample = Serialization.DeserializeFromXmlFile <TripSummary>(_fileSample.Path); _listSummary.Add(_sample); } } if (_listSummary.Count == 0) { _appBar.Show(AppBarPage.SIDE.BOTH); } else if (_listSummary.Count > 0) { List <TripSummary> _tripSummOrd = _listSummary.OrderByDescending <TripSummary, DateTime>(o => o.DateArrival).ToList <TripSummary>(); foreach (TripSummary _summary in _tripSummOrd) { // displayed trip description block TripDescUserControl blk = new TripDescUserControl(this, _app.AppSettings.GetConfig("CONFIG_MILES"), _app.AppSettings.ThemeColors); blk.DefBlockTrip = _summary; _listTripDesc.Add(blk); Distance += _summary.Distance; } } StorageFile _imageAccount = UserInformation.GetAccountPicture(AccountPictureKind.SmallImage) as StorageFile; #if DEBUG _imageAccount = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///assets/user.png")); _app.AppSettings.DisplayName = _res.GetString("Guest"); #endif IRandomAccessStream _stream = await _imageAccount.OpenReadAsync(); BitmapImage _bmp = new BitmapImage(); _bmp.SetSource(_stream); profilePicture.Source = _bmp; profilePicture.Visibility = Visibility.Visible; profileName.Text = _app.AppSettings.DisplayName + " >"; rewards(); foreach (TripDescUserControl _tripDesc in _listTripDesc) { _app.SynchroManager.UpdateAll(_tripDesc.DefBlockTrip); } }
public void NavigateToConf(TripSummary _summary) { ConfObj _obj = new ConfObj(this, _summary, null); this.Frame.Navigate(typeof(ViewConf), _obj); }
public async Task SaveSummary() { await TripSummary.Save(_listSummary); }
public abstract Task <Boolean> DeleteContent(TripSummary _summary);
private async Task <UploadOperation> synchronizePicture(Picture _picture, String _pathAlbum, int _index, TripSummary _summary) { StorageFile _file; BackgroundUploader _uploader = new BackgroundUploader(); UploadOperation _upload = null; String _request = API_FILES_PUT + "/sandbox/" + _pathAlbum + "/" + _picture.Name + _picture.Extension + "?access_token=" + Token + "&overwrite=true"; try { if (_summary.Sample) { _file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///appdata/" + _summary.PathThumb + "/" + _summary.PicturesThumb[_index % 4])); } else { _file = await StorageFile.GetFileFromPathAsync(_picture.GetPath()); } } catch (FileNotFoundException) { return(null); } try { _upload = _uploader.CreateUpload(new Uri(_request), _file); } catch (Exception e) { Debug.WriteLine(e.Message); } return(_upload); }
private async Task <Boolean> synchronizeAlbum(Album _album, StorageFolder _folderAlbum, TripSummary _summary) { Boolean _found = false; Boolean _status = true; IReadOnlyList <IStorageItem> _items = await _folderAlbum.GetItemsAsync(); foreach (Picture _picture in _album.Pictures) { ProgressUpdate(Res.GetString("Upload") + " \"" + _picture.Name + _picture.Extension + "\"", 100 * _album.Pictures.IndexOf(_picture) / _album.Pictures.Count); foreach (StorageFile _item in _items) { if (_item.Name.Equals(_picture.Name + _picture.Extension)) { _found = true; break; } } if (!_found) { _status &= await synchronizePicture(_picture, _folderAlbum, _album.Pictures.IndexOf(_picture), _summary); } if (!_status || CancelInProgress()) { return(false); } } return(true); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { _initFinished = false; _listLoaded = false; if (e.Parameter is ConfObj) { TripSummaryRef = (e.Parameter as ConfObj).TripSummary; AlbumSummaryRef = (e.Parameter as ConfObj).AlbumSummary; PageRef = (e.Parameter as ConfObj).Page; } else { throw new Exception(); } TripRef = await Trip.LoadFromSummary(TripSummaryRef); if ((TripRef.Sample) || !(PageRef is ViewHome)) { TextBoxReadOnly(TripName, true); TextBoxReadOnly(TripLocation, true); } // config from summary TripLocation.Text = TripSummaryRef.LocationFromTo; if (TripRef.Sample) { TripName.Text = TripSummaryRef.LocationMain; TripPath.Text = "Sample"; btnUpdate.IsEnabled = false; } else { TripName.Text = TripSummaryRef.FolderTopName; TripPath.Text = TripRef.PathRoot; } // config from trip AlbumNum.Text = TripRef.Albums.Count().ToString(); ChkRename.IsChecked = TripRef.Reorganize; ChkDropbox.IsChecked = TripSummaryRef.SyncDropbox.Requested; UpdateCheckSync(TripSummaryRef.SyncDropbox, ComboDropbox, ChkDropbox); ChkUsb.IsChecked = TripSummaryRef.SyncUsb.Requested; UpdateCheckSync(TripSummaryRef.SyncUsb, ComboUsb, ChkUsb); UpdateLayout(); // used for selection AlbumConfUserControl _itemRef = null; int _count = 0; foreach (Album _album in TripRef.Albums) { _count += _album.Pictures.Count; AlbumConfUserControl _userControl = new AlbumConfUserControl(_album, NotifyChange); listAlbums.Add(_userControl); if ((AlbumSummaryRef != null) && (_album.Id == AlbumSummaryRef.Id)) { _itemRef = _userControl; } } PicNum.Text = _count.ToString(); tableAlbums.ItemsSource = listAlbums; if (_itemRef != null) { tableAlbums.SelectedItem = _itemRef; tableAlbums.ScrollIntoView(_itemRef, ScrollIntoViewAlignment.Leading); } _initFinished = true; ProgressFinished(""); navigationHelper.OnNavigatedTo(e); }
public ConfObj(Page _pageRef, TripSummary _tripSummary, AlbumSummary _albumSummary) { TripSummary = _tripSummary; AlbumSummary = _albumSummary; Page = _pageRef; }
public async override Task <Boolean> DeleteContent(TripSummary _summary) { return(await Delete(_summary.FolderTopName)); }