Exemple #1
0
        //Create a Drive
        public async Task <OHDrive> Create(string name, long size, OHDriveOptions driveOptions = null)
        {
            string json      = "";
            var    driveDict = new Dictionary <string, string>();

            //name and size are required
            if (string.IsNullOrEmpty(name) || size == 0)
            {
                throw new Exception("Name and Size are required for drive creation");
            }

            driveDict["name"] = name;
            driveDict["size"] = size.ToString();
            if (driveOptions != null)
            {
                driveDict = SetDriveOptions(driveDict, driveOptions, false);
            }

            json = JsonConvert.SerializeObject(driveDict);
            var content = new StringContent(json, UnicodeEncoding.UTF8, "application/json");

            using (HttpClient client = OHUtilities.CreateClient(userID, secretKey))
            {
                var url      = urlBase + "create";
                var response = await client.PostAsync(url, content);

                json = await response.Content.ReadAsStringAsync();
            }

            return(DeserializeDrive(json));
        }
        //Create a Drive 
        public async Task<OHDrive> Create(string name, long size, OHDriveOptions driveOptions = null)
        {
            string json = "";
            var driveDict = new Dictionary<string, string>();

            //name and size are required
            if (string.IsNullOrEmpty(name) || size == 0)
                throw new Exception("Name and Size are required for drive creation");

            driveDict["name"] = name;
            driveDict["size"] = size.ToString();
            if (driveOptions != null)
            {
                driveDict = SetDriveOptions(driveDict, driveOptions, false);
            }

            json = JsonConvert.SerializeObject(driveDict);
            var content = new StringContent(json, UnicodeEncoding.UTF8, "application/json");

            using (HttpClient client = OHUtilities.CreateClient(userID, secretKey))
            {
                var url = urlBase + "create";
                var response = await client.PostAsync(url, content);
                json = await response.Content.ReadAsStringAsync();
            }

            return DeserializeDrive(json);
        }
        public static OHDrive SetDrive()
        {
            var driveService = new OHDriveService();
            var driveOptions = new OHDriveOptions();
            driveOptions.ClaimType = "exclusive";
            driveOptions.Encryption = "none";
            driveOptions.Tags = new[] { "newtest", "c-sharp-api-v2" };
            var drives = driveService.GetAll().Result;
            var drive = drives.FirstOrDefault(x => x.Name == "oh-api-test");

            return driveService.Set(drive.DriveID, drive.Name, 1073741824, driveOptions).Result;
        }
Exemple #4
0
 // Private routines
 private Dictionary <string, string> SetDriveOptions(Dictionary <string, string> driveDict, OHDriveOptions driveOptions, bool isSetRequest)
 {
     if (!string.IsNullOrEmpty(driveOptions.ClaimType))
     {
         driveDict["claim:type"] = driveOptions.ClaimType;
     }
     if (driveOptions.Readers != null && driveOptions.Readers.Any())
     {
         driveDict["readers"] = string.Join(" ", driveOptions.Readers);
     }
     if (driveOptions.Tags != null && driveOptions.Tags.Any())
     {
         driveDict["tags"] = string.Join(" ", driveOptions.Tags);
     }
     if (!isSetRequest)
     {
         if (driveOptions.Avoids != null && driveOptions.Avoids.Any())
         {
             driveDict["avoid"] = string.Join(" ", driveOptions.Avoids);
         }
         if (!string.IsNullOrEmpty(driveOptions.Encryption))
         {
             driveDict["encryption:cipher"] = driveOptions.Encryption;
         }
     }
     return(driveDict);
 }
 // Private routines 
 private Dictionary<string, string> SetDriveOptions(Dictionary<string, string> driveDict, OHDriveOptions driveOptions, bool isSetRequest)
 {
     if (!string.IsNullOrEmpty(driveOptions.ClaimType))
         driveDict["claim:type"] = driveOptions.ClaimType;
     if (driveOptions.Readers != null && driveOptions.Readers.Any())
         driveDict["readers"] = string.Join(" ", driveOptions.Readers);
     if (driveOptions.Tags != null && driveOptions.Tags.Any())
         driveDict["tags"] = string.Join(" ", driveOptions.Tags);
     if (!isSetRequest)
     {
         if (driveOptions.Avoids != null && driveOptions.Avoids.Any())
             driveDict["avoid"] = string.Join(" ", driveOptions.Avoids);
         if (!string.IsNullOrEmpty(driveOptions.Encryption))
             driveDict["encryption:cipher"] = driveOptions.Encryption;
     }
     return driveDict;
 }