本文整理汇总了C#中IDictionary.GetCast方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.GetCast方法的具体用法?C# IDictionary.GetCast怎么用?C# IDictionary.GetCast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.GetCast方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SmallestLength
private static long SmallestLength(IDictionary<string, object> attachment)
{
long length = attachment.GetCast<long>("length");
long encodedLength = attachment.GetCast<long>("encoded_length", -1);
if (encodedLength != -1) {
length = encodedLength;
}
return length;
}
示例2: ProcessBody
private static void ProcessBody(IDictionary<string, object> body)
{
var feed = body.GetCast<string>("feed");
if (feed != null) {
if (feed.Equals("longpoll")) {
body["feed"] = ChangesFeedMode.LongPoll;
} else if (feed.Equals("continuous")) {
body["feed"] = ChangesFeedMode.Continuous;
} else if (feed.Equals("eventsource")) {
body["feed"] = ChangesFeedMode.EventSource;
}
} else {
body["feed"] = ChangesFeedMode.Normal;
}
var contentOptions = DocumentContentOptions.None;
if (body.GetCast<bool>("attachments")) {
contentOptions |= DocumentContentOptions.IncludeAttachments;
}
if (body.GetCast<bool>("local_seq")) {
contentOptions |= DocumentContentOptions.IncludeLocalSeq;
}
if (body.GetCast<bool>("conflicts")) {
contentOptions |= DocumentContentOptions.IncludeConflicts;
}
if (body.GetCast<bool>("revs")) {
contentOptions |= DocumentContentOptions.IncludeRevs;
}
if (body.GetCast<bool>("revs_info")) {
contentOptions |= DocumentContentOptions.IncludeRevsInfo;
}
body["content_options"] = contentOptions;
}
示例3: AttachmentInternal
public AttachmentInternal(string name, IDictionary<string, object> info)
: this(name, info.GetCast<string>("content_type"))
{
Length = info.GetCast<long>("length");
EncodedLength = info.GetCast<long>("encoded_length");
_digest = info.GetCast<string>("digest");
if (_digest != null) {
BlobKey = new BlobKey(_digest);
}
string encodingString = info.GetCast<string>("encoding");
if (encodingString != null) {
if (encodingString.Equals("gzip")) {
Encoding = AttachmentEncoding.GZIP;
} else {
throw new CouchbaseLiteException(StatusCode.BadEncoding);
}
}
var data = info.Get("data");
if (data != null) {
// If there's inline attachment data, decode and store it:
if (data is string) {
_data = Convert.FromBase64String((string)data);
} else {
_data = data as IEnumerable<byte>;
}
if (_data == null) {
throw new CouchbaseLiteException(StatusCode.BadEncoding);
}
SetPossiblyEncodedLength(_data.LongCount());
} else if (info.GetCast<bool>("stub", false)) {
// This item is just a stub; validate and skip it
if(info.ContainsKey("revpos")) {
var revPos = info.GetCast<int>("revpos");
if (revPos <= 0) {
throw new CouchbaseLiteException(StatusCode.BadAttachment);
}
RevPos = revPos;
}
} else if (info.GetCast<bool>("follows", false)) {
// I can't handle this myself; my caller will look it up from the digest
if (Digest == null) {
throw new CouchbaseLiteException(StatusCode.BadAttachment);
}
if(info.ContainsKey("revpos")) {
var revPos = info.GetCast<int>("revpos");
if (revPos <= 0) {
throw new CouchbaseLiteException(StatusCode.BadAttachment);
}
RevPos = revPos;
}
} else {
throw new CouchbaseLiteException(StatusCode.BadAttachment);
}
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:61,代码来源:AttachmentInternal.cs
示例4: PutDocument
internal RevisionInternal PutDocument(string docId, IDictionary<string, object> properties, string prevRevId, bool allowConflict, Status resultStatus)
{
bool deleting = properties == null || properties.GetCast<bool>("_deleted");
Log.D(TAG, "PUT _id={0}, _rev={1}, _deleted={2}, allowConflict={3}", docId, prevRevId, deleting, allowConflict);
if ((prevRevId != null && docId == null) || (deleting && docId == null)) {
if (resultStatus != null) {
resultStatus.Code = StatusCode.BadId;
return null;
}
}
if (properties != null && properties.Get("_attachments").AsDictionary<string, object>() != null) {
var tmpRev = new RevisionInternal(docId, prevRevId, deleting);
tmpRev.SetProperties(properties);
if (!ProcessAttachmentsForRevision(tmpRev, prevRevId, resultStatus)) {
return null;
}
properties = tmpRev.GetProperties();
}
StoreValidation validationBlock = null;
if (Shared.HasValues("validation", Name)) {
validationBlock = ValidateRevision;
}
var putRev = Storage.PutRevision(docId, prevRevId, properties, deleting, allowConflict, validationBlock, resultStatus);
if (putRev != null) {
Log.D(TAG, "--> created {0}", putRev);
if (!string.IsNullOrEmpty(docId)) {
UnsavedRevisionDocumentCache.Remove(docId);
}
}
return putRev;
}
示例5: AttachmentInternal
public AttachmentInternal(string name, IDictionary<string, object> info)
: this(name, info.GetCast<string>("content_type"))
{
Length = info.GetCast<long>("length");
EncodedLength = info.GetCast<long>("encoded_length");
_digest = info.GetCast<string>("digest");
if (_digest != null) {
BlobKey = new BlobKey(_digest);
}
string encodingString = info.GetCast<string>("encoding");
if (encodingString != null) {
if (encodingString.Equals("gzip")) {
Encoding = AttachmentEncoding.GZIP;
} else {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadEncoding, TAG,
"Invalid encoding type ({0}) in ctor", encodingString);
}
}
var data = info.Get("data");
if (data != null) {
// If there's inline attachment data, decode and store it:
if (data is string) {
_data = Convert.FromBase64String((string)data);
} else {
_data = data as IEnumerable<byte>;
}
if (_data == null) {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadEncoding, TAG,
"Invalid data type ({0}) in ctor", data.GetType().Name);
}
SetPossiblyEncodedLength(_data.LongCount());
} else if (info.GetCast<bool>("stub", false)) {
// This item is just a stub; validate and skip it
if(info.ContainsKey("revpos")) {
var revPos = info.GetCast("revpos", -1); // PouchDB has a bug that generates "revpos":0; allow this (#627)
if (revPos < 0) {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadAttachment, TAG,
"Invalid revpos ({0}) in ctor", revPos);
}
RevPos = revPos;
}
} else if (info.GetCast<bool>("follows", false)) {
// I can't handle this myself; my caller will look it up from the digest
if (Digest == null) {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadAttachment, TAG,
"follows is true, but the attachment digest is null in ctor");
}
if(info.ContainsKey("revpos")) {
var revPos = info.GetCast("revpos", -1); // PouchDB has a bug that generates "revpos":0; allow this (#627)
if (revPos < 0) {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadAttachment, TAG,
"Invalid revpos ({0}) in ctor", revPos);
}
RevPos = revPos;
}
} else {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadAttachment, TAG,
"Neither data nor stub nor follows was specified on the attachment data");
}
}
示例6: SaveDocument
private bool SaveDocument(C4Document *doc, string revId, IDictionary<string, object> properties)
{
// Is the new revision the winner?
Native.c4doc_selectCurrentRevision(doc);
bool isWinner = (string)doc->selectedRev.revID == revId;
// Update the documentType:
if (isWinner) {
var type = properties == null ? null : properties.GetCast<string>("type");
ForestDBBridge.Check(err => Native.c4doc_setType(doc, type, err));
}
// Save:
ForestDBBridge.Check(err => Native.c4doc_save(doc, (uint)MaxRevTreeDepth, err));
return isWinner;
}
示例7: PutDocument
internal RevisionInternal PutDocument(string docId, IDictionary<string, object> properties, string prevRevId, bool allowConflict)
{
bool deleting = properties == null || properties.GetCast<bool>("_deleted");
Log.D(TAG, "PUT _id={0}, _rev={1}, _deleted={2}, allowConflict={3}", docId, prevRevId, deleting, allowConflict);
if ((prevRevId != null && docId == null) || (deleting && docId == null)) {
throw new CouchbaseLiteException(StatusCode.BadId);
}
if (properties != null && properties.Get("_attachments").AsDictionary<string, object>() != null) {
var tmpRev = new RevisionInternal(docId, prevRevId, deleting);
tmpRev.SetProperties(properties);
if (!ProcessAttachmentsForRevision(tmpRev, prevRevId == null ? null : new List<string> { prevRevId })) {
return null;
}
properties = tmpRev.GetProperties();
}
StoreValidation validationBlock = null;
if (Shared.HasValues("validation", Name)) {
validationBlock = ValidateRevision;
}
var putRev = Storage.PutRevision(docId, prevRevId, properties, deleting, allowConflict, validationBlock);
if (putRev != null) {
Log.D(TAG, "--> created {0}", putRev);
if (!string.IsNullOrEmpty(docId)) {
var dummy = default(WeakReference);
UnsavedRevisionDocumentCache.TryRemove(docId, out dummy);
}
}
return putRev;
}
示例8: AttachmentWriterForAttachment
// This is ONLY FOR TESTS
internal BlobStoreWriter AttachmentWriterForAttachment(IDictionary<string, object> attachment)
{
var digest = attachment.GetCast<string>("digest");
if (digest == null) {
return null;
}
return _pendingAttachmentsByDigest.Get(digest);
}
示例9: Compile
internal Status Compile(IDictionary<string, object> viewProps, string language)
{
language = language ?? "javascript";
string mapSource = viewProps.Get("map") as string;
if (mapSource == null) {
return new Status(StatusCode.NotFound);
}
MapDelegate mapDelegate = Compiler.CompileMap(mapSource, language);
if (mapDelegate == null) {
Log.W(TAG, "View {0} could not compile {1} map fn: {2}", Name, language, mapSource);
return new Status(StatusCode.CallbackError);
}
string reduceSource = viewProps.Get("reduce") as string;
ReduceDelegate reduceDelegate = null;
if (reduceSource != null) {
reduceDelegate = Compiler.CompileReduce(reduceSource, language);
if (reduceDelegate == null) {
Log.W(TAG, "View {0} could not compile {1} reduce fn: {2}", Name, language, mapSource);
return new Status(StatusCode.CallbackError);
}
}
string version = Misc.HexSHA1Digest(Manager.GetObjectMapper().WriteValueAsBytes(viewProps));
SetMapReduce(mapDelegate, reduceDelegate, version);
DocumentType = viewProps.GetCast<string>("documentType");
var options = viewProps.Get("options").AsDictionary<string, object>();
Collation = ViewCollation.Unicode;
if (options != null && options.ContainsKey("collation")) {
string collation = options["collation"] as string;
if (collation.ToLower().Equals("raw")) {
Collation = ViewCollation.Raw;
}
}
return new Status(StatusCode.Ok);
}
示例10: StatusFromBulkDocsResponseItem
/// <summary>
/// Gets the status from a response from _bulk_docs and translates it into
/// a Status object
/// </summary>
/// <returns>The status of the request</returns>
/// <param name="item">The response received</param>
protected Status StatusFromBulkDocsResponseItem(IDictionary<string, object> item)
{
try {
if (!item.ContainsKey("error")) {
return new Status(StatusCode.Ok);
}
var errorStr = item.Get("error") as string;
if (StringEx.IsNullOrWhiteSpace(errorStr)) {
return new Status(StatusCode.Ok);
}
// 'status' property is nonstandard; TouchDB returns it, others don't.
var status = item.GetCast<int>("status");
if (status >= 400) {
return new Status((StatusCode)status);
}
// If no 'status' present, interpret magic hardcoded CouchDB error strings:
if (errorStr.Equals("unauthorized", StringComparison.InvariantCultureIgnoreCase)) {
return new Status(StatusCode.Unauthorized);
} else {
if (errorStr.Equals("forbidden", StringComparison.InvariantCultureIgnoreCase)) {
return new Status(StatusCode.Forbidden);
} else {
if (errorStr.Equals("conflict", StringComparison.InvariantCultureIgnoreCase)) {
return new Status(StatusCode.Conflict);
} else {
return new Status(StatusCode.UpStreamError);
}
}
}
} catch (Exception e) {
Log.E(Database.TAG, "Exception getting status from " + item, e);
}
return new Status(StatusCode.Ok);
}
示例11: ParseRevisionHistoryDict
public static IList<RevisionID> ParseRevisionHistoryDict(IDictionary<string, object> dict)
{
if(dict == null) {
return null;
}
// Extract the history, expanding the numeric prefixes
var start = dict.GetCast<int>("start");
var revIDs = dict.Get("ids").AsList<string>();
return revIDs?.Select(x =>
{
var str = x as string;
if(str == null) {
return null;
}
if(start > 0) {
str = String.Format("{0}-{1}", start--, str);
}
return str.AsRevID();
})?.ToList();
}
示例12: PutDocument
internal RevisionInternal PutDocument(string docId, IDictionary<string, object> properties, RevisionID prevRevId, bool allowConflict, Uri source)
{
bool deleting = properties == null || properties.GetCast<bool>("_deleted");
Log.To.Database.V(TAG, "PUT _id={0}, _rev={1}, _deleted={2}, allowConflict={3}",
new SecureLogString(docId, LogMessageSensitivity.PotentiallyInsecure), prevRevId, deleting, allowConflict);
if(prevRevId != null && docId == null) {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadId, TAG,
"prevRevId {0} specified in PutDocument, but docId not specified", prevRevId);
}
if(deleting && docId == null) {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadId, TAG,
"No document ID specified on a delete request");
}
if(properties != null && properties.Get("_attachments").AsDictionary<string, object>() != null) {
var generation = prevRevId == null ? 1 : prevRevId.Generation + 1;
var tmpRevID = String.Format("{0}-00", generation).AsRevID();
var tmpRev = new RevisionInternal(docId ?? "x", tmpRevID, deleting);
tmpRev.SetProperties(properties);
if(!ProcessAttachmentsForRevision(tmpRev, prevRevId == null ? null : new List<RevisionID> { prevRevId })) {
return null;
}
properties = tmpRev.GetProperties();
}
StoreValidation validationBlock = null;
if(Shared.HasValues("validation", Name)) {
validationBlock = ValidateRevision;
}
return Storage.PutRevision(docId, prevRevId, properties, deleting, allowConflict, source, validationBlock);
}
示例13: ParseTokens
private bool ParseTokens(IDictionary<string, object> tokens)
{
var idToken = tokens.GetCast<string>("id_token");
if(idToken == null) {
return false;
}
IDToken = idToken;
var newRefreshToken = tokens.GetCast<string>("refresh_token");
if (newRefreshToken != null) {
RefreshToken = newRefreshToken;
}
Username = tokens.GetCast<string>("name");
_haveSessionCookie = tokens.ContainsKey("session_id");
return true;
}