本文整理汇总了C#中Raven.Imports.Newtonsoft.Json.JsonTextWriter.WriteStartObject方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteStartObject方法的具体用法?C# JsonTextWriter.WriteStartObject怎么用?C# JsonTextWriter.WriteStartObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Imports.Newtonsoft.Json.JsonTextWriter
的用法示例。
在下文中一共展示了JsonTextWriter.WriteStartObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(object parameter)
{
var saveFile = new SaveFileDialog
{
DefaultFileName = string.Format("Dump of {0}, {1}", ApplicationModel.Database.Value.Name, DateTimeOffset.Now.ToString("MMM dd yyyy HH-mm", CultureInfo.InvariantCulture)),
DefaultExt = ".raven.dump",
Filter = "Raven Dumps|*.raven.dump",
};
if (saveFile.ShowDialog() != true)
return;
stream = saveFile.OpenFile();
gZipStream = new GZipStream(stream, CompressionMode.Compress);
streamWriter = new StreamWriter(gZipStream);
jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
taskModel.TaskStatus = TaskStatus.Started;
output(String.Format("Exporting to {0}", saveFile.SafeFileName));
output("Begin reading indexes");
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("Indexes");
jsonWriter.WriteStartArray();
ReadIndexes(0)
.Catch(exception => Infrastructure.Execute.OnTheUI(() => Finish(exception)));
}
示例2: StreamToClient
private void StreamToClient(Stream stream, int pageSize, Etag etag)
{
using (var cts = new CancellationTokenSource())
using (var timeout = cts.TimeoutAfter(FileSystemsLandlord.SystemConfiguration.DatabaseOperationTimeout))
using (var writer = new JsonTextWriter(new StreamWriter(stream)))
{
writer.WriteStartObject();
writer.WritePropertyName("Results");
writer.WriteStartArray();
Storage.Batch(accessor =>
{
var files = accessor.GetFilesAfter(etag, pageSize);
foreach (var file in files)
{
timeout.Delay();
var doc = RavenJObject.FromObject(file);
doc.WriteTo(writer);
writer.WriteRaw(Environment.NewLine);
}
});
writer.WriteEndArray();
writer.WriteEndObject();
writer.Flush();
}
}
示例3: StreamToClient
private void StreamToClient(Stream stream, int pageSize, Etag etag, OrderedPartCollection<AbstractFileReadTrigger> readTriggers)
{
using (var cts = new CancellationTokenSource())
using (var timeout = cts.TimeoutAfter(FileSystemsLandlord.SystemConfiguration.DatabaseOperationTimeout))
using (var writer = new JsonTextWriter(new StreamWriter(stream)))
{
writer.WriteStartObject();
writer.WritePropertyName("Results");
writer.WriteStartArray();
Storage.Batch(accessor =>
{
var files = accessor.GetFilesAfter(etag, pageSize);
foreach (var file in files)
{
if (readTriggers.CanReadFile(file.FullPath, file.Metadata, ReadOperation.Load) == false)
continue;
timeout.Delay();
var doc = RavenJObject.FromObject(file);
doc.WriteTo(writer);
writer.WriteRaw(Environment.NewLine);
}
});
writer.WriteEndArray();
writer.WriteEndObject();
writer.Flush();
}
}
示例4: Execute
public override void Execute(object parameter)
{
TaskCheckBox attachmentUI = taskModel.TaskInputs.FirstOrDefault(x => x.Name == "Include Attachments") as TaskCheckBox;
includeAttachments = attachmentUI != null && attachmentUI.Value;
var saveFile = new SaveFileDialog
{
DefaultExt = ".ravendump",
Filter = "Raven Dumps|*.ravendump;*.raven.dump",
};
var name = ApplicationModel.Database.Value.Name;
var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray());
var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture));
try
{
saveFile.DefaultFileName = defaultFileName;
}
catch { }
if (saveFile.ShowDialog() != true)
return;
taskModel.CanExecute.Value = false;
stream = saveFile.OpenFile();
gZipStream = new GZipStream(stream, CompressionMode.Compress);
streamWriter = new StreamWriter(gZipStream);
jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
taskModel.TaskStatus = TaskStatus.Started;
output(String.Format("Exporting to {0}", saveFile.SafeFileName));
jsonWriter.WriteStartObject();
Action finalized = () =>
{
jsonWriter.WriteEndObject();
Infrastructure.Execute.OnTheUI(() => Finish(null));
};
Action readAttachments = () => ReadAttachments(Guid.Empty, 0, callback: finalized);
Action readDocuments = () => ReadDocuments(Guid.Empty, 0, callback: includeAttachments ? readAttachments : finalized);
try
{
ReadIndexes(0, callback: readDocuments);
}
catch (Exception ex)
{
taskModel.ReportError(ex);
Infrastructure.Execute.OnTheUI(() => Finish(ex));
}
}
示例5: StreamToClient
private void StreamToClient(Stream stream, string startsWith, int start, int pageSize, Etag etag, string matches, int nextPageStart, string skipAfter)
{
var bufferStream = new BufferedStream(stream, 1024 * 64);
using (var cts = new CancellationTokenSource())
using (var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout))
using (var writer = new JsonTextWriter(new StreamWriter(bufferStream)))
{
writer.WriteStartObject();
writer.WritePropertyName("Results");
writer.WriteStartArray();
Action<JsonDocument> addDocument = doc =>
{
timeout.Delay();
doc.ToJson().WriteTo(writer);
writer.WriteRaw(Environment.NewLine);
};
Database.TransactionalStorage.Batch(accessor =>
{
// we may be sending a LOT of documents to the user, and most
// of them aren't going to be relevant for other ops, so we are going to skip
// the cache for that, to avoid filling it up very quickly
using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
{
if (string.IsNullOrEmpty(startsWith))
{
Database.Documents.GetDocuments(start, pageSize, etag, cts.Token, addDocument);
}
else
{
var nextPageStartInternal = nextPageStart;
Database.Documents.GetDocumentsWithIdStartingWith(startsWith, matches, null, start, pageSize, cts.Token, ref nextPageStartInternal, addDocument, skipAfter: skipAfter);
nextPageStart = nextPageStartInternal;
}
}
});
writer.WriteEndArray();
writer.WritePropertyName("NextPageStart");
writer.WriteValue(nextPageStart);
writer.WriteEndObject();
writer.Flush();
bufferStream.Flush();
}
}
示例6: Respond
public override void Respond(IHttpContext context)
{
using (context.Response.Streaming())
{
context.Response.ContentType = "application/json; charset=utf-8";
using (var writer = new JsonTextWriter(new StreamWriter(context.Response.OutputStream)))
{
writer.WriteStartObject();
writer.WritePropertyName("Results");
writer.WriteStartArray();
Database.TransactionalStorage.Batch(accessor =>
{
var startsWith = context.Request.QueryString["startsWith"];
int pageSize = context.GetPageSize(int.MaxValue);
if (string.IsNullOrEmpty(context.Request.QueryString["pageSize"]))
pageSize = int.MaxValue;
// we may be sending a LOT of documents to the user, and most
// of them aren't going to be relevant for other ops, so we are going to skip
// the cache for that, to avoid filling it up very quickly
using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
{
if (string.IsNullOrEmpty(startsWith))
{
Database.GetDocuments(context.GetStart(), pageSize, context.GetEtagFromQueryString(),
doc => doc.WriteTo(writer));
}
else
{
Database.GetDocumentsWithIdStartingWith(
startsWith,
context.Request.QueryString["matches"],
context.Request.QueryString["exclude"],
context.GetStart(),
pageSize,
doc => doc.WriteTo(writer));
}
}
});
writer.WriteEndArray();
writer.WriteEndObject();
writer.Flush();
}
}
}
示例7: Respond
public override void Respond(IHttpContext context)
{
context.Response.BufferOutput = false;
var match = urlMatcher.Match(context.GetRequestUrl());
var index = match.Groups[1].Value;
var query = context.GetIndexQueryFromHttpContext(int.MaxValue);
if (string.IsNullOrEmpty(context.Request.QueryString["pageSize"]))
query.PageSize = int.MaxValue;
var isHeadRequest = context.Request.HttpMethod == "HEAD";
if (isHeadRequest)
query.PageSize = 0;
JsonWriter writer = null;
Database.Query(index, query, information =>
{
context.Response.AddHeader("Raven-Result-Etag", information.ResultEtag.ToString());
context.Response.AddHeader("Raven-Index-Etag", information.IndexEtag.ToString());
context.Response.AddHeader("Raven-Is-Stale", information.IsStable ? "true" : "false");
context.Response.AddHeader("Raven-Index", information.Index);
context.Response.AddHeader("Raven-Total-Results", information.TotalResults.ToString(CultureInfo.InvariantCulture));
context.Response.AddHeader("Raven-Index-Timestamp",
information.IndexTimestamp.ToString(Default.DateTimeFormatsToWrite,
CultureInfo.InvariantCulture));
if (isHeadRequest)
return;
writer = new JsonTextWriter(new StreamWriter(context.Response.OutputStream));
writer.WriteStartObject();
writer.WritePropertyName("Results");
writer.WriteStartArray();
}, result => result.WriteTo(writer, Default.Converters));
if (isHeadRequest)
return;
writer.WriteEndArray();
writer.WriteEndObject();
if (writer != null)
{
writer.Flush();
writer.Close();
}
}
示例8: Execute
public override void Execute(object parameter)
{
var saveFile = new SaveFileDialog
{
DefaultExt = ".ravendump",
Filter = "Raven Dumps|*.ravendump;*.raven.dump",
};
var name = ApplicationModel.Database.Value.Name;
var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray());
var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture));
try
{
saveFile.DefaultFileName = defaultFileName;
}
catch { }
if (saveFile.ShowDialog() != true)
return;
taskModel.CanExecute.Value = false;
stream = saveFile.OpenFile();
gZipStream = new GZipStream(stream, CompressionMode.Compress);
streamWriter = new StreamWriter(gZipStream);
jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
taskModel.TaskStatus = TaskStatus.Started;
output(String.Format("Exporting to {0}", saveFile.SafeFileName));
output("Begin reading indexes");
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("Indexes");
jsonWriter.WriteStartArray();
ReadIndexes(0)
.Catch(exception =>
{
taskModel.ReportError(exception);
Infrastructure.Execute.OnTheUI(() => Finish(exception));
});
}
示例9: Export
public void Export(string file)
{
using (var streamWriter =
new StreamWriter(new GZipStream(File.Create(file), CompressionMode.Compress)))
{
var jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
jsonWriter.WriteStartObject();
WriteItemsFromDb(jsonWriter, "Indexes", start => _documentDatabase.GetIndexes(start, 128));
WriteItemsFromDb(jsonWriter, "Docs", start => _documentDatabase.GetDocuments(start, 128, null));
WriteItemsFromDb(jsonWriter, "Attachments", GetAttachments);
jsonWriter.WriteEndObject();
}
}
示例10: ExportDatabase
public void ExportDatabase()
{
using (var stream = File.Create(outputDirectory))
using (var gZipStream = new GZipStream(stream, CompressionMode.Compress,leaveOpen: true))
using (var streamWriter = new StreamWriter(gZipStream))
{
var jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
jsonWriter.WriteStartObject();
//Indexes
jsonWriter.WritePropertyName("Indexes");
jsonWriter.WriteStartArray();
WriteIndexes(jsonWriter);
jsonWriter.WriteEndArray();
//Documents
jsonWriter.WritePropertyName("Docs");
jsonWriter.WriteStartArray();
WriteDocuments(jsonWriter);
jsonWriter.WriteEndArray();
//Attachments
jsonWriter.WritePropertyName("Attachments");
jsonWriter.WriteStartArray();
WriteAttachments(jsonWriter);
jsonWriter.WriteEndArray();
//Transformers
jsonWriter.WritePropertyName("Transformers");
jsonWriter.WriteStartArray();
WriteTransformers(jsonWriter);
jsonWriter.WriteEndArray();
//Identities
jsonWriter.WritePropertyName("Identities");
jsonWriter.WriteStartArray();
WriteIdentities(jsonWriter);
jsonWriter.WriteEndArray();
//end of export
jsonWriter.WriteEndObject();
streamWriter.Flush();
}
}
示例11: StreamToClient
private void StreamToClient(Stream stream, ExportOptions options, Lazy<NameValueCollection> headers, IPrincipal user)
{
var old = CurrentOperationContext.Headers.Value;
var oldUser = CurrentOperationContext.User.Value;
try
{
CurrentOperationContext.Headers.Value = headers;
CurrentOperationContext.User.Value = user;
Database.TransactionalStorage.Batch(accessor =>
{
var bufferStream = new BufferedStream(stream, 1024 * 64);
using (var cts = new CancellationTokenSource())
using (var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout))
using (var streamWriter = new StreamWriter(bufferStream))
using (var writer = new JsonTextWriter(streamWriter))
{
writer.WriteStartObject();
writer.WritePropertyName("Results");
writer.WriteStartArray();
var exporter = new SmugglerExporter(Database, options);
exporter.Export(item => WriteToStream(writer, item, timeout), cts.Token);
writer.WriteEndArray();
writer.WriteEndObject();
writer.Flush();
bufferStream.Flush();
}
});
}
finally
{
CurrentOperationContext.Headers.Value = old;
CurrentOperationContext.User.Value = oldUser;
}
}
示例12: Respond
public override void Respond(IHttpContext context)
{
context.Response.BufferOutput = false;
using (var writer = new JsonTextWriter(new StreamWriter(context.Response.OutputStream)))
{
writer.WriteStartObject();
writer.WritePropertyName("Results");
writer.WriteStartArray();
Database.TransactionalStorage.Batch(accessor =>
{
var startsWith = context.Request.QueryString["startsWith"];
int pageSize = context.GetPageSize(int.MaxValue);
if (string.IsNullOrEmpty(context.Request.QueryString["pageSize"]))
pageSize = int.MaxValue;
if (string.IsNullOrEmpty(startsWith))
{
Database.GetDocuments(context.GetStart(), pageSize, context.GetEtagFromQueryString(),
doc => doc.WriteTo(writer));
}
else
{
Database.GetDocumentsWithIdStartingWith(
startsWith,
context.Request.QueryString["matches"],
context.GetStart(),
pageSize,
doc => doc.WriteTo(writer));
}
});
writer.WriteEndArray();
writer.WriteEndObject();
writer.Flush();
}
}
示例13: WriteReadWrite
public void WriteReadWrite()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw)
{
Formatting = Formatting.Indented
})
{
jsonWriter.WriteStartArray();
jsonWriter.WriteValue(true);
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("integer");
jsonWriter.WriteValue(99);
jsonWriter.WritePropertyName("string");
jsonWriter.WriteValue("how now brown cow?");
jsonWriter.WritePropertyName("array");
jsonWriter.WriteStartArray();
for (int i = 0; i < 5; i++)
{
jsonWriter.WriteValue(i);
}
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("decimal");
jsonWriter.WriteValue(990.00990099m);
jsonWriter.WriteEndObject();
jsonWriter.WriteValue(5);
jsonWriter.WriteEndArray();
jsonWriter.WriteEndObject();
jsonWriter.WriteValue("This is a string.");
jsonWriter.WriteNull();
jsonWriter.WriteNull();
jsonWriter.WriteEndArray();
}
string json = sb.ToString();
JsonSerializer serializer = new JsonSerializer();
object jsonObject = serializer.Deserialize(new JsonTextReader(new StringReader(json)));
sb = new StringBuilder();
sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw)
{
Formatting = Formatting.Indented
})
{
serializer.Serialize(jsonWriter, jsonObject);
}
Assert.AreEqual(json, sb.ToString());
}
示例14: WriteIndexes
private void WriteIndexes(JsonTextWriter jsonWriter)
{
var indexDefinitionsBasePath = Path.Combine(baseDirectory, indexDefinitionFolder);
var indexes = Directory.GetFiles(indexDefinitionsBasePath, "*.index");
int currentIndexCount = 0;
foreach (var file in indexes)
{
var ravenObj = RavenJObject.Parse(File.ReadAllText(file));
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("name");
jsonWriter.WriteValue(ravenObj.Value<string>("Name"));
jsonWriter.WritePropertyName("definition");
ravenObj.WriteTo(jsonWriter);
jsonWriter.WriteEndObject();
currentIndexCount++;
ReportProgress("indexes", currentIndexCount, indexes.Count());
}
}
示例15: WriteObjectNestedInConstructor
public void WriteObjectNestedInConstructor()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonTextWriter(sw))
{
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("con");
jsonWriter.WriteStartConstructor("Ext.data.JsonStore");
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("aa");
jsonWriter.WriteValue("aa");
jsonWriter.WriteEndObject();
jsonWriter.WriteEndConstructor();
jsonWriter.WriteEndObject();
}
Assert.AreEqual(@"{""con"":new Ext.data.JsonStore({""aa"":""aa""})}", sb.ToString());
}