Пример #1
0
 public async Task<bool> PreviewFileObjectAsync(FileObject fo)
 {
     StorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(SpotObject.PREVIEW_FILE_LOCATION, CreationCollisionOption.OpenIfExists);
     StorageFile file = await folder.CreateFileAsync(fo.Name, CreationCollisionOption.ReplaceExisting);
     file = await App.BlobStorageManager.DownloadFileAsync(fo.Id, file);
     return await Launcher.LaunchFileAsync(file);
 }
Пример #2
0
 private async Task<List<FileObject>> _GetChildAsync(FileObject fileObject)
 {
     if (FileObjectViewModel.FOLDER.Equals(fileObject.Type.ToString()))
     {
         List<FileObject> list = await this.GetFilesFromFolderAsync(fileObject.Id);
         foreach (FileObject file in list)
         {
             file.FileList = await _GetChildAsync(file);
         }
         return list;
     }
     else
     {
         return null;
     }
 }
Пример #3
0
        public async Task<bool> DeleteFileObjectAsync(FileObject fo)
        {
            //////////////////////////////////////////////
            // TODO : Need to substract Storage Capacity
            //////////////////////////////////////////////

            return await App.BlobStorageManager.DeleteFileAsync(fo.Id);

            /////////////////////////////////////////////////////////////////////////////////////////////////
            /// In the future, Maybe there will be codes for the mobile service table insertion. BUT Not NOW
            /// /////////////////////////////////////////////////////////////////////////////////////////////
        }
Пример #4
0
 public async Task<bool> DownloadFileObjectAsync(IStorageManager StorageManager, FileObject fo)
 {
     Stream instream = await App.BlobStorageManager.DownloadFileStreamAsync(fo.Id);
     FileObject root = await StorageManager.GetRootFolderAsync();
     return await StorageManager.UploadFileStreamAsync(root.Id, fo.Name, instream);
 }
Пример #5
0
 public static List<FileObject> GetTreeForFolder(FileObject folder)
 {
     if (folder == null) return null;
     if (folder.FileList == null) return null;
     if (!GetCurrentTree().Contains(folder)) GetCurrentTree().Push(folder);
     return folder.FileList;
 }
Пример #6
0
        public async Task<string> AddFileObjectAsync(FileObject fo)
        {
            /////////////////////////////////////////
            // TODO : Need to add Storage Capacity
            /////////////////////////////////////////

            if (fo == null) 
                throw new Exception();
            IStorageManager StorageManager = Switcher.GetCurrentStorage();
            string sourceId = fo.Id;
            if (StorageManager.GetStorageName().Equals(AppResources.GoogleDrive)) 
                sourceId = fo.DownloadUrl;
            return await App.BlobStorageManager.UploadFileStreamAsync
                (this.PtcAccountId, this.Id, fo.Name, await StorageManager.DownloadFileStreamAsync(sourceId));

            /////////////////////////////////////////////////////////////////////////////////////////////////
            /// In the future, Maybe there will be codes for the mobile service table insertion. BUT Not NOW
            /// /////////////////////////////////////////////////////////////////////////////////////////////
        }
Пример #7
0
 public static FileObject ConvertToFileObject(FileObjectSQL fos)
 {
     FileObject fo = new FileObject(fos.Id, fos.Name, fos.Size, fos.Type, fos.Extension, fos.UpdateAt, fos.Thumbnail, fos.DownloadUrl, fos.MimeType);
     fo.SpotId = fos.SpotId;
     if (fos.ProfileName != null && fos.ProfileId != null && fos.ProfileEmail != null && fos.ProfilePhoneNumber != null)
     {
         fo.Owner = new ProfileObject();
         fo.Owner.Id = fos.ProfileId;
         fo.Owner.Email = fos.ProfileEmail;
         fo.Owner.Name = fos.ProfileName;
         fo.Owner.PhoneNumber = fos.ProfilePhoneNumber;
     }
     if (fo.Type.Equals(FileObject.FileObjectType.FOLDER))
         fo.FileList = new List<FileObject>();
     return fo;
 }
        /// <summary>
        /// Converting GoogleDrive Model to FileObject
        /// </summary>
        /// <param name="file">GoogleDrive Model</param>
        /// <returns>POJO FileObject</returns>
        public static FileObject ConvertToFileObject(Google.Apis.Drive.v2.Data.File file)
        {
            String Id = file.Id ?? "No Id";
            
            double Size = (file.FileSize == null ? 0.0 : file.FileSize.Value * 1.0);
            FileObject.FileObjectType Type = (file.MimeType.Contains("application/vnd.google-apps.folder")) ? FileObject.FileObjectType.FOLDER : (file.MimeType.Contains("application/vnd.google-apps") ? FileObject.FileObjectType.GOOGLE_DOC : FileObject.FileObjectType.FILE);
            string Extension = file.FileExtension ?? "No Extension";
            string UpdateAt = file.ModifiedDate.ToString();
            string Thumbnail = file.ThumbnailLink ?? "No Thumbnail";
            string DownloadUrl = String.Empty;

            if (file.ExportLinks != null && file.MimeType != null && file.MimeType.Contains("application/vnd.google-apps"))
                DownloadUrl = file.ExportLinks[GoogleDriveManager.GoogleDocMapper[file.MimeType]];
            else
                DownloadUrl = file.DownloadUrl;

            string MimeType = file.MimeType ?? "No MimeType";
            string Name = "";

            if (!"application/vnd.google-apps.folder".Equals(file.MimeType) && file.MimeType.Contains("application/vnd.google-apps"))
            {
                Name = file.Title + "." + GoogleDriveManager.ExtensionMapper[file.MimeType];
                Extension = GoogleDriveManager.ExtensionMapper[file.MimeType];
            }
            else
            {
                Name = file.Title;
            }

            FileObject ret = new FileObject(Id, Name, Size, Type, Extension, UpdateAt, Thumbnail, DownloadUrl, MimeType);
            if (Type.Equals(FileObject.FileObjectType.FOLDER))
                ret.FileList = new List<FileObject>();
            return ret;
        }
Пример #9
0
 public static void ConvertToFileObjectSQL(List<FileObjectSQL> list, FileObject fo, string parentId, int level)
 {
     if (list == null) System.Diagnostics.Debugger.Break();
     FileObjectSQL fos = new FileObjectSQL();
     fos.Id = fo.Id;
     fos.Name = fo.Name;
     fos.Size = fo.Size;
     fos.Type = fo.Type;
     fos.Extension = fo.Extension;
     fos.UpdateAt = fo.UpdateAt;
     fos.Thumbnail = fo.Thumbnail;
     fos.DownloadUrl = fo.DownloadUrl;
     fos.MimeType = fo.MimeType;
     fos.ParentId = parentId;
     fos.Level = level;
     if (fo.Owner != null)
     {
         fos.ProfileId = fo.Owner.Id;
         fos.ProfileEmail = fo.Owner.Email;
         fos.ProfilePhoneNumber = fo.Owner.PhoneNumber;
         fos.ProfileName = fo.Owner.Name;
     }
     fos.SpotId = fo.SpotId;
     list.Add(fos);
     if (fo.FileList != null)
     {
         level++;
         for (var i = 0; i < fo.FileList.Count; i++)
         {
             ConvertToFileObjectSQL(list, fo.FileList[i], fo.Id, level);
         }
     }
 }
Пример #10
0
        public static FileObject ConvertToFileObject(FileObjectDataContext db, FileObjectSQL fos)
        {
            FileObject fo = new FileObject(fos.Id, fos.Name, fos.Size, fos.Type, fos.Extension, fos.UpdateAt, fos.Thumbnail, fos.DownloadUrl, fos.MimeType);
            fo.SpotId = fos.SpotId;
            if (fos.ProfileName != null && fos.ProfileId != null && fos.ProfileEmail != null && fos.ProfilePhoneNumber != null)
            {
                fo.Owner = new ProfileObject();
                fo.Owner.Id = fos.ProfileId;
                fo.Owner.Email = fos.ProfileEmail;
                fo.Owner.Name = fos.ProfileName;
                fo.Owner.PhoneNumber = fos.ProfilePhoneNumber;
            }

            fo.FileList = GetChildList(db, fos.Id);
            return fo;
        }
Пример #11
0
        public static void PrintFile(FileObject file)
        {
            Debug.WriteLine("id : " + file.Id);
            Debug.WriteLine("Name : " + file.Name);
            Debug.WriteLine("Size : " + file.Size);
            Debug.WriteLine("Type : " + file.Type);
            Debug.WriteLine("Extension : " + file.Extension);
            Debug.WriteLine("UpdateAt : " + file.UpdateAt);
            Debug.WriteLine("Thumbnail : " + file.Thumbnail);
            Debug.WriteLine("DownloadUrl : " + file.DownloadUrl);
            Debug.WriteLine("MimeType : " + file.MimeType);

            Debug.WriteLine("----child START-----");
            PrintFileList(file.FileList);
            Debug.WriteLine("----child END-----");
        }
Пример #12
0
 public static MSFileObject ConvertToMSFileObject(FileObject fo)
 {
     return new MSFileObject(fo.Name, fo.Type.ToString(), fo.Size, fo.Extension, fo.UpdateAt, fo.DownloadUrl, fo.MimeType, fo.Owner.Id, fo.Owner.Name, fo.SpotId);
 }
Пример #13
0
 public static FileObject ConvertToFileObject(MSFileObject msfo)
 {
     FileObject fo = new FileObject();
     fo.Id = msfo.id;
     fo.Name = msfo.name;
     fo.Type = (FileObjectType)Enum.Parse(typeof(FileObjectType), msfo.file_type);
     fo.Size = msfo.size;
     fo.Extension = msfo.extension;
     fo.UpdateAt = msfo.update_at;
     fo.DownloadUrl = msfo.download_url;
     fo.MimeType = msfo.mime_type;
     fo.SpotId = msfo.spot_id;
     fo.Owner = new ProfileObject(msfo.owner_account_id, msfo.owner_account_name);
     return fo;
 }
        public async Task<FileObject> Test(FileObject root)
        {
            List<FileObject> list = new List<FileObject>();
            Dictionary<string, FileObject> folderMap = new Dictionary<string, FileObject>();
            List<Google.Apis.Drive.v2.Data.File> unhandled = new List<Google.Apis.Drive.v2.Data.File>();

            // Get childern by q
            FilesResource.ListRequest rr = this.Service.Files.List();
            rr.Q = "'root' in parents and trashed=false and mimeType != 'application/vnd.google-apps.form' and 'me' in owners";
            FileList fileList = await rr.ExecuteAsync();
            root.FileList = new List<FileObject>();
            folderMap.Add(root.Id, root);
            foreach (Google.Apis.Drive.v2.Data.File file in fileList.Items)
            {
                System.Diagnostics.Debug.WriteLine(file.Title);
                if (file.Title.Equals("Taylor")) System.Diagnostics.Debugger.Break();
                if (file.MimeType.Contains("application/vnd.google-apps.folder"))
                {
                    folderMap.Add(file.Id, ConvertToFileObjectHelper.ConvertToFileObject(file));
                }

                if (file.Parents != null && file.Parents.Count == 1)
                {

                    if (folderMap.ContainsKey(file.Parents[0].Id))
                    {
                        folderMap[file.Parents[0].Id].FileList.Add(ConvertToFileObjectHelper.ConvertToFileObject(file));
                        if ((file.Parents[0].IsRoot.Value)) System.Diagnostics.Debug.WriteLine("Root Parent!");
                    }
                    else
                    {
                        // for later work.
                        unhandled.Add(file);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("no parent : " + file.Title);
                    //System.Diagnostics.Debugger.Break();
                }
            }


            // TODO : Handle Unhandled files

            foreach (var file in unhandled)
            {
                if (folderMap.ContainsKey(file.Parents[0].Id))
                {
                    folderMap[file.Parents[0].Id].FileList.Add(ConvertToFileObjectHelper.ConvertToFileObject(file));
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("unhandled : " + file.Title);
                    //System.Diagnostics.Debugger.Break();
                }
            }
            return root;
        }
 // Get a root folder.
 public async Task<FileObject> GetRootFolderAsync()
 {
     FileObject rootFile = new FileObject();
     AboutResource aboutResource = this.Service.About;
     About about = await aboutResource.Get().ExecuteAsync();
     rootFile.Id = about.RootFolderId;
     this.RootFodlerId = about.RootFolderId;
     rootFile.Name = "";
     return rootFile;
 }