public object DefineType(IType type) { var line = 0; var offset = 0; var flags = 0; object typeMetadata; if (this.typesMetadataCache.TryGetValue(type, out typeMetadata)) { return(typeMetadata); } if (type.IsPrimitiveType()) { typeMetadata = this.DefinePrimitiveType(type, line, offset, flags); this.typesMetadataCache[type] = typeMetadata; } else { var structureType = new CollectionMetadata(this.indexedMetadata); var reference = this.structuresByName ? (object)type.FullName : (object)structureType; this.typesMetadataCache[type] = reference; this.DefineStructureType(type, line, offset, flags, structureType); typeMetadata = reference; } return(typeMetadata); }
public CollectionResponse(Dictionary<string, List<string>> headers, int status, List<TEntity> data, CollectionMetadata paging, TMeta metadata) : base(headers, status) { this.elements = data; this.paging = paging; this.metadata = metadata; }
public CollectionMetadata DefineMember(IField field, bool create = false, CollectionMetadata structureType = null) { var line = 0; var size = field.FieldType.GetTypeSize(true) * 8; var align = LlvmWriter.PointerSize * 8; var offset = !field.IsStatic ? field.GetFieldOffset() * 8 : 0; // static var flags = field.IsStatic ? 4096 : 0; CollectionMetadata memberMetadata; if (!create && this.typeMembersMetadataCache.TryGetValue(field, out memberMetadata)) { return(memberMetadata); } var fieldMetadata = new CollectionMetadata(this.indexedMetadata); var typeMember = fieldMetadata.Add( string.Format(@"0xd\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}", field.Name, line, size, align, offset, flags), this.file, this.structuresByName || structureType == null ? (object)this.DefineType(field.DeclaringType) : (object)structureType, this.DefineType(field.FieldType)); if (this.structuresByName) { typeMember.Add((object)null); } typeMembersMetadataCache[field] = typeMember; return(typeMember); }
public DebugInfoCompileUnitEntry( DebugInfoGenerator debugInfoGenerator, ISourceFileEntry entry, CollectionMetadata file) { this.debugInfoGenerator = debugInfoGenerator; this.file = file; CollectionMetadata enumTypes; CollectionMetadata retainedTypes; CollectionMetadata subprograms; CollectionMetadata globalVariables; CollectionMetadata importedEntities; this.debugInfoGenerator.DefineCompilationUnit( this.file, out enumTypes, out retainedTypes, out subprograms, out globalVariables, out importedEntities); this.enumTypes = enumTypes; this.retainedTypes = retainedTypes; this.subprograms = subprograms; this.globalVariables = globalVariables; this.importedEntities = importedEntities; }
private void DefineStructureType( IType type, int line, int offset, int flags, CollectionMetadata structureType, CollectionMetadata members) { structureType.Add( string.Format( @"0x13\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}\000", type.Name, line, type.GetTypeSize(this.llvmWriter, true) * 8, LlvmWriter.PointerSize * 8, offset, flags), this.file, null, null, members, null, null, this.structuresByName ? type.FullName : null); if (this.structuresByName) { this.retainedTypes.Add(structureType); } }
// Callback that will handle all exceptions. private void HandleException(object sender, HandleExceptionEventArgs eventArgs) { // Determine if this is the exception thrown due to !FindRoots if ((eventArgs.FirstChance == 1) && (eventArgs.Exception.ExceptionCode == 0xE0444143)) { // Calculate the promoted bytes and determine if it is over the input threshold. // Get the number of server GC heaps. int nHeaps; if (!eventArgs.Debugger.Evaluate("clr!SVR::gc_heap::n_heaps", out nHeaps)) { _EncounteredException = new Exception("Unable to get the number of heaps."); return; } uint promotedBytes = 0; if (nHeaps > 0) { // Server GC for (uint i = 0; i < nHeaps; ++i) { // Calculate the array offset. uint offset = i * 16; // hardcoded in gc as well. uint result; if (!eventArgs.Debugger.Evaluate("clr!SVR::gc_heap::g_promoted", true, offset, out result)) { _EncounteredException = new Exception("Unable to calculate promoted bytes for server GC."); return; } promotedBytes += result; } } else { // Workstation GC if (!eventArgs.Debugger.Evaluate("clr!WKS::gc_heap::g_promoted", false, out promotedBytes)) { _EncounteredException = new Exception("Unable to get promoted bytes for workstation GC."); return; } } _Log.WriteLine("Promoted Bytes: {0}; In MB: {1}", promotedBytes, promotedBytes / 1024 / 1024); // If we've exceeded the promoted bytes threshold, take a process dump. if (promotedBytes > _PromotedBytesThreshold) { // Take a heap snapshot. _CollectionMetadata = _CaptureDump(_PID); _CapturedDump = true; } else { _Log.WriteLine("Skipping GC."); // Execute !FindRoots again. eventArgs.Debugger.Execute("!FindRoots -gen " + _GenerationToTrigger); } } }
private object DefineSubrangeType(int count, object countMember = null) { ////if (countMember != null) ////{ //// count = -1; ////} object subrangeType; if (this.subrangeTypeCache.TryGetValue(count, out subrangeType)) { return(subrangeType); } ////if (countMember == null) ////{ subrangeType = new CollectionMetadata(this.indexedMetadata).Add(string.Format(@"0x21\000\00{0}", count)); this.subrangeTypeCache[count] = subrangeType; ////} ////else ////{ //// // next line should work but not working. //// //subrangeType = new CollectionMetadata(this.indexedMetadata).Add(@"0x21\000", countMember); //// //subrangeType = new CollectionMetadata(this.indexedMetadata).Add(@"0x21", this.DefineExpression(), this.DefineExpression()); ////} return(subrangeType); }
public void TestGetOptions() { CollectionMetadata cmd = DB["reads"].Metadata; Document options = cmd.Options; Assert.IsNotNull(options); }
private void ProcessObject <T>(IEnumerable <T> responseObject, HttpResponseMessage response, bool isIQueryable) where T : class { var metadata = new CollectionMetadata <T>(response); //uncomment this to preserve content negotation, but remember about typecasting for DataContractSerliaizer //var formatter = GlobalConfiguration.Configuration.Formatters.First(t => t.SupportedMediaTypes.Contains(new MediaTypeHeaderValue(response.Content.Headers.ContentType.MediaType))); //response.Content = new ObjectContent<Metadata<T>>(metadata, formatter); response.Content = new ObjectContent <CollectionMetadata <T> >(metadata, GlobalConfiguration.Configuration.Formatters[0]); }
public DebugInfoSourceFileEntry(DebugInfoGenerator debugInfoGenerator, string directory, string fileName) { this.debugInfoGenerator = debugInfoGenerator; this.Directory = directory; this.FileName = fileName; this.file = this.debugInfoGenerator.DefineFile(this); }
public void TestCreateIndexNoNames() { CollectionMetadata cmd = DB["indextests"].Metadata; cmd.CreateIndex(new Document().Add("lname", IndexOrder.Ascending).Add("fname", IndexOrder.Ascending), true); Dictionary <string, Document> indexes = cmd.Indexes; Assert.IsNotNull(indexes["_lname_fname_unique_"]); }
public void TestCreateIndex() { CollectionMetadata cmd = DB["indextests"].Metadata; cmd.CreateIndex("lastnames", new Document().Add("lname", IndexOrder.Ascending), false); Dictionary <string, Document> indexes = cmd.Indexes; Assert.IsNotNull(indexes["lastnames"]); }
public void SequencePoint(int offset, int lineBegin, int colBegin, CollectionMetadata function) { var dbgLine = new CollectionMetadata(this.indexedMetadata).Add(lineBegin, colBegin, function, null); if (dbgLine.Index.HasValue) { this.indexByOffset[offset] = dbgLine.Index.Value; } }
public CollectionMetadata DefineTagExpression() { if (this.tagExpression == null) { this.tagExpression = new CollectionMetadata(this.indexedMetadata).Add("0x102"); } return(this.tagExpression); }
public CollectionResponse <TEntity, TMeta> DecodeResponse(TransportResponse transportResponse) { List <TEntity> elements; CollectionMetadata paging = null; TMeta metadata = null; object output; // Decode elements if (transportResponse.data.TryGetValue("elements", out output)) { try { elements = (output as List <object>) .Select(element => DataUtil.BuildRecord <TEntity>((Dictionary <string, object>)element)) .ToList(); } catch { throw new InvalidCastException("Error decoding elements from TransportResponse."); } } else { throw new KeyNotFoundException("Could not find elements in TransportResponse."); } // Decode paging (optional) if (transportResponse.data.TryGetValue("paging", out output)) { try { paging = DataUtil.BuildRecord <CollectionMetadata>((Dictionary <string, object>)output); } catch { throw new InvalidCastException("Error decoding paging data from TransportResponse."); } } // Decode metadata (optional) if (transportResponse.data.TryGetValue("metadata", out output)) { try { metadata = DataUtil.BuildRecord <TMeta>((Dictionary <string, object>)output); } catch { throw new InvalidCastException("Error decoding metadata from TransportResponse."); } } return(new CollectionResponse <TEntity, TMeta>(transportResponse.responseHeaders, transportResponse.status ?? 200, elements, paging, metadata)); }
public void DefineCompilationUnit( CollectionMetadata file, out CollectionMetadata enumTypes, out CollectionMetadata retainedTypes, out CollectionMetadata subprograms, out CollectionMetadata globalVariables, out CollectionMetadata importedEntities) { if (!this.CompileUnit.IsEmpty) { var first = this.CompileUnit[0] as CollectionMetadata; enumTypes = first[2] as CollectionMetadata; retainedTypes = first[3] as CollectionMetadata; subprograms = first[4] as CollectionMetadata; globalVariables = (first[5] as CollectionMetadata)[0] as CollectionMetadata; importedEntities = first[6] as CollectionMetadata; this.file = file; this.fileType = new CollectionMetadata(this.indexedMetadata).Add("0x29", file); return; } // 4 - C++ // 12 - C // 11 - Java var lang = 12; var compilationUnit = new CollectionMetadata(this.indexedMetadata).Add( string.Format(@"0x11\00{0}\00{1}\000\00\000\00\001", lang, IdentityString), // file file, // Enum Types enumTypes = new CollectionMetadata(this.indexedMetadata), // Retained Types retainedTypes = new CollectionMetadata(this.indexedMetadata), // Subprograms subprograms = new CollectionMetadata(this.indexedMetadata), // Global Variables new CollectionMetadata(this.indexedMetadata).Add( globalVariables = new CollectionMetadata(this.indexedMetadata) { NullIfEmpty = true }), // Imported entities importedEntities = new CollectionMetadata(this.indexedMetadata)); this.globalVariables = globalVariables; this.retainedTypes = retainedTypes; this.file = file; this.fileType = new CollectionMetadata(this.indexedMetadata).Add("0x29", file); this.CompileUnit.Add(compilationUnit); }
public DebugInfoSourceMethodBuilder( DebugInfoGenerator debugInfoGenerator, ISourceMethod method, CollectionMetadata file, CollectionMetadata subprograms) { this.debugInfoGenerator = debugInfoGenerator; CollectionMetadata functionVariables; subprograms.Add(this.function = debugInfoGenerator.DefineMethod(method, file, out functionVariables)); }
public void TestDropIndex() { CollectionMetadata cmd = DB["indextests"].Metadata; cmd.CreateIndex("firstnames", new Document().Add("fname", IndexOrder.Ascending), false); Dictionary <string, Document> indexes = cmd.Indexes; Assert.IsNotNull(indexes["firstnames"]); cmd.DropIndex("firstnames"); Assert.IsFalse(cmd.Indexes.ContainsKey("firstnames")); }
public DebugInfoSourceMethodBuilder(DebugInfoGenerator debugInfoGenerator, ISourceMethod method, CollectionMetadata file, CollectionMetadata subprograms) { this.debugInfoGenerator = debugInfoGenerator; CollectionMetadata subroutineTypes; CollectionMetadata functionVariables; subprograms.Add(this.function = debugInfoGenerator.DefineMethod(method, file, out functionVariables)); this.functionVariables = functionVariables; }
private CollectionMetadata DefineMembers(IType type, CollectionMetadata structureType) { var members = new CollectionMetadata(this.indexedMetadata); foreach (var field in IlReader.Fields(type, this.llvmWriter)) { members.Add(this.DefineMember(field, true, structureType)); } return(members); }
public void TestGetIndexes() { CollectionMetadata cmd = DB["indextests"].Metadata; Dictionary <string, Document> indexes = cmd.Indexes; Assert.IsNotNull(indexes); Assert.IsTrue(indexes.Count > 0, "Should have been at least one index found."); foreach (string key in indexes.Keys) { System.Console.WriteLine(String.Format("Key: {0} Value: {1}", key, indexes[key])); } }
public async Task UpdateAsync(CollectionMetadata collection) { var props = EntitySerializer.Serialize(collection.Properties); using (var cmd = _unitOfWork.CreateDbCommand()) { cmd.CommandText = @"UPDATE CollectionMetadata SET Properties = @Properties WHERE Id = @id"; cmd.AddParameter("Id", collection.Id); cmd.AddParameter("Properties", props); await cmd.ExecuteNonQueryAsync(); } }
public void TestRename() { DB["rename"].Insert(new Document() { { "test", "rename" } }); Assert.AreEqual(1, DB["rename"].Count()); CollectionMetadata cmd = DB["rename"].Metadata; cmd.Rename("renamed"); Assert.IsFalse(DB.GetCollectionNames().Contains(DB.Name + ".rename"), "Shouldn't have found collection"); Assert.IsTrue(DB.GetCollectionNames().Contains(DB.Name + ".renamed"), "Should have found collection"); Assert.AreEqual(1, DB["renamed"].Count()); }
public async Task CreateAsync(CollectionMetadata entity) { var props = EntitySerializer.Serialize(entity.Properties); using (var cmd = _unitOfWork.CreateDbCommand()) { cmd.CommandText = @"INSERT INTO CollectionMetadata (Name, ApplicationId, Properties) VALUES(@Name, @ApplicationId, @Properties)"; cmd.AddParameter("Name", entity.Name); cmd.AddParameter("ApplicationId", entity.ApplicationId); cmd.AddParameter("Properties", props); await cmd.ExecuteNonQueryAsync(); } }
public CollectionMetadata DefineMember( string fieldName, IType fieldType, int offset, IType fieldDeclaringType, bool create = false, CollectionMetadata structureType = null) { return(this.DefineMember( fieldName, fieldType, offset, fieldDeclaringType, create, structureType, this.DefineType(fieldType))); }
public CollectionMetadata DefineMember( string fieldName, IType fieldType, int offset, IType fieldDeclaringType, bool create = false, CollectionMetadata structureType = null, object definedMedataType = null, int count = 1) { var line = 0; var size = fieldType.GetTypeSize(this.llvmWriter, true) * 8 * count; var align = LlvmWriter.PointerSize * 8; // static var flags = 0; var key = string.Concat(fieldType, offset); CollectionMetadata memberMetadata; if (!create && this.typeMembersByOffsetMetadataCache.TryGetValue(key, out memberMetadata)) { return(memberMetadata); } var fieldMetadata = new CollectionMetadata(this.indexedMetadata); var typeMember = fieldMetadata.Add( string.Format(@"0xd\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}", fieldName, line, size, align, offset, flags), this.file, this.structuresByName || structureType == null ? this.FindStructure(fieldDeclaringType) : (object)structureType, definedMedataType); if (this.structuresByName) { typeMember.Add((object)null); } this.typeMembersByOffsetMetadataCache[key] = typeMember; return(typeMember); }
/// <summary> /// Process an event asynchronously. /// </summary> /// <param name="e">event to process</param> /// <returns> /// Task to wait on. /// </returns> public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e) { if (e == null) { throw new ArgumentNullException("e"); } _logger.Debug("doing collections"); var collections = await _repository.GetCollectionsAsync(e.Incident.ApplicationId); foreach (var collectionDto in e.Report.ContextCollections) { var isNew = false; var meta = collections.FirstOrDefault(x => x.Name.Equals(collectionDto.Name, StringComparison.OrdinalIgnoreCase)); if (meta == null) { isNew = true; meta = new CollectionMetadata(e.Incident.ApplicationId, collectionDto.Name); } foreach (var property in collectionDto.Properties) { meta.AddOrUpdateProperty(property.Key); } if (!meta.IsUpdated) { continue; } if (isNew) { await _repository.CreateAsync(meta); } else { await _repository.UpdateAsync(meta); } } _logger.Debug("collections done"); }
public void AddCollectionTest() { //Arrange var name = "My first collection"; var collections = collectionsContext.LoadCollectionMetadata(); var collection = new CollectionMetadata() { Name = name, Created = DateTime.Now }; //Act collections.Add(collection); collectionsContext.SaveCollectionMetadata(collections); //Assert var savedCollection = collectionsContext.LoadCollectionMetadata(); Assert.IsNotNull(savedCollection.SingleOrDefault(c => c.Name == name)); }
// TODO: make it flexible private CollectionMetadata DefineArrayMembers(IType type, CollectionMetadata structureType) { Debug.Assert(type != null && type.IsArray); var members = new CollectionMetadata(this.indexedMetadata); var elementsCount = 10; CollectionMetadata countMember = null; if (!type.IsMultiArray) { var countOffset = type.GetFieldByName("length", this.llvmWriter).GetFieldOffset(this.llvmWriter); countMember = this.DefineMember( "length", this.llvmWriter.System.System_Int32, countOffset * 8, type, true, structureType); members.Add(countMember); } var dataOffset = type.GetFieldByName("data", this.llvmWriter).GetFieldOffset(this.llvmWriter); members.Add( this.DefineMember( "data", type, dataOffset * 8, type, true, structureType, this.DefineCArrayType(type.GetElementType(), 0, 0, elementsCount, countMember), 0)); return(members); }
private void DefineStructureType(IType type, int line, int offset, int flags, CollectionMetadata structureType) { this.DefineStructureType(type, line, offset, flags, structureType, this.DefineMembers(type, structureType)); }
public object DefineType(IType type) { var line = 0; var offset = 0; var flags = 0; object typeMetadata; if (this.typesMetadataCache.TryGetValue(type, out typeMetadata)) { return(typeMetadata); } if (type.IsPrimitiveType()) { typeMetadata = this.DefinePrimitiveType(type, line, offset, flags); this.typesMetadataCache[type] = typeMetadata; } else if (type.IsPointer) { typeMetadata = this.DefinePointerType(type, line, offset); this.typesMetadataCache[type] = typeMetadata; } else if (type.IsByRef) { typeMetadata = this.DefineByRefType(type, line, offset); this.typesMetadataCache[type] = typeMetadata; } else if (type.IsArray) { var structureType = new CollectionMetadata(this.indexedMetadata); var structureOrStructureRef = this.structuresByName ? type.FullName : (object)structureType; var pointer = this.DefinePointerType(structureType, line, offset); this.typeStructuresMetadataCache[type] = structureOrStructureRef; this.typesMetadataCache[type] = pointer; this.DefineStructureType( type, line, offset, flags, structureType, this.DefineArrayMembers(type, structureType)); typeMetadata = pointer; } else { var structureType = new CollectionMetadata(this.indexedMetadata); var structureOrStructureRef = this.structuresByName ? type.FullName : (object)structureType; object pointer = null; if (!type.IsStructureType() && !type.IsEnum) { pointer = this.DefinePointerType(structureType, line, offset); } this.typeStructuresMetadataCache[type] = structureOrStructureRef; this.typesMetadataCache[type] = pointer ?? structureOrStructureRef; this.DefineStructureType(type, line, offset, flags, structureType); typeMetadata = pointer ?? structureOrStructureRef; } return(typeMetadata); }