コード例 #1
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);
            }
        }
コード例 #2
0
        public SandboxWatchdog(string rootFolder)
        {
            if (rootFolder == null)
            {
                throw new ArgumentNullException("rootFolder");
            }

            _filesystem     = new FileSystem();
            _rootFolder     = rootFolder;
            _pendingActions = new ConcurrentQueue <PendingAction>();

            _currentSandbox = new Sandbox(Enumerable.Empty <Solution>(), Enumerable.Empty <Project>());

            _thread = new Thread(ExecutePendingActions)
            {
                IsBackground = true
            };
            _fileSystemWatcher = new FileSystemWatcher(_rootFolder)
            {
                IncludeSubdirectories = true,
                NotifyFilter          = NotifyFilters.LastWrite |
                                        NotifyFilters.FileName |
                                        NotifyFilters.CreationTime |
                                        NotifyFilters.Size,
                Filter = "*.csproj"
            };
            _fileSystemWatcher.Created            += OnCreated;
            _fileSystemWatcher.Deleted            += OnDeleted;
            _fileSystemWatcher.Changed            += OnChanged;
            _fileSystemWatcher.Renamed            += OnRenamed;
            _fileSystemWatcher.Error              += OnError;
            _fileSystemWatcher.EnableRaisingEvents = true;

            _pendingActions.Enqueue(PendingAction.Reload(_rootFolder));
            _thread.Start();
        }
コード例 #3
0
 private void OnRenamed(object sender, RenamedEventArgs e)
 {
     _pendingActions.Enqueue(PendingAction.CreateOrUpdate(e.Name));
 }
コード例 #4
0
 private void OnChanged(object sender, FileSystemEventArgs e)
 {
     _pendingActions.Enqueue(PendingAction.CreateOrUpdate(e.Name));
 }
コード例 #5
0
 private void OnDeleted(object sender, FileSystemEventArgs e)
 {
     _pendingActions.Enqueue(PendingAction.Delete(e.Name));
 }