예제 #1
0
        //public void ConstructQueryTraceEngine(ADOTabular.AdomdClientWrappers.AdomdType connectionType, string sessionId, List<DaxStudioTraceEventClass> eventsToCapture)
        //{
        //    var stubGlobalOptions =  new StubGlobalOptions();
        //    ConstructQueryTraceEngine(connectionType, sessionId, eventsToCapture, stubGlobalOptions);
        //}

        public void ConstructQueryTraceEngine(AdomdType connectionType, string sessionId, List <DaxStudioTraceEventClass> eventsToCapture, bool filterForCurrentSession, string powerBIFileName)    //, IGlobalOptions globalOptions)
        {
            try
            {
                Log.Debug("{class} {method} {event}", "QueryTraceHub", "ConstructQueryTraceEngine", "Starting");
                string powerPivotConnStr = "";
                using (var xl = new ExcelHelper(Globals.ThisAddIn.Application))
                {
                    powerPivotConnStr = xl.GetPowerPivotConnectionString();
                    // override command type if this is Excel 2013 or later
                    if (xl.IsExcel2013OrLater)
                    {
                        connectionType = AdomdType.Excel;
                        Log.Debug("{class} {method} {event}", "QueryTraceHub", "ConstructQueryTraceEngine", "Constructing QueryTraceEngineExcel");
                        // Anonymouse delegate stops .Net from trying to load MIcrosoft.Excel.Amo.dll when we are running inside Excel 2010
                        VoidDelegate f = delegate
                        {
                            _xlEngine                 = new QueryTraceEngineExcel(powerPivotConnStr, connectionType, sessionId, "", eventsToCapture, filterForCurrentSession);
                            _xlEngine.TraceError     += ((o, e) => { Clients.Caller.OnTraceError(e); });
                            _xlEngine.TraceCompleted += ((o, e) => { OnTraceCompleted(e); });
                            _xlEngine.TraceStarted   += ((o, e) => { Clients.Caller.OnTraceStarted(); });
                        };
                        f();
                        Log.Debug("{class} {method} {event} {status}", "QueryTraceHub", "ConstructQueryTraceEngine", "Constructed QueryTraceEngineExcel", (_xlEngine != null));
                    }
                    else
                    {
                        connectionType = AdomdType.AnalysisServices;
                        Log.Debug("{class} {method} {event}", "QueryTraceHub", "ConstructQueryTraceEngine", "Constructing QueryTraceEngine");
                        _engine                 = new QueryTraceEngine(powerPivotConnStr, connectionType, sessionId, "", "", eventsToCapture, new StubGlobalOptions(), filterForCurrentSession, powerBIFileName);
                        _engine.TraceError     += ((o, e) => { Clients.Caller.OnTraceError(e); });
                        _engine.TraceWarning   += ((o, e) => { Clients.Caller.OnTraceWarning(e); });
                        _engine.TraceCompleted += ((o, e) => { OnTraceCompleted(e); });
                        _engine.TraceStarted   += ((o, e) => { Clients.Caller.OnTraceStarted(); });
                        Log.Debug("{class} {method} {event} {status}", "QueryTraceHub", "ConstructQueryTraceEngine", "Constructed QueryTraceEngine", (_engine != null));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("{class} {method} {exception}", "QueryTraceHub", "ConstructQueryTraceEngine", ex.Message);
                Clients.Caller.OnTraceError(string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
            }
        }
예제 #2
0
        public new void Dispose()
        {
            Log.Debug("{class} {method} {event}", "QueryTraceHub", "Dispose", "enter");
            if (_xlEngine != null)
            {
                Log.Debug("{class} {method} {event}", "QueryTraceHub", "Dispose", "disposing xlEngine");
                // Anonymouse delegate stops .Net from trying to load MIcrosoft.Excel.Amo.dll when we are running inside Excel 2010
                VoidDelegate f = delegate
                {
                    _xlEngine.Dispose();
                    _xlEngine = null;
                };
                f();
            }
            if (_engine != null)
            {
                Log.Debug("{class} {method} {event}", "QueryTraceHub", "Dispose", "disposing engine");

                _engine.Dispose();
                _engine = null;
            }
            Log.Debug("{class} {method} {event}", "QueryTraceHub", "Dispose", "exit");
        }