Пример #1
0
        public MainWindow(User user)
        {
            this.user = user;
            InitializeComponent();
            this.Height              = (SystemParameters.PrimaryScreenHeight);
            this.Width               = (SystemParameters.PrimaryScreenWidth);
            this.menu1.Width         = (SystemParameters.PrimaryScreenWidth);
            this.fileTreeMenu.Height = (SystemParameters.PrimaryScreenHeight) - 116; //82
            this.pathBox.Width       = (SystemParameters.PrimaryScreenWidth) - 198;
            this.scrollText.Width    = (SystemParameters.PrimaryScreenWidth) - 198;
            this.folderView.Width    = (SystemParameters.PrimaryScreenWidth) - 193;
            this.folderView.Height   = (SystemParameters.PrimaryScreenHeight) - 200;

//          Test Code to show that generatePath works
            CommonDescriptor cd1 = new CommonDescriptor("gpname", "filetype", "filePath", "fileID", "accountType", new DateTime(1), 1);
            CommonDescriptor cd2 = new CommonDescriptor("pname", "filetype", "filePath", "fileID", "accountType", new DateTime(1), 1);
            CommonDescriptor cd3 = new CommonDescriptor("name", "filetype", "filePath", "fileID", "accountType", new DateTime(1), 1);

            Models.SupportClasses.TreeNode grandparentNode = new Models.SupportClasses.TreeNode(null, cd1);
            Models.SupportClasses.TreeNode parentNode      = new Models.SupportClasses.TreeNode(grandparentNode, cd2);
            Models.SupportClasses.TreeNode node            = new Models.SupportClasses.TreeNode(parentNode, cd3);
            generatePath(node, " ");
//          End generatePath testcode

            windowsDownloadManager = new WindowsDownloadManager();
            windowsUploadManager   = new WindowsUploadManager();
            metaDataController     = new MetaDataController(metaDataStorageLocation);

            //mimicLogin();
            setButtonsClickable(false);
        }
Пример #2
0
        public async Task<bool> downloadFileAsync(CommonDescriptor cd)
        {
            OneDriveCommunicationParser odcp = new OneDriveCommunicationParser();
            WindowsDownloadManager wdm = new WindowsDownloadManager();
            var _oneDriveClient = InitializeAPI.oneDriveClient;
            //_oneDriveClient.AuthenticateAsync();

            var fileId = cd.FileID;
            
            string extension = odcp.getExtension(cd.FileType); 
            try
            {
                var contentStream = await _oneDriveClient.Drive.Items[fileId].Content.Request().GetAsync();
                wdm.downloadFile((MemoryStream)contentStream, cd.FileName + extension);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return false;
            }

            return true;


        }
 public void WindowsDownloadManagerTest()
 {
     try
     {
         WindowsDownloadManager win = new WindowsDownloadManager();
     }
     catch (Exception)
     {
         Assert.Fail();
     }
 }
Пример #4
0
        public async Task <bool> downloadFileAsync(CommonDescriptor cd)
        {
            var _googleDriveService = InitializeAPI.googleDriveService;

            //TODO: THE MIMETYPE THIS IS CAN'T BE THE SAME MIMETYPE AS WHAT IT WAS SAVED. It needs to be an export type.
            //https://developers.google.com/drive/v3/web/manage-downloads#downloading_google_documents
            string extension, mimeType = "";
            //figure out the mimetype by using the extension in the file name.

            GoogleDriveCommunicationParser gdcp = new GoogleDriveCommunicationParser();

            if (cd.FileName.IndexOf('.') != -1)
            {
                //has an extension.
                extension = cd.FileName.Substring(cd.FileName.IndexOf('.')); //gets the extension.
            }
            else
            {
                //get a 'default' extension based on the format, convert to a real extension
                extension = cd.FileType;
                extension = gdcp.convertExtension(extension);
                if (extension == null)
                {
                    //still can't find a good extension
                    //not able to be downloaded, cancel download
                    //TODO: ban the user from pressing download on these kinds of files?
                    return(false);
                }
            }
            mimeType = gdcp.getMimeType(extension);

            if (mimeType == null)
            {
                //user cancelled giving us a new extension, cancel the download
                return(false);
            }

            var request = _googleDriveService.Files.Get(cd.FileID);
            var stream  = new MemoryStream();
            WindowsDownloadManager wdm = new WindowsDownloadManager();



            request.MediaDownloader.ProgressChanged +=
                (IDownloadProgress progress) =>
            {
                switch (progress.Status)
                {
                case DownloadStatus.Downloading:
                {
                    Console.WriteLine(progress.BytesDownloaded);
                    break;
                }

                case DownloadStatus.Completed:
                {
                    Console.WriteLine("Download complete.");
                    break;
                }

                case DownloadStatus.Failed:
                {
                    Console.WriteLine("Download failed.");
                    break;
                }
                }
            };

            try
            {
                IDownloadProgress x = await request.DownloadAsync(stream);

                wdm.downloadFile(stream, cd.FileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }

            return(true);
        }