//Required by interface
        public CommonDescriptor createCommonDescriptor(string relativeFilePath, string jsonMetaDataFile)
        {
            JsonFileParser parser = new JsonFileParser();

            cd_google_Value_Dictionary = parser.retrieveValues(cd_google_Term_Dictionary, jsonMetaDataFile);

            //variables to pass in
            string   fileName, fileType, fsize, lastMod, fileID;
            DateTime lastModified;
            int      fileSize;

            //google specific logic for creation
            cd_google_Value_Dictionary.TryGetValue("fileName", out fileName);
            cd_google_Value_Dictionary.TryGetValue("fileType", out fileType);
            if (fileType.Equals("application/vnd.google-apps.folder")) //googles folders are called this.
            {
                //do translaion for fileType
                fileType = "folder";
            }
            cd_google_Value_Dictionary.TryGetValue("fileID", out fileID);
            cd_google_Value_Dictionary.TryGetValue("fileSize", out fsize);
            cd_google_Value_Dictionary.TryGetValue("lastModified", out lastMod);
            lastModified = Convert.ToDateTime(lastMod);
            Int32.TryParse(fsize, out fileSize);

            CommonDescriptor cd = new CommonDescriptor(fileName, fileType, relativeFilePath, fileID, "Google Drive", lastModified, fileSize);

            return(cd);
        }
Пример #2
0
        /*
         * Deserialize the common descriptor file and return the object.
         */
        private CommonDescriptor getCommonDescriptorFile(string relativeFilePath)
        {
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            string           filePath           = rootStoragePath + COMMONDESCRIPTORPATH + relativeFilePath;
            string           jsonCD             = File.ReadAllText(filePath);
            CommonDescriptor cd = jsonSerializer.Deserialize <CommonDescriptor>(jsonCD);

            return(cd);
        }
Пример #3
0
        public TreeNode getRoot(string accountName, string rootID, string accountType)
        {
            //root has no parent, and a bastardized CD.
            CommonDescriptor rootDescriptor = new CommonDescriptor(accountName, "folder", accountName, rootID, accountType, new DateTime(), 0);
            TreeNode         root           = new TreeNode(null, rootDescriptor);
            string           rootPath       = rootStoragePath + COMMONDESCRIPTORPATH + accountName;

            return(createTree(root, rootPath));
        }
Пример #4
0
 public Boolean deleteCloudObjet(CommonDescriptor cd)
 {
     if (cd.FileType.Equals("folder"))
     {
         return(removeDirectory(cd.FilePath));
     }
     else
     {
         return(removeFile(cd.FilePath, cd.FileName));
     }
 }
Пример #5
0
        /*
         * Takes in a CommonDescriptor object, transforms it to a JSON file, and then saves it to the disk
         */
        public void addCommonDescriptorFile(CommonDescriptor cd)
        {
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            string filePath       = getAbsoluteFilePathForAddingCDFile(cd.FilePath); //this filePath should be cleansed from CD creation.
            var    serializedJson = jsonSerializer.Serialize(cd);

            if (cd.FileType.Equals("folder"))
            {
                File.WriteAllText(filePath + "\\" + replaceProhibitedCharacters(cd.FileName) + "_folder.json", serializedJson);
            }
            else
            {
                File.WriteAllText(filePath + "\\" + replaceProhibitedCharacters(cd.FileName) + "_file.json", serializedJson);
            }
        }
        //Required by interface
        public CommonDescriptor createCommonDescriptor(string relativeFilePath, string jsonMetaData)
        {
            JsonFileParser parser = new JsonFileParser();

            cd_od_value_dictionary = parser.retrieveValues(cd_od_Term_Dictionary, jsonMetaData);

            //variables to pass
            string   fileName, fileType, fsize, lastMod, fileID;
            DateTime lastModified;
            int      fileSize;

            //OneDrive specific logic
            cd_od_value_dictionary.TryGetValue("fileName", out fileName);
            cd_od_value_dictionary.TryGetValue("fileType", out fileType);
            if (fileType == "")
            {
                //null represents 'not a file' aka a folder
                fileType = "folder";
            }
            else
            {
                JObject metaData  = JObject.Parse(jsonMetaData);
                JObject curToken  = (JObject)metaData.GetValue("File");
                JToken  nextToken = curToken.GetValue("MimeType");
                fileType = (string)Convert.ChangeType(nextToken.ToString(), typeof(string));
            }

            cd_od_value_dictionary.TryGetValue("fileID", out fileID);
            cd_od_value_dictionary.TryGetValue("fileSize", out fsize);
            cd_od_value_dictionary.TryGetValue("lastModified", out lastMod);
            lastModified = Convert.ToDateTime(lastMod);
            Int32.TryParse(fsize, out fileSize);

            CommonDescriptor cd = new CommonDescriptor(fileName, fileType, relativeFilePath, fileID, "One Drive", lastModified, fileSize);

            return(cd);
        }