//Das ist keine echte Testmethode, aber sinnvoll um eventuell Informationen aus den Exif-Daten zu aktualisieren //[TestMethod] public void UpdateThumbs() { var repository = new DataRepository(); var connector = new DropboxConnector(repository); var member = new Member(); var photos = repository.Queryable <Photo>().Include(p => p.DirectLinks) .Include(p => p.Exif).Where(p => p.CaptureDate == DateTime.MinValue).ToList(); foreach (var photo in photos) { if (photo.DirectLinks == null) { continue; } Log.Info(string.Format("Bearbeite Foto {0} von {3}, mit Namen {1} und Ordner {2}", photo.Id, photo.Name, photo.Folder, photo.MemberId)); var link = photo.DirectLinks.FirstOrDefault(d => d.Size == 0); if (link != null) { var url = link.Url; var image = GetImageFromURL(url); if (image == null) { Log.Info(string.Format("Die Url {0} ist nicht gültig", url)); continue; } var stream = new MemoryStream(); image.Write(stream); stream.Seek(0, SeekOrigin.Begin); var exif = Processing.ReadExifData(stream); if (exif != null) { member.Id = photo.MemberId; connector.CurrentMember = member; exif.PhotoId = photo.Id; if ((string.IsNullOrEmpty(photo.Title) || photo.Title.Equals("Untitled")) && string.IsNullOrEmpty(exif.Title) && !exif.Title.Equals("Untitled")) { photo.Title = exif.Title; } photo.Exif = exif; connector.ExtractCategoriesAndTopics(photo); photo.CaptureDate = exif.CaptureDate; repository.Update(photo); } stream.Close(); stream.Dispose(); image.Dispose(); } } }
internal IConnector CurrentConnector(Member member) { if (member == null || member.StorageAccesses.Count == 0) { return(null); } IConnector connector; switch (member.StorageAccessType) { case StorageProviderType.Dropbox: connector = new DropboxConnector(DataRepository); break; case StorageProviderType.GoogleDrive: connector = new GoogleDrive(DataRepository); break; case StorageProviderType.OneDrive: connector = new Connector.OneDrive.OneDrive(DataRepository); break; case StorageProviderType.LocalDrive: connector = new LocalDrive(DataRepository, string.Format("{0}://{1}", Request.RequestUri.Scheme, Request.RequestUri.Authority), member.Alias); break; default: throw new NotImplementedException("Der Connector ist noch nicht implementiert!"); } var access = member.StorageAccesses.First(s => s.Type == member.StorageAccessType); connector.RedirectUrl = RedirectUrl; connector.CurrentMember = member; connector.Connect(access); return(connector); }
private static void SynchFiles(Member member, DropboxConnector connector, DataRepository repository) { var info = new Notification() { Type = NotificationType.DropboxSynchronization, MemberId = member.Id, }; foreach (var currentStep in connector.RefreshFolderContent()) { info.Date = DateTime.Now; info.Data = currentStep; if (currentStep.Photo != null) { info.PhotoTitle = currentStep.Photo.Name; NotificationHub.PushNotification(info); } if (currentStep.Photo != null) { SavePhotosToDatabase(repository, currentStep.Photo); } } }
internal static Location SetLocationDetails(double latitude, double longitude) { // > http://maps.googleapis.com/maps/api/geocode/json?latlng=LATITUDE,LONGITUDE&sensor=true var request = DropboxConnector.CreateGeoLocationRequest(longitude, latitude); try { var restClient = GetClient("http://maps.googleapis.com"); var response = restClient.Execute <GoogleGeoCodeResponse>(request); if (response.StatusCode == HttpStatusCode.OK && response.Data.results.Any()) { var components = response.Data.results[0].address_components; var location = new Location { Latitude = latitude, Longitude = longitude, Country = components.Where(x => x.types.Contains("country")) .DefaultIfEmpty(new address_component()) .First() .long_name, CountryIsoCode = components.Where(x => x.types.Contains("country")) .DefaultIfEmpty(new address_component()) .First() .short_name, State = components.Where(x => x.types.Contains("administrative_area_level_1")) .DefaultIfEmpty(new address_component()) .First() .long_name, County = components.Where(x => x.types.Contains("administrative_area_level_2")) .DefaultIfEmpty(new address_component()) .First() .long_name, City = components.Where(x => x.types.Contains("locality")) .DefaultIfEmpty(new address_component()) .First() .long_name, Street = components.Where(x => x.types.Contains("route")) .DefaultIfEmpty(new address_component()) .First() .long_name, PhotoCount = 1 }; var arrayToConcat = new[] { location.City ?? location.County ?? location.State, location.Country }; location.Name = string.Join(", ", arrayToConcat .Where(x => !string.IsNullOrEmpty(x))); if (!string.IsNullOrEmpty(location.CountryIsoCode) && location.CountryIsoCode.Length == 2) { location.CountryIsoCode = GetIsoCode3(location.CountryIsoCode); } if (string.IsNullOrEmpty(location.CountryIsoCode)) { location.CountryIsoCode = "???"; } return(location); } } catch (Exception ex) { //Wir ignorieren das, da das Auslesen auch noch manuell implementiert wird Log.Debug("Error setting location", ex); } return(null); }
internal static void StartSynch(dynamic stateInfo) { string userId = stateInfo.UserId.ToString(); lock (_lock) { try { if (DropboxConnector.IsSynchInProgressForUser(userId)) { return; } var repository = new DataRepository(); var memberId = repository.Queryable <MemberStorageAccess>() .Where(m => m.UserId == userId) .Select(m => m.MemberId) .SingleOrDefault(); if (memberId == Constants.NotSetId) { Log.Error("Member not found for user" + userId); return; } var connector = new DropboxConnector(repository); var member = repository.Queryable <Member>().Include(m => m.StorageAccesses) .Include(m => m.Options).FirstOrDefault(m => m.Id == memberId); if (member == null || !member.Options.UseDropboxWebhook) { Log.Info("Member not found or Webhook not enabled"); return; } var access = member.StorageAccesses.FirstOrDefault(s => s.Type == StorageProviderType.Dropbox); connector.CurrentMember = member; connector.Connect(access); Log.Info("Deleting missing photos for " + member.Id); connector.DeleteNotExistingPhotos(); var count = connector.GetFileList().Entries.Count; if (count > 0) { Log.Info(count + " files to synch to begin with"); var info = new Notification() { Type = NotificationType.DropboxSynchronization, MemberId = member.Id, Date = DateTime.Now, Data = new SynchProgress() { Index = 0, TotalFileCount = count } }; if (count > 0) { NotificationHub.PushNotification(info); } while (count > 0) { SynchFiles(member, connector, repository); count = connector.GetFileList().Entries.Count; Log.Info(count + " files to synch left"); } var notification = new Notification() { Type = NotificationType.DropboxSynchronization, MemberId = member.Id, UserAlias = "fotosteam" }; repository.Add(notification); } } catch (Exception ex) { Log.Error(ex); } finally { lock (_lock) { stateInfo.Session.RemoveUserFromSession(userId); } } } }
private void SetUpConnection() { _target = new DropboxConnector(RequestHelper.CurrentDataRepository); }