/// <summary>
        /// Create a new <see cref="SqliteFuncEvalQuery"/> instance.
        /// </summary>
        /// <param name="inspectionContext">Context for all function evaluations</param>
        /// <param name="sqliteInstanceName">Property name of a 'sqlite3 *' instance</param>
        /// <param name="query">Query to execute</param>
        /// <returns><see cref="SqliteFuncEvalQuery"/> instance</returns>
        public static async Task <SqliteFuncEvalQuery> CreateAsync(
            DkmInspectionContext inspectionContext,
            string sqliteInstanceName,
            string query)
        {
            // Initialize the query
            return(await Task.Run(() =>
            {
                bool isAlreadyInit;
                DkmComponentManager.InitializeThread(DkmComponentManager.IdeComponentId, out isAlreadyInit);

                try
                {
                    var funcEval = new SqliteFuncEvalQuery(inspectionContext, sqliteInstanceName, query);

                    funcEval.PrepareQuery();
                    int columnCount = funcEval.QueryColumnCount();
                    funcEval.QueryColumnDetails(columnCount);

                    return funcEval;
                }
                finally
                {
                    if (!isAlreadyInit)
                    {
                        DkmComponentManager.UninitializeThread(DkmComponentManager.IdeComponentId);
                    }
                }
            }));
        }
        /// <inheritdoc />
        public void Dispose()
        {
            if (this.isDisposed)
            {
                return;
            }

            bool isAlreadyInit;

            DkmComponentManager.InitializeThread(DkmComponentManager.IdeComponentId, out isAlreadyInit);

            try
            {
                this.FinalizeQuery();

                DkmProcess process = this.inspectionContext.Thread.Process;
                process.FreeVirtualMemory(this.procMemForQuery, 0, MEM_RELEASE);
            }
            finally
            {
                if (!isAlreadyInit)
                {
                    DkmComponentManager.UninitializeThread(DkmComponentManager.IdeComponentId);
                }
            }

            this.isDisposed = true;
        }
        /// <summary>
        /// Execute the query and return rows up to the maximum
        /// </summary>
        /// <param name="maxRows">Maximum number of rows to returns</param>
        /// <param name="token"><see cref="CancellationToken"/> instance</param>
        /// <returns><see cref="IEnumerable{T}"/> of row data</returns>
        public async Task <IEnumerable <string[]> > ExecuteAsync(int maxRows, CancellationToken token)
        {
            if (this.queryComplete)
            {
                return(Enumerable.Empty <string[]>());
            }

            return(await Task.Run(() =>
            {
                bool isAlreadyInit;
                DkmComponentManager.InitializeThread(DkmComponentManager.IdeComponentId, out isAlreadyInit);

                try
                {
                    return this.GetRows(maxRows, token);
                }
                finally
                {
                    if (!isAlreadyInit)
                    {
                        DkmComponentManager.UninitializeThread(DkmComponentManager.IdeComponentId);
                    }
                }
            }));
        }
Esempio n. 4
0
            public ThreadInitializer(Guid id)
            {
                if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                {
                    _alreadyInitialized = true;
                }
                else
                {
                    DkmComponentManager.InitializeThread(id, out _alreadyInitialized);
                }

                _id = id;
            }
Esempio n. 5
0
 /// <summary>
 /// Initializes the <see cref="VSDebugger"/> class.
 /// </summary>
 static VSDebuggerProxy()
 {
     initializationForThread = new System.Threading.ThreadLocal <bool>(() =>
     {
         try
         {
             DkmComponentManager.InitializeThread(DkmComponentManager.IdeComponentId);
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     });
 }
        /// <summary>
        /// Finds a module of given MVID in one of the processes being debugged and returns its baseline metadata.
        /// Shall only be called while in debug mode.
        /// </summary>
        public ModuleMetadata TryGetBaselineMetadata(Guid mvid)
        {
            return(_baselineMetadata.GetOrAdd(mvid, m =>
            {
                DkmComponentManager.InitializeThread(DebuggerService.ComponentId);

                try
                {
                    var clrModuleInstance = FindClrModuleInstance(m);
                    if (clrModuleInstance == null)
                    {
                        return default;
                    }

                    var metadata = GetBaselineModuleMetadata(clrModuleInstance);
                    if (metadata == null)
                    {
                        return default;
                    }

                    // hook up a callback on module unload (the call blocks until the message is processed):
                    DkmCustomMessage.Create(
                        Connection: clrModuleInstance.Process.Connection,
                        Process: clrModuleInstance.Process,
                        SourceId: DebuggerService.MessageSourceId,
                        MessageCode: 0,
                        Parameter1: this,
                        Parameter2: clrModuleInstance).SendLower();

                    return metadata;
                }
                finally
                {
                    DkmComponentManager.UninitializeThread(DebuggerService.ComponentId);
                }
            }));
        }
Esempio n. 7
0
 public ThreadInitializer(Guid id)
 {
     DkmComponentManager.InitializeThread(id, out _alreadyInitialized);
     _id = id;
 }