本文整理汇总了C#中System.IO.BufferedStream.ToJObject方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.ToJObject方法的具体用法?C# BufferedStream.ToJObject怎么用?C# BufferedStream.ToJObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.ToJObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public IEnumerable<ListItem> Read(string name, Guid start, int take)
{
Api.JetSetCurrentIndex(session, Lists, "by_name_and_etag");
Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
Api.MakeKey(session, Lists, start.TransformToValueForEsentSorting(), MakeKeyGrbit.None);
if (Api.TrySeek(session, Lists, SeekGrbit.SeekGT) == false)
yield break;
int count = 0;
do
{
var nameFromDb = Api.RetrieveColumnAsString(session, Lists, tableColumnsCache.ListsColumns["name"], Encoding.Unicode);
if(string.Equals(name, nameFromDb, StringComparison.InvariantCultureIgnoreCase) == false)
yield break;
count++;
var etag = Api.RetrieveColumn(session, Lists, tableColumnsCache.ListsColumns["etag"]).TransfromToGuidWithProperSorting();
using (Stream stream = new BufferedStream(new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"])))
{
yield return new ListItem
{
Etag = etag,
Data = stream.ToJObject(),
Key = Api.RetrieveColumnAsString(session, Lists, tableColumnsCache.ListsColumns["key"], Encoding.Unicode)
};
}
} while (Api.TryMoveNext(session, Lists) && count < take);
}
示例2: GetMappedResults
public IEnumerable<RavenJObject> GetMappedResults(params GetMappedResultsParams[] getMappedResultsParams)
{
var optimizedIndexReader = new OptimizedIndexReader<GetMappedResultsParams>(Session, MappedResults, getMappedResultsParams.Length);
Api.JetSetCurrentIndex(session, MappedResults, "by_reduce_key_and_view_hashed");
foreach (var item in getMappedResultsParams)
{
Api.MakeKey(session, MappedResults, item.ViewAndReduceKeyHashed, MakeKeyGrbit.NewKey);
if (Api.TrySeek(session, MappedResults, SeekGrbit.SeekEQ) == false)
continue;
Api.MakeKey(session, MappedResults, item.ViewAndReduceKeyHashed, MakeKeyGrbit.NewKey);
Api.JetSetIndexRange(session, MappedResults, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive);
do
{
optimizedIndexReader.Add(item);
} while (Api.TryMoveNext(session, MappedResults));
}
return optimizedIndexReader
.Where(item =>
{
// we need to check that we don't have hash collisions
var currentReduceKey = Api.RetrieveColumnAsString(session, MappedResults,
tableColumnsCache.MappedResultsColumns["reduce_key"]);
if (currentReduceKey != item.ReduceKey)
return false;
var currentView = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"]);
return currentView == item.View;
})
.Select(item =>
{
using (var stream = new BufferedStream(new ColumnStream(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"])))
{
return stream.ToJObject();
}
});
}
示例3: ReadLast
public ListItem ReadLast(string name)
{
Api.JetSetCurrentIndex(session, Lists, "by_name_and_etag");
Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
Api.MakeKey(session, Lists, Etag.InvalidEtag.TransformToValueForEsentSorting(), MakeKeyGrbit.None);
if (Api.TrySeek(session, Lists, SeekGrbit.SeekLE) == false)
return null;
var nameFromDb = Api.RetrieveColumnAsString(session, Lists, tableColumnsCache.ListsColumns["name"], Encoding.Unicode);
if (string.Equals(name, nameFromDb, StringComparison.InvariantCultureIgnoreCase) == false)
return null;
using (Stream stream = new BufferedStream(new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"])))
{
return new ListItem
{
Data = stream.ToJObject(),
Key = Api.RetrieveColumnAsString(session, Lists, tableColumnsCache.ListsColumns["key"], Encoding.Unicode),
Etag = Etag.Parse(Api.RetrieveColumn(session, Lists, tableColumnsCache.ListsColumns["etag"])),
CreatedAt = Api.RetrieveColumnAsDateTime(session, Lists, tableColumnsCache.ListsColumns["created_at"]).Value
};
}
}
示例4: Read
public ListItem Read(string name, string key)
{
Api.JetSetCurrentIndex(session, Lists, "by_name_and_key");
Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
Api.MakeKey(session, Lists, key, Encoding.Unicode, MakeKeyGrbit.None);
if (Api.TrySeek(session, Lists, SeekGrbit.SeekEQ) == false)
return null;
using (Stream stream = new BufferedStream(new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"])))
{
return new ListItem
{
Data = stream.ToJObject(),
Key = Api.RetrieveColumnAsString(session, Lists, tableColumnsCache.ListsColumns["key"], Encoding.Unicode),
Etag = Etag.Parse(Api.RetrieveColumn(session, Lists, tableColumnsCache.ListsColumns["etag"])),
CreatedAt = Api.RetrieveColumnAsDateTime(session, Lists, tableColumnsCache.ListsColumns["created_at"]).Value
};
}
}
示例5: Read
public IEnumerable<ListItem> Read(string name, int start, int take)
{
Api.JetSetCurrentIndex(session, Lists, "by_name_and_etag");
Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
if (Api.TrySeek(session, Lists, SeekGrbit.SeekGT) == false)
yield break;
int skipped = 0;
while (skipped < start)
{
if (!Api.TryMoveNext(session, Lists))
yield break;
skipped++;
}
int count = 0;
do
{
var nameFromDb = Api.RetrieveColumnAsString(session, Lists, tableColumnsCache.ListsColumns["name"], Encoding.Unicode);
if (string.Equals(name, nameFromDb, StringComparison.InvariantCultureIgnoreCase) == false)
yield break;
var etag = Etag.Parse(Api.RetrieveColumn(session, Lists, tableColumnsCache.ListsColumns["etag"]));
count++;
using (Stream stream = new BufferedStream(new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"])))
{
yield return new ListItem
{
Etag = etag,
Data = stream.ToJObject(),
Key = Api.RetrieveColumnAsString(session, Lists, tableColumnsCache.ListsColumns["key"], Encoding.Unicode),
CreatedAt = Api.RetrieveColumnAsDateTime(session, Lists, tableColumnsCache.ListsColumns["created_at"]).Value
};
}
} while (Api.TryMoveNext(session, Lists) && count < take);
}
示例6: GetMappedResults
public IEnumerable<RavenJObject> GetMappedResults(params GetMappedResultsParams[] getMappedResultsParams)
{
// optimized according to this: http://managedesent.codeplex.com/discussions/274843#post680337
var primaryKeyIndexes = new List<Tuple<byte[], GetMappedResultsParams>>();
Api.JetSetCurrentIndex(session, MappedResults, "by_reduce_key_and_view_hashed");
foreach (var item in getMappedResultsParams)
{
Api.MakeKey(session, MappedResults, item.ViewAndReduceKeyHashed, MakeKeyGrbit.NewKey);
if (Api.TrySeek(session, MappedResults, SeekGrbit.SeekEQ) == false)
continue;
var bookmarkBuffer = new byte[SystemParameters.BookmarkMost];
var ignoredBuffer = new byte[SystemParameters.BookmarkMost];
Api.MakeKey(session, MappedResults, item.ViewAndReduceKeyHashed, MakeKeyGrbit.NewKey);
Api.JetSetIndexRange(session, MappedResults, SetIndexRangeGrbit.RangeUpperLimit | SetIndexRangeGrbit.RangeInclusive);
do
{
int actualBookmarkSize;
int ignored;
Api.JetGetSecondaryIndexBookmark(session, MappedResults, ignoredBuffer, ignoredBuffer.Length, out ignored, bookmarkBuffer,
bookmarkBuffer.Length, out actualBookmarkSize, GetSecondaryIndexBookmarkGrbit.None);
primaryKeyIndexes.Add(Tuple.Create(bookmarkBuffer.Take(actualBookmarkSize).ToArray(), item));
} while (Api.TryMoveNext(session, MappedResults));
}
primaryKeyIndexes.Sort((x, y) =>
{
var bytes1 = x.Item1;
var bytes2 = y.Item1;
for (int i = 0; i < Math.Min(bytes1.Length, bytes2.Length); i++)
{
if (bytes1[i] != bytes2[i])
return bytes1[i] - bytes2[i];
}
return bytes1.Length - bytes2.Length;
});
foreach (var primaryKeyIndexTuple in primaryKeyIndexes)
{
var bookmark = primaryKeyIndexTuple.Item1;
var item = primaryKeyIndexTuple.Item2;
Api.JetGotoBookmark(session, MappedResults, bookmark, bookmark.Length);
// we need to check that we don't have hash collisions
var currentReduceKey = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"]);
if (currentReduceKey != item.ReduceKey)
continue;
var currentView = Api.RetrieveColumnAsString(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"]);
if (currentView != item.View)
continue;
RavenJObject obj;
using(var stream = new BufferedStream(new ColumnStream(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"])))
{
obj = stream.ToJObject();
}
yield return obj;
}
}