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/CrypPlugins/PeerToPeerBaseProxy
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.