Ejemplo n.º 1
0
        private Task OnActivationInternalAsync(ProjectUpdatingCancelEventArgs e)
        {
            IsActivating = true;

            return(OnActivationAsync(e));
        }
Ejemplo n.º 2
0
 protected virtual Task OnActivationAsync(ProjectUpdatingCancelEventArgs e)
 {
     return(TaskHelper.Completed);
 }
        public async Task <bool> SetActiveProjectAsync(IProject project)
        {
            using (await _commonAsyncLock.LockAsync())
            {
                var activeProject = ActiveProject;

                if (project != null && !Projects.Contains(project))
                {
                    return(false);
                }

                var activeProjectLocation = activeProject?.Location;
                var newProjectLocation    = project?.Location;

                if (string.Equals(activeProjectLocation, newProjectLocation))
                {
                    return(false);
                }

                Log.Info(project != null
                    ? $"Activating project '{project.Location}'"
                    : "Deactivating currently active project");

                var eventArgs = new ProjectUpdatingCancelEventArgs(activeProject, project);

                _projectStateSetter.SetProjectDeactivating(activeProject?.Location, true);
                _projectStateSetter.SetProjectActivating(project?.Location, true);

                await ProjectActivationAsync.SafeInvokeAsync(this, eventArgs, false).ConfigureAwait(false);

                if (eventArgs.Cancel)
                {
                    Log.Info(project != null
                        ? $"Activating project '{project.Location}' was canceled"
                        : "Deactivating currently active project");

                    _projectStateSetter.SetProjectActivating(project?.Location, false);

                    await ProjectActivationCanceledAsync.SafeInvokeAsync(this, new ProjectEventArgs(project)).ConfigureAwait(false);

                    return(false);
                }

                Exception exception = null;

                try
                {
                    ActiveProject = project;
                }
                catch (Exception ex)
                {
                    exception = ex;
                }

                if (exception != null)
                {
                    Log.Error(exception, project != null
                        ? $"Failed to activate project '{project.Location}'"
                        : "Failed to deactivate currently active project");

                    _projectStateSetter.SetProjectActivating(project?.Location ?? string.Empty, false);
                    await ProjectActivationFailedAsync.SafeInvokeAsync(this, new ProjectErrorEventArgs(project, exception)).ConfigureAwait(false);

                    return(false);
                }

                _projectStateSetter.SetProjectDeactivating(activeProject?.Location, false);
                _projectStateSetter.SetProjectActivating(project?.Location, false);

                await ProjectActivatedAsync.SafeInvokeAsync(this, new ProjectUpdatedEventArgs(activeProject, project)).ConfigureAwait(false);

                Log.Debug(project != null
                    ? $"Activating project '{project.Location}' was canceled"
                    : "Deactivating currently active project");

                return(true);
            }
        }