Пример #1
0
        protected override void InitializeCommands()
        {
            this.CreateRegistrationCommand = new PresenterCommand()
            {
                CanExecuteDelegate = code => PeerClassifier.Length > 0,
                ExecuteDelegate = code =>
                {
                    PeerName name = new PeerName(this.PeerClassifier,_peerNameType);

                    try
                    {
                        _service.CreateRegistration(name, 8080);
                    }
                    catch (PeerToPeerException ex)
                    {
                        ServiceLocator.Resolve<IMessageBoxService>().ShowError(ex.Message);
                    }
                    finally
                    {

                        this.PeerClassifier = string.Empty;
                    }
                }
            };

            this.SetSecureCommand = new PresenterCommand()
            {
                CanExecuteDelegate = secure => true,
                ExecuteDelegate = secure =>
                    {
                        _peerNameType = ((bool)secure) ? PeerNameType.Secured : PeerNameType.Unsecured;
                    }
            };

            this.LookupRegistrationCommand = new PresenterCommand
            {
                CanExecuteDelegate = code => PeerClassifier.Length>0,
                ExecuteDelegate = code =>
                    {
                        try
                        {
                            PeerName peer = new PeerName(PeerClassifier, _peerNameType);
                            LookupPresenter presenter = new LookupPresenter(peer,_service);
                            ServiceLocator.Resolve<IDialogService>().ShowDialog("LookUpRegistration", presenter);
                        }
                        catch (PeerToPeerException ex)
                        {
                            ServiceLocator.Resolve<IMessageBoxService>().ShowError(ex.Message);
                        }
                        finally
                        {
                            this.PeerClassifier = string.Empty;
                        }
                    }
            };
        }
Пример #2
0
        protected override void InitializeCommands()
        {
            this.CreateRegistrationCommand = new PresenterCommand()
            {
                CanExecuteDelegate = code => PeerClassifier.Length > 0,
                ExecuteDelegate    = code =>
                {
                    PeerName name = new PeerName(this.PeerClassifier, _peerNameType);

                    try
                    {
                        _service.CreateRegistration(name, 8080);
                    }
                    catch (PeerToPeerException ex)
                    {
                        ServiceLocator.Resolve <IMessageBoxService>().ShowError(ex.Message);
                    }
                    finally
                    {
                        this.PeerClassifier = string.Empty;
                    }
                }
            };

            this.SetSecureCommand = new PresenterCommand()
            {
                CanExecuteDelegate = secure => true,
                ExecuteDelegate    = secure =>
                {
                    _peerNameType = ((bool)secure) ? PeerNameType.Secured : PeerNameType.Unsecured;
                }
            };

            this.LookupRegistrationCommand = new PresenterCommand
            {
                CanExecuteDelegate = code => PeerClassifier.Length > 0,
                ExecuteDelegate    = code =>
                {
                    try
                    {
                        PeerName        peer      = new PeerName(PeerClassifier, _peerNameType);
                        LookupPresenter presenter = new LookupPresenter(peer, _service);
                        ServiceLocator.Resolve <IDialogService>().ShowDialog("LookUpRegistration", presenter);
                    }
                    catch (PeerToPeerException ex)
                    {
                        ServiceLocator.Resolve <IMessageBoxService>().ShowError(ex.Message);
                    }
                    finally
                    {
                        this.PeerClassifier = string.Empty;
                    }
                }
            };
        }
Пример #3
0
        //</Snippet1>

        /// <summary>
        /// Parse the command line arguments
        /// </summary>
        private static bool ParseCommandLine(string[] args)
        {
            //Command line format:
            const string usage = "Usage: RegisterPeerName.exe <Peer Name Classifier> <PeerNameType:Secured|UnSecured> <Port #> <Comment> <Cloud Name:Available|AllLinkLocal|Global>";

            try
            {
                if (args.Length < 5)
                {
                    Console.WriteLine(usage);
                    return(false);
                }

                peerNameClassifier = args[0];

                //Create a secure or unsecure PeerName using the command line arguments: <PeerNameClassifier> and <PeerNameType:Secured|UnSecured>
                string peerNameTypeArgument = args[1].ToLower();
                if (peerNameTypeArgument.Equals("secured"))
                {
                    peerNameType = PeerNameType.Secured;
                }
                else if (peerNameTypeArgument.Equals("unsecured"))
                {
                    peerNameType = PeerNameType.Unsecured;
                }
                else
                {
                    Console.WriteLine("PeerNameType argument is invalid.\n");
                    Console.WriteLine(usage);
                    return(false);
                }

                // read the port number
                portNumber = int.Parse(args[2]);

                // read the commment to assign to the peername
                comment = args[3];

                // determine the cloud to register the peername into
                string cloudNameArgument = args[4].ToLower();
                if (cloudNameArgument.Equals("available"))
                {
                    cloudName = Cloud.Available;
                }
                else if (cloudNameArgument.Equals("alllinklocal"))
                {
                    cloudName = Cloud.AllLinkLocal;
                }
                else if (cloudNameArgument.Equals("global"))
                {
                    cloudName = Cloud.Global;
                }
                else
                {
                    Console.WriteLine("Cloud Name argument is invalid.\n");
                    Console.WriteLine(usage);
                    return(false);
                }
            }
            catch (Exception e)
            {
                // P2P is not supported on Windows Server 2003
                if (e.InnerException != null)
                {
                    Console.WriteLine("Error occurred while attempting to register the PeerName: {0}", e.Message);
                    Console.WriteLine(e.StackTrace);

                    Console.WriteLine("Inner Exception is {0}", e.InnerException);
                }
                else
                {
                    Console.WriteLine("Error occurred while attempting to register the PeerName: {0}", e.Message);
                    Console.WriteLine(usage);

                    Console.WriteLine("Exception is {0}", e);
                    Console.WriteLine(e.StackTrace);
                }
                return(false);
            }
            return(true);
        }
Пример #4
0
        public PeerName(string classifier, PeerNameType peerNameType)
        {
            //-------------------------------------------------
            //Check arguments
            //-------------------------------------------------
            if ((classifier == null || classifier.Length == 0) &&
                peerNameType == PeerNameType.Unsecured)
            {
                throw new ArgumentNullException("classifier");
            }
            if (classifier != null && classifier.Length > PEER_MAX_CLASSIFIER_LENGTH)
            {
                throw new ArgumentException(SR.GetString(SR.Pnrp_InvalidClassifier), "classifier");
            }
            //--------------------------------------------------
            //Normalize using NFC
            //--------------------------------------------------
            if (classifier != null && classifier.Length > 0)
            {
                classifier = classifier.Normalize(NormalizationForm.FormC);
            }
            //-------------------------------------------------
            //call the helper to create the PeerName
            //-------------------------------------------------
            Int32        result;
            SafePeerData shNewPeerName     = null;
            SafePeerData shDefaultIdentity = null;

            try
            {
                if (peerNameType == PeerNameType.Unsecured)
                {
                    result = UnsafeP2PNativeMethods.PeerCreatePeerName((string)null, classifier, out shNewPeerName);
                    if (result != 0)
                    {
                        throw PeerToPeerException.CreateFromHr(SR.GetString(SR.Pnrp_CouldNotCreateUnsecuredPeerName), result);
                    }
                    m_Authority = PEERNAME_UNSECURED_AUTHORITY;
                }
                else
                {
                    result = UnsafeP2PNativeMethods.PeerIdentityGetDefault(out shDefaultIdentity);
                    if (result != 0)
                    {
                        throw PeerToPeerException.CreateFromHr(SR.GetString(SR.Pnrp_CouldNotGetDefaultIdentity), result);
                    }
                    m_Authority = shDefaultIdentity.UnicodeString;
                    //}

                    result = UnsafeP2PNativeMethods.PeerCreatePeerName(m_Authority, classifier, out shNewPeerName);
                    if (result != 0)
                    {
                        throw PeerToPeerException.CreateFromHr(SR.GetString(SR.Pnrp_CouldNotCreateSecuredPeerName), result);
                    }
                }
                m_PeerName   = shNewPeerName.UnicodeString;
                m_Classifier = classifier;
            }
            finally
            {
                if (shNewPeerName != null)
                {
                    shNewPeerName.Dispose();
                }
                if (shDefaultIdentity != null)
                {
                    shDefaultIdentity.Dispose();
                }
            }
            Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "PeerName instance created - PeerName {0} Authority {1} Classfier {2}", m_PeerName, m_Authority, m_Classifier);
        }
Пример #5
0
        public PeerNameRecordCollection LookupRegistration(string classifier, PeerNameType peerType)
        {
            PeerName peerName = new PeerName(classifier, peerType);

            return(LookupRegistration(peerName));
        }
Пример #6
0
 public PeerNameRecordCollection LookupRegistration(string classifier, PeerNameType peerType)
 {
     PeerName peerName = new PeerName(classifier, peerType);
     return LookupRegistration(peerName);
 }