Пример #1
0
        private void ExecutePendingActions()
        {
            var sandboxLoader = new SandboxLoader(_filesystem);

            while (!_isDisposed)
            {
                PendingAction action;
                while (_pendingActions.TryDequeue(out action))
                {
                    Execute(sandboxLoader, action);
                }

                // TODO: We should probably add a delay

                _currentSandbox = sandboxLoader.CreateSandbox();

                Thread.Sleep(TimeSpan.FromMilliseconds(100));
            }
        }
Пример #2
0
        private void Execute(SandboxLoader loader, PendingAction action)
        {
            try
            {
                switch (action.Type)
                {
                case PendingActionType.CreateOrUpdate:
                    loader.CreateOrUpdate(action.Path);
                    break;

                case PendingActionType.Remove:
                    loader.Delete(action.Path);
                    break;

                case PendingActionType.Reload:
                    foreach (string file in Directory.EnumerateFiles(action.Path, "*.csproj", SearchOption.AllDirectories))
                    {
                        _pendingActions.Enqueue(PendingAction.CreateOrUpdate(file));
                    }
                    break;
                }
            }
            catch (Exception e)
            {
                // We should retry operations for certain failures because
                // changes are the operation will succeed the next time.
                // Reasons are:
                // - The file is currently owned by another process
                // - The file is being modified and not yet ready to be consumed
                // - Some other related race condition occured that will likely be remedied in the future
                // Algorithm:
                // Exponential backoff with a fixed upper limit of tries.
                // TODO: Implement!

                Log.ErrorFormat("Caught unexpected exception while executing '{0}': {1}",
                                action,
                                e);
            }
        }