本文整理汇总了C#中Context.Store方法的典型用法代码示例。如果您正苦于以下问题:C# Context.Store方法的具体用法?C# Context.Store怎么用?C# Context.Store使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.Store方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLookup
public void TestLookup()
{
var allocationInstruction =
new MessageTemplate(ObjectMother.AllocationInstruction)
{
TypeReference = new QName("AllocationInstruction")
};
var allocations = new Sequence(ObjectMother.Allocations) {TypeReference = new QName("Allocation")};
var context = new Context();
context.Store(DictionaryFields.Type, allocationInstruction, new QName("ID"), String("1234"));
Assert.AreEqual(String("1234"),
context.Lookup(DictionaryFields.Type, allocationInstruction, new QName("ID")));
Assert.AreEqual(ScalarValue.Undefined,
context.Lookup(DictionaryFields.Type, allocations.Group, new QName("ID")));
}
示例2: Encode
public override byte[] Encode(FieldValue fieldValue, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder)
{
var priorValue = context.Lookup(Dictionary, encodeTemplate, Key);
var value_Renamed = (ScalarValue) fieldValue;
if (!operatorCodec.CanEncode(value_Renamed, this))
{
Global.HandleError(Error.FastConstants.D3_CANT_ENCODE_VALUE, "The scalar " + this + " cannot encode the value " + value_Renamed);
}
var valueToEncode = operatorCodec.GetValueToEncode(value_Renamed, priorValue, this, presenceMapBuilder);
if (operator_Renamed.ShouldStoreValue(value_Renamed))
{
context.Store(Dictionary, encodeTemplate, Key, value_Renamed);
}
if (valueToEncode == null)
{
return new byte[0];
}
byte[] encoding = typeCodec.Encode(valueToEncode);
if (context.TraceEnabled && encoding.Length > 0)
{
context.GetEncodeTrace().Field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.Index);
}
return encoding;
}
示例3: Decode
public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader presenceMapReader)
{
try
{
ScalarValue previousValue = null;
if (operator_Renamed.UsesDictionary())
{
previousValue = context.Lookup(Dictionary, decodeTemplate, Key);
ValidateDictionaryTypeAgainstFieldType(previousValue, type);
}
ScalarValue value_Renamed;
int pmapIndex = presenceMapReader.Index;
if (IsPresent(presenceMapReader))
{
if (context.TraceEnabled)
in_Renamed = new RecordingInputStream(in_Renamed);
if (!operatorCodec.ShouldDecodeType())
{
return operatorCodec.DecodeValue(null, null, this);
}
ScalarValue decodedValue = typeCodec.Decode(in_Renamed);
value_Renamed = DecodeValue(decodedValue, previousValue);
if (context.TraceEnabled)
context.DecodeTrace.Field(this, value_Renamed, decodedValue, ((RecordingInputStream) in_Renamed).Buffer, pmapIndex);
}
else
{
value_Renamed = Decode(previousValue);
}
ValidateDecodedValueIsCorrectForType(value_Renamed, type);
if (!((Operator == Template.Operator.Operator.DELTA) && (value_Renamed == null)))
{
context.Store(Dictionary, decodeTemplate, Key, value_Renamed);
}
return value_Renamed;
}
catch (FastException e)
{
throw new FastException("Error occurred while decoding " + this, e.Code, e);
}
}
示例4: Encode
public override byte[] Encode(IFieldValue fieldValue, Group encodeTemplate, Context context,
BitVectorBuilder presenceMapBuilder)
{
IDictionary dict = context.GetDictionary(Dictionary);
ScalarValue priorValue = context.Lookup(dict, encodeTemplate, Key);
var value = (ScalarValue) fieldValue;
if (!_operatorCodec.CanEncode(value, this))
{
Global.ErrorHandler.OnError(null, DynError.CantEncodeValue,
"The scalar {0} cannot encode the value {1}", this, value);
}
ScalarValue valueToEncode = _operatorCodec.GetValueToEncode(value, priorValue, this,
presenceMapBuilder);
if (_operator.ShouldStoreValue(value))
{
context.Store(dict, encodeTemplate, Key, value);
}
if (valueToEncode == null)
{
return ByteUtil.EmptyByteArray;
}
byte[] encoding = _typeCodec.Encode(valueToEncode);
if (context.TraceEnabled && encoding.Length > 0)
{
context.EncodeTrace.Field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.Index);
}
return encoding;
}
示例5: Decode
public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context,
BitVectorReader presenceMapReader)
{
try
{
ScalarValue priorValue = null;
IDictionary dict = null;
QName key = Key;
ScalarValue value;
int pmapIndex = presenceMapReader.Index;
if (IsPresent(presenceMapReader))
{
if (context.TraceEnabled)
inStream = new RecordingInputStream(inStream);
if (!_operatorCodec.ShouldDecodeType)
return _operatorCodec.DecodeValue(null, null, this);
if (_operatorCodec.DecodeNewValueNeedsPrevious)
{
dict = context.GetDictionary(Dictionary);
priorValue = context.Lookup(dict, decodeTemplate, key);
ValidateDictionaryTypeAgainstFieldType(priorValue, _fastType);
}
ScalarValue decodedValue = _typeCodec.Decode(inStream);
value = _operatorCodec.DecodeValue(decodedValue, priorValue, this);
if (context.TraceEnabled)
context.DecodeTrace.Field(this, value, decodedValue,
((RecordingInputStream) inStream).Buffer, pmapIndex);
}
else
{
if (_operatorCodec.DecodeEmptyValueNeedsPrevious)
{
dict = context.GetDictionary(Dictionary);
priorValue = context.Lookup(dict, decodeTemplate, key);
ValidateDictionaryTypeAgainstFieldType(priorValue, _fastType);
}
value = _operatorCodec.DecodeEmptyValue(priorValue, this);
}
ValidateDecodedValueIsCorrectForType(value, _fastType);
#warning TODO: Review if this previous "if" statement is needed.
// if (Operator != Template.Operator.Operator.DELTA || value != null)
if (value != null &&
(_operatorCodec.DecodeNewValueNeedsPrevious || _operatorCodec.DecodeEmptyValueNeedsPrevious))
{
context.Store(dict ?? context.GetDictionary(Dictionary), decodeTemplate, key, value);
}
return value;
}
catch (DynErrorException e)
{
throw new DynErrorException(e, e.Error, "Error occurred while decoding {0}", this);
}
}