当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteConnection.CreateCatalogTableIfNotExists方法代码示例

本文整理汇总了C#中SQLite.SQLiteConnection.CreateCatalogTableIfNotExists方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.CreateCatalogTableIfNotExists方法的具体用法?C# SQLiteConnection.CreateCatalogTableIfNotExists怎么用?C# SQLiteConnection.CreateCatalogTableIfNotExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQLite.SQLiteConnection的用法示例。


在下文中一共展示了SQLiteConnection.CreateCatalogTableIfNotExists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateCatalogDatabaseAndInsertEntries

        internal void CreateCatalogDatabaseAndInsertEntries(string dbFilename, Uri registryUrl, string registryCacheDirectory) {
            Directory.CreateDirectory(Path.GetDirectoryName(dbFilename));

            using (var db = new SQLiteConnection(dbFilename)) {
                // prevent errors from occurring when table doesn't exist
                db.RunInTransaction(() => {
                    db.CreateCatalogTableIfNotExists();
                    db.InsertOrReplace(new DbVersion() {
                        Id = _databaseSchemaVersion
                    });
                    db.InsertOrReplace(new RegistryFileMapping() {
                        RegistryUrl = registryUrl.ToString(),
                        DbFileLocation = registryCacheDirectory
                    });
                });
            }
        }
开发者ID:nareshjo,项目名称:nodejstools,代码行数:17,代码来源:NpmGetCatalogCommand.cs

示例2: ExecuteAsync

        public override async Task<bool> ExecuteAsync() {
            var dbFilename = DatabaseCacheFilePath;
            bool catalogUpdated = false;
            string filename = null;
            string registryCacheDirectory = null;
            string registryCachePath = null;
            string registryCacheFilePath = null;

            // Use a semaphore instead of a mutex because await may return to a thread other than the calling thread.
            using (var semaphore = GetDatabaseSemaphore()) {
                // Wait until file is downloaded/parsed if another download is already in session.
                // Allows user to open multiple npm windows and show progress bar without file-in-use errors.
                bool success = await Task.Run(() => semaphore.WaitOne(TimeSpan.FromMinutes(5)));
                if (!success) {
                    // Return immediately so that the user can explicitly decide to refresh on failure.
                    return false;
                }

                Uri registryUrl = await GetRegistryUrl();
                OnOutputLogged(string.Format(Resources.InfoRegistryUrl, registryUrl));

                try {
                    DbVersion version = null;
                    RegistryInfo registryInfo = null;
                    RegistryFileMapping registryFileMapping = null;

                    Directory.CreateDirectory(Path.GetDirectoryName(dbFilename));

                    using (var db = new SQLiteConnection(dbFilename)) {
                        // prevent errors from occurring when table doesn't exist
                        db.CreateCatalogTableIfNotExists();
                        version = db.Table<DbVersion>().FirstOrDefault();
                        registryFileMapping = db.Table<RegistryFileMapping>().FirstOrDefault(info => info.RegistryUrl == registryUrl.ToString());
                    }

                    registryCacheDirectory = registryFileMapping != null ? registryFileMapping.DbFileLocation : Guid.NewGuid().ToString();
                    registryCachePath = Path.Combine(CachePath, registryCacheDirectory);
                    registryCacheFilePath = Path.Combine(registryCachePath, RegistryCacheFilename);

                    Directory.CreateDirectory(Path.GetDirectoryName(registryCacheFilePath));

                    if (File.Exists(registryCacheFilePath)) {
                        using (var registryDb = new SQLiteConnection(registryCacheFilePath)) {
                            // prevent errors from occurring when table doesn't exist
                            registryDb.CreateRegistryTableIfNotExists();
                            registryInfo = registryDb.Table<RegistryInfo>().FirstOrDefault();
                        }
                    }

                    bool correctDatabaseSchema = version != null && version.Id == _databaseSchemaVersion;
                    bool incrementalUpdate = correctDatabaseSchema && _forceDownload && registryInfo != null && registryInfo.Revision > 0;
                    bool fullUpdate = correctDatabaseSchema && (registryInfo == null || registryInfo.Revision <= 0);

                    if (!correctDatabaseSchema) {
                        OnOutputLogged(Resources.InfoCatalogUpgrade);
                        SafeDeleteFolder(CachePath);

                        CreateCatalogDatabaseAndInsertEntries(dbFilename, registryUrl, registryCacheDirectory);

                        filename = await UpdatePackageCache(registryUrl, CachePath);
                        catalogUpdated = true;
                    } else if (incrementalUpdate) {
                        filename = await UpdatePackageCache(registryUrl, registryCachePath, registryInfo.Revision);
                        catalogUpdated = true;
                    } else if (fullUpdate) {
                        CreateCatalogDatabaseAndInsertEntries(dbFilename, registryUrl, registryCacheDirectory);

                        filename = await UpdatePackageCache(registryUrl, registryCachePath);
                        catalogUpdated = true;
                    }

                    if (catalogUpdated) {
                        var fileInfo = new FileInfo(filename);
                        OnOutputLogged(String.Format(Resources.InfoReadingBytesFromPackageCache, fileInfo.Length, filename, fileInfo.LastWriteTime));

                        using (var reader = new StreamReader(filename)) {
                            await Task.Run(() => ParseResultsAndAddToDatabase(reader, registryCacheFilePath, registryUrl.ToString()));
                        }
                    }

                    using (var db = new SQLiteConnection(registryCacheFilePath)) {
                        db.CreateRegistryTableIfNotExists();
                        ResultsCount = db.Table<CatalogEntry>().Count();
                    }
                } catch (Exception ex) {
                    if (ex is StackOverflowException ||
                        ex is OutOfMemoryException ||
                        ex is ThreadAbortException ||
                        ex is AccessViolationException) {
                        throw;
                    }
                    // assume the results are corrupted
                    OnOutputLogged(ex.ToString());
                    throw;
                } finally {
                    if (ResultsCount == null) {
                        OnOutputLogged(string.Format(Resources.DownloadOrParsingFailed, CachePath));
                        SafeDeleteFolder(registryCacheDirectory);
                    } else if (ResultsCount <= 0) {
                        // Database file exists, but is corrupt. Delete database, so that we can download the file next time arround.
//.........这里部分代码省略.........
开发者ID:nareshjo,项目名称:nodejstools,代码行数:101,代码来源:NpmGetCatalogCommand.cs


注:本文中的SQLite.SQLiteConnection.CreateCatalogTableIfNotExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。