public void ShouldWriteArrayForArrayMapping() { var mapping = new ArrayMapping(); writer.VerifyXml(mapping) .RootElement.HasName("array"); }
private openLSE.Model.ECA.PhasorCollection CreateECAPhasorCollection(TypeMapping typeMapping) { Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(mapping => mapping.Field.Identifier); openLSE.Model.ECA.PhasorCollection obj = new openLSE.Model.ECA.PhasorCollection(); { // Create openLSE.Model.ECA.Phasor UDT array for "Phasors" field ArrayMapping arrayMapping = (ArrayMapping)fieldLookup["Phasors"]; PushWindowFrame(arrayMapping); List <openLSE.Model.ECA.Phasor> list = new List <openLSE.Model.ECA.Phasor>(); int count = GetUDTArrayTypeMappingCount(arrayMapping); for (int i = 0; i < count; i++) { TypeMapping nestedMapping = GetUDTArrayTypeMapping(arrayMapping, i); list.Add(CreateECAPhasor(nestedMapping)); } obj.Phasors = list.ToArray(); PopWindowFrame(arrayMapping); } return(obj); }
public ArrayInspector(ArrayMapping mapping) : base(mapping) { this.mapping = mapping; mappedProperties.AutoMap(); mappedProperties.Map(x => x.LazyLoad, x => x.Lazy); }
private TVA_LSETestHarness.Model.ECA._PhasorCollectionMeta FillECA_PhasorCollectionMeta(TypeMapping typeMapping) { Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(mapping => mapping.Field.Identifier); TVA_LSETestHarness.Model.ECA._PhasorCollectionMeta obj = new TVA_LSETestHarness.Model.ECA._PhasorCollectionMeta(); { // Initialize TVA_LSETestHarness.Model.ECA._PhasorMeta UDT array for "Phasors" field ArrayMapping arrayMapping = (ArrayMapping)fieldLookup["Phasors"]; PushWindowFrameTime(arrayMapping); List <TVA_LSETestHarness.Model.ECA._PhasorMeta> list = new List <TVA_LSETestHarness.Model.ECA._PhasorMeta>(); int count = GetUDTArrayTypeMappingCount(arrayMapping); for (int i = 0; i < count; i++) { TypeMapping nestedMapping = GetUDTArrayTypeMapping(arrayMapping, i); list.Add(FillECA_PhasorMeta(nestedMapping)); } obj.Phasors = list.ToArray(); PopWindowFrameTime(arrayMapping); } return(obj); }
private void CollectFromECAPhasorCollection(List <IMeasurement> measurements, TypeMapping typeMapping, TVA_LSETestHarness.Model.ECA.PhasorCollection data, TVA_LSETestHarness.Model.ECA._PhasorCollectionMeta meta) { Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(mapping => mapping.Field.Identifier); { // Convert values from TVA_LSETestHarness.Model.ECA.Phasor UDT array for "Phasors" field to measurements ArrayMapping arrayMapping = (ArrayMapping)fieldLookup["Phasors"]; int dataLength = data.Phasors.Length; int metaLength = meta.Phasors.Length; if (dataLength != metaLength) { throw new InvalidOperationException($"Values array length ({dataLength}) and MetaValues array length ({metaLength}) for field \"Phasors\" must be the same."); } PushWindowFrameTime(arrayMapping); for (int i = 0; i < dataLength; i++) { TypeMapping nestedMapping = GetUDTArrayTypeMapping(arrayMapping, i); CollectFromECAPhasor(measurements, nestedMapping, data.Phasors[i], meta.Phasors[i]); } PopWindowFrameTime(arrayMapping); } }
public void ShouldWriteCacheElement() { var mapping = new ArrayMapping(); mapping.Cache = new CacheMapping(); writer.VerifyXml(mapping) .Element("cache").Exists(); }
public void ShouldWriteRelationshipElement() { var mapping = new ArrayMapping(); mapping.Relationship = new OneToManyMapping(); writer.VerifyXml(mapping) .Element("one-to-many").Exists(); }
public void ShouldWriteIndexElement() { var mapping = new ArrayMapping(); mapping.Index = new IndexMapping(); writer.VerifyXml(mapping) .Element("index").Exists(); }
protected int GetUDTArrayTypeMappingCount(ArrayMapping arrayMapping) { if (arrayMapping.WindowSize != 0.0M) { return(m_cachedFrameTimes.Length); } return(m_cachedMappings.Length); }
public void ShouldWriteElement() { var mapping = new ArrayMapping(); mapping.Element = new ElementMapping(); writer.VerifyXml(mapping) .Element("element").Exists(); }
public override void ProcessArray(ArrayMapping mapping) { var conventions = finder.Find <IArrayConvention>(); Apply <IArrayInspector, IArrayInstance>(conventions, new ArrayInstance(mapping)); ApplyCollectionConventions(mapping); }
public void ShouldNotWriteCollectionTypeWhenEmpty() { var bagMapping = new ArrayMapping { CollectionType = TypeReference.Empty }; writer.VerifyXml(bagMapping) .DoesntHaveAttribute("collection-type"); }
private static TimeSpan GetRetentionTime(ArrayMapping arrayMapping) { decimal amount = arrayMapping.WindowSize; TimeSpan unit = arrayMapping.WindowUnit; decimal sampleAmount = arrayMapping.SampleRate; TimeSpan sampleUnit = arrayMapping.SampleUnit; return(GetRelativeTime(amount, unit, sampleAmount, sampleUnit)); }
/// <summary> /// if mysql return MySqlParameter[] pars /// if sqlerver return SqlParameter[] pars ... /// </summary> /// <param name="parameters"></param> /// <returns></returns> public override IDataParameter[] ToIDbDataParameter(params SugarParameter[] parameters) { if (parameters == null || parameters.Length == 0) { return(null); } KdbndpParameter[] result = new KdbndpParameter[parameters.Length]; int index = 0; foreach (var parameter in parameters) { if (parameter.Value == null) { parameter.Value = DBNull.Value; } var sqlParameter = new KdbndpParameter(); sqlParameter.ParameterName = parameter.ParameterName; sqlParameter.Size = parameter.Size; sqlParameter.Value = parameter.Value; sqlParameter.DbType = parameter.DbType; sqlParameter.Direction = parameter.Direction; if (parameter.IsJson) { sqlParameter.KdbndpDbType = KdbndpDbType.Json; } if (parameter.IsArray) { // sqlParameter.Value = this.Context.Utilities.SerializeObject(sqlParameter.Value); var type = sqlParameter.Value.GetType(); if (ArrayMapping.ContainsKey(type)) { sqlParameter.KdbndpDbType = ArrayMapping[type] | KdbndpDbType.Array; } else { Check.Exception(true, sqlParameter.Value.GetType().Name + " No Support"); } } if (sqlParameter.Direction == 0) { sqlParameter.Direction = ParameterDirection.Input; } result[index] = sqlParameter; if (sqlParameter.Direction.IsIn(ParameterDirection.Output, ParameterDirection.InputOutput, ParameterDirection.ReturnValue)) { if (this.OutputParameters == null) { this.OutputParameters = new List <IDataParameter>(); } this.OutputParameters.RemoveAll(it => it.ParameterName == sqlParameter.ParameterName); this.OutputParameters.Add(sqlParameter); } ++index; } return(result); }
public void ShouldWriteKey() { var mapping = new ArrayMapping { Key = new KeyMapping() }; writer.VerifyXml(mapping) .Element("key").Exists(); }
protected TypeMapping GetUDTArrayTypeMapping(ArrayMapping arrayMapping, int index) { if (arrayMapping.WindowSize != 0.0M) { m_keyIndex = m_lastKeyIndex; CurrentFrameTime = m_cachedFrameTimes[index]; return(m_cachedMapping); } return(m_cachedMappings[index]); }
protected int GetArrayMeasurementCount(ArrayMapping arrayMapping) { MeasurementKey[] keys = m_keys[m_keyIndex++]; if (arrayMapping.WindowSize != 0.0M) { AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); return(sampleWindow.GetTimestamps(m_currentFrameTime).Count); } return(keys.Length); }
private bool WriteEnumAndArrayTypes(StructMapping structMapping, object o, string n, string ns, XmlMapping parentMapping) { if (o is Enum) { Writer.WriteStartElement(n, ns); EnumMapping enumMapping = null; Type enumType = o.GetType(); foreach (var m in parentMapping.Scope.TypeMappings) { var em = m as EnumMapping; if (em != null && em.TypeDesc.Type == enumType) { enumMapping = em; break; } } Debug.Assert(enumMapping != null); WriteXsiType(enumMapping.TypeName, ns); Writer.WriteString(WriteEnumMethod(enumMapping, o)); Writer.WriteEndElement(); return(true); } if (o is Array) { Debug.Assert(parentMapping != null); Writer.WriteStartElement(n, ns); ArrayMapping arrayMapping = null; Type arrayType = o.GetType(); foreach (var m in parentMapping.Scope.TypeMappings) { var am = m as ArrayMapping; if (am != null && am.TypeDesc.Type == arrayType) { arrayMapping = am; break; } } Debug.Assert(arrayMapping != null); WriteXsiType(arrayMapping.TypeName, ns); WriteMember(o, null, arrayMapping.ElementsSortedByDerivation, null, null, arrayMapping.TypeDesc, true); Writer.WriteEndElement(); return(true); } return(false); }
protected int GetArrayMeasurementCount(ArrayMapping arrayMapping) { Lazy <bool> isNanType = new Lazy <bool>(() => { DataType underlyingType = (arrayMapping.Field.Type as ArrayType)?.UnderlyingType; return(!s_nonNanTypes.Contains($"{underlyingType?.Category}.{underlyingType?.Identifier}")); }); // Set OverRangeError flag if the value of the measurement is NaN and the // destination field's type does not support NaN; this will set the UnreasonableValue // flag in the ECA MeasurementFlags of the MetaValues structure Func <IMeasurement, IMeasurement> toNotNan = measurement => new Measurement() { Metadata = measurement.Metadata, Timestamp = measurement.Timestamp, Value = 0.0D, StateFlags = measurement.StateFlags | MeasurementStateFlags.OverRangeError }; if (arrayMapping.WindowSize != 0.0M) { // native[] where each array element is the same mapping, but represent different times AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_cachedMeasurements = AlignmentCoordinator .GetMeasurements(m_keys[m_keyIndex++].Single(), CurrentFrameTime, sampleWindow) .Select(measurement => (!IsNaNOrInfinity(measurement.Value) || isNanType.Value) ? measurement : toNotNan(measurement)) .ToArray(); } else if (arrayMapping.RelativeTime != 0.0M) { // native[] where each array element is the same time (relative to now), but represent different mappings AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_cachedMeasurements = m_keys[m_keyIndex++] .Select(key => AlignmentCoordinator.GetMeasurement(key, CurrentFrameTime, sampleWindow)) .Select(measurement => (!IsNaNOrInfinity(measurement.Value) || isNanType.Value) ? measurement : toNotNan(measurement)) .ToArray(); } else { // native[] where each array element is the same time, but represent different mappings m_cachedMeasurements = SignalLookup.GetMeasurements(m_keys[m_keyIndex++]) .Select(measurement => (!IsNaNOrInfinity(measurement.Value) || isNanType.Value) ? measurement : toNotNan(measurement)) .ToArray(); } return(m_cachedMeasurements.Length); }
private static bool IsNeedNullableMember(ElementAccessor element) { if (element.Mapping is ArrayMapping) { ArrayMapping arrayMapping = (ArrayMapping)element.Mapping; if (arrayMapping.Elements != null && arrayMapping.Elements.Length == 1) { return(IsNeedNullableMember(arrayMapping.Elements[0])); } return(false); } else { return(element.IsNullable && element.Mapping.TypeDesc.IsValueType); } }
private void ParseWindowExpression(ArrayMapping arrayMapping) { string identifier; // Read the next token as an identifier identifier = ParseIdentifier(); arrayMapping.TimeWindowExpression = identifier; SkipWhitespace(); if (identifier.Equals("last", StringComparison.OrdinalIgnoreCase)) { // The "last" keyword is followed by a // timespan and an optional sample rate ParseTimeSpan(arrayMapping); arrayMapping.RelativeTime = arrayMapping.WindowSize; arrayMapping.RelativeUnit = arrayMapping.WindowUnit; } else if (identifier.Equals("from", StringComparison.OrdinalIgnoreCase)) { // The from keyword is followed by // a relative time and a time span ParseRelativeTime(arrayMapping); SkipWhitespace(); // Read the next token as an identifier identifier = ParseIdentifier(); arrayMapping.TimeWindowExpression += " " + identifier; SkipWhitespace(); // The "for" keyword is expected to exist // between the relative time and the time span if (identifier != "for") { RaiseCompileError($"Unexpected identifier: {identifier}. Expected 'for' keyword."); } // Parse the time span ParseTimeSpan(arrayMapping); } else { // If the "last" and "from" keywords are not specified, raise an error RaiseCompileError($"Unexpected identifier: {identifier}. Expected 'last' keyword or 'from' keyword."); } }
private void Write(TextWriter writer, TypeMapping typeMapping) { writer.WriteLine($"{typeMapping.Type.Category} {typeMapping.Type.Identifier} {typeMapping.Identifier} {{"); foreach (FieldMapping fieldMapping in typeMapping.FieldMappings) { ArrayMapping arrayMapping = fieldMapping as ArrayMapping; string expression = fieldMapping.Expression.Any(char.IsWhiteSpace) ? $"{{ {fieldMapping.Expression} }}" : fieldMapping.Expression; string fieldMappingText; if ((object)arrayMapping == null) { fieldMappingText = $" {fieldMapping.Field.Identifier}: {expression} {ToRelativeTimeText(fieldMapping)}"; } else if (arrayMapping.WindowSize == 0.0M) { fieldMappingText = $" {fieldMapping.Field.Identifier}: {{ {fieldMapping.Expression} }} {ToRelativeTimeText(fieldMapping)}"; } else if (fieldMapping.RelativeTime == 0.0M) { fieldMappingText = $" {fieldMapping.Field.Identifier}: {expression} last {ToTimeSpanText(arrayMapping)}"; } else if (fieldMapping.RelativeTime != arrayMapping.WindowSize || fieldMapping.RelativeUnit != arrayMapping.WindowUnit) { fieldMappingText = $" {fieldMapping.Field.Identifier}: {expression} from {ToRelativeTimeText(fieldMapping)} for {ToTimeSpanText(arrayMapping)}"; } else { fieldMappingText = $" {fieldMapping.Field.Identifier}: {expression} last {ToTimeSpanText(arrayMapping)}"; } if (fieldMapping.SampleRate != 0.0M) { writer.WriteLine($"{fieldMappingText} {ToSampleRateText(fieldMapping)}"); } else { writer.WriteLine(fieldMappingText); } } writer.WriteLine("}"); writer.WriteLine(); }
private ArrayMapping ParseArrayMappingMapping() { ArrayMapping arrayMapping = new ArrayMapping(); if (m_endOfFile) { RaiseCompileError("Unexpected end of file. Expected '{' or identifier."); } if (m_currentChar == '{') { arrayMapping.Expression = ReadToClosingBrace().Trim(); } else { arrayMapping.Expression = ParseIdentifier(); } SkipToNewline(); if (m_endOfFile) { RaiseCompileError("Unexpected end of file. Expected 'last' keyword, 'from' keyword, number, or newline."); } if (char.IsDigit(m_currentChar)) { ParseRelativeTime(arrayMapping); } else if (m_currentChar != '\n') { ParseWindowExpression(arrayMapping); } SkipToNewline(); if (!m_endOfFile && m_currentChar == '@') { ParseSampleRate(arrayMapping); } return(arrayMapping); }
private ArrayMapping ImportArrayLikeMapping(ArrayModel model, RecursionLimiter limiter) { ArrayMapping mapping = new ArrayMapping(); mapping.IsSoap = true; TypeMapping itemTypeMapping = ImportTypeMapping(model.Element, limiter); if (itemTypeMapping.TypeDesc.IsValueType && !itemTypeMapping.TypeDesc.IsPrimitive && !itemTypeMapping.TypeDesc.IsEnum) { throw new NotSupportedException(SR.Format(SR.XmlRpcArrayOfValueTypes, model.TypeDesc.FullName)); } mapping.TypeDesc = model.TypeDesc; mapping.Elements = new ElementAccessor[] { CreateElementAccessor(itemTypeMapping, mapping.Namespace) }; SetArrayMappingType(mapping); // in the case of an ArrayMapping we can have more that one mapping correspond to a type // examples of that are ArrayList and object[] both will map tp ArrayOfur-type // so we create a link list for all mappings of the same XSD type ArrayMapping existingMapping = (ArrayMapping)_types[mapping.TypeName, mapping.Namespace]; if (existingMapping != null) { ArrayMapping first = existingMapping; while (existingMapping != null) { if (existingMapping.TypeDesc == model.TypeDesc) { return(existingMapping); } existingMapping = existingMapping.Next; } mapping.Next = first; _types[mapping.TypeName, mapping.Namespace] = mapping; return(mapping); } _typeScope.AddTypeMapping(mapping); _types.Add(mapping.TypeName, mapping.Namespace, mapping); IncludeTypes(model.Type); return(mapping); }
protected void PushWindowFrameTime(ArrayMapping arrayMapping) { if (arrayMapping.WindowSize != 0.0M) { AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_lastKeyIndex = m_keyIndex; m_cachedFrameTime = CurrentFrameTime; m_cachedFrameTimes = sampleWindow.GetTimestamps(m_currentFrameTime).ToArray(); m_cachedMapping = GetTypeMapping(arrayMapping); } else if (arrayMapping.RelativeTime != 0.0M) { m_cachedFrameTime = CurrentFrameTime; CurrentFrameTime = GetRelativeFrameTime(arrayMapping); m_cachedMappings = m_mappingCompiler.EnumerateTypeMappings(arrayMapping.Expression).ToArray(); } else { m_cachedMappings = m_mappingCompiler.EnumerateTypeMappings(arrayMapping.Expression).ToArray(); } }
private string ToTimeSpanText(ArrayMapping arrayMapping) { decimal windowSize = arrayMapping.WindowSize; TimeSpan windowUnit = arrayMapping.WindowUnit; if (windowSize == 0.0M) { return(string.Empty); } if (windowUnit != TimeSpan.Zero) { return((windowSize != 1.0M) ? $"{windowSize} {ToUnitText(windowUnit)}s" : $"{windowSize} {ToUnitText(windowUnit)}"); } return((windowSize != 1.0M) ? $"{windowSize} points" : $"{windowSize} point"); }
private StatusWords CreateECAStatusWords(TypeMapping typeMapping) { Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(mapping => mapping.Field.Identifier); StatusWords obj = new StatusWords(); { // Create double array for "Values" field ArrayMapping arrayMapping = (ArrayMapping)fieldLookup["Values"]; List <double> list = new List <double>(); int count = GetArrayMeasurementCount(arrayMapping); for (int i = 0; i < count; i++) { IMeasurement measurement = GetArrayMeasurement(i); list.Add((double)measurement.Value); } obj.Values = list.ToArray(); } return(obj); }
private _StatusWordsMeta CreateECA_StatusWordsMeta(TypeMapping typeMapping) { Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(mapping => mapping.Field.Identifier); _StatusWordsMeta obj = new _StatusWordsMeta(); { // Create MetaValues array for "Values" field ArrayMapping arrayMapping = (ArrayMapping)fieldLookup["Values"]; List <MetaValues> list = new List <MetaValues>(); int count = GetArrayMeasurementCount(arrayMapping); for (int i = 0; i < count; i++) { IMeasurement measurement = GetArrayMeasurement(i); list.Add(GetMetaValues(measurement)); } obj.Values = list.ToArray(); } return(obj); }
protected void PushWindowFrame(ArrayMapping arrayMapping) { if (arrayMapping.WindowSize != 0.0M) { // UDT[] where each array element is the same mapping, but represent different times m_cachedFrame = CurrentFrame; m_lastKeyIndex = m_keyIndex; m_lastMappingCollectionIndex = m_mappingCollectionIndex; m_cachedMapping = GetTypeMapping(arrayMapping); m_cachedFrames = GetWindowFrames(arrayMapping); } else if (arrayMapping.RelativeTime != 0.0M) { // UDT[] where each array element is the same time (relative to now), but represent different mappings m_cachedFrame = CurrentFrame; CurrentFrame = GetRelativeFrame(arrayMapping); m_cachedMappings = m_mappingCollections[m_mappingCollectionIndex++]; } else { // UDT[] where each array element is the same time, but represent different mappings m_cachedMappings = m_mappingCollections[m_mappingCollectionIndex++]; } }
private void BuildMappingCollections(TypeMapping inputMapping) { foreach (FieldMapping fieldMapping in inputMapping.FieldMappings) { ArrayMapping arrayMapping = fieldMapping as ArrayMapping; DataType fieldType = fieldMapping.Field.Type; DataType underlyingType = (fieldType as ArrayType)?.UnderlyingType; // ReSharper disable once PossibleNullReferenceException if (fieldType.IsArray && underlyingType.IsUserDefined && arrayMapping.WindowSize == 0.0M) { m_mappingCollections.Add(MappingCompiler.EnumerateTypeMappings(arrayMapping.Expression).ToArray()); } if (fieldType.IsArray && underlyingType.IsUserDefined) { m_mappingCompiler.EnumerateTypeMappings(fieldMapping.Expression).ToList().ForEach(BuildMappingCollections); } else if (fieldType.IsUserDefined) { BuildMappingCollections(m_mappingCompiler.GetTypeMapping(fieldMapping.Expression)); } } }
protected int GetArrayMeasurementCount(ArrayMapping arrayMapping) { if (arrayMapping.WindowSize != 0.0M) { // native[] where each array element is the same mapping, but represent different times AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_cachedMeasurements = AlignmentCoordinator.GetMeasurements(Keys[m_keyIndex++].Single(), CurrentFrameTime, sampleWindow).ToArray(); } else if (arrayMapping.RelativeTime != 0.0M) { // native[] where each array element is the same time (relative to now), but represent different mappings AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_cachedMeasurements = Keys[m_keyIndex++].Select(key => AlignmentCoordinator.GetMeasurement(key, CurrentFrameTime, sampleWindow)).ToArray(); } else { // native[] where each array element is the same time, but represent different mappings m_cachedMeasurements = SignalLookup.GetMeasurements(Keys[m_keyIndex++]); } return(m_cachedMeasurements.Length); }
private openLSE.Model.ECA._DigitalsMeta CreateECA_DigitalsMeta(TypeMapping typeMapping) { Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(mapping => mapping.Field.Identifier); openLSE.Model.ECA._DigitalsMeta obj = new openLSE.Model.ECA._DigitalsMeta(); { // Create MetaValues array for "Values" field ArrayMapping arrayMapping = (ArrayMapping)fieldLookup["Values"]; List <MetaValues> list = new List <MetaValues>(); int count = GetArrayMeasurementCount(arrayMapping); for (int i = 0; i < count; i++) { IMeasurement measurement = GetArrayMeasurement(i); list.Add(GetMetaValuesWithNormalFlag(measurement)); } obj.Values = list.ToArray(); } return(obj); }
public void MutableShouldBeTrueByDefaultOnArrayMapping() { var mapping = new ArrayMapping(); mapping.Mutable.ShouldBeTrue(); }
public virtual void ProcessArray(ArrayMapping mapping) { }
public virtual void Visit(ArrayMapping mapping) { }
public void CreateDsl() { mapping = new ArrayMapping(); inspector = new ArrayInspector(mapping); }