public Result DeleteConfigValue(string aSection, string aKeyName, Result aResult) { if (String.IsNullOrEmpty(aSection)) { throw new ArgumentException("aSection cannot be null nor empty"); } if (String.IsNullOrEmpty(aKeyName)) { throw new ArgumentException("aKeyName cannot be null nor empty"); } if (aResult == null) { throw new ArgumentNullException("aResult"); } BasePlug.At(Constants.CONFIG, XUri.EncodeFragment(aSection), XUri.EncodeFragment(aKeyName)).Delete(DreamMessage.Ok(), new Result <DreamMessage>()).WhenDone( a => { if (a.Status == DreamStatus.Ok) { aResult.Return(); // remove " and "\n } else { aResult.Throw(new CouchException(a)); } }, aResult.Throw ); return(aResult); }
/// <summary> /// Deletes the specified database /// </summary> /// <param name="aDatabaseName">Database to delete</param> /// <param name="aResult"></param> /// <returns></returns> public Result <JObject> DeleteDatabase(string aDatabaseName, Result <JObject> aResult) { if (String.IsNullOrEmpty(aDatabaseName)) { throw new ArgumentException("DatabaseName cannot be null nor empty"); } if (aResult == null) { throw new ArgumentNullException("aResult"); } BasePlug.At(XUri.EncodeFragment(aDatabaseName)).Delete(new Result <DreamMessage>()).WhenDone( a => { if (a.Status == DreamStatus.Ok) { aResult.Return(JObject.Parse(a.ToText())); } else { aResult.Throw(new CouchException(a)); } }, aResult.Throw ); return(aResult); }
/// <summary> /// Returns a bool indicating whether or not the database exists. /// </summary> /// <param name="aDatabaseName"></param> /// <param name="aResult"></param> /// <returns></returns> public Result <bool> HasDatabase(string aDatabaseName, Result <bool> aResult) { if (String.IsNullOrEmpty(aDatabaseName)) { throw new ArgumentException("DatabaseName cannot be null nor empty"); } if (aResult == null) { throw new ArgumentNullException("aResult"); } BasePlug.At(XUri.EncodeFragment(aDatabaseName)).Head(new Result <DreamMessage>()).WhenDone( a => aResult.Return(a.Status == DreamStatus.Ok), aResult.Throw ); return(aResult); }
public Result <string> GetConfigValue(string aSection, string aKeyName, Result <string> aResult) { if (String.IsNullOrEmpty(aSection)) { throw new ArgumentException("aSection cannot be null nor empty"); } if (String.IsNullOrEmpty(aKeyName)) { throw new ArgumentException("aKeyName cannot be null nor empty"); } if (aResult == null) { throw new ArgumentNullException("aResult"); } BasePlug.At(Constants.CONFIG, XUri.EncodeFragment(aSection), XUri.EncodeFragment(aKeyName)).Get(DreamMessage.Ok(), new Result <DreamMessage>()).WhenDone( a => { string value = a.ToText(); switch (a.Status) { case DreamStatus.Ok: aResult.Return(value.Substring(1, value.Length - 3)); // remove " and "\n break; case DreamStatus.NotFound: aResult.Return((string)null); break; default: aResult.Throw(new CouchException(a)); break; } }, aResult.Throw ); return(aResult); }
/// <summary> /// Gets a Database /// </summary> /// <param name="aDatabaseName">Name of the database</param> /// <param name="createIfNotExists">Flag specifying if the database must be created if not found</param> /// <param name="aResult"></param> /// <returns></returns> public Result <CouchDatabase> GetDatabase(string aDatabaseName, bool createIfNotExists, Result <CouchDatabase> aResult) { if (String.IsNullOrEmpty(aDatabaseName)) { throw new ArgumentException("DatabaseName cannot be null nor empty"); } if (aResult == null) { throw new ArgumentNullException("aResult"); } HasDatabase(aDatabaseName, new Result <bool>()).WhenDone( exists => { if (exists) { aResult.Return(new CouchDatabase(BasePlug.At(XUri.EncodeFragment(aDatabaseName)))); } else { if (createIfNotExists) { CreateDatabase(aDatabaseName, new Result <JObject>()).WhenDone( a => aResult.Return(new CouchDatabase(BasePlug.At(XUri.EncodeFragment(aDatabaseName)))), aResult.Throw ); } else { aResult.Return((CouchDatabase)null); } } }, aResult.Throw ); return(aResult); }
public Result <Dictionary <string, string> > GetConfigSection(string aSection, Result <Dictionary <string, string> > aResult) { if (aSection == null) { throw new ArgumentNullException("aSection"); } if (aResult == null) { throw new ArgumentNullException("aResult"); } if (String.IsNullOrEmpty(aSection)) { throw new ArgumentException("Section cannot be empty"); } BasePlug.At(Constants.CONFIG, XUri.EncodeFragment(aSection)).Get(DreamMessage.Ok(), new Result <DreamMessage>()).WhenDone( a => { switch (a.Status) { case DreamStatus.Ok: aResult.Return(JsonConvert.DeserializeObject <Dictionary <string, string> >(a.ToText())); break; case DreamStatus.NotFound: aResult.Return(new Dictionary <string, string>()); break; default: aResult.Throw(new CouchException(a)); break; } }, aResult.Throw ); return(aResult); }
public void EncodeFragment() { Assert.AreEqual("a^b|c#d", XUri.EncodeFragment("a^b|c#d")); }