bovender framework
C# framework that implements MVVM and more
ProcessCompletedAction.cs
1 /* ProcessCompletedAction.cs
2  * part of Daniel's XL Toolbox NG
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 using System.Windows;
23 using Bovender.Mvvm.Messaging;
24 
25 namespace Bovender.Mvvm.Actions
26 {
32  {
33  #region Properties
34 
39  public bool HasException
40  {
41  get
42  {
44  return (c != null && c.Exception != null);
45  }
46  }
47 
48  #endregion
49 
50  #region Constructors
51 
52  public ProcessCompletedAction() : base() { }
53 
54  public ProcessCompletedAction(ProcessMessageContent processMessageContent)
55  : this()
56  {
57  Content = processMessageContent;
58  }
59 
61  ProcessMessageContent processMessageContent,
62  string caption)
63  : this(processMessageContent)
64  {
65  Caption = caption;
66  }
67 
69  ProcessMessageContent processMessageContent,
70  string caption,
71  string message)
72  : this(processMessageContent, caption)
73  {
74  Message = message;
75  }
76 
78  ProcessMessageContent processMessageContent,
79  string caption,
80  string message,
81  string okButtonText)
82  : this(processMessageContent, caption, message)
83  {
84  OkButtonText = okButtonText;
85  }
86 
88  ProcessMessageContent processMessageContent,
89  string caption,
90  string message,
91  string okButtonText,
92  string param)
93  : this(processMessageContent, caption, message, okButtonText)
94  {
95  Param1 = param;
96  }
97 
99  ProcessMessageContent processMessageContent,
100  string caption,
101  string message,
102  string okButtonText,
103  string param1, string param2)
104  : this(processMessageContent, caption, message, okButtonText, param1)
105  {
106  Param2 = param2;
107  }
108 
109  public ProcessCompletedAction(
110  ProcessMessageContent processMessageContent,
111  string caption,
112  string message,
113  string okButtonText,
114  string param1, string param2, string param3)
115  : this(processMessageContent, caption, message, okButtonText, param1, param2)
116  {
117  Param3 = param3;
118  }
119 
120  #endregion
121 
122  #region Virtual methods
123 
124  protected virtual Window CreateSuccessWindow()
125  {
127  }
128 
129  protected virtual Window CreateFailureWindow()
130  {
131  return new Bovender.Mvvm.Views.ProcessFailedView();
132  }
133 
134  protected virtual Window CreateCancelledWindow()
135  {
136  return new Bovender.Mvvm.Views.NotificationView();
137  }
138 
139  #endregion
140 
141  #region Overrides
142 
143  protected override Window CreateView()
144  {
145  Logger.Info("ProcessCompletedAction.CreateView");
146  ProcessMessageContent content = Content as ProcessMessageContent;
147  if (Content is ProcessMessageContent)
148  {
149  if (content.WasCancelled)
150  {
151  Logger.Info("Process was cancelled");
152  return CreateCancelledWindow();
153  }
154  else if (content.WasSuccessful && content.Exception == null)
155  {
156  Logger.Info("Process was successful");
157  return CreateSuccessWindow();
158  }
159  else
160  {
161  Logger.Warn("Process failed!");
162  return CreateFailureWindow();
163  }
164  }
165  else
166  {
167  Logger.Fatal("ProcessCompletedAction requires ProcessMessageContent, got {0}",
168  Content.GetType().AssemblyQualifiedName);
169  throw new ArgumentException(
170  "This message action must be used for Messages with ProcessMessageContent only.");
171  }
172  }
173 
174  #endregion
175 
176  #region Class logger
177 
178  private static NLog.Logger Logger { get { return _logger.Value; } }
179 
180  private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
181 
182  #endregion
183  }
184 }
Interaction logic for ProcessFailedView.xaml
Holds information about percent completion of a process and defines events that occur when the proces...
WPF action that invokes different views depending on the status of a completed process.
Conveys a message from a view model to a consumer (typically, a view) that has subscribed to the Sent...
Definition: Message.cs:31
Exception Exception
If something in the process went wrong, this will be the corresponding exception. ...
Interaction logic for NotificationView.xaml
Interaction logic for ProcessSucceededView.xaml
override Window CreateView()
Returns a view that can bind to expected message contents.
Opens a generic WPF dialog window that displays a message and has a single OK button.