Beispiel #1
0
 protected override void ProcessRecord()
 {
     // this resolves relative paths and wildcards to a collection of resolved paths
     foreach (PathInfo filePath in this.SessionState.Path.GetResolvedPSPathFromPSPath(mTraceFile))
     {
         TraceFile tf = new TraceFile();
         tf.InitializeAsReader(filePath.ProviderPath);
         while (tf.Read())
         {
             // dynamically build a powershell response object based on
             // the available fields in the trace file.
             PSObject pso = new PSObject();
             for (int i = 0; i < tf.FieldCount; i++)
             {
                 if (!tf.IsNull(i) && tf.GetFieldType(i) == typeof(System.DateTime))
                 {
                     DateTime dt = tf.GetDateTime(i);
                     dt = new DateTime(dt.Ticks, DateTimeKind.Utc);
                     pso.Properties.Add(new PSNoteProperty(tf.GetName(i), dt.ToLocalTime()));
                 }
                 else
                 {
                     pso.Properties.Add(new PSNoteProperty(tf.GetName(i), tf.GetValue(i)));
                 }
             }
             if (!tf.IsNull(tf.GetOrdinal("EventSubclass")) && OutputSSASTraceSubclasses)
             {
                 //pso.Properties.Add(new PSNoteProperty("EventSubClassName",tf.TranslateSubclass((string)tf.GetValue(tf.GetOrdinal("EventClass")),"1" , (int)tf.GetValue(tf.GetOrdinal("EventSubclass")) )));
                 pso.Properties.Add(new PSNoteProperty("EventSubclassName"
                                                       , System.Enum.GetName(typeof(Microsoft.AnalysisServices.TraceEventSubclass), tf.GetValue(tf.GetOrdinal("EventSubclass")))
                                                       ));
             }
             WriteObject(pso);
         }
         tf.Close();
     }
 }
        private void ReadTraceFile(string filename)
        {
            var traceFile = new TraceFile();
            traceFile.InitializeAsReader(filename);

            var eventClassOrdinal = traceFile.GetOrdinal("EventClass");
            var textDataOrdinal = traceFile.GetOrdinal("TextData");
            //var databaseNameOrdinal = traceFile.GetOrdinal("DatabaseName");
            var startTimeOrdinal = traceFile.GetOrdinal("StartTime");
            var durationOrdinal = traceFile.GetOrdinal("Duration");

            while (traceFile.Read())
            {
                var eventClass = traceFile.GetString(eventClassOrdinal);

                // skip on start, end on stop
                if (eventClass.Equals("trace start", StringComparison.InvariantCultureIgnoreCase)) continue;
                if (eventClass.Equals("trace stop", StringComparison.InvariantCultureIgnoreCase)) break;

                var textData = traceFile.GetString(textDataOrdinal);
                //var databaseName = traceFile.GetString(databaseNameOrdinal);
                var startTime = traceFile.GetDateTime(startTimeOrdinal);
                var duration = traceFile.GetInt64(durationOrdinal)/1000; // duration is in microseconds

                // send the canonical query to the agent
                _agentConnect.Store(new Sample
                                        {
                                            //Method = databaseName,
                                            Uri = _parser.Rewrite(textData),
                                            ResponseTime = duration,
                                            Timestamp = startTime.Ticks
                                        }, Logger);
                DebugHelper.LogEntry(_eventLog, string.Format("Data sent: '{0}'", textData), EventLogEntryType.SuccessAudit);
            }

            traceFile.Close();
        }