Exemplo n.º 1
0
        public static IShellItem CreateItemFromName(string path)
        {
            IShellItem nativeShellItem;
            var        shellItem2Guid = new Guid(IShellItem2Guid);
            var        retCode        = SHCreateItemFromParsingName(Path.GetFullPath(path), IntPtr.Zero, ref shellItem2Guid,
                                                                    out nativeShellItem);

            if (retCode == 0)
            {
                return(nativeShellItem);
            }

            LogEx.For(typeof(Shell32)).Warning("Failed to create IShellItem for {Path} with {HRESULT}", path, retCode);
            return(null);
        }
Exemplo n.º 2
0
        public static async Task <IPersistenceService> Create(string directory)
        {
            try
            {
                var dbFile = new FileInfo(Path.Combine(directory, ".aspect.sqlite"));
                if (!dbFile.Exists)
                {
                    SQLiteConnection.CreateFile(dbFile.FullName);
                    dbFile.Attributes = FileAttributes.NotContentIndexed | FileAttributes.Hidden;
                }

                var connectionString = new SQLiteConnectionStringBuilder
                {
                    DataSource     = dbFile.FullName,
                    DateTimeFormat = SQLiteDateFormats.UnixEpoch,
                    BinaryGUID     = true,
                    DateTimeKind   = DateTimeKind.Utc,
                    ReadOnly       = false
                }.ToString();

                var persistence = new PersistenceService(connectionString);
                var results     = await persistence._Initialize().DontCaptureContext();

                if (!results.Successful)
                {
                    // TODO: handle this more elegantly
                    throw new Exception($"Failed to migrate database: {dbFile.FullName}", results.Error);
                }

                return(persistence);
            }
            catch (Exception ex)
            {
                LogEx.For(typeof(PersistenceService))
                .Error(ex, "Failed to initialize SQLite persistence service.");
                return(new NoOpPersistenceService());
            }
        }
Exemplo n.º 3
0
 private static ILogger Log([CallerMemberName] string memberName = null) =>
 LogEx.For(typeof(ThumbnailService), memberName);