Task.cs :  » Web-Frameworks » Ingenious-MVC » Ingenious » Mvc » 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 » Web Frameworks » Ingenious MVC 
Ingenious MVC » Ingenious » Mvc » Task.cs
#region License

/**
 * Ingenious MVC : An MVC framework for .NET 2.0
 * Copyright (C) 2006, JDP Group
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Authors: - Kent Boogaart (kentcb@internode.on.net)
 */

#endregion

using System;
using Ingenious.Mvc.Util;

namespace Ingenious.Mvc{
  /// <include file='Task.doc.xml' path='/doc/member[@name="T:Task"]/*'/>
  [Serializable]
  public class Task : IEquatable<Task>
  {
    private Task _owner;
    private Id<Task> _id;
    private TaskManager _taskManager;
    private DateTime _timestamp;
    [field: NonSerialized]
    private object _data;
    private TaskState _state;
    private static readonly Log _log = Log.CreateForType(typeof(Task));

    /// <include file='Task.doc.xml' path='/doc/member[@name="P:Owner"]/*'/>
    public Task Owner
    {
      get
      {
        return _owner;
      }
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="P:Id"]/*'/>
    public Id<Task> Id
    {
      get
      {
        return _id;
      }
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="P:Manager"]/*'/>
    public TaskManager Manager
    {
      get
      {
        return _taskManager;
      }
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="P:Timestamp"]/*'/>
    public DateTime Timestamp
    {
      get
      {
        return _timestamp;
      }
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="P:Data"]/*'/>
    public object Data
    {
      get
      {
        return _data;
      }
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="P:State"]/*'/>
    public TaskState State
    {
      get
      {
        return _state;
      }
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="E:Starting"]/*'/>
    [field: NonSerialized]
    public event EventHandler<TaskEventArgs> Starting;

    /// <include file='Task.doc.xml' path='/doc/member[@name="E:Started"]/*'/>
    [field: NonSerialized]
    public event EventHandler<TaskEventArgs> Started;

    /// <include file='Task.doc.xml' path='/doc/member[@name="E:Ending"]/*'/>
    [field: NonSerialized]
    public event EventHandler<TaskEndingEventArgs> Ending;

    /// <include file='Task.doc.xml' path='/doc/member[@name="E:Ended"]/*'/>
    [field: NonSerialized]
    public event EventHandler<TaskEventArgs> Ended;

    /// <include file='Task.doc.xml' path='/doc/member[@name="M:.ctor(Ingenious.Mvc.Task,Ingenious.Mvc.Id`1,Ingenious.Mvc.TaskManager,System.Object)"]/*'/>
    public Task(Task owner, Id<Task> id, TaskManager taskManager, object data)
    {
      ArgumentHelper.AssertNotEmpty(id, "id");
      ArgumentHelper.AssertNotNull(taskManager, "taskManager");
      _owner = owner;
      _id = id;
      _taskManager = taskManager;
      _timestamp = DateTime.Now;
      _data = data;
      _log.Verbose("Constructed Task with ID '{0}' and owner task ID '{1}'.", id, (owner == null) ? string.Empty : owner.Id.ToString());
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="M:Start()"]/*'/>
    internal void Start()
    {
      _log.Information("Starting task with ID '{0}'.", _id);
      TaskEventArgs taskEventArgs = new TaskEventArgs(this);
      OnStarting(taskEventArgs);
      _state = TaskState.Started;
      OnStarted(taskEventArgs);
      _log.Information("Started task with ID '{0}'.", _id);
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="M:End()"]/*'/>
    public void End()
    {
      ExceptionHelper.ThrowIf(_state != TaskState.Started, "End.taskNotStarted", Id);
      _log.Information("Ending task with ID '{0}'.", _id);
      TaskEndingEventArgs endingEventArgs = new TaskEndingEventArgs(this);
      OnEnding(endingEventArgs);

      //allows the ending to be cancelled
      if (!endingEventArgs.Cancel)
      {
        _state = TaskState.Ended;
        OnEnded(new TaskEventArgs(this));
        _log.Information("Ended task with ID '{0}'.", _id);
      }
      else
      {
        _log.Information("Ending of task with ID '{0}' was cancelled.", _id);
      }
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="M:Equals(Ingenious.Mvc.Task)"]/*'/>
    public bool Equals(Task task)
    {
      if (task == null)
      {
        return false;
      }

      return _id.Equals(task._id);
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="M:Equals(System.Object)"]/*'/>
    public override bool Equals(object obj)
    {
      Task task = obj as Task;

      if (task != null)
      {
        return Equals(task);
      }

      return false;
    }

    /// <include file='Task.doc.xml' path='/doc/member[@name="M:GetHashCode()"]/*'/>
    public override int GetHashCode()
    {
      return _id.GetHashCode();
    }

    /// <summary>
    /// Raises the <see cref="Starting"/> event.
    /// </summary>
    protected virtual void OnStarting(TaskEventArgs e)
    {
      EventHelper.Raise(Starting, this, e);
    }

    /// <summary>
    /// Raises the <see cref="Started"/> event.
    /// </summary>
    protected virtual void OnStarted(TaskEventArgs e)
    {
      EventHelper.Raise(Started, this, e);
    }

    /// <summary>
    /// Raises the <see cref="Ending"/> event.
    /// </summary>
    protected virtual void OnEnding(TaskEndingEventArgs e)
    {
      EventHelper.Raise(Ending, this, e);
    }

    /// <summary>
    /// Raises the <see cref="Ended"/> event.
    /// </summary>
    protected virtual void OnEnded(TaskEventArgs e)
    {
      EventHelper.Raise(Ended, this, e);
    }
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.