/// <summary> /// Удаление из базы данных всех записей, удовлетворяющих указанному критерию /// </summary> /// <param name="maskRecord"></param> /// <param name="compare"></param> public void Delete(Record maskRecord, string compare = "=") { try { Connection.Open(); using (SQLiteCommand command = Connection.CreateCommand()) { string where = String.Join(" AND ", maskRecord.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(maskRecord, null))) .Select(prop => String.Format("{0}{1}@{0}", prop.Name, compare))); command.CommandText = String.IsNullOrWhiteSpace(where) ? String.Format("DELETE FROM {0}", maskRecord.GetType().Name) : String.Format("DELETE FROM {0} WHERE {1}", maskRecord.GetType().Name, where); Debug.WriteLine(command.CommandText); foreach ( PropertyInfo prop in maskRecord.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(maskRecord, null))) ) { command.Parameters.Add(new SQLiteParameter(String.Format("@{0}", prop.Name), prop.GetValue(maskRecord, null))); } command.ExecuteNonQuery(); } } finally { Connection.Close(); } }
public static void Serialize(Stream ms, Record rr) { WriteDomainName(ms, rr.Name); WriteUInt16(ms, (ushort)Enum.Parse(typeof(RecordType), rr.GetType().Name.Substring("Record".Length))); WriteUInt16(ms, (ushort)rr.Class); WriteUInt32(ms, rr.TTL); var n = new MemoryStream(); var type = rr.GetType(); foreach (var field in type.GetFields().Where(x => x.DeclaringType == type)) { var fieldType = field.FieldType; var value = field.GetValue(rr); if (fieldType == typeof(byte)) { ms.WriteByte((byte)value); } else if (fieldType == typeof(ushort)) { WriteUInt16(ms, (ushort)value); } else if (fieldType == typeof(int)) { WriteInt32(ms, (int)value); } else if (fieldType == typeof(uint)) { WriteUInt32(ms, (uint)value); } else if (fieldType == typeof(byte[])) { var array = (byte[])value; ms.Write(array, 0, array.Length); } else if (fieldType == typeof(string)) { if (field.HasAttribute <DomainNameAttribute>()) { WriteDomainName(ms, (string)value); } else { WriteText(ms, (string)value); } } } WriteUInt16(ms, (ushort)n.Length); n.CopyTo(ms); }
public void Method_GetType_ByIndex() { Assert.Throws <FieldMissingException>(() => _1RES_1REC_2FLD.GetType(-1)); Assert.Throws <FieldMissingException>(() => _1RES_1REC_2FLD.GetType(3)); Assert.AreEqual(typeof(int), _1RES_1REC_2FLD.GetType(0)); Assert.AreEqual(typeof(string), _1RES_1REC_2FLD.GetType(1)); }
/// <summary> /// loop through all subrecords of a record /// </summary> /// <param name="record"></param> /// <param name="map"></param> /// <param name="fileMap"></param> private static void GetPathsInRecord( Record record, Dictionary <string, List <string> > map) { var recordDict = new List <string>(); var properties = record .GetType() .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) .OrderBy(x => x.MetadataToken) .ToList(); foreach (var property in properties) { var val = record is not null?property.GetValue(record) : null; if (val is Subrecord subrecord) { GetPathsInSubRecordRecursive(subrecord, recordDict); } } if (recordDict.Count > 0 && record is not null) { var id = record.GetEditorId().TrimEnd('\0'); map.Add(id, recordDict); } }
public virtual object GetValue(string fieldName) { Debug.Assert(!string.IsNullOrWhiteSpace(fieldName)); var result = default(object); var methodName = string.Format("GetValue{0}", fieldName); var methodInfo = GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (methodInfo != null) { result = methodInfo.Invoke(this, null); } else { var propInfo = Record.GetType().GetProperty(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (propInfo != null) { result = propInfo.GetValue(Record); } } return(result); }
public IVAxisAggregate(RecordStream rs, ChartRecordAggregate container, AxisRecord axis) : base(RuleName_IVAXIS, container) { this.axis = axis; if (rs.PeekNextChartSid() == CatSerRangeRecord.sid) { catSerRange = (CatSerRangeRecord)rs.GetNext(); } Debug.Assert(rs.PeekNextChartSid() == AxcExtRecord.sid); axcExt = (AxcExtRecord)rs.GetNext(); if (rs.PeekNextChartSid() == CatLabRecord.sid) { catLab = (CatLabRecord)rs.GetNext(); } axs = new AXSAggregate(rs, this); while (rs.PeekNextChartSid() == CrtMlFrtRecord.sid) { crtmlfrtList.Add(new CrtMlFrtAggregate(rs, this)); } Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); }
public void RecordConstructor_CreatesInstanceOfRecord_Record() { Artist newArtist = new Artist("test"); Record newRecord = new Record("test", newArtist); Assert.AreEqual(typeof(Record), newRecord.GetType()); }
public async Task <List <Keyword> > GetKeywords(Record record) { var keywords = new List <Keyword>(); var tasks = new List <Task <IEnumerable <Keyword> > >(); foreach (var property in record.GetType().GetProperties()) { if (property.PropertyType == typeof(string) && !property.Name.Equals("Diagnosis")) { var value = (string)property.GetValue(record); if (!string.IsNullOrEmpty(value)) { tasks.Add(ProcessProperty(property.Name, value)); } } } var results = await Task.WhenAll(tasks); foreach (var result in results) { keywords.AddRange(result); } keywords.ForEach(k => k.Id = Guid.NewGuid()); return(keywords); }
/** * Finds the index where the sheet validations header record should be inserted * @param records the records for this sheet * * + WINDOW2 * o SCL * o PANE * oo SELECTION * o STANDARDWIDTH * oo MERGEDCELLS * o LABELRANGES * o PHONETICPR * o Conditional Formatting Table * o Hyperlink Table * o Data Validity Table * o SHEETLAYOUT * o SHEETPROTECTION * o RANGEPROTECTION * + EOF */ private static int FindDataValidationTableInsertPos(List <RecordBase> records) { int i = records.Count - 1; if (!(records[i] is EOFRecord)) { throw new InvalidOperationException("Last sheet record should be EOFRecord"); } while (i > 0) { i--; RecordBase rb = records[i]; if (IsDVTPriorRecord(rb)) { Record nextRec = (Record)records[i + 1]; if (!IsDVTSubsequentRecord(nextRec.Sid)) { throw new InvalidOperationException("Unexpected (" + nextRec.GetType().Name + ") found after (" + rb.GetType().Name + ")"); } return(i + 1); } Record rec = (Record)rb; if (!IsDVTSubsequentRecord(rec.Sid)) { throw new InvalidOperationException("Unexpected (" + rec.GetType().Name + ") while looking for DV Table insert pos"); } } return(0); }
public static IEnumerable <SelectListItem> ToComboBoxListItem <T>(this List <T> SourceList, System.Linq.Expressions.Expression <Func <T, object> > DisplayeMember, System.Linq.Expressions.Expression <Func <T, object> > ValueMember, Boolean isListBox, string DefaultValue) { string _valueMember = ""; if (ValueMember.Body is System.Linq.Expressions.UnaryExpression) { var expression = (System.Linq.Expressions.UnaryExpression)ValueMember.Body; _valueMember = ((System.Linq.Expressions.MemberExpression)expression.Operand).Member.Name; } else if (ValueMember.Body is System.Linq.Expressions.MemberExpression) { var expression = (System.Linq.Expressions.MemberExpression)ValueMember.Body; _valueMember = expression.Member.Name; } string _displayMember = ""; if (DisplayeMember.Body is System.Linq.Expressions.UnaryExpression) { var expression = (System.Linq.Expressions.UnaryExpression)DisplayeMember.Body; _displayMember = ((System.Linq.Expressions.MemberExpression)expression.Operand).Member.Name; } else if (DisplayeMember.Body is System.Linq.Expressions.MemberExpression) { var expression = (System.Linq.Expressions.MemberExpression)DisplayeMember.Body; _displayMember = expression.Member.Name; } List <SelectListItem> list = new List <SelectListItem>(); list.Add(new SelectListItem { Value = "0", Text = "انتخاب کنید" }); foreach (var Record in SourceList) { var x = Record.GetType().GetProperty(_valueMember).GetValue(Record, null); var y = Record.GetType().GetProperty(_displayMember).GetValue(Record, null); if (x != null && y != null) { { list.Add(new SelectListItem { Value = Record.GetType().GetProperty(_valueMember).GetValue(Record, null).ToString(), Text = Record.GetType().GetProperty(_displayMember).GetValue(Record, null).ToString(), Selected = (string.IsNullOrEmpty(DefaultValue) ? false : ((Record.GetType().GetProperty(_valueMember).GetValue(Record, null).ToString() == DefaultValue) ? true : false)) }); } } } return(list.AsEnumerable()); }
public static DataTable LINQResultToDataTable <T>(IEnumerable <T> Linqlist) { DataTable dt = new DataTable(); PropertyInfo[] columns = null; if (Linqlist == null) { return(dt); } foreach (T Record in Linqlist) { if (columns == null) { columns = ((Type)Record.GetType()).GetProperties(); foreach (PropertyInfo GetProperty in columns) { Type colType = GetProperty.PropertyType; if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable <>))) { colType = colType.GetGenericArguments()[0]; } dt.Columns.Add(new DataColumn(GetProperty.Name, colType)); } } DataRow dr = dt.NewRow(); foreach (PropertyInfo pinfo in columns) { dr[pinfo.Name] = pinfo.GetValue(Record, null) == null ? DBNull.Value : pinfo.GetValue (Record, null); } dt.Rows.Add(dr); } return(dt); }
public DVAxisAggregate(RecordStream rs, ChartRecordAggregate container, AxisRecord axis) : base(RuleName_DVAXIS, container) { if (axis == null) { this.axis = (AxisRecord)rs.GetNext(); rs.GetNext(); } else { this.axis = axis; } if (rs.PeekNextChartSid() == ValueRangeRecord.sid) { valueRange = (ValueRangeRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == YMultRecord.sid) { axm = new AXMAggregate(rs, this); } axs = new AXSAggregate(rs, this); if (rs.PeekNextChartSid() == CrtMlFrtRecord.sid) { crtmlfrt = new CrtMlFrtAggregate(rs, this); } Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); }
public static void DeleteRecord(Record record) { DataLayer dl = new DataLayer(); String type = record.GetType().ToString(); dl.DeleteRecord(Utilities.ToLong(record.RecordId), type.Substring(type.LastIndexOf(".") + 1, (type.Length - (type.LastIndexOf(".") + 1)))); }
public LDAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_LD, container) { legend = (LegendRecord)rs.GetNext(); rs.GetNext();//BeginRecord pos = (PosRecord)rs.GetNext(); attachedLabel = new AttachedLabelAggregate(rs, this); if (rs.PeekNextChartSid() == FrameRecord.sid) { frame = new FrameAggregate(rs, this); } if (rs.PeekNextChartSid() == CrtLayout12Record.sid) { crtLayout = (CrtLayout12Record)rs.GetNext(); } if (rs.PeekNextChartSid() == TextPropsStreamRecord.sid) { textProps = new TextPropsAggregate(rs, this); } if (rs.PeekNextChartSid() == CrtMlFrtRecord.sid) { crtMlFrt = new CrtMlFrtAggregate(rs, this); } Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); }
public GelFrameAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_GELFRAME, container) { gelFrame1 = (GelFrameRecord)rs.GetNext(); int sid = rs.PeekNextChartSid(); if (sid == GelFrameRecord.sid) { gelFrame2 = (GelFrameRecord)rs.GetNext(); sid = rs.PeekNextChartSid(); } if (sid == ContinueRecord.sid) { while (rs.PeekNextChartSid() == ContinueRecord.sid) { continues.Add((ContinueRecord)rs.GetNext()); } } if (rs.PeekNextChartSid() == BeginRecord.sid) { rs.GetNext(); picF = (PicFRecord)rs.GetNext(); Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); } }
public AxisParentAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_AXISPARENT, container) { axisPraent = (AxisParentRecord)rs.GetNext(); rs.GetNext(); pos = (PosRecord)rs.GetNext(); if (ChartFormatRecord.sid != rs.PeekNextChartSid()) { try { axes = new AxesAggregate(rs, this); } catch { Debug.Print("not find axes rule records"); axes = null; } } Debug.Assert(ChartFormatRecord.sid == rs.PeekNextChartSid()); while (ChartFormatRecord.sid == rs.PeekNextChartSid()) { crtList.Add(new CRTAggregate(rs, this)); } Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); }
public IEnumerable <Record> Load(Record maskRecord, string compare = "=") { var list = new List <Record>(); try { Connection.Open(); using (SQLiteCommand command = Connection.CreateCommand()) { string where = String.Join(" AND ", maskRecord.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(maskRecord, null))) .Select(prop => String.Format("{0}{1}@{0}", prop.Name, compare))); command.CommandText = String.IsNullOrWhiteSpace(where) ? String.Format("SELECT * FROM {0}", maskRecord.GetType().Name) : String.Format("SELECT * FROM {0} WHERE {1}", maskRecord.GetType().Name, where); Debug.WriteLine(command.CommandText); foreach ( PropertyInfo prop in maskRecord.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(maskRecord, null))) ) { command.Parameters.Add(new SQLiteParameter(String.Format("@{0}", prop.Name), prop.GetValue(maskRecord, null))); } SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { object record = Activator.CreateInstance(maskRecord.GetType()); for (int i = 0; i < reader.FieldCount; i++) { record.GetType() .GetProperty(reader.GetName(i)) .SetValue(record, reader[i], null); } list.Add((Record)record); } } } finally { Connection.Close(); } return(list); }
protected override void UpdateInternal() { // Serialize to JSON and save to text file. var json = JsonConvert.SerializeObject(Record, Record.GetType(), _jsonSerializerSettings); var filename = GetFilename(); File.WriteAllText(filename, json); }
public SeriesFormatAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_SERIESFORMAT, container) { series = (SeriesRecord)rs.GetNext(); rs.GetNext(); BRAIRecord ai; SeriesTextRecord sText; while (rs.PeekNextChartSid() == BRAIRecord.sid) { sText = null; ai = (BRAIRecord)rs.GetNext(); if (rs.PeekNextChartSid() == SeriesTextRecord.sid) { sText = (SeriesTextRecord)rs.GetNext(); } dic4AI.Add(ai, sText); } if (rs.PeekNextChartSid() == DataFormatRecord.sid) { while (rs.PeekNextChartSid() == DataFormatRecord.sid) { ssList.Add(new SSAggregate(rs, this)); } } if (rs.PeekNextChartSid() == SerToCrtRecord.sid) { serToCrt = (SerToCrtRecord)rs.GetNext(); } else { if (rs.PeekNextChartSid() == SerParentRecord.sid) { serParent = (SerParentRecord)rs.GetNext(); if (rs.PeekNextChartSid() == SerAuxTrendRecord.sid) { serAuxTrend = (SerAuxTrendRecord)rs.GetNext(); } else { serAuxErrBar = (SerAuxErrBarRecord)rs.GetNext(); } } } if (rs.PeekNextChartSid() == LegendExceptionRecord.sid) { while (rs.PeekNextChartSid() == LegendExceptionRecord.sid) { leList.Add(new LegendExceptionAggregate(rs, this)); } } Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); }
/// <summary> /// Checks that the first record in the list of records is of type <typeparamref name="T"/> and involves the specified state. /// The record is removed after the check. /// </summary> /// <typeparam name="T">Type of the record.</typeparam> /// <param name="state">The state.</param> private void CheckRecord <T>(StateMachine.States state) { Record record = this.records.FirstOrDefault(); Assert.NotNull(record); Assert.True(record.GetType() == typeof(T) && record.State == state, record.Message); this.records.RemoveAt(0); }
/** * @param rs record stream with all {@link SharedFormulaRecord} * {@link ArrayRecord}, {@link TableRecord} {@link MergeCellsRecord} Records removed */ public RowRecordsAggregate(RecordStream rs, SharedValueManager svm) : this(svm) { while (rs.HasNext()) { Record rec = rs.GetNext(); switch (rec.Sid) { case RowRecord.sid: InsertRow((RowRecord)rec); continue; case DConRefRecord.sid: AddUnknownRecord(rec); continue; case HyperlinkRecord.sid: _hyperlinkRecordRecords.Add((HyperlinkRecord)rec); continue; case DBCellRecord.sid: // end of 'Row Block'. Should only occur after cell records // ignore DBCELL records because POI generates them upon re-serialization continue; } if (rec is UnknownRecord) { // might need to keep track of where exactly these belong AddUnknownRecord((UnknownRecord)rec); while (rs.PeekNextSid() == ContinueRecord.sid) { AddUnknownRecord(rs.GetNext()); } continue; } if (rec is MulBlankRecord) { _valuesAgg.AddMultipleBlanks((MulBlankRecord)rec); continue; } if (!(rec is CellValueRecordInterface)) { //TODO: correct it, SeriesIndexRecord will appear in a separate chart sheet that contains a single chart // rule SERIESDATA = Dimensions 3(SIIndex *(Number / BoolErr / Blank / Label)) if (rec.Sid == SeriesIndexRecord.sid) { AddUnknownRecord(rec); continue; } throw new InvalidOperationException("Unexpected record type (" + rec.GetType().Name + ")"); } _valuesAgg.Construct((CellValueRecordInterface)rec, rs, svm); } }
public SSAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_SS, container) { dataFormat = (DataFormatRecord)rs.GetNext(); rs.GetNext(); if (rs.PeekNextChartSid() == Chart3DBarShapeRecord.sid) { chart3DBarShape = (Chart3DBarShapeRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == LineFormatRecord.sid) { lineFormat = (LineFormatRecord)rs.GetNext(); areaFormat = (AreaFormatRecord)rs.GetNext(); pieFormat = (PieFormatRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == SerFmtRecord.sid) { serFmt = (SerFmtRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == GelFrameRecord.sid) { gelFrame = new GelFrameAggregate(rs, this); } if (rs.PeekNextChartSid() == MarkerFormatRecord.sid) { markerFormat = (MarkerFormatRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == AttachedLabelRecord.sid) { attachedLabel = (AttachedLabelRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == ShapePropsStreamRecord.sid) { shapeProps1 = new ShapePropsAggregate(rs, this); } if (rs.PeekNextChartSid() == ShapePropsStreamRecord.sid) { shapeProps2 = new ShapePropsAggregate(rs, this); } if (rs.PeekNextChartSid() == CrtMlFrtRecord.sid) { crtMlFrt = new CrtMlFrtAggregate(rs, this); } Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); }
public DatAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_DAT, container) { dat = (DatRecord)rs.GetNext(); rs.GetNext(); ld = new LDAggregate(rs, this); Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); }
public int InsertOrReplace(Record record) { int insertOrReplace = 0; try { Connection.Open(); using (SQLiteCommand command = Connection.CreateCommand()) { command.CommandText = String.Format("INSERT OR REPLACE INTO {0}({1}) VALUES ({2})", record.GetType().Name, String.Join(",", record.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(record, null))) .Select(prop => prop.Name)), String.Join(",", record.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(record, null))) .Select(prop => "@" + prop.Name))); Debug.WriteLine(command.CommandText); foreach ( PropertyInfo prop in record.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(record, null))) ) { command.Parameters.Add(new SQLiteParameter(String.Format("@{0}", prop.Name), prop.GetValue(record, null))); } insertOrReplace = command.ExecuteNonQuery(); } } finally { Connection.Close(); } return(insertOrReplace); }
public bool ProcessRecord(Record rec) { // System.out.println(rec.toString()); Assert.AreEqual( expectedRecordTypes[recCnt[0]], rec.GetType().Name, "Record type" ); CompareData(rec, "Record " + recCnt + ": "); recCnt[0]++; return(true); }
public RecordTreeNode(Record record) { if (record is ObjRecord) { ObjRecord or = (ObjRecord)record; IList subrecs = or.SubRecords; foreach (SubRecord sr in subrecs) { this.Nodes.Add(new SubRecordTreeNode(sr)); } this.ImageKey = "Folder"; this.SelectedImageKey = "Folder"; } else if (record is SSTRecord) { IEnumerator strings = ((SSTRecord)record).GetStrings(); this.ImageKey = "Folder"; this.SelectedImageKey = "Folder"; while (strings.MoveNext()) { this.Nodes.Add(new UnicodeStringTreeNode((UnicodeString)strings.Current)); } } else if (record is DrawingGroupRecord) { this.ImageKey = "Folder"; this.SelectedImageKey = "Folder"; DrawingGroupRecord dgr = (DrawingGroupRecord)record; for (int i = 0; i < dgr.EscherRecords.Count; i++) { this.Nodes.Add(new EscherRecordTreeNode((NPOI.DDF.EscherRecord)dgr.EscherRecords[i])); } } else { this.ImageKey = "Binary"; } if (record is UnknownRecord) { this.Text = UnknownRecord.GetBiffName(record.Sid) + "*"; } else { this.Text = record.GetType().Name; } this.Record = record; }
public AttachedLabelAggregate(RecordStream rs, ChartRecordAggregate container) : base(RuleName_ATTACHEDLABEL, container) { ChartSheetAggregate cs = GetContainer <ChartSheetAggregate>(ChartRecordAggregate.RuleName_CHARTSHEET); _isFirst = cs.AttachLabelCount == 0; cs.AttachLabelCount++; text = (TextRecord)rs.GetNext(); rs.GetNext();//BeginRecord pos = (PosRecord)rs.GetNext(); if (rs.PeekNextChartSid() == FontXRecord.sid) { fontX = (FontXRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == AlRunsRecord.sid) { alRuns = (AlRunsRecord)rs.GetNext(); } brai = (BRAIRecord)rs.GetNext(); if (rs.PeekNextChartSid() == SeriesTextRecord.sid) { seriesText = (SeriesTextRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == FrameRecord.sid) { frame = new FrameAggregate(rs, this); } if (rs.PeekNextChartSid() == ObjectLinkRecord.sid) { objectLink = (ObjectLinkRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == DataLabExtContentsRecord.sid) { dataLab = (DataLabExtContentsRecord)rs.GetNext(); } if (rs.PeekNextChartSid() == CrtLayout12Record.sid) { crtLayout = (CrtLayout12Record)rs.GetNext(); } if (rs.PeekNextChartSid() == TextPropsStreamRecord.sid) { textProps = new TextPropsAggregate(rs, this); } if (rs.PeekNextChartSid() == CrtMlFrtRecord.sid) { crtMlFrt = new CrtMlFrtAggregate(rs, this); } Record r = rs.GetNext();//EndRecord Debug.Assert(r.GetType() == typeof(EndRecord)); }
/// <summary> /// Проверка существования записей в базе данных с указанным критерием /// </summary> /// <param name="maskRecord">Параметры критерия поиска записей</param> /// <param name="compare"></param> /// <returns></returns> public bool Exists(Record maskRecord, string compare = "=") { bool value = false; try { Connection.Open(); using (SQLiteCommand command = Connection.CreateCommand()) { string where = String.Join(" AND ", maskRecord.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(maskRecord, null))) .Select(prop => String.Format("{0}{1}@{0}", prop.Name, compare))); command.CommandText = String.IsNullOrWhiteSpace(where) ? String.Format("SELECT * FROM {0} LIMIT 1", maskRecord.GetType().Name) : String.Format("SELECT * FROM {0} WHERE {1} LIMIT 1", maskRecord.GetType().Name, where); Debug.WriteLine(command.CommandText); foreach ( PropertyInfo prop in maskRecord.GetType() .GetProperties() .Where(prop => !IsNullOrEmpty(prop.GetValue(maskRecord, null))) ) { command.Parameters.Add(new SQLiteParameter(String.Format("@{0}", prop.Name), prop.GetValue(maskRecord, null))); } SQLiteDataReader reader = command.ExecuteReader(); value = reader.HasRows; } } finally { Connection.Close(); } return(value); }
public void VisitRecord(Record r) { int estimatedSize = r.RecordSize; byte[] buf = new byte[estimatedSize]; int serializedSize = r.Serialize(0, buf); if (estimatedSize != serializedSize) { throw new AssertionException("serialized size mismatch for record (" + r.GetType().Name + ")"); } _totalSize += estimatedSize; }
public object ConvertToExternalType() { var type = System.Type.GetType(string.Format("ManagedDnsQuery.DNS.ExternalConcretes.{0}, {1}", Type, "ManagedDnsQuery")); if (type != null && Record != null) { IEnumerable <object> propVals = Record.GetType() .GetProperties() .Select(prop => prop.GetValue(Record, null)) .ToArray(); return(Activator.CreateInstance(type, new object[] { Name, Type, Class, Ttl, propVals })); } return(null); }
/// <summary> /// Kreira subitem /// </summary> /// <param name="record"></param> /// <param name="cm"></param> /// <param name="position"></param> /// <param name="count"></param> private static void CreateSubItems(Record record, Cm cm, int position, int count) { log.Debug("Mapper:CreateSubItems"); try { PropertyInfo[] props = record.GetType().GetProperties(); for (int i = 0; i < count; i++) { cm.Value.Add(new Cm()); cm.Empty = false; cm.Delimiter = "/"; foreach (PropertyInfo prop in props) { object[] attrs = prop.GetCustomAttributes(true); object[] sorted = attrs.OrderBy(a => ((FieldAttribute)a).Position).ToArray(); foreach (object attr in sorted) { FieldSubtypeAttribute subtypeAttr = attr as FieldSubtypeAttribute; if (subtypeAttr != null) { if (subtypeAttr.Parent.Equals(GetRecordItemName(record, position))) { //TODO: namespace hardkodiran!!! object instance = Activator.CreateInstance(Type.GetType("astm.protocol.record." + subtypeAttr.Type)); ((Cm)cm.Value[i]).Value.Add((Field)instance); } } } } } } catch (Exception ex) { log.Error(ex.ToString()); throw; } }
/// <summary> /// Dohvaca ime itema unutar Record-a /// </summary> /// <param name="record"></param> /// <param name="position"></param> /// <returns></returns> private static string GetRecordItemName(Record record, int position) { log.Debug("Mapper:GetRecordItemName"); try { PropertyInfo[] props = record.GetType().GetProperties(); foreach (PropertyInfo prop in props) { object[] attrs = prop.GetCustomAttributes(true); foreach (object attr in attrs) { FieldAttribute fieldAttr = attr as FieldAttribute; if (fieldAttr != null) { if (fieldAttr as FieldSubtypeAttribute == null) if (fieldAttr.Position == position) return fieldAttr.Name; } } } return null; } catch (Exception ex) { log.Error(ex.ToString()); throw; } }
/// <summary> /// Setira item unutar Record-a /// </summary> /// <param name="record"></param> /// <param name="value"></param> /// <param name="position"></param> private static void SetRecordItem(Record record, string value, int position) { log.Debug("Mapper:SetRecordItem"); try { PropertyInfo[] props = record.GetType().GetProperties(); foreach (PropertyInfo prop in props) { object[] attrs = prop.GetCustomAttributes(true); foreach (object attr in attrs) { FieldAttribute fieldAttr = attr as FieldAttribute; if (fieldAttr != null) { if (fieldAttr as FieldSubtypeAttribute == null) if (fieldAttr.Position == position) { object instance = Activator.CreateInstance(Type.GetType("astm.protocol.record." + fieldAttr.Type)); ((Field)instance).SetValue(value); record.GetType().GetProperty(fieldAttr.Name).SetValue(record, (Field)instance, null); return; } } } } } catch (Exception ex) { log.Error(ex.ToString()); throw; } }