OUT-445: Implement Update Now button. Change to adapter function needed until it works fully. OUT-445
authorThomas
Tue, 22 May 2018 09:49:37 +0200
branchOUT-445
changeset 2205 4299ea51fbf6
parent 2204 94aaeb734ef2
child 2212 02f58420dce0
OUT-445: Implement Update Now button. Change to adapter function needed until it works fully.
Properties/Resources.Designer.cs
Properties/Resources.de.resx
Properties/Resources.resx
UI/FormControlOptions.xaml
UI/FormControlOptions.xaml.cs
--- a/Properties/Resources.Designer.cs	Fri May 18 12:14:05 2018 +0200
+++ b/Properties/Resources.Designer.cs	Tue May 22 09:49:37 2018 +0200
@@ -1356,6 +1356,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Check for update.
+        /// </summary>
+        public static string Options_CheckForUpdate {
+            get {
+                return ResourceManager.GetString("Options_CheckForUpdate", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Store messages securely for these accounts:.
         /// </summary>
         public static string Options_EncryptedAccountsText {
@@ -1527,6 +1536,24 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Looking for updates....
+        /// </summary>
+        public static string Options_LookingForUpdate {
+            get {
+                return ResourceManager.GetString("Options_LookingForUpdate", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to No updates found.
+        /// </summary>
+        public static string Options_NoUpdateFound {
+            get {
+                return ResourceManager.GetString("Options_NoUpdateFound", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to OK.
         /// </summary>
         public static string Options_OKText {
@@ -1671,6 +1698,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Update found. The installer will be launched..
+        /// </summary>
+        public static string Options_UpdateFound {
+            get {
+                return ResourceManager.GetString("Options_UpdateFound", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Cc.
         /// </summary>
         public static string PreviewMessage_CcText {
--- a/Properties/Resources.de.resx	Fri May 18 12:14:05 2018 +0200
+++ b/Properties/Resources.de.resx	Tue May 22 09:49:37 2018 +0200
@@ -819,4 +819,16 @@
   <data name="KeySyncWizard_PEPSuccessOtherKeyUsedAsDefault" xml:space="preserve">
     <value>Der Schlüssel von Ihrem anderen Gerät wird nun standardmäßig verwendet.</value>
   </data>
+  <data name="Options_CheckForUpdate" xml:space="preserve">
+    <value>Nach Update suchen</value>
+  </data>
+  <data name="Options_LookingForUpdate" xml:space="preserve">
+    <value>Es wird nach einem Update gesucht ...</value>
+  </data>
+  <data name="Options_NoUpdateFound" xml:space="preserve">
+    <value>Es wurde kein Update gefunden</value>
+  </data>
+  <data name="Options_UpdateFound" xml:space="preserve">
+    <value>Update gefunden. Der Installer wird automatisch geöffnet.</value>
+  </data>
 </root>
\ No newline at end of file
--- a/Properties/Resources.resx	Fri May 18 12:14:05 2018 +0200
+++ b/Properties/Resources.resx	Tue May 22 09:49:37 2018 +0200
@@ -907,4 +907,16 @@
   <data name="KeySyncWizard_PEPSuccessOtherKeyUsed" xml:space="preserve">
     <value>The key from your other device will now also be used to decrypt messages.</value>
   </data>
+  <data name="Options_CheckForUpdate" xml:space="preserve">
+    <value>Check for update</value>
+  </data>
+  <data name="Options_LookingForUpdate" xml:space="preserve">
+    <value>Looking for updates...</value>
+  </data>
+  <data name="Options_NoUpdateFound" xml:space="preserve">
+    <value>No updates found</value>
+  </data>
+  <data name="Options_UpdateFound" xml:space="preserve">
+    <value>Update found. The installer will be launched.</value>
+  </data>
 </root>
\ No newline at end of file
--- a/UI/FormControlOptions.xaml	Fri May 18 12:14:05 2018 +0200
+++ b/UI/FormControlOptions.xaml	Tue May 22 09:49:37 2018 +0200
@@ -691,8 +691,10 @@
                         <RowDefinition Height="Auto" />
                         <RowDefinition Height="Auto" />
                         <RowDefinition Height="Auto" />
+                        <RowDefinition Height="*" />
                         <RowDefinition Height="Auto" />
-                        <RowDefinition Height="*" />
+                        <RowDefinition Height="Auto" />
+                        <RowDefinition Height="Auto" />
                     </Grid.RowDefinitions>
 
                     <!-- About title -->
@@ -771,7 +773,7 @@
                     <Grid Grid.Row="5"
                           VerticalAlignment="Bottom">
                         <Grid.Margin>
-                            <Thickness Bottom="{StaticResource PageBottomSpacing}"
+                            <Thickness Bottom="{StaticResource PageSubSectionSpacing}"
                                        Left="{StaticResource PageLeftSpacing}"
                                        Right="0"
                                        Top="0" />
@@ -801,6 +803,48 @@
                                        Margin="{StaticResource CheckBoxContentMarginWhenCenter}" />
                         </CheckBox>
                     </Grid>
+                    <Label Grid.Row="6"
+                           x:Name="LookingForUpdateLabel"
+                           Content="{Binding Path=LookingForUpdateLabelText}"
+                           Visibility="{Binding Path=LookingForUpdateLabelVisibility}">
+                        <Label.Margin>
+                            <Thickness Bottom="0"
+                                       Left="{StaticResource PageLeftSpacing}"
+                                       Right="0"
+                                       Top="0">
+                            </Thickness>
+                        </Label.Margin>
+                    </Label>
+                    <Button Grid.Row="7"
+                            Content="{x:Static p:Resources.Options_CheckForUpdate}"
+                            Style="{StaticResource StyleConfirmButton}"
+                            HorizontalAlignment="Left"
+                            Padding="{StaticResource ButtonPaddingStandard}"
+                            Click="ButtonCheckForUpdates_Click"
+                            Visibility="{Binding Path=IsCheckingForUpdates, Converter={StaticResource InvertBoolToVisibility}}">
+                        <Button.Margin>
+                            <Thickness Bottom="{StaticResource PageBottomSpacing}"
+                                       Left="{StaticResource PageLeftSpacing}"
+                                       Right="0"
+                                       Top="{StaticResource PageSubSectionSpacing}">
+                            </Thickness>
+                        </Button.Margin>
+                    </Button>
+                    <Button Grid.Row="7"
+                            Content="{x:Static p:Resources.Options_CancelText}"
+                            Style="{StaticResource StyleWrongButton}"
+                            HorizontalAlignment="Left"
+                            Padding="{StaticResource ButtonPaddingStandard}"
+                            Click="ButtonCheckForUpdatesCancel_Click"
+                            Visibility="{Binding Path=IsCheckingForUpdates, Converter={StaticResource BoolToVisibility}}">
+                        <Button.Margin>
+                            <Thickness Bottom="{StaticResource PageBottomSpacing}"
+                                       Left="{StaticResource PageLeftSpacing}"
+                                       Right="0"
+                                       Top="{StaticResource PageSubSectionSpacing}">
+                            </Thickness>
+                        </Button.Margin>
+                    </Button>
                 </Grid>
             </TabItem>
 
--- a/UI/FormControlOptions.xaml.cs	Fri May 18 12:14:05 2018 +0200
+++ b/UI/FormControlOptions.xaml.cs	Tue May 22 09:49:37 2018 +0200
@@ -121,6 +121,50 @@
         }
 
         /// <summary>
+        /// Event handler for when the Check for updates button is pressed.
+        /// </summary>
+        private void ButtonCheckForUpdates_Click(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                this.displayState.IsCheckingForUpdates = true;
+                this.displayState.LookingForUpdateLabelText = Properties.Resources.Options_LookingForUpdate;
+                this.displayState.LookingForUpdateLabelVisibility = Visibility.Visible;
+                System.Threading.Tasks.Task.Factory.StartNew(new Action(() =>
+                {
+                    // TODO: This method has to return a status whether an update has been found or not
+                    ThisAddIn.PEPEngine.UpdateNow();
+                }), System.Threading.Tasks.TaskCreationOptions.LongRunning).ContinueWith((result) =>
+                 {
+                     this.displayState.IsCheckingForUpdates = false;
+
+                     // TODO: Adjust this condition to the return status of the UpdateNow() method
+                     if (result.IsCompleted)
+                     {
+                         this.displayState.LookingForUpdateLabelText = Properties.Resources.Options_UpdateFound;
+                     }
+                     else
+                     {
+                         this.displayState.LookingForUpdateLabelText = Properties.Resources.Options_NoUpdateFound;
+                     }
+                 });
+            }
+            catch (Exception ex)
+            {
+                Log.Error("ButtonCheckForUpdates_Click: Error checking for updates. " + ex.ToString());
+                this.displayState.IsCheckingForUpdates = false;
+            }
+        }
+
+        /// <summary>
+        /// Event handler for when the Cancel to check for updates button is pressed.
+        /// </summary>
+        private void ButtonCheckForUpdatesCancel_Click(object sender, RoutedEventArgs e)
+        {
+            this.displayState.IsCheckingForUpdates = false;
+        }
+
+        /// <summary>
         /// Event handler for when the OK button is pressed.
         /// </summary>
         private void ButtonOK_Click(object sender, RoutedEventArgs e)
@@ -351,6 +395,7 @@
             private bool                                    _IsAutoUpdateEnabled;
             private string                                  _IsAutoUpdateEnabledText;
             private bool                                    _IsBlacklistAddEnabled;
+            private bool                                    _IsCheckingForUpdates;
             private bool                                    _IsDeveloperModeEnabled;
             private bool                                    _IsEncryptAllAccountsEnabled;
             private string                                  _IsEncryptAllAccountsEnabledText;
@@ -378,6 +423,8 @@
             private string                                  _LogOutlook;
             private string                                  _LogOutlookText;
             private string                                  _LogRefreshText;
+            private string                                  _LookingForUpdateLabelText;
+            private Visibility                              _LookingForUpdateLabelVisibility;
             private string                                  _OKText;
             private string                                  _OpenKeyManagerText;
             private string                                  _PageAboutText;
@@ -614,6 +661,22 @@
                 get { return (this._IsBlacklistAddEnabled); }
             }
 
+
+            /// <summary>
+            /// Gets or sets whether we are currently checking for updates.
+            /// </summary>
+            public bool IsCheckingForUpdates
+            {
+                get { return (this._IsCheckingForUpdates); }
+                set
+                {
+                    this._IsCheckingForUpdates = value;
+                    this.RaisePropertyChangedEvent(nameof(this.IsCheckingForUpdates));
+
+                    this.CalcDependentProperties();
+                }
+            }
+
             /// <summary>
             /// Gets or sets whether developer mode is enabled.
             /// </summary>
@@ -930,6 +993,32 @@
             }
 
             /// <summary>
+            /// Gets or sets the text for the Looking for updates label
+            /// </summary>
+            public string LookingForUpdateLabelText
+            {
+                get { return (this._LookingForUpdateLabelText); }
+                set
+                {
+                    this._LookingForUpdateLabelText = value;
+                    this.RaisePropertyChangedEvent(nameof(this.LookingForUpdateLabelText));
+                }
+            }
+
+            /// <summary>
+            /// Gets or sets the visibility for the Looking for updates label
+            /// </summary>
+            public Visibility LookingForUpdateLabelVisibility
+            {
+                get { return (this._LookingForUpdateLabelVisibility); }
+                set
+                {
+                    this._LookingForUpdateLabelVisibility = value;
+                    this.RaisePropertyChangedEvent(nameof(this.LookingForUpdateLabelVisibility));
+                }
+            }
+
+            /// <summary>
             /// Gets the OK button text.
             /// </summary>
             public string OKText
@@ -1291,6 +1380,7 @@
 
                 copy.IsAdvancedEnabled = this._IsAdvancedEnabled;
                 copy.IsAutoUpdateEnabled = this._IsAutoUpdateEnabled;
+                copy.IsCheckingForUpdates = this._IsCheckingForUpdates;
                 copy.IsDeveloperModeEnabled = this._IsDeveloperModeEnabled;
                 copy.IsEncryptAllAccountsEnabled = this._IsEncryptAllAccountsEnabled;
                 copy.IsKeyServerUsed = this._IsKeyServerUsed;
@@ -1341,6 +1431,7 @@
                 this._BlacklistSelectedIndex = -1;
                 this._IsAdvancedEnabled = false;
                 this._IsAutoUpdateEnabled = PEPSettings.IS_AUTO_UPDATE_ENABLED_DEFAULT;
+                this._IsCheckingForUpdates = false;
                 this._IsDeveloperModeEnabled = PEPSettings.IS_DEVELOPER_MODE_ENABLED_DEFAULT;
                 this._IsEncryptAllAccountsEnabled = PEPSettings.IS_ENCRYPT_ALL_ACCOUNTS_ENABLED_DEFAULT;
                 this._IsKeyServerUsed = PEPSettings.IS_KEY_SERVER_USED_DEFAULT;
@@ -1355,6 +1446,7 @@
                 this._IsVerboseLoggingEnabled = PEPSettings.IS_VERBOSE_LOGGING_ENABLED_DEFAULT;
                 this._LogEngine = null;
                 this._LogOutlook = null;
+                this._LookingForUpdateLabelVisibility = Visibility.Hidden;
                 this._PEPCopyright = null;
                 this._PEPCredits = null;
                 this._PEPName = null;
@@ -1375,6 +1467,7 @@
                 this.RaisePropertyChangedEvent(nameof(this.BlacklistSelectedIndex));
                 this.RaisePropertyChangedEvent(nameof(this.IsAdvancedEnabled));
                 this.RaisePropertyChangedEvent(nameof(this.IsAutoUpdateEnabled));
+                this.RaisePropertyChangedEvent(nameof(this.IsCheckingForUpdates));
                 this.RaisePropertyChangedEvent(nameof(this.IsDeveloperModeEnabled));
                 this.RaisePropertyChangedEvent(nameof(this.IsEncryptAllAccountsEnabled));
                 this.RaisePropertyChangedEvent(nameof(this.IsKeyServerUsed));
@@ -1389,6 +1482,7 @@
                 this.RaisePropertyChangedEvent(nameof(this.IsVerboseLoggingEnabled));
                 this.RaisePropertyChangedEvent(nameof(this.LogEngine));
                 this.RaisePropertyChangedEvent(nameof(this.LogOutlook));
+                this.RaisePropertyChangedEvent(nameof(this.LookingForUpdateLabelVisibility));
                 this.RaisePropertyChangedEvent(nameof(this.PEPCopyright));
                 this.RaisePropertyChangedEvent(nameof(this.PEPCredits));
                 this.RaisePropertyChangedEvent(nameof(this.PEPName));
@@ -1422,6 +1516,7 @@
                 this._LogEngineText = pEp.Properties.Resources.Options_LogEngineText;
                 this._LogOutlookText = pEp.Properties.Resources.Options_LogOutlookText;
                 this._LogRefreshText = pEp.Properties.Resources.Options_LogRefreshText;
+                this._LookingForUpdateLabelText = pEp.Properties.Resources.Options_LookingForUpdate;
                 this._OKText = pEp.Properties.Resources.Options_OKText;
                 this._OpenKeyManagerText = pEp.Properties.Resources.Options_OpenKeyManagerText;
                 this._PageAboutText = pEp.Properties.Resources.Options_PageAboutText;
@@ -1461,6 +1556,7 @@
                 this.RaisePropertyChangedEvent(nameof(this.LogEngineText));
                 this.RaisePropertyChangedEvent(nameof(this.LogOutlookText));
                 this.RaisePropertyChangedEvent(nameof(this.LogRefreshText));
+                this.RaisePropertyChangedEvent(nameof(this.LookingForUpdateLabelText));
                 this.RaisePropertyChangedEvent(nameof(this.OKText));
                 this.RaisePropertyChangedEvent(nameof(this.OpenKeyManagerText));
                 this.RaisePropertyChangedEvent(nameof(this.PageAboutText));