Exemple #1
0
 public TaskList(IEnumerable<TaskTable> tasks, IEnumerable<CategoryTable> categories, int currentPosition = 0)
 {
     _tasks = tasks.ToList();
     _taskDictionary = _tasks.ToDictionary(task => task.Id);
     _category = categories.ToDictionary(cat => cat.Id);
     _enumerator = new TaskEnumerator(this) { CurrentPosition = currentPosition };
 }
Exemple #2
0
        public async Task Update(ILogger logger, string droplocation)
        {
            Logger.Log("Updating feeds...");

            var updatedFeeds = await TaskEnumerator.WhenAll(FetchRss, logger, GetFeeds());

            var torrentsToDownload = await TaskEnumerator.WhenAll(FindTorrentsToDownload, logger, updatedFeeds);

            await TaskEnumerator.WhenAll(DownloadTorrent, logger, torrentsToDownload.SelectMany(x => x));
        }
Exemple #3
0
        public IEnumerator <object> GetFolderPaths()
        {
            var iter = new TaskEnumerator <Folder>(GetFolders());
            var f    = Scheduler.Start(iter.GetArray());

            yield return(f);

            string[] folders = (from _ in (Folder[])f.Result select _.Path).ToArray();

            yield return(new Result(folders));
        }
Exemple #4
0
        public static IEnumerator <object> AutoShowConfiguration(string[] argv)
        {
            bool    show = false;
            IFuture f;

            if (argv.Contains("--configure"))
            {
                show = true;
            }
            else
            {
                {
                    var iter = new TaskEnumerator <TagDatabase.Folder>(Database.GetFolders());
                    f = Scheduler.Start(iter.GetArray());
                }

                yield return(f);

                if (((TagDatabase.Folder[])f.Result).Length == 0)
                {
                    show = true;
                }
                else
                {
                    {
                        var iter = new TaskEnumerator <TagDatabase.Filter>(Database.GetFilters());
                        f = Scheduler.Start(iter.GetArray());
                    }

                    yield return(f);

                    if (((TagDatabase.Filter[])f.Result).Length == 0)
                    {
                        show = true;
                    }
                }
            }

            if (show)
            {
#if !MONO
                using (var dialog = new ConfigurationDialog(Database))
                    if (dialog.ShowDialog() != DialogResult.OK)
                    {
                        yield return(ExitTask());
                    }
#else
                Console.WriteLine("Configuration required :-(");
                yield return(ExitTask());
#endif
            }
        }
Exemple #5
0
        public void TestIterateSequence () {
            using (var iter = new TaskEnumerator<int>(CountToThree(), 1)) {
                for (int i = 1; i <= 3; i++) {
                    Assert.IsFalse(iter.Disposed);
                    Scheduler.WaitFor(iter.Fetch());

                    using (var e = iter.CurrentItems) {
                        Assert.IsTrue(e.MoveNext());
                        Assert.AreEqual(i, e.Current);
                        Assert.IsFalse(e.MoveNext());
                    }
                }
            }
        }
Exemple #6
0
        public TaskEnumerator <IDataRecord> Execute(params object[] parameters)
        {
            var fReader = this.ExecuteReader(parameters);

            var e = new TaskEnumerator <IDataRecord>(ExecuteTask(fReader), 1);

            e.OnEarlyDispose = () => {
                fReader.Dispose();

                if (fReader.Completed)
                {
                    fReader.Result.Dispose();
                }
            };

            return(e);
        }
Exemple #7
0
        public TaskEnumerator <T> Execute <T> (Func <IDataReader, T> customMapper, params object[] parameters)
        {
            var fReader = this.ExecuteReader(parameters);

            var e = new TaskEnumerator <T>(ExecuteCustomMapper <T>(customMapper, fReader));

            e.OnEarlyDispose = () => {
                fReader.Dispose();

                if (fReader.Completed)
                {
                    fReader.Result.Dispose();
                }
            };

            return(e);
        }
Exemple #8
0
        public TaskEnumerator <T> Execute <T> (params object[] parameters)
            where T : class, new()
        {
            var fReader = this.ExecuteReader(parameters);

            var e = new TaskEnumerator <T>(ExecuteMapper <T>(fReader));

            e.OnEarlyDispose = () => {
                fReader.Dispose();

                if (fReader.Completed)
                {
                    fReader.Result.Dispose();
                }
            };

            return(e);
        }
Exemple #9
0
        public void IteratorFailsMoveNextOnceIterationIsComplete () {
            var iter = new TaskEnumerator<int>(JustOne(), 1);

            Assert.IsFalse(iter.Disposed);
            Scheduler.WaitFor(iter.Fetch());

            using (var e = iter.CurrentItems) {
                Assert.IsTrue(e.MoveNext());
                Assert.AreEqual(1, e.Current);
                Assert.IsFalse(e.MoveNext());
            }

            Assert.IsFalse(iter.Disposed);
            Scheduler.WaitFor(iter.Fetch());
            Assert.IsTrue(iter.Disposed);

            iter.Dispose();
        }
Exemple #10
0
        private IEnumerator <object> ReadPreferences()
        {
            txtIndexLocation.Text = Program.DatabasePath;

            {
                Future <string> f;
                yield return(DB.GetPreference("TextEditor.Name").Run(out f));

                cbTextEditor.Text = f.Result ?? "SciTE";

                yield return(DB.GetPreference("TextEditor.Location").Run(out f));

                txtEditorLocation.Text = f.Result ?? @"C:\Program Files\SciTE\SciTE.exe";
            }

            yield return(ReadHotkeyPreference("SearchFiles", hkSearchFiles));

            {
                TagDatabase.Folder[] folders = null;
                var iter = new TaskEnumerator <TagDatabase.Folder>(DB.GetFolders());
                yield return(iter.GetArray().Bind(() => folders));

                Folders.Clear();
                if (folders != null)
                {
                    Folders.AddRange(folders);
                }

                RefreshFolderList();
            }

            using (var iter = new TaskEnumerator <TagDatabase.Filter>(DB.GetFilters()))
                while (!iter.Disposed)
                {
                    yield return(iter.Fetch());

                    foreach (var filter in iter)
                    {
                        Filters.Add(filter.Pattern);
                    }
                }

            RefreshFileTypeList();
        }
        private void Initialize()
        {
            try
            {
                _redColor = Resources.GetColor(Resource.Color.task_progress_red);
                _greenColor = Resources.GetColor(Resource.Color.task_progress_green);

                _playerName = FindViewById<TextView>(Resource.Id.playerInGameName);
                _playerPosition = FindViewById<TextView>(Resource.Id.playerInGamePostion);
                _playerScore = FindViewById<TextView>(Resource.Id.playerInGameScore);
                _makeThisButton = FindViewById<Button>(Resource.Id.makeThisButton);
                _refuseButton = FindViewById<Button>(Resource.Id.refuseButton);
                _cardImage = FindViewById<ImageButton>(Resource.Id.taskImageButton);
                _actionButton = (TextView)CreateActionButton(Resource.Drawable.table_button);
                _points = FindViewById<TextView>(Resource.Id.points);
                _x2 = FindViewById<TextView>(Resource.Id.x2);
                _coninueButton = FindViewById<ImageButton>(Resource.Id.continueButton);
                _scoreTextView = FindViewById<TextView>(Resource.Id.scoreString);

                _taskEnumerator = Rep.DatabaseHelper.Tasks.Enumerator;
                _playerEnumerator = Rep.Instance.Players.Enumerator;

                _playerName.SetTypeface(Rep.FontManager.Get(Font.Bold), TypefaceStyle.Normal);
                _playerPosition.SetTypeface(Rep.FontManager.Get(Font.Regular), TypefaceStyle.Normal);
                _makeThisButton.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                _refuseButton.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                _playerScore.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                _points.SetTypeface(Rep.FontManager.Get(Font.Bold), TypefaceStyle.Normal);
                _x2.SetTypeface(Rep.FontManager.Get(Font.Bold), TypefaceStyle.Normal);
                _cardImage.SetImageResource(Resource.Drawable.card_backside); ;
                _scoreTextView.SetTypeface(Rep.FontManager.Get(Font.Condensed), TypefaceStyle.Normal);

                _taskProgressView = FindViewById<RelativeLayout>(Resource.Id.taskProgressView);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "Initialize", exception, true);
            }
        }
Exemple #12
0
        private void Initialize()
        {
            try
            {
                _redColor   = Resources.GetColor(Resource.Color.task_progress_red);
                _greenColor = Resources.GetColor(Resource.Color.task_progress_green);

                _playerName     = FindViewById <TextView>(Resource.Id.playerInGameName);
                _playerPosition = FindViewById <TextView>(Resource.Id.playerInGamePostion);
                _playerScore    = FindViewById <TextView>(Resource.Id.playerInGameScore);
                _makeThisButton = FindViewById <Button>(Resource.Id.makeThisButton);
                _refuseButton   = FindViewById <Button>(Resource.Id.refuseButton);
                _cardImage      = FindViewById <ImageButton>(Resource.Id.taskImageButton);
                _actionButton   = (TextView)CreateActionButton(Resource.Drawable.table_button);
                _points         = FindViewById <TextView>(Resource.Id.points);
                _x2             = FindViewById <TextView>(Resource.Id.x2);
                _coninueButton  = FindViewById <ImageButton>(Resource.Id.continueButton);
                _scoreTextView  = FindViewById <TextView>(Resource.Id.scoreString);

                _taskEnumerator   = Rep.DatabaseHelper.Tasks.Enumerator;
                _playerEnumerator = Rep.Instance.Players.Enumerator;

                _playerName.SetTypeface(Rep.FontManager.Get(Font.Bold), TypefaceStyle.Normal);
                _playerPosition.SetTypeface(Rep.FontManager.Get(Font.Regular), TypefaceStyle.Normal);
                _makeThisButton.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                _refuseButton.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                _playerScore.SetTypeface(Rep.FontManager.Get(Font.BoldCondensed), TypefaceStyle.Normal);
                _points.SetTypeface(Rep.FontManager.Get(Font.Bold), TypefaceStyle.Normal);
                _x2.SetTypeface(Rep.FontManager.Get(Font.Bold), TypefaceStyle.Normal);
                _cardImage.SetImageResource(Resource.Drawable.card_backside);;
                _scoreTextView.SetTypeface(Rep.FontManager.Get(Font.Condensed), TypefaceStyle.Normal);

                _taskProgressView = FindViewById <RelativeLayout>(Resource.Id.taskProgressView);
            }
            catch (Exception exception)
            {
                GaService.TrackAppException(this.Class, "Initialize", exception, true);
            }
        }
Exemple #13
0
        public void TestTypeCoercion () {
            var iter = new TaskEnumerator<int>(TwoTypes(), 1);

            Assert.IsFalse(iter.Disposed);
            Scheduler.WaitFor(iter.Fetch());

            using (var e = iter.CurrentItems) {
                Assert.IsTrue(e.MoveNext());
                Assert.AreEqual(1, e.Current);
            }

            Assert.IsFalse(iter.Disposed);

            try {
                Scheduler.WaitFor(iter.Fetch());
                Assert.Fail("Fetch did not throw an InvalidCastException");
            } catch (FutureException fe) {
                Assert.IsInstanceOf<InvalidCastException>(fe.InnerException);
            }

            iter.Dispose();
        }
Exemple #14
0
        public static IEnumerator<object> AutoShowConfiguration(string[] argv)
        {
            bool show = false;
            IFuture f;

            if (argv.Contains("--configure")) {
                show = true;
            } else {
                {
                    var iter = new TaskEnumerator<TagDatabase.Folder>(Database.GetFolders());
                    f = Scheduler.Start(iter.GetArray());
                }

                yield return f;

                if (((TagDatabase.Folder[])f.Result).Length == 0) {
                    show = true;
                } else {
                    {
                        var iter = new TaskEnumerator<TagDatabase.Filter>(Database.GetFilters());
                        f = Scheduler.Start(iter.GetArray());
                    }

                    yield return f;

                    if (((TagDatabase.Filter[])f.Result).Length == 0)
                        show = true;
                }
            }

            if (show) {
            #if !MONO
                using (var dialog = new ConfigurationDialog(Database))
                    if (dialog.ShowDialog() != DialogResult.OK)
                        yield return ExitTask();
            #else
                Console.WriteLine("Configuration required :-(");
                yield return ExitTask();
            #endif
            }
        }
        private IEnumerator<object> ReadPreferences()
        {
            txtIndexLocation.Text = Program.DatabasePath;

            {
                Future<string> f;
                yield return DB.GetPreference("TextEditor.Name").Run(out f);
                cbTextEditor.Text = f.Result ?? "SciTE";

                yield return DB.GetPreference("TextEditor.Location").Run(out f);
                txtEditorLocation.Text = f.Result ?? @"C:\Program Files\SciTE\SciTE.exe";
            }

            yield return ReadHotkeyPreference("SearchFiles", hkSearchFiles);

            {
                TagDatabase.Folder[] folders = null;
                var iter = new TaskEnumerator<TagDatabase.Folder>(DB.GetFolders());
                yield return iter.GetArray().Bind(() => folders);

                Folders.Clear();
                if (folders != null)
                    Folders.AddRange(folders);

                RefreshFolderList();
            }

            using (var iter = new TaskEnumerator<TagDatabase.Filter>(DB.GetFilters()))
            while (!iter.Disposed) {
                yield return iter.Fetch();

                foreach (var filter in iter)
                    Filters.Add(filter.Pattern);
            }

            RefreshFileTypeList();
        }
Exemple #16
0
        public void TestToArray () {
            var iter = new TaskEnumerator<int>(CountToThree(), 1);

            int[] result = (int[])Scheduler.WaitFor(iter.GetArray());

            Assert.AreEqual(new int[] { 1, 2, 3 }, result);
        }
Exemple #17
0
        IEnumerator<object> IterationTask (TaskEnumerator<int> iterator, List<int> output) {
            while (!iterator.Disposed) {
                yield return iterator.Fetch();

                foreach (var item in iterator)
                    output.Add(item);
            }
        }
Exemple #18
0
        public void IteratorRaisesOnceIteratorIsDisposed () {
            var iter = new TaskEnumerator<int>(JustOne(), 1);
            iter.Dispose();

            try {
                using (var e = iter.CurrentItems) {
                    var _ = e.Current;
                    Assert.Fail("e.Current did not throw an InvalidOperationException");
                }
            } catch (InvalidOperationException) {
            }
        }
Exemple #19
0
        public void IteratorDisposedIsTrueOnceDisposed () {
            var iter = new TaskEnumerator<int>(JustOne(), 1);
            iter.Dispose();

            Assert.IsTrue(iter.Disposed);
        }
Exemple #20
0
        public static IEnumerator<object> MonitorForChanges()
        {
            Scheduler.Start(
                PeriodicGC(),
                TaskExecutionPolicy.RunAsBackgroundTask
            );

            string[] filters;
            TagDatabase.Folder[] folders = null;

            {
                Future<string[]> f;
                yield return Database.GetFilterPatterns().Run(out f);
                filters = f.Result;
            }

            {
                var iter = new TaskEnumerator<TagDatabase.Folder>(Database.GetFolders());
                yield return Scheduler.Start(iter.GetArray())
                    .Bind( () => folders );
            }

            var exclusionList = (from folder in folders where folder.Excluded select folder.Path).ToArray();

            DiskMonitor monitor = new DiskMonitor(
                (from folder in folders select folder.Path).ToArray(),
                filters,
                new string[] {
                    System.Text.RegularExpressions.Regex.Escape(@"\.svn\"),
                    System.Text.RegularExpressions.Regex.Escape(@"\.git\"),
                    System.Text.RegularExpressions.Regex.Escape(@"\.hg\")
                }
            );
            monitor.Monitoring = true;

            var changedFiles = new List<string>();
            var deletedFiles = new List<string>();
            long lastDiskChange = 0;
            long updateInterval = TimeSpan.FromSeconds(10).Ticks;

            while (true) {
                long now = DateTime.Now.Ticks;
                if ((changedFiles.Count > 0) && ((now - lastDiskChange) > updateInterval)) {
                    var filenames = changedFiles.ToArray();
                    changedFiles.Clear();

                    yield return UpdateIndex(filenames);
                }
                if ((deletedFiles.Count > 0) && ((now - lastDiskChange) > updateInterval)) {
                    using (new ActiveWorker(String.Format("Pruning {0} item(s) from index", deletedFiles.Count))) {
                        string[] filenames = deletedFiles.ToArray();
                        deletedFiles.Clear();

                        yield return DeleteSourceFiles(filenames);
                    }
                }

                using (new ActiveWorker(String.Format("Reading disk change history"))) {
                    now = DateTime.Now.Ticks;
                    foreach (string filename in monitor.GetChangedFiles().Distinct()) {
                        lastDiskChange = now;

                        bool excluded = false;
                        foreach (var exclusion in exclusionList) {
                            if (filename.StartsWith(exclusion)) {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                            changedFiles.Add(filename);
                    }

                    foreach (string filename in monitor.GetDeletedFiles().Distinct()) {
                        lastDiskChange = now;

                        bool excluded = false;
                        foreach (var exclusion in exclusionList) {
                            if (filename.StartsWith(exclusion)) {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                            deletedFiles.Add(filename);
                    }
                }

                yield return new Sleep(2.5);
            }
        }
Exemple #21
0
        public void IteratorRaisesIfCurrentIsAccessedBeforeInitialMoveNext () {
            var iter = new TaskEnumerator<int>(JustOne(), 1);

            Assert.IsFalse(iter.Disposed);
            Scheduler.WaitFor(iter.Fetch());

            try {
                using (var e = iter.CurrentItems) {
                    var _ = e.Current;
                    Assert.Fail("e.Current did not throw an InvalidOperationException");
                }
            } catch (InvalidOperationException) {
            }

            iter.Dispose();
        }
Exemple #22
0
        public static IEnumerator<object> RebuildIndexTask(bool saveOldData)
        {
            using (new ActiveWorker("Rebuilding index...")) {
                var conn = new SQLiteConnection(String.Format("Data Source={0}", DatabasePath + "_new"));
                conn.Open();
                var cw = new ConnectionWrapper(Scheduler, conn);

                yield return cw.ExecuteSQL("PRAGMA auto_vacuum=none");

                long schemaVersion = GetEmbeddedSchemaVersion();

                var fSchema = cw.ExecuteSQL(GetEmbeddedSchema());
                yield return fSchema;

                var trans = cw.CreateTransaction();
                yield return trans;

                if (saveOldData)
                    using (var iter = new TaskEnumerator<TagDatabase.Folder>(Database.GetFolders()))
                    while (!iter.Disposed) {
                        yield return iter.Fetch();

                        foreach (TagDatabase.Folder item in iter)
                            yield return cw.ExecuteSQL(
                                "INSERT INTO Folders (Folders_Path, Folders_Excluded) VALUES (?, ?)",
                                item.Path, item.Excluded
                            );
                    }

                if (saveOldData)
                    using (var iter = new TaskEnumerator<TagDatabase.Filter>(Database.GetFilters()))
                    while (!iter.Disposed) {
                        yield return iter.Fetch();

                        foreach (TagDatabase.Filter item in iter)
                            yield return cw.ExecuteSQL(
                                "INSERT INTO Filters (Filters_Pattern) VALUES (?)",
                                item.Pattern
                            );
                    }

                if (saveOldData)
                    using (var iter = Database.Connection.BuildQuery(
                        "SELECT Preferences_Name, Preferences_Value FROM Preferences"
                    ).Execute())
                    while (!iter.Disposed) {
                        yield return iter.Fetch();

                        foreach (IDataRecord item in iter)
                            yield return cw.ExecuteSQL(
                                "INSERT INTO Preferences (Preferences_Name, Preferences_Value) VALUES (?, ?)",
                                item.GetValue(0), item.GetValue(1)
                            );
                    }

                yield return trans.Commit();

                yield return Database.Connection.Dispose();

                yield return RestartTask();
            }
        }
Exemple #23
0
        private void Initialize()
        {
            _playerName = FindViewById<TextView> (Resource.Id.playerInGameName);
            _playerPosition = FindViewById<TextView> (Resource.Id.playerInGamePostion);
            _playerScore = FindViewById<TextView> (Resource.Id.playerInGameScore);
            _makeThisButton = FindViewById<Button>(Resource.Id.makeThisButton);
            _refuseButton = FindViewById<Button>(Resource.Id.refuseButton);
            _cardImage = FindViewById<ImageButton>(Resource.Id.taskImageButton);
            _actionButton = (TextView)CreateActionButton (Resource.Drawable.table_button);
            _points = FindViewById<TextView> (Resource.Id.points);
            _x2 = FindViewById<TextView> (Resource.Id.x2);
            _taskEnumerator = (TaskEnumerator)Rep.Instance.Tasks.GetEnumerator ();

            _playerName.SetTypeface(this.MyriadProFont(MyriadPro.Bold),TypefaceStyle.Normal);
            _playerPosition.SetTypeface(this.MyriadProFont(MyriadPro.Regular),TypefaceStyle.Normal);
            _makeThisButton.SetTypeface(this.MyriadProFont(MyriadPro.BoldCondensed), TypefaceStyle.Normal);
            _refuseButton.SetTypeface(this.MyriadProFont(MyriadPro.BoldCondensed), TypefaceStyle.Normal);
            _playerScore.SetTypeface(this.MyriadProFont(MyriadPro.BoldCondensed), TypefaceStyle.Normal);
            _points.SetTypeface (this.MyriadProFont (MyriadPro.Bold), TypefaceStyle.Normal);
            _x2.SetTypeface (this.MyriadProFont (MyriadPro.Bold), TypefaceStyle.Normal);
            _cardImage.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.card_backside));
            FindViewById<TextView>(Resource.Id.scoreString).SetTypeface(this.MyriadProFont(MyriadPro.Condensed), TypefaceStyle.Normal);
        }
Exemple #24
0
        public IEnumerator<object> GetFolderPaths()
        {
            var iter = new TaskEnumerator<Folder>(GetFolders());
            var f = Scheduler.Start(iter.GetArray());

            yield return f;

            string[] folders = (from _ in (Folder[])f.Result select _.Path).ToArray();

            yield return new Result(folders);
        }
Exemple #25
0
        public IEnumerator<object> UpdateFileListAndGetChangeSet(BlockingQueue<Change> changeSet)
        {
            string filters;
            Folder[] folders = null;
            string[] exclusionList;

            {
                Future<string[]> f;
                yield return GetFilterPatterns().Run(out f);
                filters = String.Join(";", f.Result);
            }

            {
                var iter = new TaskEnumerator<TagDatabase.Folder>(GetFolders());
                yield return Scheduler.Start(iter.GetArray())
                    .Bind(() => folders);
                exclusionList = (from folder in folders where folder.Excluded select folder.Path).ToArray();
            }

            using (var iterator = new TaskEnumerator<SourceFile>(GetSourceFiles()))
            while (!iterator.Disposed) {
                yield return iterator.Fetch();

                foreach (var file in iterator) {
                    bool validFolder = false;
                    bool fileExists = false;

                    foreach (var folder in folders) {
                        if (file.Path.StartsWith(folder.Path)) {
                            if (folder.Excluded) {
                                validFolder = false;
                                break;
                            } else {
                                validFolder = true;
                            }
                        }
                    }

                    if (validFolder)
                        fileExists = System.IO.File.Exists(file.Path);

                    if (!validFolder || !fileExists)
                        changeSet.Enqueue(
                            new Change { Filename = file.Path, Deleted = true }
                        );
                }
            }

            foreach (var folder in folders) {
                if (folder.Excluded)
                    continue;

                var enumerator = Squared.Util.IO.EnumDirectoryEntries(
                    folder.Path, filters, true, Squared.Util.IO.IsFile
                );

                using (var dirEntries = TaskEnumerator<IO.DirectoryEntry>.FromEnumerable(enumerator))
                while (!dirEntries.Disposed) {
                    yield return dirEntries.Fetch();

                    foreach (var entry in dirEntries) {
                        bool excluded = false;
                        foreach (var exclusion in exclusionList) {
                            if (entry.Name.StartsWith(exclusion)) {
                                excluded = true;
                                break;
                            }
                        }

                        if (excluded)
                            continue;

                        long newTimestamp = entry.LastWritten;
                        long oldTimestamp = 0;

                        IFuture f;
                        yield return GetSourceFileTimestamp(entry.Name).Run(out f);
                        if (f.Result is long)
                            oldTimestamp = (long)f.Result;

                        if (newTimestamp > oldTimestamp)
                            changeSet.Enqueue(
                                new Change { Filename = entry.Name, Deleted = false }
                            );
                    }
                }
            }

            yield break;
        }
Exemple #26
0
        public static IEnumerator <object> MonitorForChanges()
        {
            Scheduler.Start(
                PeriodicGC(),
                TaskExecutionPolicy.RunAsBackgroundTask
                );

            string[]             filters;
            TagDatabase.Folder[] folders = null;

            {
                Future <string[]> f;
                yield return(Database.GetFilterPatterns().Run(out f));

                filters = f.Result;
            }

            {
                var iter = new TaskEnumerator <TagDatabase.Folder>(Database.GetFolders());
                yield return(Scheduler.Start(iter.GetArray())
                             .Bind(() => folders));
            }

            var exclusionList = (from folder in folders where folder.Excluded select folder.Path).ToArray();

            DiskMonitor monitor = new DiskMonitor(
                (from folder in folders select folder.Path).ToArray(),
                filters,
                new string[] {
                System.Text.RegularExpressions.Regex.Escape(@"\.svn\"),
                System.Text.RegularExpressions.Regex.Escape(@"\.git\"),
                System.Text.RegularExpressions.Regex.Escape(@"\.hg\")
            }
                );

            monitor.Monitoring = true;

            var  changedFiles   = new List <string>();
            var  deletedFiles   = new List <string>();
            long lastDiskChange = 0;
            long updateInterval = TimeSpan.FromSeconds(10).Ticks;

            while (true)
            {
                long now = DateTime.Now.Ticks;
                if ((changedFiles.Count > 0) && ((now - lastDiskChange) > updateInterval))
                {
                    var filenames = changedFiles.ToArray();
                    changedFiles.Clear();

                    yield return(UpdateIndex(filenames));
                }
                if ((deletedFiles.Count > 0) && ((now - lastDiskChange) > updateInterval))
                {
                    using (new ActiveWorker(String.Format("Pruning {0} item(s) from index", deletedFiles.Count))) {
                        string[] filenames = deletedFiles.ToArray();
                        deletedFiles.Clear();

                        yield return(DeleteSourceFiles(filenames));
                    }
                }

                using (new ActiveWorker(String.Format("Reading disk change history"))) {
                    now = DateTime.Now.Ticks;
                    foreach (string filename in monitor.GetChangedFiles().Distinct())
                    {
                        lastDiskChange = now;

                        bool excluded = false;
                        foreach (var exclusion in exclusionList)
                        {
                            if (filename.StartsWith(exclusion))
                            {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                        {
                            changedFiles.Add(filename);
                        }
                    }

                    foreach (string filename in monitor.GetDeletedFiles().Distinct())
                    {
                        lastDiskChange = now;

                        bool excluded = false;
                        foreach (var exclusion in exclusionList)
                        {
                            if (filename.StartsWith(exclusion))
                            {
                                excluded = true;
                                break;
                            }
                        }

                        if (!excluded)
                        {
                            deletedFiles.Add(filename);
                        }
                    }
                }

                yield return(new Sleep(2.5));
            }
        }
Exemple #27
0
        public IEnumerator <object> UpdateFileListAndGetChangeSet(BlockingQueue <Change> changeSet)
        {
            string filters;

            Folder[] folders = null;
            string[] exclusionList;

            {
                Future <string[]> f;
                yield return(GetFilterPatterns().Run(out f));

                filters = String.Join(";", f.Result);
            }

            {
                var iter = new TaskEnumerator <TagDatabase.Folder>(GetFolders());
                yield return(Scheduler.Start(iter.GetArray())
                             .Bind(() => folders));

                exclusionList = (from folder in folders where folder.Excluded select folder.Path).ToArray();
            }

            using (var iterator = new TaskEnumerator <SourceFile>(GetSourceFiles()))
                while (!iterator.Disposed)
                {
                    yield return(iterator.Fetch());

                    foreach (var file in iterator)
                    {
                        bool validFolder = false;
                        bool fileExists  = false;

                        foreach (var folder in folders)
                        {
                            if (file.Path.StartsWith(folder.Path))
                            {
                                if (folder.Excluded)
                                {
                                    validFolder = false;
                                    break;
                                }
                                else
                                {
                                    validFolder = true;
                                }
                            }
                        }

                        if (validFolder)
                        {
                            fileExists = System.IO.File.Exists(file.Path);
                        }

                        if (!validFolder || !fileExists)
                        {
                            changeSet.Enqueue(
                                new Change {
                                Filename = file.Path, Deleted = true
                            }
                                );
                        }
                    }
                }

            foreach (var folder in folders)
            {
                if (folder.Excluded)
                {
                    continue;
                }

                var enumerator = Squared.Util.IO.EnumDirectoryEntries(
                    folder.Path, filters, true, Squared.Util.IO.IsFile
                    );

                using (var dirEntries = TaskEnumerator <IO.DirectoryEntry> .FromEnumerable(enumerator))
                    while (!dirEntries.Disposed)
                    {
                        yield return(dirEntries.Fetch());

                        foreach (var entry in dirEntries)
                        {
                            bool excluded = false;
                            foreach (var exclusion in exclusionList)
                            {
                                if (entry.Name.StartsWith(exclusion))
                                {
                                    excluded = true;
                                    break;
                                }
                            }

                            if (excluded)
                            {
                                continue;
                            }

                            long newTimestamp = entry.LastWritten;
                            long oldTimestamp = 0;

                            IFuture f;
                            yield return(GetSourceFileTimestamp(entry.Name).Run(out f));

                            if (f.Result is long)
                            {
                                oldTimestamp = (long)f.Result;
                            }

                            if (newTimestamp > oldTimestamp)
                            {
                                changeSet.Enqueue(
                                    new Change {
                                    Filename = entry.Name, Deleted = false
                                }
                                    );
                            }
                        }
                    }
            }

            yield break;
        }
Exemple #28
0
        public static IEnumerator <object> RebuildIndexTask(bool saveOldData)
        {
            using (new ActiveWorker("Rebuilding index...")) {
                var conn = new SQLiteConnection(String.Format("Data Source={0}", DatabasePath + "_new"));
                conn.Open();
                var cw = new ConnectionWrapper(Scheduler, conn);

                yield return(cw.ExecuteSQL("PRAGMA auto_vacuum=none"));

                long schemaVersion = GetEmbeddedSchemaVersion();

                var fSchema = cw.ExecuteSQL(GetEmbeddedSchema());
                yield return(fSchema);

                var trans = cw.CreateTransaction();
                yield return(trans);

                if (saveOldData)
                {
                    using (var iter = new TaskEnumerator <TagDatabase.Folder>(Database.GetFolders()))
                        while (!iter.Disposed)
                        {
                            yield return(iter.Fetch());

                            foreach (TagDatabase.Folder item in iter)
                            {
                                yield return(cw.ExecuteSQL(
                                                 "INSERT INTO Folders (Folders_Path, Folders_Excluded) VALUES (?, ?)",
                                                 item.Path, item.Excluded
                                                 ));
                            }
                        }
                }

                if (saveOldData)
                {
                    using (var iter = new TaskEnumerator <TagDatabase.Filter>(Database.GetFilters()))
                        while (!iter.Disposed)
                        {
                            yield return(iter.Fetch());

                            foreach (TagDatabase.Filter item in iter)
                            {
                                yield return(cw.ExecuteSQL(
                                                 "INSERT INTO Filters (Filters_Pattern) VALUES (?)",
                                                 item.Pattern
                                                 ));
                            }
                        }
                }

                if (saveOldData)
                {
                    using (var iter = Database.Connection.BuildQuery(
                               "SELECT Preferences_Name, Preferences_Value FROM Preferences"
                               ).Execute())
                        while (!iter.Disposed)
                        {
                            yield return(iter.Fetch());

                            foreach (IDataRecord item in iter)
                            {
                                yield return(cw.ExecuteSQL(
                                                 "INSERT INTO Preferences (Preferences_Name, Preferences_Value) VALUES (?, ?)",
                                                 item.GetValue(0), item.GetValue(1)
                                                 ));
                            }
                        }
                }

                yield return(trans.Commit());

                yield return(Database.Connection.Dispose());

                yield return(RestartTask());
            }
        }