本文整理汇总了C#中ODocument.SetField方法的典型用法代码示例。如果您正苦于以下问题:C# ODocument.SetField方法的具体用法?C# ODocument.SetField怎么用?C# ODocument.SetField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODocument
的用法示例。
在下文中一共展示了ODocument.SetField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldRetrieveRecordMetadata
public void ShouldRetrieveRecordMetadata()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
database
.Create
.Class("TestClass")
.Run();
var document = new ODocument();
document.OClassName = "TestClass";
document.SetField("bar", 12345);
document.SetField("foo", "foo value 345");
var createdDocument = database
.Create
.Document(document)
.Run();
var metadata = database
.Metadata
.ORID(createdDocument.ORID)
.Run();
Assert.IsNotNull(metadata);
Assert.AreEqual(createdDocument.ORID, metadata.ORID);
Assert.AreEqual(createdDocument.OVersion, metadata.OVersion);
}
}
}
示例2: Response
public ODocument Response(Response response)
{
ODocument document = new ODocument();
if (response == null)
{
return document;
}
var reader = response.Reader;
// operation specific fields
byte existByte = reader.ReadByte();
if (existByte == 0)
{
document.SetField("Exists", false);
}
else
{
document.SetField("Exists", true);
}
return document;
}
示例3: Response
public override ODocument Response(Response response)
{
ODocument document = new ODocument();
if (response == null)
{
return document;
}
var reader = response.Reader;
if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
ReadToken(reader);
// operation specific fields
byte existByte = reader.ReadByte();
if (existByte == 0)
{
document.SetField("Exists", false);
}
else
{
document.SetField("Exists", true);
}
return document;
}
示例4: Response
public ODocument Response(Response response)
{
// start from this position since standard fields (status, session ID) has been already parsed
int offset = 5;
ODocument document = new ODocument();
if (response == null)
{
return document;
}
// operation specific fields
byte existByte = BinarySerializer.ToByte(response.Data.Skip(offset).Take(1).ToArray());
offset += 1;
if (existByte == 0)
{
document.SetField("Exists", false);
}
else
{
document.SetField("Exists", true);
}
return document;
}
示例5: Response
public ODocument Response(Response response)
{
// start from this position since standard fields (status, session ID) has been already parsed
int offset = 5;
ODocument document = new ODocument();
if (response == null)
{
return document;
}
// operation specific fields
document.SetField("SessionId", BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray()));
offset += 4;
short clusterCount = BinarySerializer.ToShort(response.Data.Skip(offset).Take(2).ToArray());
document.SetField("ClusterCount", clusterCount);
offset += 2;
if (clusterCount > 0)
{
List<OCluster> clusters = new List<OCluster>();
for (int i = 1; i <= clusterCount; i++)
{
OCluster cluster = new OCluster();
int clusterNameLength = BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray());
offset += 4;
cluster.Name = BinarySerializer.ToString(response.Data.Skip(offset).Take(clusterNameLength).ToArray());
offset += clusterNameLength;
cluster.Id = BinarySerializer.ToShort(response.Data.Skip(offset).Take(2).ToArray());
offset += 2;
int clusterTypeLength = BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray());
offset += 4;
string clusterName = BinarySerializer.ToString(response.Data.Skip(offset).Take(clusterTypeLength).ToArray());
cluster.Type = (OClusterType)Enum.Parse(typeof(OClusterType), clusterName, true);
offset += clusterTypeLength;
cluster.DataSegmentID = BinarySerializer.ToShort(response.Data.Skip(offset).Take(2).ToArray());
offset += 2;
clusters.Add(cluster);
}
document.SetField("Clusters", clusters);
}
int clusterConfigLength = BinarySerializer.ToInt(response.Data.Skip(offset).Take(4).ToArray());
offset += 4;
document.SetField("ClusterConfig", response.Data.Skip(offset).Take(clusterConfigLength).ToArray());
offset += clusterConfigLength;
return document;
}
示例6: ShouldUpdateClassFromDocument
public void ShouldUpdateClassFromDocument()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document = new ODocument();
document.OClassName = "TestClass";
document
.SetField("foo", "foo string value")
.SetField("bar", 12345);
database
.Insert(document)
.Run();
database
.Insert(document)
.Run();
document
.SetField("bar", 54321)
.SetField("baz", "new baz value");
int documentsUpdated = database
.Update(document)
.Run();
Assert.AreEqual(documentsUpdated, 2);
List<ODocument> documents = database
.Select()
.From("TestClass")
.ToList();
Assert.AreEqual(documents.Count, 2);
for (int i = 0; i < documents.Count; i++)
{
Assert.IsTrue(documents[i].ORID != null);
Assert.AreEqual(documents[i].OClassName, document.OClassName);
Assert.AreEqual(documents[i].GetField<string>("foo"), document.GetField<string>("foo"));
Assert.AreEqual(documents[i].GetField<int>("bar"), document.GetField<int>("bar"));
Assert.AreEqual(documents[i].GetField<string>("baz"), document.GetField<string>("baz"));
}
}
}
}
示例7: Response
public override ODocument Response(Response response)
{
ODocument document = new ODocument();
if (response == null)
{
return document;
}
var reader = response.Reader;
if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
ReadToken(reader);
short clusterCount = reader.ReadInt16EndianAware();
document.SetField("ClusterCount", clusterCount);
if (clusterCount > 0)
{
List<OCluster> clusters = new List<OCluster>();
for (int i = 1; i <= clusterCount; i++)
{
OCluster cluster = new OCluster();
int clusterNameLength = reader.ReadInt32EndianAware();
cluster.Name = System.Text.Encoding.Default.GetString(reader.ReadBytes(clusterNameLength));
cluster.Id = reader.ReadInt16EndianAware();
if (OClient.ProtocolVersion < 24)
{
int clusterTypeLength = reader.ReadInt32EndianAware();
string clusterType = System.Text.Encoding.Default.GetString(reader.ReadBytes(clusterTypeLength));
//cluster.Type = (OClusterType)Enum.Parse(typeof(OClusterType), clusterType, true);
if (OClient.ProtocolVersion >= 12)
cluster.DataSegmentID = reader.ReadInt16EndianAware();
else
cluster.DataSegmentID = 0;
}
clusters.Add(cluster);
}
document.SetField("Clusters", clusters);
}
return document;
}
示例8: CreateVertexWithHeavyEdgeTX
public void CreateVertexWithHeavyEdgeTX()
{
var v1 = new ODocument { OClassName = "TestVertex" };
v1.SetField("Name", "First");
v1.SetField("Bar", 1);
var v2 = new ODocument { OClassName = "TestVertex" };
v2.SetField("Name", "Second");
v2.SetField("Bar", 2);
var e1 = new ODocument { OClassName = "TestEdge" };
e1.SetField("Weight", 1.3f);
// Add records to the transaction
_database.Transaction.Add(v1);
_database.Transaction.Add(v2);
_database.Transaction.Add(e1);
// link records
v1.SetField("in_TestEdge", e1.ORID);
v2.SetField("out_TestEdge", e1.ORID);
e1.SetField("in", v1.ORID);
e1.SetField("out", v2.ORID);
_database.Transaction.Commit();
Assert.NotNull(v1.ORID);
Assert.NotNull(v2.ORID);
Assert.NotNull(e1.ORID);
var lv1 = _database.Load.ORID(v1.ORID).Run();
var lv2 = _database.Load.ORID(v2.ORID).Run();
var le1 = _database.Load.ORID(e1.ORID).Run();
Assert.Equal(v1.GetField<string>("Name"), lv1.GetField<string>("Name"));
Assert.Equal(v1.GetField<int>("Bar"), lv1.GetField<int>("Bar"));
Assert.Equal(v2.GetField<string>("Name"), lv2.GetField<string>("Name"));
Assert.Equal(v2.GetField<int>("Bar"), lv2.GetField<int>("Bar"));
Assert.Equal(e1.GetField<float>("Weight"), le1.GetField<float>("Weight"));
Assert.Equal(e1.ORID, lv1.GetField<ORID>("in_TestEdge"));
Assert.Equal(e1.ORID, lv2.GetField<ORID>("out_TestEdge"));
Assert.Equal(v1.ORID, le1.GetField<ORID>("in"));
Assert.Equal(v2.ORID, le1.GetField<ORID>("out"));
}
示例9: Range
public ODocument Range()
{
var document = new ODocument();
foreach (var cluster in _clusterIds)
{
var operation = new DataClusterDataRange(_connection.Database);
operation.ClusterId = cluster.Id;
var d = _connection.ExecuteOperation(operation);
if (!string.IsNullOrEmpty(cluster.Name))
document.SetField<ODocument>(cluster.Name, d.GetField<ODocument>("Content"));
else
document.SetField<ODocument>(cluster.Id.ToString(), d.GetField<ODocument>("Content"));
}
return document;
}
示例10: Response
public override ODocument Response(Response response)
{
ODocument responseDocument = new ODocument();
var reader = response.Reader;
if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
ReadToken(reader);
var createdRecordMapping = new Dictionary<ORID, ORID>();
int recordCount = reader.ReadInt32EndianAware();
for (int i = 0; i < recordCount; i++)
{
var tempORID = ReadORID(reader);
var realORID = ReadORID(reader);
createdRecordMapping.Add(tempORID, realORID);
}
responseDocument.SetField("CreatedRecordMapping", createdRecordMapping);
int updatedCount = reader.ReadInt32EndianAware();
var updateRecordVersions = new Dictionary<ORID, int>();
for (int i = 0; i < updatedCount; i++)
{
var orid = ReadORID(reader);
var newVersion = reader.ReadInt32EndianAware();
updateRecordVersions.Add(orid, newVersion);
}
responseDocument.SetField("UpdatedRecordVersions", updateRecordVersions);
// Work around differents in storage type < version 2.0
if (_database.ProtocolVersion >= 28 || (_database.ProtocolVersion >= 20 && _database.ProtocolVersion <= 27 && !EndOfStream(reader)))
{
int collectionChanges = reader.ReadInt32EndianAware();
if (collectionChanges > 0)
throw new NotSupportedException("Processing of collection changes is not implemented. Failing rather than ignoring potentially significant data");
//for (int i = 0; i < collectionChanges; i++)
//{
// long mBitsOfId = reader.ReadInt64EndianAware();
// long lBitsOfId = reader.ReadInt64EndianAware();
// var updatedFileId = reader.ReadInt64EndianAware();
// var updatedPageIndex = reader.ReadInt64EndianAware();
// var updatedPageOffset = reader.ReadInt32EndianAware();
//}
}
return responseDocument;
}
示例11: ShouldCreateDocumentClassSet
public void ShouldCreateDocumentClassSet()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document = new ODocument();
document.OClassName = "TestClass";
document
.SetField("foo", "foo string value")
.SetField("bar", 12345);
ODocument createdDocument = database
.Create.Document("TestClass")
.Set(document)
.Run();
Assert.NotNull(createdDocument.ORID);
Assert.Equal("TestClass", createdDocument.OClassName);
Assert.Equal(document.GetField<string>("foo"), createdDocument.GetField<string>("foo"));
Assert.Equal(document.GetField<int>("bar"), createdDocument.GetField<int>("bar"));
}
}
}
示例12: RunInternal
private OCommandResult RunInternal()
{
try
{
if (_parameters == null)
throw new ArgumentNullException("_parameters");
var paramsDocument = new ODocument();
paramsDocument.OClassName = "";
paramsDocument.SetField(OClient.ProtocolVersion < 22 ? "params" : "parameters", _parameters);
var serializer = RecordSerializerFactory.GetSerializer(_connection.Database);
CommandPayloadCommand payload = new CommandPayloadCommand();
payload.Text = ToString();
payload.SimpleParams = serializer.Serialize(paramsDocument);
Command operation = new Command(_connection.Database);
operation.OperationMode = OperationMode.Synchronous;
operation.CommandPayload = payload;
ODocument document = _connection.ExecuteOperation(operation);
return new OCommandResult(document);
}
finally
{
_parameters = null;
}
}
示例13: ShouldDeserializeWholeStructure
//[Fact]
public void ShouldDeserializeWholeStructure()
{
/*
The whole record is structured in three main segments
+---------------+------------------+---------------+-------------+
| version:byte | className:string | header:byte[] | data:byte[] |
+---------------+------------------+---------------+-------------+
*/
//byte version = 0;
byte[] className = Encoding.UTF8.GetBytes("TestClass");
byte[] header = new byte[0];
byte[] data = new byte[0];
//string serString = "ABJUZXN0Q2xhc3MpAAAAEQDI/wE=";
string serString1 = "AAxQZXJzb24EaWQAAABEBwhuYW1lAAAAaQcOc3VybmFtZQAAAHAHEGJpcnRoZGF5AAAAdwYQY2hpbGRyZW4AAAB9AQBIZjk1M2VjNmMtNGYyMC00NDlhLWE2ODQtYjQ2ODkxNmU4NmM3DEJpbGx5MQxNYXllczGUlfWVo1IC/wE=";
var document = new ODocument();
document.OClassName = "TestClass";
document.SetField<DateTime>("_date", DateTime.Now);
var createdDocument = database
.Create
.Document(document)
.Run();
Assert.Equal(document.GetField<DateTime>("_date").Date, createdDocument.GetField<DateTime>("eeee"));
var serBytes1 = Convert.FromBase64String(serString1);
var doc = serializer.Deserialize(serBytes1, new ODocument());
}
示例14: Response
public override ODocument Response(Response response)
{
Dictionary<ORID, int> entries = new Dictionary<ORID, int>();
ODocument document = new ODocument();
if (response == null)
{
return document;
}
var reader = response.Reader;
if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
ReadToken(reader);
// (count:int)[(key:binary)(value:binary)]
var bytesLength = reader.ReadInt32EndianAware();
var count = reader.ReadInt32EndianAware();
for (int i = 0; i < count; i++)
{
// key
short clusterId = reader.ReadInt16EndianAware();
long clusterPosition = reader.ReadInt64EndianAware();
var rid = new ORID(clusterId, clusterPosition);
// value
var value = reader.ReadInt32EndianAware();
entries.Add(rid, value);
}
document.SetField<Dictionary<ORID, int>>("entries", entries);
return document;
}
示例15: Response
public override ODocument Response(Response response)
{
ODocument document = new ODocument();
if (response == null)
{
return document;
}
var reader = response.Reader;
if (response.Connection.ProtocolVersion > 26 && response.Connection.UseTokenBasedSession)
ReadToken(reader);
short len = reader.ReadInt16EndianAware();
Dictionary<string, string> configList = new Dictionary<string, string>();
for (int i = 0; i < len; i++)
{
string key = reader.ReadInt32PrefixedString();
string value = reader.ReadInt32PrefixedString();
configList.Add(key, value);
}
document.SetField<Dictionary<string, string>>("config", configList);
return document;
}