LINQPad "native" 连接到本地 Windows Search/oledb 数据库

LINQPad "native" connection to local Windows Search/oledb database

我正在尝试使用 LINQPad 连接到我的本地 Windows 搜索索引。我可以使用此处所述的代码手动连接:https://forum.linqpad.net/discussion/2060/connection-to-windows-search:

using (var connection = new OleDbConnection ("Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\""))
{
    connection.Open();
    var cmd = connection.CreateCommand();
    cmd.CommandText = @"SELECT TOP 10 System.ItemPathDisplay, System.ItemUrl FROM SYSTEMINDEX WHERE System.ItemType = '.config'";
    cmd.ExecuteReader().Dump();   // LINQPad lets you Dump a DataReader
}

我希望现在有一种方法可以使用本机 LINQPad 连接来完成此操作。我尝试了一些第三方“LINQ to DB”驱动程序,但没有成功。有人知道怎么做吗?谢谢!

Joe Albahari(LINQPad 创建者)确认没有此驱动程序。这是我想出的,使用 DapperSystem.Data.OleDb nuget 包:

const string defaultActivityQuery = @"SELECT
    System.ActivityHistory.AppId,
    System.ActivityHistory.AppActivityId,
    System.ActivityHistory.StartTime, 
    System.ActivityHistory.EndTime,
    System.ActivityHistory.ActiveDuration,
    System.Activity.AppDisplayName,
    System.Activity.ContentUri,
    System.Activity.Description,
    System.Activity.DisplayText,
    System.Activity.AppImageUri,
    System.Activity.BackgroundColor
FROM SystemIndex
WHERE (System.Activity.ActivityId IS NOT NULL) AND (System.ActivityHistory.StartTime > {0})
ORDER BY System.ActivityHistory.EndTime DESC";

...

var activities = WinSearch(string.Format(defaultActivityQuery, DateTime.Today.AddDays(-1).ToFileTimeUtc()));
...

static List<ActivityRecord> WinSearch(string query)
{
    using OleDbConnection oleDbConnection = new OleDbConnection("Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"");

    var results = oleDbConnection.Query(query);
    return JsonConvert.DeserializeObject<List<ActivityRecord>>(JsonConvert.SerializeObject(results));
}

public class ActivityRecord
{
    [JsonProperty("SYSTEM.ACTIVITYHISTORY.APPID")]
    public string? AppId { get; set; }

    [JsonProperty("SYSTEM.ACTIVITYHISTORY.STARTTIME")]
    public string? StartTimeString
    {
        set => this.StartTime = double.TryParse(value, out double result) ? DateTime.FromFileTimeUtc((long)result).ToLocalTime() : null;
    }

    public DateTime? StartTime { get; private set; }

    [JsonProperty("SYSTEM.ACTIVITYHISTORY.ENDTIME")]
    public string? EndTimeString
    {
        set => this.EndTime = double.TryParse(value, out double result) ? DateTime.FromFileTimeUtc((long)result).ToLocalTime() : null;
    }

    public DateTime? EndTime { get; private set; }

    [JsonProperty("SYSTEM.ACTIVITYHISTORY.ActiveDuration")]
    public string? ActiveDurationString
    {
        set => this.ActiveDuration = double.TryParse(value, out double result) ? TimeSpan.FromTicks((long)result) : null;
    }

    public TimeSpan? ActiveDuration { get; private set; }

    public TimeSpan? Duration => this.EndTime - this.StartTime;

    [JsonProperty("SYSTEM.ACTIVITY.APPDISPLAYNAME")]
    public string? AppDisplayName { get; set; }

    [JsonProperty("SYSTEM.ACTIVITY.ContentUri")]
    public string? ContentUri { get; set; }

    [JsonProperty("SYSTEM.ACTIVITY.DESCRIPTION")]
    public string? Description { get; set; }

    [JsonProperty("SYSTEM.ACTIVITY.DISPLAYTEXT")]
    public string? DisplayText { get; set; }

    [JsonProperty("SYSTEM.ACTIVITYHISTORY.APPACTIVITYID")]
    public string? AppActivityId { get; set; }
}

希望这对其他人有帮助!