Changeset 1611


Ignore:
Timestamp:
Jun 9, 2010, 12:44:27 AM (12 years ago)
Author:
Paul Lelgemann
Message:

o CrypWin: P2P world button always visible
o Changed behaviour of command line option "-p2p" and "-peer2peer": triggers autoconnect to peer-to-peer network during startup of CrypTool
o P2PEditor: "Start" button disabled and moved to settings pane for consistency
o CrypP2P: local workspace path is set to "%TEMP%/CrypTool", if not specified before
+ PeerToPeerProxy has a new setting to enable autoconnecting the peer-to-peer network, if it is not connected during workspace start

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/P2PManager.cs

    r1589 r1611  
    1616
    1717using System;
    18 using System.Windows.Forms;
     18using System.IO;
    1919using Cryptool.P2P.Internal;
    2020using Cryptool.P2P.Worker;
     
    3636        {
    3737            P2PBase = new P2PBase(this);
     38            ValidateSettings();
    3839
    3940            // to forward event from overlay/dht MessageReceived-Event from P2PBase
     
    4748        public P2PBase P2PBase { get; private set; }
    4849        public bool IsP2PConnecting { get; internal set; }
     50        public bool IsAutoconnectConsoleOptionSet { get; set; }
    4951
    5052        #endregion
     
    8890        public void HandleConnectOnStartup()
    8991        {
    90             if (P2PSettings.Default.ConnectOnStartup && IsReadyToConnect())
     92            var isAutoconnectConfiguredOrRequested = P2PSettings.Default.ConnectOnStartup || IsAutoconnectConsoleOptionSet;
     93            var isReadyToConnect = IsReadyToConnect();
     94
     95            if (isReadyToConnect && isAutoconnectConfiguredOrRequested)
    9196            {
    9297                GuiLogMessage("Connect on startup enabled. Establishing connection...", NotificationLevel.Info);
     
    122127            if (OnPeerMessageReceived != null)
    123128                OnPeerMessageReceived(sourceAddr, data);
     129        }
     130
     131        private static void ValidateSettings()
     132        {
     133            if (String.IsNullOrEmpty(P2PSettings.Default.WorkspacePath))
     134            {
     135                var tempForUser = Path.Combine(Path.GetTempPath(), "CrypTool2");
     136                Directory.CreateDirectory(tempForUser);
     137                P2PSettings.Default.WorkspacePath = tempForUser;
     138                P2PSettings.Default.Save();
     139            }
    124140        }
    125141
  • trunk/CrypPlugins/P2PEditor/Distributed/DistributedJob.cs

    r1579 r1611  
    22using System.ComponentModel;
    33using System.IO;
    4 using System.Runtime.Serialization;
    54using Cryptool.P2P;
    65
     
    6059            // Avoid overwriting previous versions of this workspace or workspaces with common names by adding an integer prefix
    6160            LocalFilePath = Path.Combine(workspacePath, JobOwner + "_" + FileName);
    62             int counter = 0;
     61            var counter = 0;
    6362            while (File.Exists(LocalFilePath))
    6463            {
  • trunk/CrypPlugins/P2PEditor/P2PEditor.cs

    r1549 r1611  
    2020using System.Windows.Controls;
    2121using Cryptool.Core;
    22 using Cryptool.P2P;
    23 using Cryptool.P2P.Worker;
    2422using Cryptool.P2PEditor.Distributed;
    2523using Cryptool.P2PEditor.GUI;
     
    137135        public bool CanExecute
    138136        {
    139             get { return !P2PManager.Instance.IsP2PConnected() && !P2PManager.Instance.IsP2PConnecting; }
     137            get { return false; }
    140138        }
    141139
    142140        public bool CanStop
    143141        {
    144             // TODO design problem? when set to true, CrypWin will terminate execute Stop() (and terminate the P2P connection) when switching back to an AnotherEditor instance
    145             // get { return P2PManager.Instance.IsP2PConnected() && !P2PManager.Instance.IsP2PConnecting; }
    146142            get { return false; }
    147143        }
     
    180176        public void Execute()
    181177        {
    182             RunConnectionWorker();
    183         }
    184 
    185         private void RunConnectionWorker()
    186         {
    187             var connectionWorker = new ConnectionWorker(P2PManager.Instance.P2PBase);
    188             connectionWorker.BackgroundWorker.RunWorkerCompleted += ((P2PEditorPresentation) Presentation).ConnectionWorkerCompleted;
    189             connectionWorker.Start();
    190178        }
    191179
     
    200188        public void Stop()
    201189        {
    202             RunConnectionWorker();
    203190        }
    204191
     
    213200        public event PropertyChangedEventHandler PropertyChanged;
    214201
    215         public PluginManager PluginManager
    216         {
    217             get { return null; }
    218             set { }
    219         }
     202        public PluginManager PluginManager { get; set; }
    220203
    221204        #endregion
  • trunk/CrypPlugins/P2PEditor/P2PEditorSettings.cs

    r1604 r1611  
    1818using Cryptool.P2P;
    1919using Cryptool.P2P.Worker;
     20using Cryptool.P2PEditor.GUI;
    2021using Cryptool.PluginBase;
    2122using Cryptool.Plugins.PeerToPeer.Internal;
     
    2829        private readonly P2PSettings _settings;
    2930
    30         private const string GroupExpert = "advanced_settings";
     31        private const string GroupExperienced = "experienced_settings";
     32        private const string GroupExpert = "expert_settings";
    3133
    3234        public P2PEditorSettings(P2PEditor p2PEditor)
     
    9496        }
    9597
    96         [TaskPane("distributedJobListRefreshInterval_caption", "distributedJobListRefreshInterval_tooltip", null, 3, false, DisplayLevel.Experienced,
     98        [TaskPane("start_caption", "start_tooltip", null, 3, true, DisplayLevel.Beginner, ControlType.Button)]
     99        public void ButtonStart()
     100        {
     101            if (!P2PManager.Instance.IsP2PConnected() && !P2PManager.Instance.IsP2PConnecting)
     102            {
     103                RunConnectionWorker();
     104                OnPropertyChanged("ButtonStart");
     105                _p2PEditor.GuiLogMessage(Resources.Attributes.start_launched, NotificationLevel.Info);
     106            } else
     107            {
     108                _p2PEditor.GuiLogMessage(Resources.Attributes.start_failed, NotificationLevel.Warning);
     109            }
     110        }
     111
     112        [TaskPane("stop_caption", "stop_tooltip", null, 4, true, DisplayLevel.Beginner, ControlType.Button)]
     113        public void ButtonStop()
     114        {
     115            if (P2PManager.Instance.IsP2PConnected() && !P2PManager.Instance.IsP2PConnecting)
     116            {
     117                RunConnectionWorker();
     118                OnPropertyChanged("ButtonStop");
     119                _p2PEditor.GuiLogMessage(Resources.Attributes.stop_launched, NotificationLevel.Info);
     120            }
     121            else
     122            {
     123                _p2PEditor.GuiLogMessage(Resources.Attributes.stop_failed, NotificationLevel.Warning);
     124            }
     125        }
     126
     127        [TaskPane("distributedJobListRefreshInterval_caption", "distributedJobListRefreshInterval_tooltip", GroupExperienced, 0, false, DisplayLevel.Experienced,
    97128            ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
    98129        public int DistributedJobListRefreshInterval
     
    110141        }
    111142
    112         [TaskPane("connectOnStartup_caption", "onnectOnStartup_tooltip", null, 4, true, DisplayLevel.Experienced,
     143        [TaskPane("connectOnStartup_caption", "connectOnStartup_tooltip", GroupExperienced, 1, true, DisplayLevel.Experienced,
    113144            ControlType.CheckBox)]
    114145        public bool ConnectOnStartup
     
    126157        }
    127158
    128         // TODO make button obsolete - stop button should be fine, but is currently not suited (see todo in P2PEditor:Stop())
    129         [TaskPane("stop_caption", "stop_tooltip", null, 5, true, DisplayLevel.Beginner, ControlType.Button)]
    130         public void BtnStop()
    131         {
    132             if (P2PManager.Instance.IsP2PConnected() && !P2PManager.Instance.IsP2PConnecting)
    133             {
    134                 new ConnectionWorker(P2PManager.Instance.P2PBase).Start();
    135                 OnPropertyChanged("BtnStop");
    136             }
    137         }
    138 
    139         [TaskPane("linkmanager_caption", "linkmanager_tooltip", GroupExpert, 0, false, DisplayLevel.Professional,
     159        [TaskPane("linkmanager_caption", "linkmanager_tooltip", GroupExpert, 0, false, DisplayLevel.Expert,
    140160            ControlType.ComboBox, new[] {"Snal"})]
    141161        public int LinkManager
     
    153173        }
    154174
    155         [TaskPane("bootstrapper_caption", "bootstrapper_tooltip", GroupExpert, 1, false, DisplayLevel.Professional
     175        [TaskPane("bootstrapper_caption", "bootstrapper_tooltip", GroupExpert, 1, false, DisplayLevel.Expert
    156176            , ControlType.ComboBox, new[] {"LocalMachineBootstrapper", "IrcBootstrapper"})]
    157177        public int Bootstrapper
     
    169189        }
    170190
    171         [TaskPane("overlay_caption", "overlay_tooltip", GroupExpert, 2, false, DisplayLevel.Professional,
     191        [TaskPane("overlay_caption", "overlay_tooltip", GroupExpert, 2, false, DisplayLevel.Expert,
    172192            ControlType.ComboBox, new[] {"FullMeshOverlay"})]
    173193        public int Overlay
     
    185205        }
    186206
    187         [TaskPane("dht_caption", "dht_tooltip", GroupExpert, 3, false, DisplayLevel.Professional,
     207        [TaskPane("dht_caption", "dht_tooltip", GroupExpert, 3, false, DisplayLevel.Expert,
    188208            ControlType.ComboBox, new[] {"FullMeshDHT"})]
    189209        public int Dht
     
    201221        }
    202222
    203         [TaskPane("transportprotocol_caption", "transportprotocol_tooltip", GroupExpert, 3, false, DisplayLevel.Professional,
     223        [TaskPane("transportprotocol_caption", "transportprotocol_tooltip", GroupExpert, 3, false, DisplayLevel.Expert,
    204224            ControlType.ComboBox, new[] { "TCP", "TCP_UDP", "UDP" })]
    205225        public int TransportProtocol
     
    276296            P2PSettings.Default.Save();
    277297        }
     298
     299        private void RunConnectionWorker()
     300        {
     301            var connectionWorker = new ConnectionWorker(P2PManager.Instance.P2PBase);
     302            connectionWorker.BackgroundWorker.RunWorkerCompleted += ((P2PEditorPresentation)_p2PEditor.Presentation).ConnectionWorkerCompleted;
     303            connectionWorker.Start();
     304        }
    278305    }
    279306}
  • trunk/CrypPlugins/P2PEditor/Resources/Attributes.Designer.cs

    r1604 r1611  
    6262       
    6363        /// <summary>
    64         ///   Looks up a localized string similar to Advanced settings.
    65         /// </summary>
    66         internal static string advanced_settings {
    67             get {
    68                 return ResourceManager.GetString("advanced_settings", resourceCulture);
    69             }
    70         }
    71        
    72         /// <summary>
    7364        ///   Looks up a localized string similar to Bootstrapper type.
    7465        /// </summary>
     
    134125       
    135126        /// <summary>
    136         ///   Looks up a localized string similar to LinkManager type.
     127        ///   Looks up a localized string similar to Experienced settings.
     128        /// </summary>
     129        internal static string experienced_settings {
     130            get {
     131                return ResourceManager.GetString("experienced_settings", resourceCulture);
     132            }
     133        }
     134       
     135        /// <summary>
     136        ///   Looks up a localized string similar to Expert settings.
     137        /// </summary>
     138        internal static string expert_settings {
     139            get {
     140                return ResourceManager.GetString("expert_settings", resourceCulture);
     141            }
     142        }
     143       
     144        /// <summary>
     145        ///   Looks up a localized string similar to Link manager type.
    137146        /// </summary>
    138147        internal static string linkmanager_caption {
     
    143152       
    144153        /// <summary>
    145         ///   Looks up a localized string similar to LinkManager type.
     154        ///   Looks up a localized string similar to Link manager type.
    146155        /// </summary>
    147156        internal static string linkmanager_tooltip {
     
    233242       
    234243        /// <summary>
     244        ///   Looks up a localized string similar to Connect.
     245        /// </summary>
     246        internal static string start_caption {
     247            get {
     248                return ResourceManager.GetString("start_caption", resourceCulture);
     249            }
     250        }
     251       
     252        /// <summary>
     253        ///   Looks up a localized string similar to Cannot connect to the P2P network. You are already connected or a connection attempt is in progress..
     254        /// </summary>
     255        internal static string start_failed {
     256            get {
     257                return ResourceManager.GetString("start_failed", resourceCulture);
     258            }
     259        }
     260       
     261        /// <summary>
     262        ///   Looks up a localized string similar to Connection to the P2P network will be established in the background..
     263        /// </summary>
     264        internal static string start_launched {
     265            get {
     266                return ResourceManager.GetString("start_launched", resourceCulture);
     267            }
     268        }
     269       
     270        /// <summary>
     271        ///   Looks up a localized string similar to Connect to the P2P network..
     272        /// </summary>
     273        internal static string start_tooltip {
     274            get {
     275                return ResourceManager.GetString("start_tooltip", resourceCulture);
     276            }
     277        }
     278       
     279        /// <summary>
    235280        ///   Looks up a localized string similar to Disconnect.
    236281        /// </summary>
     
    242287       
    243288        /// <summary>
    244         ///   Looks up a localized string similar to Disconnect from P2P network. For debugging only..
     289        ///   Looks up a localized string similar to Cannot disconnect from the P2P network. You are not connected or a connection attempt is in progress..
     290        /// </summary>
     291        internal static string stop_failed {
     292            get {
     293                return ResourceManager.GetString("stop_failed", resourceCulture);
     294            }
     295        }
     296       
     297        /// <summary>
     298        ///   Looks up a localized string similar to Disconnecting from the P2P network..
     299        /// </summary>
     300        internal static string stop_launched {
     301            get {
     302                return ResourceManager.GetString("stop_launched", resourceCulture);
     303            }
     304        }
     305       
     306        /// <summary>
     307        ///   Looks up a localized string similar to Disconnect from P2P network..
    245308        /// </summary>
    246309        internal static string stop_tooltip {
  • trunk/CrypPlugins/P2PEditor/Resources/Attributes.resx

    r1604 r1611  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </resheader>
    120   <data name="advanced_settings" xml:space="preserve">
    121     <value>Advanced settings</value>
    122   </data>
    123120  <data name="bootstrapper_caption" xml:space="preserve">
    124121    <value>Bootstrapper type</value>
     
    142139    <value>Refreshes the the distributed job list in the given interval. A value of 0 will disable the automated process.</value>
    143140  </data>
     141  <data name="experienced_settings" xml:space="preserve">
     142    <value>Experienced settings</value>
     143  </data>
     144  <data name="expert_settings" xml:space="preserve">
     145    <value>Expert settings</value>
     146  </data>
    144147  <data name="linkmanager_caption" xml:space="preserve">
    145     <value>LinkManager type</value>
     148    <value>Link manager type</value>
    146149  </data>
    147150  <data name="linkmanager_tooltip" xml:space="preserve">
    148     <value>LinkManager type</value>
     151    <value>Link manager type</value>
    149152  </data>
    150153  <data name="localPort_caption" xml:space="preserve">
     
    175178    <value>Overlay type</value>
    176179  </data>
     180  <data name="start_caption" xml:space="preserve">
     181    <value>Connect</value>
     182  </data>
     183  <data name="start_failed" xml:space="preserve">
     184    <value>Cannot connect to the P2P network. You are already connected or a connection attempt is in progress.</value>
     185  </data>
     186  <data name="start_launched" xml:space="preserve">
     187    <value>Connection to the P2P network will be established in the background.</value>
     188  </data>
     189  <data name="start_tooltip" xml:space="preserve">
     190    <value>Connect to the P2P network.</value>
     191  </data>
    177192  <data name="stop_caption" xml:space="preserve">
    178193    <value>Disconnect</value>
    179194  </data>
     195  <data name="stop_failed" xml:space="preserve">
     196    <value>Cannot disconnect from the P2P network. You are not connected or a connection attempt is in progress.</value>
     197  </data>
     198  <data name="stop_launched" xml:space="preserve">
     199    <value>Disconnecting from the P2P network.</value>
     200  </data>
    180201  <data name="stop_tooltip" xml:space="preserve">
    181     <value>Disconnect from P2P network. For debugging only.</value>
     202    <value>Disconnect from P2P network.</value>
    182203  </data>
    183204  <data name="transportprotocol_caption" xml:space="preserve">
  • trunk/CrypPlugins/PeerToPeerBaseProxy/P2PPeer.cs

    r1589 r1611  
    2222using Cryptool.P2P;
    2323using Cryptool.P2P.Internal;
     24using Cryptool.P2P.Worker;
    2425using Cryptool.PluginBase;
    2526using Cryptool.PluginBase.Control;
     
    8182        public bool PeerStarted()
    8283        {
    83             return P2PManager.Instance.IsP2PConnected();
     84            return P2PManager.Instance.IsP2PConnected() && !P2PManager.Instance.IsP2PConnecting;
    8485        }
    8586
     
    9495                _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
    9596            }
     97            else if (!P2PManager.Instance.IsP2PConnected() && P2PManager.Instance.IsP2PConnecting)
     98            {
     99                HandleAlreadyConnecting();
     100            }
    96101            else
    97102            {
    98                 GuiLogMessage("P2P network must be configured and connecting using the world button.",
     103                if (_settings.Autoconnect)
     104                {
     105                    HandleAutoconnect();
     106                }
     107                else
     108                {
     109                    GuiLogMessage("P2P network offline. Please check the autoconnect checkbox of the proxy plugin or connect manually first.",
     110                                      NotificationLevel.Error);
     111                    _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Error);
     112                    throw new ApplicationException("Workaround for wrong error handling... Workspace should be stopped now.");
     113                }
     114            }
     115        }
     116
     117        private void HandleAlreadyConnecting()
     118        {
     119            P2PManager.OnP2PConnectionStateChangeOccurred += HandleConnectionStateChange;
     120            _connectResetEvent = new AutoResetEvent(false);
     121            _connectResetEvent.WaitOne();
     122
     123            if (P2PManager.Instance.IsP2PConnected())
     124            {
     125                GuiLogMessage("P2P connected.", NotificationLevel.Info);
     126                _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
     127            }
     128            else
     129            {
     130                GuiLogMessage("P2P network could not be connected.",
    99131                              NotificationLevel.Error);
    100132                _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Error);
    101             }
     133                throw new ApplicationException("Workaround for wrong error handling... Workspace should be stopped now.");
     134            }
     135        }
     136
     137        private void HandleAutoconnect()
     138        {
     139            P2PManager.OnP2PConnectionStateChangeOccurred += HandleConnectionStateChange;
     140            _connectResetEvent = new AutoResetEvent(false);
     141
     142            new ConnectionWorker(P2PManager.Instance.P2PBase).Start();
     143
     144            _connectResetEvent.WaitOne();
     145
     146            if (P2PManager.Instance.IsP2PConnected())
     147            {
     148                GuiLogMessage("P2P network was connected due to plugin setting.",
     149                              NotificationLevel.Info);
     150                _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
     151            }
     152            else
     153            {
     154                GuiLogMessage("P2P network could not be connected.",
     155                              NotificationLevel.Error);
     156                _settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Error);
     157                throw new ApplicationException("Workaround for wrong error handling... Workspace should be stopped now.");
     158            }
     159        }
     160
     161        void HandleConnectionStateChange(object sender, bool newState)
     162        {
     163            _connectResetEvent.Set();
    102164        }
    103165
     
    114176        private IP2PControl _p2PSlave;
    115177        private P2PPeerSettings _settings;
     178        private AutoResetEvent _connectResetEvent;
    116179
    117180        #endregion
     
    122185        {
    123186            _settings = new P2PPeerSettings();
    124             _settings.TaskPaneAttributeChanged += SettingsTaskPaneAttributeChanged;
    125187            _settings.OnPluginStatusChanged += SettingsOnPluginStatusChanged;
    126188        }
     
    418480        private static bool SystemJoinedCompletely()
    419481        {
    420             return P2PManager.Instance.IsP2PConnected();
     482            return P2PManager.Instance.IsP2PConnected() && !P2PManager.Instance.IsP2PConnecting;
    421483        }
    422484
  • trunk/CrypPlugins/PeerToPeerBaseProxy/P2PPeerSettings.cs

    r1589 r1611  
    77    internal class P2PPeerSettings : ISettings
    88    {
     9        private readonly P2PProxySettings _settings;
     10
    911        #region PeerStatus enum
    1012
     
    3133        public P2PPeerSettings()
    3234        {
    33             if (TaskPaneAttributeChanged != null)
    34                 TaskPaneAttributeChanged(this,
    35                                          new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer("BtnStop",
    36                                                                                                              Visibility.
    37                                                                                                                  Hidden)));
    3835            ChangePluginIcon(PeerStatus.NotConnected);
     36            _settings = P2PProxySettings.Default;
    3937        }
    4038
    4139        #endregion
    4240
    43         public event TaskPaneAttributeChangedHandler TaskPaneAttributeChanged;
     41        [TaskPane("Autoconnect P2P network", "Autoconnect to the P2P network, when the workspace is executed.", null, 0, true, DisplayLevel.Beginner,
     42            ControlType.CheckBox)]
     43        public bool Autoconnect
     44        {
     45            get { return _settings.Autoconnect; }
     46            set
     47            {
     48                if (value != _settings.Autoconnect)
     49                {
     50                    _settings.Autoconnect = value;
     51                    OnPropertyChanged("Autoconnect");
     52                    HasChanges = true;
     53                }
     54            }
     55        }
    4456
    4557        private void OnPropertyChanged(string p)
     
    4961                PropertyChanged(this, new PropertyChangedEventArgs(p));
    5062            }
     63
     64            P2PProxySettings.Default.Save();
    5165        }
    5266
  • trunk/CrypPlugins/PeerToPeerBaseProxy/PeerToPeerBaseProxy.csproj

    r1487 r1611  
    6464    <Compile Include="P2PPeer.cs" />
    6565    <Compile Include="P2PPeerSettings.cs" />
     66    <Compile Include="P2PProxySettings.Designer.cs">
     67      <AutoGen>True</AutoGen>
     68      <DesignTimeSharedInput>True</DesignTimeSharedInput>
     69      <DependentUpon>P2PProxySettings.settings</DependentUpon>
     70    </Compile>
    6671    <Compile Include="Properties\AssemblyInfo.cs" />
    6772  </ItemGroup>
     
    9297    </ProjectReference>
    9398  </ItemGroup>
     99  <ItemGroup>
     100    <None Include="app.config" />
     101    <None Include="P2PProxySettings.settings">
     102      <Generator>SettingsSingleFileGenerator</Generator>
     103      <LastGenOutput>P2PProxySettings.Designer.cs</LastGenOutput>
     104    </None>
     105  </ItemGroup>
     106  <ItemGroup />
    94107  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    95108  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset for help on using the changeset viewer.