public SkyDrivePhoto(ICloudFolder parent, IDictionary <string, object> objectDictionary) : base(parent, objectDictionary) { this.TagsCount = Dictionary.tags_count; this.TagsEnabled = Dictionary.tags_enabled; this.IsEmbeddable = Dictionary.is_embeddable; this.PictureLocation = Dictionary.picture; this.WhenTaken = DynamicExtension.ToDateTime(Dictionary.when_taken); this.Height = Dictionary.height; this.Width = Dictionary.width; this.CameraMake = Dictionary.camera_make; this.CameraModel = Dictionary.camera_model; this.FocalRatio = Dictionary.focal_ration; this.FocalLength = Dictionary.focal_length; this.ExposureNumerator = Dictionary.exposure_numerator; this.ExposureDenominator = Dictionary.exposure_denominator; this.PhotographyLocation = Dictionary.location ?? "Location Unavailable."; this.Photos = new Dictionary <PhotoType, PhotoCard>(Dictionary.images.Count); foreach (dynamic photo in Dictionary.images) { var card = new PhotoCard(); card.Height = photo.height; card.Width = photo.width; card.PhotoType = (PhotoType)Enum.Parse(typeof(PhotoType), photo.type, true); card.DownloadSourceLocation = photo.source; if (this.Photos.ContainsKey(card.PhotoType)) { this.Photos.Remove(card.PhotoType); } this.Photos.Add(card.PhotoType, card); } }
public SkyDrivePhoto(ICloudFolder parent, IDictionary<string, object> objectDictionary) : base(parent, objectDictionary) { this.TagsCount = Dictionary.tags_count; this.TagsEnabled = Dictionary.tags_enabled; this.IsEmbeddable = Dictionary.is_embeddable; this.PictureLocation = Dictionary.picture; this.WhenTaken = DynamicExtension.ToDateTime(Dictionary.when_taken); this.Height = Dictionary.height; this.Width = Dictionary.width; this.CameraMake = Dictionary.camera_make; this.CameraModel = Dictionary.camera_model; this.FocalRatio = Dictionary.focal_ration; this.FocalLength = Dictionary.focal_length; this.ExposureNumerator = Dictionary.exposure_numerator; this.ExposureDenominator = Dictionary.exposure_denominator; this.PhotographyLocation = Dictionary.location ?? "Location Unavailable."; this.Photos = new Dictionary<PhotoType, PhotoCard>(Dictionary.images.Count); foreach (dynamic photo in Dictionary.images) { var card = new PhotoCard(); card.Height = photo.height; card.Width = photo.width; card.PhotoType = (PhotoType) Enum.Parse(typeof (PhotoType), photo.type, true); card.DownloadSourceLocation = photo.source; if (this.Photos.ContainsKey(card.PhotoType)) this.Photos.Remove(card.PhotoType); this.Photos.Add(card.PhotoType, card); } }
public CloudFolder(ICloudFolder folder, IFolder parent) : base(string.Empty, parent) { if (folder.IsNull() || parent.IsNull()) { throw new ArgumentNullException(); } this.CloudItem = folder; this.Parent = parent; this.Name = folder.Name; this.LastModifyTime = folder.ModificationTime; this.Size = folder.Size; this.FullPath = Path.Combine(parent.FullPath, folder.CloudId); this.AddPlaceHolder(); }
private async void Init(LiveConnectSession session) { if (session == null) throw new NullReferenceException("The 'session' parameter cannot be null"); _liveClient = new LiveConnectClient(session); _absoluteRootDirectory = RootDirectory; LiveOperationResult operationResult = await _liveClient.GetAsync("me"); //me, or user id will be taken cared of by the session object which will specifically connect to a particular user. so no need to worry about supporting multiple user accounts here. dynamic result = operationResult.Result; this.UserName = result.name; _rootCloudObject = await GetRootDirectoryAsync(); //_rootCloudObject = new SkyDriveObject(operationResult.Result.Result); }
private ICloudFolder FindParent(ICloudFolder searchFrom, string childId) { foreach (ICloudObject obj in searchFrom.Children) { if (obj.Id == childId) return searchFrom; else { if (obj is ICloudFolder) { ICloudFolder parent = FindParent((ICloudFolder)obj, childId); if (parent != null) return parent; } } } return null; }
private async void Init(LiveConnectSession session) { if (session == null) { throw new NullReferenceException("The 'session' parameter cannot be null"); } _liveClient = new LiveConnectClient(session); _absoluteRootDirectory = RootDirectory; LiveOperationResult operationResult = await _liveClient.GetAsync("me"); //me, or user id will be taken cared of by the session object which will specifically connect to a particular user. so no need to worry about supporting multiple user accounts here. dynamic result = operationResult.Result; this.UserName = result.name; _rootCloudObject = await GetRootDirectoryAsync(); //_rootCloudObject = new SkyDriveObject(operationResult.Result.Result); }
/// <summary> /// Returns the translated path for the given unique onedrive path. e.g. OneDrive://SkyDrive/ can be translated to me/SkyDrive or folder.72981f91d7bb629c. /// </summary> /// <param name="uniqueOneDrivePath"></param> /// <returns></returns> public override async Task <string> GetTranslatedPathFromAsync(string uniqueOneDrivePath) { string[] objectNames = uniqueOneDrivePath.Substring(SkyDrivePrefix.Length).Split(OneDriveSettings.PATH_SEPERATOR); if (objectNames == null || objectNames.Length == 0) { throw new OneDriveOutOfSyncException("OneDrive is out of sync.", OneDriveErrorCode.OneDriveIsOutOfSync); } if (_rootCloudObject.ChildObjectCountOnTheCloud == 0) { _rootCloudObject = await GetRootDirectoryAsync(); if (_rootCloudObject.ChildObjectCountOnTheCloud == 0) { throw new OneDriveOutOfSyncException("OneDrive is out of sync.", OneDriveErrorCode.OneDriveIsOutOfSync); } } return(await TriangulateObjectIdFromPathAsync(objectNames, _rootCloudObject, 0)); }
private ICloudFolder FindParent(ICloudFolder searchFrom, string childId) { foreach (ICloudObject obj in searchFrom.Children) { if (obj.Id == childId) { return(searchFrom); } else { if (obj is ICloudFolder) { ICloudFolder parent = FindParent((ICloudFolder)obj, childId); if (parent != null) { return(parent); } } } } return(null); }
private async Task <ICloudObject> _GetCloudObjectFromSkyDriveObjectIdAsync(string skyDriveObjectId, bool fetchChildren = true) { ICloudObject cloudObject = null; //TODO: Validate if session requires renewal. Skydrive does not supports unique paths with sub directories. //do some recursive calls to construct sub directory paths with some caching so that the path can be optimized. //do make sure that the path exists aka is not deleted or moved. LiveOperationResult operationResult = await _liveClient.GetAsync(skyDriveObjectId); dynamic result = operationResult.Result; ICloudFolder parent = FindParent(_rootCloudObject, result.id); if (result.type == "folder") { if (fetchChildren) { LiveOperationResult childrenResult = await _liveClient.GetAsync(skyDriveObjectId + "/files"); cloudObject = new SkyDriveFolder(parent, result, ((dynamic)childrenResult.Result).data); } else { cloudObject = new SkyDriveFolder(parent, result, null); } } else if (result.type == "album") { if (fetchChildren) { LiveOperationResult childrenResult = await _liveClient.GetAsync(skyDriveObjectId + "/files"); cloudObject = new SkyDriveAlbum(parent, result, ((dynamic)childrenResult.Result).data); } else { cloudObject = new SkyDriveAlbum(parent, result, null); } } else if (result.type == "file") { cloudObject = new SkyDriveFile(parent, result); } else if (result.type == "photo") { cloudObject = new SkyDrivePhoto(parent, result); } //Replace the oldChildRef with the new ref. We need to do it everytime to keep the offline cache updated. if (cloudObject != null && parent != null) { ICloudObject oldChildRef = parent.Children.FirstOrDefault(obj => obj.Id == cloudObject.Id); if (oldChildRef != null) { int index = parent.Children.IndexOf(oldChildRef); parent.Children.Remove(oldChildRef); parent.Children.Insert(index, cloudObject); } } return(cloudObject); }
private async Task <string> TriangulateObjectIdFromPathAsync(string[] objectNames, ICloudFolder searchFromFolder, ushort currentIndex) { if (objectNames == null || objectNames.Length < currentIndex) { return(string.Empty); } ICloudObject objectFound = null; string searchFor = objectNames[currentIndex]; //verify if searchFromFolder and objectNames are in sync. We should have something to search from in the following check. if (searchFromFolder.Children.Count == 0 && (searchFromFolder.ChildObjectCountOnTheCloud > 0 || currentIndex < objectNames.Length - 1)) { searchFromFolder = (ICloudFolder)(await _GetCloudObjectFromSkyDriveObjectIdAsync(searchFromFolder.Id, true)); if (searchFromFolder.Children.Count == 0) { throw new OneDriveOutOfSyncException("The Cloud Object cannot be found : " + searchFor, OneDriveErrorCode.CloudObjectNotFound); } } //Check if the Cached collection tree has got the object information. foreach (ICloudObject obj in searchFromFolder.Children) { if (obj.Name == searchFor) { objectFound = obj; if (currentIndex < objectNames.Length - 1) //Search for more recursively! objectFound should be a folder. { var folder = objectFound as ICloudFolder; if (folder != null) { return(await TriangulateObjectIdFromPathAsync(objectNames, folder, ++currentIndex)); } throw new OneDriveOutOfSyncException("The Cloud Object is no more a folder. It may have changed recently : " + searchFor, OneDriveErrorCode.CloudObjectTypeChanged); } break; //Object found but verify! } } if (currentIndex == objectNames.Length - 1) { if (objectFound != null) { if (objectFound.IsValid) { return(objectFound.Id); } searchFromFolder = (ICloudFolder) await _GetCloudObjectFromSkyDriveObjectIdAsync(searchFromFolder.Id); if (searchFromFolder.ChildObjectCountOnTheCloud > 0) { //Verify by unique id that the object has not changed. ICloudObject realObject = searchFromFolder.Children.First(child => child.Id == objectFound.Id); return(realObject.Id); } throw new OneDriveOutOfSyncException("The Cloud Object cannot be found : " + searchFor, OneDriveErrorCode.CloudObjectNotFound); } throw new OneDriveOutOfSyncException("The Cloud Object cannot be found : " + searchFor, OneDriveErrorCode.CloudObjectNotFound); } throw new OneDriveOutOfSyncException("The Cloud Object is no more a folder. It may have changed recently : " + searchFor, OneDriveErrorCode.CloudObjectTypeChanged); }
private async Task<string> TriangulateObjectIdFromPathAsync(string[] objectNames, ICloudFolder searchFromFolder, ushort currentIndex) { if (objectNames == null || objectNames.Length < currentIndex) return string.Empty; ICloudObject objectFound = null; string searchFor = objectNames[currentIndex]; //verify if searchFromFolder and objectNames are in sync. We should have something to search from in the following check. if (searchFromFolder.Children.Count == 0 && (searchFromFolder.ChildObjectCountOnTheCloud > 0 || currentIndex < objectNames.Length - 1)) { searchFromFolder = (ICloudFolder)(await _GetCloudObjectFromSkyDriveObjectIdAsync(searchFromFolder.Id, true)); if (searchFromFolder.Children.Count == 0) throw new OneDriveOutOfSyncException("The Cloud Object cannot be found : " + searchFor, OneDriveErrorCode.CloudObjectNotFound); } //Check if the Cached collection tree has got the object information. foreach (ICloudObject obj in searchFromFolder.Children) { if (obj.Name == searchFor) { objectFound = obj; if (currentIndex < objectNames.Length - 1) //Search for more recursively! objectFound should be a folder. { var folder = objectFound as ICloudFolder; if(folder != null) return await TriangulateObjectIdFromPathAsync(objectNames, folder, ++currentIndex); throw new OneDriveOutOfSyncException("The Cloud Object is no more a folder. It may have changed recently : " + searchFor, OneDriveErrorCode.CloudObjectTypeChanged); } break; //Object found but verify! } } if (currentIndex == objectNames.Length - 1) { if (objectFound != null) { if (objectFound.IsValid) return objectFound.Id; searchFromFolder = (ICloudFolder)await _GetCloudObjectFromSkyDriveObjectIdAsync(searchFromFolder.Id); if (searchFromFolder.ChildObjectCountOnTheCloud > 0) { //Verify by unique id that the object has not changed. ICloudObject realObject = searchFromFolder.Children.First(child => child.Id == objectFound.Id); return realObject.Id; } throw new OneDriveOutOfSyncException("The Cloud Object cannot be found : " + searchFor, OneDriveErrorCode.CloudObjectNotFound); } throw new OneDriveOutOfSyncException("The Cloud Object cannot be found : " + searchFor, OneDriveErrorCode.CloudObjectNotFound); } throw new OneDriveOutOfSyncException("The Cloud Object is no more a folder. It may have changed recently : " + searchFor, OneDriveErrorCode.CloudObjectTypeChanged); }
/// <summary> /// Returns the translated path for the given unique onedrive path. e.g. OneDrive://SkyDrive/ can be translated to me/SkyDrive or folder.72981f91d7bb629c. /// </summary> /// <param name="uniqueOneDrivePath"></param> /// <returns></returns> public override async Task<string> GetTranslatedPathFromAsync(string uniqueOneDrivePath) { string[] objectNames = uniqueOneDrivePath.Substring(SkyDrivePrefix.Length).Split(OneDriveSettings.PATH_SEPERATOR); if (objectNames == null || objectNames.Length == 0) throw new OneDriveOutOfSyncException("OneDrive is out of sync.", OneDriveErrorCode.OneDriveIsOutOfSync); if (_rootCloudObject.ChildObjectCountOnTheCloud == 0) { _rootCloudObject = await GetRootDirectoryAsync(); if (_rootCloudObject.ChildObjectCountOnTheCloud == 0) { throw new OneDriveOutOfSyncException("OneDrive is out of sync.", OneDriveErrorCode.OneDriveIsOutOfSync); } } return await TriangulateObjectIdFromPathAsync(objectNames, _rootCloudObject, 0); }