Ignore:
Timestamp:
May 21, 2010, 4:00:55 PM (12 years ago)
Author:
Paul Lelgemann
Message:
  • Removed unused references and using statement in CrypP2P, PeerToPeer, PeerToPeerBaseProxy

+ Skeleton for P2PEditor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/P2PManager.cs

    r1438 r1458  
    1616
    1717using System;
    18 using System.Collections.Generic;
    19 using System.Text;
    20 using System.ComponentModel;
    21 
     18using System.Windows.Forms;
     19using Cryptool.P2P.Internal;
     20using Cryptool.P2P.Worker;
    2221using Cryptool.PluginBase;
    2322using Cryptool.PluginBase.Miscellaneous;
    24 using System.Windows.Forms;
    25 using Cryptool.P2P.Worker;
     23using Cryptool.Plugins.PeerToPeer.Internal;
    2624using DevComponents.WpfRibbon;
    27 using Cryptool.Plugins.PeerToPeer;
    28 using Cryptool.Plugins.PeerToPeer.Internal;
    29 using Cryptool.P2P.Internal;
    3025
    3126namespace Cryptool.P2P
     
    3429    {
    3530        #region Singleton
    36         static readonly P2PManager INSTANCE = new P2PManager();
    37         private P2PManager() { }
    3831
    39         public static P2PManager Instance
     32        public static readonly P2PManager Instance = new P2PManager();
     33
     34        private P2PManager()
    4035        {
    41             get
    42             {
    43                 return INSTANCE;
    44             }
    4536        }
     37
    4638        #endregion
    4739
    4840        # region Constants
    49         public const string P2PDisconnectImageURI = "images/peer2peer-disconnect.png";
    50         public const string P2PConnectImageURI = "images/peer2peer-connect.png";
     41
     42        public const string P2PDisconnectImageUri = "images/peer2peer-disconnect.png";
     43        public const string P2PConnectImageUri = "images/peer2peer-connect.png";
     44
    5145        # endregion
    5246
    5347        #region Private variables
     48
    5449        public P2PBase P2PBase { get; set; }
    5550        private P2PSettings P2PSettings { get; set; }
    5651        private ButtonDropDown P2PButton { get; set; }
     52
    5753        #endregion
    5854
    5955        #region Events
    60         public static event Cryptool.PluginBase.GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
     56
     57        public static event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
    6158
    6259        // to forward event from overlay/dht MessageReceived-Event from P2PBase
    6360        public event P2PBase.P2PMessageReceived OnPeerMessageReceived;
     61
    6462        #endregion Events
    6563
     
    6866        /// regarding certificates.
    6967        /// </summary>
    70         /// <param name="p2pButton">Button that can change the connection state
     68        /// <param name="p2PButton">Button that can change the connection state
    7169        /// and displays it by showing different images.</param>
    72         public void Initialize(ButtonDropDown p2pButton)
     70        public void Initialize(ButtonDropDown p2PButton)
    7371        {
    74             this.P2PButton = p2pButton;
    75             this.P2PBase = new P2PBase();
    76             this.P2PSettings = new P2PSettings();
    77             this.P2PBase.AllowLoggingToMonitor = this.P2PSettings.Log2Monitor;
     72            P2PButton = p2PButton;
     73            P2PBase = new P2PBase();
     74            P2PSettings = new P2PSettings();
     75            P2PBase.AllowLoggingToMonitor = P2PSettings.Log2Monitor;
    7876
    7977            // Register events
    8078
    8179            // to forward event from overlay/dht MessageReceived-Event from P2PBase
    82             this.P2PBase.OnP2PMessageReceived += new P2PBase.P2PMessageReceived(p2pBase_OnP2PMessageReceived);
     80            P2PBase.OnP2PMessageReceived += p2pBase_OnP2PMessageReceived;
    8381
    8482            // Register exit event to terminate P2P connection without loosing data
    8583            // TODO check if this is correct, should be - but handler is not called (and application does not shut down), probably unrelated to this problem
    86             Application.ApplicationExit += new EventHandler(HandleDisconnectByApplicationShutdown);
     84            Application.ApplicationExit += HandleDisconnectByApplicationShutdown;
    8785        }
    8886
     
    115113        }
    116114
    117         #region DHT operations
    118         // TODO add error handling, if P2P if not connected
    119         public static bool Store(string key, byte[] data)
    120         {
    121             return INSTANCE.P2PBase.SynchStore(key, data);
    122         }
    123 
    124          public static bool Store(string key, string data)
    125         {
    126             return INSTANCE.P2PBase.SynchStore(key, data);
    127         }
    128 
    129         public static byte[] Retrieve(string key)
    130         {
    131             return INSTANCE.P2PBase.SynchRetrieve(key);
    132         }
    133 
    134         public static bool Remove(string key)
    135         {
    136             return INSTANCE.P2PBase.SynchRemove(key);
    137         }
    138         #endregion DHT operations
    139 
    140115        // to forward event from overlay/dht MessageReceived-Event from P2PBase
    141116        private void p2pBase_OnP2PMessageReceived(PeerId sourceAddr, byte[] data)
     
    146121
    147122        #region Framework methods
    148         void HandleDisconnectByApplicationShutdown(object sender, EventArgs e)
     123
     124        private void HandleDisconnectByApplicationShutdown(object sender, EventArgs e)
    149125        {
    150126            if (P2PConnected())
     
    158134            EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, null, new GuiLogEventArgs(message, null, logLevel));
    159135        }
     136
    160137        #endregion Framework methods
     138
     139        #region DHT operations
     140
     141        // TODO add error handling, if P2P is not connected
     142        public static bool Store(string key, byte[] data)
     143        {
     144            return Instance.P2PBase.SynchStore(key, data);
     145        }
     146
     147        public static bool Store(string key, string data)
     148        {
     149            return Instance.P2PBase.SynchStore(key, data);
     150        }
     151
     152        public static byte[] Retrieve(string key)
     153        {
     154            return Instance.P2PBase.SynchRetrieve(key);
     155        }
     156
     157        public static bool Remove(string key)
     158        {
     159            return Instance.P2PBase.SynchRemove(key);
     160        }
     161
     162        #endregion DHT operations
    161163    }
    162164}
Note: See TracChangeset for help on using the changeset viewer.