Exemple #1
0
        public void addMetaDataFolderTest()
        {
            string             root       = "L://TestingFolder";
            MetaDataController mc         = new MetaDataController(root);
            string             testString = mc.addMetaDataFolder("", "", "a*");

            Assert.AreEqual("a_", testString);
        }
Exemple #2
0
        private async Task fetchAllMDFiles(MetaDataController controller, string relativeRequestPath, string parentID)
        {
            var _oneDriveClient = InitializeAPI.oneDriveClient;

            //will hold all of the children from this directory (parentID)
            List<Item> allChildren = new List<Item>();

            //will hold the current children gathered from an iteration, oneDrive returns 200 children by default
            IChildrenCollectionPage curChildren;
            curChildren = await _oneDriveClient.Drive.Items[parentID].Children.Request().GetAsync();


            allChildren.AddRange(curChildren);
            //NextPageRequest is not null iff there are more children to fetch
            while (curChildren.NextPageRequest != null)
            {
                //Get the nextPageRequest, will be null if there isn't anymore.
                string nextPageLinkString = curChildren.NextPageRequest.GetHttpRequestMessage().RequestUri.ToString();
                curChildren.InitializeNextPageRequest(_oneDriveClient, nextPageLinkString);
                curChildren = await curChildren.NextPageRequest.GetAsync();
                allChildren.AddRange(curChildren);
            }

            //Have all of the children, now iterate through them
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            CommonDescriptor curCD;
            string curFileSerialized, cleansedName;

            foreach (var child in allChildren)
            {
                
                curFileSerialized = serializer.Serialize(child);
                if(child.File == null) //folder
                {
                    //For each folder add the metaDataFolder, the CD, and then recurse.
                    cleansedName = controller.addMetaDataFolder(curFileSerialized, relativeRequestPath, child.Name);
                    curCD = oneDriveCommParser.createCommonDescriptor(relativeRequestPath, curFileSerialized);
                    controller.addCommonDescriptorFile(curCD);
                    await fetchAllMDFiles(controller, relativeRequestPath + "\\" + cleansedName, child.Id);
                }
                else  //file
                {
                    //For each file add the metadatafile, and the CD.
                    cleansedName = controller.addMetaDataFile(curFileSerialized, relativeRequestPath, child.Name);
                    curCD = oneDriveCommParser.createCommonDescriptor(relativeRequestPath, curFileSerialized);
                    controller.addCommonDescriptorFile(curCD);

                    var s = child.File.MimeType;

                    //var a = child.File.MimeType;

                }

            }

        }
Exemple #3
0
        //TODO: have controller be global, or static
        private void fetchAllMDFiles(MetaDataController controller, string relativeRequestPath, string parentID)
        {
            string googleFolderName = "application/vnd.google-apps.folder";
            int    numItemsPerFetch = 1000;

            //over arching list of files in this directory
            IList <Google.Apis.Drive.v3.Data.File> allFiles = new List <Google.Apis.Drive.v3.Data.File>();

            //Each iteration fill the files list.
            IList <Google.Apis.Drive.v3.Data.File> iterationFiles;

            //Execution for each iteration
            FileList exec;

            var googleDriveService = InitializeAPI.googleDriveService;

            FilesResource.ListRequest listRequest = googleDriveService.Files.List();

            string nextPageToken = null;

            Boolean moreFilesExist = true;

            //get all files in this directory
            while (moreFilesExist)
            {
                listRequest          = googleDriveService.Files.List();
                listRequest.Fields   = "nextPageToken, files";
                listRequest.PageSize = numItemsPerFetch; //get 20 things each pass
                listRequest.Q        = "'" + parentID + "' in parents";
                //get the next 10 possible folders
                if (nextPageToken != null)
                {
                    listRequest.PageToken = nextPageToken;
                }
                exec           = listRequest.Execute();
                nextPageToken  = exec.NextPageToken;
                iterationFiles = exec.Files;


                foreach (var cur in iterationFiles)
                {
                    if (cur.Trashed != true)
                    {
                        //not trash
                        allFiles.Add(cur);
                    }
                }
                if (iterationFiles.Count != numItemsPerFetch)
                {
                    //we did not have max items, no more items to fetch
                    moreFilesExist = false;
                }
            }


            //now we have all files/folders in the current directory

            Google.Apis.Drive.v3.Data.File curFile;

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string           curFileSerialized;
            string           cleansedName;
            CommonDescriptor curCD;

            while (allFiles.Count != 0)               //while there are elements
            {
                curFile           = allFiles.First(); //get first file
                curFileSerialized = serializer.Serialize(curFile);
                //pathForFile = controller.getAbsoluteFilePathForAddingMDFile(relativeRequestPath);


                if (curFile.MimeType.Equals(googleFolderName)) //folder
                {
                    //For each folder add the metaDataFolder, the CD, and then recurse.
                    cleansedName = controller.addMetaDataFolder(curFileSerialized, relativeRequestPath, curFile.Name);
                    curCD        = googleCommParser.createCommonDescriptor(relativeRequestPath, curFileSerialized);
                    controller.addCommonDescriptorFile(curCD);
                    fetchAllMDFiles(controller, relativeRequestPath + "\\" + cleansedName, curFile.Id);
                }
                else  //file
                {
                    //For each file add the metadatafile, and the CD.

                    //cleansedName is the 'clean' name of the curFile.Name, don't need to use it cause this terminates.
                    cleansedName = controller.addMetaDataFile(curFileSerialized, relativeRequestPath, curFile.Name);
                    curCD        = googleCommParser.createCommonDescriptor(relativeRequestPath, curFileSerialized);
                    controller.addCommonDescriptorFile(curCD);
                }
                allFiles.RemoveAt(0); //remove this element
            }
        }