-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Expand file tree
/
Copy pathDataSourceManager.cs
More file actions
52 lines (44 loc) · 1.27 KB
/
DataSourceManager.cs
File metadata and controls
52 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices;
using ManagedCommon;
using ManagedCsWin32;
using Microsoft.CmdPal.Ext.Indexer.Indexer.SystemSearch;
namespace Microsoft.CmdPal.Ext.Indexer.Indexer;
internal static class DataSourceManager
{
private static IDBInitialize _dataSource;
public static IDBInitialize GetDataSource()
{
if (_dataSource is null)
{
InitializeDataSource();
}
return _dataSource;
}
private static bool InitializeDataSource()
{
try
{
_dataSource = ComHelper.CreateComInstance<IDBInitialize>(ref Unsafe.AsRef(in CLSID.CollatorDataSource), CLSCTX.InProcServer);
}
catch (Exception ex)
{
Logger.LogError("Failed to create datasource.", ex);
return false;
}
try
{
_dataSource.Initialize();
}
catch (Exception ex)
{
Logger.LogError("Failed to initialize datasource.", ex);
_dataSource = null;
return false;
}
return true;
}
}