Esempio n. 1
0
 public void WriteMetadata(LogsharkRunContext run)
 {
     try
     {
         var metadata = new LogsharkRunMetadata(run);
         Log.DebugFormat("Started phase {0}: {1}", run.CurrentPhase, JsonConvert.SerializeObject(metadata));
     }
     catch (Exception ex)
     {
         throw new MetadataWriterException(String.Format("Failed to write Logshark metadata for run '{0}': {1}", run.Id, ex.Message));
     }
 }
        public void WriteMetadata(LogsharkRunContext run)
        {
            try
            {
                var metadata = new LogsharkRunMetadata(run, metadataRecordId);

                using (IDbConnection db = connectionFactory.OpenDbConnection())
                {
                    // Create or migrate metadata db tables.
                    if (!isDatabaseInitialized)
                    {
                        isDatabaseInitialized = InitializeTables(db);
                    }

                    // Update the existing record, if we have one; otherwise, create a new record.
                    if (!metadataRecordId.HasValue)
                    {
                        Log.Debug("Creating metadata record for this Logshark run in database..");
                        db.Insert(metadata);
                        metadataRecordId = Convert.ToInt32(db.GetLastInsertId());
                        metadata.Id      = metadataRecordId.Value;
                    }
                    else
                    {
                        Log.DebugFormat("Updating metadata about the {0} phase of this Logshark run in database..", metadata.CurrentProcessingPhase);
                        db.Update(metadata);
                    }

                    // Explicitly handle writing of data to foreign tables only once, due to limitations of the ORM.
                    if (!isCustomMetadataWritten)
                    {
                        isCustomMetadataWritten = WriteMetadata(metadata.CustomMetadataRecords, db);
                    }
                    if (!isPluginExecutionMetadataWritten)
                    {
                        isPluginExecutionMetadataWritten = WriteMetadata(metadata.PluginExecutionMetadataRecords, db);
                    }
                    if (!isPublishedWorkbookMetadataWritten)
                    {
                        isPublishedWorkbookMetadataWritten = WriteMetadata(metadata.PublishedWorkbookMetadataRecords, db);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new MetadataWriterException(String.Format("Failed to update Logshark metadata for run '{0}' in database: {1}", run.Id, ex.Message));
            }
        }