bovender framework
C# framework that implements MVVM and more
ProcessModel.cs
1 /* ProcessModel.cs
2  * part of Bovender framework
3  *
4  * Copyright 2014-2018 Daniel Kraus
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 
23 namespace Bovender.Mvvm.Models
24 {
30  public abstract class ProcessModel : IProcessModel
31  {
32  #region Public methods
33 
37  public void Cancel()
38  {
39  IsCancellationRequested = true;
40  OnCancelling();
41  }
42 
43  #endregion
44 
45  #region Events
46 
47  public event EventHandler<ProcessModelEventArgs> Cancelling;
48 
49  #endregion
50 
51  #region Abstract methods
52 
60  public abstract bool Execute();
61 
62  #endregion
63 
64  #region Protected methods
65 
66  protected virtual void OnCancelling()
67  {
68  EventHandler<ProcessModelEventArgs> h = Cancelling;
69  if (h != null)
70  {
71  Logger.Info("Raising Cancel event; {0} subscriber(s)", h.GetInvocationList().Length);
72  h(this, new ProcessModelEventArgs(this));
73  }
74  }
75 
76  #endregion
77 
78  #region Protected properties
79 
80  protected ProcessModel Dependent { get; set; }
81 
87  protected bool IsCancellationRequested { get; set; }
88 
89  #endregion
90 
91  #region Class logger
92 
93  private static NLog.Logger Logger { get { return _logger.Value; } }
94 
95  private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
96 
97  #endregion
98  }
99 }
void Cancel()
Cancels the current process
Definition: ProcessModel.cs:37
Abstract base class for models that perform a lengthy process asynchronously.
Definition: ProcessModel.cs:30