Calculator.cs :  » Windows-Presentation-Foundation » Caliburn » BackgroundProcessing » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Windows Presentation Foundation » Caliburn 
Caliburn » BackgroundProcessing » Calculator.cs
namespace BackgroundProcessing{
  using System.Threading;
  using Caliburn.PresentationFramework.Actions;
  using Caliburn.PresentationFramework.Filters;
  using Framework;

  public class Calculator
  {
    public bool CanDivide(double left, double right)
    {
      return right != 0;
    }

    [Preview("CanDivide")]
    [AsyncAction(Callback = "DivideComplete", BlockInteraction = true)]
    //Note: The action is labeled with a title and registered into a collection of running actions during 
    //    its entire execution.
    //    By default it is marked with IsIndeterminate flag, meaning that the action has an indeterminate 
    //    duration and doesn't support progress notification; this way the RunningTaskView could display 
    //    an appropriate indeterminate progress indicator.
    [ActionInfo("Executing division...")]
    public double Divide(double left, double right)
    {
            Thread.Sleep(10000);//Don't ever call Thread.Sleep....it's just for demo purposes.
      return left / right;
    }

    public double DivideComplete(double result)
    {
      return result * 100;
    }

    public bool CanCalculateFactorial(int number)
    {
      return number > 0 && number <= 16;
    }

    [Preview("CanCalculateFactorial")]
    [AsyncAction(BlockInteraction = false)]
    //Note: The action is labeled with a title and registered into a collection of running actions during 
    //    its entire execution. 
    //    In addiction it is marked as supporting progress notification (IsIndeterminate = false), meaning
    //    that the action can provide information about its work progress; this allows the RunningTaskView 
    //    to display the correct progress indicator based on the notifications.
    //    Setting IsCancellable=true allows RunningActionsView to enable an appropriate control to
    //    cancel operation
    [ActionInfo("Calculating factorial...", IsIndeterminate = false, IsCancellable=true)]
    public int Factorial(int number)
    {
      double stepPercentage = 1.0 / number;
      int result = 1;

      for (int i = 1; i <= number; ++i)
      {
        if (RunningAction.Current.CancellationPending)
        {
          RunningAction.Current.Title = "Cancelling...";
          return 0;
        }

        result = result * i;

        //notifies the completed percentage of the work
        RunningAction.Current.CurrentPercentage = stepPercentage * i;

        //changing title...
        if (number > 6 && i >= number - 2)
          RunningAction.Current.Title = "Almost done...";

        Thread.Sleep(1000);
      }

      return result;
    }

    [AsyncAction(BlockInteraction = true )]
    [ActionInfo("Executing very long action", IsIndeterminate = false, IsCancellable = true)]
    public void VeryLongAction() 
        {
      for (int i = 1; i <= 1000; ++i)
      {
        if (RunningAction.Current.CancellationPending)
          return;

        RunningAction.Current.CurrentPercentage = i/1000.0;
        Thread.Sleep(10);
      }
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.