Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Windows
pEp for Outlook
Compare Revisions
b58c6e33612ecd26af3503f0aca9560d3534ad51...78ac17684c3ab05b46e6e4201307cca1f6bb0ca4
Commits (3)
Renaming
· 2b3974db
Thomas
authored
Sep 22, 2021
2b3974db
Execute all API calls in background and catch errors
· c72ce70a
Thomas
authored
Sep 23, 2021
c72ce70a
Adjust algorithm to find patch mail item
· 78ac1768
Thomas
authored
Sep 27, 2021
78ac1768
Hide whitespace changes
Inline
Side-by-side
DPE/DPEWebClient.cs
View file @
78ac1768
using
pEp.Extensions
;
using
System
;
using
System.Net
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
namespace
pEp.DPE
{
internal
static
class
DPEWebClient
{
private
static
readonly
HttpClient
httpClient
=
new
HttpClient
();
private
static
readonly
string
dbePostUrl
=
Globals
.
ThisAddIn
.
Settings
.
DPEWebClientUrl
+
"patches/"
;
private
static
readonly
HttpClient
httpClient
=
new
HttpClient
();
private
static
readonly
string
DPE_POST_URL
=
Globals
.
ThisAddIn
.
Settings
.
DPEWebClientUrl
+
"patches/"
;
public
static
readonly
string
REJECT_PATCH_SUFFIX
=
"/reject/"
;
public
static
readonly
string
SUPPORT_PATCH_SUFFIX
=
"/support/"
;
public
const
string
REJECT_PATCH_SUFFIX
=
"/reject/"
;
public
const
string
SUPPORT_PATCH_SUFFIX
=
"/support/"
;
/// <summary>
/// Rejects a given patch.
/// </summary>
/// <param name="patch">The patch to reject.</param>
/// <param name="me">The own identity that rejects the patch.</param>
public
static
async
void
RejectPatch
(
Patch
patch
,
PEPIdentity
me
)
/// <exception cref="ArgumentNullException" />
/// <exception cref="HttpRequestException" />
/// <returns>The Http response.</returns>
public
static
async
Task
<
HttpResponseMessage
>
RejectPatch
(
Patch
patch
,
PEPIdentity
me
)
{
// POST http://
server
:port/pEpDPE/patches/patch_id/reject
// POST http://
localhost
:port/pEpDPE/patches/patch_id/reject
try
{
HttpResponseMessage
response
=
await
DPEWebClient
.
httpClient
.
PostAsync
(
DPEWebClient
.
dbePostUrl
,
new
StringContent
(
patch
.
Id
+
DPEWebClient
.
REJECT_PATCH_SUFFIX
));
Log
.
Verbose
(
$"SuggestPatch: Patch
{
patch
.
Id
}
rejected. Return status is
{
Enum
.
GetName
(
typeof
(
HttpStatusCode
),
response
.
StatusCode
)
}
"
);
return
await
DPEWebClient
.
httpClient
.
PostAsync
(
DPEWebClient
.
DPE_POST_URL
,
new
StringContent
(
patch
.
Id
+
DPEWebClient
.
REJECT_PATCH_SUFFIX
));
}
catch
(
Exception
ex
)
catch
(
ArgumentNull
Exception
ex
)
{
Log
.
Error
(
"RejectPatch: Error rejecting patch. "
+
ex
.
ToString
());
Log
.
ErrorAndFailInDebugMode
(
"RejectPatch: Error rejecting patch. "
+
ex
);
throw
ex
;
}
catch
(
HttpRequestException
ex
)
{
Log
.
Error
(
"RejectPatch: Error rejecting patch. "
+
ex
);
throw
ex
;
}
}
...
...
@@ -39,20 +46,26 @@ namespace pEp.DPE
/// </summary>
/// <param name="patch">The patch to suggest.</param>
/// <param name="me">The own identity that suggests the patch.</param>
public
static
async
void
SuggestPatch
(
Patch
patch
,
PEPIdentity
me
)
/// <exception cref="ArgumentNullException" />
/// <exception cref="HttpRequestException" />
/// <returns>The Http response.</returns>
public
static
async
Task
<
HttpResponseMessage
>
SuggestPatch
(
Patch
patch
,
PEPIdentity
me
)
{
// POST http://server:port/pEpDPE/patches/
string
xml
=
patch
.
Serialize
();
// POST http://localhost:port/pEpDPE/patches/
try
{
HttpResponseMessage
response
=
await
DPEWebClient
.
httpClient
.
PostAsync
(
DPEWebClient
.
dbePostUrl
,
new
StringContent
(
xml
));
Log
.
Verbose
(
$"SuggestPatch: New patch posted. Return status is
{
Enum
.
GetName
(
typeof
(
HttpStatusCode
),
response
.
StatusCode
)
}
"
);
string
xml
=
patch
.
Serialize
();
return
await
DPEWebClient
.
httpClient
.
PostAsync
(
DPEWebClient
.
DPE_POST_URL
,
new
StringContent
(
xml
));
}
catch
(
ArgumentNullException
ex
)
{
Log
.
ErrorAndFailInDebugMode
(
"SuggestPatch: Error suggesting patch. "
+
ex
);
throw
ex
;
}
catch
(
Exception
ex
)
catch
(
HttpRequest
Exception
ex
)
{
Log
.
Error
(
"SuggestPatch: Error suggesting patch. "
+
ex
.
ToString
());
Log
.
Error
(
"SuggestPatch: Error suggesting patch. "
+
ex
);
throw
ex
;
}
}
...
...
@@ -61,19 +74,26 @@ namespace pEp.DPE
/// </summary>
/// <param name="patch">The patch to support.</param>
/// <param name="me">The own identity that supports the patch.</param>
public
static
async
void
SupportPatch
(
Patch
patch
,
PEPIdentity
me
)
/// <exception cref="ArgumentNullException" />
/// <exception cref="HttpRequestException" />
/// <returns>The Http response.</returns>
public
static
async
Task
<
HttpResponseMessage
>
SupportPatch
(
Patch
patch
,
PEPIdentity
me
)
{
// POST http://
server
:port/pEpDPE/patches/patch_id/support
// POST http://
localhost
:port/pEpDPE/patches/patch_id/support
try
{
HttpResponseMessage
response
=
await
DPEWebClient
.
httpClient
.
PostAsync
(
DPEWebClient
.
dbePostUrl
,
new
StringContent
(
patch
.
Id
+
DPEWebClient
.
SUPPORT_PATCH_SUFFIX
));
Log
.
Verbose
(
$"SuggestPatch: Patch
{
patch
.
Id
}
supported. Return status is
{
Enum
.
GetName
(
typeof
(
HttpStatusCode
),
response
.
StatusCode
)
}
"
);
return
await
DPEWebClient
.
httpClient
.
PostAsync
(
DPEWebClient
.
DPE_POST_URL
,
new
StringContent
(
patch
.
Id
+
DPEWebClient
.
SUPPORT_PATCH_SUFFIX
));
}
catch
(
ArgumentNullException
ex
)
{
Log
.
ErrorAndFailInDebugMode
(
"SupportPatch: Error supporting patch. "
+
ex
);
throw
ex
;
}
catch
(
Exception
ex
)
catch
(
HttpRequest
Exception
ex
)
{
Log
.
Error
(
"SupportPatch: Error supporting patch. "
+
ex
.
ToString
());
Log
.
Error
(
"SupportPatch: Error supporting patch. "
+
ex
);
throw
ex
;
}
}
}
...
...
DPE/DistributedPolicyEngine.cs
View file @
78ac1768
...
...
@@ -3,6 +3,9 @@ using pEp.Extensions;
using
System
;
using
System.IO
;
using
System.Linq
;
using
System.Net
;
using
System.Net.Http
;
using
System.Threading.Tasks
;
using
Outlook
=
Microsoft
.
Office
.
Interop
.
Outlook
;
namespace
pEp.DPE
...
...
@@ -14,6 +17,21 @@ namespace pEp.DPE
private
const
string
PATCH_MESSAGE_SUBJECT
=
"Configuration changes"
;
public
const
string
DPE_MESSAGE_CLASS
=
"IPM.Note.DPE"
;
public
enum
PatchStatus
{
Open
,
Accepted
,
Supported
,
Rejected
}
private
enum
PostAction
{
Reject
,
Suggest
,
Support
}
private
readonly
PEPIdentity
ownIdentity
;
private
readonly
PatchEvents
patchEvents
;
...
...
@@ -56,6 +74,10 @@ namespace pEp.DPE
ThisAddIn
.
PEPEngine
.
ShowNotification
(
"New patch suggested"
,
patch
.
CommitMessage
+
" "
+
patch
.
Diff
);
}
#
endregion
#
region
Methods
/// <summary>
/// Creates a mail item that shows a suggested patch.
/// </summary>
...
...
@@ -88,6 +110,7 @@ namespace pEp.DPE
{
MapiProperty
.
PidTagMessageDeliveryTime
,
DateTime
.
UtcNow
}
});
omi
.
SetMessageFlag
(
MapiPropertyValue
.
EnumPidTagMessageFlags
.
mfUnsent
,
false
);
omi
.
SetUserProperty
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_ID
,
patch
.
Id
);
// Move to inbox and set Received time
mi
=
omi
.
Move
(
Globals
.
ThisAddIn
.
Application
.
Session
.
GetDefaultFolder
(
Outlook
.
OlDefaultFolders
.
olFolderInbox
));
...
...
@@ -104,10 +127,6 @@ namespace pEp.DPE
}
}
#
endregion
#
region
Methods
/// <summary>
/// Disposes of all resources.
/// </summary>
...
...
@@ -117,17 +136,161 @@ namespace pEp.DPE
this
.
patchEvents
.
Dispose
();
}
/// <summary>
/// Gets the corresponding patch mail item.
/// </summary>
/// <param name="patch">The patch that this item belongs to.</param>
/// <returns>The patch mail item or null if not found.</returns>
public
Outlook
.
MailItem
GetPatchMailItem
(
Patch
patch
)
{
Outlook
.
Folder
inbox
=
null
;
Outlook
.
Items
items
=
null
;
try
{
inbox
=
Globals
.
ThisAddIn
.
Application
.
Session
.
GetDefaultFolder
(
Outlook
.
OlDefaultFolders
.
olFolderInbox
)
as
Outlook
.
Folder
;
items
=
inbox
?.
Items
;
if
(
items
?.
Count
>
0
)
{
Log
.
Verbose
(
"GetPatchMailItem: "
+
items
.
Count
+
" items found in "
+
inbox
.
FolderPath
);
// First filter out older items
items
=
items
.
Restrict
(
"[ReceivedTime] >= '"
+
patch
.
CreationDate
.
ToString
(
"g"
)
+
"'"
);
Log
.
Verbose
(
"GetPatchMailItem: Items since receival of patch: "
+
items
?.
Count
??
"0"
);
Outlook
.
UserDefinedProperties
up
=
inbox
.
UserDefinedProperties
;
if
(
up
.
Find
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_ID
)
==
null
)
{
up
.
Add
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_ID
,
Outlook
.
OlUserPropertyType
.
olText
);
}
// Now find the one with the respective patch id
string
filter
=
string
.
Format
(
"[{0}] = '{1}'"
,
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_ID
,
patch
.
Id
);
items
=
items
.
Restrict
(
filter
);
if
(
items
.
Count
>
1
)
{
Log
.
Error
(
"GetPatchMailItem: More than one item found with patch id "
+
patch
.
Id
);
}
else
if
(
items
.
Count
<
1
)
{
Log
.
Error
(
"GetPatchMailItem: No item found with patch id "
+
patch
.
Id
);
}
else
{
return
items
[
1
]
as
Outlook
.
MailItem
;
}
}
else
{
Log
.
Verbose
(
"GetPatchMailItem: No items were found or folder was null."
);
}
}
catch
(
Exception
ex
)
{
Log
.
Error
(
"GetPatchMailItem: Error occured. "
+
ex
);
}
finally
{
inbox
=
null
;
items
=
null
;
}
return
null
;
}
/// <summary>
/// Performs the given post action.
/// </summary>
/// <param name="patch">The patch to post.</param>
/// <param name="me">The own identity.</param>
/// <param name="postAction">The POST action to perform.</param>
/// <returns></returns>
private
async
Task
<
Exception
>
PostAsync
(
Patch
patch
,
PEPIdentity
me
,
PostAction
postAction
)
{
// Determine the correct method to execute
Task
<
HttpResponseMessage
>
postTask
=
null
;
switch
(
postAction
)
{
case
PostAction
.
Reject
:
postTask
=
DPEWebClient
.
RejectPatch
(
patch
,
me
);
break
;
case
PostAction
.
Suggest
:
postTask
=
DPEWebClient
.
SuggestPatch
(
patch
,
me
);
break
;
case
PostAction
.
Support
:
postTask
=
DPEWebClient
.
SupportPatch
(
patch
,
me
);
break
;
default
:
Log
.
ErrorAndFailInDebugMode
(
"PostAsync: Unknown post action."
);
break
;
}
// Execute the task and return status
return
await
postTask
.
ContinueWith
((
task
)
=>
{
if
(
task
.
Exception
!=
null
)
{
Log
.
Error
(
"ExecuteAsync: Error executing POST of type "
+
Enum
.
GetName
(
typeof
(
PostAction
),
postAction
));
return
task
.
Exception
;
}
else
{
return
(
task
.
Result
.
StatusCode
!=
HttpStatusCode
.
OK
)
?
new
Exception
(
Enum
.
GetName
(
typeof
(
HttpStatusCode
),
task
.
Result
.
StatusCode
))
:
null
;
}
});
}
/// <summary>
/// Rejects a given patch.
/// </summary>
/// <param name="patch">The patch to reject.</param>
/// <param name="me">The own identity that rejects the patch.</param>
public
void
Reject
(
Patch
patch
,
PEPIdentity
me
)
public
async
Task
Reject
(
Patch
patch
,
PEPIdentity
me
)
{
DPEWebClient
.
RejectPatch
(
patch
,
me
);
if
(
await
this
.
PostAsync
(
patch
,
me
,
PostAction
.
Reject
)
is
Exception
ex
)
{
throw
ex
;
}
this
.
UpdatePatchMailItem
(
patch
,
PatchStatus
.
Rejected
);
AdapterExtensions
.
ShowNotification
(
"Patch rejected"
,
patch
.
CommitMessage
);
}
/// <summary>
/// Updates the patch mail item after a successful change in the patch status.
/// </summary>
/// <param name="patch">The corresponding patch.</param>
/// <param name="patchStatus">The new patch status.</param>
/// <returns>True if the mail item was updated correctly, otherwise false.</returns>
private
bool
UpdatePatchMailItem
(
Patch
patch
,
PatchStatus
patchStatus
)
{
Outlook
.
MailItem
omi
=
null
;
try
{
omi
=
this
.
GetPatchMailItem
(
patch
);
// Update the user properties
if
(
omi
!=
null
)
{
omi
.
SetUserProperty
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_STATUS
,
(
int
)
patchStatus
);
omi
.
SetUserProperty
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_EDIT_DATE
,
DateTime
.
UtcNow
);
omi
.
Save
();
}
}
catch
(
Exception
ex
)
{
Log
.
Error
(
"UpdatePatchMailItem: Error occured. "
+
ex
);
return
false
;
}
return
true
;
}
/// <summary>
/// Subscribes to the given patch events.
/// </summary>
...
...
@@ -144,9 +307,13 @@ namespace pEp.DPE
/// </summary>
/// <param name="patch">The patch to suggest.</param>
/// <param name="me">The own identity that suggests the patch.</param>
public
void
Suggest
(
Patch
patch
,
PEPIdentity
me
)
public
async
Task
Suggest
(
Patch
patch
,
PEPIdentity
me
)
{
DPEWebClient
.
SuggestPatch
(
patch
,
me
);
if
(
await
this
.
PostAsync
(
patch
,
me
,
PostAction
.
Suggest
)
is
Exception
ex
)
{
throw
ex
;
}
AdapterExtensions
.
ShowNotification
(
"Patch suggested"
,
patch
.
CommitMessage
);
}
...
...
@@ -155,9 +322,14 @@ namespace pEp.DPE
/// </summary>
/// <param name="patch">The patch to support.</param>
/// <param name="me">The own identity that supports the patch.</param>
public
void
Support
(
Patch
patch
,
PEPIdentity
me
)
public
async
Task
Support
(
Patch
patch
,
PEPIdentity
me
)
{
DPEWebClient
.
SupportPatch
(
patch
,
me
);
if
(
await
this
.
PostAsync
(
patch
,
me
,
PostAction
.
Support
)
is
Exception
ex
)
{
throw
ex
;
}
this
.
UpdatePatchMailItem
(
patch
,
PatchStatus
.
Supported
);
AdapterExtensions
.
ShowNotification
(
"Patch supported"
,
patch
.
CommitMessage
);
}
...
...
DPE/Interfaces/IDistributedPolicyEngine.cs
View file @
78ac1768
using
System
;
using
System.Threading.Tasks
;
namespace
pEp.DPE.Interfaces
{
...
...
@@ -6,8 +7,8 @@ namespace pEp.DPE.Interfaces
{
void
Subscribe
(
PatchEvents
patchEvents
);
void
Unsubscribe
(
PatchEvents
patchEvents
);
void
Suggest
(
Patch
patch
,
PEPIdentity
me
);
void
Support
(
Patch
patch
,
PEPIdentity
me
);
void
Reject
(
Patch
patch
,
PEPIdentity
me
);
Task
Suggest
(
Patch
patch
,
PEPIdentity
me
);
Task
Support
(
Patch
patch
,
PEPIdentity
me
);
Task
Reject
(
Patch
patch
,
PEPIdentity
me
);
}
}
Extensions/MailItemExtensions.cs
View file @
78ac1768
...
...
@@ -19,6 +19,7 @@ namespace pEp
{
public
const
string
USER_PROPERTY_KEY_DPE_PATCH_STATUS
=
"patchStatus"
;
public
const
string
USER_PROPERTY_KEY_DPE_PATCH_EDIT_DATE
=
"patchEditDate"
;
public
const
string
USER_PROPERTY_KEY_DPE_PATCH_ID
=
"patchId"
;
public
const
string
USER_PROPERTY_KEY_INSPECTOR_CLOSED
=
"inspectorClosed"
;
public
const
string
USER_PROPERTY_KEY_IS_INCOMING
=
"isIncoming"
;
public
const
string
USER_PROPERTY_KEY_IS_MIRROR
=
"isMirror"
;
...
...
UI/FormRegionDPE.cs
View file @
78ac1768
using
pEp.DPE
;
using
pEp.UI.ViewModels
;
using
System
;
using
System.ComponentModel
;
using
Outlook
=
Microsoft
.
Office
.
Interop
.
Outlook
;
namespace
pEp
...
...
@@ -36,12 +35,12 @@ namespace pEp
string
xml
=
omi
.
HTMLBody
;
Patch
patch
=
Patch
.
Deserialize
(
xml
);
FormControlPatchViewModel
.
PatchStatus
patchStatus
=
FormControlPatchViewModel
.
PatchStatus
.
Open
;
DistributedPolicyEngine
.
PatchStatus
patchStatus
=
DistributedPolicyEngine
.
PatchStatus
.
Open
;
DateTime
?
editDate
=
null
;
// Get patch status if available
if
((
omi
.
GetUserProperty
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_STATUS
,
FormControlPatchViewModel
.
PatchStatus
.
Open
)
is
string
patchStatusString
)
&&
Enum
.
TryParse
(
patchStatusString
,
out
FormControlPatchViewModel
.
PatchStatus
status
))
if
((
omi
.
GetUserProperty
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_STATUS
,
DistributedPolicyEngine
.
PatchStatus
.
Open
)
is
string
patchStatusString
)
&&
Enum
.
TryParse
(
patchStatusString
,
out
DistributedPolicyEngine
.
PatchStatus
status
))
{
patchStatus
=
status
;
}
...
...
@@ -53,16 +52,10 @@ namespace pEp
editDate
=
savedEditDate
;
}
// Get the patch submitter
// Get the patch submitter
and set data context
if
(
PEPIdentity
.
GetFromIdentity
(
omi
,
out
PEPIdentity
submitter
)
==
Globals
.
ReturnStatus
.
Success
)
{
this
.
FormControlPatchView
.
DataContext
=
new
FormControlPatchViewModel
(
patch
,
submitter
,
patchStatus
,
editDate
);
// Subscribe to property changed event
if
(
this
.
FormControlPatchView
.
DataContext
is
FormControlPatchViewModel
formControlPatchViewModel
)
{
formControlPatchViewModel
.
PropertyChanged
+=
this
.
FormRegionDPE_PropertyChanged
;
}
}
else
{
...
...
@@ -79,55 +72,11 @@ namespace pEp
}
}
/// <summary>
/// Event handler for when a property in the associated view model changes.
/// </summary>
private
void
FormRegionDPE_PropertyChanged
(
object
sender
,
PropertyChangedEventArgs
e
)
{
// Set patch status and edit date as user properties if being changed
if
((
e
.
PropertyName
==
nameof
(
FormControlPatchViewModel
.
Status
))
||
(
e
.
PropertyName
==
nameof
(
FormControlPatchViewModel
.
EditDate
)))
{
Outlook
.
MailItem
omi
=
null
;
try
{
omi
=
this
.
OutlookItem
as
Outlook
.
MailItem
;
FormControlPatchViewModel
.
PatchStatus
patchStatus
=
(
sender
as
FormControlPatchViewModel
).
Status
;
DateTime
?
editDate
=
(
sender
as
FormControlPatchViewModel
).
EditDate
;
if
(
patchStatus
!=
FormControlPatchViewModel
.
PatchStatus
.
Open
)
{
omi
.
SetUserProperty
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_STATUS
,
Enum
.
GetName
(
typeof
(
FormControlPatchViewModel
.
PatchStatus
),
patchStatus
));
}
if
(
editDate
!=
null
)
{
omi
.
SetUserProperty
(
MailItemExtensions
.
USER_PROPERTY_KEY_DPE_PATCH_EDIT_DATE
,
editDate
?.
ToString
(
"f"
));
}
omi
.
Save
();
}
catch
(
Exception
ex
)
{
Log
.
Error
(
"FormRegionDPE_PropertyChanged: Error setting user property. "
+
ex
);
}
finally
{
omi
=
null
;
}
}
}
// Occurs when the form region is closed.
// Use this.OutlookItem to get a reference to the current Outlook item.
// Use this.OutlookFormRegion to get a reference to the form region.
private
void
FormRegionDPE_FormRegionClosed
(
object
sender
,
EventArgs
e
)
{
// Unsubscribe from property changed event
if
(
this
.
FormControlPatchView
.
DataContext
is
FormControlPatchViewModel
formControlPatchViewModel
)
{
formControlPatchViewModel
.
PropertyChanged
-=
this
.
FormRegionDPE_PropertyChanged
;
}
}
}
}
UI/ViewModels/FormControlPatchViewModel.cs
View file @
78ac1768
using
pEp.DPE
;
using
pEp.UI.Models
;
using
System
;
using
System.Threading.Tasks
;
using
System.Windows
;
using
System.Windows.Documents
;
using
System.Windows.Media
;
...
...
@@ -7,23 +10,15 @@ namespace pEp.UI.ViewModels
{
internal
class
FormControlPatchViewModel
:
ViewModelBase
{
public
enum
PatchStatus
{
Open
,
Accepted
,
Supported
,
Rejected
}
#
region
Fields
private
readonly
Patch
patch
;
private
Brush
_Background
=
Brushes
.
White
;
private
FlowDocument
_DisplayDiff
=
null
;
private
DateTime
?
_EditDate
=
null
;
private
string
_Explanation
=
null
;
private
PatchStatus
_Status
=
PatchStatus
.
Open
;
private
Brush
_Background
=
Brushes
.
White
;
private
FlowDocument
_DisplayDiff
=
null
;
private
DateTime
?
_EditDate
=
null
;
private
string
_Explanation
=
null
;
private
DistributedPolicyEngine
.
PatchStatus
_Status
=
DistributedPolicyEngine
.
PatchStatus
.
Open
;
#
endregion
...
...
@@ -93,7 +88,7 @@ namespace pEp.UI.ViewModels
/// <summary>
/// The command to accept the patch dialog.
/// </summary>
public
RelayCommand
OKButtonCommand
=>
new
RelayCommand
(
this
.
SupportPatch
,
p
=>
(
this
.
Status
==
PatchStatus
.
Open
));
public
RelayCommand
OKButtonCommand
=>
new
RelayCommand
(
this
.
SupportPatch
,
p
=>
(
this
.
Status
==
DistributedPolicyEngine
.
PatchStatus
.
Open
));
/// <summary>
/// Gets the OK button text.
...
...
@@ -103,7 +98,7 @@ namespace pEp.UI.ViewModels
/// <summary>
/// The command to reject the dialog.
/// </summary>
public
RelayCommand
RejectButtonCommand
=>
new
RelayCommand
(
this
.
RejectPatch
,
p
=>
(
this
.
Status
==
PatchStatus
.
Open
));
public
RelayCommand
RejectButtonCommand
=>
new
RelayCommand
(
this
.
RejectPatch
,
p
=>
(
this
.
Status
==
DistributedPolicyEngine
.
PatchStatus
.
Open
));
/// <summary>
/// Gets the Reject button text.
...
...
@@ -118,7 +113,7 @@ namespace pEp.UI.ViewModels
/// <summary>
/// Gets or sets the status of this patch.
/// </summary>
public
PatchStatus
Status
{
get
=>
this
.
_Status
;
set
=>
this
.
SetProperty
(
ref
this
.
_Status
,
value
);
}
public
DistributedPolicyEngine
.
PatchStatus
Status
{
get
=>
this
.
_Status
;
set
=>
this
.
SetProperty
(
ref
this
.
_Status
,
value
);
}
/// <summary>
/// Gets or sets the tag of the patch.
...
...
@@ -157,7 +152,7 @@ namespace pEp.UI.ViewModels
/// <param name="submitter">The submitter of the patch.</param>
/// <param name="status">The status of the patch.</param>
/// <param name="editDate">The last time this patch was edited (accepted/supported/rejected).</param>
public
FormControlPatchViewModel
(
Patch
patch
,
PEPIdentity
submitter
,
PatchStatus
status
=
PatchStatus
.
Open
,
DateTime
?
editDate
=
null
)
public
FormControlPatchViewModel
(
Patch
patch
,
PEPIdentity
submitter
,
DistributedPolicyEngine
.
PatchStatus
status
=
DistributedPolicyEngine
.
PatchStatus
.
Open
,
DateTime
?
editDate
=
null
)
{
this
.
EditDate
=
editDate
;
this
.
patch
=
patch
;
...
...
@@ -175,10 +170,24 @@ namespace pEp.UI.ViewModels
/// Rejects this patch.
/// </summary>
/// <param name="parameter">The command parameter.</param>
private
void
RejectPatch
(
object
parameter
)
private
async
void
RejectPatch
(
object
parameter
)
{
Globals
.
ThisAddIn
.
DistributedPolicyEngine
.
Reject
(
this
.
patch
,
new
PEPIdentity
());
this
.
UpdateView
(
PatchStatus
.
Rejected
);
try
{
await
Globals
.
ThisAddIn
.
DistributedPolicyEngine
.
Reject
(
this
.
patch
,
new
PEPIdentity
());
}
catch
(
Exception
ex
)
{
while
(
ex
.
InnerException
!=
null
)
{
ex
=
ex
.
InnerException
;
}
CustomMessageBox
.
ShowDialog
(
ex
.
Message
,
"Error"
,
"OK"
);
return
;
}
this
.
UpdateView
(
DistributedPolicyEngine
.
PatchStatus
.
Rejected
);
}
/// <summary>
...
...
@@ -194,16 +203,16 @@ namespace pEp.UI.ViewModels
switch
(
this
.
Status
)
{
case
PatchStatus
.
Accepted
:
case
DistributedPolicyEngine
.
PatchStatus
.
Accepted
:
this
.
Explanation
=
$"Accepted on
{
editDate
}
"
;
break
;
case
PatchStatus
.
Supported
:
case
DistributedPolicyEngine
.
PatchStatus
.
Supported
:
this
.
Explanation
=
$"Supported on
{
editDate
}
"
;
break
;
case
PatchStatus
.
Rejected
:
case
DistributedPolicyEngine
.
PatchStatus
.
Rejected
:
this
.
Explanation
=
$"Rejected on
{
editDate
}
"
;
break
;
case
PatchStatus
.
Open
:
case
DistributedPolicyEngine
.
PatchStatus
.
Open
:
default
:
this
.
Explanation
=
"New configuration changes pending approval"
;
break
;
...
...
@@ -214,23 +223,39 @@ namespace pEp.UI.ViewModels
/// Supports this patch.
/// </summary>
/// <param name="parameter">The command parameter.</param>
private
void
SupportPatch
(
object
parameter
)
private
async
void
SupportPatch
(
object
parameter
)
{
Globals
.
ThisAddIn
.
DistributedPolicyEngine
.
Support
(
this
.
patch
,
new
PEPIdentity
());
this
.
UpdateView
(
PatchStatus
.
Supported
);
try
{
await
Globals
.
ThisAddIn
.
DistributedPolicyEngine
.
Support
(
this
.
patch
,
new
PEPIdentity
());
}
catch
(
Exception
ex
)
{
Log
.
Error
(
"SupportPatch: Error occured. "
+
ex
);
while
(
ex
.
InnerException
!=
null
)
{
ex
=
ex
.
InnerException
;
}
CustomMessageBox
.
ShowDialog
(
ex
.
Message
,
"Error"
,
"OK"
);
return
;
}
this
.
UpdateView
(
DistributedPolicyEngine
.
PatchStatus
.
Supported
);
}
/// <summary>
/// Updates the view according to a new patch status.
/// </summary>
/// <param name="patchStatus">The new patch status.</param>
private
void
UpdateView
(
PatchStatus
patchStatus
)
private
void
UpdateView
(
DistributedPolicyEngine
.
PatchStatus
patchStatus
)
{
this
.
Status
=
patchStatus
;
this
.
EditDate
=
DateTime
.
UtcNow
;
this
.
SetExplanation
();
this
.
DisplayDiff
=
PatchDialogViewModel
.
FormatDiff
(
this
.
Diff
,
this
.
Status
==
PatchStatus
.
Open
);
this
.
Background
=
(
patchStatus
==
PatchStatus
.
Open
)
?
Brushes
.
White
:
Brushes
.
WhiteSmoke
;
this
.
DisplayDiff
=
PatchDialogViewModel
.
FormatDiff
(
this
.
Diff
,
this
.
Status
==
DistributedPolicyEngine
.
PatchStatus
.
Open
);
this
.
Background
=
(
patchStatus
==
DistributedPolicyEngine
.
PatchStatus
.
Open
)
?
Brushes
.
White
:
Brushes
.
WhiteSmoke
;
}
#
endregion
...
...
UI/ViewModels/PatchDialogViewModel.cs
View file @
78ac1768
...
...
@@ -621,7 +621,6 @@ namespace pEp.UI.ViewModels
#
region
Static
methods
/// <summary>
/// Formats the diff displaying colors of changes.
/// </summary>
...
...
UI/Views/PatchDialogView.xaml
View file @
78ac1768
...
...
@@ -98,6 +98,7 @@
<Button Content="{Binding OKButtonText}"
Command="{Binding OKButtonCommand}"
IsEnabled="{Binding IsValid}"
IsDefault="True"
Margin="10"
Style="{StaticResource StyleButtonGray}"/>
<Button Content="{Binding CancelButtonText}"
...
...