Exemplo n.º 1
0
        private void Start()
        {
            try
            {
                Log.Verbose("{class} {method} {message}", "QueryTraceEngine", "Start", "entering");
                if (_trace != null)
                {
                    if (_trace.IsStarted || Status == QueryTraceStatus.Starting || Status == QueryTraceStatus.Started)
                    {
                        return; // exit here if trace is already started
                    }
                }
                if (Status != QueryTraceStatus.Started)
                {
                    Status = QueryTraceStatus.Starting;
                }
                Log.Verbose("{class} {method} {event}", "QueryTraceEngine", "Start", "Connecting to: " + _connectionString);
                if (_connection != null)
                {
                    _connection.Dispose();
                }
                ConfigureTrace(_connectionString, _connectionType, _sessionId, _applicationName, _databaseName, _filterForCurrentSession);
                _connection = new ADOTabular.ADOTabularConnection(_connectionString, _connectionType);
                try
                {
                    _connection.Open();
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "{class} {method} {message}", "QueryTraceEngine", "Start (connection.open catch)", ex.Message);
                    // try again?
                    _connection.Open();
                }
                _trace = GetTrace();
                SetupTrace(_trace, Events);

                _trace.OnEvent += OnTraceEventInternal;
                _trace.Start();

                // create timer to "ping" the server with DISCOVER_SESSION requests
                // until the trace events start to fire.
                if (_startingTimer == null)
                {
                    _startingTimer = new Timer();
                }

                _startingTimer.Interval = 500;
                _startingTimer.Elapsed += OnTimerElapsed;
                _startingTimer.Enabled  = true;
                _startingTimer.Start();
                utcPingStart = DateTime.UtcNow;
                // Wait for Trace to become active
                Log.Verbose("{class} {method} {message}", "QueryTraceEngine", "Start", "exiting");
            }
            catch (Exception ex)
            {
                RaiseError(ex);
                //Log.Error("{class} {method} {message}","QueryTraceEngine" , "Start", ex.Message);
            }
        }
Exemplo n.º 2
0
        public void TestVertipaqAnalyzerProfile()
        {
            //var cnnStr = ConnectionString;
            //var cnnStr = @"Data Source=http://localhost:9000/xmla;Workstation ID=C:\Users\c950497\Downloads\RAD Model.xlsx";
            var cnnStr = @"Data Source=localhost:9134;";
            var cnn    = new ADOTabular.ADOTabularConnection(cnnStr, ADOTabular.AdomdClientWrappers.AdomdType.AnalysisServices);

            cnn.Open();
            var db      = cnn.Database;
            var profile = ModelAnalyzer.Create(cnn);



            JsonSerializer serializer = new JsonSerializer();

            //serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            using (StreamWriter sw = new StreamWriter(@"d:\temp\BUSINESS_NBN_CUBE_VertipaqAnalyzerProfile.json"))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, profile);
                    // {"ExpiryDate":new Date(1230375600000),"Price":0}
                }

            cnn.Close();
        }
Exemplo n.º 3
0
        public void TestAdventureWorksProfile()
        {
            var cnn = new ADOTabular.ADOTabularConnection(ConnectionString, ADOTabular.AdomdClientWrappers.AdomdType.AnalysisServices);

            cnn.Open();
            var db      = cnn.Database;
            var profile = DatabaseProfiler.Create(db);

            Assert.AreEqual(db.Name, profile.Name);
            Assert.AreEqual(7, profile.Tables.Count);

            JsonSerializer serializer = new JsonSerializer();

            //serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            using (StreamWriter sw = new StreamWriter(@"c:\temp\profile.json"))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, profile);
                    // {"ExpiryDate":new Date(1230375600000),"Price":0}
                }

            cnn.Close();
        }
Exemplo n.º 4
0
 private void OnTimerElapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         Execute.OnUIThread(() => {
             // lock to prevent multiple threads attempting to open the connection
             lock (connectionLockObj)
             {
                 if (_connection.State != System.Data.ConnectionState.Open)
                 {
                     _connection.Open();
                 }
                 _connection.Ping();
             }
         });
     }
     catch (Exception ex)
     {
         Execute.OnUIThread(() => RaiseError(ex));
         //TODO stop trace and send message to reset UI
     }
     finally
     {
         // if past timeout then exit and display error
         if ((DateTime.UtcNow - utcPingStart).Seconds > 30)
         {
             _startingTimer.Stop();
             DisposeTrace();
             RaiseError("Timeout exceeded attempting to start Trace");
         }
     }
 }
Exemplo n.º 5
0
        public void Start()
        {
            try
            {
                Log.Debug("{class} {method} {event}", "QueryTraceEngine", "Start", "entered");

                if (_trace != null)
                {
                    if (_trace.IsStarted || Status == QueryTraceStatus.Starting || Status == QueryTraceStatus.Started)
                    {
                        Log.Debug("{class} {method} {event}", "QueryTraceEngine", "Start", "exiting method - trace already started");
                        return; // if threturn; // exit here if trace is already startede trace is already running exit here
                    }
                }

                if (Status != QueryTraceStatus.Started)
                {
                    Status = QueryTraceStatus.Starting;
                }
                Log.Debug("{class} {method} {event}", "QueryTraceEngine", "Start", "Connecting to: " + _connectionString);
                //HACK - wait 1.5 seconds to allow trace to start
                //       using the ping method thows a connection was lost error when starting a second trace
                _connection = new ADOTabular.ADOTabularConnection($"{_originalConnectionString};SessionId={_sessionId}", _connectionType);
                _connection.Open();
                _trace = GetTrace();
                SetupTrace(_trace, Events);

                _trace.OnEvent += OnTraceEventInternal;
                _trace.Start();

                // create timer to "ping" the server with DISCOVER_SESSION requests
                // until the trace events start to fire.
                if (_startingTimer == null)
                {
                    _startingTimer = new Timer();
                }
                //HACK - wait 1.5 seconds to allow trace to start
                //       using the ping method thows a connection was lost error when starting a second trace
                _startingTimer.Interval = 300;
                _startingTimer.Elapsed += OnTimerElapsed;
                _startingTimer.Enabled  = true;
                _startingTimer.Start();
                utcPingStart = DateTime.UtcNow;
                // Wait for Trace to become active
                Log.Debug("{class} {method} {event}", "QueryTraceEngine", "Start", "exit");
            }
            catch (Exception ex)
            {
                OutputError($"Error starting trace: {ex.Message}");
                Log.Error("{class} {method} {message} {stacktrace}", "QueryTraceEngine", "Start", ex.Message, ex.StackTrace);
            }
        }
Exemplo n.º 6
0
        private void OnTimerElapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                //Execute.OnUIThread(() => {  // TODO - why did I put this on the UI thread???
                // lock to prevent multiple threads attempting to open the connection
                lock (_connectionLockObj)
                {
                    var policy = Policy
                                 .Handle <Exception>()
                                 .WaitAndRetry(
                        3,
                        retryAttempt => TimeSpan.FromMilliseconds(Math.Pow(2, retryAttempt) * 100),
                        (exception, timeSpan, context) => {
                        Log.Error(exception, "{class} {method}", "QueryTraceEngine", "OnTimerElapsed");
                        System.Diagnostics.Debug.WriteLine("Error pinging trace connection: " + exception.Message);
                        // TODO - should we raise event aggregator
                        RaiseWarning("There was an error while pinging the trace - retrying");
                    }
                        );

                    policy.Execute(() => {
                        if (_connection.State != System.Data.ConnectionState.Open)
                        {
                            _connection.Open();
                        }
                        Debug.WriteLine("Connection.Ping()");
                        _connection.PingTrace();
                        Log.Verbose("{class} {method} {message}", "QueryTraceEngine", "OnTimerElapsed", "Pinging Connection");
                    });
                }

                //});
            }
            catch (Exception ex)
            {
                Execute.OnUIThread(() => RaiseError(ex));
                //TODO stop trace and send message to reset UI
            }
            finally
            {
                // if past timeout then exit and display error
                if ((DateTime.UtcNow - _utcPingStart).Seconds > this.TraceStartTimeoutSecs)
                {
                    _startingTimer.Stop();
                    DisposeTrace();
                    RaiseError("Timeout exceeded attempting to start Trace. You could try increasing this timeout in the Options");
                }
            }
        }
Exemplo n.º 7
0
        //public void Clear()
        //{
        //    _trace.Events.Clear();
        //}
        public void Start()
        {
            if (_trace != null)
                if (_trace.IsStarted || Status == QueryTraceStatus.Starting )
                    return; // if the trace is already running exit here

            if (Status != QueryTraceStatus.Started)  Status = QueryTraceStatus.Starting;
            _connection = new ADOTabular.ADOTabularConnection(_connectionString, _connectionType);
            _connection.Open();
            _trace = GetTrace();
            SetupTrace(_trace, _eventsToCapture);
            _trace.Start();

            // create timer to "ping" the server with DISCOVER_SESSION requests
            // until the trace events start to fire.
            if (_startingTimer == null)
                _startingTimer = new Timer();
            _startingTimer.Interval = 300;  //TODO - make time interval shorter?
            _startingTimer.Elapsed += OnTimerElapsed;
            _startingTimer.Enabled = true;
            _startingTimer.Start();
            utcPingStart = DateTime.UtcNow;
            // Wait for Trace to become active
        }
Exemplo n.º 8
0
        public void Start()
        {
            try
            {
                if (_trace != null)
                    if (_trace.IsStarted || Status == QueryTraceStatus.Starting)
                        return; // exit here if trace is already started

                if (Status != QueryTraceStatus.Started)  Status = QueryTraceStatus.Starting;
                Log.Verbose("{class} {method} {event}", "QueryTraceEngine", "Start", "Connecting to: " + _connectionString);
                _connection = new ADOTabular.ADOTabularConnection(_connectionString, _connectionType);
                _connection.Open();
                _trace = GetTrace();
                SetupTrace(_trace, _eventsToCapture);
                _trace.Start();

                // create timer to "ping" the server with DISCOVER_SESSION requests
                // until the trace events start to fire.
                if (_startingTimer == null)
                    _startingTimer = new Timer();
                _startingTimer.Interval = 300;  //TODO - make time interval shorter?
                _startingTimer.Elapsed += OnTimerElapsed;
                _startingTimer.Enabled = true;
                _startingTimer.Start();
                utcPingStart = DateTime.UtcNow;
                // Wait for Trace to become active
            }
            catch (Exception ex)
            {
                Log.Error("{class} {method} {message}","QueryTraceEngine" , "Start", ex.Message);
            }
        }