Esempio n. 1
0
        private void PostProcessDownload(OneDriveFile file, string filepath, bool wasSuccess)
        {
            // Removes the file from the queue of files to download.
            int filesLeft;

            lock (_syncRoot)
            {
                // Removes the file if it is registered.
                _dlFiles.RemoveAll(f => f.Id == file.Id);

                // Gets how many files are pending completion.
                filesLeft = _dlFiles.Count;
            }

            if (wasSuccess)
            {
                // Raise information about this progress.
                RaiseSyncProgress(addedFiles: new string[] { filepath });
            }

            // If no more files are pending download, the sync is over!
            if (filesLeft == 0)
            {
                EndSyncDownloads();
            }
        }
        /// <summary>
        /// Downloads the file locally
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task DownloadFileAsync(OneDriveFile file)
        {
            // Prepare the picker suggisting the same OneDrive file name
            var picker = new FileSavePicker
            {
                SuggestedFileName      = file.Name,
                SuggestedStartLocation = PickerLocationId.Downloads,
                DefaultFileExtension   = Path.GetExtension(file.Name),
            };

            picker.FileTypeChoices.Add(file.Name, new List <string> {
                picker.DefaultFileExtension
            });
            // Ask where save the file
            StorageFile storageFile = await picker.PickSaveFileAsync();

            // storageFile is null if the user cancel the pick operation
            if (storageFile != null)
            {
                // Add a new item at the beginning of the list
                var item = new OneDriveFileProgress(file);
                _progressItems.Insert(0, item);
                // Start the download operation
                await item.DownloadFileAsync(storageFile, file.DownloadUri);
            }
        }
Esempio n. 3
0
        public CloudFiles AddFiles(Dictionary <string, object> items)
        {
            UniValue file = UniValue.Create((Dictionary <string, object>)items);
            var      map  = new ApiDataMapping();

            map.Add("id", "FileID");
            map.Add("name", "FileName");
            map.Add("@content.downloadUrl", "DownUrl");
            map.Add("size", "FileSize", typeof(long));
            map.Add("lastModifiedDateTime", "modifiedDate");
            FileInfo fi = new FileInfo(file, map);

            fi.driveinfo = driveinfo;
            if (fi.Items.CollectionItems.ContainsKey("folder"))
            {
                fi.IsFile = false;
            }
            else
            {
                fi.IsFile    = true;
                fi.Extention = GetExtension(fi.FileName);
            }
            fi.Thumnail = GetTumbNail(fi.FileID);
            OneDriveFile itemss = new OneDriveFile(fi);

            files.Add(itemss);
            return(itemss);
        }
Esempio n. 4
0
        public override async Task AddFiles(string id)
        {
            ODItemReference item = new ODItemReference {
                Id = id
            };

            files = new List <OneDriveFile>();
            ODItem selectedItem;

            selectedItem = await connect.GetItemAsync(item, ItemRetrievalOptions.DefaultWithChildrenThumbnails);

            if (null != selectedItem)
            {
                var pagedItemCollection = await selectedItem.PagedChildrenCollectionAsync(connect, ChildrenRetrievalOptions.DefaultWithThumbnails);

                while (pagedItemCollection.MoreItemsAvailable())
                {
                    pagedItemCollection = await pagedItemCollection.GetNextPage(connect);
                }

                foreach (var items in pagedItemCollection.Collection)
                {
                    OneDriveFile oditem = new OneDriveFile(connect);
                    oditem.Oditem = items;
                    files.Add(oditem);
                }
            }
        }
Esempio n. 5
0
        protected static Brush GetIconBrushForFileType(OneDriveFile item)
        {
            var extention = item.FileExtention.ToLower();

            if (FileIconBrushesDictionary.ContainsKey(extention))
            {
                return(FileIconBrushesDictionary[extention]);
            }
            return(_fileBrush);
        }
Esempio n. 6
0
        // fullPath is any number of directories then filename
        // eg. dir1/dir2/dir3/myfile.txt
        public OneDriveFile GetOneDriveEntryByFileNameAndDirectory(string fullPath)
        {
            if (string.IsNullOrEmpty(fullPath))
            {
                return(null);
            }

            List <OneDriveDirectory> skydriveListing;
            OneDriveDirectory        selectedEntry = null;
            OneDriveFile             selectedFile  = null;

            // root listing.
            skydriveListing = ListOneDriveDirectoryWithUrl("");
            var fileFound = false;
            var sp        = fullPath.Split('/');
            var searchDir = "";

            foreach (var entry in sp)
            {
                var foundEntry = (from e in skydriveListing where e.Name == entry select e).FirstOrDefault();
                if (foundEntry != null && foundEntry.Type == "folder")
                {
                    searchDir       = foundEntry.Id + "/";
                    skydriveListing = ListOneDriveDirectoryWithUrl(searchDir);
                }

                // cant have == "file", since "photos" etc come up as different types.
                if (foundEntry != null && foundEntry.Type != "folder")
                {
                    fileFound = true;
                    var l = ListOneDriveFileWithUrl(foundEntry.Id);
                    if (l != null)
                    {
                        selectedFile = l;
                    }
                }

                selectedEntry = foundEntry;
            }

            if (!fileFound)
            {
                selectedFile = null;
            }

            return(selectedFile);
        }
Esempio n. 7
0
        private void BeginDownloadFile(OneDriveFile file)
        {
            // Sync Step 3: We're scheduling some files to be downloaded.

            // Adds the file id to the list of currently downloading files.
            lock (_syncRoot)
            {
                _dlFiles.Add(file);
            }

            // Starts downloading the cartridge to the isostore.
            bool shouldDirectDownload = !IsBackgroundDownloadAllowed;

            Log(file.ToString() + ", directDownload = " + shouldDirectDownload);
            string fileAttribute = file.Id + "/content";

            if (shouldDirectDownload)
            {
                // Direct download.
                Log("Starts DownloadAsync");
                StartTaskAndContinueWith(
                    () => _liveClient.DownloadAsync(fileAttribute),
                    t => OnLiveClientDownloadCompleted(t, file));
            }
            else
            {
                try
                {
                    // Tries to perform a background download.
                    Log("Starts BackgroundDownloadAsync");
                    StartTaskAndContinueWith(
                        () => _liveClient.BackgroundDownloadAsync(
                            fileAttribute,
                            new Uri(GetTempIsoStorePath(file.Name), UriKind.RelativeOrAbsolute)
                            ),
                        t => OnLiveClientBackgroundDownloadCompleted(t, file));
                }
                catch (Exception)
                {
                    // Tries the direct download method.
                    Log("Starts DownloadAsync (fallback)");
                    StartTaskAndContinueWith(
                        () => _liveClient.DownloadAsync(fileAttribute),
                        t => OnLiveClientDownloadCompleted(t, file));
                }
            }
        }
Esempio n. 8
0
 public async Task AddFiles(string id)
 {
     try
     {
         var parameter = new HttpParameterCollection()
         {
             { "access_token", driveinfo.token.access_token }
         };
         var result = OAuthUtility.Get(string.Format("https://api.onedrive.com/v1.0/drive/items/{0}/children", id), parameter);
         var map    = new ApiDataMapping();
         map.Add("id", "FileID");
         map.Add("name", "FileName");
         map.Add("@content.downloadUrl", "DownUrl");
         map.Add("size", "FileSize", typeof(long));
         map.Add("lastModifiedDateTime", "modifiedDate");
         foreach (var item in result.Result.CollectionItems.Items["value"].CollectionItems.Items.Values)
         {
             FileInfo fi = new FileInfo(item, map);
             fi.driveinfo = driveinfo;
             if (id == "root")
             {
                 fi.Path = "OneDrive/";
             }
             if (fi.Items.CollectionItems.ContainsKey("folder"))
             {
                 fi.IsFile = false;
                 fi.Path  += fi.FileName + "/";
             }
             else
             {
                 fi.IsFile    = true;
                 fi.Extention = GetExtension(fi.FileName);
                 fi.DownUrl   = item.CollectionItems["@content.downloadUrl"].ToString();
             }
             fi.Thumnail = GetTumbNail(fi.FileID);
             OneDriveFile items = new OneDriveFile(fi);
             files.Add(items);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(string.Format("원드라이브 파일 불러오기 오류 : {0}", e));
     }
 }
Esempio n. 9
0
        async internal void importSubscriptionsFromOneDrive()
        {
            if (MessageBox.Show("Podcatcher will try to find and import the latest podcasts that were exported from Podcatcher. Please login to OneDrive to continue.",
                                "Import from OneDrive",
                                MessageBoxButton.OKCancel) != MessageBoxResult.OK)
            {
                return;
            }

            OneDriveFile latestExport = (await OneDriveManager.getInstance().getFileListing("me/SkyDrive/files"))
                                        .OrderByDescending(file => file.Created)
                                        .Where(file => file.Name.Contains("PodcatcherSubscriptions"))
                                        .FirstOrDefault();

            if (latestExport == null)
            {
                MessageBox.Show("Could not find any exported podcasts from Podcatcher on OneDrive. Make sure to have the exported OPML file in your root OneDrive folder.");
                return;
            }

            Debug.WriteLine("Going to get file {0} (Id: {1}) from {2}: ", latestExport.Name, latestExport.Id, latestExport.Url);
            PodcastSubscriptionsManager.getInstance().addSubscriptionFromOPMLFile(latestExport.Url);
        }
Esempio n. 10
0
        private async void NavigateToItem(CloudFiles item)
        {
            flowLayoutPanel_filecontent.Controls.Clear();
            if ((item as GoogleFile) != null)
            {
                GoogleFile file      = (GoogleFile)item;
                AllFolder  newfolder = new GoogleFolder(file.Service);
                await newfolder.AddFiles(file.GetId());

                LoadTile(newfolder);
            }
            else if ((item as OneDriveFile) != null)
            {
                OneDriveFile file      = (OneDriveFile)item;
                AllFolder    newfolder = new OneDriveFolder(file.Connect);
                await newfolder.AddFiles(file.GetId());

                LoadTile(newfolder);
            }
            else
            {
                MessageBox.Show("파일 열기 실패");
            }
        }
Esempio n. 11
0
        private void OnLiveClientDownloadCompleted(System.Threading.Tasks.Task <LiveDownloadOperationResult> task, OneDriveFile file)
        {
            // Sync Step 4. The file has been downloaded as a memory stream.
            // Write it to its direct location.
            // (This runs on the emulator and on devices where the background download method failed.)

            if (!CheckTaskCompleted(task, "Download failed (" + file.Name + ")"))
            {
                PostProcessDownload(file, null, false);
                return;
            }

            LiveDownloadOperationResult result = task.Result;

            string filepath = GetIsoStorePath(file.Name, file.DownloadDirectory);
            bool   success  = false;

            try
            {
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    // Makes sure the directory exists.
                    isf.CreateDirectory(file.DownloadDirectory);

                    // Creates a file at the right place.
                    using (IsolatedStorageFileStream fs = isf.OpenFile(filepath, FileMode.Create))
                    {
                        result.Stream.CopyTo(fs);
                    }
                }

                Log("Created " + filepath);

                success = true;
            }
            catch (Exception e)
            {
                Log("Error while writing " + filepath + ": " + e.Message);
                Geowigo.Utils.DebugUtils.DumpException(e, file.ToString(), true);

                success = false;
            }

            PostProcessDownload(file, filepath, success);
        }
Esempio n. 12
0
        private void OnLiveClientBackgroundDownloadCompleted(System.Threading.Tasks.Task <LiveOperationResult> task, OneDriveFile file)
        {
            // Sync Step 4. The file has already been downloaded to isostore.
            // Just move it to its right location.
            // (This only runs on the device.)

            if (!CheckTaskCompleted(task, "Background download failed (" + file.Name + ")"))
            {
                PostProcessDownload(file, null, false);
                return;
            }

            LiveOperationResult result = task.Result;

            string filepath = GetIsoStorePath(file.Name, file.DownloadDirectory);
            bool   success;

            try
            {
                // Moves the file.
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    // Makes sure the directory exists.
                    isf.CreateDirectory(file.DownloadDirectory);

                    // Removes the destination file if it exists.
                    if (isf.FileExists(filepath))
                    {
                        isf.DeleteFile(filepath);
                    }

                    // Moves the downloaded file to the right place.
                    isf.MoveFile(GetTempIsoStorePath(file.Name), filepath);
                    Log("Moved file to " + filepath);

                    success = true;
                }
            }
            catch (Exception e)
            {
                Log("Error while moving " + filepath + ": " + e.Message);
                Geowigo.Utils.DebugUtils.DumpException(e, file.ToString(), true);

                success = false;
            }

            PostProcessDownload(file, filepath, success);
        }
Esempio n. 13
0
 public string GetPath(string path, OneDriveFile file)
 {
     return(path + "/" + file.name);
 }
 private void list_DownloadFile(object sender, OneDriveFile file)
 {
     _ = progress.DownloadFileAsync(file);
 }