private void FindDependencies(IProgressTask progressTask) { var dependencies = new ConcurrentDictionary<MemberInfo, ICollection<AssemblyInfo>>(); _inputAssemblies.AsParallel().ForAll(filename => { foreach (var dep in GetDependencies(filename)) { MemberInfo m = new MemberInfo() { MemberDocId = dep.MemberDocId, TypeDocId = dep.TypeDocId, DefinedInAssemblyIdentity = dep.DefinedInAssemblyIdentity }; // Add this memberinfo HashSet<AssemblyInfo> newassembly = new HashSet<AssemblyInfo>(); newassembly.Add(dep.CallingAssembly); ICollection<AssemblyInfo> assemblies = dependencies.AddOrUpdate(m, newassembly, (key, existingSet) => { lock (existingSet) { existingSet.Add(dep.CallingAssembly); } return existingSet; }); } progressTask.ReportUnitComplete(); }); _cachedDependencies = dependencies; }
/// <summary> /// Initialises a new instance of the <see cref="ProgressDialog" /> class. /// </summary> /// <param name="task"> /// The task. /// </param> public ProgressDialog(IProgressTask task) { InitializeComponent(); progressTask = task; progressTask.TaskComplete += OnProgressTaskOnTaskComplete; Logger.LogMessage += OnLogMessage; }
protected void OnLoginFinished(bool result, Account account) { this.command.Enabled = true; if (result) { /* login successed */ if (log.IsDebugEnabled) { log.Debug("login successed."); } IProgressTask <float> task = this.viewModel.LoadScene(); task.OnPreExecute(() => { this.command.Enabled = false;/*by databinding, auto set button.interactable = false. */ }).OnFinish(() => { this.command.Enabled = true;/*by databinding, auto set button.interactable = true. */ this.Dismiss(); }).Start(); } else { /* login cancelled */ if (log.IsDebugEnabled) { log.Debug("login cancelled."); } } }
/// <summary> /// Initializes a new instance of the <see cref="ProgressDialog"/> class. /// </summary> /// <param name="task"> /// The task. /// </param> public ProgressDialog(IProgressTask task) { this.InitializeComponent(); this.progressTask = task; this.progressTask.TaskComplete += this.OnProgressTaskOnTaskComplete; Logger.LogMessage += this.OnLogMessage; }
void OnTaskCompleted(IProgressTask task) { switch (task.TaskNongeneric.Status) { case TaskStatus.RanToCompletion: { previousTask = task; ProgressVisibility = Visibility.Collapsed; if (!BindingOperations.IsDataBound(contentPresenter, ContentPresenter.ContentProperty)) { contentPresenter.SetBinding( ContentPresenter.ContentProperty, new Binding("Child") { Source = this } ); } childDataContext.Self = task.ResultNongeneric; break; } case TaskStatus.Faulted: case TaskStatus.Canceled: Task = previousTask; break; default: throw new InvalidOperationException(); } }
void OnTaskChangedCore(IProgressTask task) { if (task == previousTask) { return; } if (task.TaskNongeneric.IsCompleted) { OnTaskCompleted(task); } else { ProgressVisibility = Visibility.Visible; var context = SynchronizationContext.Current; task.TaskNongeneric.ContinueWith(_ => { if (context == null) { OnTaskCompleted(task); } else { context.Post(__ => OnTaskCompleted(task), default(object)); } }); } }
private void FindDependencies(IProgressTask progressTask) { var dependencies = new ConcurrentDictionary <MemberInfo, ICollection <AssemblyInfo> >(); _inputAssemblies.AsParallel().ForAll(filename => { foreach (var dep in GetDependencies(filename)) { MemberInfo m = new MemberInfo() { MemberDocId = dep.MemberDocId, TypeDocId = dep.TypeDocId, DefinedInAssemblyIdentity = dep.DefinedInAssemblyIdentity }; // Add this memberinfo HashSet <AssemblyInfo> newassembly = new HashSet <AssemblyInfo>(); newassembly.Add(dep.CallingAssembly); ICollection <AssemblyInfo> assemblies = dependencies.AddOrUpdate(m, newassembly, (key, existingSet) => { lock (existingSet) { existingSet.Add(dep.CallingAssembly); } return(existingSet); }); } progressTask.ReportUnitComplete(); }); _cachedDependencies = dependencies; }
/// <summary> /// Shows a progress dialog box /// </summary> /// <param name="task">Task</param> /// <param name="title">Title</param> /// <param name="ownerWindow">Owner window</param> public static void Show(IProgressTask task, string title, Window ownerWindow) { var win = new ProgressDlg(); var vm = new ProgressVM(System.Windows.Threading.Dispatcher.CurrentDispatcher, task); win.Owner = ownerWindow; win.DataContext = vm; win.Title = title; win.ShowDialog(); }
public void Start(IProgressTask task) { this.task = task; Thread t = new Thread(new ThreadStart(RunningMethodDelegate)); Start(); t.Start(); }
public void AddTask(IProgressTask task) { Debug.Log("new task " + task.Description); Tasks.Add(task); task.OnUpdated += TaskUpdated; task.OnCompleted += TaskCompleted; updated = true; }
public ProgressVM(Dispatcher dispatcher, IProgressTask task) { this.dispatcher = dispatcher; this.task = task; this.progressMinimum = task.ProgressMinimum; this.progressMaximum = task.ProgressMaximum; this.isIndeterminate = task.IsIndeterminate; Start(); }
public static DependencyFinderEngine ComputeDependencies(IEnumerable<string> inputAssemblies, IProgressTask progressTask) { var engine = new DependencyFinderEngine(inputAssemblies); engine.FindDependencies(progressTask); return engine; }
void TaskCompleted(IProgressTask task, bool success, Exception exception) { Debug.Log($"task completed: {task.Description}: {Mathf.Floor(task.Progress * 100.0f)} success? {success}"); OnTaskCompleted.Invoke(task, success, exception); Tasks.Remove(task); task.OnUpdated -= TaskUpdated; task.OnCompleted -= TaskCompleted; updated = true; }
public void Add(IProgressTask task) { task.OnProgress += t => StateHasChanged(); task.OnComplete += t => StateHasChanged(); _tasks.Add(task); StateHasChanged(); }
public ProgressVM(Dispatcher dispatcher, IProgressTask task) { this.dispatcher = dispatcher; this.task = task; this.progressMinimum = task.ProgressMinimum; this.progressMaximum = task.ProgressMaximum; this.isIndeterminate = task.IsIndeterminate; Start(); }
/// <summary> /// Starts the progress indication for the specified Project Task. /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="taskName"> /// The task name. /// </param> public void StartTaskProgress(IProgressTask task, string taskName) { var dialog = new ProgressDialog(task) { Text = taskName }; dialog.ShowDialog(this); }
public ProgressVM(Dispatcher dispatcher, IProgressTask task) { this.dispatcher = dispatcher; this.task = task; this.progressMinimum = task.ProgressMinimum; this.progressMaximum = task.ProgressMaximum; this.isIndeterminate = task.IsIndeterminate; this.cancellationTokenSource = new CancellationTokenSource(); Start(); }
public void RestoreNugets(RunnerOptions options, IProgressTask task) { if (options.NoRestore) { task.Increment(100); return; } Solutions.IncrementForEach(task, 100, sln => sln.RestoreNugets(options)); }
public ProgressVM(Dispatcher dispatcher, IProgressTask task) { this.dispatcher = dispatcher; this.task = task; this.progressMinimum = task.ProgressMinimum; this.progressMaximum = task.ProgressMaximum; this.isIndeterminate = task.IsIndeterminate; this.cancellationTokenSource = new CancellationTokenSource(); Start(); }
/// <summary> /// Shows a progress dialog box /// </summary> /// <param name="task">Task</param> /// <param name="title">Title</param> /// <param name="ownerWindow">Owner window</param> public static void Show(IProgressTask task, string title, Window ownerWindow) { var win = new ProgressDlg(); var vm = new ProgressVM(System.Windows.Threading.Dispatcher.CurrentDispatcher, task); win.Owner = ownerWindow; win.DataContext = vm; win.Title = title; win.ShowDialog(); }
public async Task AddTransitiveReferences(RunnerOptions options, IProgressTask task) { var projects = await Solutions.Select(sln => sln.Projects.Value) .WhenAll(projs => projs.SelectMany(proj => proj) .Distinct()); projects.IncrementForEach(task, 100, project => { project.AddTransitiveReferences(this, options); }); }
public static void IncrementForEach <T>(this IEnumerable <T> enumerable, IProgressTask progress, double value, Action <T> predicate) { var list = enumerable.ToList(); var incrementValue = value / list.Count; foreach (var item in list) { predicate(item); progress.Increment(incrementValue); } }
public static async Task DeduplicateProjects(List <Solution> solutions, IProgressTask createWorkspaceTask) { var projects = await solutions.Select(sln => sln.Projects.Value) .WhenAll(projs => projs.SelectMany(projs => projs) .DistinctBy(proj => proj.Filepath) .ToList()); foreach (var sln in solutions) { await sln.ReplaceProjects(projects); createWorkspaceTask.Increment(33.0 / solutions.Count); } }
/// <summary> /// Simulate a loading task. /// </summary> public void Unzip() { Loading loading = null; IProgressTask <float> task = this.viewModel.Unzip(); task.OnPreExecute(() => { loading = Loading.Show(); this.command.Enabled = false;/*by databinding, auto set button.interactable = false. */ }).OnFinish(() => { loading.Dispose(); this.OpenLoginWindow(); this.command.Enabled = true;/*by databinding, auto set button.interactable = true. */ }).Start(30); }
public async Task CheckForCircularReferences(IProgressTask task) { var projects = await Solutions.Select(sln => sln.Projects.Value) .WhenAll(projs => projs.SelectMany(projs => projs) .Distinct()) .ToDictionaryAsync(proj => proj.PackageId, proj => proj); projects.Values.IncrementForEach(task, 100, project => { var rootNode = new ReferenceNode(project, null); var open = new List <ReferenceNode>(project.GetProjectReferences(this).Select(proj => new ReferenceNode(proj, rootNode)).Distinct()); var closed = new List <ReferenceNode>(new[] { rootNode }); while (open.Any()) { var openProj = open.First(); open.Remove(openProj); closed.Add(openProj); foreach (var projRef in openProj.Project.GetProjectReferences(this)) { if (projRef == project) { throw new CyclicReferenceException(new ReferenceNode(projRef, openProj).Expand(node => node.Parent) .Select(node => node.Project) .Reverse() .ToList()); } if (!closed.Any(node => node.Project == projRef)) { open.Add(new ReferenceNode(projRef, openProj)); } } } }); }
protected void RunSubtask(IProgressTask task) { task.Message += (sender, args) => InvokeMessage(args.Reason, args.Message); task.ProgressChanged += (sender, args) => SetStepProgress(args.Progress); task.Run(); }
public static Task IncrementWhenAll(this IEnumerable <Task> enumerable, IProgressTask task, double value) { var tasksList = enumerable.ToList(); return(Task.WhenAll(tasksList.Select(async t => { await t; task.Increment(value / tasksList.Count); }))); }
/// <summary> /// Starts the progress indication for the specified Project Task. /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="taskName"> /// The task name. /// </param> public void StartTaskProgress(IProgressTask task, string taskName) { var dialog = new ProgressDialog(task) { Text = taskName }; dialog.ShowDialog(this); }
public async Task RemoveReferencesAsync(IProgressTask task) => await Solutions.Select(sln => sln.Projects.Value) .WhenAll(projs => projs.SelectMany(projs => projs) .IncrementForEach(task, 100, proj => proj.RemoveReferences(this)));
/// <summary> /// Starts the progress indication for the specified Project Task. /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="taskName"> /// The task name. /// </param> public void StartTaskProgress(IProgressTask task, string taskName) { // Not needed in this dialog. }
public static async Task IncrementForEach <T>(this IEnumerable <T> enumerable, IProgressTask progress, double value, Func <T, Task> predicate) { var list = enumerable.ToList(); var incrementValue = value / list.Count; foreach (var item in list) { await predicate(item); progress.Increment(incrementValue); } }
public static DependencyFinderEngine ComputeDependencies(IEnumerable <string> inputAssemblies, IProgressTask progressTask) { var engine = new DependencyFinderEngine(inputAssemblies); engine.FindDependencies(progressTask); return(engine); }
public static async Task <Workspace> CreateAsync(IOutputWriter outputWriter, IEnumerable <string> solutionPaths, IProgressTask createWorkspaceTask) { var solutions = solutionPaths.Select(path => new Solution(outputWriter, path)) .ToList(); await createWorkspaceTask.IncrementWhenAll(solutions.Select(sln => sln.Projects.Value), 33); await DeduplicateProjects(solutions, createWorkspaceTask); await createWorkspaceTask.IncrementWhenAll(solutions.Select(sln => sln.CheckDetachedProjectReferences()), 34); createWorkspaceTask.StopTask(); return(new Workspace(outputWriter, solutions)); }
public Task PopulateSolutionsAsync(IProgressTask task) => Solutions.IncrementForEach(task, 100, async sln =>
/// <summary> /// Starts the progress indication for the specified Project Task. /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="taskName"> /// The task name. /// </param> public void StartTaskProgress(IProgressTask task, string taskName) { // Not needed. }
/// <summary> /// Starts the progress indication for the specified Project Task. /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="taskName"> /// The task name. /// </param> public void StartTaskProgress(IProgressTask task, string taskName) { // Not needed in this dialog. }
private void TaskUpdated(IProgressTask task) { updated = true; }
/// <summary> /// Starts the progress indication for the specified Project Task. /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="taskName"> /// The task name. /// </param> public void StartTaskProgress(IProgressTask task, string taskName) { // Not needed. }
protected void RunSubtask(IProgressTask task) { task.Message += (sender, args) => InvokeMessage(args.Reason, args.Message); task.ProgressChanged += (sender, args) => SetStepProgress(args.Progress); task.Run(); }
public static bool IsComplete(this IProgressTask task) { return(task.Status == TaskStatus.Completed || task.Status == TaskStatus.Cancelled || task.Status == TaskStatus.Failed); }