Exemple #1
0
        protected static void FillNullsFrom(ICloudObject thisObject, ICloudObject otherObject)
        {
            /* Fill otherObject null properties with
             * this object object properties.
             */

            var sourceProps = otherObject.GetType().GetRuntimeProperties()
                              .Where(x => x.CanWrite).ToList();
            var destProps = otherObject.GetType().GetRuntimeProperties()
                            .Where(x => x.CanWrite).ToList();

            foreach (var sourceProp in sourceProps)
            {
                var value = sourceProp.GetValue(thisObject, null);
                var p     = destProps.FirstOrDefault(x => x.Name == sourceProp.Name);

                if (p != null)
                {
                    var valueDst = p.GetValue(otherObject, null);

                    if (valueDst == null)
                    {
                        p.SetValue(otherObject, value, null);
                    }
                }
            }
        }
 public SkyDriveAudio(ICloudObject parent, IDictionary <string, object> objectDictionary) : base(parent, objectDictionary)
 {
     Title       = Dictionary.title;
     Artist      = Dictionary.artist;
     Album       = Dictionary.album;
     AlbumArtist = Dictionary.album_artist;
     Genre       = Dictionary.genre;
     Duration    = Dictionary.duration;
     Picture     = Dictionary.picture;
 }
 public SkyDriveAudio(ICloudObject parent, IDictionary<string, object> objectDictionary)
     : base(parent, objectDictionary)
 {
     Title = Dictionary.title;
     Artist = Dictionary.artist;
     Album = Dictionary.album;
     AlbumArtist = Dictionary.album_artist;
     Genre = Dictionary.genre;
     Duration = Dictionary.duration;
     Picture = Dictionary.picture;
 }
Exemple #4
0
        public SkyDriveFolder(ICloudObject parent, IDictionary <string, object> objectDictionary, IEnumerable <object> children) : base(parent, objectDictionary)
        {
            Children = new List <ICloudObject>();
            if (Dictionary.type == "folder" || Dictionary.type == "album")
            {
                this.ChildObjectCountOnTheCloud = Dictionary.count ?? 0;
            }

            if (children != null)
            {
                PopulateChildren(children);
            }
        }
        public SkyDriveFolder(ICloudObject parent, IDictionary<string, object> objectDictionary, IEnumerable<object> children) : base(parent, objectDictionary)
        {
            Children = new List<ICloudObject>();
            if (Dictionary.type == "folder" || Dictionary.type == "album")
            {
                this.ChildObjectCountOnTheCloud = Dictionary.count ?? 0;
            }

            if (children != null)
            {
                PopulateChildren(children);
            }
        }
Exemple #6
0
        /// <summary>
        /// A path which is virtual but something which is supported by OneDrive. e.g. OneDrive://SkyDrive/me/abc/def and using a PathTranslator this could translate to something like folder.72981f91d7bb629c in case of SkyDrive
        /// </summary>
        public string GetOneDriveFullPath()
        {
            ICloudObject obj   = this;
            var          paths = new List <string>();

            do
            {
                paths.Add(obj.Name);
                obj = obj.Parent;
                if (obj == null)
                {
                    break;
                }
            } while (true);

            paths.Reverse();
            return(OneDriveSettings.ONE_DRIVE_PROTOCOL + string.Join(OneDriveSettings.PATH_SEPERATOR.ToString(), paths));
        }
Exemple #7
0
        public void CopyTo(ICloudObject otherObject)
        {
            if (otherObject.GetType().IsAssignableFrom(_helpee.GetType()) ||
                _helpee.GetType().IsAssignableFrom(otherObject.GetType()))
            {
                var sourceProps = _helpee.GetType().GetRuntimeProperties()
                                  .Where(x => x.CanWrite).ToList();
                var destProps = otherObject.GetType().GetRuntimeProperties()
                                .Where(x => x.CanWrite).ToList();

                foreach (var sourceProp in sourceProps)
                {
                    var destProp = destProps.FirstOrDefault(
                        prop => (prop.Name == sourceProp.Name &&
                                 prop.GetType() == sourceProp.GetType()));

                    if (destProp != null)
                    {
                        destProp.SetValue(otherObject, sourceProp.GetValue(_helpee, null), null);
                    }
                }
            }
        }
        protected SkyDriveObject(ICloudObject parent, IDictionary<string, object> objectDictionary)
        {
            _objectCachedOn = DateTime.Now;
            this.Parent = parent;
            // TODO: Complete member initialization
            this.Dictionary = objectDictionary;

            this.Id = Dictionary.id;
            this.Name = Dictionary.name;
            CreatedBy = Dictionary.from.name;
            CreatedByUserId = Dictionary.from.id;
            this.Size = Dictionary.size ?? 0;
            this.Description = Dictionary.description;
            this.FullPath = Dictionary.link;
            this.CreatedOn = DynamicExtension.ToDateTime(Dictionary.created_time);

            this.UpdatedOn = DynamicExtension.ToDateTime(Dictionary.updated_time);

            this.SharedWith = GetSharedWith(Dictionary.shared_with);
            this.UploadLocation = Dictionary.upload_location;

            this.CommentsCount = Dictionary.comments_count;
            this.CommentsEnabled = Dictionary.comments_enabled;
        }
Exemple #9
0
        protected SkyDriveObject(ICloudObject parent, IDictionary <string, object> objectDictionary)
        {
            _objectCachedOn = DateTime.Now;
            this.Parent     = parent;
            // TODO: Complete member initialization
            this.Dictionary = objectDictionary;

            this.Id          = Dictionary.id;
            this.Name        = Dictionary.name;
            CreatedBy        = Dictionary.from.name;
            CreatedByUserId  = Dictionary.from.id;
            this.Size        = Dictionary.size ?? 0;
            this.Description = Dictionary.description;
            this.FullPath    = Dictionary.link;
            this.CreatedOn   = DynamicExtension.ToDateTime(Dictionary.created_time);

            this.UpdatedOn = DynamicExtension.ToDateTime(Dictionary.updated_time);

            this.SharedWith     = GetSharedWith(Dictionary.shared_with);
            this.UploadLocation = Dictionary.upload_location;

            this.CommentsCount   = Dictionary.comments_count;
            this.CommentsEnabled = Dictionary.comments_enabled;
        }
        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);
        }
 public Task <bool> CancelDownload(ICloudObject cloudObject)
 {
     throw new System.NotImplementedException();
 }
 public Task <bool> IsObjectInDownloadQueue(ICloudObject cloudObject)
 {
     throw new System.NotImplementedException();
 }
Exemple #13
0
 public SkyDriveFile(ICloudObject parent, IDictionary<string, object> objectDictionary)
     : base(parent, objectDictionary)
 {
     this.DownloadSourceLocation = Dictionary.source;
 }
Exemple #14
0
 public void CopyTo(ICloudObject otherObject)
 {
     _helper.CopyTo(otherObject);
 }
 public BackgroundDownloadPackage(ICloudObject cloudObject, IStorageFile storageFile)
 {
     this.CloudObject = cloudObject;
     this.StorageFile = storageFile;
 }
 public Task<bool> IsObjectInDownloadQueue(ICloudObject cloudObject)
 {
     throw new System.NotImplementedException();
 }
 public Task<DownloadStatus> GetDownloadStatus(ICloudObject cloudObject)
 {
     throw new System.NotImplementedException();
 }
 public Task<bool> CancelDownload(ICloudObject cloudObject)
 {
     throw new System.NotImplementedException();
 }
Exemple #19
0
 public SkyDriveFile(ICloudObject parent, IDictionary <string, object> objectDictionary)
     : base(parent, objectDictionary)
 {
     this.DownloadSourceLocation = Dictionary.source;
 }
Exemple #20
0
 private string GetObjectPath(ICloudObject obj)
 {
     return(Path + @"\" + obj.CollectionKey.TrimEnd('/') + ".json");
 }
Exemple #21
0
 public SkyDriveAlbum(ICloudObject parent, IDictionary <string, object> objectDictionary, IEnumerable <object> children)
     : base(parent, objectDictionary, children)
 {
 }
 public Task <DownloadStatus> GetDownloadStatus(ICloudObject cloudObject)
 {
     throw new System.NotImplementedException();
 }
Exemple #23
0
 public SkyDriveAlbum(ICloudObject parent, IDictionary<string, object> objectDictionary, IEnumerable<object> children)
     : base(parent, objectDictionary, children)
 {
 }
        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);
        }
Exemple #25
0
 public CloudObjectHelper(ICloudObject helpee)
 {
     _helpee = helpee;
 }
 public BackgroundDownloadPackage(ICloudObject cloudObject, IStorageFile storageFile)
 {
     this.CloudObject = cloudObject;
     this.StorageFile = storageFile;
 }