示例#1
0
        private void Shell_FileSaved(object sender, Shell.FileSavedEventArgs e)
        {
            try
            {
                var options = ProbeToolsPackage.Instance.EditorOptions;
                if (!options.DisableBackgroundScan)
                {
                    var fileContext = FileContextUtil.GetFileContextFromFileName(e.FileName);
                    if (ProbeEnvironment.CurrentAppSettings.FileExistsInApp(e.FileName))
                    {
                        if (fileContext != FileContext.Include && !FileContextUtil.IsLocalizedFile(e.FileName))
                        {
                            Log.Debug("Scanner detected a saved file: {0}", e.FileName);

                            EnqueueChangedFile(e.FileName);
                        }
                        else
                        {
                            Log.Debug("Scanner detected an include file was saved: {0}", e.FileName);

                            EnqueueFilesDependentOnInclude(e.FileName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteEx(ex);
            }
        }
示例#2
0
        public void EnqueueChangedFile(string fullPath)
        {
            var options = ProbeToolsPackage.Instance.EditorOptions;

            if (options.DisableBackgroundScan)
            {
                return;
            }

            var fileContext = FileContextUtil.GetFileContextFromFileName(fullPath);

            if (fileContext != FileContext.Include && fileContext != FileContext.Dictionary)
            {
                lock (_scanLock)
                {
                    if (_scanQueue == null)
                    {
                        _scanQueue = new Queue <ScanInfo>();
                    }
                    if (!_scanQueue.Any(s => string.Equals(s.fileName, fullPath, StringComparison.OrdinalIgnoreCase)))
                    {
                        _scanQueue.Enqueue(new ScanInfo
                        {
                            fileName  = fullPath,
                            mode      = FFScanMode.Deep,
                            forceScan = true
                        });
                    }
                }
            }
        }
示例#3
0
        public FFFile(FFApp app, FFDatabase db, SQLiteDataReader fileRdr)
        {
#if DEBUG
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (fileRdr == null)
            {
                throw new ArgumentNullException("rdr");
            }
#endif
            _app      = app;
            _id       = fileRdr.GetInt64(fileRdr.GetOrdinal("rowid"));
            _fileName = fileRdr.GetString(fileRdr.GetOrdinal("file_name"));
            _context  = FileContextUtil.GetFileContextFromFileName(_fileName);
            _modified = fileRdr.GetDateTime(fileRdr.GetOrdinal("modified"));

            var className = FileContextUtil.GetClassNameFromFileName(_fileName);
            if (!string.IsNullOrEmpty(className))
            {
                _class = new FFClass(_app, this, className);
            }

            UpdateVisibility();
        }
示例#4
0
        public FFFile(FFApp app, string fileName)
        {
#if DEBUG
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }
#endif
            _app      = app;
            _id       = 0L;             // Will be inserted during next database update
            _fileName = fileName;
            _modified = Constants.ZeroDate;
            _context  = FileContextUtil.GetFileContextFromFileName(_fileName);

            var className = FileContextUtil.GetClassNameFromFileName(_fileName);
            if (!string.IsNullOrEmpty(className))
            {
                _class = new FFClass(_app, this, className);
            }

            UpdateVisibility();
        }
示例#5
0
        private void ProcessSourceDir(FFApp app, string dir, List <ScanInfo> scanList)
        {
            try
            {
                foreach (var fileName in Directory.GetFiles(dir))
                {
                    if (!FileContextUtil.IsLocalizedFile(fileName))
                    {
                        var fileContext = FileContextUtil.GetFileContextFromFileName(fileName);
                        switch (fileContext)
                        {
                        case FileContext.Include:
                            // Ignore include files.
                            break;

                        case FileContext.Dictionary:
                            // Deep scan for dictionary only; no exports produced.
                            scanList.Add(new ScanInfo {
                                fileName = fileName, mode = FFScanMode.Deep
                            });
                            break;

                        case FileContext.Function:
                        case FileContext.ClientClass:
                        case FileContext.NeutralClass:
                        case FileContext.ServerClass:
                        case FileContext.ServerProgram:
                            // Files that export global functions must be scanned twice:
                            // First for the exports before everything else, then again for the deep info.
                            scanList.Add(new ScanInfo {
                                fileName = fileName, mode = FFScanMode.Exports
                            });
                            scanList.Add(new ScanInfo {
                                fileName = fileName, mode = FFScanMode.Deep
                            });
                            break;

                        default:
                            scanList.Add(new ScanInfo {
                                fileName = fileName, mode = FFScanMode.Deep
                            });
                            break;
                        }
                    }
                }

                foreach (var subDir in Directory.GetDirectories(dir))
                {
                    ProcessSourceDir(app, subDir, scanList);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, string.Format("Exception when scanning directory '{0}' for functions.", dir));
            }
        }
示例#6
0
        private void EnqueueFilesDependentOnInclude(string includeFileName)
        {
            if (_currentApp == null)
            {
                return;
            }

            var options = ProbeToolsPackage.Instance.EditorOptions;

            if (options.DisableBackgroundScan)
            {
                return;
            }

            using (var db = new FFDatabase())
            {
                var fileIds = new Dictionary <long, string>();

                using (var cmd = db.CreateCommand(@"
					select file_id, file_name from include_depends
					inner join file_ on file_.rowid = include_depends.file_id
					where include_depends.app_id = @app_id
					and include_depends.include_file_name = @include_file_name
					"                    ))
                {
                    cmd.Parameters.AddWithValue("@app_id", _currentApp.Id);
                    cmd.Parameters.AddWithValue("@include_file_name", includeFileName);

                    using (var rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            var fileName = rdr.GetString(1);
                            var context  = FileContextUtil.GetFileContextFromFileName(fileName);
                            if (context != FileContext.Include && context != FileContext.Dictionary)
                            {
                                fileIds[rdr.GetInt64(0)] = fileName;
                            }
                        }
                    }
                }

                if (fileIds.Any())
                {
                    Log.Debug("Resetting modified date on {0} file(s).", fileIds.Count);

                    using (var txn = db.BeginTransaction())
                    {
                        using (var cmd = db.CreateCommand("update file_ set modified = '1900-01-01' where rowid = @id"))
                        {
                            foreach (var item in fileIds)
                            {
                                cmd.Parameters.Clear();
                                cmd.Parameters.AddWithValue("@id", item.Key);
                                cmd.ExecuteNonQuery();

                                _currentApp.TrySetFileDate(item.Value, DateTime.MinValue);
                            }
                        }
                        txn.Commit();
                    }
                }
            }

            RestartScanning("Include file changed; scanning dependent files.");
        }