示例#1
0
        public static void BuildNewIndexFile(List <string> searchPaths)
        {
            string indexPath = GetDefaultIndexFilePath();

            if (File.Exists(indexPath))
            {
                File.Delete(indexPath);
            }

            indexPath = CreateNewLayerfileIndexDB();

            List <string> layerFiles = new List <string>();

            foreach (string path in searchPaths)
            {
                LayerfileIndexer indexer = new LayerfileIndexer(path);

                layerFiles.AddRange(indexer.LayerFiles);
            }
        }
示例#2
0
        /// <summary>
        /// Builds the index file with layers
        /// </summary>
        /// <param name="searchPaths">The search paths.</param>
        public void BuildIndex(List <string> searchPaths)
        {
            if (!File.Exists(this.IndexPath))
            {
                CreateNewIndexFile(this.IndexPath);
            }

            List <string> layerFiles = new List <string>();

            int i = 0;


            foreach (string searchPath in searchPaths)
            {
                i++;

                LayerfileIndexer indexer = new LayerfileIndexer(searchPath);
                indexer.Search();
                layerFiles.AddRange(indexer.LayerFiles);

                OnProgressUpdate(i, searchPaths.Count, "Scanning Search Path " + searchPath);
            }

            List <string> insertSQLStatements = new List <string>();

            i = 0;
            foreach (string filePath in layerFiles)
            {
                i++;

                FileInfo fileInfo = new FileInfo(filePath);


                ILayerFile layerFile = new LayerFileClass();
                layerFile.Open(filePath);
                ILayer layer = layerFile.Layer;

                ILayerGeneralProperties layerProps = (ILayerGeneralProperties)layer;
                ILayerExtensions        layerExt   = (ILayerExtensions)layer;

                string lyrGUID  = "00000000-0000-0000-0000-000000000000";
                string revision = "0";

                if (Layer.Util.LayerExtHelper.UmbrielPropertySetExists(layerExt))
                {
                    IPropertySet propertySet = Util.LayerExtHelper.GetUmbrielPropertySet(layerExt);
                    if (propertySet != null && Util.LayerExtHelper.PropertyExists(propertySet, "GUID"))
                    {
                        lyrGUID = propertySet.GetProperty("GUID").ToString();
                    }

                    if (propertySet != null && Util.LayerExtHelper.PropertyExists(propertySet, "revision"))
                    {
                        revision = propertySet.GetProperty("revision").ToString();
                    }
                }

                StringBuilder sql = new StringBuilder();
                sql.AppendLine("INSERT INTO layerfile ");
                sql.AppendLine("(lyrgid,lyrName,lyrDescription,lyrFileName,lyrFullPath,lyrParentDir,lyrRevision,DateRecCreated,DateRecModified)");
                sql.AppendLine(" VALUES (");

                sql.AppendLine("'" + lyrGUID + "'");
                sql.AppendLine(",'" + layer.Name.Replace("'", "''") + "'");
                sql.AppendLine(",'" + layerProps.LayerDescription.Replace("'", "''") + "'");
                sql.AppendLine(",'" + Path.GetFileName(filePath) + "'");
                sql.AppendLine(",\"" + filePath + "\"");
                sql.AppendLine(",'" + Path.GetDirectoryName(filePath) + "'");
                sql.AppendLine("," + revision + "");

                sql.AppendLine(",'" + SqliteDateString(DateTime.Now) + "'");
                sql.AppendLine(",'" + SqliteDateString(DateTime.Now) + "'");

                sql.AppendLine(")");

                Debug.WriteLine(sql.ToString());
                insertSQLStatements.Add(sql.ToString());

                OnProgressUpdate(i, layerFiles.Count, "Building layer data file: ");

                if (layer != null)
                {
                    // System.Runtime.InteropServices.Marshal.FinalReleaseComObject(layerFile);
                }
            }

            i = 0;

            // build insert sql statement
            using (SQLiteConnection cnn = new SQLiteConnection(this.GetDBConnectionString()))
            {
                cnn.Open();

                using (DbTransaction transaction = cnn.BeginTransaction())
                {
                    using (DbCommand cmd = cnn.CreateCommand())
                    {
                        foreach (string sql in insertSQLStatements)
                        {
                            i++;

                            cmd.CommandText = sql;
                            cmd.ExecuteNonQuery();

                            OnProgressUpdate(i, insertSQLStatements.Count, "Inserting data: ");
                        }
                    }
                    transaction.Commit();
                }

                OnProgressUpdate(i, insertSQLStatements.Count, "Insert Complete!");

                cnn.Close();
            }
        }